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: #if defined(LIBC_SCCS) && !defined(lint)
8: static char sccsid[] = "@(#)fstab.c 5.2 (Berkeley) 3/9/86";
9: #endif LIBC_SCCS and not lint
10:
11: #include <fstab.h>
12: #include <stdio.h>
13: #include <ctype.h>
14:
15: static struct fstab fs;
16: static char line[BUFSIZ+1];
17: static FILE *fs_file = 0;
18:
19: static char *
20: fsskip(p)
21: register char *p;
22: {
23:
24: while (*p && *p != ':')
25: ++p;
26: if (*p)
27: *p++ = 0;
28: return (p);
29: }
30:
31: static char *
32: fsdigit(backp, string, end)
33: int *backp;
34: char *string, end;
35: {
36: register int value = 0;
37: register char *cp;
38:
39: for (cp = string; *cp && isdigit(*cp); cp++) {
40: value *= 10;
41: value += *cp - '0';
42: }
43: if (*cp == '\0')
44: return ((char *)0);
45: *backp = value;
46: while (*cp && *cp != end)
47: cp++;
48: if (*cp == '\0')
49: return ((char *)0);
50: return (cp+1);
51: }
52:
53: static
54: fstabscan(fs)
55: struct fstab *fs;
56: {
57: register char *cp;
58:
59: cp = fgets(line, 256, fs_file);
60: if (cp == NULL)
61: return (EOF);
62: fs->fs_spec = cp;
63: cp = fsskip(cp);
64: fs->fs_file = cp;
65: cp = fsskip(cp);
66: fs->fs_type = cp;
67: cp = fsskip(cp);
68: cp = fsdigit(&fs->fs_freq, cp, ':');
69: if (cp == 0)
70: return (3);
71: cp = fsdigit(&fs->fs_passno, cp, '\n');
72: if (cp == 0)
73: return (4);
74: return (5);
75: }
76:
77: setfsent()
78: {
79:
80: if (fs_file)
81: endfsent();
82: if ((fs_file = fopen(FSTAB, "r")) == NULL) {
83: fs_file = 0;
84: return (0);
85: }
86: return (1);
87: }
88:
89: endfsent()
90: {
91:
92: if (fs_file) {
93: fclose(fs_file);
94: fs_file = 0;
95: }
96: return (1);
97: }
98:
99: struct fstab *
100: getfsent()
101: {
102: int nfields;
103:
104: if ((fs_file == 0) && (setfsent() == 0))
105: return ((struct fstab *)0);
106: nfields = fstabscan(&fs);
107: if (nfields == EOF || nfields != 5)
108: return ((struct fstab *)0);
109: return (&fs);
110: }
111:
112: struct fstab *
113: getfsspec(name)
114: char *name;
115: {
116: register struct fstab *fsp;
117:
118: if (setfsent() == 0) /* start from the beginning */
119: return ((struct fstab *)0);
120: while((fsp = getfsent()) != 0)
121: if (strcmp(fsp->fs_spec, name) == 0)
122: return (fsp);
123: return ((struct fstab *)0);
124: }
125:
126: struct fstab *
127: getfsfile(name)
128: char *name;
129: {
130: register struct fstab *fsp;
131:
132: if (setfsent() == 0) /* start from the beginning */
133: return ((struct fstab *)0);
134: while ((fsp = getfsent()) != 0)
135: if (strcmp(fsp->fs_file, name) == 0)
136: return (fsp);
137: return ((struct fstab *)0);
138: }
139:
140: struct fstab *
141: getfstype(type)
142: char *type;
143: {
144: register struct fstab *fs;
145:
146: if (setfsent() == 0)
147: return ((struct fstab *)0);
148: while ((fs = getfsent()) != 0)
149: if (strcmp(fs->fs_type, type) == 0)
150: return (fs);
151: return ((struct fstab *)0);
152: }
Defined functions
Defined variables
fs
defined in line
15; used 13 times
line
defined in line
16; used 1 times
sccsid
defined in line
8;
never used