8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libbc / libc / gen / common / fstab.c
blob7fa88f0a5b0403da2a3eaf43ddeb364600a6ff5c
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 1990 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <fstab.h>
30 #include <stdio.h>
31 #include <ctype.h>
32 #include <mntent.h>
34 static struct fstab *pfs;
35 static FILE *fs_file;
37 static int
38 fstabscan(struct fstab *fs)
40 struct mntent *mnt;
42 /* skip over all filesystem types except '4.2', 'swap' & 'ignore' */
43 while (((mnt = getmntent(fs_file)) != NULL) &&
44 !((strcmp(mnt->mnt_type, MNTTYPE_42) == 0) ||
45 (strcmp(mnt->mnt_type, MNTTYPE_SWAP) == 0) ||
46 (strcmp(mnt->mnt_type, MNTTYPE_IGNORE) == 0)))
47 continue;
48 if (mnt == NULL)
49 return (EOF);
50 fs->fs_spec = mnt->mnt_fsname;
51 fs->fs_file = mnt->mnt_dir;
52 if (strcmp(mnt->mnt_type, MNTTYPE_IGNORE) == 0) {
53 strcpy(mnt->mnt_opts, FSTAB_XX);
54 } else if (strcmp(mnt->mnt_type, MNTTYPE_SWAP) == 0) {
55 strcpy(mnt->mnt_opts, FSTAB_SW);
56 } else if (hasmntopt(mnt, MNTOPT_RO)) {
57 strcpy(mnt->mnt_opts, FSTAB_RO);
58 } else if (hasmntopt(mnt, MNTOPT_QUOTA)) {
59 strcpy(mnt->mnt_opts, FSTAB_RQ);
60 } else {
61 strcpy(mnt->mnt_opts, FSTAB_RW);
63 fs->fs_type = mnt->mnt_opts;
64 fs->fs_freq = mnt->mnt_freq;
65 fs->fs_passno = mnt->mnt_passno;
66 return (5);
69 int
70 setfsent(void)
73 if (fs_file)
74 endfsent();
75 if ((fs_file = setmntent(FSTAB, "r")) == NULL) {
76 fs_file = 0;
77 return (0);
79 return (1);
82 int
83 endfsent(void)
86 if (fs_file) {
87 endmntent(fs_file);
88 fs_file = 0;
90 return (1);
93 struct fstab *
94 getfsent(void)
96 int nfields;
98 if ((fs_file == 0) && (setfsent() == 0))
99 return ((struct fstab *)0);
100 if (pfs == 0) {
101 pfs = (struct fstab *)malloc(sizeof (struct fstab));
102 if (pfs == 0)
103 return (0);
105 nfields = fstabscan(pfs);
106 if (nfields == EOF || nfields != 5)
107 return ((struct fstab *)0);
108 return (pfs);
111 struct fstab *
112 getfsspec(char *name)
114 struct fstab *fsp;
116 if (setfsent() == 0) /* start from the beginning */
117 return ((struct fstab *)0);
118 while((fsp = getfsent()) != 0)
119 if (strcmp(fsp->fs_spec, name) == 0)
120 return (fsp);
121 return ((struct fstab *)0);
124 struct fstab *
125 getfsfile(char *name)
127 struct fstab *fsp;
129 if (setfsent() == 0) /* start from the beginning */
130 return ((struct fstab *)0);
131 while ((fsp = getfsent()) != 0)
132 if (strcmp(fsp->fs_file, name) == 0)
133 return (fsp);
134 return ((struct fstab *)0);
137 struct fstab *
138 getfstype(char *type)
140 struct fstab *fs;
142 if (setfsent() == 0)
143 return ((struct fstab *)0);
144 while ((fs = getfsent()) != 0)
145 if (strcmp(fs->fs_type, type) == 0)
146 return (fs);
147 return ((struct fstab *)0);