mount_nfs.c revision 1.61.2.2 1 1.61.2.2 yamt /* $NetBSD: mount_nfs.c,v 1.61.2.2 2007/11/30 16:13:16 yamt Exp $ */
2 1.61.2.2 yamt
3 1.61.2.2 yamt /*
4 1.61.2.2 yamt * Copyright (c) 1992, 1993, 1994
5 1.61.2.2 yamt * The Regents of the University of California. All rights reserved.
6 1.61.2.2 yamt *
7 1.61.2.2 yamt * This code is derived from software contributed to Berkeley by
8 1.61.2.2 yamt * Rick Macklem at The University of Guelph.
9 1.61.2.2 yamt *
10 1.61.2.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.61.2.2 yamt * modification, are permitted provided that the following conditions
12 1.61.2.2 yamt * are met:
13 1.61.2.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.61.2.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.61.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.61.2.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.61.2.2 yamt * documentation and/or other materials provided with the distribution.
18 1.61.2.2 yamt * 3. Neither the name of the University nor the names of its contributors
19 1.61.2.2 yamt * may be used to endorse or promote products derived from this software
20 1.61.2.2 yamt * without specific prior written permission.
21 1.61.2.2 yamt *
22 1.61.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.61.2.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.61.2.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.61.2.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.61.2.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.61.2.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.61.2.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.61.2.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.61.2.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.61.2.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.61.2.2 yamt * SUCH DAMAGE.
33 1.61.2.2 yamt */
34 1.61.2.2 yamt
35 1.61.2.2 yamt #include <sys/cdefs.h>
36 1.61.2.2 yamt #ifndef lint
37 1.61.2.2 yamt __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\n\
38 1.61.2.2 yamt The Regents of the University of California. All rights reserved.\n");
39 1.61.2.2 yamt #endif /* not lint */
40 1.61.2.2 yamt
41 1.61.2.2 yamt #ifndef lint
42 1.61.2.2 yamt #if 0
43 1.61.2.2 yamt static char sccsid[] = "@(#)mount_nfs.c 8.11 (Berkeley) 5/4/95";
44 1.61.2.2 yamt #else
45 1.61.2.2 yamt __RCSID("$NetBSD: mount_nfs.c,v 1.61.2.2 2007/11/30 16:13:16 yamt Exp $");
46 1.61.2.2 yamt #endif
47 1.61.2.2 yamt #endif /* not lint */
48 1.61.2.2 yamt
49 1.61.2.2 yamt #include <sys/param.h>
50 1.61.2.2 yamt #include <sys/mount.h>
51 1.61.2.2 yamt #include <sys/socket.h>
52 1.61.2.2 yamt #include <sys/stat.h>
53 1.61.2.2 yamt #include <syslog.h>
54 1.61.2.2 yamt
55 1.61.2.2 yamt #ifdef ISO
56 1.61.2.2 yamt #include <netiso/iso.h>
57 1.61.2.2 yamt #endif
58 1.61.2.2 yamt
59 1.61.2.2 yamt #include <nfs/rpcv2.h>
60 1.61.2.2 yamt #include <nfs/nfsproto.h>
61 1.61.2.2 yamt #include <nfs/nfs.h>
62 1.61.2.2 yamt #include <nfs/nfsmount.h>
63 1.61.2.2 yamt
64 1.61.2.2 yamt #include <arpa/inet.h>
65 1.61.2.2 yamt
66 1.61.2.2 yamt #include <err.h>
67 1.61.2.2 yamt #include <errno.h>
68 1.61.2.2 yamt #include <fcntl.h>
69 1.61.2.2 yamt #include <netdb.h>
70 1.61.2.2 yamt #include <signal.h>
71 1.61.2.2 yamt #include <stdio.h>
72 1.61.2.2 yamt #include <stdlib.h>
73 1.61.2.2 yamt #include <string.h>
74 1.61.2.2 yamt #include <unistd.h>
75 1.61.2.2 yamt #include <util.h>
76 1.61.2.2 yamt
77 1.61.2.2 yamt #include <mntopts.h>
78 1.61.2.2 yamt
79 1.61.2.2 yamt #include "mount_nfs.h"
80 1.61.2.2 yamt
81 1.61.2.2 yamt #define ALTF_BG 0x00000001
82 1.61.2.2 yamt #define ALTF_CONN 0x00000002
83 1.61.2.2 yamt #define ALTF_DUMBTIMR 0x00000004
84 1.61.2.2 yamt #define ALTF_INTR 0x00000008
85 1.61.2.2 yamt #define ALTF_NFSV3 0x00000020
86 1.61.2.2 yamt #define ALTF_RDIRPLUS 0x00000040
87 1.61.2.2 yamt #define ALTF_MNTUDP 0x00000080
88 1.61.2.2 yamt #define ALTF_NORESPORT 0x00000100
89 1.61.2.2 yamt #define ALTF_SEQPACKET 0x00000200
90 1.61.2.2 yamt #define ALTF_NQNFS 0x00000400
91 1.61.2.2 yamt #define ALTF_SOFT 0x00000800
92 1.61.2.2 yamt #define ALTF_TCP 0x00001000
93 1.61.2.2 yamt #define ALTF_NFSV2 0x00002000
94 1.61.2.2 yamt #define ALTF_PORT 0x00004000
95 1.61.2.2 yamt #define ALTF_RSIZE 0x00008000
96 1.61.2.2 yamt #define ALTF_WSIZE 0x00010000
97 1.61.2.2 yamt #define ALTF_RDIRSIZE 0x00020000
98 1.61.2.2 yamt #define ALTF_MAXGRPS 0x00040000
99 1.61.2.2 yamt #define ALTF_LEASETERM 0x00080000
100 1.61.2.2 yamt #define ALTF_READAHEAD 0x00100000
101 1.61.2.2 yamt #define ALTF_DEADTHRESH 0x00200000
102 1.61.2.2 yamt #define ALTF_TIMEO 0x00400000
103 1.61.2.2 yamt #define ALTF_RETRANS 0x00800000
104 1.61.2.2 yamt
105 1.61.2.2 yamt static const struct mntopt mopts[] = {
106 1.61.2.2 yamt MOPT_STDOPTS,
107 1.61.2.2 yamt MOPT_FORCE,
108 1.61.2.2 yamt MOPT_UPDATE,
109 1.61.2.2 yamt MOPT_GETARGS,
110 1.61.2.2 yamt { "bg", 0, ALTF_BG, 1 },
111 1.61.2.2 yamt { "conn", 0, ALTF_CONN, 1 },
112 1.61.2.2 yamt { "dumbtimer", 0, ALTF_DUMBTIMR, 1 },
113 1.61.2.2 yamt { "intr", 0, ALTF_INTR, 1 },
114 1.61.2.2 yamt { "nfsv3", 0, ALTF_NFSV3, 1 },
115 1.61.2.2 yamt { "rdirplus", 0, ALTF_RDIRPLUS, 1 },
116 1.61.2.2 yamt { "mntudp", 0, ALTF_MNTUDP, 1 },
117 1.61.2.2 yamt { "noresport", 0, ALTF_NORESPORT, 1 },
118 1.61.2.2 yamt #ifdef ISO
119 1.61.2.2 yamt { "seqpacket", 0, ALTF_SEQPACKET, 1 },
120 1.61.2.2 yamt #endif
121 1.61.2.2 yamt { "nqnfs", 0, ALTF_NQNFS, 1 },
122 1.61.2.2 yamt { "soft", 0, ALTF_SOFT, 1 },
123 1.61.2.2 yamt { "tcp", 0, ALTF_TCP, 1 },
124 1.61.2.2 yamt { "nfsv2", 0, ALTF_NFSV2, 1 },
125 1.61.2.2 yamt { "port", 0, ALTF_PORT, 1 },
126 1.61.2.2 yamt { "rsize", 0, ALTF_RSIZE, 1 },
127 1.61.2.2 yamt { "wsize", 0, ALTF_WSIZE, 1 },
128 1.61.2.2 yamt { "rdirsize", 0, ALTF_RDIRSIZE, 1 },
129 1.61.2.2 yamt { "maxgrps", 0, ALTF_MAXGRPS, 1 },
130 1.61.2.2 yamt { "leaseterm", 0, ALTF_LEASETERM, 1 },
131 1.61.2.2 yamt { "readahead", 0, ALTF_READAHEAD, 1 },
132 1.61.2.2 yamt { "deadthresh", 0, ALTF_DEADTHRESH, 1 },
133 1.61.2.2 yamt { "timeo", 0, ALTF_TIMEO, 1 },
134 1.61.2.2 yamt MOPT_NULL,
135 1.61.2.2 yamt
136 1.61.2.2 yamt };
137 1.61.2.2 yamt
138 1.61.2.2 yamt struct nfs_args nfsdefargs = {
139 1.61.2.2 yamt NFS_ARGSVERSION,
140 1.61.2.2 yamt (struct sockaddr *)0,
141 1.61.2.2 yamt sizeof (struct sockaddr_in),
142 1.61.2.2 yamt SOCK_DGRAM,
143 1.61.2.2 yamt 0,
144 1.61.2.2 yamt (u_char *)0,
145 1.61.2.2 yamt 0,
146 1.61.2.2 yamt NFSMNT_NFSV3|NFSMNT_NOCONN|NFSMNT_RESVPORT,
147 1.61.2.2 yamt NFS_WSIZE,
148 1.61.2.2 yamt NFS_RSIZE,
149 1.61.2.2 yamt NFS_READDIRSIZE,
150 1.61.2.2 yamt 10,
151 1.61.2.2 yamt NFS_RETRANS,
152 1.61.2.2 yamt NFS_MAXGRPS,
153 1.61.2.2 yamt NFS_DEFRAHEAD,
154 1.61.2.2 yamt 0, /* Ignored; lease term */
155 1.61.2.2 yamt NFS_DEFDEADTHRESH,
156 1.61.2.2 yamt (char *)0,
157 1.61.2.2 yamt };
158 1.61.2.2 yamt
159 1.61.2.2 yamt int retrycnt = 0;
160 1.61.2.2 yamt int opflags = 0;
161 1.61.2.2 yamt int force2 = 0;
162 1.61.2.2 yamt int force3 = 0;
163 1.61.2.2 yamt int mnttcp_ok = 1;
164 1.61.2.2 yamt int port = 0;
165 1.61.2.2 yamt
166 1.61.2.2 yamt static void shownfsargs(const struct nfs_args *);
167 1.61.2.2 yamt #ifdef ISO
168 1.61.2.2 yamt static struct iso_addr *iso_addr(const char *);
169 1.61.2.2 yamt #endif
170 1.61.2.2 yamt int mount_nfs(int argc, char **argv);
171 1.61.2.2 yamt /* void set_rpc_maxgrouplist(int); */
172 1.61.2.2 yamt static void usage(void);
173 1.61.2.2 yamt
174 1.61.2.2 yamt #ifndef MOUNT_NOMAIN
175 1.61.2.2 yamt int
176 1.61.2.2 yamt main(int argc, char **argv)
177 1.61.2.2 yamt {
178 1.61.2.2 yamt return mount_nfs(argc, argv);
179 1.61.2.2 yamt }
180 1.61.2.2 yamt #endif
181 1.61.2.2 yamt
182 1.61.2.2 yamt int
183 1.61.2.2 yamt mount_nfs(int argc, char *argv[])
184 1.61.2.2 yamt {
185 1.61.2.2 yamt int c, retval;
186 1.61.2.2 yamt struct nfs_args *nfsargsp;
187 1.61.2.2 yamt struct nfs_args nfsargs;
188 1.61.2.2 yamt struct sockaddr_storage sa;
189 1.61.2.2 yamt int mntflags, altflags, num;
190 1.61.2.2 yamt char name[MAXPATHLEN], *p, *spec;
191 1.61.2.2 yamt mntoptparse_t mp;
192 1.61.2.2 yamt retrycnt = DEF_RETRY;
193 1.61.2.2 yamt
194 1.61.2.2 yamt mntflags = 0;
195 1.61.2.2 yamt altflags = 0;
196 1.61.2.2 yamt nfsargs = nfsdefargs;
197 1.61.2.2 yamt nfsargsp = &nfsargs;
198 1.61.2.2 yamt while ((c = getopt(argc, argv,
199 1.61.2.2 yamt "23a:bcCdD:g:I:iKL:lm:o:PpqR:r:sTt:w:x:UX")) != -1)
200 1.61.2.2 yamt switch (c) {
201 1.61.2.2 yamt case '3':
202 1.61.2.2 yamt case 'q':
203 1.61.2.2 yamt if (force2)
204 1.61.2.2 yamt errx(1, "conflicting version options");
205 1.61.2.2 yamt force3 = 1;
206 1.61.2.2 yamt break;
207 1.61.2.2 yamt case '2':
208 1.61.2.2 yamt if (force3)
209 1.61.2.2 yamt errx(1, "conflicting version options");
210 1.61.2.2 yamt force2 = 1;
211 1.61.2.2 yamt nfsargsp->flags &= ~NFSMNT_NFSV3;
212 1.61.2.2 yamt break;
213 1.61.2.2 yamt case 'a':
214 1.61.2.2 yamt num = strtol(optarg, &p, 10);
215 1.61.2.2 yamt if (*p || num < 0)
216 1.61.2.2 yamt errx(1, "illegal -a value -- %s", optarg);
217 1.61.2.2 yamt nfsargsp->readahead = num;
218 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_READAHEAD;
219 1.61.2.2 yamt break;
220 1.61.2.2 yamt case 'b':
221 1.61.2.2 yamt opflags |= BGRND;
222 1.61.2.2 yamt break;
223 1.61.2.2 yamt case 'c':
224 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_NOCONN;
225 1.61.2.2 yamt break;
226 1.61.2.2 yamt case 'C':
227 1.61.2.2 yamt nfsargsp->flags &= ~NFSMNT_NOCONN;
228 1.61.2.2 yamt break;
229 1.61.2.2 yamt case 'D':
230 1.61.2.2 yamt num = strtol(optarg, &p, 10);
231 1.61.2.2 yamt if (*p || num <= 0)
232 1.61.2.2 yamt errx(1, "illegal -D value -- %s", optarg);
233 1.61.2.2 yamt nfsargsp->deadthresh = num;
234 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_DEADTHRESH;
235 1.61.2.2 yamt break;
236 1.61.2.2 yamt case 'd':
237 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_DUMBTIMR;
238 1.61.2.2 yamt break;
239 1.61.2.2 yamt #if 0 /* XXXX */
240 1.61.2.2 yamt case 'g':
241 1.61.2.2 yamt num = strtol(optarg, &p, 10);
242 1.61.2.2 yamt if (*p || num <= 0)
243 1.61.2.2 yamt errx(1, "illegal -g value -- %s", optarg);
244 1.61.2.2 yamt set_rpc_maxgrouplist(num);
245 1.61.2.2 yamt nfsargsp->maxgrouplist = num;
246 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_MAXGRPS;
247 1.61.2.2 yamt break;
248 1.61.2.2 yamt #endif
249 1.61.2.2 yamt case 'I':
250 1.61.2.2 yamt num = strtol(optarg, &p, 10);
251 1.61.2.2 yamt if (*p || num <= 0)
252 1.61.2.2 yamt errx(1, "illegal -I value -- %s", optarg);
253 1.61.2.2 yamt nfsargsp->readdirsize = num;
254 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_READDIRSIZE;
255 1.61.2.2 yamt break;
256 1.61.2.2 yamt case 'i':
257 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_INT;
258 1.61.2.2 yamt break;
259 1.61.2.2 yamt case 'L':
260 1.61.2.2 yamt /* ignore */
261 1.61.2.2 yamt break;
262 1.61.2.2 yamt case 'l':
263 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_RDIRPLUS;
264 1.61.2.2 yamt break;
265 1.61.2.2 yamt case 'o':
266 1.61.2.2 yamt mp = getmntopts(optarg, mopts, &mntflags, &altflags);
267 1.61.2.2 yamt if (mp == NULL)
268 1.61.2.2 yamt err(1, "getmntopts");
269 1.61.2.2 yamt if (altflags & ALTF_BG)
270 1.61.2.2 yamt opflags |= BGRND;
271 1.61.2.2 yamt if (altflags & ALTF_CONN)
272 1.61.2.2 yamt nfsargsp->flags &= ~NFSMNT_NOCONN;
273 1.61.2.2 yamt if (altflags & ALTF_DUMBTIMR)
274 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_DUMBTIMR;
275 1.61.2.2 yamt if (altflags & ALTF_INTR)
276 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_INT;
277 1.61.2.2 yamt if (altflags & (ALTF_NFSV3|ALTF_NQNFS)) {
278 1.61.2.2 yamt if (force2)
279 1.61.2.2 yamt errx(1, "conflicting version options");
280 1.61.2.2 yamt force3 = 1;
281 1.61.2.2 yamt }
282 1.61.2.2 yamt if (altflags & ALTF_NFSV2) {
283 1.61.2.2 yamt if (force3)
284 1.61.2.2 yamt errx(1, "conflicting version options");
285 1.61.2.2 yamt force2 = 1;
286 1.61.2.2 yamt nfsargsp->flags &= ~NFSMNT_NFSV3;
287 1.61.2.2 yamt }
288 1.61.2.2 yamt if (altflags & ALTF_RDIRPLUS)
289 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_RDIRPLUS;
290 1.61.2.2 yamt if (altflags & ALTF_MNTUDP)
291 1.61.2.2 yamt mnttcp_ok = 0;
292 1.61.2.2 yamt if (altflags & ALTF_NORESPORT)
293 1.61.2.2 yamt nfsargsp->flags &= ~NFSMNT_RESVPORT;
294 1.61.2.2 yamt #ifdef ISO
295 1.61.2.2 yamt if (altflags & ALTF_SEQPACKET)
296 1.61.2.2 yamt nfsargsp->sotype = SOCK_SEQPACKET;
297 1.61.2.2 yamt #endif
298 1.61.2.2 yamt if (altflags & ALTF_SOFT)
299 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_SOFT;
300 1.61.2.2 yamt if (altflags & ALTF_TCP) {
301 1.61.2.2 yamt nfsargsp->sotype = SOCK_STREAM;
302 1.61.2.2 yamt }
303 1.61.2.2 yamt if (altflags & ALTF_PORT) {
304 1.61.2.2 yamt port = getmntoptnum(mp, "port");
305 1.61.2.2 yamt }
306 1.61.2.2 yamt if (altflags & ALTF_RSIZE) {
307 1.61.2.2 yamt nfsargsp->rsize =
308 1.61.2.2 yamt (int)getmntoptnum(mp, "rsize");
309 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_RSIZE;
310 1.61.2.2 yamt }
311 1.61.2.2 yamt if (altflags & ALTF_WSIZE) {
312 1.61.2.2 yamt nfsargsp->wsize =
313 1.61.2.2 yamt (int)getmntoptnum(mp, "wsize");
314 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_WSIZE;
315 1.61.2.2 yamt }
316 1.61.2.2 yamt if (altflags & ALTF_RDIRSIZE) {
317 1.61.2.2 yamt nfsargsp->rsize =
318 1.61.2.2 yamt (int)getmntoptnum(mp, "rdirsize");
319 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_READDIRSIZE;
320 1.61.2.2 yamt }
321 1.61.2.2 yamt #if 0
322 1.61.2.2 yamt if (altflags & ALTF_MAXGRPS) {
323 1.61.2.2 yamt set_rpc_maxgrouplist(num);
324 1.61.2.2 yamt nfsargsp->maxgrouplist =
325 1.61.2.2 yamt (int)getmntoptnum(mp, "maxgrps");
326 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_MAXGRPS;
327 1.61.2.2 yamt }
328 1.61.2.2 yamt #endif
329 1.61.2.2 yamt if (altflags & ALTF_LEASETERM) {
330 1.61.2.2 yamt nfsargsp->leaseterm =
331 1.61.2.2 yamt (int)getmntoptnum(mp, "leaseterm");
332 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_LEASETERM;
333 1.61.2.2 yamt }
334 1.61.2.2 yamt if (altflags & ALTF_READAHEAD) {
335 1.61.2.2 yamt nfsargsp->readahead =
336 1.61.2.2 yamt (int)getmntoptnum(mp, "readahead");
337 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_READAHEAD;
338 1.61.2.2 yamt }
339 1.61.2.2 yamt if (altflags & ALTF_DEADTHRESH) {
340 1.61.2.2 yamt nfsargsp->deadthresh =
341 1.61.2.2 yamt (int)getmntoptnum(mp, "deadthresh");
342 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_DEADTHRESH;
343 1.61.2.2 yamt }
344 1.61.2.2 yamt if (altflags & ALTF_TIMEO) {
345 1.61.2.2 yamt nfsargsp->timeo =
346 1.61.2.2 yamt (int)getmntoptnum(mp, "timeo");
347 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_TIMEO;
348 1.61.2.2 yamt }
349 1.61.2.2 yamt if (altflags & ALTF_RETRANS) {
350 1.61.2.2 yamt nfsargsp->retrans =
351 1.61.2.2 yamt (int)getmntoptnum(mp, "retrans");
352 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_RETRANS;
353 1.61.2.2 yamt }
354 1.61.2.2 yamt altflags = 0;
355 1.61.2.2 yamt freemntopts(mp);
356 1.61.2.2 yamt break;
357 1.61.2.2 yamt case 'P':
358 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_RESVPORT;
359 1.61.2.2 yamt break;
360 1.61.2.2 yamt case 'p':
361 1.61.2.2 yamt nfsargsp->flags &= ~NFSMNT_RESVPORT;
362 1.61.2.2 yamt break;
363 1.61.2.2 yamt case 'R':
364 1.61.2.2 yamt num = strtol(optarg, &p, 10);
365 1.61.2.2 yamt if (*p || num <= 0)
366 1.61.2.2 yamt errx(1, "illegal -R value -- %s", optarg);
367 1.61.2.2 yamt retrycnt = num;
368 1.61.2.2 yamt break;
369 1.61.2.2 yamt case 'r':
370 1.61.2.2 yamt num = strtol(optarg, &p, 10);
371 1.61.2.2 yamt if (*p || num <= 0)
372 1.61.2.2 yamt errx(1, "illegal -r value -- %s", optarg);
373 1.61.2.2 yamt nfsargsp->rsize = num;
374 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_RSIZE;
375 1.61.2.2 yamt break;
376 1.61.2.2 yamt #ifdef ISO
377 1.61.2.2 yamt case 'S':
378 1.61.2.2 yamt nfsargsp->sotype = SOCK_SEQPACKET;
379 1.61.2.2 yamt break;
380 1.61.2.2 yamt #endif
381 1.61.2.2 yamt case 's':
382 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_SOFT;
383 1.61.2.2 yamt break;
384 1.61.2.2 yamt case 'T':
385 1.61.2.2 yamt nfsargsp->sotype = SOCK_STREAM;
386 1.61.2.2 yamt break;
387 1.61.2.2 yamt case 't':
388 1.61.2.2 yamt num = strtol(optarg, &p, 10);
389 1.61.2.2 yamt if (*p || num <= 0)
390 1.61.2.2 yamt errx(1, "illegal -t value -- %s", optarg);
391 1.61.2.2 yamt nfsargsp->timeo = num;
392 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_TIMEO;
393 1.61.2.2 yamt break;
394 1.61.2.2 yamt case 'w':
395 1.61.2.2 yamt num = strtol(optarg, &p, 10);
396 1.61.2.2 yamt if (*p || num <= 0)
397 1.61.2.2 yamt errx(1, "illegal -w value -- %s", optarg);
398 1.61.2.2 yamt nfsargsp->wsize = num;
399 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_WSIZE;
400 1.61.2.2 yamt break;
401 1.61.2.2 yamt case 'x':
402 1.61.2.2 yamt num = strtol(optarg, &p, 10);
403 1.61.2.2 yamt if (*p || num <= 0)
404 1.61.2.2 yamt errx(1, "illegal -x value -- %s", optarg);
405 1.61.2.2 yamt nfsargsp->retrans = num;
406 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_RETRANS;
407 1.61.2.2 yamt break;
408 1.61.2.2 yamt case 'X':
409 1.61.2.2 yamt nfsargsp->flags |= NFSMNT_XLATECOOKIE;
410 1.61.2.2 yamt break;
411 1.61.2.2 yamt case 'U':
412 1.61.2.2 yamt mnttcp_ok = 0;
413 1.61.2.2 yamt break;
414 1.61.2.2 yamt default:
415 1.61.2.2 yamt usage();
416 1.61.2.2 yamt break;
417 1.61.2.2 yamt }
418 1.61.2.2 yamt argc -= optind;
419 1.61.2.2 yamt argv += optind;
420 1.61.2.2 yamt
421 1.61.2.2 yamt if (argc != 2)
422 1.61.2.2 yamt usage();
423 1.61.2.2 yamt
424 1.61.2.2 yamt spec = *argv++;
425 1.61.2.2 yamt if (realpath(*argv, name) == NULL) /* Check mounton path */
426 1.61.2.2 yamt err(1, "realpath %s", *argv);
427 1.61.2.2 yamt if (strncmp(*argv, name, MAXPATHLEN)) {
428 1.61.2.2 yamt warnx("\"%s\" is a relative path.", *argv);
429 1.61.2.2 yamt warnx("using \"%s\" instead.", name);
430 1.61.2.2 yamt }
431 1.61.2.2 yamt
432 1.61.2.2 yamt retry:
433 1.61.2.2 yamt if ((mntflags & MNT_GETARGS) != 0) {
434 1.61.2.2 yamt memset(&sa, 0, sizeof(sa));
435 1.61.2.2 yamt nfsargsp->addr = (struct sockaddr *)&sa;
436 1.61.2.2 yamt nfsargsp->addrlen = sizeof(sa);
437 1.61.2.2 yamt } else {
438 1.61.2.2 yamt char *tspec;
439 1.61.2.2 yamt
440 1.61.2.2 yamt if ((tspec = strdup(spec)) == NULL) {
441 1.61.2.2 yamt err(1, "strdup");
442 1.61.2.2 yamt }
443 1.61.2.2 yamt if (!getnfsargs(tspec, nfsargsp)) {
444 1.61.2.2 yamt exit(1);
445 1.61.2.2 yamt }
446 1.61.2.2 yamt free(tspec);
447 1.61.2.2 yamt }
448 1.61.2.2 yamt if ((retval = mount(MOUNT_NFS, name, mntflags,
449 1.61.2.2 yamt nfsargsp, sizeof *nfsargsp)) == -1) {
450 1.61.2.2 yamt /* Did we just default to v3 on a v2-only kernel?
451 1.61.2.2 yamt * If so, default to v2 & try again */
452 1.61.2.2 yamt if (errno == EPROGMISMATCH &&
453 1.61.2.2 yamt (nfsargsp->flags & NFSMNT_NFSV3) != 0 && !force3) {
454 1.61.2.2 yamt /*
455 1.61.2.2 yamt * fall back to v2. XXX lack of V3 umount.
456 1.61.2.2 yamt */
457 1.61.2.2 yamt nfsargsp->flags &= ~NFSMNT_NFSV3;
458 1.61.2.2 yamt goto retry;
459 1.61.2.2 yamt }
460 1.61.2.2 yamt }
461 1.61.2.2 yamt if (retval == -1)
462 1.61.2.2 yamt err(1, "%s on %s", spec, name);
463 1.61.2.2 yamt if (mntflags & MNT_GETARGS) {
464 1.61.2.2 yamt shownfsargs(nfsargsp);
465 1.61.2.2 yamt return (0);
466 1.61.2.2 yamt }
467 1.61.2.2 yamt
468 1.61.2.2 yamt exit(0);
469 1.61.2.2 yamt }
470 1.61.2.2 yamt
471 1.61.2.2 yamt static void
472 1.61.2.2 yamt shownfsargs(const struct nfs_args *nfsargsp)
473 1.61.2.2 yamt {
474 1.61.2.2 yamt char fbuf[2048];
475 1.61.2.2 yamt char host[NI_MAXHOST], serv[NI_MAXSERV];
476 1.61.2.2 yamt int error;
477 1.61.2.2 yamt
478 1.61.2.2 yamt (void)snprintb(fbuf, sizeof(fbuf), NFSMNT_BITS, nfsargsp->flags);
479 1.61.2.2 yamt if (nfsargsp->addr != NULL) {
480 1.61.2.2 yamt error = getnameinfo(nfsargsp->addr, nfsargsp->addrlen, host,
481 1.61.2.2 yamt sizeof(host), serv, sizeof(serv),
482 1.61.2.2 yamt NI_NUMERICHOST | NI_NUMERICSERV);
483 1.61.2.2 yamt if (error != 0)
484 1.61.2.2 yamt warnx("getnameinfo: %s", gai_strerror(error));
485 1.61.2.2 yamt } else
486 1.61.2.2 yamt error = -1;
487 1.61.2.2 yamt
488 1.61.2.2 yamt if (error == 0)
489 1.61.2.2 yamt printf("addr=%s, port=%s, addrlen=%d, ",
490 1.61.2.2 yamt host, serv, nfsargsp->addrlen);
491 1.61.2.2 yamt printf("sotype=%d, proto=%d, fhsize=%d, "
492 1.61.2.2 yamt "flags=%s, wsize=%d, rsize=%d, readdirsize=%d, timeo=%d, "
493 1.61.2.2 yamt "retrans=%d, maxgrouplist=%d, readahead=%d, leaseterm=%d, "
494 1.61.2.2 yamt "deadthresh=%d\n",
495 1.61.2.2 yamt nfsargsp->sotype,
496 1.61.2.2 yamt nfsargsp->proto,
497 1.61.2.2 yamt nfsargsp->fhsize,
498 1.61.2.2 yamt fbuf,
499 1.61.2.2 yamt nfsargsp->wsize,
500 1.61.2.2 yamt nfsargsp->rsize,
501 1.61.2.2 yamt nfsargsp->readdirsize,
502 1.61.2.2 yamt nfsargsp->timeo,
503 1.61.2.2 yamt nfsargsp->retrans,
504 1.61.2.2 yamt nfsargsp->maxgrouplist,
505 1.61.2.2 yamt nfsargsp->readahead,
506 1.61.2.2 yamt nfsargsp->leaseterm,
507 1.61.2.2 yamt nfsargsp->deadthresh);
508 1.61.2.2 yamt }
509 1.61.2.2 yamt
510 1.61.2.2 yamt static void
511 1.61.2.2 yamt usage(void)
512 1.61.2.2 yamt {
513 1.61.2.2 yamt (void)fprintf(stderr, "usage: mount_nfs %s\n%s\n%s\n%s\n%s\n",
514 1.61.2.2 yamt "[-23bCcdilPpqsTUX] [-a maxreadahead] [-D deadthresh]",
515 1.61.2.2 yamt "\t[-g maxgroups] [-I readdirsize] [-L leaseterm]",
516 1.61.2.2 yamt "\t[-o options] [-R retrycnt] [-r readsize] [-t timeout]",
517 1.61.2.2 yamt "\t[-w writesize] [-x retrans]",
518 1.61.2.2 yamt "\trhost:path node");
519 1.61.2.2 yamt exit(1);
520 1.61.2.2 yamt }
521