Added mount option nocore,
[unix-history] / sbin / mount / mount.c
CommitLineData
15637ed4
RG
1/*
2 * Copyright (c) 1980, 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35char copyright[] =
36"@(#) Copyright (c) 1980, 1989 The Regents of the University of California.\n\
37 All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41static char sccsid[] = "@(#)mount.c 5.44 (Berkeley) 2/26/91";
42#endif /* not lint */
43
44#include <sys/param.h>
45#include <sys/file.h>
46#include <sys/time.h>
47#include <sys/wait.h>
48#include <sys/errno.h>
49#include <sys/signal.h>
50#include <sys/mount.h>
51#ifdef NFS
52#include <sys/socket.h>
53#include <sys/socketvar.h>
54#include <netdb.h>
55#include <rpc/rpc.h>
56#include <rpc/pmap_clnt.h>
57#include <rpc/pmap_prot.h>
58#include <nfs/rpcv2.h>
59#include <nfs/nfsv2.h>
60#include <nfs/nfs.h>
61#endif
62#include <fstab.h>
63#include <string.h>
64#include <stdio.h>
65#include <stdlib.h>
66#include "pathnames.h"
67
68#define DEFAULT_ROOTUID -2
69
70#define BADTYPE(type) \
71 (strcmp(type, FSTAB_RO) && strcmp(type, FSTAB_RW) && \
72 strcmp(type, FSTAB_RQ))
73#define SETTYPE(type) \
74 (!strcmp(type, FSTAB_RW) || !strcmp(type, FSTAB_RQ))
75
76int fake, verbose, updateflg, mnttype;
77char *mntname, **envp;
78char **vfslist, **makevfslist();
79static void prmount();
80
81#ifdef NFS
82int xdr_dir(), xdr_fh();
83char *getnfsargs();
84struct nfs_args nfsdefargs = {
85 (struct sockaddr *)0,
86 SOCK_DGRAM,
87 0,
88 (nfsv2fh_t *)0,
89 0,
90 NFS_WSIZE,
91 NFS_RSIZE,
92 NFS_TIMEO,
93 NFS_RETRANS,
94 (char *)0,
95};
96
97struct nfhret {
98 u_long stat;
99 nfsv2fh_t nfh;
100};
101#define DEF_RETRY 10000
102int retrycnt;
103#define BGRND 1
104#define ISBGRND 2
105int opflags = 0;
106#endif
107
108main(argc, argv, arge)
109 int argc;
110 char **argv;
111 char **arge;
112{
113 extern char *optarg;
114 extern int optind;
115 register struct fstab *fs;
116 int all, ch, rval, flags, ret, pid, i;
117 long mntsize;
118 struct statfs *mntbuf, *getmntpt();
119 char *type, *options = NULL;
120 FILE *pidfile;
121
122 envp = arge;
123 all = 0;
124 type = NULL;
125 mnttype = MOUNT_UFS;
126 mntname = "ufs";
127 while ((ch = getopt(argc, argv, "afrwuvt:o:")) != EOF)
128 switch((char)ch) {
129 case 'a':
130 all = 1;
131 break;
132 case 'f':
133 fake = 1;
134 break;
135 case 'r':
136 type = FSTAB_RO;
137 break;
138 case 'u':
139 updateflg = MNT_UPDATE;
140 break;
141 case 'v':
142 verbose = 1;
143 break;
144 case 'w':
145 type = FSTAB_RW;
146 break;
147 case 'o':
148 options = optarg;
149 break;
150 case 't':
151 vfslist = makevfslist(optarg);
152 mnttype = getmnttype(optarg);
153 break;
154 case '?':
155 default:
156 usage();
157 /* NOTREACHED */
158 }
159 argc -= optind;
160 argv += optind;
161
162 /* NOSTRICT */
163
164 if (all) {
165 rval = 0;
166 while (fs = getfsent()) {
167 if (BADTYPE(fs->fs_type))
168 continue;
169 if (badvfsname(fs->fs_vfstype, vfslist))
170 continue;
171 /* `/' is special, it's always mounted */
172 if (!strcmp(fs->fs_file, "/"))
173 flags = MNT_UPDATE;
174 else
175 flags = updateflg;
176 mnttype = getmnttype(fs->fs_vfstype);
177 rval |= mountfs(fs->fs_spec, fs->fs_file, flags,
178 type, options, fs->fs_mntops);
179 }
180 exit(rval);
181 }
182
183 if (argc == 0) {
184 if (verbose || fake || type)
185 usage();
186 if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
187 (void) fprintf(stderr,
188 "mount: cannot get mount information\n");
189 exit(1);
190 }
191 for (i = 0; i < mntsize; i++) {
192 if (badvfstype(mntbuf[i].f_type, vfslist))
193 continue;
194 prmount(mntbuf[i].f_mntfromname, mntbuf[i].f_mntonname,
195 mntbuf[i].f_flags);
196 }
197 exit(0);
198 }
199
200 if (argc == 1 && updateflg) {
201 if ((mntbuf = getmntpt(*argv)) == NULL) {
202 (void) fprintf(stderr,
203 "mount: unknown special file or file system %s.\n",
204 *argv);
205 exit(1);
206 }
207 mnttype = mntbuf->f_type;
208#ifndef LETS_GET_SMALL
209 if (!strcmp(mntbuf->f_mntfromname, "root_device")) {
210 fs = getfsfile("/");
211 strcpy(mntbuf->f_mntfromname, fs->fs_spec);
212 }
213#endif
214 ret = mountfs(mntbuf->f_mntfromname, mntbuf->f_mntonname,
215 updateflg, type, options, (char *)NULL);
216 } else if (argc == 1) {
217#ifndef LETS_GET_SMALL
218 if (!(fs = getfsfile(*argv)) && !(fs = getfsspec(*argv))) {
219 (void) fprintf(stderr,
220 "mount: unknown special file or file system %s.\n",
221 *argv);
222 exit(1);
223 }
224 if (BADTYPE(fs->fs_type)) {
225 (void) fprintf(stderr,
226 "mount: %s has unknown file system type.\n", *argv);
227 exit(1);
228 }
229 mnttype = getmnttype(fs->fs_vfstype);
230 ret = mountfs(fs->fs_spec, fs->fs_file, updateflg,
231 type, options, fs->fs_mntops);
232#else
233 exit(1);
234#endif
235 } else if (argc != 2) {
236 usage();
237 ret = 1;
238 } else {
239 /*
240 * If -t flag has not been specified, and spec
241 * contains either a ':' or a '@' then assume that
242 * an NFS filesystem is being specified ala Sun.
243 */
244 if (vfslist == (char **)0 &&
245 (index(argv[0], ':') || index(argv[0], '@')))
246 mnttype = MOUNT_NFS;
247 ret = mountfs(argv[0], argv[1], updateflg, type, options,
248 (char *)NULL);
249 }
250#ifndef LETS_GET_SMALL
251 if ((pidfile = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
252 pid = 0;
253 fscanf(pidfile, "%d", &pid);
254 fclose(pidfile);
255 if (pid > 0)
256 kill(pid, SIGHUP);
257 }
258#endif
259 exit (ret);
260}
261
262mountfs(spec, name, flags, type, options, mntopts)
263 char *spec, *name, *type, *options, *mntopts;
264 int flags;
265{
266 union wait status;
267 pid_t pid;
268 int argc, i;
269 struct ufs_args args;
270#ifdef NFS
271 struct nfs_args nfsargs;
272#endif
273 char *argp, *argv[50];
274 char execname[MAXPATHLEN + 1], flagval[12];
275
276#ifdef NFS
277 nfsargs = nfsdefargs;
278#endif
279 if (mntopts)
280 getstdopts(mntopts, &flags);
281 if (options)
282 getstdopts(options, &flags);
283 if (type)
284 getstdopts(type, &flags);
285 switch (mnttype) {
286 case MOUNT_UFS:
287 if (mntopts)
288 getufsopts(mntopts, &flags);
289 if (options)
290 getufsopts(options, &flags);
291 args.fspec = spec;
292 args.exroot = DEFAULT_ROOTUID;
293 if (flags & MNT_RDONLY)
294 args.exflags = MNT_EXRDONLY;
295 else
296 args.exflags = 0;
297 argp = (caddr_t)&args;
298 break;
299
300#ifdef NFS
301 case MOUNT_NFS:
302 retrycnt = DEF_RETRY;
303 if (mntopts)
304 getnfsopts(mntopts, &nfsargs, &opflags, &retrycnt);
305 if (options)
306 getnfsopts(options, &nfsargs, &opflags, &retrycnt);
307 if (argp = getnfsargs(spec, &nfsargs))
308 break;
309 return (1);
310#endif /* NFS */
311
312#ifndef LETS_GET_SMALL
313 case MOUNT_MFS:
314 default:
315 argv[0] = mntname;
316 argc = 1;
317 if (flags) {
318 argv[argc++] = "-F";
319 sprintf(flagval, "%d", flags);
320 argv[argc++] = flagval;
321 }
322 if (mntopts)
323 argc += getexecopts(mntopts, &argv[argc]);
324 if (options)
325 argc += getexecopts(options, &argv[argc]);
326 argv[argc++] = spec;
327 argv[argc++] = name;
328 argv[argc++] = NULL;
329 sprintf(execname, "%s/mount_%s", _PATH_EXECDIR, mntname);
330 if (verbose) {
331 (void)printf("exec: %s", execname);
332 for (i = 1; i < argc - 1; i++)
333 (void)printf(" %s", argv[i]);
334 (void)printf("\n");
335 }
336 if (fake)
337 break;
338 if (pid = vfork()) {
339 if (pid == -1) {
340 perror("mount: vfork starting file system");
341 return (1);
342 }
343 if (waitpid(pid, (int *)&status, 0) != -1 &&
344 WIFEXITED(status) &&
345 WEXITSTATUS(status) != 0)
346 return (WEXITSTATUS(status));
347 spec = mntname;
348 goto out;
349 }
350 execve(execname, argv, envp);
351 (void) fprintf(stderr, "mount: cannot exec %s for %s: ",
352 execname, name);
353 perror((char *)NULL);
354 exit (1);
355#endif
356 /* NOTREACHED */
357
358 }
359 if (!fake && mount(mnttype, name, flags, argp)) {
360#ifdef NFS
361 if (opflags & ISBGRND)
362 exit(1);
363#endif
364 (void) fprintf(stderr, "%s on %s: ", spec, name);
365 switch (errno) {
366 case EMFILE:
367 (void) fprintf(stderr, "Mount table full\n");
368 break;
369 case EINVAL:
370 if (flags & MNT_UPDATE)
371 (void) fprintf(stderr, "Specified device %s\n",
372 "does not match mounted device");
373 else if (mnttype == MOUNT_UFS)
374 (void) fprintf(stderr, "Bogus super block\n");
375 else
376 perror((char *)NULL);
377 break;
378 default:
379 perror((char *)NULL);
380 break;
381 }
382 return(1);
383 }
384
385out:
386 if (verbose)
387 prmount(spec, name, flags);
388
389#ifdef NFS
390 if (opflags & ISBGRND)
391 exit(1);
392#endif
393 return(0);
394}
395
396static void
397prmount(spec, name, flags)
398 char *spec, *name;
399 register short flags;
400{
401 register int first;
402
403#ifdef NFS
404 if (opflags & ISBGRND)
405 return;
406#endif
407 (void)printf("%s on %s", spec, name);
408 if (!(flags & MNT_VISFLAGMASK)) {
409 (void)printf("\n");
410 return;
411 }
412 first = 0;
413#define PR(msg) (void)printf("%s%s", !first++ ? " (" : ", ", msg)
414 if (flags & MNT_RDONLY)
415 PR("read-only");
416 if (flags & MNT_NOEXEC)
417 PR("noexec");
418 if (flags & MNT_NOSUID)
419 PR("nosuid");
420 if (flags & MNT_NODEV)
421 PR("nodev");
422 if (flags & MNT_SYNCHRONOUS)
423 PR("synchronous");
424 if (flags & MNT_QUOTA)
425 PR("with quotas");
426 if (flags & MNT_LOCAL)
427 PR("local");
428 if (flags & MNT_EXPORTED)
429 if (flags & MNT_EXRDONLY)
430 PR("NFS exported read-only");
431 else
432 PR("NFS exported");
433 (void)printf(")\n");
434}
435
436getmnttype(fstype)
437 char *fstype;
438{
439
440 mntname = fstype;
441 if (!strcmp(fstype, "ufs"))
442 return (MOUNT_UFS);
443 if (!strcmp(fstype, "nfs"))
444 return (MOUNT_NFS);
445 if (!strcmp(fstype, "mfs"))
446 return (MOUNT_MFS);
447 return (0);
448}
449
450usage()
451{
452
453 (void) fprintf(stderr,
454 "usage:\n mount %s %s\n mount %s\n mount %s\n",
455 "[ -frwu ] [ -t nfs | ufs | external_type ]",
456 "[ -o options ] special node",
457 "[ -afrwu ] [ -t nfs | ufs | external_type ]",
458 "[ -frwu ] special | node");
459 exit(1);
460}
461
462getstdopts(options, flagp)
463 char *options;
464 int *flagp;
465{
466 register char *opt;
467 int negative;
468 char optbuf[BUFSIZ];
469
470 (void)strcpy(optbuf, options);
471 for (opt = strtok(optbuf, ","); opt; opt = strtok((char *)NULL, ",")) {
472 if (opt[0] == 'n' && opt[1] == 'o') {
473 negative++;
474 opt += 2;
475 } else {
476 negative = 0;
477 }
478 if (!negative && !strcasecmp(opt, FSTAB_RO)) {
479 *flagp |= MNT_RDONLY;
480 continue;
481 }
482 if (!negative && !strcasecmp(opt, FSTAB_RW)) {
483 *flagp &= ~MNT_RDONLY;
484 continue;
485 }
486 if (!strcasecmp(opt, "exec")) {
487 if (negative)
488 *flagp |= MNT_NOEXEC;
489 else
490 *flagp &= ~MNT_NOEXEC;
491 continue;
492 }
493 if (!strcasecmp(opt, "suid")) {
494 if (negative)
495 *flagp |= MNT_NOSUID;
496 else
497 *flagp &= ~MNT_NOSUID;
498 continue;
499 }
500 if (!strcasecmp(opt, "dev")) {
501 if (negative)
502 *flagp |= MNT_NODEV;
503 else
504 *flagp &= ~MNT_NODEV;
505 continue;
506 }
507 if (!strcasecmp(opt, "synchronous")) {
508 if (!negative)
509 *flagp |= MNT_SYNCHRONOUS;
510 else
511 *flagp &= ~MNT_SYNCHRONOUS;
512 continue;
513 }
514 }
515}
516
517/* ARGSUSED */
518getufsopts(options, flagp)
519 char *options;
520 int *flagp;
521{
522 return;
523}
524
525getexecopts(options, argv)
526 char *options;
527 char **argv;
528{
529 register int argc = 0;
530 register char *opt;
531
532 for (opt = strtok(options, ","); opt; opt = strtok((char *)NULL, ",")) {
533 if (opt[0] != '-')
534 continue;
535 argv[argc++] = opt;
536 if (opt[2] == '\0' || opt[2] != '=')
537 continue;
538 opt[2] = '\0';
539 argv[argc++] = &opt[3];
540 }
541 return (argc);
542}
543
544struct statfs *
545getmntpt(name)
546 char *name;
547{
548 long mntsize;
549 register long i;
550 struct statfs *mntbuf;
551
552 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
553 for (i = 0; i < mntsize; i++) {
554 if (!strcmp(mntbuf[i].f_mntfromname, name) ||
555 !strcmp(mntbuf[i].f_mntonname, name))
556 return (&mntbuf[i]);
557 }
558 return ((struct statfs *)0);
559}
560
561static int skipvfs;
562
563badvfstype(vfstype, vfslist)
564 short vfstype;
565 char **vfslist;
566{
567
568 if (vfslist == 0)
569 return(0);
570 while (*vfslist) {
571 if (vfstype == getmnttype(*vfslist))
572 return(skipvfs);
573 vfslist++;
574 }
575 return (!skipvfs);
576}
577
578badvfsname(vfsname, vfslist)
579 char *vfsname;
580 char **vfslist;
581{
582
583 if (vfslist == 0)
584 return(0);
585 while (*vfslist) {
586 if (strcmp(vfsname, *vfslist) == 0)
587 return(skipvfs);
588 vfslist++;
589 }
590 return (!skipvfs);
591}
592
593char **
594makevfslist(fslist)
595 char *fslist;
596{
597 register char **av, *nextcp;
598 register int i;
599
600 if (fslist == NULL)
601 return (NULL);
602 if (fslist[0] == 'n' && fslist[1] == 'o') {
603 fslist += 2;
604 skipvfs = 1;
605 }
606 for (i = 0, nextcp = fslist; *nextcp; nextcp++)
607 if (*nextcp == ',')
608 i++;
609 av = (char **)malloc((size_t)(i+2) * sizeof(char *));
610 if (av == NULL)
611 return (NULL);
612 nextcp = fslist;
613 i = 0;
614 av[i++] = nextcp;
615 while (nextcp = index(nextcp, ',')) {
616 *nextcp++ = '\0';
617 av[i++] = nextcp;
618 }
619 av[i++] = 0;
620 return (av);
621}
622
623#ifdef NFS
624exclusive(a, b)
625 char *a, *b;
626{
627
628 (void) fprintf(stderr, "mount: Options %s, %s mutually exclusive\n",
629 a, b);
630 exit(1);
631}
632
633/*
634 * Handle the getoption arg.
635 * Essentially update "opflags", "retrycnt" and "nfsargs"
636 */
637getnfsopts(optarg, nfsargsp, opflagsp, retrycntp)
638 char *optarg;
639 register struct nfs_args *nfsargsp;
640 int *opflagsp;
641 int *retrycntp;
642{
643 register char *cp, *nextcp;
644 int num;
645 char *nump;
646
647 for (cp = optarg; cp != NULL && *cp != '\0'; cp = nextcp) {
648 if ((nextcp = index(cp, ',')) != NULL)
649 *nextcp++ = '\0';
650 if ((nump = index(cp, '=')) != NULL) {
651 *nump++ = '\0';
652 num = atoi(nump);
653 } else
654 num = -1;
655 /*
656 * Just test for a string match and do it
657 */
658 if (!strcmp(cp, "bg")) {
659 *opflagsp |= BGRND;
660 } else if (!strcmp(cp, "soft")) {
661 if (nfsargsp->flags & NFSMNT_SPONGY)
662 exclusive("soft, spongy");
663 nfsargsp->flags |= NFSMNT_SOFT;
664 } else if (!strcmp(cp, "spongy")) {
665 if (nfsargsp->flags & NFSMNT_SOFT)
666 exclusive("soft, spongy");
667 nfsargsp->flags |= NFSMNT_SPONGY;
668 } else if (!strcmp(cp, "compress")) {
669 nfsargsp->flags |= NFSMNT_COMPRESS;
670 } else if (!strcmp(cp, "intr")) {
671 nfsargsp->flags |= NFSMNT_INT;
672 } else if (!strcmp(cp, "tcp")) {
673 nfsargsp->sotype = SOCK_STREAM;
674 } else if (!strcmp(cp, "noconn")) {
675 nfsargsp->flags |= NFSMNT_NOCONN;
676 } else if (!strcmp(cp, "retry") && num > 0) {
677 *retrycntp = num;
678 } else if (!strcmp(cp, "rsize") && num > 0) {
679 nfsargsp->rsize = num;
680 nfsargsp->flags |= NFSMNT_RSIZE;
681 } else if (!strcmp(cp, "wsize") && num > 0) {
682 nfsargsp->wsize = num;
683 nfsargsp->flags |= NFSMNT_WSIZE;
684 } else if (!strcmp(cp, "timeo") && num > 0) {
685 nfsargsp->timeo = num;
686 nfsargsp->flags |= NFSMNT_TIMEO;
687 } else if (!strcmp(cp, "retrans") && num > 0) {
688 nfsargsp->retrans = num;
689 nfsargsp->flags |= NFSMNT_RETRANS;
690 }
691 }
692 if (nfsargsp->sotype == SOCK_DGRAM) {
693 if (nfsargsp->rsize > NFS_MAXDGRAMDATA)
694 nfsargsp->rsize = NFS_MAXDGRAMDATA;
695 if (nfsargsp->wsize > NFS_MAXDGRAMDATA)
696 nfsargsp->wsize = NFS_MAXDGRAMDATA;
697 }
698}
699
700char *
701getnfsargs(spec, nfsargsp)
702 char *spec;
703 struct nfs_args *nfsargsp;
704{
705 register CLIENT *clp;
706 struct hostent *hp;
707 static struct sockaddr_in saddr;
708 struct timeval pertry, try;
709 enum clnt_stat clnt_stat;
710 int so = RPC_ANYSOCK;
711 char *fsp, *hostp, *delimp;
712 u_short tport;
713 static struct nfhret nfhret;
714 static char nam[MNAMELEN + 1];
715 char buf[MAXPATHLEN + 1];
716
717 strncpy(buf, spec, MAXPATHLEN);
718 buf[MAXPATHLEN] = '\0';
719 strncpy(nam, spec, MNAMELEN);
720 nam[MNAMELEN] = '\0';
721 if ((delimp = index(buf, '@')) != NULL) {
722 hostp = delimp + 1;
723 fsp = buf;
724 } else if ((delimp = index(buf, ':')) != NULL) {
725 hostp = buf;
726 fsp = delimp + 1;
727 } else {
728 (void) fprintf(stderr,
729 "mount: No <host>:<dirpath> or <dirpath>@<host> spec\n");
730 return (0);
731 }
732 *delimp = '\0';
733 if ((hp = gethostbyname(hostp)) == NULL) {
734 (void) fprintf(stderr, "mount: Can't get net id for host\n");
735 return (0);
736 }
737 bcopy(hp->h_addr, (caddr_t)&saddr.sin_addr, hp->h_length);
738 nfhret.stat = ETIMEDOUT; /* Mark not yet successful */
739 while (retrycnt > 0) {
740 saddr.sin_family = AF_INET;
741 saddr.sin_port = htons(PMAPPORT);
742 if ((tport = pmap_getport(&saddr, RPCPROG_NFS,
743 NFS_VER2, IPPROTO_UDP)) == 0) {
744 if ((opflags & ISBGRND) == 0)
745 clnt_pcreateerror("NFS Portmap");
746 } else {
747 saddr.sin_port = 0;
748 pertry.tv_sec = 10;
749 pertry.tv_usec = 0;
750 if ((clp = clntudp_create(&saddr, RPCPROG_MNT,
751 RPCMNT_VER1, pertry, &so)) == NULL) {
752 if ((opflags & ISBGRND) == 0)
753 clnt_pcreateerror("Cannot MNT PRC");
754 } else {
755 clp->cl_auth = authunix_create_default();
756 try.tv_sec = 10;
757 try.tv_usec = 0;
758 clnt_stat = clnt_call(clp, RPCMNT_MOUNT,
759 xdr_dir, fsp, xdr_fh, &nfhret, try);
760 if (clnt_stat != RPC_SUCCESS) {
761 if ((opflags & ISBGRND) == 0)
762 clnt_perror(clp, "Bad MNT RPC");
763 } else {
764 auth_destroy(clp->cl_auth);
765 clnt_destroy(clp);
766 retrycnt = 0;
767 }
768 }
769 }
770 if (--retrycnt > 0) {
771 if (opflags & BGRND) {
772 opflags &= ~BGRND;
773 if (fork())
774 return (0);
775 else
776 opflags |= ISBGRND;
777 }
778 sleep(10);
779 }
780 }
781 if (nfhret.stat) {
782 if (opflags & ISBGRND)
783 exit(1);
784 (void) fprintf(stderr, "Mount RPC error on %s: ", spec);
785 errno = nfhret.stat;
786 perror((char *)NULL);
787 return (0);
788 }
789 saddr.sin_port = htons(tport);
790 nfsargsp->addr = (struct sockaddr *) &saddr;
791 nfsargsp->fh = &nfhret.nfh;
792 nfsargsp->hostname = nam;
793 return ((caddr_t)nfsargsp);
794}
795
796/*
797 * xdr routines for mount rpc's
798 */
799xdr_dir(xdrsp, dirp)
800 XDR *xdrsp;
801 char *dirp;
802{
803 return (xdr_string(xdrsp, &dirp, RPCMNT_PATHLEN));
804}
805
806xdr_fh(xdrsp, np)
807 XDR *xdrsp;
808 struct nfhret *np;
809{
810 if (!xdr_u_long(xdrsp, &(np->stat)))
811 return (0);
812 if (np->stat)
813 return (1);
814 return (xdr_opaque(xdrsp, (caddr_t)&(np->nfh), NFSX_FH));
815}
816#endif /* NFS */