From 2b5cceb5c799794121bfab1a7652ea06b164cb3e Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 15 Sep 2010 16:55:47 +0200 Subject: [PATCH] libmount: add mnt_optstr_get_userspace_mountflags() Signed-off-by: Karel Zak --- shlibs/mount/src/Makefile.am | 2 +- shlibs/mount/src/mount.h.in | 1 + shlibs/mount/src/mount.sym | 1 + shlibs/mount/src/optstr.c | 108 +++++++++++++++++++++++++++-------- 4 files changed, 86 insertions(+), 26 deletions(-) diff --git a/shlibs/mount/src/Makefile.am b/shlibs/mount/src/Makefile.am index 9ce46737..e007272c 100644 --- a/shlibs/mount/src/Makefile.am +++ b/shlibs/mount/src/Makefile.am @@ -11,7 +11,7 @@ nodist_mountinc_HEADERS = mount.h usrlib_exec_LTLIBRARIES = libmount.la libmount_la_SOURCES = mountP.h version.c utils.c test.c init.c cache.c \ optstr.c optmap.c iter.c lock.c \ - fs.c tab.c tab_parse.c tab_update.c \ + fs.c tab.c tab_parse.c tab_update.c context.c \ $(mountinc_HEADERS) \ $(top_srcdir)/lib/at.c \ $(top_srcdir)/include/list.h \ diff --git a/shlibs/mount/src/mount.h.in b/shlibs/mount/src/mount.h.in index b35d6452..31406835 100644 --- a/shlibs/mount/src/mount.h.in +++ b/shlibs/mount/src/mount.h.in @@ -163,6 +163,7 @@ extern int mnt_split_optstr(const char *optstr, int ifnore_user, int ignore_vfs); extern int mnt_optstr_get_mountflags(const char *optstr, unsigned long *flags); +extern int mnt_optstr_get_userspace_mountflags(const char *optstr, unsigned long *flags); /* iter.c */ enum { diff --git a/shlibs/mount/src/mount.sym b/shlibs/mount/src/mount.sym index d0fa3085..0b7a9fe8 100644 --- a/shlibs/mount/src/mount.sym +++ b/shlibs/mount/src/mount.sym @@ -109,6 +109,7 @@ global: mnt_optstr_append_option; mnt_optstr_prepend_option; mnt_optstr_get_mountflags; + mnt_optstr_get_userspace_mountflags; mnt_optstr_get_option; mnt_optstr_next_option; mnt_optstr_remove_option; diff --git a/shlibs/mount/src/optstr.c b/shlibs/mount/src/optstr.c index b809386a..c35777f2 100644 --- a/shlibs/mount/src/optstr.c +++ b/shlibs/mount/src/optstr.c @@ -438,27 +438,8 @@ int mnt_split_optstr(const char *optstr, char **user, char **vfs, char **fs, return 0; } - -/** - * mnt_optstr_get_mountflags: - * @optstr: string with comma separated list of options - * @flags: returns mount flags - * - * The mountflags are IDs from all MNT_MFLAG options from MNT_LINUX_MAP options - * map. See "struct mnt_optmap". For more details about mountflags see - * mount(2) syscall. - * - * For example: - * - * "bind,exec,foo,bar" --returns-> MS_BIND - * - * "bind,noexec,foo,bar" --returns-> MS_BIND|MS_NOEXEC - * - * Note that @flags are not zeroized by this function. - * - * Returns: 0 on success or negative number in case of error - */ -int mnt_optstr_get_mountflags(const char *optstr, unsigned long *flags) +static int mnt_optstr_get_flags(const char *optstr, const struct mnt_optmap *map, + unsigned long *flags, int mask_fltr) { struct mnt_optmap const *maps[1]; char *name, *str = (char *) optstr; @@ -466,17 +447,17 @@ int mnt_optstr_get_mountflags(const char *optstr, unsigned long *flags) assert(optstr); - if (!optstr || !flags) + if (!optstr || !flags || !map) return -EINVAL; - maps[0] = mnt_get_builtin_optmap(MNT_LINUX_MAP); + maps[0] = map; while(!mnt_optstr_next_option(&str, &name, &namesz, NULL, NULL)) { const struct mnt_optmap *ent; if (mnt_optmap_get_entry(maps, 1, name, namesz, &ent)) { - if (!(ent->mask & MNT_MFLAG)) + if (mask_fltr && !(ent->mask & mask_fltr)) continue; if (ent->mask & MNT_INVERT) *flags &= ~ent->id; @@ -485,10 +466,60 @@ int mnt_optstr_get_mountflags(const char *optstr, unsigned long *flags) } } - DBG(OPTIONS, mnt_debug("%s: mountflags 0x%08lx", optstr, *flags)); return 0; } +/** + * mnt_optstr_get_mountflags: + * @optstr: string with comma separated list of options + * @flags: returns mount flags + * + * The mountflags are IDs from all MNT_MFLAG options from MNT_LINUX_MAP options + * map. See "struct mnt_optmap". For more details about mountflags see + * mount(2) syscall. + * + * For example: + * + * "bind,exec,foo,bar" --returns-> MS_BIND + * + * "bind,noexec,foo,bar" --returns-> MS_BIND|MS_NOEXEC + * + * Note that @flags are not zeroized by this function. + * + * Returns: 0 on success or negative number in case of error + */ +int mnt_optstr_get_mountflags(const char *optstr, unsigned long *flags) +{ + return mnt_optstr_get_flags(optstr, + mnt_get_builtin_optmap(MNT_LINUX_MAP), + flags, + MNT_MFLAG); +} + +/** + * mnt_optstr_get_userspace_mountflags: + * @optstr: string with comma separated list of options + * @flags: returns mount flags + * + * The mountflags are IDs from all MNT_USERSPACE_MAP options + * map. See "struct mnt_optmap". These flags are not used for mount(2) syscall. + * + * For example: + * + * "bind,exec,loop" --returns-> MNT_MS_LOOP + * + * Note that @flags are not zeroized by this function. + * + * Returns: 0 on success or negative number in case of error + */ +int mnt_optstr_get_userspace_mountflags(const char *optstr, unsigned long *flags) +{ + return mnt_optstr_get_flags(optstr, + mnt_get_builtin_optmap(MNT_USERSPACE_MAP), + flags, + 0); +} + #ifdef TEST_PROGRAM int test_append(struct mtest *ts, int argc, char *argv[]) @@ -555,6 +586,32 @@ int test_split(struct mtest *ts, int argc, char *argv[]) return rc; } +int test_flags(struct mtest *ts, int argc, char *argv[]) +{ + char *optstr; + int rc; + unsigned long fl = 0; + + if (argc < 2) + return -EINVAL; + + optstr = strdup(argv[1]); + + rc = mnt_optstr_get_mountflags(optstr, &fl); + if (rc) + return rc; + printf("mountflags: 0x%08lx\n", fl); + + fl = 0; + rc = mnt_optstr_get_userspace_mountflags(optstr, &fl); + if (rc) + return rc; + printf("userspace-mountflags: 0x%08lx\n", fl); + + free(optstr); + return rc; +} + int test_set(struct mtest *ts, int argc, char *argv[]) { const char *value = NULL, *name; @@ -631,6 +688,7 @@ int main(int argc, char *argv[]) { "--get", test_get, " search name in optstr" }, { "--remove", test_remove, " remove name in optstr" }, { "--split", test_split, " split into FS, VFS and userspace" }, + { "--flags", test_flags, " convert options to MS_* flags" }, { NULL } }; return mnt_run_test(tss, argc, argv); -- 2.39.5