xref: /csrg-svn/usr.sbin/amd/config/mtab_aix.c (revision 61785)
144630Smckusick /*
244630Smckusick  * Copyright (c) 1990 Jan-Simon Pendry
344630Smckusick  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
4*61785Sbostic  * Copyright (c) 1990, 1993
5*61785Sbostic  *	The Regents of the University of California.  All rights reserved.
644630Smckusick  *
744630Smckusick  * This code is derived from software contributed to Berkeley by
844630Smckusick  * Jan-Simon Pendry at Imperial College, London.
944630Smckusick  *
1044630Smckusick  * %sccs.include.redist.c%
1144630Smckusick  *
12*61785Sbostic  *	@(#)mtab_aix.c	8.1 (Berkeley) 06/06/93
1349685Spendry  *
1452452Spendry  * $Id: mtab_aix.c,v 5.2.2.1 1992/02/09 15:10:07 jsp beta $
1549685Spendry  *
1644630Smckusick  */
1744630Smckusick 
1844630Smckusick #include "am.h"
1944630Smckusick 
2044630Smckusick #ifdef READ_MTAB_AIX3_STYLE
2144630Smckusick 
2244630Smckusick #include <sys/mntctl.h>
2344630Smckusick #include <sys/vmount.h>
2444630Smckusick 
mnt_dup(mp)2544630Smckusick static struct mntent *mnt_dup(mp)
2644630Smckusick struct vmount *mp;
2744630Smckusick {
2844630Smckusick 	struct mntent *new_mp = ALLOC(mntent);
2944630Smckusick 
3044630Smckusick 	char *ty;
3144630Smckusick 	new_mp->mnt_fsname = strdup(vmt2dataptr(mp, VMT_OBJECT));
3244630Smckusick 	new_mp->mnt_dir = strdup(vmt2dataptr(mp, VMT_STUB));
3344630Smckusick 	new_mp->mnt_opts = strdup(vmt2dataptr(mp, VMT_ARGS));
3444630Smckusick 	switch (mp->vmt_gfstype) {
3544630Smckusick 	case MNT_JFS:  ty = MTAB_TYPE_UFS; break;
3647534Spendry 	case MNT_NFS:
3747534Spendry 		ty = MTAB_TYPE_NFS;
3847534Spendry 		new_mp->mnt_fsname = str3cat(new_mp->mnt_fsname,
3947534Spendry 				vmt2dataptr(mp, VMT_HOSTNAME),
4047534Spendry 				":", new_mp->mnt_fsname);
4147534Spendry 		break;
4244630Smckusick 	default:  ty = "unknown"; break;
4344630Smckusick 	}
4444630Smckusick 	new_mp->mnt_type = strdup(ty);
4544630Smckusick 	new_mp->mnt_passno = mp->vmt_vfsnumber;
4644630Smckusick 	new_mp->mnt_freq = 0;
4744630Smckusick 
4844630Smckusick 	return new_mp;
4944630Smckusick }
5044630Smckusick 
5144630Smckusick /*
5244630Smckusick  * Read a mount table into memory
5344630Smckusick  */
read_mtab(fs)5444630Smckusick mntlist *read_mtab(fs)
5544630Smckusick char *fs;
5644630Smckusick {
5744630Smckusick 	mntlist **mpp, *mhp;
5844630Smckusick 
5944630Smckusick 	int i;
6044630Smckusick 	char *mntinfo = 0, *cp;
6144630Smckusick 	struct vmount *vp;
6244630Smckusick 	int ret;
6344630Smckusick 
6444630Smckusick 	/*
6544630Smckusick 	 * First figure out size of mount table
6644630Smckusick 	 * and allocate space for a copy...
6744630Smckusick 	 * Then get mount table for real.
6844630Smckusick 	 */
6944630Smckusick 	ret = mntctl(MCTL_QUERY, sizeof(i), &i);
7044630Smckusick 	if (ret == 0) {
7144630Smckusick 		mntinfo = xmalloc(i);
7244630Smckusick 		ret = mntctl(MCTL_QUERY, i, mntinfo);
7344630Smckusick 	}
7444630Smckusick 
7544630Smckusick 	if (ret <= 0) {
7644630Smckusick 		plog(XLOG_ERROR, "mntctl: %m");
7744630Smckusick 		goto out;
7844630Smckusick 	}
7944630Smckusick #ifdef DEBUG
8044630Smckusick 	/*dlog("mntctl returns %d structures", ret);*/
8144630Smckusick #endif /* DEBUG */
8244630Smckusick 
8344630Smckusick 	mpp = &mhp;
8444630Smckusick 	for (i = 0, cp = mntinfo; i < ret; i++, cp += vp->vmt_length) {
8544630Smckusick 		vp = (struct vmount *) cp;
8644630Smckusick 
8744630Smckusick 		/*
8844630Smckusick 		 * Allocate a new slot
8944630Smckusick 		 */
9044630Smckusick 		*mpp = ALLOC(mntlist);
9144630Smckusick 
9244630Smckusick 		/*
9344630Smckusick 		 * Copy the data returned by mntctl
9444630Smckusick 		 */
9544630Smckusick 		(*mpp)->mnt = mnt_dup(vp);
9644630Smckusick 
9744630Smckusick 		/*
9844630Smckusick 		 * Move to next pointer
9944630Smckusick 		 */
10044630Smckusick 		mpp = &(*mpp)->mnext;
10144630Smckusick 	}
10244630Smckusick 
10344630Smckusick 	*mpp = 0;
10444630Smckusick 
10544630Smckusick out:
10644630Smckusick 	if (mntinfo)
10744630Smckusick 		free(mntinfo);
10844630Smckusick 	return mhp;
10944630Smckusick }
11044630Smckusick 
11144630Smckusick #endif /* READ_MTAB_AIX3_STYLE */
112