diff options
author | Karel Zak | 2016-12-20 16:01:22 +0100 |
---|---|---|
committer | Karel Zak | 2016-12-20 16:01:22 +0100 |
commit | 7d395c75d1b7df677c26ef20628698247e3f216e (patch) | |
tree | 79221ac09fcc1866d3e761bd689af1e010dbe007 /libmount/src/optstr.c | |
parent | libmount: reimplement mnt_match_options() (diff) | |
download | kernel-qcow2-util-linux-7d395c75d1b7df677c26ef20628698247e3f216e.tar.gz kernel-qcow2-util-linux-7d395c75d1b7df677c26ef20628698247e3f216e.tar.xz kernel-qcow2-util-linux-7d395c75d1b7df677c26ef20628698247e3f216e.zip |
libmount: support name=value for mnt_match_options()
$ findmnt --options mode=755
TARGET SOURCE FSTYPE OPTIONS
/sys/fs/cgroup tmpfs tmpfs rw,nosuid,nodev,noexec,relatime,mode=755
/dev udev devtmpfs rw,relatime,size=1983516k,nr_inodes=495879,mode=755
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/optstr.c')
-rw-r--r-- | libmount/src/optstr.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c index 2aa6e8ccb..4b9622ed5 100644 --- a/libmount/src/optstr.c +++ b/libmount/src/optstr.c @@ -1113,8 +1113,8 @@ int mnt_optstr_fix_user(char **optstr) int mnt_match_options(const char *optstr, const char *pattern) { char *name, *pat = (char *) pattern; - char *buf; - size_t namesz = 0, valsz = 0; + char *buf, *patval; + size_t namesz = 0, patvalsz = 0; int match = 1; if (!pattern && !optstr) @@ -1128,10 +1128,11 @@ int mnt_match_options(const char *optstr, const char *pattern) /* walk on pattern string */ - while (match && !mnt_optstr_next_option(&pat, &name, &namesz, NULL, &valsz)) { + while (match && !mnt_optstr_next_option(&pat, &name, &namesz, + &patval, &patvalsz)) { char *val; size_t sz; - int no = 0; + int no = 0, rc; if (*name == '+') name++, namesz--; @@ -1140,7 +1141,14 @@ int mnt_match_options(const char *optstr, const char *pattern) xstrncpy(buf, name, namesz + 1); - switch (mnt_optstr_get_option(optstr, buf, &val, &sz)) { + rc = mnt_optstr_get_option(optstr, buf, &val, &sz); + + /* check also value (if the pattern is "foo=value") */ + if (rc == 0 && patvalsz > 0 && + (patvalsz != sz || strncmp(patval, val, sz) != 0)) + rc = 1; + + switch (rc) { case 0: /* found */ match = no == 0 ? 1 : 0; break; |