diff options
author | Karel Zak | 2010-12-22 13:15:04 +0100 |
---|---|---|
committer | Karel Zak | 2011-01-03 12:28:48 +0100 |
commit | f84fa6f7b98dd00ef6f196815b18590ca50c3528 (patch) | |
tree | 6b7c7f0a084ea242240c2fb0d9980e954ae24fcc /shlibs/mount/src/optstr.c | |
parent | tests: check for mtab (diff) | |
download | kernel-qcow2-util-linux-f84fa6f7b98dd00ef6f196815b18590ca50c3528.tar.gz kernel-qcow2-util-linux-f84fa6f7b98dd00ef6f196815b18590ca50c3528.tar.xz kernel-qcow2-util-linux-f84fa6f7b98dd00ef6f196815b18590ca50c3528.zip |
libmount: better work with mtab options
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/mount/src/optstr.c')
-rw-r--r-- | shlibs/mount/src/optstr.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/shlibs/mount/src/optstr.c b/shlibs/mount/src/optstr.c index 62c5701dd..7c41f6857 100644 --- a/shlibs/mount/src/optstr.c +++ b/shlibs/mount/src/optstr.c @@ -147,7 +147,6 @@ static int mnt_optstr_locate_option(char *optstr, const char *name, } } while(1); - DBG(OPTIONS, mnt_debug("can't found '%s' option", name)); return rc; } @@ -514,6 +513,59 @@ int mnt_split_optstr(const char *optstr, char **user, char **vfs, char **fs, } /** + * mnt_optstr_get_options + * @optstr: string with comma separated list of options + * @subset: returns newly allocated string with options + * @map: options map + * @ignore: mask of the options that should be ignored + * + * Extracts options from @optstr that belongs to the @map, for example: + * + * mnt_split_optstr_by_map(optstr, &p, + * mnt_get_builtin_optmap(MNT_LINUX_MAP), + * MNT_NOMTAB); + * + * returns all VFS options, the options that does not belong to mtab + * are ignored. + * + * Returns: 0 on success, or negative number in case of error. + */ +int mnt_optstr_get_options(const char *optstr, char **subset, + const struct mnt_optmap *map, int ignore) +{ + struct mnt_optmap const *maps[1]; + char *name, *val, *str = (char *) optstr; + size_t namesz, valsz; + + if (!optstr || !subset) + return -EINVAL; + + maps[0] = map; + *subset = NULL; + + while(!mnt_optstr_next_option(&str, &name, &namesz, &val, &valsz)) { + int rc = 0; + const struct mnt_optmap *ent; + + mnt_optmap_get_entry(maps, 1, name, namesz, &ent); + + if (!ent || !ent->id) + continue; /* ignore undefined options (comments) */ + + if (ignore && (ent->mask & ignore)) + continue; + rc = __mnt_optstr_append_option(subset, name, namesz, val, valsz); + if (rc) { + free(*subset); + return rc; + } + } + + return 0; +} + + +/** * mnt_optstr_get_flags: * @optstr: string with comma separated list of options * @flags: returns mount flags |