Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 02 Aug 1999 12:38:40 -0700
From:      Mike Smith <mike@smith.net.au>
To:        Alfred Perlstein <bright@rush.net>
Cc:        hackers@freebsd.org
Subject:   Re: confusion about nfsm_srvmtofh bad behavior? 
Message-ID:  <199908021938.MAA00862@dingo.cdrom.com>
In-Reply-To: Your message of "Mon, 02 Aug 1999 07:18:36 EDT." <Pine.BSF.3.96.990802064748.20420k-100000@cygnus.rush.net> 

next in thread | previous in thread | raw e-mail | index | archive | help
> 
> ok:
> 
> #define nfsm_srvmtofh(f) \
> 	{ int fhlen = NFSX_V3FH; \
> 		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) { \
> 				error = EBADRPC; \
> 				nfsm_reply(0); \
> 			} \
> 		} \
> 		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); \
> 		} \
> 	}
> 
> notice the bcopy?  i don't really understand why we always
> seem to copy 64 bytes (NFSX_V3FH), isn't this a bug?

Yeah, you could probably rewrite as:

#define nfsm_srvmtofh(f) \
	{ 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) { \
				error = EBADRPC; \
				nfsm_reply(0); \
			} else { \
				nfsm_dissect(tl, u_int32_t *, NFSX_V3FH); \
				bcopy((caddr_t)tl, (caddr_t)(f), NFSX_V3FH); \
			}\
		} else {
			nfsm_dissect(tl, u_int32_t *, NFSX_V2FH); \
			bcopy((caddr_t)tl, (caddr_t)(f), NFSX_V2FH); \
		} \
	}

which avoids using fhlen as an argument to anything (speed) and limits 
the bcopy size appropriately by protocol.

-- 
\\  The mind's the standard       \\  Mike Smith
\\  of the man.                   \\  msmith@freebsd.org
\\    -- Joseph Merrick           \\  msmith@cdrom.com




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199908021938.MAA00862>