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