1 /* 2 * Copyright (c) 1990 Jan-Simon Pendry 3 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 4 * Copyright (c) 1990 The Regents of the University of California. 5 * 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_bsd.c 5.3 (Berkeley) 05/12/91 13 * 14 * $Id: mtab_bsd.c,v 5.2.1.2 91/05/07 22:19:35 jsp Alpha $ 15 * 16 */ 17 18 #include "am.h" 19 20 #ifdef READ_MTAB_BSD_STYLE 21 22 #include <sys/mount.h> 23 24 static struct mntent *mnt_dup(mp) 25 struct statfs *mp; 26 { 27 struct mntent *new_mp = ALLOC(mntent); 28 char *ty; 29 30 new_mp->mnt_fsname = strdup(mp->f_mntfromname); 31 new_mp->mnt_dir = strdup(mp->f_mntonname); 32 switch (mp->f_type) { 33 case MOUNT_UFS: ty = MTAB_TYPE_UFS; break; 34 case MOUNT_NFS: ty = MTAB_TYPE_NFS; break; 35 case MOUNT_MFS: ty = MTAB_TYPE_MFS; break; 36 default: ty = "unknown"; break; 37 } 38 new_mp->mnt_type = strdup(ty); 39 new_mp->mnt_opts = strdup("unset"); 40 new_mp->mnt_freq = 0; 41 new_mp->mnt_passno = 0; 42 43 return new_mp; 44 } 45 46 /* 47 * Read a mount table into memory 48 */ 49 mntlist *read_mtab(fs) 50 char *fs; 51 { 52 mntlist **mpp, *mhp; 53 struct statfs *mntbufp, *mntp; 54 55 int nloc = getmntinfo(&mntbufp, MNT_NOWAIT); 56 57 if (nloc == 0) { 58 plog(XLOG_ERROR, "Can't read mount table"); 59 return 0; 60 } 61 62 mpp = &mhp; 63 for (mntp = mntbufp; mntp < mntbufp + nloc; mntp++) { 64 /* 65 * Allocate a new slot 66 */ 67 *mpp = ALLOC(mntlist); 68 69 /* 70 * Copy the data returned by getmntent 71 */ 72 (*mpp)->mnt = mnt_dup(mntp); 73 74 /* 75 * Move to next pointer 76 */ 77 mpp = &(*mpp)->mnext; 78 } 79 80 return mhp; 81 } 82 83 #endif /* READ_MTAB_BSD_STYLE */ 84