1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 1990-1997 by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <errno.h> 30 #include <sys/types.h> 31 #include <rpc/types.h> 32 #include <sys/time.h> 33 #include <sys/mount.h> 34 #include <sys/syscall.h> 35 #include <netinet/in.h> 36 37 38 #define GETFSIND 1 /* translate fs id to ftype index */ 39 #define CLIENT 1 /* #defined in <pn.h> */ 40 #define MS_RFFLAGS (MS_CACHE) 41 42 /* 43 * Flags bits passed to mount(2), from the SVR4 sys/mount.h header file. 44 */ 45 #define MS_RDONLY 0x01 /* read only bit */ 46 #define MS_DATA 0x04 /* 6-argument mount */ 47 #define MS_NOSUID 0x10 /* Setuid programs disallowed */ 48 #define MS_REMOUNT 0x20 /* Remount */ 49 #define MS_NOTRUNC 0x40 /* Return ENAMETOOLONG for long filenames */ 50 51 /* 52 * structs netbuf, knetconfig, and nfsarg from SVR4 53 */ 54 55 56 struct netbuf { 57 unsigned int maxlen; 58 unsigned int len; 59 char *buf; 60 }; 61 62 struct knetconfig { 63 unsigned long knc_semantics; /* token name */ 64 char *knc_protofmly; /* protocol family */ 65 char *knc_proto; /* protocol */ 66 dev_t knc_rdev; /* device id */ 67 unsigned long knc_unused[8]; 68 }; 69 70 struct nfsarg { 71 struct netbuf *addr; /* file server address */ 72 /* secure NFS time sync address */ 73 struct netbuf *syncaddr; 74 /* transport knetconfig struct */ 75 struct knetconfig *knconf; 76 char *hostname; /* server's hostname */ 77 char *netname; /* server's netname */ 78 caddr_t fh; /* File handle to be mounted */ 79 int flags; /* flags */ 80 int wsize; /* write size in bytes */ 81 int rsize; /* read size in bytes */ 82 int timeo; /* initial timeout in .1 secs */ 83 int retrans; /* times to retry send */ 84 int acregmin; /* attr cache file min secs */ 85 int acregmax; /* attr cache file max secs */ 86 int acdirmin; /* attr cache dir min secs */ 87 int acdirmax; /* attr cache dir max secs */ 88 }; 89 90 int 91 mount(type, dir, flags, data) 92 char *type, *dir; 93 int flags; 94 caddr_t data; 95 { 96 int idx, nflags = 0; 97 int returnValue; 98 char fstr[32]; 99 struct nfsarg narg; 100 struct nfsarg *na = &narg; 101 struct nfs_args *nfsa; 102 103 if (strcmp(type, "4.2") == 0) 104 strcpy(fstr, "ufs"); 105 else if (strcmp(type, "lo") == 0) 106 strcpy(fstr, "lo"); 107 else if (strcmp(type, "nfs") == 0) 108 strcpy(fstr, "nfs"); 109 110 if ((idx = sysfs(GETFSIND, fstr)) == -1) 111 return (-1); 112 113 nflags = MS_NOTRUNC; 114 switch (flags) { 115 case M_RDONLY: nflags |= MS_RDONLY; 116 case M_NOSUID: nflags |= MS_NOSUID; 117 case M_REMOUNT: nflags |= MS_REMOUNT; 118 } 119 120 if (strcmp(type, "4.2") == 0) 121 return (_syscall(SYS_mount, data, dir, nflags, idx, 0, 0)); 122 else if (strcmp(type, "lo") == 0) 123 return (_syscall(SYS_mount, data, dir, nflags, idx, 0, 0)); 124 else if (strcmp(type, "nfs") == 0) { 125 nflags |= MS_DATA; 126 nfsa = (struct nfs_args *)data; 127 if ((na->addr = 128 (struct netbuf *)malloc(sizeof (struct netbuf))) == NULL) 129 return (-1); 130 if ((na->syncaddr = 131 (struct netbuf *)malloc(sizeof (struct netbuf))) == NULL) { 132 free(na->addr); 133 return (-1); 134 } 135 if ((na->knconf = 136 (struct knetconfig *)malloc(sizeof (struct knetconfig))) == NULL) { 137 free(na->addr); 138 free(na->syncaddr); 139 return (-1); 140 } 141 na->addr->maxlen = sizeof (struct sockaddr_in); 142 na->addr->len = na->addr->maxlen; 143 na->addr->buf = (char *)nfsa->addr; 144 na->syncaddr->maxlen = na->addr->maxlen; 145 na->syncaddr->len = na->syncaddr->maxlen; 146 na->syncaddr->buf = (char *)nfsa->addr; 147 strcpy(na->hostname, nfsa->hostname); 148 strcpy(na->netname, nfsa->netname); 149 na->fh = nfsa->fh; 150 na->flags = nfsa->flags; 151 na->wsize = nfsa->wsize; 152 na->rsize = nfsa->rsize; 153 na->timeo = nfsa->timeo; 154 na->retrans = nfsa->retrans; 155 na->acregmin = nfsa->acregmin; 156 na->acregmax = nfsa->acregmax; 157 na->acdirmin = nfsa->acdirmin; 158 na->acdirmax = nfsa->acdirmax; 159 returnValue = (_syscall(SYS_mount, data, dir, nflags, idx, na, 160 sizeof (struct nfsarg))); 161 free(na->addr); 162 free(na->syncaddr); 163 free(na->knconf); 164 return (returnValue); 165 } 166 } 167