17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
23*5d54f3d8Smuffin * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24*5d54f3d8Smuffin * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include <errno.h>
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <rpc/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/time.h>
337c478bd9Sstevel@tonic-gate #include <sys/mount.h>
347c478bd9Sstevel@tonic-gate #include <sys/syscall.h>
357c478bd9Sstevel@tonic-gate #include <netinet/in.h>
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate #define GETFSIND 1 /* translate fs id to ftype index */
397c478bd9Sstevel@tonic-gate #define CLIENT 1 /* #defined in <pn.h> */
407c478bd9Sstevel@tonic-gate #define MS_RFFLAGS (MS_CACHE)
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate * Flags bits passed to mount(2), from the SVR4 sys/mount.h header file.
447c478bd9Sstevel@tonic-gate */
457c478bd9Sstevel@tonic-gate #define MS_RDONLY 0x01 /* read only bit */
467c478bd9Sstevel@tonic-gate #define MS_DATA 0x04 /* 6-argument mount */
477c478bd9Sstevel@tonic-gate #define MS_NOSUID 0x10 /* Setuid programs disallowed */
487c478bd9Sstevel@tonic-gate #define MS_REMOUNT 0x20 /* Remount */
497c478bd9Sstevel@tonic-gate #define MS_NOTRUNC 0x40 /* Return ENAMETOOLONG for long filenames */
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate * structs netbuf, knetconfig, and nfsarg from SVR4
537c478bd9Sstevel@tonic-gate */
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate struct netbuf {
577c478bd9Sstevel@tonic-gate unsigned int maxlen;
587c478bd9Sstevel@tonic-gate unsigned int len;
597c478bd9Sstevel@tonic-gate char *buf;
607c478bd9Sstevel@tonic-gate };
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate struct knetconfig {
637c478bd9Sstevel@tonic-gate unsigned long knc_semantics; /* token name */
647c478bd9Sstevel@tonic-gate char *knc_protofmly; /* protocol family */
657c478bd9Sstevel@tonic-gate char *knc_proto; /* protocol */
667c478bd9Sstevel@tonic-gate dev_t knc_rdev; /* device id */
677c478bd9Sstevel@tonic-gate unsigned long knc_unused[8];
687c478bd9Sstevel@tonic-gate };
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate struct nfsarg {
717c478bd9Sstevel@tonic-gate struct netbuf *addr; /* file server address */
727c478bd9Sstevel@tonic-gate /* secure NFS time sync address */
737c478bd9Sstevel@tonic-gate struct netbuf *syncaddr;
747c478bd9Sstevel@tonic-gate /* transport knetconfig struct */
757c478bd9Sstevel@tonic-gate struct knetconfig *knconf;
767c478bd9Sstevel@tonic-gate char *hostname; /* server's hostname */
777c478bd9Sstevel@tonic-gate char *netname; /* server's netname */
787c478bd9Sstevel@tonic-gate caddr_t fh; /* File handle to be mounted */
797c478bd9Sstevel@tonic-gate int flags; /* flags */
807c478bd9Sstevel@tonic-gate int wsize; /* write size in bytes */
817c478bd9Sstevel@tonic-gate int rsize; /* read size in bytes */
827c478bd9Sstevel@tonic-gate int timeo; /* initial timeout in .1 secs */
837c478bd9Sstevel@tonic-gate int retrans; /* times to retry send */
847c478bd9Sstevel@tonic-gate int acregmin; /* attr cache file min secs */
857c478bd9Sstevel@tonic-gate int acregmax; /* attr cache file max secs */
867c478bd9Sstevel@tonic-gate int acdirmin; /* attr cache dir min secs */
877c478bd9Sstevel@tonic-gate int acdirmax; /* attr cache dir max secs */
887c478bd9Sstevel@tonic-gate };
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate int
mount(char * type,char * dir,int flags,caddr_t data)91*5d54f3d8Smuffin mount(char *type, char *dir, int flags, caddr_t data)
927c478bd9Sstevel@tonic-gate {
937c478bd9Sstevel@tonic-gate int idx, nflags = 0;
947c478bd9Sstevel@tonic-gate int returnValue;
957c478bd9Sstevel@tonic-gate char fstr[32];
967c478bd9Sstevel@tonic-gate struct nfsarg narg;
977c478bd9Sstevel@tonic-gate struct nfsarg *na = &narg;
987c478bd9Sstevel@tonic-gate struct nfs_args *nfsa;
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate if (strcmp(type, "4.2") == 0)
1017c478bd9Sstevel@tonic-gate strcpy(fstr, "ufs");
1027c478bd9Sstevel@tonic-gate else if (strcmp(type, "lo") == 0)
1037c478bd9Sstevel@tonic-gate strcpy(fstr, "lo");
1047c478bd9Sstevel@tonic-gate else if (strcmp(type, "nfs") == 0)
1057c478bd9Sstevel@tonic-gate strcpy(fstr, "nfs");
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate if ((idx = sysfs(GETFSIND, fstr)) == -1)
1087c478bd9Sstevel@tonic-gate return (-1);
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate nflags = MS_NOTRUNC;
1117c478bd9Sstevel@tonic-gate switch (flags) {
1127c478bd9Sstevel@tonic-gate case M_RDONLY: nflags |= MS_RDONLY;
1137c478bd9Sstevel@tonic-gate case M_NOSUID: nflags |= MS_NOSUID;
1147c478bd9Sstevel@tonic-gate case M_REMOUNT: nflags |= MS_REMOUNT;
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate if (strcmp(type, "4.2") == 0)
1187c478bd9Sstevel@tonic-gate return (_syscall(SYS_mount, data, dir, nflags, idx, 0, 0));
1197c478bd9Sstevel@tonic-gate else if (strcmp(type, "lo") == 0)
1207c478bd9Sstevel@tonic-gate return (_syscall(SYS_mount, data, dir, nflags, idx, 0, 0));
1217c478bd9Sstevel@tonic-gate else if (strcmp(type, "nfs") == 0) {
1227c478bd9Sstevel@tonic-gate nflags |= MS_DATA;
1237c478bd9Sstevel@tonic-gate nfsa = (struct nfs_args *)data;
1247c478bd9Sstevel@tonic-gate if ((na->addr =
1257c478bd9Sstevel@tonic-gate (struct netbuf *)malloc(sizeof (struct netbuf))) == NULL)
1267c478bd9Sstevel@tonic-gate return (-1);
1277c478bd9Sstevel@tonic-gate if ((na->syncaddr =
1287c478bd9Sstevel@tonic-gate (struct netbuf *)malloc(sizeof (struct netbuf))) == NULL) {
1297c478bd9Sstevel@tonic-gate free(na->addr);
1307c478bd9Sstevel@tonic-gate return (-1);
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate if ((na->knconf =
1337c478bd9Sstevel@tonic-gate (struct knetconfig *)malloc(sizeof (struct knetconfig))) == NULL) {
1347c478bd9Sstevel@tonic-gate free(na->addr);
1357c478bd9Sstevel@tonic-gate free(na->syncaddr);
1367c478bd9Sstevel@tonic-gate return (-1);
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate na->addr->maxlen = sizeof (struct sockaddr_in);
1397c478bd9Sstevel@tonic-gate na->addr->len = na->addr->maxlen;
1407c478bd9Sstevel@tonic-gate na->addr->buf = (char *)nfsa->addr;
1417c478bd9Sstevel@tonic-gate na->syncaddr->maxlen = na->addr->maxlen;
1427c478bd9Sstevel@tonic-gate na->syncaddr->len = na->syncaddr->maxlen;
1437c478bd9Sstevel@tonic-gate na->syncaddr->buf = (char *)nfsa->addr;
1447c478bd9Sstevel@tonic-gate strcpy(na->hostname, nfsa->hostname);
1457c478bd9Sstevel@tonic-gate strcpy(na->netname, nfsa->netname);
1467c478bd9Sstevel@tonic-gate na->fh = nfsa->fh;
1477c478bd9Sstevel@tonic-gate na->flags = nfsa->flags;
1487c478bd9Sstevel@tonic-gate na->wsize = nfsa->wsize;
1497c478bd9Sstevel@tonic-gate na->rsize = nfsa->rsize;
1507c478bd9Sstevel@tonic-gate na->timeo = nfsa->timeo;
1517c478bd9Sstevel@tonic-gate na->retrans = nfsa->retrans;
1527c478bd9Sstevel@tonic-gate na->acregmin = nfsa->acregmin;
1537c478bd9Sstevel@tonic-gate na->acregmax = nfsa->acregmax;
1547c478bd9Sstevel@tonic-gate na->acdirmin = nfsa->acdirmin;
1557c478bd9Sstevel@tonic-gate na->acdirmax = nfsa->acdirmax;
1567c478bd9Sstevel@tonic-gate returnValue = (_syscall(SYS_mount, data, dir, nflags, idx, na,
1577c478bd9Sstevel@tonic-gate sizeof (struct nfsarg)));
1587c478bd9Sstevel@tonic-gate free(na->addr);
1597c478bd9Sstevel@tonic-gate free(na->syncaddr);
1607c478bd9Sstevel@tonic-gate free(na->knconf);
1617c478bd9Sstevel@tonic-gate return (returnValue);
1627c478bd9Sstevel@tonic-gate }
163*5d54f3d8Smuffin return (-1);
1647c478bd9Sstevel@tonic-gate }
165