1: static  char    sccsid []   = "@(#)mount.c	1.1	5/2/81";
   2: /*static char *sccsid = "@(#)mount.c	4.3 (Berkeley) 10/15/80";*/
   3: 
   4: #include <stdio.h>
   5: #include <fstab.h>
   6: 
   7: /*
   8:  * mount
   9:  */
  10: 
  11: int mountall;
  12: #define NMOUNT  16
  13: #define NAMSIZ  32
  14: 
  15: struct mtab {
  16:     char    file[NAMSIZ];
  17:     char    spec[NAMSIZ];
  18: } mtab[NMOUNT];
  19: 
  20: int ro;
  21: main(argc, argv)
  22: char **argv;
  23: {
  24:     register struct mtab *mp;
  25:     register char *np;
  26:     int mf;
  27: 
  28:     mountall = 0;
  29:     mf = open("/etc/mtab", 0);
  30:     read(mf, (char *)mtab, NMOUNT*2*NAMSIZ);
  31:     if (argc==1) {
  32:         for (mp = mtab; mp < &mtab[NMOUNT]; mp++)
  33:             if (mp->file[0])
  34:                 printf("%s on %s\n", mp->spec, mp->file);
  35:         exit(0);
  36:     }
  37: 
  38:     if (argc == 2){
  39:         if (strcmp(argv[1], "-a") == 0)
  40:             mountall++;
  41:         else {
  42:             fprintf(stdout,"arg count\n");
  43:             exit(1);
  44:         }
  45:     }
  46: 
  47:     if (!mountall){
  48:         ro = 0;
  49:         if(argc > 3)
  50:             ro++;
  51:         if (mountfs(argv[1], argv[2], ro)){
  52:             perror("mount");
  53:             exit(1);
  54:         }
  55:     } else {
  56:         struct  fstab   *fsp;
  57:         close(2); dup(1);
  58:         if (setfsent() == 0)
  59:             perror(FSTAB), exit(1);
  60:         while ( (fsp = getfsent()) != 0){
  61:             if (strcmp(fsp->fs_file, "/") == 0)
  62:                 continue;
  63:             ro = !strcmp(fsp->fs_type, FSTAB_RO);
  64:             if (ro==0 && strcmp(fsp->fs_type, FSTAB_RW))
  65:                 continue;
  66:             if (mountfs(fsp->fs_spec, fsp->fs_file, ro))
  67:                 failed(fsp);
  68:             else
  69:                 succeed(fsp);
  70:         }
  71:         endfsent();
  72:     }
  73:     exit(0);
  74: }
  75: failed(fsp)
  76:     register    struct  fstab *fsp;
  77: {
  78:     extern int errno;
  79:     extern char *sys_errlist[];
  80:     int err = errno;
  81:     printf("Attempt to mount ");
  82:     location(fsp);
  83:     printf("FAILED: %s\n", sys_errlist[err]);
  84: }
  85: succeed(fsp)
  86:     register    struct  fstab *fsp;
  87: {
  88:     printf("Mounted ");
  89:     location(fsp);
  90:     printf("\n");
  91: }
  92: location(fsp)
  93:     register    struct  fstab *fsp;
  94: {
  95:     extern  int ro;
  96:     printf("%s on %s %s ",
  97:         fsp->fs_file, fsp->fs_spec,
  98:         ro ? "(Read Only)" : "");
  99: }
 100: 
 101: mountfs(spec, name, ro)
 102:     char    *spec, *name;
 103:     int ro;
 104: {
 105:     register    char    *np;
 106:     register    struct  mtab    *mp;
 107:     int mf;
 108: 
 109:     if(mount(spec, name, ro) < 0) {
 110:         return(1);
 111:     }
 112:     np = spec;
 113:     while(*np++)
 114:         ;
 115:     np--;
 116:     while(*--np == '/')
 117:         *np = '\0';
 118:     while(np > spec && *--np != '/')
 119:         ;
 120:     if(*np == '/')
 121:         np++;
 122:     spec = np;
 123:     for (mp = mtab; mp < &mtab[NMOUNT]; mp++) {
 124:         if (mp->file[0] == 0) {
 125:             for (np = mp->spec; np < &mp->spec[NAMSIZ-1];)
 126:                 if ((*np++ = *spec++) == 0)
 127:                     spec--;
 128:             for (np = mp->file; np < &mp->file[NAMSIZ-1];)
 129:                 if ((*np++ = *name++) == 0)
 130:                     name--;
 131:             mp = &mtab[NMOUNT];
 132:             while ((--mp)->file[0] == 0);
 133:             mf = creat("/etc/mtab", 0644);
 134:             write(mf, (char *)mtab, (mp-mtab+1)*2*NAMSIZ);
 135:             return(0);
 136:         }
 137:     }
 138:     return(0);
 139: }

Defined functions

failed defined in line 75; used 1 times
  • in line 67
location defined in line 92; used 2 times
main defined in line 21; never used
mountfs defined in line 101; used 2 times
succeed defined in line 85; used 1 times
  • in line 69

Defined variables

mountall defined in line 11; used 3 times
mtab defined in line 18; used 8 times
ro defined in line 20; used 11 times
sccsid defined in line 1; never used

Defined struct's

mtab defined in line 15; used 4 times

Defined macros

NAMSIZ defined in line 13; used 6 times
NMOUNT defined in line 12; used 5 times
Last modified: 1982-02-04
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 847
Valid CSS Valid XHTML 1.0 Strict