summaryrefslogtreecommitdiffstats
path: root/shlibs/mount/src/optstr.c
diff options
context:
space:
mode:
authorKarel Zak2010-09-15 16:55:47 +0200
committerKarel Zak2011-01-03 12:28:42 +0100
commit2b5cceb5c799794121bfab1a7652ea06b164cb3e (patch)
tree39bb80ecf7945bcea456b40511ee0de9ade76ab4 /shlibs/mount/src/optstr.c
parentlibmount: add MNT_FS_SWAP flag (diff)
downloadkernel-qcow2-util-linux-2b5cceb5c799794121bfab1a7652ea06b164cb3e.tar.gz
kernel-qcow2-util-linux-2b5cceb5c799794121bfab1a7652ea06b164cb3e.tar.xz
kernel-qcow2-util-linux-2b5cceb5c799794121bfab1a7652ea06b164cb3e.zip
libmount: add mnt_optstr_get_userspace_mountflags()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/mount/src/optstr.c')
-rw-r--r--shlibs/mount/src/optstr.c108
1 files changed, 83 insertions, 25 deletions
diff --git a/shlibs/mount/src/optstr.c b/shlibs/mount/src/optstr.c
index b809386aa..c35777f2d 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);