17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
22*5d54f3d8Smuffin /*
23*5d54f3d8Smuffin * Copyright 1990 Sun Microsystems, Inc. All rights reserved.
24*5d54f3d8Smuffin * Use is subject to license terms.
25*5d54f3d8Smuffin */
26*5d54f3d8Smuffin
277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include <fstab.h>
307c478bd9Sstevel@tonic-gate #include <stdio.h>
317c478bd9Sstevel@tonic-gate #include <ctype.h>
327c478bd9Sstevel@tonic-gate #include <mntent.h>
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate static struct fstab *pfs;
357c478bd9Sstevel@tonic-gate static FILE *fs_file;
367c478bd9Sstevel@tonic-gate
37*5d54f3d8Smuffin static int
fstabscan(struct fstab * fs)38*5d54f3d8Smuffin fstabscan(struct fstab *fs)
397c478bd9Sstevel@tonic-gate {
407c478bd9Sstevel@tonic-gate struct mntent *mnt;
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate /* skip over all filesystem types except '4.2', 'swap' & 'ignore' */
437c478bd9Sstevel@tonic-gate while (((mnt = getmntent(fs_file)) != NULL) &&
447c478bd9Sstevel@tonic-gate !((strcmp(mnt->mnt_type, MNTTYPE_42) == 0) ||
457c478bd9Sstevel@tonic-gate (strcmp(mnt->mnt_type, MNTTYPE_SWAP) == 0) ||
467c478bd9Sstevel@tonic-gate (strcmp(mnt->mnt_type, MNTTYPE_IGNORE) == 0)))
477c478bd9Sstevel@tonic-gate continue;
487c478bd9Sstevel@tonic-gate if (mnt == NULL)
497c478bd9Sstevel@tonic-gate return (EOF);
507c478bd9Sstevel@tonic-gate fs->fs_spec = mnt->mnt_fsname;
517c478bd9Sstevel@tonic-gate fs->fs_file = mnt->mnt_dir;
527c478bd9Sstevel@tonic-gate if (strcmp(mnt->mnt_type, MNTTYPE_IGNORE) == 0) {
537c478bd9Sstevel@tonic-gate strcpy(mnt->mnt_opts, FSTAB_XX);
547c478bd9Sstevel@tonic-gate } else if (strcmp(mnt->mnt_type, MNTTYPE_SWAP) == 0) {
557c478bd9Sstevel@tonic-gate strcpy(mnt->mnt_opts, FSTAB_SW);
567c478bd9Sstevel@tonic-gate } else if (hasmntopt(mnt, MNTOPT_RO)) {
577c478bd9Sstevel@tonic-gate strcpy(mnt->mnt_opts, FSTAB_RO);
587c478bd9Sstevel@tonic-gate } else if (hasmntopt(mnt, MNTOPT_QUOTA)) {
597c478bd9Sstevel@tonic-gate strcpy(mnt->mnt_opts, FSTAB_RQ);
607c478bd9Sstevel@tonic-gate } else {
617c478bd9Sstevel@tonic-gate strcpy(mnt->mnt_opts, FSTAB_RW);
627c478bd9Sstevel@tonic-gate }
637c478bd9Sstevel@tonic-gate fs->fs_type = mnt->mnt_opts;
647c478bd9Sstevel@tonic-gate fs->fs_freq = mnt->mnt_freq;
657c478bd9Sstevel@tonic-gate fs->fs_passno = mnt->mnt_passno;
667c478bd9Sstevel@tonic-gate return (5);
677c478bd9Sstevel@tonic-gate }
687c478bd9Sstevel@tonic-gate
69*5d54f3d8Smuffin int
setfsent(void)70*5d54f3d8Smuffin setfsent(void)
717c478bd9Sstevel@tonic-gate {
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate if (fs_file)
747c478bd9Sstevel@tonic-gate endfsent();
757c478bd9Sstevel@tonic-gate if ((fs_file = setmntent(FSTAB, "r")) == NULL) {
767c478bd9Sstevel@tonic-gate fs_file = 0;
777c478bd9Sstevel@tonic-gate return (0);
787c478bd9Sstevel@tonic-gate }
797c478bd9Sstevel@tonic-gate return (1);
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate
82*5d54f3d8Smuffin int
endfsent(void)83*5d54f3d8Smuffin endfsent(void)
847c478bd9Sstevel@tonic-gate {
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate if (fs_file) {
877c478bd9Sstevel@tonic-gate endmntent(fs_file);
887c478bd9Sstevel@tonic-gate fs_file = 0;
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate return (1);
917c478bd9Sstevel@tonic-gate }
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate struct fstab *
getfsent(void)94*5d54f3d8Smuffin getfsent(void)
957c478bd9Sstevel@tonic-gate {
967c478bd9Sstevel@tonic-gate int nfields;
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate if ((fs_file == 0) && (setfsent() == 0))
997c478bd9Sstevel@tonic-gate return ((struct fstab *)0);
1007c478bd9Sstevel@tonic-gate if (pfs == 0) {
1017c478bd9Sstevel@tonic-gate pfs = (struct fstab *)malloc(sizeof (struct fstab));
1027c478bd9Sstevel@tonic-gate if (pfs == 0)
1037c478bd9Sstevel@tonic-gate return (0);
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate nfields = fstabscan(pfs);
1067c478bd9Sstevel@tonic-gate if (nfields == EOF || nfields != 5)
1077c478bd9Sstevel@tonic-gate return ((struct fstab *)0);
1087c478bd9Sstevel@tonic-gate return (pfs);
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate struct fstab *
getfsspec(char * name)112*5d54f3d8Smuffin getfsspec(char *name)
1137c478bd9Sstevel@tonic-gate {
114*5d54f3d8Smuffin struct fstab *fsp;
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate if (setfsent() == 0) /* start from the beginning */
1177c478bd9Sstevel@tonic-gate return ((struct fstab *)0);
1187c478bd9Sstevel@tonic-gate while((fsp = getfsent()) != 0)
1197c478bd9Sstevel@tonic-gate if (strcmp(fsp->fs_spec, name) == 0)
1207c478bd9Sstevel@tonic-gate return (fsp);
1217c478bd9Sstevel@tonic-gate return ((struct fstab *)0);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate struct fstab *
getfsfile(char * name)125*5d54f3d8Smuffin getfsfile(char *name)
1267c478bd9Sstevel@tonic-gate {
127*5d54f3d8Smuffin struct fstab *fsp;
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate if (setfsent() == 0) /* start from the beginning */
1307c478bd9Sstevel@tonic-gate return ((struct fstab *)0);
1317c478bd9Sstevel@tonic-gate while ((fsp = getfsent()) != 0)
1327c478bd9Sstevel@tonic-gate if (strcmp(fsp->fs_file, name) == 0)
1337c478bd9Sstevel@tonic-gate return (fsp);
1347c478bd9Sstevel@tonic-gate return ((struct fstab *)0);
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate struct fstab *
getfstype(char * type)138*5d54f3d8Smuffin getfstype(char *type)
1397c478bd9Sstevel@tonic-gate {
140*5d54f3d8Smuffin struct fstab *fs;
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate if (setfsent() == 0)
1437c478bd9Sstevel@tonic-gate return ((struct fstab *)0);
1447c478bd9Sstevel@tonic-gate while ((fs = getfsent()) != 0)
1457c478bd9Sstevel@tonic-gate if (strcmp(fs->fs_type, type) == 0)
1467c478bd9Sstevel@tonic-gate return (fs);
1477c478bd9Sstevel@tonic-gate return ((struct fstab *)0);
1487c478bd9Sstevel@tonic-gate }
149