1 /* 2 * $Id: mtab_bsd.c,v 5.2.1.1 90/10/21 22:30:46 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_bsd.c 5.2 (Berkeley) 03/17/91 15 */ 16 17 #include "am.h" 18 19 #ifdef READ_MTAB_BSD_STYLE 20 21 #include <sys/mount.h> 22 23 static struct mntent *mnt_dup(mp) 24 struct statfs *mp; 25 { 26 struct mntent *new_mp = ALLOC(mntent); 27 char *ty; 28 29 new_mp->mnt_fsname = strdup(mp->f_mntfromname); 30 new_mp->mnt_dir = strdup(mp->f_mntonname); 31 switch (mp->f_type) { 32 case MOUNT_UFS: ty = MTAB_TYPE_UFS; break; 33 case MOUNT_NFS: ty = MTAB_TYPE_NFS; break; 34 case MOUNT_MFS: ty = MTAB_TYPE_MFS; break; 35 default: ty = "unknown"; break; 36 } 37 new_mp->mnt_type = strdup(ty); 38 new_mp->mnt_opts = strdup("unset"); 39 new_mp->mnt_freq = 0; 40 new_mp->mnt_passno = 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 struct statfs *mntbufp, *mntp; 53 54 int nloc = getmntinfo(&mntbufp, MNT_NOWAIT); 55 56 if (nloc == 0) { 57 plog(XLOG_ERROR, "Can't read mount table"); 58 return 0; 59 } 60 61 mpp = &mhp; 62 for (mntp = mntbufp; mntp < mntbufp + nloc; mntp++) { 63 /* 64 * Allocate a new slot 65 */ 66 *mpp = ALLOC(mntlist); 67 68 /* 69 * Copy the data returned by getmntent 70 */ 71 (*mpp)->mnt = mnt_dup(mntp); 72 73 /* 74 * Move to next pointer 75 */ 76 mpp = &(*mpp)->mnext; 77 } 78 79 return mhp; 80 } 81 82 #endif /* READ_MTAB_BSD_STYLE */ 83