1 /* 2 * $Id: mtab_aix.c,v 5.2.1.1 90/10/21 22:30:40 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_aix.c 5.2 (Berkeley) 03/17/91 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: 36 ty = MTAB_TYPE_NFS; 37 new_mp->mnt_fsname = str3cat(new_mp->mnt_fsname, 38 vmt2dataptr(mp, VMT_HOSTNAME), 39 ":", new_mp->mnt_fsname); 40 break; 41 default: ty = "unknown"; break; 42 } 43 new_mp->mnt_type = strdup(ty); 44 new_mp->mnt_passno = mp->vmt_vfsnumber; 45 new_mp->mnt_freq = 0; 46 47 return new_mp; 48 } 49 50 /* 51 * Read a mount table into memory 52 */ 53 mntlist *read_mtab(fs) 54 char *fs; 55 { 56 mntlist **mpp, *mhp; 57 58 int i; 59 char *mntinfo = 0, *cp; 60 struct vmount *vp; 61 int ret; 62 63 /* 64 * First figure out size of mount table 65 * and allocate space for a copy... 66 * Then get mount table for real. 67 */ 68 ret = mntctl(MCTL_QUERY, sizeof(i), &i); 69 if (ret == 0) { 70 mntinfo = xmalloc(i); 71 ret = mntctl(MCTL_QUERY, i, mntinfo); 72 } 73 74 if (ret <= 0) { 75 plog(XLOG_ERROR, "mntctl: %m"); 76 goto out; 77 } 78 #ifdef DEBUG 79 /*dlog("mntctl returns %d structures", ret);*/ 80 #endif /* DEBUG */ 81 82 mpp = &mhp; 83 for (i = 0, cp = mntinfo; i < ret; i++, cp += vp->vmt_length) { 84 vp = (struct vmount *) cp; 85 86 /* 87 * Allocate a new slot 88 */ 89 *mpp = ALLOC(mntlist); 90 91 /* 92 * Copy the data returned by mntctl 93 */ 94 (*mpp)->mnt = mnt_dup(vp); 95 96 /* 97 * Move to next pointer 98 */ 99 mpp = &(*mpp)->mnext; 100 } 101 102 *mpp = 0; 103 104 out: 105 if (mntinfo) 106 free(mntinfo); 107 return mhp; 108 } 109 110 #endif /* READ_MTAB_AIX3_STYLE */ 111