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