2009-11-30 20:17:55 +03:00
|
|
|
/* $NetBSD: mount_nfs.c,v 1.68 2009/11/30 17:17:55 pooka Exp $ */
|
1995-03-18 17:54:19 +03:00
|
|
|
|
1994-06-08 23:23:02 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Rick Macklem at The University of Guelph.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 14:04:22 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-06-08 23:23:02 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-09-15 09:31:35 +04:00
|
|
|
#include <sys/cdefs.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
#ifndef lint
|
2008-07-20 05:20:21 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\
|
|
|
|
The Regents of the University of California. All rights reserved.");
|
1994-06-08 23:23:02 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1995-03-18 17:54:19 +03:00
|
|
|
#if 0
|
1996-02-18 14:58:24 +03:00
|
|
|
static char sccsid[] = "@(#)mount_nfs.c 8.11 (Berkeley) 5/4/95";
|
1995-03-18 17:54:19 +03:00
|
|
|
#else
|
2009-11-30 20:17:55 +03:00
|
|
|
__RCSID("$NetBSD: mount_nfs.c,v 1.68 2009/11/30 17:17:55 pooka Exp $");
|
1995-03-18 17:54:19 +03:00
|
|
|
#endif
|
1994-06-08 23:23:02 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/stat.h>
|
1995-03-28 21:18:59 +04:00
|
|
|
#include <syslog.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
|
|
|
|
#ifdef ISO
|
|
|
|
#include <netiso/iso.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <nfs/rpcv2.h>
|
1996-02-18 14:58:24 +03:00
|
|
|
#include <nfs/nfsproto.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
#include <nfs/nfs.h>
|
1998-03-01 05:20:01 +03:00
|
|
|
#include <nfs/nfsmount.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1998-02-03 06:32:43 +03:00
|
|
|
#include <string.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
#include <unistd.h>
|
2002-09-21 22:43:31 +04:00
|
|
|
#include <util.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
|
2003-03-22 14:15:45 +03:00
|
|
|
#include <mntopts.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
|
2008-10-16 13:12:54 +04:00
|
|
|
#include "mountprog.h"
|
2005-05-16 01:18:34 +04:00
|
|
|
#include "mount_nfs.h"
|
|
|
|
|
2003-04-11 21:39:09 +04:00
|
|
|
#define ALTF_BG 0x00000001
|
|
|
|
#define ALTF_CONN 0x00000002
|
|
|
|
#define ALTF_DUMBTIMR 0x00000004
|
|
|
|
#define ALTF_INTR 0x00000008
|
|
|
|
#define ALTF_NFSV3 0x00000020
|
|
|
|
#define ALTF_RDIRPLUS 0x00000040
|
|
|
|
#define ALTF_MNTUDP 0x00000080
|
|
|
|
#define ALTF_NORESPORT 0x00000100
|
|
|
|
#define ALTF_SEQPACKET 0x00000200
|
|
|
|
#define ALTF_NQNFS 0x00000400
|
|
|
|
#define ALTF_SOFT 0x00000800
|
|
|
|
#define ALTF_TCP 0x00001000
|
|
|
|
#define ALTF_NFSV2 0x00002000
|
|
|
|
#define ALTF_PORT 0x00004000
|
|
|
|
#define ALTF_RSIZE 0x00008000
|
|
|
|
#define ALTF_WSIZE 0x00010000
|
|
|
|
#define ALTF_RDIRSIZE 0x00020000
|
|
|
|
#define ALTF_MAXGRPS 0x00040000
|
|
|
|
#define ALTF_LEASETERM 0x00080000
|
|
|
|
#define ALTF_READAHEAD 0x00100000
|
|
|
|
#define ALTF_DEADTHRESH 0x00200000
|
|
|
|
#define ALTF_TIMEO 0x00400000
|
|
|
|
#define ALTF_RETRANS 0x00800000
|
1996-02-18 14:58:24 +03:00
|
|
|
|
2000-10-30 23:56:57 +03:00
|
|
|
static const struct mntopt mopts[] = {
|
1994-06-08 23:23:02 +04:00
|
|
|
MOPT_STDOPTS,
|
|
|
|
MOPT_FORCE,
|
|
|
|
MOPT_UPDATE,
|
2002-09-21 22:43:31 +04:00
|
|
|
MOPT_GETARGS,
|
1996-02-18 14:58:24 +03:00
|
|
|
{ "bg", 0, ALTF_BG, 1 },
|
1996-10-28 00:18:03 +03:00
|
|
|
{ "conn", 0, ALTF_CONN, 1 },
|
1996-02-18 14:58:24 +03:00
|
|
|
{ "dumbtimer", 0, ALTF_DUMBTIMR, 1 },
|
|
|
|
{ "intr", 0, ALTF_INTR, 1 },
|
|
|
|
{ "nfsv3", 0, ALTF_NFSV3, 1 },
|
|
|
|
{ "rdirplus", 0, ALTF_RDIRPLUS, 1 },
|
|
|
|
{ "mntudp", 0, ALTF_MNTUDP, 1 },
|
2009-01-11 23:22:11 +03:00
|
|
|
{ "resport", 1, ALTF_NORESPORT, 1 },
|
1996-02-18 14:58:24 +03:00
|
|
|
#ifdef ISO
|
|
|
|
{ "seqpacket", 0, ALTF_SEQPACKET, 1 },
|
|
|
|
#endif
|
|
|
|
{ "nqnfs", 0, ALTF_NQNFS, 1 },
|
|
|
|
{ "soft", 0, ALTF_SOFT, 1 },
|
|
|
|
{ "tcp", 0, ALTF_TCP, 1 },
|
1996-05-24 02:52:49 +04:00
|
|
|
{ "nfsv2", 0, ALTF_NFSV2, 1 },
|
2003-04-11 21:39:09 +04:00
|
|
|
{ "port", 0, ALTF_PORT, 1 },
|
|
|
|
{ "rsize", 0, ALTF_RSIZE, 1 },
|
|
|
|
{ "wsize", 0, ALTF_WSIZE, 1 },
|
|
|
|
{ "rdirsize", 0, ALTF_RDIRSIZE, 1 },
|
|
|
|
{ "maxgrps", 0, ALTF_MAXGRPS, 1 },
|
|
|
|
{ "leaseterm", 0, ALTF_LEASETERM, 1 },
|
|
|
|
{ "readahead", 0, ALTF_READAHEAD, 1 },
|
|
|
|
{ "deadthresh", 0, ALTF_DEADTHRESH, 1 },
|
|
|
|
{ "timeo", 0, ALTF_TIMEO, 1 },
|
2006-10-16 07:37:42 +04:00
|
|
|
MOPT_NULL,
|
2003-04-11 21:39:09 +04:00
|
|
|
|
1994-06-08 23:23:02 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct nfs_args nfsdefargs = {
|
2009-02-20 18:37:22 +03:00
|
|
|
.version = NFS_ARGSVERSION,
|
|
|
|
.addr = NULL,
|
|
|
|
.addrlen = sizeof(struct sockaddr_in),
|
|
|
|
.sotype = SOCK_DGRAM,
|
|
|
|
.proto = 0,
|
|
|
|
.fh = NULL,
|
|
|
|
.fhsize = 0,
|
|
|
|
.flags = NFSMNT_NFSV3|NFSMNT_NOCONN|NFSMNT_RESVPORT,
|
|
|
|
.wsize = NFS_WSIZE,
|
|
|
|
.rsize = NFS_RSIZE,
|
|
|
|
.readdirsize = NFS_READDIRSIZE,
|
|
|
|
.timeo = 10,
|
|
|
|
.retrans = NFS_RETRANS,
|
|
|
|
.maxgrouplist = NFS_MAXGRPS,
|
|
|
|
.readahead = NFS_DEFRAHEAD,
|
|
|
|
.leaseterm = 0, /* Ignored; lease term */
|
|
|
|
.deadthresh = NFS_DEFDEADTHRESH,
|
|
|
|
.hostname = NULL,
|
1994-06-08 23:23:02 +04:00
|
|
|
};
|
|
|
|
|
2008-10-16 13:12:54 +04:00
|
|
|
#define DEF_RETRY 10000
|
|
|
|
|
2008-09-28 00:39:42 +04:00
|
|
|
int retrycnt = DEF_RETRY;
|
1994-06-08 23:23:02 +04:00
|
|
|
int opflags = 0;
|
1996-02-18 14:58:24 +03:00
|
|
|
int force2 = 0;
|
|
|
|
int force3 = 0;
|
2000-06-09 04:06:36 +04:00
|
|
|
int mnttcp_ok = 1;
|
2003-04-11 21:39:09 +04:00
|
|
|
int port = 0;
|
1994-06-08 23:23:02 +04:00
|
|
|
|
2005-02-05 17:55:44 +03:00
|
|
|
static void shownfsargs(const struct nfs_args *);
|
1994-06-08 23:23:02 +04:00
|
|
|
#ifdef ISO
|
2005-02-05 17:55:44 +03:00
|
|
|
static struct iso_addr *iso_addr(const char *);
|
1994-06-08 23:23:02 +04:00
|
|
|
#endif
|
2005-02-05 17:55:44 +03:00
|
|
|
int mount_nfs(int argc, char **argv);
|
|
|
|
/* void set_rpc_maxgrouplist(int); */
|
|
|
|
static void usage(void);
|
1994-06-08 23:23:02 +04:00
|
|
|
|
2000-10-30 23:56:57 +03:00
|
|
|
#ifndef MOUNT_NOMAIN
|
1994-06-08 23:23:02 +04:00
|
|
|
int
|
2005-02-05 17:55:44 +03:00
|
|
|
main(int argc, char **argv)
|
2000-10-30 23:56:57 +03:00
|
|
|
{
|
2008-10-16 13:12:54 +04:00
|
|
|
|
|
|
|
setprogname(argv[0]);
|
2000-10-30 23:56:57 +03:00
|
|
|
return mount_nfs(argc, argv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-16 13:12:54 +04:00
|
|
|
void
|
|
|
|
mount_nfs_dogetargs(struct nfs_args *nfsargsp, int mntflags, const char *spec)
|
1994-06-08 23:23:02 +04:00
|
|
|
{
|
2009-04-03 11:26:07 +04:00
|
|
|
static struct sockaddr_storage sa;
|
2008-10-16 13:12:54 +04:00
|
|
|
char *tspec;
|
|
|
|
|
|
|
|
if ((mntflags & MNT_GETARGS) != 0) {
|
|
|
|
memset(&sa, 0, sizeof(sa));
|
|
|
|
nfsargsp->addr = (struct sockaddr *)&sa;
|
|
|
|
nfsargsp->addrlen = sizeof(sa);
|
|
|
|
} else {
|
|
|
|
if ((tspec = strdup(spec)) == NULL) {
|
|
|
|
err(1, "strdup");
|
|
|
|
}
|
|
|
|
if (!getnfsargs(tspec, nfsargsp)) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
free(tspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mount_nfs_parseargs(int argc, char *argv[],
|
|
|
|
struct nfs_args *nfsargsp, int *mntflags,
|
|
|
|
char *spec, char *name)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
int altflags, num;
|
|
|
|
int c;
|
2003-04-11 21:39:09 +04:00
|
|
|
mntoptparse_t mp;
|
1994-06-08 23:23:02 +04:00
|
|
|
|
2008-10-16 13:12:54 +04:00
|
|
|
*mntflags = 0;
|
1996-02-18 14:58:24 +03:00
|
|
|
altflags = 0;
|
2008-10-16 13:12:54 +04:00
|
|
|
memset(nfsargsp, 0, sizeof(*nfsargsp));
|
|
|
|
*nfsargsp = nfsdefargs;
|
1994-06-08 23:23:02 +04:00
|
|
|
while ((c = getopt(argc, argv,
|
1997-10-19 05:24:47 +04:00
|
|
|
"23a:bcCdD:g:I:iKL:lm:o:PpqR:r:sTt:w:x:UX")) != -1)
|
1994-06-08 23:23:02 +04:00
|
|
|
switch (c) {
|
1996-02-18 14:58:24 +03:00
|
|
|
case '3':
|
2006-11-09 13:07:00 +03:00
|
|
|
case 'q':
|
1996-02-18 14:58:24 +03:00
|
|
|
if (force2)
|
2006-11-09 13:07:00 +03:00
|
|
|
errx(1, "conflicting version options");
|
1996-02-18 14:58:24 +03:00
|
|
|
force3 = 1;
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
if (force3)
|
2006-11-09 13:07:00 +03:00
|
|
|
errx(1, "conflicting version options");
|
1996-02-18 14:58:24 +03:00
|
|
|
force2 = 1;
|
|
|
|
nfsargsp->flags &= ~NFSMNT_NFSV3;
|
|
|
|
break;
|
1994-06-08 23:23:02 +04:00
|
|
|
case 'a':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num < 0)
|
|
|
|
errx(1, "illegal -a value -- %s", optarg);
|
|
|
|
nfsargsp->readahead = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_READAHEAD;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
opflags |= BGRND;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
nfsargsp->flags |= NFSMNT_NOCONN;
|
|
|
|
break;
|
1996-10-28 00:18:03 +03:00
|
|
|
case 'C':
|
|
|
|
nfsargsp->flags &= ~NFSMNT_NOCONN;
|
|
|
|
break;
|
1994-06-08 23:23:02 +04:00
|
|
|
case 'D':
|
2006-12-27 14:05:04 +03:00
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -D value -- %s", optarg);
|
|
|
|
nfsargsp->deadthresh = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_DEADTHRESH;
|
1994-06-08 23:23:02 +04:00
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
nfsargsp->flags |= NFSMNT_DUMBTIMR;
|
|
|
|
break;
|
1994-06-24 16:04:53 +04:00
|
|
|
#if 0 /* XXXX */
|
1994-06-08 23:23:02 +04:00
|
|
|
case 'g':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -g value -- %s", optarg);
|
|
|
|
set_rpc_maxgrouplist(num);
|
|
|
|
nfsargsp->maxgrouplist = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_MAXGRPS;
|
|
|
|
break;
|
1994-06-24 16:04:53 +04:00
|
|
|
#endif
|
1996-02-18 14:58:24 +03:00
|
|
|
case 'I':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -I value -- %s", optarg);
|
|
|
|
nfsargsp->readdirsize = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_READDIRSIZE;
|
|
|
|
break;
|
1994-06-08 23:23:02 +04:00
|
|
|
case 'i':
|
|
|
|
nfsargsp->flags |= NFSMNT_INT;
|
|
|
|
break;
|
|
|
|
case 'L':
|
2006-11-09 13:07:00 +03:00
|
|
|
/* ignore */
|
1994-06-08 23:23:02 +04:00
|
|
|
break;
|
|
|
|
case 'l':
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->flags |= NFSMNT_RDIRPLUS;
|
1994-06-08 23:23:02 +04:00
|
|
|
break;
|
|
|
|
case 'o':
|
2008-10-16 13:12:54 +04:00
|
|
|
mp = getmntopts(optarg, mopts, mntflags, &altflags);
|
2003-04-11 21:39:09 +04:00
|
|
|
if (mp == NULL)
|
2006-03-22 00:11:41 +03:00
|
|
|
err(1, "getmntopts");
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_BG)
|
1996-02-18 14:58:24 +03:00
|
|
|
opflags |= BGRND;
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_CONN)
|
1996-10-28 00:18:03 +03:00
|
|
|
nfsargsp->flags &= ~NFSMNT_NOCONN;
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_DUMBTIMR)
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->flags |= NFSMNT_DUMBTIMR;
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_INTR)
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->flags |= NFSMNT_INT;
|
2006-11-09 13:07:00 +03:00
|
|
|
if (altflags & (ALTF_NFSV3|ALTF_NQNFS)) {
|
1996-05-24 02:52:49 +04:00
|
|
|
if (force2)
|
2002-10-01 07:08:56 +04:00
|
|
|
errx(1, "conflicting version options");
|
1996-05-24 02:52:49 +04:00
|
|
|
force3 = 1;
|
|
|
|
}
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_NFSV2) {
|
1996-05-24 02:52:49 +04:00
|
|
|
if (force3)
|
2002-10-01 07:08:56 +04:00
|
|
|
errx(1, "conflicting version options");
|
1996-05-24 02:52:49 +04:00
|
|
|
force2 = 1;
|
|
|
|
nfsargsp->flags &= ~NFSMNT_NFSV3;
|
|
|
|
}
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_RDIRPLUS)
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->flags |= NFSMNT_RDIRPLUS;
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_MNTUDP)
|
1996-02-18 14:58:24 +03:00
|
|
|
mnttcp_ok = 0;
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_NORESPORT)
|
1997-03-23 23:59:56 +03:00
|
|
|
nfsargsp->flags &= ~NFSMNT_RESVPORT;
|
1996-02-18 14:58:24 +03:00
|
|
|
#ifdef ISO
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_SEQPACKET)
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->sotype = SOCK_SEQPACKET;
|
|
|
|
#endif
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_SOFT)
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->flags |= NFSMNT_SOFT;
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_TCP) {
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->sotype = SOCK_STREAM;
|
|
|
|
}
|
2003-04-11 21:39:09 +04:00
|
|
|
if (altflags & ALTF_PORT) {
|
|
|
|
port = getmntoptnum(mp, "port");
|
|
|
|
}
|
|
|
|
if (altflags & ALTF_RSIZE) {
|
|
|
|
nfsargsp->rsize =
|
|
|
|
(int)getmntoptnum(mp, "rsize");
|
|
|
|
nfsargsp->flags |= NFSMNT_RSIZE;
|
|
|
|
}
|
|
|
|
if (altflags & ALTF_WSIZE) {
|
2003-05-16 19:33:45 +04:00
|
|
|
nfsargsp->wsize =
|
2003-04-11 21:39:09 +04:00
|
|
|
(int)getmntoptnum(mp, "wsize");
|
|
|
|
nfsargsp->flags |= NFSMNT_WSIZE;
|
|
|
|
}
|
|
|
|
if (altflags & ALTF_RDIRSIZE) {
|
|
|
|
nfsargsp->rsize =
|
|
|
|
(int)getmntoptnum(mp, "rdirsize");
|
|
|
|
nfsargsp->flags |= NFSMNT_READDIRSIZE;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
if (altflags & ALTF_MAXGRPS) {
|
|
|
|
set_rpc_maxgrouplist(num);
|
|
|
|
nfsargsp->maxgrouplist =
|
|
|
|
(int)getmntoptnum(mp, "maxgrps");
|
|
|
|
nfsargsp->flags |= NFSMNT_MAXGRPS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (altflags & ALTF_LEASETERM) {
|
|
|
|
nfsargsp->leaseterm =
|
|
|
|
(int)getmntoptnum(mp, "leaseterm");
|
|
|
|
nfsargsp->flags |= NFSMNT_LEASETERM;
|
|
|
|
}
|
|
|
|
if (altflags & ALTF_READAHEAD) {
|
|
|
|
nfsargsp->readahead =
|
|
|
|
(int)getmntoptnum(mp, "readahead");
|
|
|
|
nfsargsp->flags |= NFSMNT_READAHEAD;
|
|
|
|
}
|
|
|
|
if (altflags & ALTF_DEADTHRESH) {
|
|
|
|
nfsargsp->deadthresh =
|
|
|
|
(int)getmntoptnum(mp, "deadthresh");
|
|
|
|
nfsargsp->flags |= NFSMNT_DEADTHRESH;
|
|
|
|
}
|
|
|
|
if (altflags & ALTF_TIMEO) {
|
|
|
|
nfsargsp->timeo =
|
|
|
|
(int)getmntoptnum(mp, "timeo");
|
|
|
|
nfsargsp->flags |= NFSMNT_TIMEO;
|
|
|
|
}
|
|
|
|
if (altflags & ALTF_RETRANS) {
|
|
|
|
nfsargsp->retrans =
|
|
|
|
(int)getmntoptnum(mp, "retrans");
|
|
|
|
nfsargsp->flags |= NFSMNT_RETRANS;
|
|
|
|
}
|
1996-02-18 14:58:24 +03:00
|
|
|
altflags = 0;
|
2003-04-11 21:39:09 +04:00
|
|
|
freemntopts(mp);
|
1994-06-08 23:23:02 +04:00
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
nfsargsp->flags |= NFSMNT_RESVPORT;
|
|
|
|
break;
|
|
|
|
case 'p':
|
1997-03-23 23:59:56 +03:00
|
|
|
nfsargsp->flags &= ~NFSMNT_RESVPORT;
|
1994-06-08 23:23:02 +04:00
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -R value -- %s", optarg);
|
|
|
|
retrycnt = num;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -r value -- %s", optarg);
|
|
|
|
nfsargsp->rsize = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_RSIZE;
|
|
|
|
break;
|
1997-03-23 23:59:56 +03:00
|
|
|
#ifdef ISO
|
|
|
|
case 'S':
|
|
|
|
nfsargsp->sotype = SOCK_SEQPACKET;
|
|
|
|
break;
|
|
|
|
#endif
|
1994-06-08 23:23:02 +04:00
|
|
|
case 's':
|
|
|
|
nfsargsp->flags |= NFSMNT_SOFT;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
nfsargsp->sotype = SOCK_STREAM;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -t value -- %s", optarg);
|
|
|
|
nfsargsp->timeo = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_TIMEO;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -w value -- %s", optarg);
|
|
|
|
nfsargsp->wsize = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_WSIZE;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -x value -- %s", optarg);
|
|
|
|
nfsargsp->retrans = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_RETRANS;
|
|
|
|
break;
|
1997-10-19 05:24:47 +04:00
|
|
|
case 'X':
|
|
|
|
nfsargsp->flags |= NFSMNT_XLATECOOKIE;
|
|
|
|
break;
|
1996-02-18 14:58:24 +03:00
|
|
|
case 'U':
|
|
|
|
mnttcp_ok = 0;
|
|
|
|
break;
|
1994-06-08 23:23:02 +04:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc != 2)
|
1994-12-29 03:48:42 +03:00
|
|
|
usage();
|
1994-06-08 23:23:02 +04:00
|
|
|
|
2008-10-16 13:12:54 +04:00
|
|
|
strlcpy(spec, *argv++, MAXPATHLEN);
|
|
|
|
pathadj(*argv, name);
|
|
|
|
mount_nfs_dogetargs(nfsargsp, *mntflags, spec);
|
|
|
|
}
|
2005-01-31 08:19:18 +03:00
|
|
|
|
2008-10-16 13:12:54 +04:00
|
|
|
int
|
|
|
|
mount_nfs(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char spec[MAXPATHLEN], name[MAXPATHLEN];
|
|
|
|
struct nfs_args args;
|
|
|
|
int mntflags;
|
|
|
|
int retval;
|
2006-05-20 12:06:48 +04:00
|
|
|
|
2008-10-16 13:12:54 +04:00
|
|
|
mount_nfs_parseargs(argc, argv, &args, &mntflags, spec, name);
|
|
|
|
|
|
|
|
retry:
|
2007-07-16 21:06:52 +04:00
|
|
|
if ((retval = mount(MOUNT_NFS, name, mntflags,
|
2008-10-16 13:12:54 +04:00
|
|
|
&args, sizeof args)) == -1) {
|
2002-06-16 06:27:31 +04:00
|
|
|
/* Did we just default to v3 on a v2-only kernel?
|
|
|
|
* If so, default to v2 & try again */
|
2006-05-20 12:06:48 +04:00
|
|
|
if (errno == EPROGMISMATCH &&
|
2008-10-16 13:12:54 +04:00
|
|
|
(args.flags & NFSMNT_NFSV3) != 0 && !force3) {
|
2006-05-20 12:06:48 +04:00
|
|
|
/*
|
|
|
|
* fall back to v2. XXX lack of V3 umount.
|
|
|
|
*/
|
2008-10-16 13:12:54 +04:00
|
|
|
args.flags &= ~NFSMNT_NFSV3;
|
|
|
|
mount_nfs_dogetargs(&args, mntflags, spec);
|
2006-05-20 12:06:48 +04:00
|
|
|
goto retry;
|
2002-06-16 06:27:31 +04:00
|
|
|
}
|
|
|
|
}
|
2007-07-16 21:06:52 +04:00
|
|
|
if (retval == -1)
|
2006-05-20 12:06:48 +04:00
|
|
|
err(1, "%s on %s", spec, name);
|
2002-09-21 22:43:31 +04:00
|
|
|
if (mntflags & MNT_GETARGS) {
|
2008-10-16 13:12:54 +04:00
|
|
|
shownfsargs(&args);
|
2002-10-21 07:58:07 +04:00
|
|
|
return (0);
|
2002-09-21 22:43:31 +04:00
|
|
|
}
|
|
|
|
|
1994-06-08 23:23:02 +04:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2002-09-21 22:43:31 +04:00
|
|
|
static void
|
2005-02-05 17:55:44 +03:00
|
|
|
shownfsargs(const struct nfs_args *nfsargsp)
|
2002-09-21 22:43:31 +04:00
|
|
|
{
|
|
|
|
char fbuf[2048];
|
2002-10-21 07:58:07 +04:00
|
|
|
char host[NI_MAXHOST], serv[NI_MAXSERV];
|
|
|
|
int error;
|
2002-09-21 22:43:31 +04:00
|
|
|
|
|
|
|
(void)snprintb(fbuf, sizeof(fbuf), NFSMNT_BITS, nfsargsp->flags);
|
2002-10-21 07:58:07 +04:00
|
|
|
if (nfsargsp->addr != NULL) {
|
|
|
|
error = getnameinfo(nfsargsp->addr, nfsargsp->addrlen, host,
|
|
|
|
sizeof(host), serv, sizeof(serv),
|
|
|
|
NI_NUMERICHOST | NI_NUMERICSERV);
|
|
|
|
if (error != 0)
|
|
|
|
warnx("getnameinfo: %s", gai_strerror(error));
|
|
|
|
} else
|
|
|
|
error = -1;
|
|
|
|
|
|
|
|
if (error == 0)
|
2003-04-10 08:40:38 +04:00
|
|
|
printf("addr=%s, port=%s, addrlen=%d, ",
|
2002-10-21 07:58:07 +04:00
|
|
|
host, serv, nfsargsp->addrlen);
|
2003-04-07 17:31:17 +04:00
|
|
|
printf("sotype=%d, proto=%d, fhsize=%d, "
|
2002-09-21 22:43:31 +04:00
|
|
|
"flags=%s, wsize=%d, rsize=%d, readdirsize=%d, timeo=%d, "
|
|
|
|
"retrans=%d, maxgrouplist=%d, readahead=%d, leaseterm=%d, "
|
|
|
|
"deadthresh=%d\n",
|
|
|
|
nfsargsp->sotype,
|
|
|
|
nfsargsp->proto,
|
|
|
|
nfsargsp->fhsize,
|
|
|
|
fbuf,
|
|
|
|
nfsargsp->wsize,
|
|
|
|
nfsargsp->rsize,
|
|
|
|
nfsargsp->readdirsize,
|
|
|
|
nfsargsp->timeo,
|
|
|
|
nfsargsp->retrans,
|
|
|
|
nfsargsp->maxgrouplist,
|
|
|
|
nfsargsp->readahead,
|
|
|
|
nfsargsp->leaseterm,
|
|
|
|
nfsargsp->deadthresh);
|
|
|
|
}
|
|
|
|
|
2000-10-30 23:56:57 +03:00
|
|
|
static void
|
2005-02-05 17:55:44 +03:00
|
|
|
usage(void)
|
1994-06-08 23:23:02 +04:00
|
|
|
{
|
2009-11-30 20:17:55 +03:00
|
|
|
(void)fprintf(stderr, "usage: %s %s\n%s\n%s\n%s\n%s\n", getprogname(),
|
2006-12-27 14:28:59 +03:00
|
|
|
"[-23bCcdilPpqsTUX] [-a maxreadahead] [-D deadthresh]",
|
2006-03-24 02:23:27 +03:00
|
|
|
"\t[-g maxgroups] [-I readdirsize] [-L leaseterm]",
|
1999-11-21 03:53:58 +03:00
|
|
|
"\t[-o options] [-R retrycnt] [-r readsize] [-t timeout]",
|
|
|
|
"\t[-w writesize] [-x retrans]",
|
1994-06-08 23:23:02 +04:00
|
|
|
"\trhost:path node");
|
|
|
|
exit(1);
|
|
|
|
}
|