144630Smckusick /* 244630Smckusick * Copyright (c) 1990 Jan-Simon Pendry 344630Smckusick * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 461785Sbostic * Copyright (c) 1990, 1993 561785Sbostic * The Regents of the University of California. 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*69328Spendry * @(#)mtab_bsd.c 8.2 (Berkeley) 05/10/95 1349685Spendry * 1452452Spendry * $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 mnt_dup(mp)2444630Smckusickstatic 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); 32*69328Spendry #if BSD >= 199506 33*69328Spendry ty = mp->f_fstypename; 34*69328Spendry #else 3544630Smckusick switch (mp->f_type) { 3644630Smckusick case MOUNT_UFS: ty = MTAB_TYPE_UFS; break; 3744630Smckusick case MOUNT_NFS: ty = MTAB_TYPE_NFS; break; 3844630Smckusick case MOUNT_MFS: ty = MTAB_TYPE_MFS; break; 3944630Smckusick default: ty = "unknown"; break; 4044630Smckusick } 41*69328Spendry #endif 4244630Smckusick new_mp->mnt_type = strdup(ty); 4344630Smckusick new_mp->mnt_opts = strdup("unset"); 4444630Smckusick new_mp->mnt_freq = 0; 4544630Smckusick new_mp->mnt_passno = 0; 4644630Smckusick 4744630Smckusick return new_mp; 4844630Smckusick } 4944630Smckusick 5044630Smckusick /* 5144630Smckusick * Read a mount table into memory 5244630Smckusick */ read_mtab(fs)5344630Smckusickmntlist *read_mtab(fs) 5444630Smckusick char *fs; 5544630Smckusick { 5644630Smckusick mntlist **mpp, *mhp; 5744630Smckusick struct statfs *mntbufp, *mntp; 5844630Smckusick 5944630Smckusick int nloc = getmntinfo(&mntbufp, MNT_NOWAIT); 6044630Smckusick 6144630Smckusick if (nloc == 0) { 6244630Smckusick plog(XLOG_ERROR, "Can't read mount table"); 6344630Smckusick return 0; 6444630Smckusick } 6544630Smckusick 6644630Smckusick mpp = &mhp; 6744630Smckusick for (mntp = mntbufp; mntp < mntbufp + nloc; mntp++) { 6844630Smckusick /* 6944630Smckusick * Allocate a new slot 7044630Smckusick */ 7144630Smckusick *mpp = ALLOC(mntlist); 7244630Smckusick 7344630Smckusick /* 7444630Smckusick * Copy the data returned by getmntent 7544630Smckusick */ 7644630Smckusick (*mpp)->mnt = mnt_dup(mntp); 7744630Smckusick 7844630Smckusick /* 7944630Smckusick * Move to next pointer 8044630Smckusick */ 8144630Smckusick mpp = &(*mpp)->mnext; 8244630Smckusick } 8344630Smckusick 8456725Spendry /* 8556725Spendry * Terminate the list 8656725Spendry */ 8756725Spendry *mpp = 0; 8856725Spendry 8944630Smckusick return mhp; 9044630Smckusick } 9144630Smckusick 9244630Smckusick #endif /* READ_MTAB_BSD_STYLE */ 93