1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <rpc/types.h>
30*0Sstevel@tonic-gate #include <rpc/xdr.h>
31*0Sstevel@tonic-gate #include <rpc/rpc.h>
32*0Sstevel@tonic-gate #include <rpcsvc/nfs_prot.h>
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate /*
35*0Sstevel@tonic-gate * Xdr routines for NFS ops.
36*0Sstevel@tonic-gate */
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate static bool_t
xdr_b_nfs_fh3(XDR * xdrs,nfs_fh3 * objp)39*0Sstevel@tonic-gate xdr_b_nfs_fh3(XDR *xdrs, nfs_fh3 *objp)
40*0Sstevel@tonic-gate {
41*0Sstevel@tonic-gate return (xdr_bytes(xdrs, (char **)&objp->data.data_val,
42*0Sstevel@tonic-gate (uint_t *)&objp->data.data_len, NFS3_FHSIZE));
43*0Sstevel@tonic-gate }
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gate static bool_t
xdr_b_fattr3(XDR * xdrs,fattr3 * objp)46*0Sstevel@tonic-gate xdr_b_fattr3(XDR *xdrs, fattr3 *objp)
47*0Sstevel@tonic-gate {
48*0Sstevel@tonic-gate if (!xdr_enum(xdrs, (enum_t *)&objp->type))
49*0Sstevel@tonic-gate return (FALSE);
50*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &objp->mode))
51*0Sstevel@tonic-gate return (FALSE);
52*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &objp->nlink))
53*0Sstevel@tonic-gate return (FALSE);
54*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &objp->uid))
55*0Sstevel@tonic-gate return (FALSE);
56*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &objp->gid))
57*0Sstevel@tonic-gate return (FALSE);
58*0Sstevel@tonic-gate if (!xdr_u_longlong_t(xdrs, &objp->size))
59*0Sstevel@tonic-gate return (FALSE);
60*0Sstevel@tonic-gate if (!xdr_u_longlong_t(xdrs, &objp->used))
61*0Sstevel@tonic-gate return (FALSE);
62*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &objp->rdev.specdata1))
63*0Sstevel@tonic-gate return (FALSE);
64*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &objp->rdev.specdata2))
65*0Sstevel@tonic-gate return (FALSE);
66*0Sstevel@tonic-gate if (!xdr_u_longlong_t(xdrs, &objp->fsid))
67*0Sstevel@tonic-gate return (FALSE);
68*0Sstevel@tonic-gate if (!xdr_u_longlong_t(xdrs, &objp->fileid))
69*0Sstevel@tonic-gate return (FALSE);
70*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &objp->atime.seconds))
71*0Sstevel@tonic-gate return (FALSE);
72*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &objp->atime.nseconds))
73*0Sstevel@tonic-gate return (FALSE);
74*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &objp->mtime.seconds))
75*0Sstevel@tonic-gate return (FALSE);
76*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &objp->mtime.nseconds))
77*0Sstevel@tonic-gate return (FALSE);
78*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &objp->ctime.seconds))
79*0Sstevel@tonic-gate return (FALSE);
80*0Sstevel@tonic-gate return (xdr_u_int(xdrs, &objp->ctime.nseconds));
81*0Sstevel@tonic-gate }
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate static bool_t
xdr_b_post_op_attr(XDR * xdrs,post_op_attr * objp)84*0Sstevel@tonic-gate xdr_b_post_op_attr(XDR *xdrs, post_op_attr *objp)
85*0Sstevel@tonic-gate {
86*0Sstevel@tonic-gate if (!xdr_bool(xdrs, &objp->attributes_follow))
87*0Sstevel@tonic-gate return (FALSE);
88*0Sstevel@tonic-gate switch (objp->attributes_follow) {
89*0Sstevel@tonic-gate case TRUE:
90*0Sstevel@tonic-gate return (xdr_b_fattr3(xdrs, &objp->post_op_attr_u.attributes));
91*0Sstevel@tonic-gate case FALSE:
92*0Sstevel@tonic-gate return (TRUE);
93*0Sstevel@tonic-gate default:
94*0Sstevel@tonic-gate return (FALSE);
95*0Sstevel@tonic-gate }
96*0Sstevel@tonic-gate }
97*0Sstevel@tonic-gate
98*0Sstevel@tonic-gate static bool_t
xdr_b_diropargs3(XDR * xdrs,diropargs3 * objp)99*0Sstevel@tonic-gate xdr_b_diropargs3(XDR *xdrs, diropargs3 *objp)
100*0Sstevel@tonic-gate {
101*0Sstevel@tonic-gate if (!xdr_b_nfs_fh3(xdrs, &objp->dir))
102*0Sstevel@tonic-gate return (FALSE);
103*0Sstevel@tonic-gate return (xdr_string(xdrs, &objp->name, ~0));
104*0Sstevel@tonic-gate }
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate bool_t
xdr_GETATTR3args(XDR * xdrs,GETATTR3args * objp)107*0Sstevel@tonic-gate xdr_GETATTR3args(XDR *xdrs, GETATTR3args *objp)
108*0Sstevel@tonic-gate {
109*0Sstevel@tonic-gate return (xdr_b_nfs_fh3(xdrs, &objp->object));
110*0Sstevel@tonic-gate }
111*0Sstevel@tonic-gate
112*0Sstevel@tonic-gate static bool_t
xdr_b_GETATTR3resok(XDR * xdrs,GETATTR3resok * objp)113*0Sstevel@tonic-gate xdr_b_GETATTR3resok(XDR *xdrs, GETATTR3resok *objp)
114*0Sstevel@tonic-gate {
115*0Sstevel@tonic-gate return (xdr_b_fattr3(xdrs, &objp->obj_attributes));
116*0Sstevel@tonic-gate }
117*0Sstevel@tonic-gate
118*0Sstevel@tonic-gate bool_t
xdr_GETATTR3res(XDR * xdrs,GETATTR3res * objp)119*0Sstevel@tonic-gate xdr_GETATTR3res(XDR *xdrs, GETATTR3res *objp)
120*0Sstevel@tonic-gate {
121*0Sstevel@tonic-gate if (!xdr_enum(xdrs, (enum_t *)&objp->status))
122*0Sstevel@tonic-gate return (FALSE);
123*0Sstevel@tonic-gate if (objp->status == NFS3_OK)
124*0Sstevel@tonic-gate return (xdr_b_GETATTR3resok(xdrs, &objp->GETATTR3res_u.resok));
125*0Sstevel@tonic-gate return (TRUE);
126*0Sstevel@tonic-gate }
127*0Sstevel@tonic-gate
128*0Sstevel@tonic-gate bool_t
xdr_LOOKUP3args(XDR * xdrs,LOOKUP3args * objp)129*0Sstevel@tonic-gate xdr_LOOKUP3args(XDR *xdrs, LOOKUP3args *objp)
130*0Sstevel@tonic-gate {
131*0Sstevel@tonic-gate return (xdr_b_diropargs3(xdrs, &objp->what));
132*0Sstevel@tonic-gate }
133*0Sstevel@tonic-gate
134*0Sstevel@tonic-gate static bool_t
xdr_b_LOOKUP3resok(XDR * xdrs,LOOKUP3resok * objp)135*0Sstevel@tonic-gate xdr_b_LOOKUP3resok(XDR *xdrs, LOOKUP3resok *objp)
136*0Sstevel@tonic-gate {
137*0Sstevel@tonic-gate if (!xdr_b_nfs_fh3(xdrs, &objp->object))
138*0Sstevel@tonic-gate return (FALSE);
139*0Sstevel@tonic-gate if (!xdr_b_post_op_attr(xdrs, &objp->obj_attributes))
140*0Sstevel@tonic-gate return (FALSE);
141*0Sstevel@tonic-gate return (xdr_b_post_op_attr(xdrs, &objp->dir_attributes));
142*0Sstevel@tonic-gate }
143*0Sstevel@tonic-gate
144*0Sstevel@tonic-gate static bool_t
xdr_b_LOOKUP3resfail(XDR * xdrs,LOOKUP3resfail * objp)145*0Sstevel@tonic-gate xdr_b_LOOKUP3resfail(XDR *xdrs, LOOKUP3resfail *objp)
146*0Sstevel@tonic-gate {
147*0Sstevel@tonic-gate return (xdr_b_post_op_attr(xdrs, &objp->dir_attributes));
148*0Sstevel@tonic-gate }
149*0Sstevel@tonic-gate
150*0Sstevel@tonic-gate bool_t
xdr_LOOKUP3res(XDR * xdrs,LOOKUP3res * objp)151*0Sstevel@tonic-gate xdr_LOOKUP3res(XDR *xdrs, LOOKUP3res *objp)
152*0Sstevel@tonic-gate {
153*0Sstevel@tonic-gate if (!xdr_enum(xdrs, (enum_t *)&objp->status))
154*0Sstevel@tonic-gate return (FALSE);
155*0Sstevel@tonic-gate
156*0Sstevel@tonic-gate if (objp->status == NFS3_OK)
157*0Sstevel@tonic-gate return (xdr_b_LOOKUP3resok(xdrs, &objp->LOOKUP3res_u.resok));
158*0Sstevel@tonic-gate
159*0Sstevel@tonic-gate return (xdr_b_LOOKUP3resfail(xdrs, &objp->LOOKUP3res_u.resfail));
160*0Sstevel@tonic-gate }
161*0Sstevel@tonic-gate
162*0Sstevel@tonic-gate bool_t
xdr_READLINK3args(XDR * xdrs,READLINK3args * objp)163*0Sstevel@tonic-gate xdr_READLINK3args(XDR *xdrs, READLINK3args *objp)
164*0Sstevel@tonic-gate {
165*0Sstevel@tonic-gate return (xdr_b_nfs_fh3(xdrs, &objp->symlink));
166*0Sstevel@tonic-gate }
167*0Sstevel@tonic-gate
168*0Sstevel@tonic-gate static bool_t
xdr_b_READLINK3resok(XDR * xdrs,READLINK3resok * objp)169*0Sstevel@tonic-gate xdr_b_READLINK3resok(XDR *xdrs, READLINK3resok *objp)
170*0Sstevel@tonic-gate {
171*0Sstevel@tonic-gate if (!xdr_b_post_op_attr(xdrs, &objp->symlink_attributes))
172*0Sstevel@tonic-gate return (FALSE);
173*0Sstevel@tonic-gate return (xdr_string(xdrs, &objp->data, ~0));
174*0Sstevel@tonic-gate }
175*0Sstevel@tonic-gate
176*0Sstevel@tonic-gate static bool_t
xdr_b_READLINK3resfail(XDR * xdrs,READLINK3resfail * objp)177*0Sstevel@tonic-gate xdr_b_READLINK3resfail(XDR *xdrs, READLINK3resfail *objp)
178*0Sstevel@tonic-gate {
179*0Sstevel@tonic-gate return (xdr_b_post_op_attr(xdrs, &objp->symlink_attributes));
180*0Sstevel@tonic-gate }
181*0Sstevel@tonic-gate
182*0Sstevel@tonic-gate bool_t
xdr_READLINK3res(XDR * xdrs,READLINK3res * objp)183*0Sstevel@tonic-gate xdr_READLINK3res(XDR *xdrs, READLINK3res *objp)
184*0Sstevel@tonic-gate {
185*0Sstevel@tonic-gate if (!xdr_enum(xdrs, (enum_t *)&objp->status))
186*0Sstevel@tonic-gate return (FALSE);
187*0Sstevel@tonic-gate if (objp->status == NFS3_OK)
188*0Sstevel@tonic-gate return (xdr_b_READLINK3resok(xdrs,
189*0Sstevel@tonic-gate &objp->READLINK3res_u.resok));
190*0Sstevel@tonic-gate return (xdr_b_READLINK3resfail(xdrs, &objp->READLINK3res_u.resfail));
191*0Sstevel@tonic-gate }
192*0Sstevel@tonic-gate
193*0Sstevel@tonic-gate bool_t
xdr_READ3args(XDR * xdrs,READ3args * objp)194*0Sstevel@tonic-gate xdr_READ3args(XDR *xdrs, READ3args *objp)
195*0Sstevel@tonic-gate {
196*0Sstevel@tonic-gate if (!xdr_b_nfs_fh3(xdrs, &objp->file))
197*0Sstevel@tonic-gate return (FALSE);
198*0Sstevel@tonic-gate if (!xdr_u_longlong_t(xdrs, &objp->offset))
199*0Sstevel@tonic-gate return (FALSE);
200*0Sstevel@tonic-gate return (xdr_u_int(xdrs, &objp->count));
201*0Sstevel@tonic-gate }
202*0Sstevel@tonic-gate
203*0Sstevel@tonic-gate static bool_t
xdr_b_READ3resok(XDR * xdrs,READ3resok * objp)204*0Sstevel@tonic-gate xdr_b_READ3resok(XDR *xdrs, READ3resok *objp)
205*0Sstevel@tonic-gate {
206*0Sstevel@tonic-gate if (!xdr_b_post_op_attr(xdrs, &objp->file_attributes))
207*0Sstevel@tonic-gate return (FALSE);
208*0Sstevel@tonic-gate if (!xdr_u_int(xdrs, &objp->count))
209*0Sstevel@tonic-gate return (FALSE);
210*0Sstevel@tonic-gate if (!xdr_bool(xdrs, &objp->eof))
211*0Sstevel@tonic-gate return (FALSE);
212*0Sstevel@tonic-gate return (xdr_bytes(xdrs, (char **)&objp->data.data_val,
213*0Sstevel@tonic-gate (uint_t *)&objp->data.data_len, ~0));
214*0Sstevel@tonic-gate }
215*0Sstevel@tonic-gate
216*0Sstevel@tonic-gate static bool_t
xdr_b_READ3resfail(XDR * xdrs,READ3resfail * objp)217*0Sstevel@tonic-gate xdr_b_READ3resfail(XDR *xdrs, READ3resfail *objp)
218*0Sstevel@tonic-gate {
219*0Sstevel@tonic-gate return (xdr_b_post_op_attr(xdrs, &objp->file_attributes));
220*0Sstevel@tonic-gate }
221*0Sstevel@tonic-gate
222*0Sstevel@tonic-gate bool_t
xdr_READ3res(XDR * xdrs,READ3res * objp)223*0Sstevel@tonic-gate xdr_READ3res(XDR *xdrs, READ3res *objp)
224*0Sstevel@tonic-gate {
225*0Sstevel@tonic-gate if (!xdr_enum(xdrs, (enum_t *)&objp->status))
226*0Sstevel@tonic-gate return (FALSE);
227*0Sstevel@tonic-gate if (objp->status == NFS3_OK)
228*0Sstevel@tonic-gate return (xdr_b_READ3resok(xdrs, &objp->READ3res_u.resok));
229*0Sstevel@tonic-gate return (xdr_b_READ3resfail(xdrs, &objp->READ3res_u.resfail));
230*0Sstevel@tonic-gate }
231*0Sstevel@tonic-gate
232*0Sstevel@tonic-gate bool_t
xdr_READDIR3args(XDR * xdrs,READDIR3args * objp)233*0Sstevel@tonic-gate xdr_READDIR3args(XDR *xdrs, READDIR3args *objp)
234*0Sstevel@tonic-gate {
235*0Sstevel@tonic-gate if (!xdr_b_nfs_fh3(xdrs, &objp->dir))
236*0Sstevel@tonic-gate return (FALSE);
237*0Sstevel@tonic-gate if (!xdr_u_longlong_t(xdrs, &objp->cookie))
238*0Sstevel@tonic-gate return (FALSE);
239*0Sstevel@tonic-gate if (!xdr_opaque(xdrs, objp->cookieverf, NFS3_COOKIEVERFSIZE))
240*0Sstevel@tonic-gate return (FALSE);
241*0Sstevel@tonic-gate return (xdr_u_int(xdrs, &objp->count));
242*0Sstevel@tonic-gate }
243*0Sstevel@tonic-gate
244*0Sstevel@tonic-gate static bool_t
xdr_b_entry3(XDR * xdrs,entry3 * objp)245*0Sstevel@tonic-gate xdr_b_entry3(XDR *xdrs, entry3 *objp)
246*0Sstevel@tonic-gate {
247*0Sstevel@tonic-gate if (!xdr_u_longlong_t(xdrs, &objp->fileid))
248*0Sstevel@tonic-gate return (FALSE);
249*0Sstevel@tonic-gate if (!xdr_string(xdrs, &objp->name, ~0))
250*0Sstevel@tonic-gate return (FALSE);
251*0Sstevel@tonic-gate if (!xdr_u_longlong_t(xdrs, &objp->cookie))
252*0Sstevel@tonic-gate return (FALSE);
253*0Sstevel@tonic-gate return (xdr_pointer(xdrs, (char **)&objp->nextentry,
254*0Sstevel@tonic-gate sizeof (entry3), (xdrproc_t)xdr_b_entry3));
255*0Sstevel@tonic-gate }
256*0Sstevel@tonic-gate
257*0Sstevel@tonic-gate static bool_t
xdr_b_READDIR3resok(XDR * xdrs,READDIR3resok * objp)258*0Sstevel@tonic-gate xdr_b_READDIR3resok(XDR *xdrs, READDIR3resok *objp)
259*0Sstevel@tonic-gate {
260*0Sstevel@tonic-gate if (!xdr_b_post_op_attr(xdrs, &objp->dir_attributes))
261*0Sstevel@tonic-gate return (FALSE);
262*0Sstevel@tonic-gate if (!xdr_opaque(xdrs, objp->cookieverf, NFS3_COOKIEVERFSIZE))
263*0Sstevel@tonic-gate return (FALSE);
264*0Sstevel@tonic-gate if (!xdr_pointer(xdrs, (char **)&objp->reply.entries,
265*0Sstevel@tonic-gate sizeof (entry3), (xdrproc_t)xdr_b_entry3))
266*0Sstevel@tonic-gate return (FALSE);
267*0Sstevel@tonic-gate return (xdr_bool(xdrs, &objp->reply.eof));
268*0Sstevel@tonic-gate }
269*0Sstevel@tonic-gate
270*0Sstevel@tonic-gate static bool_t
xdr_b_READDIR3resfail(XDR * xdrs,READDIR3resfail * objp)271*0Sstevel@tonic-gate xdr_b_READDIR3resfail(XDR *xdrs, READDIR3resfail *objp)
272*0Sstevel@tonic-gate {
273*0Sstevel@tonic-gate return (xdr_b_post_op_attr(xdrs, &objp->dir_attributes));
274*0Sstevel@tonic-gate }
275*0Sstevel@tonic-gate
276*0Sstevel@tonic-gate bool_t
xdr_READDIR3res(XDR * xdrs,READDIR3res * objp)277*0Sstevel@tonic-gate xdr_READDIR3res(XDR *xdrs, READDIR3res *objp)
278*0Sstevel@tonic-gate {
279*0Sstevel@tonic-gate if (!xdr_enum(xdrs, (enum_t *)&objp->status))
280*0Sstevel@tonic-gate return (FALSE);
281*0Sstevel@tonic-gate if (objp->status == NFS3_OK)
282*0Sstevel@tonic-gate return (xdr_b_READDIR3resok(xdrs, &objp->READDIR3res_u.resok));
283*0Sstevel@tonic-gate return (xdr_b_READDIR3resfail(xdrs, &objp->READDIR3res_u.resfail));
284*0Sstevel@tonic-gate }
285