1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
--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/Makefile | 5 ++--
utils/match-options.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
utils/match-options.h | 33 ++++++++++++++++++++++++
utils/mount.c | 19 ++++++++++++--
4 files changed, 121 insertions(+), 4 deletions(-)
create mode 100644 utils/match-options.c
create mode 100644 utils/match-options.h
diff --git a/utils/Makefile b/utils/Makefile
index e3bed0b..6975fb5 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -28,7 +28,8 @@ SRCS = shd.c ps.c settrans.c syncfs.c showtrans.c addauth.c rmauth.c \
uptime.sh psout.c ids.c vmstat.c portinfo.c devprobe.c vminfo.c \
parse.c frobauth.c frobauth-mod.c setauth.c pids.c nonsugid.c \
unsu.c ftpcp.c ftpdir.c storeread.c storecat.c msgport.c \
- rpctrace.c mount.c gcore.c fakeauth.c fakeroot.sh remap.sh
+ rpctrace.c mount.c gcore.c fakeauth.c fakeroot.sh remap.sh \
+ match-options.c
OBJS = $(filter-out %.sh,$(SRCS:.c=.o))
HURDLIBS = ps ihash store fshelp ports ftpconn shouldbeinlibc
@@ -72,7 +73,7 @@ fakeauth-CPPFLAGS = -I$(srcdir)/../auth
authServer-CPPFLAGS = -I$(srcdir)/../auth
auth_requestUser-CPPFLAGS = -I$(srcdir)/../auth
-mount: ../sutils/fstab.o ../sutils/clookup.o \
+mount: ../sutils/fstab.o ../sutils/clookup.o match-options.o \
$(foreach L,fshelp ports,../lib$L/lib$L.a)
../sutils/fstab.o ../sutils/clookup.o: FORCE
$(MAKE) -C $(@D) $(@F)
diff --git a/utils/match-options.c b/utils/match-options.c
new file mode 100644
index 0000000..11fc9dc
--- /dev/null
+++ b/utils/match-options.c
@@ -0,0 +1,68 @@
+/* Common functionality for the --test-opts flag of mount and umount.
+
+ Copyright (C) 2013 Free Software Foundation, Inc.
+ Written by Justus Winter <4winter@informatik.uni-hamburg.de>
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <argz.h>
+#include <error.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "match-options.h"
+
+char *test_opts;
+size_t test_opts_len;
+
+int
+match_options (struct mntent *mntent)
+{
+ char *opts;
+ size_t opts_len;
+
+ error_t err = argz_create_sep (mntent->mnt_opts, ',', &opts, &opts_len);
+ if (err)
+ error (3, err, "parsing mount options failed");
+
+ for (char *test = test_opts;
+ test; test = argz_next (test_opts, test_opts_len, test))
+ {
+ char *needle = test;
+ int inverse = strncmp("no", needle, 2) == 0;
+ if (inverse)
+ needle += 2;
+
+ int match = 0;
+ for (char *opt = opts; opt; opt = argz_next (opts, opts_len, opt))
+ {
+ if (strcmp (opt, needle) == 0) {
+ if (inverse)
+ return 0; /* foo in opts, nofoo in test_opts. */
+
+ /* foo in opts, foo in test_opts, record match. */
+ match = 1;
+ }
+ }
+
+ if (! inverse && ! match)
+ return 0; /* No foo in opts, but foo in test_opts. */
+ }
+
+ /* If no conflicting test_opt was encountered, return success. */
+ return 1;
+}
diff --git a/utils/match-options.h b/utils/match-options.h
new file mode 100644
index 0000000..ea7ae70
--- /dev/null
+++ b/utils/match-options.h
@@ -0,0 +1,33 @@
+/* Common functionality for the --test-opts flag of mount and umount.
+
+ Copyright (C) 2013 Free Software Foundation, Inc.
+ Written by Justus Winter <4winter@informatik.uni-hamburg.de>
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <mntent.h>
+
+extern char *test_opts;
+extern size_t test_opts_len;
+
+/* Check whether the given mount entry matches the given set of
+ options.
+
+ Returns 0 if foo is in the options vector but nofoo is in test_opts.
+ Returns 0 if foo is in test_opts but foo is not in the options vector. */
+int
+match_options (struct mntent *mntent);
diff --git a/utils/mount.c b/utils/mount.c
index f8928f1..73a7539 100644
--- a/utils/mount.c
+++ b/utils/mount.c
@@ -29,6 +29,8 @@
#include <hurd/fshelp.h>
#include <hurd/paths.h>
+#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;
--
1.7.10.4
|