add -f and -v
authorBill Joy <root@ucbvax.Berkeley.EDU>
Sun, 4 Oct 1981 08:07:04 +0000 (00:07 -0800)
committerBill Joy <root@ucbvax.Berkeley.EDU>
Sun, 4 Oct 1981 08:07:04 +0000 (00:07 -0800)
SCCS-vsn: sbin/mount/mount.c 4.5

usr/src/sbin/mount/mount.c

index 8c3eac8..6b3c093 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)mount.c     4.4 (Berkeley) %G%";
+static char *sccsid = "@(#)mount.c     4.5 (Berkeley) %G%";
 #include <stdio.h>
 #include <fstab.h>
 
 #include <stdio.h>
 #include <fstab.h>
 
@@ -6,7 +6,6 @@ static char *sccsid = "@(#)mount.c      4.4 (Berkeley) %G%";
  * mount
  */
 
  * mount
  */
 
-int    mountall;
 #define        NMOUNT  16
 #define        NAMSIZ  32
 
 #define        NMOUNT  16
 #define        NAMSIZ  32
 
@@ -15,8 +14,10 @@ struct mtab {
        char    spec[NAMSIZ];
 } mtab[NMOUNT];
 
        char    spec[NAMSIZ];
 } mtab[NMOUNT];
 
+int    all;
 int    ro;
 int    fake;
 int    ro;
 int    fake;
+int    verbose;
 main(argc, argv)
 char **argv;
 {
 main(argc, argv)
 char **argv;
 {
@@ -24,7 +25,6 @@ char **argv;
        register char *np;
        int mf;
 
        register char *np;
        int mf;
 
-       mountall = 0;
        mf = open("/etc/mtab", 0);
        read(mf, (char *)mtab, NMOUNT*2*NAMSIZ);
        if (argc==1) {
        mf = open("/etc/mtab", 0);
        read(mf, (char *)mtab, NMOUNT*2*NAMSIZ);
        if (argc==1) {
@@ -33,107 +33,98 @@ char **argv;
                                printf("%s on %s\n", mp->spec, mp->file);
                exit(0);
        }
                                printf("%s on %s\n", mp->spec, mp->file);
                exit(0);
        }
-
-       if (argc == 2){
-               if (strcmp(argv[1], "-a") == 0)
-                       mountall++;
-               else {
-                       fprintf(stdout,"arg count\n");
-                       exit(1);
+top:
+       if (argc > 1) {
+               if (strcmp(argv[1], "-a") == 0) {
+                       all++;
+                       argc--, argv++;
+                       goto top;
                }
                }
-       }
-       if (!strcmp(argv[1], "-f"))
-               fake++, argc--, argv++;
-
-       if (!mountall){
-               ro = 0;
-               if(argc > 3)
-                       ro++;
-               if (mountfs(argv[1], argv[2], ro)){
-                       perror("mount");
-                       exit(1);
+               if (!strcmp(argv[1], "-f")) {
+                       fake++;
+                       argc--, argv++;
+                       goto top;
                }
                }
-       } else {
+               if (!strcmp(argv[1], "-v")) {
+                       verbose++;
+                       argc--, argv++;
+                       goto top;
+               }
+       }
+       if (all) {
                struct  fstab   *fsp;
                struct  fstab   *fsp;
+               if (argc > 1)
+                       goto argcnt;
                close(2); dup(1);
                if (setfsent() == 0)
                        perror(FSTAB), exit(1);
                close(2); dup(1);
                if (setfsent() == 0)
                        perror(FSTAB), exit(1);
-               while ( (fsp = getfsent()) != 0){
+               while ( (fsp = getfsent()) != 0) {
                        if (strcmp(fsp->fs_file, "/") == 0)
                                continue;
                        ro = !strcmp(fsp->fs_type, FSTAB_RO);
                        if (ro==0 && strcmp(fsp->fs_type, FSTAB_RW))
                                continue;
                        if (strcmp(fsp->fs_file, "/") == 0)
                                continue;
                        ro = !strcmp(fsp->fs_type, FSTAB_RO);
                        if (ro==0 && strcmp(fsp->fs_type, FSTAB_RW))
                                continue;
-                       if (mountfs(fsp->fs_spec, fsp->fs_file, ro))
-                               failed(fsp);
-                       else
-                               succeed(fsp);
+                       mountfs(fsp->fs_spec, fsp->fs_file, ro);
                }
                }
-               endfsent();
+               exit(0);
        }
        }
-       exit(0);
-}
-failed(fsp)
-       register        struct  fstab *fsp;
-{
-       extern int errno;
-       extern char *sys_errlist[];
-       int err = errno;
-       printf("Attempt to mount ");
-       location(fsp);
-       printf("FAILED: %s\n", sys_errlist[err]);
-}
-succeed(fsp)
-       register        struct  fstab *fsp;
-{
-       printf("Mounted ");
-       location(fsp);
-       printf("\n");
-}
-location(fsp)
-       register        struct  fstab *fsp;
-{
-       extern  int     ro;
-       printf("%s on %s %s ",
-               fsp->fs_file, fsp->fs_spec,
-               ro ? "(Read Only)" : "");
+       if (argc < 2 || argc > 3) {
+argcnt:
+               printf("arg count\n");
+               exit(1);
+       }
+       ro = 0;
+       if(argc > 3)
+               ro++;
+       mountfs(argv[1], argv[2], ro);
 }
 
 mountfs(spec, name, ro)
 }
 
 mountfs(spec, name, ro)
