summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2010-08-05 12:24:59 +0200
committerKarel Zak2011-01-03 12:28:40 +0100
commit922d87965c6371986863dae18e001f8e22731651 (patch)
tree6b6ae610574abc8ef648bff62dcd24a598bfb0cd
parentlibmount: improve mnt_get_fs_root() and mnt_get_mountpoint() (diff)
downloadkernel-qcow2-util-linux-922d87965c6371986863dae18e001f8e22731651.tar.gz
kernel-qcow2-util-linux-922d87965c6371986863dae18e001f8e22731651.tar.xz
kernel-qcow2-util-linux-922d87965c6371986863dae18e001f8e22731651.zip
libmount: add mnt_optstr_get_mountflags()
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--shlibs/mount/src/mount.h.in23
-rw-r--r--shlibs/mount/src/mount.sym1
-rw-r--r--shlibs/mount/src/optstr.c50
3 files changed, 74 insertions, 0 deletions
diff --git a/shlibs/mount/src/mount.h.in b/shlibs/mount/src/mount.h.in
index 6a1cd19be..a1944c543 100644
--- a/shlibs/mount/src/mount.h.in
+++ b/shlibs/mount/src/mount.h.in
@@ -102,6 +102,27 @@ typedef struct _mnt_fs mnt_fs;
*/
typedef struct _mnt_tab mnt_tab;
+/**
+ * mnt_mtab
+ *
+ * /etc/mtab or /var/run/mountinfo update description
+ */
+typedef struct _mnt_mtab mnt_mtab;
+
+/*
+ * Tab file format
+ */
+enum {
+ MNT_FMT_FSTAB = 1, /* /etc/{fs,m}tab */
+ MNT_FMT_MTAB = MNT_FMT_FSTAB, /* alias */
+ MNT_FMT_MOUNTINFO /* /proc/#/mountinfo */
+};
+
+enum {
+ MNT_ACT_MOUNT = 1,
+ MNT_ACT_UMOUNT
+};
+
/* init.c */
extern void mnt_init_debug(int mask);
@@ -150,6 +171,8 @@ extern int mnt_split_optstr(const char *optstr,
char **user, char **vfs, char **fs,
int ifnore_user, int ignore_vfs);
+extern int mnt_optstr_get_mountflags(const char *optstr);
+
/* iter.c */
enum {
diff --git a/shlibs/mount/src/mount.sym b/shlibs/mount/src/mount.sym
index d37bb8b12..cf0f7753b 100644
--- a/shlibs/mount/src/mount.sym
+++ b/shlibs/mount/src/mount.sym
@@ -103,6 +103,7 @@ global:
mnt_optls_remove_option_by_flags;
mnt_optls_remove_option_by_iflags;
mnt_optstr_append_option;
+ mnt_optstr_get_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 f17bd7d3a..c209784d7 100644
--- a/shlibs/mount/src/optstr.c
+++ b/shlibs/mount/src/optstr.c
@@ -406,6 +406,56 @@ 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
+ *
+ * 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
+ *
+ * Returns: mount flags or 0.
+ */
+int mnt_optstr_get_mountflags(const char *optstr)
+{
+ int flags = 0;
+ struct mnt_optmap const *maps[1];
+ char *name, *str = (char *) optstr;
+ size_t namesz = 0;
+
+ assert(optstr);
+
+ if (!optstr)
+ return -1;
+
+ maps[0] = mnt_get_builtin_optmap(MNT_LINUX_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))
+ continue;
+ if (ent->mask & MNT_INVERT)
+ flags &= ~ent->id;
+ else
+ flags |= ent->id;
+ }
+ }
+
+ DBG(DEBUG_OPTIONS, fprintf(stderr,
+ "libmount: optstr '%s': mountflags 0x%08x", optstr, flags));
+ return flags;
+}
+
#ifdef TEST_PROGRAM
int test_append(struct mtest *ts, int argc, char *argv[])