Date: Wed, 5 May 1999 14:00:02 -0700 (PDT) From: David Malone <dwmalone@maths.tcd.ie> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/6399: [PATCH] When using "-u" mount doesn't start from the fstab options Message-ID: <199905052100.OAA78207@freefall.freebsd.org>
index | next in thread | raw e-mail
The following reply was made to PR bin/6399; it has been noted by GNATS.
From: David Malone <dwmalone@maths.tcd.ie>
To: jkoshy@freebsd.org
Cc: Freebsd-gnats-submit@freebsd.org
Subject: Re: bin/6399: [PATCH] When using "-u" mount doesn't start from the fstab options
Date: Wed, 05 May 1999 21:51:53 +0100
I've fixed the dereferencing a NULL pointer if the filesystem isn't in fstab,
fixed a missing return, made the style more like the surounding style and added
two comments. Is it suitable for committing yet?
David.
--- mount.c.orig Wed May 5 12:42:51 1999
+++ mount.c Wed May 5 14:02:40 1999
@@ -72,11 +72,14 @@
int ismounted __P((struct fstab *, struct statfs *, int));
int isremountable __P((const char *));
void mangle __P((char *, int *, const char **));
+char *update_options __P((char *, char *, int));
int mountfs __P((const char *, const char *, const char *,
int, const char *, const char *));
+void remopt __P((char *, const char *));
void prmount __P((struct statfs *));
void putfsent __P((const struct statfs *));
void usage __P((void));
+char *flags2opts __P((int));
/* Map from mount options to printable formats. */
static struct opt {
@@ -224,10 +227,15 @@
errx(1,
"unknown special file or file system %s",
*argv);
- if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL)
+ if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL) {
mntfromname = fs->fs_spec;
- else
+ options = update_options(options, fs->fs_mntops,
+ mntbuf->f_flags);
+ } else {
mntfromname = mntbuf->f_mntfromname;
+ options = update_options(options, NULL,
+ mntbuf->f_flags);
+ }
rval = mountfs(mntbuf->f_fstypename, mntfromname,
mntbuf->f_mntonname, init_flags, options, 0);
break;
@@ -524,6 +532,9 @@
size_t i;
char *cp;
+ if (s1 == NULL || *s1 == '\0')
+ return s0;
+
if (s0 && *s0) {
i = strlen(s0) + strlen(s1) + 1 + 1;
if ((cp = malloc(i)) == NULL)
@@ -564,6 +575,90 @@
*argcp = argc;
}
+
+char *
+update_options(opts, fstab, curflags)
+ char *opts;
+ char *fstab;
+ int curflags;
+{
+ char *o, *p;
+ char *cur;
+ char *expopt, *newopt, *tmpopt;
+
+ if (opts == NULL)
+ return strdup("");
+
+ fstab = strdup(fstab);
+ remopt(fstab, "fstab");
+ remopt(fstab, "cur");
+ cur = flags2opts(curflags);
+
+ /*
+ * Expand all "cur" and "fstab" options passed to us first.
+ */
+ expopt = NULL;
+ for (p = opts; (o = strsep(&p, ",")) != NULL;) {
+ if (strcmp("fstab", o) == 0)
+ expopt = catopt(expopt, fstab);
+ else if (strcmp("cur", o) == 0)
+ expopt = catopt(expopt, cur);
+ else
+ expopt = catopt(expopt, o);
+ }
+ free(fstab);
+ free(cur);
+ free(opts);
+
+ /*
+ * Remove previous contradictory arguments. Given option "foo" we
+ * remove all the "nofoo" options. Given "nofoo" we remove "nonofoo"
+ * and "foo" - so we can deal with possible options like "notice".
+ */
+ newopt = NULL;
+ for (p = expopt; (o = strsep(&p, ",")) != NULL;) {
+ if ((tmpopt = malloc( strlen(o) + 2 + 1 )) == NULL)
+ errx(1, "malloc failed");
+
+ strcpy(tmpopt, "no");
+ strcat(tmpopt, o);
+ remopt(newopt, tmpopt);
+ free(tmpopt);
+
+ if (strncmp("no", o, 2) == 0)
+ remopt(newopt, o+2);
+
+ newopt = catopt(newopt, o);
+ }
+ free(expopt);
+
+ return newopt;
+}
+
+void
+remopt(string, opt)
+ char *string;
+ const char *opt;
+{
+ char *o, *p, *r;
+
+ if (string == NULL || *string == '\0' || opt == NULL || *opt == '\0')
+ return;
+
+ r = string;
+
+ for (p = string; (o = strsep(&p, ",")) != NULL;) {
+ if (strcmp(opt, o) != 0) {
+ if (*r == ',' && *o != '\0')
+ r++;
+ while ((*r++ = *o++) != '\0')
+ ;
+ *--r = ',';
+ }
+ }
+ *r = '\0';
+}
+
void
usage()
{
@@ -580,33 +675,12 @@
const struct statfs *ent;
{
struct fstab *fst;
-
+ char *opts;
+
+ opts = flags2opts(ent->f_flags);
printf("%s\t%s\t%s %s", ent->f_mntfromname, ent->f_mntonname,
- ent->f_fstypename, (ent->f_flags & MNT_RDONLY) ? "ro" : "rw");
-
- /* XXX should use optnames[] - put shorter names in it. */
- if (ent->f_flags & MNT_SYNCHRONOUS)
- printf(",sync");
- if (ent->f_flags & MNT_NOEXEC)
- printf(",noexec");
- if (ent->f_flags & MNT_NOSUID)
- printf(",nosuid");
- if (ent->f_flags & MNT_NODEV)
- printf(",nodev");
- if (ent->f_flags & MNT_UNION)
- printf(",union");
- if (ent->f_flags & MNT_ASYNC)
- printf(",async");
- if (ent->f_flags & MNT_NOATIME)
- printf(",noatime");
- if (ent->f_flags & MNT_NOCLUSTERR)
- printf(",noclusterr");
- if (ent->f_flags & MNT_NOCLUSTERW)
- printf(",noclusterw");
- if (ent->f_flags & MNT_NOSYMFOLLOW)
- printf (",nosymfollow");
- if (ent->f_flags & MNT_SUIDDIR)
- printf(",suiddir");
+ ent->f_fstypename, opts);
+ free(opts);
if ((fst = getfsspec(ent->f_mntfromname)))
printf("\t%u %u\n", fst->fs_freq, fst->fs_passno);
@@ -616,4 +690,30 @@
printf("\t1 1\n");
else
printf("\t0 0\n");
+}
+
+
+char *
+flags2opts(flags)
+ int flags;
+{
+ char *res;
+
+ res = NULL;
+
+ res = catopt(res, (flags & MNT_RDONLY) ? "ro" : "rw");
+
+ if (flags & MNT_SYNCHRONOUS) res = catopt(res, "sync");
+ if (flags & MNT_NOEXEC) res = catopt(res, "noexec");
+ if (flags & MNT_NOSUID) res = catopt(res, "nosuid");
+ if (flags & MNT_NODEV) res = catopt(res, "nodev");
+ if (flags & MNT_UNION) res = catopt(res, "union");
+ if (flags & MNT_ASYNC) res = catopt(res, "async");
+ if (flags & MNT_NOATIME) res = catopt(res, "noatime");
+ if (flags & MNT_NOCLUSTERR) res = catopt(res, "noclusterr");
+ if (flags & MNT_NOCLUSTERW) res = catopt(res, "noclusterw");
+ if (flags & MNT_NOSYMFOLLOW) res = catopt(res, "nosymfollow");
+ if (flags & MNT_SUIDDIR) res = catopt(res, "suiddir");
+
+ return res;
}
--- mount.8.orig Wed May 5 12:42:51 1999
+++ mount.8 Wed May 5 12:43:01 1999
@@ -112,12 +112,25 @@
flag to set,
and should not be used unless you are prepared to recreate the file
system should your system crash.
+.It cur
+When using the
+.Fl u
+flag this is the same as giving the options currently in effect. To
+see what these options are you can use the
+.Fl p
+flag.
.It force
The same as
.Fl f ;
forces the revocation of write access when trying to downgrade
a filesystem mount status from read-write to read-only. Also
forces the R/W mount of an unclean filesystem (dangerous; use with caution).
+.It fstab
+When using the
+.Fl u
+this is the same as giving all the options listed in the
+.Xr fstab 5
+file for the filesystem.
.It noatime
Do not update the file access time when reading from a file. This option
is useful on filesystems where there are large numbers of files and
@@ -287,13 +300,10 @@
files on the filesystem are currently open for writing unless the
.Fl f
flag is also specified.
-The set of options is determined by first extracting the options
-for the file system from the
-.Xr fstab 5
-table,
-then applying any options specified by the
-.Fl o
+The set of options is determined by
+applying any options specified by the
argument,
+.Fl o
and finally applying the
.Fl r
or
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199905052100.OAA78207>
