From fce0d9b321de631d62c079179ff70ecfd90a2356 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 4 Aug 1999 14:41:39 +0000 Subject: [PATCH] Don't over-allocate and over-copy shorter NFSv2 filehandles and then correct the pointers afterwards. It's kinda bogus that we generate a 24 (?) byte filehandle (2 x int32 fsid and 16 byte VFS fhandle) and pad it out to 64 bytes for NFSv3 with garbage. The whole point of NFSv3's variable filehandle length was to allow for shorter handles, both in memory and over the wire. I plan on taking a shot at fixing this shortly. --- sys/nfs/nfs_common.h | 21 +++++++++++---------- sys/nfs/nfsm_subs.h | 21 +++++++++++---------- sys/nfsclient/nfsm_subs.h | 21 +++++++++++---------- sys/nfsserver/nfsm_subs.h | 21 +++++++++++---------- 4 files changed, 44 insertions(+), 40 deletions(-) diff --git a/sys/nfs/nfs_common.h b/sys/nfs/nfs_common.h index 5efe1499882e..f70645fd495b 100644 --- a/sys/nfs/nfs_common.h +++ b/sys/nfs/nfs_common.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95 - * $Id: nfsm_subs.h,v 1.23 1999/06/05 05:35:03 peter Exp $ + * $Id: nfsm_subs.h,v 1.24 1999/06/23 04:44:14 julian Exp $ */ @@ -419,24 +419,25 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, } } #define nfsm_srvmtofh(f) \ - { int fhlen = NFSX_V3FH; \ + do { \ + int fhlen; \ if (nfsd->nd_flag & ND_NFSV3) { \ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ fhlen = fxdr_unsigned(int, *tl); \ - if (fhlen == 0) { \ - bzero((caddr_t)(f), NFSX_V3FH); \ - } else if (fhlen != NFSX_V3FH) { \ + if (fhlen != 0 && fhlen != NFSX_V3FH) { \ error = EBADRPC; \ nfsm_reply(0); \ } \ + } else { \ + fhlen = NFSX_V2FH; \ } \ if (fhlen != 0) { \ - nfsm_dissect(tl, u_int32_t *, NFSX_V3FH); \ - bcopy((caddr_t)tl, (caddr_t)(f), NFSX_V3FH); \ - if ((nfsd->nd_flag & ND_NFSV3) == 0) \ - nfsm_adv(NFSX_V2FH - NFSX_V3FH); \ + nfsm_dissect(tl, u_int32_t *, fhlen); \ + bcopy((caddr_t)tl, (caddr_t)(f), fhlen); \ + } else {\ + bzero((caddr_t)(f), NFSX_V3FH); \ } \ - } + } while (0) #define nfsm_clget \ if (bp >= be) { \ diff --git a/sys/nfs/nfsm_subs.h b/sys/nfs/nfsm_subs.h index 5efe1499882e..f70645fd495b 100644 --- a/sys/nfs/nfsm_subs.h +++ b/sys/nfs/nfsm_subs.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95 - * $Id: nfsm_subs.h,v 1.23 1999/06/05 05:35:03 peter Exp $ + * $Id: nfsm_subs.h,v 1.24 1999/06/23 04:44:14 julian Exp $ */ @@ -419,24 +419,25 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, } } #define nfsm_srvmtofh(f) \ - { int fhlen = NFSX_V3FH; \ + do { \ + int fhlen; \ if (nfsd->nd_flag & ND_NFSV3) { \ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ fhlen = fxdr_unsigned(int, *tl); \ - if (fhlen == 0) { \ - bzero((caddr_t)(f), NFSX_V3FH); \ - } else if (fhlen != NFSX_V3FH) { \ + if (fhlen != 0 && fhlen != NFSX_V3FH) { \ error = EBADRPC; \ nfsm_reply(0); \ } \ + } else { \ + fhlen = NFSX_V2FH; \ } \ if (fhlen != 0) { \ - nfsm_dissect(tl, u_int32_t *, NFSX_V3FH); \ - bcopy((caddr_t)tl, (caddr_t)(f), NFSX_V3FH); \ - if ((nfsd->nd_flag & ND_NFSV3) == 0) \ - nfsm_adv(NFSX_V2FH - NFSX_V3FH); \ + nfsm_dissect(tl, u_int32_t *, fhlen); \ + bcopy((caddr_t)tl, (caddr_t)(f), fhlen); \ + } else {\ + bzero((caddr_t)(f), NFSX_V3FH); \ } \ - } + } while (0) #define nfsm_clget \ if (bp >= be) { \ diff --git a/sys/nfsclient/nfsm_subs.h b/sys/nfsclient/nfsm_subs.h index 5efe1499882e..f70645fd495b 100644 --- a/sys/nfsclient/nfsm_subs.h +++ b/sys/nfsclient/nfsm_subs.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95 - * $Id: nfsm_subs.h,v 1.23 1999/06/05 05:35:03 peter Exp $ + * $Id: nfsm_subs.h,v 1.24 1999/06/23 04:44:14 julian Exp $ */ @@ -419,24 +419,25 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, } } #define nfsm_srvmtofh(f) \ - { int fhlen = NFSX_V3FH; \ + do { \ + int fhlen; \ if (nfsd->nd_flag & ND_NFSV3) { \ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ fhlen = fxdr_unsigned(int, *tl); \ - if (fhlen == 0) { \ - bzero((caddr_t)(f), NFSX_V3FH); \ - } else if (fhlen != NFSX_V3FH) { \ + if (fhlen != 0 && fhlen != NFSX_V3FH) { \ error = EBADRPC; \ nfsm_reply(0); \ } \ + } else { \ + fhlen = NFSX_V2FH; \ } \ if (fhlen != 0) { \ - nfsm_dissect(tl, u_int32_t *, NFSX_V3FH); \ - bcopy((caddr_t)tl, (caddr_t)(f), NFSX_V3FH); \ - if ((nfsd->nd_flag & ND_NFSV3) == 0) \ - nfsm_adv(NFSX_V2FH - NFSX_V3FH); \ + nfsm_dissect(tl, u_int32_t *, fhlen); \ + bcopy((caddr_t)tl, (caddr_t)(f), fhlen); \ + } else {\ + bzero((caddr_t)(f), NFSX_V3FH); \ } \ - } + } while (0) #define nfsm_clget \ if (bp >= be) { \ diff --git a/sys/nfsserver/nfsm_subs.h b/sys/nfsserver/nfsm_subs.h index 5efe1499882e..f70645fd495b 100644 --- a/sys/nfsserver/nfsm_subs.h +++ b/sys/nfsserver/nfsm_subs.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95 - * $Id: nfsm_subs.h,v 1.23 1999/06/05 05:35:03 peter Exp $ + * $Id: nfsm_subs.h,v 1.24 1999/06/23 04:44:14 julian Exp $ */ @@ -419,24 +419,25 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid, } } #define nfsm_srvmtofh(f) \ - { int fhlen = NFSX_V3FH; \ + do { \ + int fhlen; \ if (nfsd->nd_flag & ND_NFSV3) { \ nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \ fhlen = fxdr_unsigned(int, *tl); \ - if (fhlen == 0) { \ - bzero((caddr_t)(f), NFSX_V3FH); \ - } else if (fhlen != NFSX_V3FH) { \ + if (fhlen != 0 && fhlen != NFSX_V3FH) { \ error = EBADRPC; \ nfsm_reply(0); \ } \ + } else { \ + fhlen = NFSX_V2FH; \ } \ if (fhlen != 0) { \ - nfsm_dissect(tl, u_int32_t *, NFSX_V3FH); \ - bcopy((caddr_t)tl, (caddr_t)(f), NFSX_V3FH); \ - if ((nfsd->nd_flag & ND_NFSV3) == 0) \ - nfsm_adv(NFSX_V2FH - NFSX_V3FH); \ + nfsm_dissect(tl, u_int32_t *, fhlen); \ + bcopy((caddr_t)tl, (caddr_t)(f), fhlen); \ + } else {\ + bzero((caddr_t)(f), NFSX_V3FH); \ } \ - } + } while (0) #define nfsm_clget \ if (bp >= be) { \