2 * nfsmount.c -- Linux NFS mount
3 * Copyright (C) 1993 Rick Sladkey <jrs@world.std.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * Wed Feb 8 12:51:48 1995, biro@yggdrasil.com (Ross Biro): allow all port
16 * numbers to be specified on the command line.
18 * Fri, 8 Mar 1996 18:01:39, Swen Thuemmler <swen@uni-paderborn.de>:
19 * Omit the call to connect() for Linux version 1.3.11 or later.
21 * Wed Oct 1 23:55:28 1997: Dick Streefland <dick_streefland@tasking.com>
22 * Implemented the "bg", "fg" and "retry" mount options for NFS.
24 * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
25 * - added Native Language Support
27 * Modified by Olaf Kirch and Trond Myklebust for new NFS code,
30 * 2006-06-06 Amit Gud <agud@redhat.com>
31 * - Moved with modifcations to nfs-utils/utils/mount from util-linux/mount.
35 * nfsmount.c,v 1.1.1.1 1993/11/18 08:40:51 jrs Exp
47 #include <rpc/pmap_prot.h>
48 #include <rpc/pmap_clnt.h>
49 #include <sys/socket.h>
52 #include <netinet/in.h>
53 #include <arpa/inet.h>
55 #include <sys/mount.h>
62 #include "nfsumount.h"
63 #include "nfs_mount.h"
64 #include "mount_constants.h"
75 #ifndef HAVE_INET_ATON
76 #define inet_aton(a,b) (0)
79 typedef dirpath mnt2arg_t;
80 typedef dirpath mnt3arg_t;
81 typedef dirpath mntarg_t;
83 typedef struct fhstatus mnt2res_t;
84 typedef struct mountres3 mnt3res_t;
90 extern int nfs_mount_data_version;
94 extern int linux_version_code();
96 static const unsigned int probe_udp_only[] = {
101 static const unsigned int probe_udp_first[] = {
107 static const unsigned int probe_tcp_first[] = {
113 static const unsigned long probe_nfs2_only[] = {
118 static const unsigned long probe_nfs3_first[] = {
124 static const unsigned long probe_mnt1_first[] = {
130 static const unsigned long probe_mnt3_first[] = {
137 int nfs_gethostbyname(const char *, struct sockaddr_in *);
138 int nfs_gethostbyname(const char *hostname, struct sockaddr_in *saddr)
142 saddr->sin_family = AF_INET;
143 if (!inet_aton(hostname, &saddr->sin_addr)) {
144 if ((hp = gethostbyname(hostname)) == NULL) {
145 fprintf(stderr, _("mount: can't get address for %s\n"),
149 if (hp->h_length > sizeof(*saddr)) {
151 _("mount: got bad hp->h_length\n"));
152 hp->h_length = sizeof(*saddr);
154 memcpy(&saddr->sin_addr, hp->h_addr, hp->h_length);
161 * getport() is very similar to pmap_getport() with
162 * the exception this version uses a non-reserve ports
163 * instead of reserve ports since reserve ports
164 * are not needed for pmap requests.
168 struct sockaddr_in *saddr,
179 saddr->sin_port = htons (PMAPPORT);
180 socket = get_socket(saddr, prot, FALSE, FALSE);
184 clnt = clntudp_bufcreate(saddr,
185 PMAPPROG, PMAPVERS, TIMEOUT, &socket,
186 UDPMSGSIZE, UDPMSGSIZE);
189 clnt = clnttcp_create(saddr,
190 PMAPPROG, PMAPVERS, &socket, 50, 500);
194 parms.pm_prog = prog;
195 parms.pm_vers = vers;
196 parms.pm_prot = prot;
197 parms.pm_port = 0; /* not needed or used */
199 stat = clnt_call(clnt, PMAPPROC_GETPORT, (xdrproc_t)xdr_pmap,
200 (caddr_t)&parms, (xdrproc_t)xdr_u_short, (caddr_t)&port, TIMEOUT);
202 clnt_geterr(clnt, &rpc_createerr.cf_error);
203 rpc_createerr.cf_stat = stat;
206 if (stat != RPC_SUCCESS)
209 rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
218 * Use the portmapper to discover whether or not the service we want is
219 * available. The lists 'versions' and 'protos' define ordered sequences
220 * of service versions and udp/tcp protocols to probe for.
223 probe_port(clnt_addr_t *server,
224 const u_long *versions,
227 struct sockaddr_in *saddr = &server->saddr;
228 struct pmap *pmap = &server->pmap;
229 const u_long prog = pmap->pm_prog, *p_vers;
230 const u_int prot = (u_int)pmap->pm_prot,
232 const u_short port = (u_short) pmap->pm_port;
233 u_long vers = pmap->pm_vers;
235 p_prot = prot ? &prot : protos;
236 p_vers = vers ? &vers : versions;
237 rpc_createerr.cf_stat = 0;
239 saddr->sin_port = htons(PMAPPORT);
240 p_port = getport(saddr, prog, *p_vers, *p_prot);
242 if (!port || port == p_port) {
243 saddr->sin_port = htons(p_port);
246 "mount: trying %s prog %ld vers %ld prot %s port %d\n",
247 inet_ntoa(saddr->sin_addr), prog, *p_vers,
248 *p_prot == IPPROTO_UDP ? "udp" : "tcp", p_port);
250 if (clnt_ping(saddr, prog, *p_vers, *p_prot, NULL))
252 if (rpc_createerr.cf_stat == RPC_TIMEDOUT)
256 if (rpc_createerr.cf_stat != RPC_PROGNOTREGISTERED)
264 if (vers == pmap->pm_vers) {
268 if (vers || !*++p_vers)
276 pmap->pm_vers = *p_vers;
278 pmap->pm_prot = *p_prot;
280 pmap->pm_port = p_port;
281 rpc_createerr.cf_stat = 0;
285 static int probe_nfsport(clnt_addr_t *nfs_server)
287 struct pmap *pmap = &nfs_server->pmap;
289 if (pmap->pm_vers && pmap->pm_prot && pmap->pm_port)
292 if (nfs_mount_data_version >= 4)
293 return probe_port(nfs_server, probe_nfs3_first, probe_tcp_first);
295 return probe_port(nfs_server, probe_nfs2_only, probe_udp_only);
298 int probe_mntport(clnt_addr_t *mnt_server)
300 struct pmap *pmap = &mnt_server->pmap;
302 if (pmap->pm_vers && pmap->pm_prot && pmap->pm_port)
305 if (nfs_mount_data_version >= 4)
306 return probe_port(mnt_server, probe_mnt3_first, probe_udp_first);
308 return probe_port(mnt_server, probe_mnt1_first, probe_udp_only);
312 probe_bothports(clnt_addr_t *mnt_server, clnt_addr_t *nfs_server)
314 struct pmap *nfs_pmap = &nfs_server->pmap;
315 struct pmap *mnt_pmap = &mnt_server->pmap;
316 struct pmap save_nfs, save_mnt;
318 const unsigned long *probe_vers;
320 if (mnt_pmap->pm_vers && !nfs_pmap->pm_vers)
321 nfs_pmap->pm_vers = mntvers_to_nfs(mnt_pmap->pm_vers);
322 else if (nfs_pmap->pm_vers && !mnt_pmap->pm_vers)
323 mnt_pmap->pm_vers = nfsvers_to_mnt(nfs_pmap->pm_vers);
324 if (nfs_pmap->pm_vers)
327 memcpy(&save_nfs, nfs_pmap, sizeof(save_nfs));
328 memcpy(&save_mnt, mnt_pmap, sizeof(save_mnt));
329 probe_vers = (nfs_mount_data_version >= 4) ?
330 probe_mnt3_first : probe_mnt1_first;
332 for (; *probe_vers; probe_vers++) {
333 nfs_pmap->pm_vers = mntvers_to_nfs(*probe_vers);
334 if ((res = probe_nfsport(nfs_server) != 0)) {
335 mnt_pmap->pm_vers = nfsvers_to_mnt(nfs_pmap->pm_vers);
336 if ((res = probe_mntport(mnt_server)) != 0)
338 memcpy(mnt_pmap, &save_mnt, sizeof(*mnt_pmap));
340 switch (rpc_createerr.cf_stat) {
341 case RPC_PROGVERSMISMATCH:
342 case RPC_PROGNOTREGISTERED:
347 memcpy(nfs_pmap, &save_nfs, sizeof(*nfs_pmap));
354 if (!probe_nfsport(nfs_server))
356 return probe_mntport(mnt_server);
359 static inline enum clnt_stat
360 nfs3_mount(CLIENT *clnt, mnt3arg_t *mnt3arg, mnt3res_t *mnt3res)
362 return clnt_call(clnt, MOUNTPROC3_MNT,
363 (xdrproc_t) xdr_dirpath, (caddr_t) mnt3arg,
364 (xdrproc_t) xdr_mountres3, (caddr_t) mnt3res,
368 static inline enum clnt_stat
369 nfs2_mount(CLIENT *clnt, mnt2arg_t *mnt2arg, mnt2res_t *mnt2res)
371 return clnt_call(clnt, MOUNTPROC_MNT,
372 (xdrproc_t) xdr_dirpath, (caddr_t) mnt2arg,
373 (xdrproc_t) xdr_fhstatus, (caddr_t) mnt2res,
378 nfs_call_mount(clnt_addr_t *mnt_server, clnt_addr_t *nfs_server,
379 mntarg_t *mntarg, mntres_t *mntres)
385 if (!probe_bothports(mnt_server, nfs_server))
388 clnt = mnt_openclnt(mnt_server, &msock);
391 /* make pointers in xdr_mountres3 NULL so
392 * that xdr_array allocates memory for us
394 memset(mntres, 0, sizeof(*mntres));
395 switch (mnt_server->pmap.pm_vers) {
397 stat = nfs3_mount(clnt, mntarg, &mntres->nfsv3);
401 stat = nfs2_mount(clnt, mntarg, &mntres->nfsv2);
406 if (stat != RPC_SUCCESS) {
407 clnt_geterr(clnt, &rpc_createerr.cf_error);
408 rpc_createerr.cf_stat = stat;
410 mnt_closeclnt(clnt, msock);
411 if (stat == RPC_SUCCESS)
418 parse_options(char *old_opts, struct nfs_mount_data *data,
419 int *bg, int *retry, clnt_addr_t *mnt_server,
420 clnt_addr_t *nfs_server, char *new_opts, const int opt_size)
422 struct sockaddr_in *mnt_saddr = &mnt_server->saddr;
423 struct pmap *mnt_pmap = &mnt_server->pmap;
424 struct pmap *nfs_pmap = &nfs_server->pmap;
426 char *opt, *opteq, *p, *opt_b;
427 char *mounthost = NULL;
434 len = strlen(new_opts);
435 for (p=old_opts, opt_b=NULL; p && *p; p++) {
437 opt_b = p; /* begin of the option item */
439 open_quote ^= 1; /* reverse the status */
441 continue; /* still in a quoted block */
443 *p = '\0'; /* terminate the option item */
444 if (*p == '\0' || *(p+1) == '\0') {
445 opt = opt_b; /* opt is useful now */
449 continue; /* still somewhere in the option item */
451 if (strlen(opt) >= sizeof(cbuf))
453 if ((opteq = strchr(opt, '=')) && isdigit(opteq[1])) {
454 int val = atoi(opteq + 1);
456 /* printf("opt=%s\n", opt); */
457 if (!strcmp(opt, "rsize"))
459 else if (!strcmp(opt, "wsize"))
461 else if (!strcmp(opt, "timeo"))
463 else if (!strcmp(opt, "retrans"))
465 else if (!strcmp(opt, "acregmin"))
466 data->acregmin = val;
467 else if (!strcmp(opt, "acregmax"))
468 data->acregmax = val;
469 else if (!strcmp(opt, "acdirmin"))
470 data->acdirmin = val;
471 else if (!strcmp(opt, "acdirmax"))
472 data->acdirmax = val;
473 else if (!strcmp(opt, "actimeo")) {
474 data->acregmin = val;
475 data->acregmax = val;
476 data->acdirmin = val;
477 data->acdirmax = val;
479 else if (!strcmp(opt, "retry"))
481 else if (!strcmp(opt, "port"))
482 nfs_pmap->pm_port = val;
483 else if (!strcmp(opt, "mountport"))
484 mnt_pmap->pm_port = val;
485 else if (!strcmp(opt, "mountprog"))
486 mnt_pmap->pm_prog = val;
487 else if (!strcmp(opt, "mountvers"))
488 mnt_pmap->pm_vers = val;
489 else if (!strcmp(opt, "mounthost"))
490 mounthost=xstrndup(opteq+1, strcspn(opteq+1," \t\n\r,"));
491 else if (!strcmp(opt, "nfsprog"))
492 nfs_pmap->pm_prog = val;
493 else if (!strcmp(opt, "nfsvers") ||
494 !strcmp(opt, "vers")) {
495 nfs_pmap->pm_vers = val;
497 #if NFS_MOUNT_VERSION >= 2
498 } else if (!strcmp(opt, "namlen")) {
499 if (nfs_mount_data_version >= 2)
506 } else if (!strcmp(opt, "addr")) {
513 sprintf(cbuf, "%s=%s,", opt, opteq+1);
516 if (!strcmp(opt, "proto")) {
517 if (!strcmp(opteq+1, "udp")) {
518 nfs_pmap->pm_prot = IPPROTO_UDP;
519 mnt_pmap->pm_prot = IPPROTO_UDP;
520 #if NFS_MOUNT_VERSION >= 2
521 data->flags &= ~NFS_MOUNT_TCP;
522 } else if (!strcmp(opteq+1, "tcp") &&
523 nfs_mount_data_version > 2) {
524 nfs_pmap->pm_prot = IPPROTO_TCP;
525 mnt_pmap->pm_prot = IPPROTO_TCP;
526 data->flags |= NFS_MOUNT_TCP;
532 #if NFS_MOUNT_VERSION >= 5
533 } else if (!strcmp(opt, "sec")) {
534 char *secflavor = opteq+1;
536 if (nfs_mount_data_version < 5) {
537 printf(_("Warning: ignoring sec=%s option\n"), secflavor);
539 } else if (!strcmp(secflavor, "none"))
540 data->pseudoflavor = AUTH_NONE;
541 else if (!strcmp(secflavor, "sys"))
542 data->pseudoflavor = AUTH_SYS;
543 else if (!strcmp(secflavor, "krb5"))
544 data->pseudoflavor = AUTH_GSS_KRB5;
545 else if (!strcmp(secflavor, "krb5i"))
546 data->pseudoflavor = AUTH_GSS_KRB5I;
547 else if (!strcmp(secflavor, "krb5p"))
548 data->pseudoflavor = AUTH_GSS_KRB5P;
549 else if (!strcmp(secflavor, "lipkey"))
550 data->pseudoflavor = AUTH_GSS_LKEY;
551 else if (!strcmp(secflavor, "lipkey-i"))
552 data->pseudoflavor = AUTH_GSS_LKEYI;
553 else if (!strcmp(secflavor, "lipkey-p"))
554 data->pseudoflavor = AUTH_GSS_LKEYP;
555 else if (!strcmp(secflavor, "spkm3"))
556 data->pseudoflavor = AUTH_GSS_SPKM;
557 else if (!strcmp(secflavor, "spkm3i"))
558 data->pseudoflavor = AUTH_GSS_SPKMI;
559 else if (!strcmp(secflavor, "spkm3p"))
560 data->pseudoflavor = AUTH_GSS_SPKMP;
564 printf(_("Warning: Unrecognized security flavor %s.\n"),
568 data->flags |= NFS_MOUNT_SECFLAVOUR;
570 } else if (!strcmp(opt, "mounthost"))
571 mounthost=xstrndup(opteq+1,
572 strcspn(opteq+1," \t\n\r,"));
573 else if (!strcmp(opt, "context")) {
574 char *context = opteq + 1;
575 int ctxlen = strlen(context);
577 if (ctxlen > NFS_MAX_CONTEXT_LEN) {
578 printf(_("context parameter exceeds limit of %d\n"),
579 NFS_MAX_CONTEXT_LEN);
582 /* The context string is in the format of
583 * "system_u:object_r:...". We only want
584 * the context str between the quotes.
587 strncpy(data->context, context+1,
590 strncpy(data->context, context,
591 NFS_MAX_CONTEXT_LEN);
596 sprintf(cbuf, "%s=%s,", opt, opteq+1);
599 if (!strncmp(opt, "no", 2)) {
603 if (!strcmp(opt, "bg"))
605 else if (!strcmp(opt, "fg"))
607 else if (!strcmp(opt, "soft")) {
608 data->flags &= ~NFS_MOUNT_SOFT;
610 data->flags |= NFS_MOUNT_SOFT;
611 } else if (!strcmp(opt, "hard")) {
612 data->flags &= ~NFS_MOUNT_SOFT;
614 data->flags |= NFS_MOUNT_SOFT;
615 } else if (!strcmp(opt, "intr")) {
616 data->flags &= ~NFS_MOUNT_INTR;
618 data->flags |= NFS_MOUNT_INTR;
619 } else if (!strcmp(opt, "posix")) {
620 data->flags &= ~NFS_MOUNT_POSIX;
622 data->flags |= NFS_MOUNT_POSIX;
623 } else if (!strcmp(opt, "cto")) {
624 data->flags &= ~NFS_MOUNT_NOCTO;
626 data->flags |= NFS_MOUNT_NOCTO;
627 } else if (!strcmp(opt, "ac")) {
628 data->flags &= ~NFS_MOUNT_NOAC;
630 data->flags |= NFS_MOUNT_NOAC;
631 #if NFS_MOUNT_VERSION >= 2
632 } else if (!strcmp(opt, "tcp")) {
633 data->flags &= ~NFS_MOUNT_TCP;
635 if (nfs_mount_data_version < 2)
637 nfs_pmap->pm_prot = IPPROTO_TCP;
638 mnt_pmap->pm_prot = IPPROTO_TCP;
639 data->flags |= NFS_MOUNT_TCP;
641 mnt_pmap->pm_prot = IPPROTO_UDP;
642 nfs_pmap->pm_prot = IPPROTO_UDP;
644 } else if (!strcmp(opt, "udp")) {
645 data->flags &= ~NFS_MOUNT_TCP;
647 if (nfs_mount_data_version < 2)
649 nfs_pmap->pm_prot = IPPROTO_TCP;
650 mnt_pmap->pm_prot = IPPROTO_TCP;
651 data->flags |= NFS_MOUNT_TCP;
653 nfs_pmap->pm_prot = IPPROTO_UDP;
654 mnt_pmap->pm_prot = IPPROTO_UDP;
657 #if NFS_MOUNT_VERSION >= 3
658 } else if (!strcmp(opt, "lock")) {
659 data->flags &= ~NFS_MOUNT_NONLM;
661 if (nfs_mount_data_version < 3)
663 data->flags |= NFS_MOUNT_NONLM;
666 #if NFS_MOUNT_VERSION >= 4
667 } else if (!strcmp(opt, "broken_suid")) {
668 data->flags &= ~NFS_MOUNT_BROKEN_SUID;
670 if (nfs_mount_data_version < 4)
672 data->flags |= NFS_MOUNT_BROKEN_SUID;
674 } else if (!strcmp(opt, "acl")) {
675 data->flags &= ~NFS_MOUNT_NOACL;
677 data->flags |= NFS_MOUNT_NOACL;
678 } else if (!strcmp(opt, "rdirplus")) {
679 data->flags &= ~NFS_MOUNT_NORDIRPLUS;
681 data->flags |= NFS_MOUNT_NORDIRPLUS;
682 } else if (!strcmp(opt, "sharecache")) {
683 data->flags &= ~NFS_MOUNT_UNSHARED;
685 data->flags |= NFS_MOUNT_UNSHARED;
691 printf(_("Unsupported nfs mount option: "
692 "%s%s\n"), val ? "" : "no", opt);
695 sprintf(cbuf, val ? "%s,":"no%s,", opt);
698 if (len >= opt_size) {
699 printf(_("mount: excessively long option argument\n"));
702 strcat(new_opts, cbuf);
704 /* See if the nfs host = mount host. */
706 if (!nfs_gethostbyname(mounthost, mnt_saddr))
708 *mnt_server->hostname = mounthost;
712 printf(_("Bad nfs mount parameter: %s\n"), opt);
717 static int nfsmnt_check_compat(const struct pmap *nfs_pmap,
718 const struct pmap *mnt_pmap)
720 unsigned int max_nfs_vers = (nfs_mount_data_version >= 4) ? 3 : 2;
721 unsigned int max_mnt_vers = (nfs_mount_data_version >= 4) ? 3 : 2;
723 if (nfs_pmap->pm_vers == 4) {
724 fprintf(stderr, _("Please use '-t nfs4' "
725 "instead of '-o vers=4'.\n"));
729 if (nfs_pmap->pm_vers) {
730 if (nfs_pmap->pm_vers > max_nfs_vers || nfs_pmap->pm_vers < 2) {
731 fprintf(stderr, _("NFS version %ld is not supported.\n"),
737 if (mnt_pmap->pm_vers > max_mnt_vers) {
738 fprintf(stderr, _("NFS mount version %ld s not supported.\n"),
750 nfsmount(const char *spec, const char *node, int *flags,
751 char **extra_opts, char **mount_opts,
752 int running_bg, int *need_statd)
754 static char *prev_bg_host;
756 char *hostname, *dirname, *old_opts, *mounthost = NULL;
757 char new_opts[1024], cbuf[1024];
758 static struct nfs_mount_data data;
760 static int doonce = 0;
762 clnt_addr_t mnt_server = { &mounthost, };
763 clnt_addr_t nfs_server = { &hostname, };
764 struct sockaddr_in *nfs_saddr = &nfs_server.saddr;
765 struct pmap *mnt_pmap = &mnt_server.pmap,
766 *nfs_pmap = &nfs_server.pmap;
767 struct pmap save_mnt, save_nfs;
776 int retval = EX_FAIL;
781 if (strlen(spec) >= sizeof(hostdir)) {
782 fprintf(stderr, _("mount: "
783 "excessively long host:dir argument\n"));
786 strcpy(hostdir, spec);
787 if ((s = strchr(hostdir, ':'))) {
791 /* Ignore all but first hostname in replicated mounts
792 until they can be fully supported. (mack@sgi.com) */
793 if ((s = strchr(hostdir, ','))) {
797 "multiple hostnames not supported\n"));
802 "directory to mount not in host:dir format\n"));
806 if (!nfs_gethostbyname(hostname, nfs_saddr))
808 mounthost = hostname;
809 memcpy (&mnt_server.saddr, nfs_saddr, sizeof (mnt_server.saddr));
811 /* add IP address to mtab options for use when unmounting */
813 s = inet_ntoa(nfs_saddr->sin_addr);
814 old_opts = *extra_opts;
818 /* Set default options.
819 * rsize/wsize (and bsize, for ver >= 3) are left 0 in order to
820 * let the kernel decide.
821 * timeo is filled in after we know whether it'll be TCP or UDP. */
822 memset(&data, 0, sizeof(data));
827 #if NFS_MOUNT_VERSION >= 2
828 data.namlen = NAME_MAX;
832 retry = 10000; /* 10000 minutes ~ 1 week */
834 memset(mnt_pmap, 0, sizeof(*mnt_pmap));
835 mnt_pmap->pm_prog = MOUNTPROG;
836 memset(nfs_pmap, 0, sizeof(*nfs_pmap));
837 nfs_pmap->pm_prog = NFS_PROGRAM;
841 if (!parse_options(old_opts, &data, &bg, &retry, &mnt_server, &nfs_server,
842 new_opts, sizeof(new_opts)))
844 if (!nfsmnt_check_compat(nfs_pmap, mnt_pmap))
847 if (retry == 10000 && !bg)
848 retry = 2; /* reset for fg mounts */
851 #ifdef NFS_MOUNT_DEBUG
852 printf("rsize = %d, wsize = %d, timeo = %d, retrans = %d\n",
853 data.rsize, data.wsize, data.timeo, data.retrans);
854 printf("acreg (min, max) = (%d, %d), acdir (min, max) = (%d, %d)\n",
855 data.acregmin, data.acregmax, data.acdirmin, data.acdirmax);
856 printf("port = %d, bg = %d, retry = %d, flags = %.8x\n",
857 nfs_pmap->pm_port, bg, retry, data.flags);
858 printf("mountprog = %d, mountvers = %d, nfsprog = %d, nfsvers = %d\n",
859 mnt_pmap->pm_prog, mnt_pmap->pm_vers,
860 nfs_pmap->pm_prog, nfs_pmap->pm_vers);
861 printf("soft = %d, intr = %d, posix = %d, nocto = %d, noac = %d ",
862 (data.flags & NFS_MOUNT_SOFT) != 0,
863 (data.flags & NFS_MOUNT_INTR) != 0,
864 (data.flags & NFS_MOUNT_POSIX) != 0,
865 (data.flags & NFS_MOUNT_NOCTO) != 0,
866 (data.flags & NFS_MOUNT_NOAC) != 0);
867 #if NFS_MOUNT_VERSION >= 2
869 (data.flags & NFS_MOUNT_TCP) != 0);
871 #if NFS_MOUNT_VERSION >= 4
872 printf("noacl = %d ", (data.flags & NFS_MOUNT_NOACL) != 0);
874 #if NFS_MOUNT_VERSION >= 5
875 printf("sec = %u ", data.pseudoflavor);
876 printf("readdirplus = %d ", (data.flags & NFS_MOUNT_NORDIRPLUS) != 0);
881 data.version = nfs_mount_data_version;
882 *mount_opts = (char *) &data;
884 if (*flags & MS_REMOUNT)
888 * If the previous mount operation on the same host was
889 * backgrounded, and the "bg" for this mount is also set,
890 * give up immediately, to avoid the initial timeout.
892 if (bg && !running_bg &&
893 prev_bg_host && strcmp(hostname, prev_bg_host) == 0) {
899 /* create mount deamon client */
902 * The following loop implements the mount retries. On the first
903 * call, "running_bg" is 0. When the mount times out, and the
904 * "bg" option is set, the exit status EX_BG will be returned.
905 * For a backgrounded mount, there will be a second call by the
906 * child process with "running_bg" set to 1.
908 * The case where the mount point is not present and the "bg"
909 * option is set, is treated as a timeout. This is done to
910 * support nested mounts.
912 * The "retry" count specified by the user is the number of
913 * minutes to retry before giving up.
915 * Only the first error message will be displayed.
917 timeout = time(NULL) + 60 * retry;
922 memcpy(&save_nfs, nfs_pmap, sizeof(save_nfs));
923 memcpy(&save_mnt, mnt_pmap, sizeof(save_mnt));
925 if (bg && stat(node, &statbuf) == -1) {
926 /* no mount point yet - sleep */
928 sleep(val); /* 1, 2, 4, 8, 16, 30, ... */
935 /* be careful not to use too many CPU cycles */
939 stat = nfs_call_mount(&mnt_server, &nfs_server,
943 memcpy(nfs_pmap, &save_nfs, sizeof(*nfs_pmap));
944 memcpy(mnt_pmap, &save_mnt, sizeof(*mnt_pmap));
948 switch(rpc_createerr.cf_stat){
951 case RPC_SYSTEMERROR:
952 if (errno == ETIMEDOUT)
955 mount_errors(*nfs_server.hostname, 0, bg);
960 mount_errors(*nfs_server.hostname, 0, bg);
963 mount_errors(*nfs_server.hostname, 1, bg);
967 prev_bg_host = xstrdup(hostname);
974 mount_errors(*nfs_server.hostname, 0, bg);
978 mount_errors(*nfs_server.hostname, 1, bg);
981 if (nfs_pmap->pm_vers == 2) {
982 if (mntres.nfsv2.fhs_status != 0) {
984 _("mount: %s:%s failed, reason given by server: %s\n"),
986 nfs_strerror(mntres.nfsv2.fhs_status));
989 memcpy(data.root.data,
990 (char *) mntres.nfsv2.fhstatus_u.fhs_fhandle,
992 #if NFS_MOUNT_VERSION >= 4
993 data.root.size = NFS_FHSIZE;
994 memcpy(data.old_root.data,
995 (char *) mntres.nfsv2.fhstatus_u.fhs_fhandle,
999 #if NFS_MOUNT_VERSION >= 4
1000 mountres3_ok *mountres;
1002 int i, *flavor, yum = 0;
1003 if (mntres.nfsv3.fhs_status != 0) {
1005 _("mount: %s:%s failed, reason given by server: %s\n"),
1007 nfs_strerror(mntres.nfsv3.fhs_status));
1010 #if NFS_MOUNT_VERSION >= 5
1011 mountres = &mntres.nfsv3.mountres3_u.mountinfo;
1012 i = mountres->auth_flavors.auth_flavors_len;
1014 goto noauth_flavors;
1016 flavor = mountres->auth_flavors.auth_flavors_val;
1018 /* If no flavour requested, use first simple
1019 * flavour that is offered.
1021 if (! (data.flags & NFS_MOUNT_SECFLAVOUR) &&
1022 (flavor[i] == AUTH_SYS ||
1023 flavor[i] == AUTH_NONE)) {
1024 data.pseudoflavor = flavor[i];
1025 data.flags |= NFS_MOUNT_SECFLAVOUR;
1027 if (flavor[i] == data.pseudoflavor)
1029 #ifdef NFS_MOUNT_DEBUG
1030 printf("auth flavor %d: %d\n",
1036 "mount: %s:%s failed, "
1037 "security flavor not supported\n",
1039 /* server has registered us in rmtab, send umount */
1040 nfs_call_umount(&mnt_server, &dirname);
1045 fhandle = &mntres.nfsv3.mountres3_u.mountinfo.fhandle;
1046 memset(data.old_root.data, 0, NFS_FHSIZE);
1047 memset(&data.root, 0, sizeof(data.root));
1048 data.root.size = fhandle->fhandle3_len;
1049 memcpy(data.root.data,
1050 (char *) fhandle->fhandle3_val,
1051 fhandle->fhandle3_len);
1053 data.flags |= NFS_MOUNT_VER3;
1057 if (nfs_mount_data_version == 1) {
1058 /* create nfs socket for kernel */
1059 if (nfs_pmap->pm_prot == IPPROTO_TCP)
1060 fsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
1062 fsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
1064 perror(_("nfs socket"));
1067 if (bindresvport(fsock, 0) < 0) {
1068 perror(_("nfs bindresvport"));
1073 #ifdef NFS_MOUNT_DEBUG
1074 printf(_("using port %d for nfs deamon\n"), nfs_pmap->pm_port);
1076 nfs_saddr->sin_port = htons(nfs_pmap->pm_port);
1078 * connect() the socket for kernels 1.3.10 and below only,
1079 * to avoid problems with multihomed hosts.
1082 if (linux_version_code() <= 0x01030a && fsock != -1
1083 && connect(fsock, (struct sockaddr *) nfs_saddr,
1084 sizeof (*nfs_saddr)) < 0) {
1085 perror(_("nfs connect"));
1089 #if NFS_MOUNT_VERSION >= 2
1090 if (nfs_pmap->pm_prot == IPPROTO_TCP)
1091 data.flags |= NFS_MOUNT_TCP;
1093 data.flags &= ~NFS_MOUNT_TCP;
1096 /* prepare data structure for kernel */
1099 memcpy((char *) &data.addr, (char *) nfs_saddr, sizeof(data.addr));
1100 strncpy(data.hostname, hostname, sizeof(data.hostname));
1103 /* Ensure we have enough padding for the following strcat()s */
1104 if (strlen(new_opts) + strlen(s) + 30 >= sizeof(new_opts)) {
1105 fprintf(stderr, _("mount: "
1106 "excessively long option argument\n"));
1110 snprintf(cbuf, sizeof(cbuf)-1, "addr=%s", s);
1111 strcat(new_opts, cbuf);
1113 *extra_opts = xstrdup(new_opts);
1114 *need_statd = ! (data.flags & NFS_MOUNT_NONLM);