]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: add functions for mount.<type> helpers
authorKarel Zak <kzak@redhat.com>
Thu, 20 Jan 2011 14:32:40 +0000 (15:32 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 21 Jan 2011 23:27:26 +0000 (00:27 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/mount/src/context.c
shlibs/mount/src/context_mount.c
shlibs/mount/src/libmount.h.in
shlibs/mount/src/mount.sym
shlibs/mount/src/mountP.h

index aad0b3930fd5057fd550b2bf0a7cc5c7371b94ed..b01d4bd042f2f5b8a55973251356b8e03a20873e 100644 (file)
@@ -47,7 +47,7 @@
  *
  * Returns: newly allocated mount context
  */
-mnt_context *mnt_new_context()
+mnt_context *mnt_new_context(void)
 {
        mnt_context *cxt;
        uid_t ruid, euid;
@@ -1454,6 +1454,20 @@ int mnt_context_strerror(mnt_context *cxt, char *buf, size_t bufsiz)
        return 0;
 }
 
+/**
+ * mnt_context_init_helper
+ * @cxt: mount context
+ * @flags: not used
+ *
+ * This function infors libmount that used from [u]mount.<type> helper.
+ *
+ * Returns: 0 on success, negative number in case of error.
+ */
+int mnt_context_init_helper(mnt_context *cxt, int flags)
+{
+       return set_flag(cxt, MNT_FL_HELPER, 1);
+}
+
 #ifdef TEST_PROGRAM
 
 mnt_lock *lock;
index 55cf48bf81dcb66e73c1602cc50e043af98d0b6c..a54983fa4105884fd4159b5b8b5dd73c69fa5d33 100644 (file)
@@ -218,6 +218,60 @@ static int evaluate_permissions(mnt_context *cxt)
        return 0;
 }
 
+/**
+ * mnt_context_mounthelper_setopt:
+ * @cxr: context
+ * @c: getopt() result
+ * @arg: getopt() optarg
+ *
+ * This function applies mount.<type> command line option (for example parsed
+ * by getopt() or getopt_long()) to @cxt. All unknown options are ignored and
+ * then 1 is returned.
+ *
+ * Returns: negative number on error, 1 if @c is unknown option, 0 on success.
+ */
+int mnt_context_mounthelper_setopt(mnt_context *cxt, int c, char *arg)
+{
+       int rc = -EINVAL;
+
+       if (!cxt || !c)
+               return -EINVAL;
+
+       switch(c) {
+       case 'f':
+               rc = mnt_context_enable_fake(cxt, TRUE);
+               break;
+       case 'n':
+               rc = mnt_context_disable_mtab(cxt, TRUE);
+               break;
+       case 'r':
+               rc = mnt_context_append_options(cxt, "ro");
+               break;
+       case 'v':
+               rc = mnt_context_enable_verbose(cxt, TRUE);
+               break;
+       case 'w':
+               rc = mnt_context_append_options(cxt, "rw");
+               break;
+       case 'o':
+               if (arg)
+                       rc = mnt_context_append_options(cxt, arg);
+               break;
+       case 's':
+               rc = mnt_context_enable_sloppy(cxt, TRUE);
+               break;
+       case 't':
+               if (arg)
+                       rc = mnt_context_set_fstype(cxt, arg);
+               break;
+       default:
+               return 1;
+               break;
+       }
+
+       return rc;
+}
+
 static int exec_helper(mnt_context *cxt)
 {
        char *o = NULL;
@@ -254,13 +308,13 @@ static int exec_helper(mnt_context *cxt)
                args[i++] = mnt_fs_get_srcpath(cxt->fs);/* 2 */
                args[i++] = mnt_fs_get_target(cxt->fs); /* 3 */
 
-               if (cxt->flags & MNT_FL_SLOPPY)
+               if (mnt_context_is_sloppy(cxt))
                        args[i++] = "-s";               /* 4 */
-               if (cxt->flags & MNT_FL_FAKE)
+               if (mnt_context_is_fake(cxt))
                        args[i++] = "-f";               /* 5 */
-               if (cxt->flags & MNT_FL_NOMTAB)
+               if (mnt_context_is_nomtab(cxt))
                        args[i++] = "-n";               /* 6 */
-               if (cxt->flags & MNT_FL_VERBOSE)
+               if (mnt_context_is_verbose(cxt))
                        args[i++] = "-v";               /* 7 */
                if (o) {
                        args[i++] = "-o";               /* 8 */
index 84f768477ff634441cf54d442bb04b61516421d2..819bdddff787ad1216828258b8548f3dfe64afb7 100644 (file)
@@ -333,6 +333,9 @@ extern void mnt_free_context(mnt_context *cxt);
 extern int mnt_reset_context(mnt_context *cxt);
 extern int mnt_context_is_restricted(mnt_context *cxt);
 
+extern int mnt_context_init_helper(mnt_context *cxt, int flags)
+extern int mnt_context_mounthelper_setopt(mnt_context *cxt, int c, char *arg);
+
 extern int mnt_context_set_optsmode(mnt_context *cxt, int mode);
 extern int mnt_context_disable_canonicalize(mnt_context *cxt, int disable);
 extern int mnt_context_enable_lazy(mnt_context *cxt, int enable);
index e29372ed5927de490c33a835853e304d1c1af82f..1a9ebb02d676da8a20aaae76cd5c0c54f66a5f98 100644 (file)
@@ -32,6 +32,7 @@ global:
        mnt_context_get_optsmode;
        mnt_context_get_status;
        mnt_context_get_userspace_mountflags;
+       mnt_context_init_helper;
        mnt_context_is_fake;
        mnt_context_is_force;
        mnt_context_is_lazy;
@@ -40,6 +41,7 @@ global:
        mnt_context_is_restricted;
        mnt_context_is_sloppy;
        mnt_context_is_verbose;
+       mnt_context_mounthelper_setopt;
        mnt_context_prepare_mount;
        mnt_context_set_cache;
        mnt_context_set_fs;
index f6c2e211727812b626b7d48ef66edbe51252c815..5b8c89c5512d9f2379a22826d0e69eeeab4656dd 100644 (file)
@@ -287,6 +287,7 @@ struct _mnt_context
 #define MNT_FL_MOUNTFLAGS_MERGED (1 << 22)     /* MS_* flags was read from optstr */
 #define MNT_FL_SAVED_USER      (1 << 23)
 #define MNT_FL_PREPARED                (1 << 24)
+#define MNT_FL_HELPER          (1 << 25)       /* [u]mount.<type> */
 
 /* default flags */
 #define MNT_FL_DEFAULT         0