From f309b8a7c90693a73ab45dc548029d1007c7afe4 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 28 Jul 2010 15:14:41 +0200 Subject: [PATCH] libmount: add uhelper=, improve mnt_split_optstr() Signed-off-by: Karel Zak --- shlibs/mount/src/fs.c | 2 +- shlibs/mount/src/mount.h.in | 5 ++++- shlibs/mount/src/optmap.c | 2 ++ shlibs/mount/src/optstr.c | 29 ++++++++++++++++++++++------- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/shlibs/mount/src/fs.c b/shlibs/mount/src/fs.c index f0eae744..7fc5e882 100644 --- a/shlibs/mount/src/fs.c +++ b/shlibs/mount/src/fs.c @@ -407,7 +407,7 @@ int mnt_fs_set_optstr(mnt_fs *fs, const char *optstr) if (!fs || !optstr) return -1; - if (mnt_split_optstr((char *) optstr, NULL, &v, &f)) + if (mnt_split_optstr((char *) optstr, NULL, &v, &f, 0, 0)) return -1; p = strdup(optstr); diff --git a/shlibs/mount/src/mount.h.in b/shlibs/mount/src/mount.h.in index 33f8d172..6a1cd19b 100644 --- a/shlibs/mount/src/mount.h.in +++ b/shlibs/mount/src/mount.h.in @@ -146,7 +146,9 @@ extern int mnt_optstr_set_option(char **optstr, const char *name, const char *value); extern int mnt_optstr_remove_option(char **optstr, const char *name); -extern int mnt_split_optstr(const char *optstr, char **user, char **vfs, char **fs); +extern int mnt_split_optstr(const char *optstr, + char **user, char **vfs, char **fs, + int ifnore_user, int ignore_vfs); /* iter.c */ enum { @@ -305,6 +307,7 @@ extern int mnt_tab_find_next_fs(mnt_tab *tb, mnt_iter *itr, #define MNT_MS_COMMENT (1 << 8) #define MNT_MS_LOOP (1 << 9) #define MNT_MS_NOFAIL (1 << 10) +#define MNT_MS_UHELPER (1 << 11) /* * mount(2) MS_* masks (MNT_MAP_LINUX map) diff --git a/shlibs/mount/src/optmap.c b/shlibs/mount/src/optmap.c index 0163776a..12ead402 100644 --- a/shlibs/mount/src/optmap.c +++ b/shlibs/mount/src/optmap.c @@ -167,6 +167,8 @@ static const struct mnt_optmap userspace_opts_map[] = { "nofail", MNT_MS_NOFAIL, MNT_NOMTAB }, /* Do not fail if ENOENT on dev */ + { "uhelper=%s", MNT_MS_UHELPER }, /* /sbin/umount. */ + { NULL, 0, 0 } }; diff --git a/shlibs/mount/src/optstr.c b/shlibs/mount/src/optstr.c index fe9ee9be..f17bd7d3 100644 --- a/shlibs/mount/src/optstr.c +++ b/shlibs/mount/src/optstr.c @@ -336,15 +336,25 @@ int mnt_optstr_remove_option(char **optstr, const char *name) * @user: returns newly allocated string with userspace options * @vfs: returns newly allocated string with VFS options * @fs: returns newly allocated string with FS options + * @ignore_user: option mask for options that should be ignored + * @ignore_vfs: option mask for options that should be ignored + * + * For example: + * + * mnt_split_optstr(optstr, &u, NULL, NULL, MNT_NOMTAB, 0); + * + * returns all userspace options, the options that does not belong to + * mtab are ignored. * * Note that FS options are all options that are undefined in MNT_USERSPACE_MAP * or MNT_LINUX_MAP. * * Returns: 0 on success, or -1 in case of error. */ -int mnt_split_optstr(char *optstr, char **user, char **vfs, char **fs) +int mnt_split_optstr(const char *optstr, char **user, char **vfs, char **fs, + int ignore_user, int ignore_vfs) { - char *name, *val; + char *name, *val, *str = (char *) optstr; size_t namesz, valsz; struct mnt_optmap const *maps[2]; @@ -363,18 +373,23 @@ int mnt_split_optstr(char *optstr, char **user, char **vfs, char **fs) if (user) *user = NULL; - while(!mnt_optstr_next_option(&optstr, &name, &namesz, &val, &valsz)) { + while(!mnt_optstr_next_option(&str, &name, &namesz, &val, &valsz)) { int rc = 0; + const struct mnt_optmap *ent; const struct mnt_optmap *m = - mnt_optmap_get_entry(maps, 2, name, namesz, NULL); + mnt_optmap_get_entry(maps, 2, name, namesz, &ent); - if (m && m == maps[0] && vfs) + if (m && m == maps[0] && vfs) { + if (ignore_vfs && (ent->mask & ignore_vfs)) + continue; rc = __mnt_optstr_append_option(vfs, name, namesz, val, valsz); - else if (m && m == maps[1] && user) + } else if (m && m == maps[1] && user) { + if (ignore_user && (ent->mask & ignore_user)) + continue; rc = __mnt_optstr_append_option(user, name, namesz, val, valsz); - else if (!m && fs) + } else if (!m && fs) rc = __mnt_optstr_append_option(fs, name, namesz, val, valsz); if (rc) { -- 2.39.5