summaryrefslogtreecommitdiffstats
path: root/sys/nfsserver/nfsm_subs.h
diff options
context:
space:
mode:
authordfr <dfr@FreeBSD.org>1995-06-27 11:07:30 +0000
committerdfr <dfr@FreeBSD.org>1995-06-27 11:07:30 +0000
commit666343f7f055c064375d48bb9a608730d7145beb (patch)
tree372bad41f8c547f40d0826ed596c53dc772ab986 /sys/nfsserver/nfsm_subs.h
parent6da3ef32238f37b3b45cf709205fcff60bcbda7f (diff)
downloadFreeBSD-src-666343f7f055c064375d48bb9a608730d7145beb.zip
FreeBSD-src-666343f7f055c064375d48bb9a608730d7145beb.tar.gz
Changes to support version 3 of the NFS protocol.
The version 2 support has been tested (client+server) against FreeBSD-2.0, IRIX 5.3 and FreeBSD-current (using a loopback mount). The version 2 support is stable AFAIK. The version 3 support has been tested with a loopback mount and minimally against an IRIX 5.3 server. It needs more testing and may have problems. I have patched amd to support the new variable length filehandles although it will still only use version 2 of the protocol. Before booting a kernel with these changes, nfs clients will need to at least build and install /usr/sbin/mount_nfs. Servers will need to build and install /usr/sbin/mountd. NFS diskless support is untested. Obtained from: Rick Macklem <rick@snowhite.cis.uoguelph.ca>
Diffstat (limited to 'sys/nfsserver/nfsm_subs.h')
-rw-r--r--sys/nfsserver/nfsm_subs.h333
1 files changed, 243 insertions, 90 deletions
diff --git a/sys/nfsserver/nfsm_subs.h b/sys/nfsserver/nfsm_subs.h
index 030a985..9e89c57 100644
--- a/sys/nfsserver/nfsm_subs.h
+++ b/sys/nfsserver/nfsm_subs.h
@@ -34,12 +34,13 @@
* SUCH DAMAGE.
*
* @(#)nfsm_subs.h 8.1 (Berkeley) 6/16/93
- * $Id: nfsm_subs.h,v 1.5 1994/10/17 17:47:42 phk Exp $
+ * $Id: nfsm_subs.h,v 1.6 1995/05/30 08:12:51 rgrimes Exp $
*/
#ifndef _NFS_NFSM_SUBS_H_
#define _NFS_NFSM_SUBS_H_
+
/*
* These macros do strange and peculiar things to mbuf chains for
* the assistance of the nfs code. To attempt to use them for any
@@ -90,49 +91,153 @@ extern struct mbuf *nfsm_reqh();
mb->m_len += (s); \
bpos += (s); }
-#define nfsm_dissect(a,c,s) \
+#define nfsm_dissect(a, c, s) \
{ t1 = mtod(md, caddr_t)+md->m_len-dpos; \
if (t1 >= (s)) { \
(a) = (c)(dpos); \
dpos += (s); \
+ } else if (t1 = nfsm_disct(&md, &dpos, (s), t1, &cp2)) { \
+ error = t1; \
+ m_freem(mrep); \
+ goto nfsmout; \
} else { \
- error = nfsm_disct(&md, &dpos, (s), t1, &cp2); \
- if (error) { \
- m_freem(mrep); \
+ (a) = (c)cp2; \
+ } }
+
+#define nfsm_fhtom(v, v3) \
+ { if (v3) { \
+ t2 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; \
+ if (t2 <= M_TRAILINGSPACE(mb)) { \
+ nfsm_build(tl, u_long *, t2); \
+ *tl++ = txdr_unsigned(VTONFS(v)->n_fhsize); \
+ *(tl + ((t2>>2) - 2)) = 0; \
+ bcopy((caddr_t)VTONFS(v)->n_fhp,(caddr_t)tl, \
+ VTONFS(v)->n_fhsize); \
+ } else if (t2 = nfsm_strtmbuf(&mb, &bpos, \
+ (caddr_t)VTONFS(v)->n_fhp, VTONFS(v)->n_fhsize)) { \
+ error = t2; \
+ m_freem(mreq); \
goto nfsmout; \
- } else { \
- (a) = (c)cp2; \
} \
+ } else { \
+ nfsm_build(cp, caddr_t, NFSX_V2FH); \
+ bcopy((caddr_t)VTONFS(v)->n_fhp, cp, NFSX_V2FH); \
} }
-#define nfsm_fhtom(v) \
- nfsm_build(cp,caddr_t,NFSX_FH); \
- bcopy((caddr_t)&(VTONFS(v)->n_fh), cp, NFSX_FH)
+#define nfsm_srvfhtom(f, v3) \
+ { if (v3) { \
+ nfsm_build(tl, u_long *, NFSX_UNSIGNED + NFSX_V3FH); \
+ *tl++ = txdr_unsigned(NFSX_V3FH); \
+ bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \
+ } else { \
+ nfsm_build(cp, caddr_t, NFSX_V2FH); \
+ bcopy((caddr_t)(f), cp, NFSX_V2FH); \
+ } }
-#define nfsm_srvfhtom(f) \
- nfsm_build(cp,caddr_t,NFSX_FH); \
- bcopy((caddr_t)(f), cp, NFSX_FH)
+#define nfsm_srvpostop_fh(f) \
+ { nfsm_build(tl, u_long *, 2 * NFSX_UNSIGNED + NFSX_V3FH); \
+ *tl++ = nfs_true; \
+ *tl++ = txdr_unsigned(NFSX_V3FH); \
+ bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \
+ }
-#define nfsm_mtofh(d,v) \
- { struct nfsnode *np; nfsv2fh_t *fhp; \
- nfsm_dissect(fhp,nfsv2fh_t *,NFSX_FH); \
- error = nfs_nget((d)->v_mount, fhp, &np); \
- if (error) { \
- m_freem(mrep); \
- goto nfsmout; \
+#define nfsm_mtofh(d, v, v3, f) \
+ { struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \
+ if (v3) { \
+ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ (f) = fxdr_unsigned(int, *tl); \
+ } else \
+ (f) = 1; \
+ if (f) { \
+ nfsm_getfh(ttfhp, ttfhsize, (v3)); \
+ if (t1 = nfs_nget((d)->v_mount, ttfhp, ttfhsize, \
+ &ttnp)) { \
+ error = t1; \
+ m_freem(mrep); \
+ goto nfsmout; \
+ } \
+ (v) = NFSTOV(ttnp); \
+ } \
+ if (v3) { \
+ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ if (f) \
+ (f) = fxdr_unsigned(int, *tl); \
+ else if (fxdr_unsigned(int, *tl)) \
+ nfsm_adv(NFSX_V3FATTR); \
} \
- (v) = NFSTOV(np); \
- nfsm_loadattr(v, (struct vattr *)0); \
+ if (f) \
+ nfsm_loadattr((v), (struct vattr *)0); \
}
-#define nfsm_loadattr(v,a) \
- { struct vnode *tvp = (v); \
- error = nfs_loadattrcache(&tvp, &md, &dpos, (a)); \
- if (error) { \
+#define nfsm_getfh(f, s, v3) \
+ { if (v3) { \
+ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \
+ (s) > NFSX_V3FHMAX) { \
+ m_freem(mrep); \
+ error = EBADRPC; \
+ goto nfsmout; \
+ } \
+ } else \
+ (s) = NFSX_V2FH; \
+ nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); }
+
+#define nfsm_loadattr(v, a) \
+ { struct vnode *ttvp = (v); \
+ if (t1 = nfs_loadattrcache(&ttvp, &md, &dpos, (a))) { \
+ error = t1; \
m_freem(mrep); \
goto nfsmout; \
} \
- (v) = tvp; }
+ (v) = ttvp; }
+
+#define nfsm_postop_attr(v, f) \
+ { struct vnode *ttvp = (v); \
+ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ if ((f) = fxdr_unsigned(int, *tl)) { \
+ if (t1 = nfs_loadattrcache(&ttvp, &md, &dpos, \
+ (struct vattr *)0)) { \
+ error = t1; \
+ (f) = 0; \
+ m_freem(mrep); \
+ goto nfsmout; \
+ } \
+ (v) = ttvp; \
+ } }
+
+/* Used as (f) for nfsm_wcc_data() */
+#define NFSV3_WCCRATTR 0
+#define NFSV3_WCCCHK 1
+
+#define nfsm_wcc_data(v, f) \
+ { int ttattrf, ttretf = 0; \
+ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ if (*tl == nfs_true) { \
+ nfsm_dissect(tl, u_long *, 6 * NFSX_UNSIGNED); \
+ if (f) \
+ ttretf = (VTONFS(v)->n_mtime == \
+ fxdr_unsigned(u_long, *(tl + 2))); \
+ } \
+ nfsm_postop_attr((v), ttattrf); \
+ if (f) { \
+ (f) = ttretf; \
+ } else { \
+ (f) = ttattrf; \
+ } }
+
+#define nfsm_v3sattr(s, a, u, g) \
+ { (s)->sa_modetrue = nfs_true; \
+ (s)->sa_mode = vtonfsv3_mode((a)->va_mode); \
+ (s)->sa_uidtrue = nfs_true; \
+ (s)->sa_uid = txdr_unsigned(u); \
+ (s)->sa_gidtrue = nfs_true; \
+ (s)->sa_gid = txdr_unsigned(g); \
+ (s)->sa_sizefalse = nfs_false; \
+ (s)->sa_atimetype = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \
+ txdr_nfsv3time(&(a)->va_atime, &(s)->sa_atime); \
+ (s)->sa_mtimetype = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \
+ txdr_nfsv3time(&(a)->va_mtime, &(s)->sa_mtime); \
+ }
#define nfsm_strsiz(s,m) \
{ nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \
@@ -149,16 +254,27 @@ extern struct mbuf *nfsm_reqh();
nfsm_reply(0); \
} }
+#define nfsm_srvnamesiz(s) \
+ { nfsm_dissect(tl,u_long *,NFSX_UNSIGNED); \
+ if (((s) = fxdr_unsigned(long,*tl)) > NFS_MAXNAMLEN) \
+ error = NFSERR_NAMETOL; \
+ if ((s) <= 0) \
+ error = EBADRPC; \
+ if (error) \
+ nfsm_reply(0); \
+ }
+
#define nfsm_mtouio(p,s) \
if ((s) > 0 && \
- (error = nfsm_mbuftouio(&md,(p),(s),&dpos))) { \
+ (t1 = nfsm_mbuftouio(&md,(p),(s),&dpos))) { \
+ error = t1; \
m_freem(mrep); \
goto nfsmout; \
}
#define nfsm_uiotom(p,s) \
- error = nfsm_uiotombuf((p),&mb,(s),&bpos); \
- if (error) { \
+ if (t1 = nfsm_uiotombuf((p),&mb,(s),&bpos)) { \
+ error = t1; \
m_freem(mreq); \
goto nfsmout; \
}
@@ -172,10 +288,13 @@ extern struct mbuf *nfsm_reqh();
#define nfsm_rndup(a) (((a)+3)&(~0x3))
#define nfsm_request(v, t, p, c) \
- error = nfs_request((v), mreq, (t), (p), \
- (c), &mrep, &md, &dpos); \
- if (error) \
- goto nfsmout
+ if (error = nfs_request((v), mreq, (t), (p), \
+ (c), &mrep, &md, &dpos)) { \
+ if (error & NFSERR_RETERR) \
+ error &= ~NFSERR_RETERR; \
+ else \
+ goto nfsmout; \
+ }
#define nfsm_strtom(a,s,m) \
if ((s) > (m)) { \
@@ -189,12 +308,10 @@ extern struct mbuf *nfsm_reqh();
*tl++ = txdr_unsigned(s); \
*(tl+((t2>>2)-2)) = 0; \
bcopy((caddr_t)(a), (caddr_t)tl, (s)); \
- } else { \
- error = nfsm_strtmbuf(&mb, &bpos, (a), (s)); \
- if (error) { \
- m_freem(mreq); \
- goto nfsmout; \
- } \
+ } else if (t2 = nfsm_strtmbuf(&mb, &bpos, (a), (s))) { \
+ error = t2; \
+ m_freem(mreq); \
+ goto nfsmout; \
}
#define nfsm_srvdone \
@@ -204,33 +321,53 @@ extern struct mbuf *nfsm_reqh();
#define nfsm_reply(s) \
{ \
nfsd->nd_repstat = error; \
- if (error) \
- (void) nfs_rephead(0, nfsd, error, cache, &frev, \
+ if (error && !(nfsd->nd_flag & ND_NFSV3)) \
+ (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \
mrq, &mb, &bpos); \
else \
- (void) nfs_rephead((s), nfsd, error, cache, &frev, \
+ (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \
mrq, &mb, &bpos); \
m_freem(mrep); \
mreq = *mrq; \
- if (error) \
+ if (error && (!(nfsd->nd_flag & ND_NFSV3) || \
+ error == EBADRPC)) \
return(0); \
}
+#define nfsm_writereply(s, v3) \
+ { \
+ nfsd->nd_repstat = error; \
+ if (error && !(v3)) \
+ (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \
+ &mreq, &mb, &bpos); \
+ else \
+ (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \
+ &mreq, &mb, &bpos); \
+ }
+
#define nfsm_adv(s) \
- t1 = mtod(md, caddr_t)+md->m_len-dpos; \
+ { t1 = mtod(md, caddr_t)+md->m_len-dpos; \
if (t1 >= (s)) { \
dpos += (s); \
- } else { \
- error = nfs_adv(&md, &dpos, (s), t1); \
- if (error) { \
- m_freem(mrep); \
- goto nfsmout; \
- } \
- }
+ } else if (t1 = nfs_adv(&md, &dpos, (s), t1)) { \
+ error = t1; \
+ m_freem(mrep); \
+ goto nfsmout; \
+ } }
#define nfsm_srvmtofh(f) \
- nfsm_dissect(tl, u_long *, NFSX_FH); \
- bcopy((caddr_t)tl, (caddr_t)f, NFSX_FH)
+ { if (nfsd->nd_flag & ND_NFSV3) { \
+ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ if (fxdr_unsigned(int, *tl) != NFSX_V3FH) { \
+ error = EBADRPC; \
+ nfsm_reply(0); \
+ } \
+ } \
+ nfsm_dissect(tl, u_long *, NFSX_V3FH); \
+ bcopy((caddr_t)tl, (caddr_t)(f), NFSX_V3FH); \
+ if ((nfsd->nd_flag & ND_NFSV3) == 0) \
+ nfsm_adv(NFSX_V2FH - NFSX_V3FH); \
+ }
#define nfsm_clget \
if (bp >= be) { \
@@ -246,41 +383,57 @@ extern struct mbuf *nfsm_reqh();
} \
tl = (u_long *)bp
-#define nfsm_srvfillattr \
- fp->fa_type = vtonfs_type(vap->va_type); \
- fp->fa_mode = vtonfs_mode(vap->va_type, vap->va_mode); \
- fp->fa_nlink = txdr_unsigned(vap->va_nlink); \
- fp->fa_uid = txdr_unsigned(vap->va_uid); \
- fp->fa_gid = txdr_unsigned(vap->va_gid); \
- if (nfsd->nd_nqlflag == NQL_NOVAL) { \
- fp->fa_nfsblocksize = txdr_unsigned(vap->va_blocksize); \
- if (vap->va_type == VFIFO) \
- fp->fa_nfsrdev = 0xffffffff; \
- else \
- fp->fa_nfsrdev = txdr_unsigned(vap->va_rdev); \
- fp->fa_nfsfsid = txdr_unsigned(vap->va_fsid); \
- fp->fa_nfsfileid = txdr_unsigned(vap->va_fileid); \
- fp->fa_nfssize = txdr_unsigned(vap->va_size); \
- fp->fa_nfsblocks = txdr_unsigned(vap->va_bytes / NFS_FABLKSIZE); \
- txdr_nfstime(&vap->va_atime, &fp->fa_nfsatime); \
- txdr_nfstime(&vap->va_mtime, &fp->fa_nfsmtime); \
- txdr_nfstime(&vap->va_ctime, &fp->fa_nfsctime); \
- } else { \
- fp->fa_nqblocksize = txdr_unsigned(vap->va_blocksize); \
- if (vap->va_type == VFIFO) \
- fp->fa_nqrdev = 0xffffffff; \
- else \
- fp->fa_nqrdev = txdr_unsigned(vap->va_rdev); \
- fp->fa_nqfsid = txdr_unsigned(vap->va_fsid); \
- fp->fa_nqfileid = txdr_unsigned(vap->va_fileid); \
- txdr_hyper(&vap->va_size, &fp->fa_nqsize); \
- txdr_hyper(&vap->va_bytes, &fp->fa_nqbytes); \
- txdr_nqtime(&vap->va_atime, &fp->fa_nqatime); \
- txdr_nqtime(&vap->va_mtime, &fp->fa_nqmtime); \
- txdr_nqtime(&vap->va_ctime, &fp->fa_nqctime); \
- fp->fa_nqflags = txdr_unsigned(vap->va_flags); \
- fp->fa_nqgen = txdr_unsigned(vap->va_gen); \
- txdr_hyper(&vap->va_filerev, &fp->fa_nqfilerev); \
- }
+#define nfsm_srvfillattr(a, f) \
+ nfsm_srvfattr(nfsd, (a), (f))
+
+#define nfsm_srvwcc_data(br, b, ar, a) \
+ nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos)
+
+#define nfsm_srvpostop_attr(r, a) \
+ nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos)
+
+#define nfsm_srvsattr(a) \
+ { nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ if (*tl == nfs_true) { \
+ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ (a)->va_mode = nfstov_mode(*tl); \
+ } \
+ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ if (*tl == nfs_true) { \
+ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ (a)->va_uid = fxdr_unsigned(uid_t, *tl); \
+ } \
+ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ if (*tl == nfs_true) { \
+ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ (a)->va_gid = fxdr_unsigned(gid_t, *tl); \
+ } \
+ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ if (*tl == nfs_true) { \
+ nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \
+ fxdr_hyper(tl, &(a)->va_size); \
+ } \
+ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ switch (fxdr_unsigned(int, *tl)) { \
+ case NFSV3SATTRTIME_TOCLIENT: \
+ nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \
+ fxdr_nfsv3time(tl, &(a)->va_atime); \
+ break; \
+ case NFSV3SATTRTIME_TOSERVER: \
+ (a)->va_atime.ts_sec = time.tv_sec; \
+ (a)->va_atime.ts_nsec = time.tv_usec * 1000; \
+ break; \
+ }; \
+ nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
+ switch (fxdr_unsigned(int, *tl)) { \
+ case NFSV3SATTRTIME_TOCLIENT: \
+ nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \
+ fxdr_nfsv3time(tl, &(a)->va_mtime); \
+ break; \
+ case NFSV3SATTRTIME_TOSERVER: \
+ (a)->va_mtime.ts_sec = time.tv_sec; \
+ (a)->va_mtime.ts_nsec = time.tv_usec * 1000; \
+ break; \
+ }; }
#endif
OpenPOWER on IntegriCloud