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