blob: a5d5b8a925db5242952c2cb47bf769c6c1dc5df3 [file] [log] [blame] [raw]
--- /dev/null 2018-11-06 01:48:55.000000000 +0800
+++ freebsd-10.3/usr/src/sbin/mount_nfs/build.sh 2018-10-17 00:59:02.737446078 +0800
@@ -0,0 +1,3 @@
+#!/bin/sh
+#gcc -Wall -O1 -I ../mount -I ../../usr.sbin/rpc.umntall mount.nfs.c -o mount.nfs ../mount/getmntopts.o ../../usr.sbin/rpc.umntall/mounttab.o -L /usr/home/WHR/src/ToolBox/libgetopt -l getopt
+gcc -Wall -g -O1 -I ../mount -I ../../usr.sbin/rpc.umntall mount.nfs.c -o mount.nfs ../mount/getmntopts.o ../../usr.sbin/rpc.umntall/mounttab.o -L /usr/home/WHR/src/ToolBox/libgetopt -l getopt
--- freebsd-10.3/usr/src/sbin/mount_nfs/mount_nfs.c 2016-03-25 09:10:18.000000000 +0800
+++ freebsd-10.3/usr/src/sbin/mount_nfs/mount.nfs.c 2018-11-06 01:48:14.520248365 +0800
@@ -160,11 +160,8 @@
memset(errmsg, 0, sizeof(errmsg));
gssname = NULL;
- fstype = strrchr(argv[0], '_');
- if (fstype == NULL)
- errx(EX_USAGE, "argv[0] must end in _fstype");
-
- ++fstype;
+ // Fstype is the new nfs (V4) by default
+ fstype = "nfs";
while ((c = getopt(argc, argv,
"23a:bcdD:g:I:iLlNo:PR:r:sTt:w:x:U")) != -1)
@@ -267,12 +264,13 @@
} else if (strcmp(opt, "nfsv2") == 0) {
pass_flag_to_nmount=0;
mountmode = V2;
+ fstype = "oldnfs";
} else if (strcmp(opt, "nfsv3") == 0) {
mountmode = V3;
+ fstype = "oldnfs";
} else if (strcmp(opt, "nfsv4") == 0) {
pass_flag_to_nmount=0;
mountmode = V4;
- fstype = "nfs";
nfsproto = IPPROTO_TCP;
if (portspec == NULL)
portspec = "2049";
@@ -347,9 +345,11 @@
switch (num) {
case 2:
mountmode = V2;
+ fstype = "oldnfs";
break;
case 3:
mountmode = V3;
+ fstype = "oldnfs";
build_iovec(&iov, &iovlen,
"nfsv3", NULL, 0);
break;
@@ -683,6 +683,7 @@
int doconnect, nfsvers, mntvers, sotype;
enum clnt_stat clntstat;
enum mountmode trymntmode;
+ int try_any = mountmode == ANY;
sotype = 0;
trymntmode = mountmode;
@@ -723,21 +724,38 @@
}
tryagain:
- if (trymntmode == V4) {
- nfsvers = 4;
- mntvers = 3; /* Workaround for GCC. */
+ if (trymntmode == V3) {
+ nfsvers = 3;
+ mntvers = 3;
} else if (trymntmode == V2) {
nfsvers = 2;
mntvers = 1;
} else {
- nfsvers = 3;
- mntvers = 3;
+ // V4 is the default
+ nfsvers = 4;
+ mntvers = 3; /* Workaround for GCC. */
+ trymntmode = V4;
}
if (portspec != NULL) {
/* `ai' contains the complete nfsd sockaddr. */
nfs_nb.buf = ai->ai_addr;
nfs_nb.len = nfs_nb.maxlen = ai->ai_addrlen;
+#if 0
+ } else if(nfsvers == 4) {
+ /* Port number default to 2049 for V4 */
+ nfs_nb.buf = &nfs_ss;
+ nfs_nb.len = nfs_nb.maxlen = ai->ai_addrlen;
+ memcpy(&nfs_ss, ai->ai_addr, ai->ai_addrlen);
+ switch(ai->ai_family) {
+ case AF_INET:
+ ((struct sockaddr_in *)&nfs_ss)->sin_port = htons(2049);
+ break;
+ case AF_INET6:
+ ((struct sockaddr_in6 *)&nfs_ss)->sin6_port = htons(2049);
+ break;
+ }
+#endif
} else {
/* Ask the remote rpcbind. */
nfs_nb.buf = &nfs_ss;
@@ -746,8 +764,8 @@
if (!rpcb_getaddr(NFS_PROGRAM, nfsvers, nconf, &nfs_nb,
hostp)) {
if (rpc_createerr.cf_stat == RPC_PROGVERSMISMATCH &&
- trymntmode == ANY) {
- trymntmode = V2;
+ try_any) {
+ trymntmode = trymntmode == V4 ? V3 : V2;
goto tryagain;
}
snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s",
@@ -788,7 +806,7 @@
clntstat = clnt_call(clp, NFSPROC_NULL, (xdrproc_t)xdr_void, NULL,
(xdrproc_t)xdr_void, NULL, try);
if (clntstat != RPC_SUCCESS) {
- if (clntstat == RPC_PROGVERSMISMATCH && trymntmode == ANY) {
+ if (clntstat == RPC_PROGVERSMISMATCH && try_any) {
clnt_destroy(clp);
trymntmode = V2;
goto tryagain;
@@ -845,7 +863,7 @@
try);
auth_destroy(clp->cl_auth);
if (clntstat != RPC_SUCCESS) {
- if (clntstat == RPC_PROGVERSMISMATCH && trymntmode == ANY) {
+ if (clntstat == RPC_PROGVERSMISMATCH && try_any) {
clnt_destroy(clp);
trymntmode = V2;
goto tryagain;
@@ -1034,7 +1052,7 @@
usage(void)
{
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
-"usage: mount_nfs [-23bcdiLlNPsTU] [-a maxreadahead] [-D deadthresh]",
+"Usage: mount.nfs [-23bcdiLlNPsTU] [-a maxreadahead] [-D deadthresh]",
" [-g maxgroups] [-I readdirsize] [-o options] [-R retrycnt]",
" [-r readsize] [-t timeout] [-w writesize] [-x retrans]",
" rhost:path node");