144630Smckusick /* 244630Smckusick * Copyright (c) 1990 Jan-Simon Pendry 344630Smckusick * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 444630Smckusick * Copyright (c) 1990 The Regents of the University of California. 544630Smckusick * All rights reserved. 644630Smckusick * 744630Smckusick * This code is derived from software contributed to Berkeley by 844630Smckusick * Jan-Simon Pendry at Imperial College, London. 944630Smckusick * 1044630Smckusick * %sccs.include.redist.c% 1144630Smckusick * 12*52452Spendry * @(#)mtab_bsd.c 5.4 (Berkeley) 02/09/92 1349685Spendry * 14*52452Spendry * $Id: mtab_bsd.c,v 5.2.2.1 1992/02/09 15:10:13 jsp beta $ 1549685Spendry * 1644630Smckusick */ 1744630Smckusick 1844630Smckusick #include "am.h" 1944630Smckusick 2044630Smckusick #ifdef READ_MTAB_BSD_STYLE 2144630Smckusick 2244630Smckusick #include <sys/mount.h> 2344630Smckusick 2444630Smckusick static struct mntent *mnt_dup(mp) 2544630Smckusick struct statfs *mp; 2644630Smckusick { 2744630Smckusick struct mntent *new_mp = ALLOC(mntent); 2844630Smckusick char *ty; 2944630Smckusick 3044630Smckusick new_mp->mnt_fsname = strdup(mp->f_mntfromname); 3144630Smckusick new_mp->mnt_dir = strdup(mp->f_mntonname); 3244630Smckusick switch (mp->f_type) { 3344630Smckusick case MOUNT_UFS: ty = MTAB_TYPE_UFS; break; 3444630Smckusick case MOUNT_NFS: ty = MTAB_TYPE_NFS; break; 3544630Smckusick case MOUNT_MFS: ty = MTAB_TYPE_MFS; break; 3644630Smckusick default: ty = "unknown"; break; 3744630Smckusick } 3844630Smckusick new_mp->mnt_type = strdup(ty); 3944630Smckusick new_mp->mnt_opts = strdup("unset"); 4044630Smckusick new_mp->mnt_freq = 0; 4144630Smckusick new_mp->mnt_passno = 0; 4244630Smckusick 4344630Smckusick return new_mp; 4444630Smckusick } 4544630Smckusick 4644630Smckusick /* 4744630Smckusick * Read a mount table into memory 4844630Smckusick */ 4944630Smckusick mntlist *read_mtab(fs) 5044630Smckusick char *fs; 5144630Smckusick { 5244630Smckusick mntlist **mpp, *mhp; 5344630Smckusick struct statfs *mntbufp, *mntp; 5444630Smckusick 5544630Smckusick int nloc = getmntinfo(&mntbufp, MNT_NOWAIT); 5644630Smckusick 5744630Smckusick if (nloc == 0) { 5844630Smckusick plog(XLOG_ERROR, "Can't read mount table"); 5944630Smckusick return 0; 6044630Smckusick } 6144630Smckusick 6244630Smckusick mpp = &mhp; 6344630Smckusick for (mntp = mntbufp; mntp < mntbufp + nloc; mntp++) { 6444630Smckusick /* 6544630Smckusick * Allocate a new slot 6644630Smckusick */ 6744630Smckusick *mpp = ALLOC(mntlist); 6844630Smckusick 6944630Smckusick /* 7044630Smckusick * Copy the data returned by getmntent 7144630Smckusick */ 7244630Smckusick (*mpp)->mnt = mnt_dup(mntp); 7344630Smckusick 7444630Smckusick /* 7544630Smckusick * Move to next pointer 7644630Smckusick */ 7744630Smckusick mpp = &(*mpp)->mnext; 7844630Smckusick } 7944630Smckusick 8044630Smckusick return mhp; 8144630Smckusick } 8244630Smckusick 8344630Smckusick #endif /* READ_MTAB_BSD_STYLE */ 84