|
|
1.1 root 1: /*
2: * Copyright (c) 1980, 1988 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #if defined(LIBC_SCCS) && !defined(lint)
21: static char sccsid[] = "@(#)fstab.c 5.11 (Berkeley) 6/1/90";
22: #endif /* LIBC_SCCS and not lint */
23:
24: #include <fstab.h>
25: #include <unistd.h>
26: #include <stdio.h>
27:
28: static FILE *_fs_fp;
29: static struct fstab _fs_fstab;
30:
31: static
32: fstabscan()
33: {
34: register char *cp;
35: #define MAXLINELENGTH 1024
36: static char line[MAXLINELENGTH];
37: char subline[MAXLINELENGTH];
38: char *fgets(), *strtok();
39: int typexx;
40:
41: for (;;) {
42: if (!(cp = fgets(line, sizeof(line), _fs_fp)))
43: return(0);
44: _fs_fstab.fs_spec = strtok(cp, " \t\n");
45: if (!_fs_fstab.fs_spec || *_fs_fstab.fs_spec == '#')
46: continue;
47: _fs_fstab.fs_file = strtok((char *)NULL, " \t\n");
48: _fs_fstab.fs_vfstype = strtok((char *)NULL, " \t\n");
49: _fs_fstab.fs_mntops = strtok((char *)NULL, " \t\n");
50: if (_fs_fstab.fs_mntops == NULL)
51: goto bad;
52: _fs_fstab.fs_freq = 0;
53: _fs_fstab.fs_passno = 0;
54: if ((cp = strtok((char *)NULL, " \t\n")) != NULL) {
55: _fs_fstab.fs_freq = atoi(cp);
56: if ((cp = strtok((char *)NULL, " \t\n")) != NULL)
57: _fs_fstab.fs_passno = atoi(cp);
58: }
59: strcpy(subline, _fs_fstab.fs_mntops);
60: for (typexx = 0, cp = strtok(subline, ","); cp;
61: cp = strtok((char *)NULL, ",")) {
62: if (strlen(cp) != 2)
63: continue;
64: if (!strcmp(cp, FSTAB_RW)) {
65: _fs_fstab.fs_type = FSTAB_RW;
66: break;
67: }
68: if (!strcmp(cp, FSTAB_RQ)) {
69: _fs_fstab.fs_type = FSTAB_RQ;
70: break;
71: }
72: if (!strcmp(cp, FSTAB_RO)) {
73: _fs_fstab.fs_type = FSTAB_RO;
74: break;
75: }
76: if (!strcmp(cp, FSTAB_SW)) {
77: _fs_fstab.fs_type = FSTAB_SW;
78: break;
79: }
80: if (!strcmp(cp, FSTAB_XX)) {
81: _fs_fstab.fs_type = FSTAB_XX;
82: typexx++;
83: break;
84: }
85: }
86: if (typexx)
87: continue;
88: if (cp != NULL)
89: return(1);
90: bad:
91: /* no way to distinguish between EOF and syntax error */
92: (void)write(STDERR_FILENO, "fstab: ", 7);
93: (void)write(STDERR_FILENO, _PATH_FSTAB,
94: sizeof(_PATH_FSTAB) - 1);
95: (void)write(STDERR_FILENO, ": syntax error.\n", 16);
96: }
97: /* NOTREACHED */
98: }
99:
100: struct fstab *
101: getfsent()
102: {
103: if (!_fs_fp && !setfsent() || !fstabscan())
104: return((struct fstab *)NULL);
105: return(&_fs_fstab);
106: }
107:
108: struct fstab *
109: getfsspec(name)
110: register char *name;
111: {
112: if (setfsent())
113: while (fstabscan())
114: if (!strcmp(_fs_fstab.fs_spec, name))
115: return(&_fs_fstab);
116: return((struct fstab *)NULL);
117: }
118:
119: struct fstab *
120: getfsfile(name)
121: register char *name;
122: {
123: if (setfsent())
124: while (fstabscan())
125: if (!strcmp(_fs_fstab.fs_file, name))
126: return(&_fs_fstab);
127: return((struct fstab *)NULL);
128: }
129:
130: setfsent()
131: {
132: if (_fs_fp) {
133: rewind(_fs_fp);
134: return(1);
135: }
136: return((_fs_fp = fopen(_PATH_FSTAB, "r")) != NULL);
137: }
138:
139: void
140: endfsent()
141: {
142: if (_fs_fp) {
143: (void)fclose(_fs_fp);
144: _fs_fp = NULL;
145: }
146: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.