-       char    *spec, *name;
-       int     ro;
+       char *spec, *name;
 {
 {
-       register        char    *np;
-       register        struct  mtab    *mp;
-       int     mf;
+       register char *np;
+       register struct mtab *mp;
+       int mf;
 
 
-       if(fake==0 && mount(spec, name, ro) < 0)
-               return(1);
+       if (fake==0) {
+               if (mount(spec, name, ro) < 0) {
+                       fprintf(stderr, "%s on ", spec);
+                       perror(name);
+                       return;
+               }
+       }
+       if (verbose)
+               fprintf(stderr, "%s on %s%s\n", spec, name,
+                   ro ? " read only" : "");
        np = spec;
        np = spec;
-       while(*np++)
+       while (*np++)
                ;
        np--;
                ;
        np--;
-       while(*--np == '/')
+       while (*--np == '/')
                *np = '\0';
                *np = '\0';
-       while(np > spec && *--np != '/')
+       while (np > spec && *--np != '/')
                ;
                ;
-       if(*np == '/')
+       if (*np == '/')
                np++;
        spec = np;
                np++;
        spec = np;
-       for (mp = mtab; mp < &mtab[NMOUNT]; mp++) {
-               if (mp->file[0] == 0) {
-                       for (np = mp->spec; np < &mp->spec[NAMSIZ-1];)
-                               if ((*np++ = *spec++) == 0)
-                                       spec--;
-                       for (np = mp->file; np < &mp->file[NAMSIZ-1];)
-                               if ((*np++ = *name++) == 0)
-                                       name--;
-                       mp = &mtab[NMOUNT];
-                       while ((--mp)->file[0] == 0);
-                       mf = creat("/etc/mtab", 0644);
-                       write(mf, (char *)mtab, (mp-mtab+1)*2*NAMSIZ);
-                       return(0);
-               }
-       }
-       return(0);
+       for (mp = mtab; mp < &mtab[NMOUNT]; mp++)
+               if (!strcmp(mp->spec, spec))
+                       goto replace;
+       for (mp = mtab; mp < &mtab[NMOUNT]; mp++)
+               if (mp->file[0] == 0)
+                       goto replace;
+       return;
+replace:
+       for (np = mp->spec; np < &mp->spec[NAMSIZ-1];)
+               if ((*np++ = *spec++) == 0)
+                       spec--;
+       for (np = mp->file; np < &mp->file[NAMSIZ-1];)
+               if ((*np++ = *name++) == 0)
+                       name--;
+       mp = &mtab[NMOUNT];
+       while ((--mp)->file[0] == 0);
+       mf = creat("/etc/mtab", 0644);
+       write(mf, (char *)mtab, (mp-mtab+1)*2*NAMSIZ);
+       close(mf);
+       return;
 }
 }