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