]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: cleanup helper initialization API
authorKarel Zak <kzak@redhat.com>
Wed, 2 Feb 2011 21:32:52 +0000 (22:32 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 2 Feb 2011 21:32:52 +0000 (22:32 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/mount/docs/libmount-sections.txt
shlibs/mount/src/context.c
shlibs/mount/src/context_mount.c
shlibs/mount/src/context_umount.c
shlibs/mount/src/libmount.h.in
shlibs/mount/src/libmount.sym
shlibs/mount/src/mountP.h

index ce744f3a2b1565c8c89f83dca91926bb8f641d19..f79374d907f2dfc767c6abde3d69419bffc96ac2 100644 (file)
@@ -171,6 +171,8 @@ mnt_update_table
 
 <SECTION>
 <FILE>context</FILE>
+mnt_context_init_helper
+mnt_context_helper_setopt
 mnt_context_append_options
 mnt_context_apply_fstab
 mnt_context_disable_canonicalize
index de852a3af31a791978e7c679b40e9bd8031dfff8..23cb4b9941a040665efd6bd05d9adb10672fdfa7 100644 (file)
@@ -1516,6 +1516,7 @@ int mnt_context_strerror(struct libmnt_context *cxt, char *buf, size_t bufsiz)
 /**
  * mnt_context_init_helper
  * @cxt: mount context
+ * @action: MNT_ACT_{UMOUNT,MOUNT}
  * @flags: not used
  *
  * This function infors libmount that used from [u]mount.<type> helper.
@@ -1529,17 +1530,44 @@ int mnt_context_strerror(struct libmnt_context *cxt, char *buf, size_t bufsiz)
  *
  * Returns: 0 on success, negative number in case of error.
  */
-int mnt_context_init_helper(struct libmnt_context *cxt, int flags)
+int mnt_context_init_helper(struct libmnt_context *cxt, int action, int flags)
 {
        int rc = mnt_context_disable_helpers(cxt, TRUE);
 
        if (!rc)
-               return set_flag(cxt, MNT_FL_HELPER, 1);
+               rc = set_flag(cxt, MNT_FL_HELPER, 1);
+       if (!rc)
+               cxt->action = action;
 
-       DBG(CXT, mnt_debug_h(cxt, "initialized for [u]mount.<type> helper"));
+       DBG(CXT, mnt_debug_h(cxt, "initialized for [u]mount.<type> helper [rc=%d]", rc));
        return rc;
 }
 
+/**
+ * mnt_context_helper_setopt:
+ * @cxr: context
+ * @c: getopt() result
+ * @arg: getopt() optarg
+ *
+ * This function applies [u]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_helper_setopt(struct libmnt_context *cxt, int c, char *arg)
+{
+       if (cxt) {
+               switch(cxt->action) {
+               case MNT_ACT_MOUNT:
+                       return mnt_context_mount_setopt(cxt, c, arg);
+               case MNT_ACT_UMOUNT:
+                       return mnt_context_umount_setopt(cxt, c, arg);
+               }
+       }
+       return -EINVAL;
+}
+
 #ifdef TEST_PROGRAM
 
 struct libmnt_lock *lock;
index 7f684727785aa9821155950fb6d63b98b643bd40..0c67546444bf413f8f0f0ed392c886f3124edcb5 100644 (file)
@@ -218,11 +218,8 @@ static int evaluate_permissions(struct libmnt_context *cxt)
        return 0;
 }
 
-/**
- * mnt_context_mounthelper_setopt:
- * @cxr: context
- * @c: getopt() result
- * @arg: getopt() optarg
+/*
+ * mnt_context_helper_setopt() backend
  *
  * This function applies mount.<type> command line option (for example parsed
  * by getopt() or getopt_long()) to @cxt. All unknown options are ignored and
@@ -230,12 +227,12 @@ static int evaluate_permissions(struct libmnt_context *cxt)
  *
  * Returns: negative number on error, 1 if @c is unknown option, 0 on success.
  */
-int mnt_context_mounthelper_setopt(struct libmnt_context *cxt, int c, char *arg)
+int mnt_context_mount_setopt(struct libmnt_context *cxt, int c, char *arg)
 {
        int rc = -EINVAL;
 
-       if (!cxt || !c)
-               return -EINVAL;
+       assert(cxt);
+       assert(cxt->action == MNT_ACT_MOUNT);
 
        switch(c) {
        case 'f':
index d38e5de6edd8c1d40d1552ac53397e8a7f04065a..122ef7f840d76cb3db3598544e462c8a31786f16 100644 (file)
@@ -371,6 +371,50 @@ static int exec_helper(struct libmnt_context *cxt)
        return rc;
 }
 
+/*
+ * mnt_context_helper_setopt() backend.
+ *
+ * This function applies umount.<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_umount_setopt(struct libmnt_context *cxt, int c, char *arg)
+{
+       int rc = -EINVAL;
+
+       assert(cxt);
+       assert(cxt->action == MNT_ACT_UMOUNT);
+
+       switch(c) {
+       case 'n':
+               rc = mnt_context_disable_mtab(cxt, TRUE);
+               break;
+       case 'l':
+               rc = mnt_context_enable_lazy(cxt, TRUE);
+               break;
+       case 'f':
+               rc = mnt_context_enable_fake(cxt, TRUE);
+               break;
+       case 'v':
+               rc = mnt_context_enable_verbose(cxt, TRUE);
+               break;
+       case 'r':
+               rc = mnt_context_enable_rdonly_umount(cxt, TRUE);
+               break;
+       case 't':
+               if (arg)
+                       rc = mnt_context_set_fstype(cxt, arg);
+               break;
+       default:
+               return 1;
+               break;
+       }
+
+       return rc;
+}
+
 static int do_umount(struct libmnt_context *cxt)
 {
        int rc = 0;
index 81fa1df333a414a5459e829336a0e1aa5c8826c7..aa00b938dc5da20df15fef3833ea23b733b614ee 100644 (file)
@@ -348,9 +348,9 @@ extern void mnt_free_context(struct libmnt_context *cxt);
 extern int mnt_reset_context(struct libmnt_context *cxt);
 extern int mnt_context_is_restricted(struct libmnt_context *cxt);
 
-extern int mnt_context_init_helper(struct libmnt_context *cxt, int flags);
-extern int mnt_context_mounthelper_setopt(struct libmnt_context *cxt, int c,
-                                         char *arg);
+extern int mnt_context_init_helper(struct libmnt_context *cxt,
+                                  int action, int flags);
+extern int mnt_context_helper_setopt(struct libmnt_context *cxt, int c, char *arg);
 
 extern int mnt_context_set_optsmode(struct libmnt_context *cxt, int mode);
 extern int mnt_context_disable_canonicalize(struct libmnt_context *cxt, int disable);
index 78f4f7e2f5872cc354b5b34285f2de8f7d3af233..2481b4931a8cab6b9eca0153b4245ddb87b9395b 100644 (file)
@@ -46,7 +46,7 @@ global:
        mnt_context_is_sloppy;
        mnt_context_is_verbose;
        mnt_context_mount;
-       mnt_context_mounthelper_setopt;
+       mnt_context_helper_setopt;
        mnt_context_prepare_mount;
        mnt_context_prepare_umount;
        mnt_context_set_cache;
index 879d58c61261045865ac2426099c0aed0c26c1e3..a38aa10e433793746902f262b6cbab04bde9dad7 100644 (file)
@@ -324,6 +324,9 @@ extern struct libmnt_fs *mnt_context_get_fs(struct libmnt_context *cxt);
 extern int mnt_context_merge_mflags(struct libmnt_context *cxt);
 extern int mnt_context_update_tabs(struct libmnt_context *cxt);
 
+extern int mnt_context_umount_setopt(struct libmnt_context *cxt, int c, char *arg);
+extern int mnt_context_mount_setopt(struct libmnt_context *cxt, int c, char *arg);
+
 /* tab_update.c */
 extern struct libmnt_fs *mnt_update_get_fs(struct libmnt_update *upd);
 extern int mnt_update_set_filename(struct libmnt_update *upd,