From 61c5d308d97dec46f856085b0cd07dfbd5c76a16 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Fri, 5 Jul 2013 17:13:28 +0200 Subject: mount: implement -O, --test-opts --test-opts in combination with --all mounts only those filesystems with options matching the given set of options. Note that the semantic of the inverting "no" prefix differs from --types: While --types=nonfs,ufs means neither nfs nor ufs, --test-opts=nofoo,bar means not foo, but bar. * utils/match-options.h: New file. * utils/match-options.c: Likewise. (test_opts): New variable. (test_opts_len): Likewise. (match_options): New function. * utils/mount.c (parse_opt): Handle -O, --test-opts. (main): Use match_options as filter. --- utils/mount.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'utils/mount.c') diff --git a/utils/mount.c b/utils/mount.c index f8928f1c..73a75391 100644 --- a/utils/mount.c +++ b/utils/mount.c @@ -29,6 +29,8 @@ #include #include +#include "match-options.h" + #define SEARCH_FMTS _HURD "%sfs\0" _HURD "%s" #define DEFAULT_FSTYPE "ext2" @@ -57,6 +59,8 @@ static const struct argp_option argp_opts[] = {"remount", 0, 0, OPTION_ALIAS}, {"verbose", 'v', 0, 0, "Give more detailed information"}, {"no-mtab", 'n', 0, 0, "Do not update /etc/mtab"}, + {"test-opts", 'O', "OPTIONS", 0, + "Only mount fstab entries matching the given set of options"}, {"fake", 'f', 0, 0, "Do not actually mount, just pretend"}, {0, 0} }; @@ -122,6 +126,12 @@ parse_opt (int key, char *arg, struct argp_state *state) fake = 1; break; + case 'O': + err = argz_create_sep (arg, ',', &test_opts, &test_opts_len); + if (err) + argp_failure (state, 100, ENOMEM, "%s", arg); + break; + case ARGP_KEY_ARG: if (mountpoint == 0) /* One arg: mountpoint */ mountpoint = arg; @@ -615,8 +625,13 @@ main (int argc, char **argv) case mount: for (fs = fstab->entries; fs; fs = fs->next) { - if (fstab_params.do_all && hasmntopt (&fs->mntent, MNTOPT_NOAUTO)) - continue; + if (fstab_params.do_all) { + if (hasmntopt (&fs->mntent, MNTOPT_NOAUTO)) + continue; + + if (! match_options (&fs->mntent)) + continue; + } err |= do_mount (fs, remount); } break; -- cgit v1.2.3