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_ultrix.c	8.1 (Berkeley) 06/06/93
13  *
14  * $Id: mtab_ultrix.c,v 5.2.2.1 1992/02/09 15:10:50 jsp beta $
15  *
16  */
17 
18 #include "am.h"
19 
20 #ifdef READ_MTAB_ULTRIX_STYLE
21 
22 #include <sys/mount.h>
23 #include <sys/fs_types.h>
24 
25 static struct mntent *mnt_dup(mp)
26 struct fs_data *mp;
27 {
28 	struct mntent *new_mp = ALLOC(mntent);
29 
30 	new_mp->mnt_fsname = strdup(mp->fd_devname);
31 	new_mp->mnt_dir = strdup(mp->fd_path);
32         if (mp->fd_fstype >= GT_NUMTYPES)
33                 mp->fd_fstype = GT_UNKWN;
34         else if (gt_names[mp->fd_fstype] == 0)
35                 mp->fd_fstype = GT_UNKWN;
36         new_mp->mnt_type = strdup(gt_names[mp->fd_fstype]);
37 	new_mp->mnt_opts = strdup("unset");
38 
39 	new_mp->mnt_freq = 0;
40 	new_mp->mnt_passno = mp->fd_dev;
41 
42 	return new_mp;
43 }
44 
45 /*
46  * Read a mount table into memory
47  */
48 mntlist *read_mtab(fs)
49 char *fs;
50 {
51 	mntlist **mpp, *mhp;
52 
53 /* From: Piete Brooks <pb@cl.cam.ac.uk> */
54 
55 	int loc=0;
56 #undef	NMOUNT
57 #define	NMOUNT	20
58 	struct fs_data mountbuffer[NMOUNT], *fs_data;
59 	int ret;
60 
61 	mpp = &mhp;
62 	while ((ret = getmountent(&loc, mountbuffer, NMOUNT)) > 0) {
63 	        for (fs_data = mountbuffer; fs_data < &mountbuffer[ret]; fs_data++) {
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(fs_data);
73 
74 			/*
75 			 * Move to next pointer
76 			 */
77 			mpp = &(*mpp)->mnext;
78 		}
79 	}
80 	if (ret < 0) {
81 		plog(XLOG_ERROR, "getmountent: %m");
82 		return 0;
83 	}
84 	*mpp = 0;
85 
86 	return mhp;
87 }
88 
89 #endif /* READ_MTAB_ULTRIX_STYLE */
90