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_bsd.c 8.2 (Berkeley) 05/10/95 13 * 14 * $Id: mtab_bsd.c,v 5.2.2.1 1992/02/09 15:10:13 jsp beta $ 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 #if BSD >= 199506 33 ty = mp->f_fstypename; 34 #else 35 switch (mp->f_type) { 36 case MOUNT_UFS: ty = MTAB_TYPE_UFS; break; 37 case MOUNT_NFS: ty = MTAB_TYPE_NFS; break; 38 case MOUNT_MFS: ty = MTAB_TYPE_MFS; break; 39 default: ty = "unknown"; break; 40 } 41 #endif 42 new_mp->mnt_type = strdup(ty); 43 new_mp->mnt_opts = strdup("unset"); 44 new_mp->mnt_freq = 0; 45 new_mp->mnt_passno = 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 struct statfs *mntbufp, *mntp; 58 59 int nloc = getmntinfo(&mntbufp, MNT_NOWAIT); 60 61 if (nloc == 0) { 62 plog(XLOG_ERROR, "Can't read mount table"); 63 return 0; 64 } 65 66 mpp = &mhp; 67 for (mntp = mntbufp; mntp < mntbufp + nloc; mntp++) { 68 /* 69 * Allocate a new slot 70 */ 71 *mpp = ALLOC(mntlist); 72 73 /* 74 * Copy the data returned by getmntent 75 */ 76 (*mpp)->mnt = mnt_dup(mntp); 77 78 /* 79 * Move to next pointer 80 */ 81 mpp = &(*mpp)->mnext; 82 } 83 84 /* 85 * Terminate the list 86 */ 87 *mpp = 0; 88 89 return mhp; 90 } 91 92 #endif /* READ_MTAB_BSD_STYLE */ 93