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