|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include <fstab.h> ! 3: #include <string.h> ! 4: #include <libc.h> ! 5: ! 6: /* ! 7: * mount ! 8: */ ! 9: ! 10: #define NMOUNT 64 ! 11: ! 12: struct mtab mtab[NMOUNT]; ! 13: ! 14: main(argc, argv) ! 15: int argc; ! 16: char **argv; ! 17: { ! 18: register struct mtab *mp; ! 19: register struct fstab *fsp; ! 20: int type, flag; ! 21: char *spec, *file; ! 22: int mf; ! 23: int mountall = 0; ! 24: ! 25: mf = open(MTAB, 0); ! 26: read(mf, (char *)mtab, sizeof(mtab)); ! 27: close(mf); ! 28: if (argc == 1) { ! 29: for (mp = mtab; mp < &mtab[NMOUNT]; mp++) ! 30: if (mp->file[0]) { ! 31: printf("%s on %s", mp->spec, mp->file); ! 32: if (mp->type) ! 33: printf(" type %d", mp->type); ! 34: printf("\n"); ! 35: } ! 36: exit(0); ! 37: } ! 38: if (argc == 2){ ! 39: if (strcmp(argv[1], "-a") == 0) ! 40: mountall++; ! 41: else { ! 42: fprintf(stderr, "usage: mount [-a] [special mountpoint [-r] [type flag]\n"); ! 43: exit(1); ! 44: } ! 45: } ! 46: if (!mountall){ ! 47: type = flag = 0; ! 48: spec = argv[1]; ! 49: file = argv[2]; ! 50: if (argc > 3 && strcmp(argv[3], "-r") == 0) { /* hack */ ! 51: flag = 1; ! 52: argc--; ! 53: argv++; ! 54: } ! 55: if (argc > 3) ! 56: type = atoi(argv[3]); ! 57: if (argc > 4) ! 58: flag = atoi(argv[4]); ! 59: if (mountfs(spec, file, type, flag)) ! 60: exit(1); ! 61: exit(0); ! 62: } ! 63: if (setfsent() == 0) { ! 64: perror(FSTAB); ! 65: exit(1); ! 66: } ! 67: while ((fsp = getfsent()) != 0) { ! 68: if (strcmp(fsp->fs_file, "/") == 0) ! 69: continue; ! 70: if (fsp->fs_ftype < 0) ! 71: continue; ! 72: if (mountfs(fsp->fs_spec, fsp->fs_file, fsp->fs_ftype, fsp->fs_flags) == 0) ! 73: babble(fsp); ! 74: } ! 75: endfsent(); ! 76: exit(0); ! 77: } ! 78: ! 79: /* ! 80: * give a reassuring message about the mount ! 81: * somewhat customised: knows about fs type 0. ! 82: * this is probably silly ! 83: */ ! 84: ! 85: babble(fsp) ! 86: register struct fstab *fsp; ! 87: { ! 88: printf("Mounted %s on %s", fsp->fs_spec, fsp->fs_file); ! 89: if (fsp->fs_ftype != 0) { ! 90: printf(" type %d", fsp->fs_ftype); ! 91: if (fsp->fs_flags) ! 92: printf(" flag %d\n", fsp->fs_flags); ! 93: } else { ! 94: switch (fsp->fs_flags) { ! 95: case 0: ! 96: break; ! 97: ! 98: case 1: ! 99: printf(" readonly"); ! 100: break; ! 101: ! 102: default: ! 103: printf(" type 0 flag %d", fsp->fs_flags); ! 104: break; ! 105: } ! 106: } ! 107: putchar('\n'); ! 108: fflush(stdout); ! 109: } ! 110: ! 111: mountfs(spec, name, type, flag) ! 112: char *spec, *name; ! 113: int type, flag; ! 114: { ! 115: register char *np; ! 116: register struct mtab *mp; ! 117: int fd; ! 118: ! 119: if ((fd = open(spec, 0)) < 0) { ! 120: cant("open %s to mount on %s: ", spec, name, 0); ! 121: return (1); ! 122: } ! 123: if (fmount(type, fd, name, flag) < 0) { ! 124: cant("mount %s on %s type %d: ", spec, name, type); ! 125: return (1); ! 126: } ! 127: close(fd); ! 128: for (mp = mtab; mp < &mtab[NMOUNT]; mp++) { ! 129: if (mp->file[0] == 0) { ! 130: strncpy(mp->file, name, sizeof(mp->file)-1); ! 131: strncpy(mp->spec, spec, sizeof(mp->spec)-1); ! 132: mp->type = type; ! 133: mp = &mtab[NMOUNT]; ! 134: while ((--mp)->file[0] == 0); ! 135: if ((fd = creat(MTAB, 0644)) < 0) ! 136: return (0); ! 137: write(fd, (char *)mtab, (mp-mtab+1)*sizeof(struct mtab)); ! 138: close(fd); ! 139: return(0); ! 140: } ! 141: } ! 142: return(0); ! 143: } ! 144: ! 145: cant(str, a, b, c) ! 146: char *str; ! 147: char *a, *b; ! 148: int c; ! 149: { ! 150: extern int errno; ! 151: int serr; ! 152: ! 153: serr = errno; ! 154: fprintf(stderr, str, a, b, c); ! 155: fflush(stderr); ! 156: errno = serr; ! 157: perror(""); ! 158: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.