1 /*
2  * $Id: mtab_ultrix.c,v 5.2.1.1 90/10/21 22:31:08 jsp Exp $
3  *
4  * Copyright (c) 1990 Jan-Simon Pendry
5  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
6  * Copyright (c) 1990 The Regents of the University of California.
7  * All rights reserved.
8  *
9  * This code is derived from software contributed to Berkeley by
10  * Jan-Simon Pendry at Imperial College, London.
11  *
12  * %sccs.include.redist.c%
13  *
14  *	@(#)mtab_ultrix.c	5.2 (Berkeley) 03/17/91
15  */
16 
17 #include "am.h"
18 
19 #ifdef READ_MTAB_ULTRIX_STYLE
20 
21 #include <sys/mount.h>
22 #include <sys/fs_types.h>
23 
24 static struct mntent *mnt_dup(mp)
25 struct fs_data *mp;
26 {
27 	struct mntent *new_mp = ALLOC(mntent);
28 
29 	new_mp->mnt_fsname = strdup(mp->fd_devname);
30 	new_mp->mnt_dir = strdup(mp->fd_path);
31         if (mp->fd_fstype >= GT_NUMTYPES)
32                 mp->fd_fstype = GT_UNKWN;
33         else if (gt_names[mp->fd_fstype] == 0)
34                 mp->fd_fstype = GT_UNKWN;
35         new_mp->mnt_type = strdup(gt_names[mp->fd_fstype]);
36 	new_mp->mnt_opts = strdup("unset");
37 
38 	new_mp->mnt_freq = 0;
39 	new_mp->mnt_passno = mp->fd_dev;
40 
41 	return new_mp;
42 }
43 
44 /*
45  * Read a mount table into memory
46  */
47 mntlist *read_mtab(fs)
48 char *fs;
49 {
50 	mntlist **mpp, *mhp;
51 
52 /* From: Piete Brooks <pb@cl.cam.ac.uk> */
53 
54 	int loc=0;
55 #undef	NMOUNT
56 #define	NMOUNT	20
57 	struct fs_data mountbuffer[NMOUNT], *fs_data;
58 	int ret;
59 
60 	mpp = &mhp;
61 	while ((ret = getmountent(&loc, mountbuffer, NMOUNT)) > 0) {
62 	        for (fs_data = mountbuffer; fs_data < &mountbuffer[ret]; fs_data++) {
63 			/*
64 			 * Allocate a new slot
65 			 */
66 			*mpp = ALLOC(mntlist);
67 
68 			/*
69 			 * Copy the data returned by getmntent
70 			 */
71 			(*mpp)->mnt = mnt_dup(fs_data);
72 
73 			/*
74 			 * Move to next pointer
75 			 */
76 			mpp = &(*mpp)->mnext;
77 		}
78 	}
79 	if (ret < 0) {
80 		plog(XLOG_ERROR, "getmountent: %m");
81 		return 0;
82 	}
83 	*mpp = 0;
84 
85 	return mhp;
86 }
87 
88 #endif /* READ_MTAB_ULTRIX_STYLE */
89