xref: /original-bsd/usr.sbin/amd/config/mtab_aix.c (revision c3e32dec)
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_aix.c	8.1 (Berkeley) 06/06/93
13  *
14  * $Id: mtab_aix.c,v 5.2.2.1 1992/02/09 15:10:07 jsp beta $
15  *
16  */
17 
18 #include "am.h"
19 
20 #ifdef READ_MTAB_AIX3_STYLE
21 
22 #include <sys/mntctl.h>
23 #include <sys/vmount.h>
24 
25 static struct mntent *mnt_dup(mp)
26 struct vmount *mp;
27 {
28 	struct mntent *new_mp = ALLOC(mntent);
29 
30 	char *ty;
31 	new_mp->mnt_fsname = strdup(vmt2dataptr(mp, VMT_OBJECT));
32 	new_mp->mnt_dir = strdup(vmt2dataptr(mp, VMT_STUB));
33 	new_mp->mnt_opts = strdup(vmt2dataptr(mp, VMT_ARGS));
34 	switch (mp->vmt_gfstype) {
35 	case MNT_JFS:  ty = MTAB_TYPE_UFS; break;
36 	case MNT_NFS:
37 		ty = MTAB_TYPE_NFS;
38 		new_mp->mnt_fsname = str3cat(new_mp->mnt_fsname,
39 				vmt2dataptr(mp, VMT_HOSTNAME),
40 				":", new_mp->mnt_fsname);
41 		break;
42 	default:  ty = "unknown"; break;
43 	}
44 	new_mp->mnt_type = strdup(ty);
45 	new_mp->mnt_passno = mp->vmt_vfsnumber;
46 	new_mp->mnt_freq = 0;
47 
48 	return new_mp;
49 }
50 
51 /*
52  * Read a mount table into memory
53  */
54 mntlist *read_mtab(fs)
55 char *fs;
56 {
57 	mntlist **mpp, *mhp;
58 
59 	int i;
60 	char *mntinfo = 0, *cp;
61 	struct vmount *vp;
62 	int ret;
63 
64 	/*
65 	 * First figure out size of mount table
66 	 * and allocate space for a copy...
67 	 * Then get mount table for real.
68 	 */
69 	ret = mntctl(MCTL_QUERY, sizeof(i), &i);
70 	if (ret == 0) {
71 		mntinfo = xmalloc(i);
72 		ret = mntctl(MCTL_QUERY, i, mntinfo);
73 	}
74 
75 	if (ret <= 0) {
76 		plog(XLOG_ERROR, "mntctl: %m");
77 		goto out;
78 	}
79 #ifdef DEBUG
80 	/*dlog("mntctl returns %d structures", ret);*/
81 #endif /* DEBUG */
82 
83 	mpp = &mhp;
84 	for (i = 0, cp = mntinfo; i < ret; i++, cp += vp->vmt_length) {
85 		vp = (struct vmount *) cp;
86 
87 		/*
88 		 * Allocate a new slot
89 		 */
90 		*mpp = ALLOC(mntlist);
91 
92 		/*
93 		 * Copy the data returned by mntctl
94 		 */
95 		(*mpp)->mnt = mnt_dup(vp);
96 
97 		/*
98 		 * Move to next pointer
99 		 */
100 		mpp = &(*mpp)->mnext;
101 	}
102 
103 	*mpp = 0;
104 
105 out:
106 	if (mntinfo)
107 		free(mntinfo);
108 	return mhp;
109 }
110 
111 #endif /* READ_MTAB_AIX3_STYLE */
112