Jan-Simon Pendry's and my new mount code
[unix-history] / usr / src / sbin / newfs / newfs.c
index bd82a34..6b44f0f 100644 (file)
@@ -1,17 +1,17 @@
 /*
 /*
- * Copyright (c) 1983, 1989, 1993
+ * Copyright (c) 1983, 1989, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * %sccs.include.redist.c%
  */
 
 #ifndef lint
  *     The Regents of the University of California.  All rights reserved.
  *
  * %sccs.include.redist.c%
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)newfs.c    8.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)newfs.c    8.6 (Berkeley) %G%";
 #endif /* not lint */
 
 #ifndef lint
 static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 static char copyright[] =
-"@(#) Copyright (c) 1983, 1989, 1993\n\
+"@(#) Copyright (c) 1983, 1989, 1993, 1994\n\
        The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
        The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
@@ -24,22 +24,31 @@ static char copyright[] =
 #include <sys/disklabel.h>
 #include <sys/file.h>
 #include <sys/mount.h>
 #include <sys/disklabel.h>
 #include <sys/file.h>
 #include <sys/mount.h>
+
 #include <ufs/ufs/dir.h>
 #include <ufs/ffs/fs.h>
 
 #include <ufs/ufs/dir.h>
 #include <ufs/ffs/fs.h>
 
+#include <ctype.h>
 #include <errno.h>
 #include <errno.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <unistd.h>
+
 #if __STDC__
 #include <stdarg.h>
 #else
 #include <varargs.h>
 #endif
 #if __STDC__
 #include <stdarg.h>
 #else
 #include <varargs.h>
 #endif
-#include <unistd.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
-#include <syslog.h>
-#include <paths.h>
+
+#include "mntopts.h"
+
+struct mntopt mopts[] = {
+       MOPT_STDOPTS,
+       { NULL },
+};
 
 #if __STDC__
 void   fatal(const char *fmt, ...);
 
 #if __STDC__
 void   fatal(const char *fmt, ...);
@@ -155,6 +164,7 @@ int unlabeled;
 char   device[MAXPATHLEN];
 char   *progname;
 
 char   device[MAXPATHLEN];
 char   *progname;
 
+int
 main(argc, argv)
        int argc;
        char *argv[];
 main(argc, argv)
        int argc;
        char *argv[];
@@ -167,11 +177,9 @@ main(argc, argv)
        struct disklabel *getdisklabel();
        struct partition oldpartition;
        struct stat st;
        struct disklabel *getdisklabel();
        struct partition oldpartition;
        struct stat st;
-       int fsi, fso;
-       char *cp, *special, *opstring, buf[BUFSIZ];
        struct statfs *mp;
        struct statfs *mp;
-       char *s1, *s2;
-       int len, n;
+       int fsi, fso, len, n;
+       char *cp, *s1, *s2, *special, *opstring, buf[BUFSIZ];
 
        if (progname = rindex(*argv, '/'))
                ++progname;
 
        if (progname = rindex(*argv, '/'))
                ++progname;
@@ -183,21 +191,16 @@ main(argc, argv)
                Nflag++;
        }
 
                Nflag++;
        }
 
-       opstring = "F:NOS:T:a:b:c:d:e:f:i:k:l:m:n:o:p:r:s:t:u:x:";
-       if (!mfs)
-               opstring += 2;          /* -F is mfs only */
-
+       opstring = mfs ?
+           "Na:b:c:d:e:f:i:m:o:s:" :
+           "NOS:T:a:b:c:d:e:f:i:k:l:m:n:o:p:r:s:t:u:x:";
        while ((ch = getopt(argc, argv, opstring)) != EOF)
        while ((ch = getopt(argc, argv, opstring)) != EOF)
-               switch(ch) {
-               case 'F':
-                       if ((mntflags = atoi(optarg)) == 0)
-                               fatal("%s: bad mount flags", optarg);
-                       break;
+               switch (ch) {
                case 'N':
                case 'N':
-                       Nflag++;
+                       Nflag = 1;
                        break;
                case 'O':
                        break;
                case 'O':
-                       Oflag++;
+                       Oflag = 1;
                        break;
                case 'S':
                        if ((sectorsize = atoi(optarg)) <= 0)
                        break;
                case 'S':
                        if ((sectorsize = atoi(optarg)) <= 0)
@@ -210,7 +213,7 @@ main(argc, argv)
 #endif
                case 'a':
                        if ((maxcontig = atoi(optarg)) <= 0)
 #endif
                case 'a':
                        if ((maxcontig = atoi(optarg)) <= 0)
-                               fatal("%s: bad max contiguous blocks\n",
+                               fatal("%s: bad maximum contiguous blocks\n",
                                    optarg);
                        break;
                case 'b':
                                    optarg);
                        break;
                case 'b':
@@ -228,12 +231,12 @@ main(argc, argv)
                        break;
                case 'e':
                        if ((maxbpg = atoi(optarg)) <= 0)
                        break;
                case 'e':
                        if ((maxbpg = atoi(optarg)) <= 0)
-                               fatal("%s: bad blocks per file in a cyl group\n",
+               fatal("%s: bad blocks per file in a cylinder group\n",
                                    optarg);
                        break;
                case 'f':
                        if ((fsize = atoi(optarg)) <= 0)
                                    optarg);
                        break;
                case 'f':
                        if ((fsize = atoi(optarg)) <= 0)
-                               fatal("%s: bad frag size", optarg);
+                               fatal("%s: bad fragment size", optarg);
                        break;
                case 'i':
                        if ((density = atoi(optarg)) <= 0)
                        break;
                case 'i':
                        if ((density = atoi(optarg)) <= 0)
@@ -257,13 +260,16 @@ main(argc, argv)
                                    optarg);
                        break;
                case 'o':
                                    optarg);
                        break;
                case 'o':
-                       if (strcmp(optarg, "space") == 0)
-                               opt = FS_OPTSPACE;
-                       else if (strcmp(optarg, "time") == 0)
-                               opt = FS_OPTTIME;
-                       else
-                               fatal("%s: bad optimization preference %s",
-                                   optarg, "(options are `space' or `time')");
+                       if (mfs)
+                               getmntopts(optarg, mopts, &mntflags);
+                       else {
+                               if (strcmp(optarg, "space") == 0)
+                                       opt = FS_OPTSPACE;
+                               else if (strcmp(optarg, "time") == 0)
+                                       opt = FS_OPTTIME;
+                               else
+       fatal("%s: unknown optimization preference: use `space' or `time'.");
+                       }
                        break;
                case 'p':
                        if ((trackspares = atoi(optarg)) < 0)
                        break;
                case 'p':
                        if ((trackspares = atoi(optarg)) < 0)
@@ -272,7 +278,7 @@ main(argc, argv)
                        break;
                case 'r':
                        if ((rpm = atoi(optarg)) <= 0)
                        break;
                case 'r':
                        if ((rpm = atoi(optarg)) <= 0)
-                               fatal("%s: bad revs/minute\n", optarg);
+                               fatal("%s: bad revolutions/minute\n", optarg);
                        break;
                case 's':
                        if ((fssize = atoi(optarg)) <= 0)
                        break;
                case 's':
                        if ((fssize = atoi(optarg)) <= 0)