diff options
Diffstat (limited to 'shlibs/mount/src/optstr.c')
-rw-r--r-- | shlibs/mount/src/optstr.c | 108 |
1 files changed, 83 insertions, 25 deletions
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, "<optstr> <name> search name in optstr" }, { "--remove", test_remove, "<optstr> <name> remove name in optstr" }, { "--split", test_split, "<optstr> split into FS, VFS and userspace" }, + { "--flags", test_flags, "<optstr> convert options to MS_* flags" }, { NULL } }; return mnt_run_test(tss, argc, argv); |