summaryrefslogtreecommitdiffstats
path: root/sbin/mount
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2006-10-24 22:02:29 +0000
committerru <ru@FreeBSD.org>2006-10-24 22:02:29 +0000
commitf5d15b9ea0fd7d28cc86f95efbb4c1d0b1c7a7a1 (patch)
tree3dcecf192cd9935e04b4814eb8d7bbd9a2f56d71 /sbin/mount
parent8e246ecb792dfd0d20a146431f4455a7dcf6348c (diff)
downloadFreeBSD-src-f5d15b9ea0fd7d28cc86f95efbb4c1d0b1c7a7a1.zip
FreeBSD-src-f5d15b9ea0fd7d28cc86f95efbb4c1d0b1c7a7a1.tar.gz
Revert rev. 1.86 by jmallett@ as it breaks "ro" mounts specified
in /etc/fstab. This has been happening due to the priority inversion; options specified on the command line should take precedence over options from fstab over default "noro" option, but since both the default "noro" and options specified on the command line (-w, -r, -o ...) were put into the same "options" variable, "noro" took precedence over fstab "ro" (this is easily visible with "mount -d"). PR: bin/100164
Diffstat (limited to 'sbin/mount')
-rw-r--r--sbin/mount/mount.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c
index 3d25b7b..a51e171 100644
--- a/sbin/mount/mount.c
+++ b/sbin/mount/mount.c
@@ -183,6 +183,26 @@ exec_mountprog(const char *name, const char *execname, char *const argv[])
return (0);
}
+static
+int specified_ro(const char *arg)
+{
+ char *optbuf, *opt;
+ int ret = 0;
+
+ optbuf = strdup(arg);
+ if (optbuf == NULL)
+ err(1, NULL);
+
+ for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
+ if (strcmp(opt, "ro") == 0) {
+ ret = 1;
+ break;
+ }
+ }
+ free(optbuf);
+ return (ret);
+}
+
int
main(int argc, char *argv[])
{
@@ -191,14 +211,12 @@ main(int argc, char *argv[])
struct statfs *mntbuf;
FILE *mountdfp;
pid_t pid;
- int all, ch, i, init_flags, late, mntsize, rval, have_fstab;
+ int all, ch, i, init_flags, late, mntsize, rval, have_fstab, ro;
char *cp, *ep, *options;
- options = strdup("noro");
- if (options == NULL)
- errx(1, "malloc failed");
-
all = init_flags = late = 0;
+ ro = 0;
+ options = NULL;
vfslist = NULL;
vfstype = "ufs";
while ((ch = getopt(argc, argv, "adlF:fo:prwt:uv")) != -1)
@@ -219,7 +237,11 @@ main(int argc, char *argv[])
late = 1;
break;
case 'o':
- options = catopt(options, optarg);
+ if (*optarg) {
+ options = catopt(options, optarg);
+ if (specified_ro(optarg))
+ ro = 1;
+ }
break;
case 'p':
fstab_style = 1;
@@ -227,6 +249,7 @@ main(int argc, char *argv[])
break;
case 'r':
options = catopt(options, "ro");
+ ro = 1;
break;
case 't':
if (vfslist != NULL)
@@ -255,6 +278,9 @@ main(int argc, char *argv[])
(strcmp(type, FSTAB_RO) && \
strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
+ if ((init_flags & MNT_UPDATE) && (ro == 0))
+ options = catopt(options, "noro");
+
rval = 0;
switch (argc) {
case 0:
OpenPOWER on IntegriCloud