summaryrefslogtreecommitdiffstats
path: root/shlibs/mount
diff options
context:
space:
mode:
authorKarel Zak2011-02-02 22:32:52 +0100
committerKarel Zak2011-02-02 22:32:52 +0100
commitb70785bca6238ea7e092dda8bd0aa56cdf1ec923 (patch)
tree96611cda1c80330668acb8545dd9cc65107d9383 /shlibs/mount
parentlibmount: add low-level API for umount (diff)
downloadkernel-qcow2-util-linux-b70785bca6238ea7e092dda8bd0aa56cdf1ec923.tar.gz
kernel-qcow2-util-linux-b70785bca6238ea7e092dda8bd0aa56cdf1ec923.tar.xz
kernel-qcow2-util-linux-b70785bca6238ea7e092dda8bd0aa56cdf1ec923.zip
libmount: cleanup helper initialization API
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/mount')
-rw-r--r--shlibs/mount/docs/libmount-sections.txt2
-rw-r--r--shlibs/mount/src/context.c34
-rw-r--r--shlibs/mount/src/context_mount.c13
-rw-r--r--shlibs/mount/src/context_umount.c44
-rw-r--r--shlibs/mount/src/libmount.h.in6
-rw-r--r--shlibs/mount/src/libmount.sym2
-rw-r--r--shlibs/mount/src/mountP.h3
7 files changed, 89 insertions, 15 deletions
diff --git a/shlibs/mount/docs/libmount-sections.txt b/shlibs/mount/docs/libmount-sections.txt
index ce744f3a2..f79374d90 100644
--- a/shlibs/mount/docs/libmount-sections.txt
+++ b/shlibs/mount/docs/libmount-sections.txt
@@ -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
diff --git a/shlibs/mount/src/context.c b/shlibs/mount/src/context.c
index de852a3af..23cb4b994 100644
--- a/shlibs/mount/src/context.c
+++ b/shlibs/mount/src/context.c
@@ -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;
diff --git a/shlibs/mount/src/context_mount.c b/shlibs/mount/src/context_mount.c
index 7f6847277..0c6754644 100644
--- a/shlibs/mount/src/context_mount.c
+++ b/shlibs/mount/src/context_mount.c
@@ -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':
diff --git a/shlibs/mount/src/context_umount.c b/shlibs/mount/src/context_umount.c
index d38e5de6e..122ef7f84 100644
--- a/shlibs/mount/src/context_umount.c
+++ b/shlibs/mount/src/context_umount.c
@@ -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;
diff --git a/shlibs/mount/src/libmount.h.in b/shlibs/mount/src/libmount.h.in
index 81fa1df33..aa00b938d 100644
--- a/shlibs/mount/src/libmount.h.in
+++ b/shlibs/mount/src/libmount.h.in
@@ -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);
diff --git a/shlibs/mount/src/libmount.sym b/shlibs/mount/src/libmount.sym
index 78f4f7e2f..2481b4931 100644
--- a/shlibs/mount/src/libmount.sym
+++ b/shlibs/mount/src/libmount.sym
@@ -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;
diff --git a/shlibs/mount/src/mountP.h b/shlibs/mount/src/mountP.h
index 879d58c61..a38aa10e4 100644
--- a/shlibs/mount/src/mountP.h
+++ b/shlibs/mount/src/mountP.h
@@ -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,