get fstype from mount entry
[unix-history] / usr / src / usr.sbin / amd / config / mtab_bsd.c
CommitLineData
e1a31032 1/*
e1a31032
KM
2 * Copyright (c) 1990 Jan-Simon Pendry
3 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
16f2cf2d
KB
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
e1a31032
KM
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Jan-Simon Pendry at Imperial College, London.
9 *
10 * %sccs.include.redist.c%
11 *
eee37df6 12 * @(#)mtab_bsd.c 8.2 (Berkeley) %G%
8d2991d5 13 *
332f0791 14 * $Id: mtab_bsd.c,v 5.2.2.1 1992/02/09 15:10:13 jsp beta $
8d2991d5 15 *
e1a31032
KM
16 */
17
18#include "am.h"
19
20#ifdef READ_MTAB_BSD_STYLE
21
22#include <sys/mount.h>
23
24static struct mntent *mnt_dup(mp)
25struct statfs *mp;
26{
27 struct mntent *new_mp = ALLOC(mntent);
28 char *ty;
29
30 new_mp->mnt_fsname = strdup(mp->f_mntfromname);
31 new_mp->mnt_dir = strdup(mp->f_mntonname);
eee37df6
JSP
32#if BSD >= 199506
33 ty = mp->f_fstypename;
34#else
e1a31032
KM
35 switch (mp->f_type) {
36 case MOUNT_UFS: ty = MTAB_TYPE_UFS; break;
37 case MOUNT_NFS: ty = MTAB_TYPE_NFS; break;
38 case MOUNT_MFS: ty = MTAB_TYPE_MFS; break;
39 default: ty = "unknown"; break;
40 }
eee37df6 41#endif
e1a31032
KM
42 new_mp->mnt_type = strdup(ty);
43 new_mp->mnt_opts = strdup("unset");
44 new_mp->mnt_freq = 0;
45 new_mp->mnt_passno = 0;
46
47 return new_mp;
48}
49
50/*
51 * Read a mount table into memory
52 */
53mntlist *read_mtab(fs)
54char *fs;
55{
56 mntlist **mpp, *mhp;
57 struct statfs *mntbufp, *mntp;
58
59 int nloc = getmntinfo(&mntbufp, MNT_NOWAIT);
60
61 if (nloc == 0) {
62 plog(XLOG_ERROR, "Can't read mount table");
63 return 0;
64 }
65
66 mpp = &mhp;
67 for (mntp = mntbufp; mntp < mntbufp + nloc; mntp++) {
68 /*
69 * Allocate a new slot
70 */
71 *mpp = ALLOC(mntlist);
72
73 /*
74 * Copy the data returned by getmntent
75 */
76 (*mpp)->mnt = mnt_dup(mntp);
77
78 /*
79 * Move to next pointer
80 */
81 mpp = &(*mpp)->mnext;
82 }
83
320d5ac7
JSP
84 /*
85 * Terminate the list
86 */
87 *mpp = 0;
88
e1a31032
KM
89 return mhp;
90}
91
92#endif /* READ_MTAB_BSD_STYLE */