libmount: cleanup helper initialization API

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2011-02-02 22:32:52 +01:00
parent 9376009202
commit b70785bca6
7 changed files with 89 additions and 15 deletions

View 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

View 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;

View 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':

View 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;

View 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);

View 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;

View 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,