home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / COMMS / P3NFS / NFSD / MOUNT_AI.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-18  |  4.8 KB  |  171 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: mount_aix.c,v 1.1.1.1 1996/03/18 09:34:01 jnhollma Exp $
  41.  *
  42.  */
  43.  
  44.  
  45. /*
  46.  * AIX 3 Mount helper
  47.  */
  48.  
  49. #include <sys/param.h>
  50. #include <sys/stat.h>
  51. #include <sys/vmount.h>
  52. #include <sys/errno.h>
  53. #include <fcntl.h>
  54.  
  55. #include "misc-aix3.h"
  56. #include "os-aix3.h"
  57.  
  58. typedef void * voidp;
  59.  
  60. #undef DEBUG
  61.  
  62. char hostname[MAXHOSTNAMELEN] = "localhost"; /* Hostname */
  63.  
  64. static int aix3_mkvp(p, gfstype, flags, object, stub, host, info, info_size, args)
  65. char *p;
  66. int gfstype;
  67. int flags;
  68. char *object;
  69. char *stub;
  70. char *host;
  71. char *info;
  72. int info_size;
  73. char *args;
  74. {
  75.     struct vmount *vp = (struct vmount *) p;
  76.     bzero((voidp) vp, sizeof(*vp));
  77.     /*
  78.      * Fill in standard fields
  79.      */
  80.     vp->vmt_revision = VMT_REVISION;
  81.     vp->vmt_flags = flags;
  82.     vp->vmt_gfstype = gfstype;
  83.  
  84. #define    VMT_ROUNDUP(len) (4 * ((len + 3) / 4))
  85. #define VMT_ASSIGN(vp, idx, data, size) \
  86.     vp->vmt_data[idx].vmt_off = p - (char *) vp; \
  87.     vp->vmt_data[idx].vmt_size = size; \
  88.     bcopy(data, p, size); \
  89.     p += VMT_ROUNDUP(size);
  90.  
  91.     /*
  92.      * Fill in all variable length data
  93.      */
  94.     p += sizeof(*vp);
  95.  
  96.     VMT_ASSIGN(vp, VMT_OBJECT, object, strlen(object) + 1);
  97.     VMT_ASSIGN(vp, VMT_STUB, stub, strlen(stub) + 1);
  98.     VMT_ASSIGN(vp, VMT_HOST, host, strlen(host) + 1);
  99.     VMT_ASSIGN(vp, VMT_HOSTNAME, host, strlen(host) + 1);
  100.     VMT_ASSIGN(vp, VMT_INFO, info, info_size);
  101.     VMT_ASSIGN(vp, VMT_ARGS, args, strlen(args) + 1);
  102.  
  103. #undef VMT_ASSIGN
  104. #undef VMT_ROUNDUP
  105.  
  106.     /*
  107.      * Return length
  108.      */
  109.     return vp->vmt_length = p - (char *) vp;
  110. }
  111.  
  112. /*
  113.  * Map from conventional mount arguments
  114.  * to AIX 3-style arguments.
  115.  */
  116. aix3_mount(fsname, dir, flags, type, data, args)
  117. char *fsname;
  118. char *dir;
  119. int flags;
  120. int type;
  121. void *data;
  122. char *args;
  123. {
  124.     char buf[4096];
  125.     int size;
  126.  
  127.         for (size = 0; size < 4096; size++) buf[size] = 0;
  128. #ifdef DEBUG
  129.     printf("aix3_mount: fsname %s, dir %s, type %d\n", fsname, dir, type);
  130. #endif
  131.  
  132. /* aix3_mkvp(p, gfstype, flags, object, stub, host, info, info_size, args) */
  133.  
  134.     switch (type) {
  135.  
  136.     case MOUNT_TYPE_NFS: {
  137.         char *host = strdup(fsname);
  138.         char *rfs = strchr(host, ':');
  139.         int free_rfs = 0;
  140.         if (rfs) {
  141.             *rfs++ = '\0';
  142.         } else {
  143.             rfs = host;
  144.             free_rfs = 1;
  145.             host = strdup(hostname);
  146.         }
  147.  
  148.         size = aix3_mkvp(buf, type, flags, rfs, dir, host, data, sizeof(struct nfs_args), args);
  149.         if (free_rfs)
  150.             free((voidp) rfs);
  151.         free(host);
  152.  
  153.         } break;
  154.  
  155.     case MOUNT_TYPE_UFS:
  156.         /* Need to open block device and extract log device info from sblk. */
  157.         errno = EINVAL;
  158.         return -1;
  159.  
  160.     default:
  161.         errno = EINVAL;
  162.         return -1;
  163.     }
  164. #ifdef DEBUG
  165.     printf("aix3_mkvp: flags %#x, size %d, args %s\n", flags, size, args);
  166.     printf("revision %d\n", ((struct vmount *)buf)->vmt_revision);
  167. #endif
  168.  
  169.     return vmount(buf, size);
  170. }
  171.