121156Sdist /* 221156Sdist * Copyright (c) 1980 Regents of the University of California. 321156Sdist * All rights reserved. The Berkeley software License Agreement 421156Sdist * specifies the terms and conditions for redistribution. 521156Sdist */ 621156Sdist 710811Ssam #ifndef lint 821156Sdist char copyright[] = 921156Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 1021156Sdist All rights reserved.\n"; 1121156Sdist #endif not lint 121057Sbill 1321156Sdist #ifndef lint 14*39316Smckusick static char sccsid[] = "@(#)mount.c 5.13 (Berkeley) 10/17/89"; 1521156Sdist #endif not lint 1621156Sdist 1739131Smckusick #include "pathnames.h" 1812808Ssam #include <sys/param.h> 1935339Sbostic #include <sys/file.h> 2038445Smckusick #include <sys/time.h> 2139133Smckusick #include <sys/wait.h> 2210811Ssam #include <fstab.h> 2316669Ssam #include <errno.h> 2435339Sbostic #include <stdio.h> 2538445Smckusick #include <strings.h> 2638445Smckusick #include <sys/dir.h> 2738445Smckusick #include <sys/uio.h> 2838445Smckusick #include <sys/namei.h> 2938445Smckusick #include <sys/mount.h> 3038445Smckusick #ifdef NFS 3138445Smckusick #include <sys/socket.h> 3238445Smckusick #include <sys/socketvar.h> 3338445Smckusick #include <netdb.h> 3438445Smckusick #include <rpc/rpc.h> 3538445Smckusick #include <rpc/pmap_clnt.h> 3638445Smckusick #include <rpc/pmap_prot.h> 3738445Smckusick #include <nfs/rpcv2.h> 3838445Smckusick #include <nfs/nfsv2.h> 3938445Smckusick #include <nfs/nfs.h> 4038445Smckusick #endif 411057Sbill 4235339Sbostic #define BADTYPE(type) \ 4335339Sbostic (strcmp(type, FSTAB_RO) && strcmp(type, FSTAB_RW) && \ 4435339Sbostic strcmp(type, FSTAB_RQ)) 4535339Sbostic #define SETTYPE(type) \ 4635339Sbostic (!strcmp(type, FSTAB_RW) || !strcmp(type, FSTAB_RQ)) 471057Sbill 4838445Smckusick static int fake, verbose, mnttype; 4939131Smckusick char **envp; 5039131Smckusick 5138445Smckusick #ifdef NFS 5238445Smckusick int xdr_dir(), xdr_fh(); 5338632Smckusick char *getnfsargs(); 5438445Smckusick struct nfs_args nfsargs = { 5538445Smckusick (struct sockaddr_in *)0, 5638445Smckusick (nfsv2fh_t *)0, 5738445Smckusick 0, 5838445Smckusick NFS_WSIZE, 5938445Smckusick NFS_RSIZE, 6038445Smckusick NFS_TIMEO, 6138445Smckusick NFS_RETRANS, 6238445Smckusick (char *)0, 6338445Smckusick }; 645073Sroot 6538445Smckusick struct nfhret { 6638445Smckusick u_long stat; 6738445Smckusick nfsv2fh_t nfh; 6838445Smckusick }; 6938445Smckusick int retrycnt = 10000; 7038445Smckusick #define BGRND 1 7138445Smckusick #define ISBGRND 2 7238445Smckusick int opflags = 0; 7338445Smckusick #endif 7438445Smckusick 7539131Smckusick main(argc, argv, arge) 765073Sroot int argc; 775073Sroot char **argv; 7839131Smckusick char **arge; 791057Sbill { 8035339Sbostic extern char *optarg; 8135339Sbostic extern int optind; 8235339Sbostic register struct fstab *fs; 8335339Sbostic register int cnt; 8438632Smckusick int all, ch, rval, sfake, i; 8538632Smckusick long mntsize; 8638632Smckusick struct statfs statfsbuf, *mntbuf; 8739131Smckusick char *type, *options = NULL; 881057Sbill 8939131Smckusick envp = arge; 9035339Sbostic all = 0; 9135339Sbostic type = NULL; 9238445Smckusick mnttype = MOUNT_UFS; 9338445Smckusick while ((ch = getopt(argc, argv, "afrwvt:o:")) != EOF) 9435339Sbostic switch((char)ch) { 9535339Sbostic case 'a': 9635339Sbostic all = 1; 9735339Sbostic break; 9835339Sbostic case 'f': 9935339Sbostic fake = 1; 10035339Sbostic break; 10135339Sbostic case 'r': 10212808Ssam type = FSTAB_RO; 10335339Sbostic break; 10435339Sbostic case 'v': 10535339Sbostic verbose = 1; 10635339Sbostic break; 10735339Sbostic case 'w': 10835339Sbostic type = FSTAB_RW; 10935339Sbostic break; 11039131Smckusick case 'o': 11139131Smckusick options = optarg; 11239131Smckusick break; 11338445Smckusick case 't': 11439133Smckusick if (mnttype = getmnttype(optarg)) 11539131Smckusick break; 11639131Smckusick /* fall through */ 11735339Sbostic case '?': 11835339Sbostic default: 11935339Sbostic usage(); 12039131Smckusick /* NOTREACHED */ 1215073Sroot } 12235339Sbostic argc -= optind; 12335339Sbostic argv += optind; 12435339Sbostic 12535339Sbostic /* NOSTRICT */ 12635339Sbostic 1274460Sroot if (all) { 12835369Sbostic rval = 0; 12935372Sbostic for (sfake = fake; fs = getfsent(); fake = sfake) { 13035372Sbostic if (BADTYPE(fs->fs_type)) 13135372Sbostic continue; 13235372Sbostic /* `/' is special, it's always mounted */ 13335372Sbostic if (!strcmp(fs->fs_file, "/")) 13435372Sbostic fake = 1; 13539133Smckusick if ((mnttype = getmnttype(fs->fs_vfstype)) == 0) { 13639133Smckusick fprintf(stderr, 13739133Smckusick "%s %s type of file system is unknown.\n", 13839133Smckusick "mount:", fs->fs_vfstype); 13939133Smckusick continue; 14039133Smckusick } 14135372Sbostic rval |= mountfs(fs->fs_spec, fs->fs_file, 14239131Smckusick type ? type : fs->fs_type, options, fs->fs_mntops); 14335372Sbostic } 14435341Sbostic exit(rval); 14535339Sbostic } 1465073Sroot 14735339Sbostic if (argc == 0) { 14835339Sbostic if (verbose || fake || type) 14935339Sbostic usage(); 15038632Smckusick if ((mntsize = getfsstat(0, 0)) < 0) { 15138632Smckusick perror("mount"); 15238632Smckusick exit(1); 15338632Smckusick } 15438632Smckusick mntbuf = 0; 15538632Smckusick do { 15638632Smckusick if (mntbuf) 15738632Smckusick free(mntbuf); 15838632Smckusick i = (mntsize + 1) * sizeof(struct statfs); 15938632Smckusick if ((mntbuf = (struct statfs *)malloc(i)) == 0) { 16038632Smckusick fprintf(stderr, 16138632Smckusick "no space for mount table buffer\n"); 16238632Smckusick exit(1); 16338632Smckusick } 16438632Smckusick if ((mntsize = getfsstat(mntbuf, i)) < 0) { 16539131Smckusick perror("mount"); 16638632Smckusick exit(1); 16738632Smckusick } 16838632Smckusick } while (i == mntsize * sizeof(struct statfs)); 169*39316Smckusick for (i = 0; i < mntsize; i++) 17038632Smckusick prmount(mntbuf[i].f_mntfromname, mntbuf[i].f_mntonname, 171*39316Smckusick mntbuf[i].f_flags); 1724460Sroot exit(0); 1731057Sbill } 17412808Ssam 17535339Sbostic if (argc == 1) { 17635339Sbostic if (!(fs = getfsfile(*argv)) && !(fs = getfsspec(*argv))) { 17735339Sbostic fprintf(stderr, 17835339Sbostic "mount: unknown special file or file system %s.\n", 17935339Sbostic *argv); 18035339Sbostic exit(1); 18135339Sbostic } 18235339Sbostic if (BADTYPE(fs->fs_type)) { 18335339Sbostic fprintf(stderr, 18435339Sbostic "mount: %s has unknown file system type.\n", *argv); 18535339Sbostic exit(1); 18635339Sbostic } 18739133Smckusick if ((mnttype = getmnttype(fs->fs_vfstype)) == 0) { 18839133Smckusick fprintf(stderr, 18939133Smckusick "mount: %s type of file system is unknown.\n", 19039133Smckusick fs->fs_vfstype); 19139133Smckusick exit(1); 19239133Smckusick } 19335369Sbostic exit(mountfs(fs->fs_spec, fs->fs_file, 19439131Smckusick type ? type : fs->fs_type, options, fs->fs_mntops)); 19512808Ssam } 1961057Sbill 19735339Sbostic if (argc != 2) 19835339Sbostic usage(); 19912808Ssam 20039131Smckusick exit(mountfs(argv[0], argv[1], type ? type : "rw", options, NULL)); 20112808Ssam } 20212808Ssam 20339131Smckusick mountfs(spec, name, type, options, mntopts) 20439131Smckusick char *spec, *name, *type, *options, *mntopts; 20512808Ssam { 20635339Sbostic extern int errno; 20735339Sbostic register int cnt; 20839131Smckusick int flags, argc, status, i; 20938070Smckusick struct ufs_args args; 21039131Smckusick char *argp, *argv[50]; 2111057Sbill 212*39316Smckusick flags = 0; 213*39316Smckusick if (!strcmp(type, FSTAB_RO)) 214*39316Smckusick flags |= M_RDONLY; 215*39316Smckusick if (options) 216*39316Smckusick getstdopts(options, &flags); 217*39316Smckusick if (mntopts) 218*39316Smckusick getstdopts(mntopts, &flags); 219*39316Smckusick switch (mnttype) { 220*39316Smckusick case MOUNT_UFS: 221*39316Smckusick if (options) 222*39316Smckusick getufsopts(options, &flags); 223*39316Smckusick if (mntopts) 224*39316Smckusick getufsopts(mntopts, &flags); 225*39316Smckusick args.fspec = spec; 226*39316Smckusick argp = (caddr_t)&args; 227*39316Smckusick break; 22838632Smckusick 22938632Smckusick #ifdef NFS 230*39316Smckusick case MOUNT_NFS: 231*39316Smckusick if (options) 232*39316Smckusick getnfsopts(options, &nfsargs, &opflags, 233*39316Smckusick &retrycnt); 234*39316Smckusick if (mntopts) 235*39316Smckusick getnfsopts(mntopts, &nfsargs, &opflags, 236*39316Smckusick &retrycnt); 237*39316Smckusick if (argp = getnfsargs(spec, name, type)) 238*39316Smckusick break; 239*39316Smckusick return (1); 24038632Smckusick #endif /* NFS */ 24138632Smckusick 24239131Smckusick #ifdef MFS 243*39316Smckusick case MOUNT_MFS: 244*39316Smckusick argv[0] = "memfs"; 245*39316Smckusick argc = 1; 246*39316Smckusick if (options) 247*39316Smckusick argc += getmfsopts(options, &argv[argc]); 248*39316Smckusick if (mntopts) 249*39316Smckusick argc += getmfsopts(mntopts, &argv[argc]); 250*39316Smckusick argv[argc++] = spec; 251*39316Smckusick argv[argc++] = name; 252*39316Smckusick if (verbose) { 253*39316Smckusick printf("exec:"); 254*39316Smckusick for (i = 0; i < argc; i++) 255*39316Smckusick printf(" %s", argv[i]); 256*39316Smckusick printf("\n"); 257*39316Smckusick } 258*39316Smckusick if (fake) 259*39316Smckusick break; 260*39316Smckusick if (i = vfork()) { 261*39316Smckusick if (i == -1) { 262*39316Smckusick perror("mount: vfork for memfs"); 263*39316Smckusick return (1); 26439131Smckusick } 265*39316Smckusick if (waitpid(i, &status, 0) != -1 && 266*39316Smckusick WIFEXITED(status) && 267*39316Smckusick WEXITSTATUS(status) != 0) 268*39316Smckusick return (WEXITSTATUS(status)); 269*39316Smckusick spec = "memfs"; 270*39316Smckusick goto out; 271*39316Smckusick } 272*39316Smckusick execve(_PATH_MEMFS, argv, envp); 273*39316Smckusick perror(_PATH_MEMFS); 274*39316Smckusick exit (1); 27539131Smckusick #endif /* MFS */ 27639131Smckusick 277*39316Smckusick default: 278*39316Smckusick if (opflags & ISBGRND) 27938632Smckusick exit(1); 280*39316Smckusick fprintf(stderr, "%d: unknown mount type\n", mnttype); 281*39316Smckusick exit(1); 282*39316Smckusick /* NOTREACHED */ 28338632Smckusick 284*39316Smckusick } 285*39316Smckusick if (!fake && mount(mnttype, name, flags, argp)) { 286*39316Smckusick if (opflags & ISBGRND) 287*39316Smckusick exit(1); 288*39316Smckusick fprintf(stderr, "%s on %s: ", spec, name); 289*39316Smckusick switch (errno) { 290*39316Smckusick case EMFILE: 291*39316Smckusick fprintf(stderr, "Mount table full\n"); 292*39316Smckusick break; 293*39316Smckusick case EINVAL: 294*39316Smckusick fprintf(stderr, "Bogus super block\n"); 295*39316Smckusick break; 296*39316Smckusick default: 297*39316Smckusick perror((char *)NULL); 298*39316Smckusick break; 2994460Sroot } 300*39316Smckusick return(1); 3014460Sroot } 30235339Sbostic 30339131Smckusick out: 30412808Ssam if (verbose) 305*39316Smckusick prmount(spec, name, flags); 30635339Sbostic 30738445Smckusick if (opflags & ISBGRND) 30838445Smckusick exit(); 30938445Smckusick else 31038445Smckusick return(0); 3111057Sbill } 31235339Sbostic 31335339Sbostic static 314*39316Smckusick prmount(spec, name, flags) 315*39316Smckusick char *spec, *name; 316*39316Smckusick long flags; 31735339Sbostic { 31838632Smckusick register char *root; 31938632Smckusick 32038445Smckusick if (opflags & ISBGRND) 32138445Smckusick return; 32238632Smckusick /* 32338632Smckusick * trim trailing /'s and find last component of name 32438632Smckusick */ 32538632Smckusick for (root = index(spec, '\0'); *--root == '/';) 32638632Smckusick /* void */; 32738632Smckusick *++root = '\0'; 32838632Smckusick if (root = rindex(spec, '/')) 32938632Smckusick spec = root + 1; 33038632Smckusick printf("%s on %s", spec, name); 331*39316Smckusick if (flags & M_RDONLY) 332*39316Smckusick printf(" (read-only)"); 333*39316Smckusick if (flags & M_NOEXEC) 334*39316Smckusick printf(" (noexec)"); 335*39316Smckusick if (flags & M_NOSUID) 336*39316Smckusick printf(" (nosuid)"); 337*39316Smckusick if (flags & M_NODEV) 338*39316Smckusick printf(" (nodev)"); 339*39316Smckusick if (flags & M_SYNCHRONOUS) 340*39316Smckusick printf(" (synchronous)"); 34135339Sbostic printf("\n"); 34235339Sbostic } 34335339Sbostic 34439133Smckusick getmnttype(fstype) 34539133Smckusick char *fstype; 34639133Smckusick { 34739133Smckusick 34839133Smckusick if (!strcmp(fstype, "ufs")) 34939133Smckusick return (MOUNT_UFS); 35039133Smckusick if (!strcmp(fstype, "nfs")) 35139133Smckusick return (MOUNT_NFS); 35239133Smckusick if (!strcmp(fstype, "mfs")) 35339133Smckusick return (MOUNT_MFS); 35439133Smckusick return (0); 35539133Smckusick } 35639133Smckusick 35738632Smckusick usage() 35835339Sbostic { 35938632Smckusick fprintf(stderr, "usage: mount [-afrw]\nor mount [-frw] special | node\nor mount [-frw] special node\n"); 36035339Sbostic exit(1); 36135339Sbostic } 36235339Sbostic 363*39316Smckusick getstdopts(options, flagp) 364*39316Smckusick char *options; 365*39316Smckusick long *flagp; 366*39316Smckusick { 367*39316Smckusick register char *opt; 368*39316Smckusick int negative; 369*39316Smckusick char *optbuf[BUFSIZ], *strtok(); 370*39316Smckusick 371*39316Smckusick strcpy(optbuf, options); 372*39316Smckusick for (opt = strtok(optbuf, ","); opt; opt = strtok(NULL, ",")) { 373*39316Smckusick if (opt[0] == 'n' && opt[1] == 'o') { 374*39316Smckusick negative++; 375*39316Smckusick opt += 2; 376*39316Smckusick } else { 377*39316Smckusick negative = 0; 378*39316Smckusick } 379*39316Smckusick if (!strcasecmp(opt, "exec")) { 380*39316Smckusick if (negative) 381*39316Smckusick *flagp |= M_NOEXEC; 382*39316Smckusick continue; 383*39316Smckusick } 384*39316Smckusick if (!strcasecmp(opt, "suid")) { 385*39316Smckusick if (negative) 386*39316Smckusick *flagp |= M_NOSUID; 387*39316Smckusick continue; 388*39316Smckusick } 389*39316Smckusick if (!strcasecmp(opt, "dev")) { 390*39316Smckusick if (negative) 391*39316Smckusick *flagp |= M_NODEV; 392*39316Smckusick continue; 393*39316Smckusick } 394*39316Smckusick if (!strcasecmp(opt, "synchronous")) { 395*39316Smckusick if (!negative) 396*39316Smckusick *flagp |= M_SYNCHRONOUS; 397*39316Smckusick continue; 398*39316Smckusick } 399*39316Smckusick } 400*39316Smckusick } 401*39316Smckusick 40239131Smckusick getufsopts(options, flagp) 40339131Smckusick char *options; 40439131Smckusick long *flagp; 40539131Smckusick { 40639131Smckusick 40739131Smckusick return; 40839131Smckusick } 40939131Smckusick 41039131Smckusick #ifdef MFS 41139131Smckusick getmfsopts(options, argv) 41239131Smckusick char *options; 41339131Smckusick char **argv; 41439131Smckusick { 41539131Smckusick register int argc = 0; 41639131Smckusick register char *opt; 41739131Smckusick char *strtok(); 41839131Smckusick 41939131Smckusick for (opt = strtok(options, ","); opt; opt = strtok(NULL, ",")) { 42039131Smckusick if (opt[0] != '-') 42139131Smckusick continue; 42239131Smckusick argv[argc++] = opt; 42339131Smckusick if (opt[2] == '\0' || opt[2] != '=') 42439131Smckusick continue; 42539131Smckusick opt[2] = '\0'; 42639131Smckusick argv[argc++] = &opt[3]; 42739131Smckusick } 42839131Smckusick return (argc); 42939131Smckusick } 43039131Smckusick #endif /* MFS */ 43139131Smckusick 43238632Smckusick #ifdef NFS 43339131Smckusick /* 43439131Smckusick * Handle the getoption arg. 43539131Smckusick * Essentially update "opflags", "retrycnt" and "nfsargs" 43639131Smckusick */ 43739131Smckusick getnfsopts(optarg, nfsargsp, opflagsp, retrycntp) 43839131Smckusick char *optarg; 43939131Smckusick struct nfs_args *nfsargsp; 44039131Smckusick int *opflagsp; 44139131Smckusick int *retrycntp; 44239131Smckusick { 44339131Smckusick register char *cp, *nextcp; 44439131Smckusick int num; 44539131Smckusick char *nump; 44639131Smckusick 44739131Smckusick cp = optarg; 44839131Smckusick while (cp != NULL && *cp != '\0') { 44939131Smckusick if ((nextcp = index(cp, ',')) != NULL) 45039131Smckusick *nextcp++ = '\0'; 45139131Smckusick if ((nump = index(cp, '=')) != NULL) { 45239131Smckusick *nump++ = '\0'; 45339131Smckusick num = atoi(nump); 45439131Smckusick } else 45539131Smckusick num = -1; 45639131Smckusick /* 45739131Smckusick * Just test for a string match and do it 45839131Smckusick */ 45939131Smckusick if (!strcmp(cp, "bg")) { 46039131Smckusick *opflagsp |= BGRND; 46139131Smckusick } else if (!strcmp(cp, "soft")) { 46239131Smckusick nfsargsp->flags |= NFSMNT_SOFT; 46339131Smckusick } else if (!strcmp(cp, "intr")) { 46439131Smckusick nfsargsp->flags |= NFSMNT_INT; 46539131Smckusick } else if (!strcmp(cp, "retry") && num > 0) { 46639131Smckusick *retrycntp = num; 46739131Smckusick } else if (!strcmp(cp, "rsize") && num > 0) { 46839131Smckusick nfsargsp->rsize = num; 46939131Smckusick nfsargsp->flags |= NFSMNT_RSIZE; 47039131Smckusick } else if (!strcmp(cp, "wsize") && num > 0) { 47139131Smckusick nfsargsp->wsize = num; 47239131Smckusick nfsargsp->flags |= NFSMNT_WSIZE; 47339131Smckusick } else if (!strcmp(cp, "timeo") && num > 0) { 47439131Smckusick nfsargsp->timeo = num; 47539131Smckusick nfsargsp->flags |= NFSMNT_TIMEO; 47639131Smckusick } else if (!strcmp(cp, "retrans") && num > 0) { 47739131Smckusick nfsargsp->retrans = num; 47839131Smckusick nfsargsp->flags |= NFSMNT_RETRANS; 47939131Smckusick } 48039131Smckusick cp = nextcp; 48139131Smckusick } 48239131Smckusick } 48339131Smckusick 48438632Smckusick char * 48538632Smckusick getnfsargs(spec) 48638632Smckusick char *spec; 48735339Sbostic { 48838632Smckusick register CLIENT *clp; 48938632Smckusick struct hostent *hp; 49038632Smckusick struct sockaddr_in saddr; 49138632Smckusick struct timeval pertry, try; 49238632Smckusick enum clnt_stat clnt_stat; 49338632Smckusick int so = RPC_ANYSOCK; 49438632Smckusick char *hostp, *delimp; 49538632Smckusick u_short tport; 49638632Smckusick struct nfhret nfhret; 49738632Smckusick char nam[MNAMELEN + 1]; 49838632Smckusick 49938632Smckusick strncpy(nam, spec, MNAMELEN); 50038632Smckusick nam[MNAMELEN] = '\0'; 50138632Smckusick if ((delimp = index(spec, '@')) != NULL) { 50238632Smckusick hostp = delimp + 1; 50338632Smckusick } else if ((delimp = index(spec, ':')) != NULL) { 50438632Smckusick hostp = spec; 50538632Smckusick spec = delimp + 1; 50638632Smckusick } else { 50738632Smckusick fprintf(stderr, 50838632Smckusick "No <host>:<dirpath> or <dirpath>@<host> spec\n"); 50938632Smckusick return (0); 51038632Smckusick } 51138632Smckusick *delimp = '\0'; 51238632Smckusick if ((hp = gethostbyname(hostp)) == NULL) { 51338632Smckusick fprintf(stderr, "Can't get net id for host\n"); 51438632Smckusick return (0); 51538632Smckusick } 51638632Smckusick bcopy(hp->h_addr, (caddr_t)&saddr.sin_addr, hp->h_length); 51738632Smckusick nfhret.stat = EACCES; /* Mark not yet successful */ 51838632Smckusick while (retrycnt > 0) { 51938632Smckusick saddr.sin_family = AF_INET; 52038632Smckusick saddr.sin_port = htons(PMAPPORT); 52138632Smckusick if ((tport = pmap_getport(&saddr, RPCPROG_NFS, 52238632Smckusick NFS_VER2, IPPROTO_UDP)) == 0) { 52338632Smckusick if ((opflags & ISBGRND) == 0) 52438632Smckusick clnt_pcreateerror("NFS Portmap"); 52538632Smckusick } else { 52638632Smckusick saddr.sin_port = 0; 52738632Smckusick pertry.tv_sec = 10; 52838632Smckusick pertry.tv_usec = 0; 52938632Smckusick if ((clp = clntudp_create(&saddr, RPCPROG_MNT, 53038632Smckusick RPCMNT_VER1, pertry, &so)) == NULL) { 53138632Smckusick if ((opflags & ISBGRND) == 0) 53238632Smckusick clnt_pcreateerror("Cannot MNT PRC"); 53338632Smckusick } else { 53438632Smckusick clp->cl_auth = authunix_create_default(); 53538632Smckusick try.tv_sec = 10; 53638632Smckusick try.tv_usec = 0; 53738632Smckusick clnt_stat = clnt_call(clp, RPCMNT_MOUNT, 53838632Smckusick xdr_dir, spec, xdr_fh, &nfhret, try); 53938632Smckusick if (clnt_stat != RPC_SUCCESS) { 54038632Smckusick if ((opflags & ISBGRND) == 0) 54138632Smckusick clnt_perror(clp, "Bad MNT RPC"); 54238632Smckusick } else { 54338632Smckusick auth_destroy(clp->cl_auth); 54438632Smckusick clnt_destroy(clp); 54538632Smckusick retrycnt = 0; 54638632Smckusick } 54738632Smckusick } 54838632Smckusick } 54938632Smckusick if (--retrycnt > 0) { 55038632Smckusick if (opflags & BGRND) { 55138632Smckusick opflags &= ~BGRND; 55238632Smckusick if (fork()) 55338632Smckusick return (0); 55438632Smckusick else 55538632Smckusick opflags |= ISBGRND; 55638632Smckusick } 55738632Smckusick sleep(10); 55838632Smckusick } 55938632Smckusick } 56038632Smckusick if (nfhret.stat) { 56138632Smckusick if (opflags & ISBGRND) 56238632Smckusick exit(1); 56338632Smckusick fprintf(stderr, "Can't access %s, errno=%d\n", spec, 56438632Smckusick nfhret.stat); 56538632Smckusick return (0); 56638632Smckusick } 56738632Smckusick saddr.sin_port = htons(tport); 56838632Smckusick nfsargs.addr = &saddr; 56938632Smckusick nfsargs.fh = &nfhret.nfh; 57038632Smckusick nfsargs.hostname = nam; 57138632Smckusick return ((caddr_t)&nfsargs); 57235339Sbostic } 57338445Smckusick 57438445Smckusick /* 57538445Smckusick * xdr routines for mount rpc's 57638445Smckusick */ 57738445Smckusick xdr_dir(xdrsp, dirp) 57838445Smckusick XDR *xdrsp; 57938445Smckusick char *dirp; 58038445Smckusick { 58138445Smckusick return (xdr_string(xdrsp, &dirp, RPCMNT_PATHLEN)); 58238445Smckusick } 58338445Smckusick 58438445Smckusick xdr_fh(xdrsp, np) 58538445Smckusick XDR *xdrsp; 58638445Smckusick struct nfhret *np; 58738445Smckusick { 58838445Smckusick if (!xdr_u_long(xdrsp, &(np->stat))) 58938445Smckusick return (0); 59038445Smckusick if (np->stat) 59138445Smckusick return (1); 59238445Smckusick return (xdr_opaque(xdrsp, (caddr_t)&(np->nfh), NFSX_FH)); 59338445Smckusick } 59438632Smckusick #endif /* NFS */ 595