<SECTION>
<FILE>context</FILE>
+mnt_context_init_helper
+mnt_context_helper_setopt
mnt_context_append_options
mnt_context_apply_fstab
mnt_context_disable_canonicalize
/**
* 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.
*
* 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;
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
*
* 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':
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;
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);
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;
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,