home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.sbin / amd / config / mtab_bsd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-12  |  3.3 KB  |  110 lines

  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.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  * 3. All advertising materials mentioning features or use of this software
  19.  *    must display the following acknowledgement:
  20.  *    This product includes software developed by the University of
  21.  *    California, Berkeley and its contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  *
  38.  *    @(#)mtab_bsd.c    5.3 (Berkeley) 5/12/91
  39.  *
  40.  * $Id: mtab_bsd.c,v 5.2.1.2 91/05/07 22:19:35 jsp Alpha $
  41.  *
  42.  */
  43.  
  44. #include "am.h"
  45.  
  46. #ifdef READ_MTAB_BSD_STYLE
  47.  
  48. #include <sys/mount.h>
  49.  
  50. static struct mntent *mnt_dup(mp)
  51. struct statfs *mp;
  52. {
  53.     struct mntent *new_mp = ALLOC(mntent);
  54.     char *ty;
  55.  
  56.     new_mp->mnt_fsname = strdup(mp->f_mntfromname);
  57.     new_mp->mnt_dir = strdup(mp->f_mntonname);
  58.     switch (mp->f_type) {
  59.     case MOUNT_UFS:  ty = MTAB_TYPE_UFS; break;
  60.     case MOUNT_NFS:  ty = MTAB_TYPE_NFS; break;
  61.     case MOUNT_MFS:  ty = MTAB_TYPE_MFS; break;
  62.     default:  ty = "unknown"; break;
  63.     }
  64.     new_mp->mnt_type = strdup(ty);
  65.     new_mp->mnt_opts = strdup("unset");
  66.     new_mp->mnt_freq = 0;
  67.     new_mp->mnt_passno = 0;
  68.  
  69.     return new_mp;
  70. }
  71.  
  72. /*
  73.  * Read a mount table into memory
  74.  */
  75. mntlist *read_mtab(fs)
  76. char *fs;
  77. {
  78.     mntlist **mpp, *mhp;
  79.     struct statfs *mntbufp, *mntp;
  80.  
  81.     int nloc = getmntinfo(&mntbufp, MNT_NOWAIT);
  82.  
  83.     if (nloc == 0) {
  84.         plog(XLOG_ERROR, "Can't read mount table");
  85.         return 0;
  86.     }
  87.  
  88.     mpp = &mhp;
  89.     for (mntp = mntbufp; mntp < mntbufp + nloc; mntp++) {
  90.         /*
  91.          * Allocate a new slot
  92.          */
  93.         *mpp = ALLOC(mntlist);
  94.  
  95.         /*
  96.          * Copy the data returned by getmntent
  97.          */
  98.         (*mpp)->mnt = mnt_dup(mntp);
  99.  
  100.         /*
  101.          * Move to next pointer
  102.          */
  103.         mpp = &(*mpp)->mnext;
  104.     }
  105.  
  106.     return mhp;
  107. }
  108.  
  109. #endif /* READ_MTAB_BSD_STYLE */
  110.