xref: /original-bsd/usr.sbin/amd/config/mtab_bsd.c (revision 04dd0305)
1 /*
2  * Copyright (c) 1990 Jan-Simon Pendry
3  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
4  * Copyright (c) 1990, 1993
5  *	The Regents of the University of California.  All rights reserved.
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  *
12  *	@(#)mtab_bsd.c	8.1 (Berkeley) 06/06/93
13  *
14  * $Id: mtab_bsd.c,v 5.2.2.1 1992/02/09 15:10:13 jsp beta $
15  *
16  */
17 
18 #include "am.h"
19 
20 #ifdef READ_MTAB_BSD_STYLE
21 
22 #include <sys/mount.h>
23 
24 static struct mntent *mnt_dup(mp)
25 struct 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);
32 	switch (mp->f_type) {
33 	case MOUNT_UFS:  ty = MTAB_TYPE_UFS; break;
34 	case MOUNT_NFS:  ty = MTAB_TYPE_NFS; break;
35 	case MOUNT_MFS:  ty = MTAB_TYPE_MFS; break;
36 	default:  ty = "unknown"; break;
37 	}
38 	new_mp->mnt_type = strdup(ty);
39 	new_mp->mnt_opts = strdup("unset");
40 	new_mp->mnt_freq = 0;
41 	new_mp->mnt_passno = 0;
42 
43 	return new_mp;
44 }
45 
46 /*
47  * Read a mount table into memory
48  */
49 mntlist *read_mtab(fs)
50 char *fs;
51 {
52 	mntlist **mpp, *mhp;
53 	struct statfs *mntbufp, *mntp;
54 
55 	int nloc = getmntinfo(&mntbufp, MNT_NOWAIT);
56 
57 	if (nloc == 0) {
58 		plog(XLOG_ERROR, "Can't read mount table");
59 		return 0;
60 	}
61 
62 	mpp = &mhp;
63 	for (mntp = mntbufp; mntp < mntbufp + nloc; mntp++) {
64 		/*
65 		 * Allocate a new slot
66 		 */
67 		*mpp = ALLOC(mntlist);
68 
69 		/*
70 		 * Copy the data returned by getmntent
71 		 */
72 		(*mpp)->mnt = mnt_dup(mntp);
73 
74 		/*
75 		 * Move to next pointer
76 		 */
77 		mpp = &(*mpp)->mnext;
78 	}
79 
80 	/*
81 	 * Terminate the list
82 	 */
83 	*mpp = 0;
84 
85 	return mhp;
86 }
87 
88 #endif /* READ_MTAB_BSD_STYLE */
89