|
|
1.1 root 1: /*
2: * Copyright (c) 1989 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * This code is derived from software contributed to Berkeley by
6: * Rick Macklem at The University of Guelph.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by the University of
19: * California, Berkeley and its contributors.
20: * 4. Neither the name of the University nor the names of its contributors
21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34: * SUCH DAMAGE.
35: *
36: * @(#)nfsm_subs.h 7.11 (Berkeley) 4/16/91
37: */
38:
1.1.1.2 ! root 39: #ifndef _NFS_NFSM_SUBS_H_
! 40: #define _NFS_NFSM_SUBS_H_
! 41:
1.1 root 42: /*
43: * These macros do strange and peculiar things to mbuf chains for
44: * the assistance of the nfs code. To attempt to use them for any
45: * other purpose will be dangerous. (they make weird assumptions)
46: */
47:
48: /*
49: * First define what the actual subs. return
50: */
51: extern struct mbuf *nfsm_reqh();
52:
53: #define M_HASCL(m) ((m)->m_flags & M_EXT)
54: #define NFSMGETHDR(m) \
55: MGETHDR(m, M_WAIT, MT_DATA); \
56: (m)->m_pkthdr.len = 0; \
57: (m)->m_pkthdr.rcvif = (struct ifnet *)0
58: #define NFSMINOFF(m) \
59: if (M_HASCL(m)) \
60: (m)->m_data = (m)->m_ext.ext_buf; \
61: else \
62: (m)->m_data = (m)->m_dat
63: #define NFSMADV(m, s) (m)->m_data += (s)
64: #define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \
65: (((m)->m_flags & M_PKTHDR)?MHLEN:MLEN))
66:
67: /*
68: * Now for the macros that do the simple stuff and call the functions
69: * for the hard stuff.
70: * These macros use several vars. declared in nfsm_reqhead and these
71: * vars. must not be used elsewhere unless you are careful not to corrupt
72: * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
73: * that may be used so long as the value is not expected to retained
74: * after a macro.
75: * I know, this is kind of dorkey, but it makes the actual op functions
76: * fairly clean and deals with the mess caused by the xdr discriminating
77: * unions.
78: */
79:
80: #ifndef lint
81: #define nfsm_build(a,c,s) \
82: t1 = NFSMSIZ(mb); \
83: if ((s) > (t1-mb->m_len)) { \
84: MGET(mb2, M_WAIT, MT_DATA); \
85: if ((s) > MLEN) \
86: panic("build > MLEN"); \
87: mb->m_next = mb2; \
88: mb = mb2; \
89: mb->m_len = 0; \
90: bpos = mtod(mb, caddr_t); \
91: } \
92: (a) = (c)(bpos); \
93: mb->m_len += (s); \
94: bpos += (s)
95: #else /* lint */
96: #define nfsm_build(a,c,s) \
97: t1 = NFSMSIZ(mb); \
98: if ((s) > (t1-mb->m_len)) { \
99: MGET(mb2, M_WAIT, MT_DATA); \
100: mb->m_next = mb2; \
101: mb = mb2; \
102: mb->m_len = 0; \
103: bpos = mtod(mb, caddr_t); \
104: } \
105: (a) = (c)(bpos); \
106: mb->m_len += (s); \
107: bpos += (s)
108: #endif /* lint */
109:
110: #define nfsm_disect(a,c,s) \
111: t1 = mtod(md, caddr_t)+md->m_len-dpos; \
112: if (t1 >= (s)) { \
113: (a) = (c)(dpos); \
114: dpos += (s); \
115: } else if (error = nfsm_disct(&md, &dpos, (s), t1, TRUE, &cp2)) { \
116: m_freem(mrep); \
117: goto nfsmout; \
118: } else { \
119: (a) = (c)cp2; \
120: }
121:
122: #define nfsm_disecton(a,c,s) \
123: t1 = mtod(md, caddr_t)+md->m_len-dpos; \
124: if (t1 >= (s)) { \
125: (a) = (c)(dpos); \
126: dpos += (s); \
127: } else if (error = nfsm_disct(&md, &dpos, (s), t1, FALSE, &cp2)) { \
128: m_freem(mrep); \
129: goto nfsmout; \
130: } else { \
131: (a) = (c)cp2; \
132: }
133:
134: #define nfsm_fhtom(v) \
135: nfsm_build(cp,caddr_t,NFSX_FH); \
136: bcopy((caddr_t)&(VTONFS(v)->n_fh), cp, NFSX_FH)
137:
138: #define nfsm_srvfhtom(f) \
139: nfsm_build(cp,caddr_t,NFSX_FH); \
140: bcopy((caddr_t)(f), cp, NFSX_FH)
141:
142: #define nfsm_mtofh(d,v) \
143: { struct nfsnode *np; nfsv2fh_t *fhp; \
144: nfsm_disect(fhp,nfsv2fh_t *,NFSX_FH); \
145: if (error = nfs_nget((d)->v_mount, fhp, &np)) { \
146: m_freem(mrep); \
147: goto nfsmout; \
148: } \
149: (v) = NFSTOV(np); \
150: nfsm_loadattr(v, (struct vattr *)0); \
151: }
152:
153: #define nfsm_loadattr(v,a) \
154: { struct vnode *tvp = (v); \
155: if (error = nfs_loadattrcache(&tvp, &md, &dpos, (a))) { \
156: m_freem(mrep); \
157: goto nfsmout; \
158: } \
159: (v) = tvp; }
160:
161: #define nfsm_strsiz(s,m) \
162: nfsm_disect(tl,u_long *,NFSX_UNSIGNED); \
163: if (((s) = fxdr_unsigned(long,*tl)) > (m)) { \
164: m_freem(mrep); \
165: error = EBADRPC; \
166: goto nfsmout; \
167: }
168:
169: #define nfsm_srvstrsiz(s,m) \
170: nfsm_disect(tl,u_long *,NFSX_UNSIGNED); \
171: if (((s) = fxdr_unsigned(long,*tl)) > (m) || (s) <= 0) { \
172: error = EBADRPC; \
173: nfsm_reply(0); \
174: }
175:
176: #define nfsm_mtouio(p,s) \
177: if ((s) > 0 && \
178: (error = nfsm_mbuftouio(&md,(p),(s),&dpos))) { \
179: m_freem(mrep); \
180: goto nfsmout; \
181: }
182:
183: #define nfsm_uiotom(p,s) \
184: if (error = nfsm_uiotombuf((p),&mb,(s),&bpos)) { \
185: m_freem(mreq); \
186: goto nfsmout; \
187: }
188:
189: #define nfsm_reqhead(a,c,s) \
190: if ((mreq = nfsm_reqh(nfs_prog,nfs_vers,(a),(c),(s),&bpos,&mb,&xid)) == NULL) { \
191: error = ENOBUFS; \
192: goto nfsmout; \
193: }
194:
195: #define nfsm_reqdone m_freem(mrep); \
196: nfsmout:
197:
198: #define nfsm_rndup(a) (((a)+3)&(~0x3))
199:
200: #define nfsm_request(v, t, p, h) \
201: if (error = nfs_request((v), mreq, xid, (t), (p), (h), \
202: (v)->v_mount, &mrep, &md, &dpos)) \
203: goto nfsmout
204:
205: #define nfsm_strtom(a,s,m) \
206: if ((s) > (m)) { \
207: m_freem(mreq); \
208: error = ENAMETOOLONG; \
209: goto nfsmout; \
210: } \
211: t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \
212: if(t2<=(NFSMSIZ(mb)-mb->m_len)){ \
213: nfsm_build(tl,u_long *,t2); \
214: *tl++ = txdr_unsigned(s); \
215: *(tl+((t2>>2)-2)) = 0; \
216: bcopy((caddr_t)(a), (caddr_t)tl, (s)); \
217: } else if (error = nfsm_strtmbuf(&mb, &bpos, (a), (s))) { \
218: m_freem(mreq); \
219: goto nfsmout; \
220: }
221:
222: #define nfsm_srvdone \
223: nfsmout: \
224: return(error)
225:
226: #ifndef lint
227: #define nfsm_reply(s) \
228: { \
229: *repstat = error; \
230: if (error) \
231: nfs_rephead(0, xid, error, mrq, &mb, &bpos); \
232: else \
233: nfs_rephead((s), xid, error, mrq, &mb, &bpos); \
234: m_freem(mrep); \
235: mreq = *mrq; \
236: if (error) \
237: return(0); \
238: }
239: #else /* lint */
240: #define nfsm_reply(s) \
241: { \
242: *repstat = error; \
243: if (error) \
244: nfs_rephead(0, xid, error, mrq, &mb, &bpos); \
245: else \
246: nfs_rephead((s), xid, error, mrq, &mb, &bpos); \
247: m_freem(mrep); \
248: mreq = *mrq; \
249: mrep = mreq; \
250: if (error) \
251: return(0); \
252: }
253: #endif /* lint */
254:
255: #define nfsm_adv(s) \
256: t1 = mtod(md, caddr_t)+md->m_len-dpos; \
257: if (t1 >= (s)) { \
258: dpos += (s); \
259: } else if (error = nfs_adv(&md, &dpos, (s), t1)) { \
260: m_freem(mrep); \
261: goto nfsmout; \
262: }
263:
264: #define nfsm_srvmtofh(f) \
265: nfsm_disecton(tl, u_long *, NFSX_FH); \
266: bcopy((caddr_t)tl, (caddr_t)f, NFSX_FH)
267:
268: #define nfsm_clget \
269: if (bp >= be) { \
270: MGET(mp, M_WAIT, MT_DATA); \
271: MCLGET(mp, M_WAIT); \
272: mp->m_len = NFSMSIZ(mp); \
273: if (mp3 == NULL) \
274: mp3 = mp2 = mp; \
275: else { \
276: mp2->m_next = mp; \
277: mp2 = mp; \
278: } \
279: bp = mtod(mp, caddr_t); \
280: be = bp+mp->m_len; \
281: } \
282: tl = (u_long *)bp
283:
284: #define nfsm_srvfillattr \
285: fp->fa_type = vtonfs_type(vap->va_type); \
286: fp->fa_mode = vtonfs_mode(vap->va_type, vap->va_mode); \
287: fp->fa_nlink = txdr_unsigned(vap->va_nlink); \
288: fp->fa_uid = txdr_unsigned(vap->va_uid); \
289: fp->fa_gid = txdr_unsigned(vap->va_gid); \
290: fp->fa_size = txdr_unsigned(vap->va_size); \
291: fp->fa_blocksize = txdr_unsigned(vap->va_blocksize); \
292: if (vap->va_type == VFIFO) \
293: fp->fa_rdev = 0xffffffff; \
294: else \
295: fp->fa_rdev = txdr_unsigned(vap->va_rdev); \
296: fp->fa_blocks = txdr_unsigned(vap->va_bytes / NFS_FABLKSIZE); \
297: fp->fa_fsid = txdr_unsigned(vap->va_fsid); \
298: fp->fa_fileid = txdr_unsigned(vap->va_fileid); \
299: fp->fa_atime.tv_sec = txdr_unsigned(vap->va_atime.tv_sec); \
300: fp->fa_atime.tv_usec = txdr_unsigned(vap->va_flags); \
301: txdr_time(&vap->va_mtime, &fp->fa_mtime); \
302: fp->fa_ctime.tv_sec = txdr_unsigned(vap->va_ctime.tv_sec); \
303: fp->fa_ctime.tv_usec = txdr_unsigned(vap->va_gen)
304:
1.1.1.2 ! root 305: #endif /* !_NFS_NFSM_SUBS_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.