|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. The Berkeley software License Agreement ! 4: * specifies the terms and conditions for redistribution. ! 5: */ ! 6: ! 7: #ifndef lint ! 8: char copyright[] = ! 9: "@(#) Copyright (c) 1980 Regents of the University of California.\n\ ! 10: All rights reserved.\n"; ! 11: #endif not lint ! 12: ! 13: #ifndef lint ! 14: static char sccsid[] = "@(#)mount.c 5.2 (Berkeley) 11/21/85"; ! 15: #endif not lint ! 16: ! 17: /* ! 18: * mount ! 19: */ ! 20: #include <sys/param.h> ! 21: ! 22: #include <stdio.h> ! 23: #include <fstab.h> ! 24: #include <mtab.h> ! 25: #include <errno.h> ! 26: ! 27: #define DNMAX (sizeof (mtab[0].m_dname) - 1) ! 28: #define PNMAX (sizeof (mtab[0].m_path) - 1) ! 29: ! 30: struct mtab mtab[NMOUNT]; ! 31: ! 32: int all; ! 33: int ro; ! 34: int fake; ! 35: int verbose; ! 36: char *index(), *rindex(); ! 37: ! 38: main(argc, argv) ! 39: int argc; ! 40: char **argv; ! 41: { ! 42: register struct mtab *mp; ! 43: register char *np; ! 44: int mf; ! 45: char *type = FSTAB_RW; ! 46: ! 47: mf = open("/etc/mtab", 0); ! 48: read(mf, (char *)mtab, sizeof (mtab)); ! 49: if (argc == 1) { ! 50: for (mp = mtab; mp < &mtab[NMOUNT]; mp++) ! 51: if (mp->m_path[0] != '\0') ! 52: prmtab(mp); ! 53: exit(0); ! 54: } ! 55: top: ! 56: if (argc > 1) { ! 57: if (!strcmp(argv[1], "-a")) { ! 58: all++; ! 59: argc--, argv++; ! 60: goto top; ! 61: } ! 62: if (!strcmp(argv[1], "-r")) { ! 63: type = FSTAB_RO; ! 64: argc--, argv++; ! 65: goto top; ! 66: } ! 67: if (!strcmp(argv[1], "-f")) { ! 68: fake++; ! 69: argc--, argv++; ! 70: goto top; ! 71: } ! 72: if (!strcmp(argv[1], "-v")) { ! 73: verbose++; ! 74: argc--, argv++; ! 75: goto top; ! 76: } ! 77: } ! 78: if (all) { ! 79: struct fstab *fsp; ! 80: ! 81: if (argc > 1) ! 82: goto argcnt; ! 83: close(2); dup(1); ! 84: if (setfsent() == 0) ! 85: perror(FSTAB), exit(1); ! 86: while ((fsp = getfsent()) != 0) { ! 87: if (strcmp(fsp->fs_file, "/") == 0) ! 88: continue; ! 89: if (strcmp(fsp->fs_type, FSTAB_RO) && ! 90: strcmp(fsp->fs_type, FSTAB_RW) && ! 91: strcmp(fsp->fs_type, FSTAB_RQ)) ! 92: continue; ! 93: mountfs(fsp->fs_spec, fsp->fs_file, fsp->fs_type); ! 94: } ! 95: exit(0); ! 96: } ! 97: if (argc == 2) { ! 98: struct fstab *fs; ! 99: ! 100: if (setfsent() == 0) ! 101: perror(FSTAB), exit(1); ! 102: fs = getfsfile(argv[1]); ! 103: if (fs == NULL) ! 104: goto argcnt; ! 105: if (strcmp(fs->fs_type, FSTAB_RO) && ! 106: strcmp(fs->fs_type, FSTAB_RW) && ! 107: strcmp(fs->fs_type, FSTAB_RQ)) ! 108: goto argcnt; ! 109: mountfs(fs->fs_spec, fs->fs_file, fs->fs_type); ! 110: exit(0); ! 111: } ! 112: if (argc != 3) { ! 113: argcnt: ! 114: fprintf(stderr, ! 115: "usage: mount [ -a ] [ -r ] [ -f ] [ -v ] [ special dir ] [ dir ]\n"); ! 116: exit(1); ! 117: } ! 118: mountfs(argv[1], argv[2], type); ! 119: } ! 120: ! 121: prmtab(mp) ! 122: register struct mtab *mp; ! 123: { ! 124: ! 125: printf("%s on %s", mp->m_dname, mp->m_path); ! 126: if (strcmp(mp->m_type, FSTAB_RO) == 0) ! 127: printf("\t(read-only)"); ! 128: if (strcmp(mp->m_type, FSTAB_RQ) == 0) ! 129: printf("\t(with quotas)"); ! 130: putchar('\n'); ! 131: } ! 132: ! 133: mountfs(spec, name, type) ! 134: char *spec, *name, *type; ! 135: { ! 136: register char *np; ! 137: register struct mtab *mp; ! 138: int mf; ! 139: ! 140: if (!fake) { ! 141: if (mount(spec, name, strcmp(type, FSTAB_RO) == 0) < 0) { ! 142: extern int errno; ! 143: char *cp; ! 144: ! 145: fprintf(stderr, "%s on ", spec); ! 146: switch (errno) { ! 147: ! 148: case EMFILE: ! 149: cp = "Mount table full"; ! 150: break; ! 151: ! 152: case EINVAL: ! 153: cp = "Bogus super block"; ! 154: break; ! 155: ! 156: default: ! 157: perror(name); ! 158: return; ! 159: } ! 160: fprintf(stderr, "%s: %s\n", name, cp); ! 161: return; ! 162: } ! 163: /* we don't do quotas.... */ ! 164: if (strcmp(type, FSTAB_RQ) == 0) ! 165: type = FSTAB_RW; ! 166: } ! 167: np = index(spec, '\0'); ! 168: while (*--np == '/') ! 169: *np = '\0'; ! 170: np = rindex(spec, '/'); ! 171: if (np) { ! 172: *np++ = '\0'; ! 173: spec = np; ! 174: } ! 175: for (mp = mtab; mp < &mtab[NMOUNT]; mp++) ! 176: if (strcmp(mp->m_dname, spec) == 0) ! 177: goto replace; ! 178: for (mp = mtab; mp < &mtab[NMOUNT]; mp++) ! 179: if (mp->m_path[0] == '\0') ! 180: goto replace; ! 181: return; ! 182: replace: ! 183: strncpy(mp->m_dname, spec, DNMAX); ! 184: mp->m_dname[DNMAX] = '\0'; ! 185: strncpy(mp->m_path, name, PNMAX); ! 186: mp->m_path[PNMAX] = '\0'; ! 187: strcpy(mp->m_type, type); ! 188: if (verbose) ! 189: prmtab(mp); ! 190: mp = mtab + NMOUNT - 1; ! 191: while (mp > mtab && mp->m_path[0] == '\0') ! 192: --mp; ! 193: mf = creat("/etc/mtab", 0644); ! 194: write(mf, (char *)mtab, (mp - mtab + 1) * sizeof (struct mtab)); ! 195: close(mf); ! 196: return; ! 197: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.