xref: /titanic_44/usr/src/lib/libbc/libc/sys/4.2/mount.c (revision 62a24de03df1f2399ceda704cb3874dabc98bbbd)
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 1997 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
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(char *type, char *dir, int flags, caddr_t data)
92 {
93 	int idx, nflags = 0;
94 	int returnValue;
95 	char fstr[32];
96 	struct nfsarg narg;
97 	struct nfsarg *na = &narg;
98 	struct nfs_args *nfsa;
99 
100 	if (strcmp(type, "4.2") == 0)
101 		strcpy(fstr, "ufs");
102 	else if (strcmp(type, "lo") == 0)
103 		strcpy(fstr, "lo");
104 	else if (strcmp(type, "nfs") == 0)
105 		strcpy(fstr, "nfs");
106 
107 	if ((idx = sysfs(GETFSIND, fstr)) == -1)
108 		return (-1);
109 
110 	nflags = MS_NOTRUNC;
111 	switch (flags) {
112 		case M_RDONLY: nflags |= MS_RDONLY;
113 		case M_NOSUID: nflags |= MS_NOSUID;
114 		case M_REMOUNT: nflags |= MS_REMOUNT;
115 	}
116 
117 	if (strcmp(type, "4.2") == 0)
118 		return (_syscall(SYS_mount, data, dir, nflags, idx, 0, 0));
119 	else if (strcmp(type, "lo") == 0)
120 		return (_syscall(SYS_mount, data, dir, nflags, idx, 0, 0));
121 	else if (strcmp(type, "nfs") == 0) {
122 		nflags |= MS_DATA;
123 		nfsa = (struct nfs_args *)data;
124 		if ((na->addr =
125 		    (struct netbuf *)malloc(sizeof (struct netbuf))) == NULL)
126 			return (-1);
127 		if ((na->syncaddr =
128 		    (struct netbuf *)malloc(sizeof (struct netbuf))) == NULL) {
129 			free(na->addr);
130 			return (-1);
131 		}
132 		if ((na->knconf =
133 (struct knetconfig *)malloc(sizeof (struct knetconfig))) == NULL) {
134 			free(na->addr);
135 			free(na->syncaddr);
136 			return (-1);
137 		}
138 		na->addr->maxlen = sizeof (struct sockaddr_in);
139 		na->addr->len = na->addr->maxlen;
140 		na->addr->buf = (char *)nfsa->addr;
141 		na->syncaddr->maxlen = na->addr->maxlen;
142 		na->syncaddr->len = na->syncaddr->maxlen;
143 		na->syncaddr->buf = (char *)nfsa->addr;
144 		strcpy(na->hostname, nfsa->hostname);
145 		strcpy(na->netname, nfsa->netname);
146 		na->fh = nfsa->fh;
147 		na->flags = nfsa->flags;
148 		na->wsize = nfsa->wsize;
149 		na->rsize = nfsa->rsize;
150 		na->timeo = nfsa->timeo;
151 		na->retrans = nfsa->retrans;
152 		na->acregmin = nfsa->acregmin;
153 		na->acregmax = nfsa->acregmax;
154 		na->acdirmin = nfsa->acdirmin;
155 		na->acdirmax = nfsa->acdirmax;
156 		returnValue = (_syscall(SYS_mount, data, dir, nflags, idx, na,
157 						sizeof (struct nfsarg)));
158 		free(na->addr);
159 		free(na->syncaddr);
160 		free(na->knconf);
161 		return (returnValue);
162 	}
163 	return (-1);
164 }
165