Home | History | Annotate | Line # | Download | only in mtab
      1 /*	$NetBSD: mtab_ultrix.c,v 1.1.1.3 2015/01/17 16:34:16 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997-2014 Erez Zadok
      5  * Copyright (c) 1990 Jan-Simon Pendry
      6  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
      7  * Copyright (c) 1990 The Regents of the University of California.
      8  * All rights reserved.
      9  *
     10  * This code is derived from software contributed to Berkeley by
     11  * Jan-Simon Pendry at Imperial College, London.
     12  *
     13  * Redistribution and use in source and binary forms, with or without
     14  * modification, are permitted provided that the following conditions
     15  * are met:
     16  * 1. Redistributions of source code must retain the above copyright
     17  *    notice, this list of conditions and the following disclaimer.
     18  * 2. Redistributions in binary form must reproduce the above copyright
     19  *    notice, this list of conditions and the following disclaimer in the
     20  *    documentation and/or other materials provided with the distribution.
     21  * 3. Neither the name of the University nor the names of its contributors
     22  *    may be used to endorse or promote products derived from this software
     23  *    without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  * SUCH DAMAGE.
     36  *
     37  *
     38  * File: am-utils/conf/mtab/mtab_ultrix.c
     39  *
     40  */
     41 
     42 /*
     43  * Include before config.h to force single definition of gt_names[] here.
     44  * This can be done unconditionally since this file is Ultrix specific
     45  * anyway and <sys/fs_types.h> is properly protected from multiple inclusion.
     46  * - Rainer Orth <ro (at) TechFak.Uni-Bielefeld.DE>
     47  * Hack hack hack.  Sigh. -Erez.
     48  */
     49 #include <sys/fs_types.h>
     50 
     51 #ifdef HAVE_CONFIG_H
     52 # include <config.h>
     53 #endif /* HAVE_CONFIG_H */
     54 #include <am_defs.h>
     55 #include <amu.h>
     56 
     57 #ifndef NMOUNT
     58 # define NMOUNT 20
     59 #endif /* NMOUNT */
     60 
     61 
     62 static mntent_t *
     63 mnt_dup(struct fs_data *mp)
     64 {
     65   mntent_t *new_mp = ALLOC(mntent_t);
     66 
     67   new_mp->mnt_fsname = xstrdup(mp->fd_devname);
     68   new_mp->mnt_dir = xstrdup(mp->fd_path);
     69   if (mp->fd_fstype >= GT_NUMTYPES)
     70     mp->fd_fstype = GT_UNKWN;
     71   else if (gt_names[mp->fd_fstype] == 0)
     72     mp->fd_fstype = GT_UNKWN;
     73   new_mp->mnt_type = xstrdup(gt_names[mp->fd_fstype]);
     74   new_mp->mnt_opts = xstrdup("unset");
     75 
     76   new_mp->mnt_freq = 0;
     77   new_mp->mnt_passno = mp->fd_dev;
     78 
     79   return new_mp;
     80 }
     81 
     82 
     83 /*
     84  * Read a mount table into memory
     85  */
     86 mntlist *
     87 read_mtab(char *fs, const char *mnttabname)
     88 {
     89   mntlist **mpp, *mhp;
     90   /* From: Piete Brooks <pb (at) cl.cam.ac.uk> */
     91   int loc = 0;
     92   struct fs_data mountbuffer[NMOUNT], *fs_data;
     93   int ret;
     94 
     95   mpp = &mhp;
     96   while ((ret = getmountent(&loc, mountbuffer, NMOUNT)) > 0) {
     97     for (fs_data = mountbuffer; fs_data < &mountbuffer[ret]; fs_data++) {
     98       /*
     99        * Allocate a new slot
    100        */
    101       *mpp = ALLOC(struct mntlist);
    102 
    103       /*
    104        * Copy the data returned by getmntent
    105        */
    106       (*mpp)->mnt = mnt_dup(fs_data);
    107 
    108       /*
    109        * Move to next pointer
    110        */
    111       mpp = &(*mpp)->mnext;
    112     }
    113   }
    114   if (ret < 0) {
    115     plog(XLOG_ERROR, "getmountent: %m");
    116     return 0;
    117   }
    118   *mpp = NULL;
    119 
    120   return mhp;
    121 }
    122