home *** CD-ROM | disk | FTP | other *** search
/ Boot Disc 8 / boot-disc-1997-04.iso / PDA_Soft / Psion / comms / p3nfs / nfsd / mtab_aix.c < prev    next >
C/C++ Source or Header  |  1996-03-17  |  4KB  |  146 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.  *    %W% (Berkeley) %G%
  39.  *
  40.  * $Id: mtab_aix.c,v 1.1.1.1 1996/03/18 09:34:01 jnhollma Exp $
  41.  *
  42.  */
  43.  
  44.  
  45. #ifdef READ_MTAB_AIX3_STYLE
  46.  
  47. #include <sys/mntctl.h>
  48. #include <sys/vmount.h>
  49.  
  50. static struct mntent *mnt_dup(mp)
  51. struct vmount *mp;
  52. {
  53.     struct mntent *new_mp = ALLOC(mntent);
  54.  
  55.     char *ty;
  56.     char *fsname = strdup(vmt2dataptr(mp, VMT_OBJECT));
  57.     new_mp->mnt_dir = strdup(vmt2dataptr(mp, VMT_STUB));
  58.     new_mp->mnt_opts = strdup(vmt2dataptr(mp, VMT_ARGS));
  59.     switch (mp->vmt_gfstype) {
  60.     case MNT_JFS:
  61.         ty = MTAB_TYPE_UFS;
  62.         new_mp->mnt_fsname = strdup(fsname);
  63.         break;
  64.  
  65.     case MNT_NFS:
  66.         ty = MTAB_TYPE_NFS;
  67.         new_mp->mnt_fsname = str3cat((char *) 0,
  68.                 vmt2dataptr(mp, VMT_HOSTNAME), ":", fsname);
  69.         break;
  70.  
  71.     default:
  72.         ty = "unknown";
  73.         new_mp->mnt_fsname = strdup(fsname);
  74.         break;
  75.     }
  76.     new_mp->mnt_type = strdup(ty);
  77.     new_mp->mnt_passno = mp->vmt_vfsnumber;
  78.     new_mp->mnt_freq = 0;
  79.  
  80.     free(fsname);
  81.  
  82.     return new_mp;
  83. }
  84.  
  85. /*
  86.  * Read a mount table into memory
  87.  */
  88. mntlist *read_mtab(fs)
  89. char *fs;
  90. {
  91.     mntlist **mpp, *mhp;
  92.  
  93.     int i;
  94.     char *mntinfo = 0, *cp;
  95.     struct vmount *vp;
  96.     int ret;
  97.  
  98.     /*
  99.      * First figure out size of mount table
  100.      * and allocate space for a copy...
  101.      * Then get mount table for real.
  102.      */
  103.     ret = mntctl(MCTL_QUERY, sizeof(i), &i);
  104.     if (ret == 0) {
  105.         mntinfo = xmalloc(i);
  106.         ret = mntctl(MCTL_QUERY, i, mntinfo);
  107.     }
  108.  
  109.     if (ret <= 0) {
  110.         plog(XLOG_ERROR, "mntctl: %m");
  111.         goto out;
  112.     }
  113. #ifdef DEBUG
  114.     /*dlog("mntctl returns %d structures", ret);*/
  115. #endif /* DEBUG */
  116.  
  117.     mpp = &mhp;
  118.     for (i = 0, cp = mntinfo; i < ret; i++, cp += vp->vmt_length) {
  119.         vp = (struct vmount *) cp;
  120.  
  121.         /*
  122.          * Allocate a new slot
  123.          */
  124.         *mpp = ALLOC(mntlist);
  125.  
  126.         /*
  127.          * Copy the data returned by mntctl
  128.          */
  129.         (*mpp)->mnt = mnt_dup(vp);
  130.  
  131.         /*
  132.          * Move to next pointer
  133.          */
  134.         mpp = &(*mpp)->mnext;
  135.     }
  136.  
  137.     *mpp = 0;
  138.  
  139. out:
  140.     if (mntinfo)
  141.         free(mntinfo);
  142.     return mhp;
  143. }
  144.  
  145. #endif /* READ_MTAB_AIX3_STYLE */
  146.