xref: /onnv-gate/usr/src/stand/lib/fs/nfs/nfs_xdr.c (revision 0:68f95e015346)
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 static bool_t
xdr_b_nfsstat(XDR * xdrs,nfsstat * objp)38*0Sstevel@tonic-gate xdr_b_nfsstat(XDR *xdrs, nfsstat *objp)
39*0Sstevel@tonic-gate {
40*0Sstevel@tonic-gate 	return (xdr_enum(xdrs, (enum_t *)objp));
41*0Sstevel@tonic-gate }
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate static bool_t
xdr_b_ftype(XDR * xdrs,ftype * objp)44*0Sstevel@tonic-gate xdr_b_ftype(XDR *xdrs, ftype *objp)
45*0Sstevel@tonic-gate {
46*0Sstevel@tonic-gate 	return (xdr_enum(xdrs, (enum_t *)objp));
47*0Sstevel@tonic-gate }
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate bool_t
xdr_nfs_fh(XDR * xdrs,nfs_fh * objp)50*0Sstevel@tonic-gate xdr_nfs_fh(XDR *xdrs, nfs_fh *objp)
51*0Sstevel@tonic-gate {
52*0Sstevel@tonic-gate 	return (xdr_opaque(xdrs, objp->data, NFS_FHSIZE));
53*0Sstevel@tonic-gate }
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate static bool_t
xdr_b_nfstime(XDR * xdrs,nfstime * objp)56*0Sstevel@tonic-gate xdr_b_nfstime(XDR *xdrs, nfstime *objp)
57*0Sstevel@tonic-gate {
58*0Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->seconds)) {
59*0Sstevel@tonic-gate 		return (FALSE);
60*0Sstevel@tonic-gate 	}
61*0Sstevel@tonic-gate 	return (xdr_u_int(xdrs, &objp->useconds));
62*0Sstevel@tonic-gate }
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate static bool_t
xdr_b_fattr(XDR * xdrs,fattr * objp)65*0Sstevel@tonic-gate xdr_b_fattr(XDR *xdrs, fattr *objp)
66*0Sstevel@tonic-gate {
67*0Sstevel@tonic-gate 	if (!xdr_b_ftype(xdrs, &objp->type)) {
68*0Sstevel@tonic-gate 		return (FALSE);
69*0Sstevel@tonic-gate 	}
70*0Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->mode)) {
71*0Sstevel@tonic-gate 		return (FALSE);
72*0Sstevel@tonic-gate 	}
73*0Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->nlink)) {
74*0Sstevel@tonic-gate 		return (FALSE);
75*0Sstevel@tonic-gate 	}
76*0Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->uid)) {
77*0Sstevel@tonic-gate 		return (FALSE);
78*0Sstevel@tonic-gate 	}
79*0Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->gid)) {
80*0Sstevel@tonic-gate 		return (FALSE);
81*0Sstevel@tonic-gate 	}
82*0Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->size)) {
83*0Sstevel@tonic-gate 		return (FALSE);
84*0Sstevel@tonic-gate 	}
85*0Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->blocksize)) {
86*0Sstevel@tonic-gate 		return (FALSE);
87*0Sstevel@tonic-gate 	}
88*0Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->rdev)) {
89*0Sstevel@tonic-gate 		return (FALSE);
90*0Sstevel@tonic-gate 	}
91*0Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->blocks)) {
92*0Sstevel@tonic-gate 		return (FALSE);
93*0Sstevel@tonic-gate 	}
94*0Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->fsid)) {
95*0Sstevel@tonic-gate 		return (FALSE);
96*0Sstevel@tonic-gate 	}
97*0Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->fileid)) {
98*0Sstevel@tonic-gate 		return (FALSE);
99*0Sstevel@tonic-gate 	}
100*0Sstevel@tonic-gate 	if (!xdr_b_nfstime(xdrs, &objp->atime)) {
101*0Sstevel@tonic-gate 		return (FALSE);
102*0Sstevel@tonic-gate 	}
103*0Sstevel@tonic-gate 	if (!xdr_b_nfstime(xdrs, &objp->mtime)) {
104*0Sstevel@tonic-gate 		return (FALSE);
105*0Sstevel@tonic-gate 	}
106*0Sstevel@tonic-gate 	return (xdr_b_nfstime(xdrs, &objp->ctime));
107*0Sstevel@tonic-gate }
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate static bool_t
xdr_b_filename(XDR * xdrs,filename * objp)110*0Sstevel@tonic-gate xdr_b_filename(XDR *xdrs, filename *objp)
111*0Sstevel@tonic-gate {
112*0Sstevel@tonic-gate 	return (xdr_string(xdrs, objp, NFS_MAXNAMLEN));
113*0Sstevel@tonic-gate }
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate static bool_t
xdr_b_nfspath(XDR * xdrs,nfspath * objp)116*0Sstevel@tonic-gate xdr_b_nfspath(XDR *xdrs, nfspath *objp)
117*0Sstevel@tonic-gate {
118*0Sstevel@tonic-gate 	return (xdr_string(xdrs, objp, NFS_MAXPATHLEN));
119*0Sstevel@tonic-gate }
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate bool_t
xdr_attrstat(XDR * xdrs,attrstat * objp)122*0Sstevel@tonic-gate xdr_attrstat(XDR *xdrs, attrstat *objp)
123*0Sstevel@tonic-gate {
124*0Sstevel@tonic-gate 	if (!xdr_b_nfsstat(xdrs, &objp->status)) {
125*0Sstevel@tonic-gate 		return (FALSE);
126*0Sstevel@tonic-gate 	}
127*0Sstevel@tonic-gate 	if (objp->status == NFS_OK) {
128*0Sstevel@tonic-gate 		return (xdr_b_fattr(xdrs, &objp->attrstat_u.attributes));
129*0Sstevel@tonic-gate 	}
130*0Sstevel@tonic-gate 	return (TRUE);
131*0Sstevel@tonic-gate }
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate bool_t
xdr_diropargs(XDR * xdrs,diropargs * objp)134*0Sstevel@tonic-gate xdr_diropargs(XDR *xdrs, diropargs *objp)
135*0Sstevel@tonic-gate {
136*0Sstevel@tonic-gate 	if (!xdr_nfs_fh(xdrs, &objp->dir)) {
137*0Sstevel@tonic-gate 		return (FALSE);
138*0Sstevel@tonic-gate 	}
139*0Sstevel@tonic-gate 	return (xdr_b_filename(xdrs, &objp->name));
140*0Sstevel@tonic-gate }
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate static bool_t
xdr_b_diropokres(XDR * xdrs,diropokres * objp)143*0Sstevel@tonic-gate xdr_b_diropokres(XDR *xdrs, diropokres *objp)
144*0Sstevel@tonic-gate {
145*0Sstevel@tonic-gate 	if (!xdr_nfs_fh(xdrs, &objp->file)) {
146*0Sstevel@tonic-gate 		return (FALSE);
147*0Sstevel@tonic-gate 	}
148*0Sstevel@tonic-gate 	return (xdr_b_fattr(xdrs, &objp->attributes));
149*0Sstevel@tonic-gate }
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate bool_t
xdr_diropres(XDR * xdrs,diropres * objp)152*0Sstevel@tonic-gate xdr_diropres(XDR *xdrs, diropres *objp)
153*0Sstevel@tonic-gate {
154*0Sstevel@tonic-gate 	if (!xdr_b_nfsstat(xdrs, &objp->status)) {
155*0Sstevel@tonic-gate 		return (FALSE);
156*0Sstevel@tonic-gate 	}
157*0Sstevel@tonic-gate 	if (objp->status == NFS_OK) {
158*0Sstevel@tonic-gate 		return (xdr_b_diropokres(xdrs, &objp->diropres_u.diropres));
159*0Sstevel@tonic-gate 	}
160*0Sstevel@tonic-gate 	return (TRUE);
161*0Sstevel@tonic-gate }
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate bool_t
xdr_readlinkres(XDR * xdrs,readlinkres * objp)164*0Sstevel@tonic-gate xdr_readlinkres(XDR *xdrs, readlinkres *objp)
165*0Sstevel@tonic-gate {
166*0Sstevel@tonic-gate 	if (!xdr_b_nfsstat(xdrs, &objp->status)) {
167*0Sstevel@tonic-gate 		return (FALSE);
168*0Sstevel@tonic-gate 	}
169*0Sstevel@tonic-gate 	if (objp->status == NFS_OK) {
170*0Sstevel@tonic-gate 		return (xdr_b_nfspath(xdrs, &objp->readlinkres_u.data));
171*0Sstevel@tonic-gate 	}
172*0Sstevel@tonic-gate 	return (TRUE);
173*0Sstevel@tonic-gate }
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate bool_t
xdr_readargs(XDR * xdrs,readargs * objp)176*0Sstevel@tonic-gate xdr_readargs(XDR *xdrs, readargs *objp)
177*0Sstevel@tonic-gate {
178*0Sstevel@tonic-gate 	if (!xdr_nfs_fh(xdrs, &objp->file)) {
179*0Sstevel@tonic-gate 		return (FALSE);
180*0Sstevel@tonic-gate 	}
181*0Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->offset)) {
182*0Sstevel@tonic-gate 		return (FALSE);
183*0Sstevel@tonic-gate 	}
184*0Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->count)) {
185*0Sstevel@tonic-gate 		return (FALSE);
186*0Sstevel@tonic-gate 	}
187*0Sstevel@tonic-gate 	return (xdr_u_int(xdrs, &objp->totalcount));
188*0Sstevel@tonic-gate }
189*0Sstevel@tonic-gate 
190*0Sstevel@tonic-gate static bool_t
xdr_b_readokres(XDR * xdrs,readokres * objp)191*0Sstevel@tonic-gate xdr_b_readokres(XDR *xdrs, readokres *objp)
192*0Sstevel@tonic-gate {
193*0Sstevel@tonic-gate 	if (!xdr_b_fattr(xdrs, &objp->attributes)) {
194*0Sstevel@tonic-gate 		return (FALSE);
195*0Sstevel@tonic-gate 	}
196*0Sstevel@tonic-gate 	return (xdr_bytes(xdrs, (char **)&objp->data.data_val,
197*0Sstevel@tonic-gate 	    (uint_t *)&objp->data.data_len, NFS_MAXDATA));
198*0Sstevel@tonic-gate }
199*0Sstevel@tonic-gate 
200*0Sstevel@tonic-gate bool_t
xdr_readres(XDR * xdrs,readres * objp)201*0Sstevel@tonic-gate xdr_readres(XDR *xdrs, readres *objp)
202*0Sstevel@tonic-gate {
203*0Sstevel@tonic-gate 	if (!xdr_b_nfsstat(xdrs, &objp->status)) {
204*0Sstevel@tonic-gate 		return (FALSE);
205*0Sstevel@tonic-gate 	}
206*0Sstevel@tonic-gate 	if (objp->status == NFS_OK) {
207*0Sstevel@tonic-gate 		return (xdr_b_readokres(xdrs, &objp->readres_u.reply));
208*0Sstevel@tonic-gate 	}
209*0Sstevel@tonic-gate 	return (TRUE);
210*0Sstevel@tonic-gate }
211*0Sstevel@tonic-gate 
212*0Sstevel@tonic-gate static bool_t
xdr_b_nfscookie(XDR * xdrs,nfscookie objp)213*0Sstevel@tonic-gate xdr_b_nfscookie(XDR *xdrs, nfscookie objp)
214*0Sstevel@tonic-gate {
215*0Sstevel@tonic-gate 	return (xdr_opaque(xdrs, objp, NFS_COOKIESIZE));
216*0Sstevel@tonic-gate }
217*0Sstevel@tonic-gate 
218*0Sstevel@tonic-gate bool_t
xdr_readdirargs(XDR * xdrs,readdirargs * objp)219*0Sstevel@tonic-gate xdr_readdirargs(XDR *xdrs, readdirargs *objp)
220*0Sstevel@tonic-gate {
221*0Sstevel@tonic-gate 	if (!xdr_nfs_fh(xdrs, &objp->dir)) {
222*0Sstevel@tonic-gate 		return (FALSE);
223*0Sstevel@tonic-gate 	}
224*0Sstevel@tonic-gate 	if (!xdr_b_nfscookie(xdrs, objp->cookie)) {
225*0Sstevel@tonic-gate 		return (FALSE);
226*0Sstevel@tonic-gate 	}
227*0Sstevel@tonic-gate 	return (xdr_u_int(xdrs, &objp->count));
228*0Sstevel@tonic-gate }
229*0Sstevel@tonic-gate 
230*0Sstevel@tonic-gate static bool_t
xdr_b_entry(XDR * xdrs,entry * objp)231*0Sstevel@tonic-gate xdr_b_entry(XDR *xdrs, entry *objp)
232*0Sstevel@tonic-gate {
233*0Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &objp->fileid)) {
234*0Sstevel@tonic-gate 		return (FALSE);
235*0Sstevel@tonic-gate 	}
236*0Sstevel@tonic-gate 	if (!xdr_b_filename(xdrs, &objp->name)) {
237*0Sstevel@tonic-gate 		return (FALSE);
238*0Sstevel@tonic-gate 	}
239*0Sstevel@tonic-gate 	if (!xdr_b_nfscookie(xdrs, objp->cookie)) {
240*0Sstevel@tonic-gate 		return (FALSE);
241*0Sstevel@tonic-gate 	}
242*0Sstevel@tonic-gate 	return (xdr_pointer(xdrs, (char **)&objp->nextentry, sizeof (entry),
243*0Sstevel@tonic-gate 						(xdrproc_t)xdr_b_entry));
244*0Sstevel@tonic-gate }
245*0Sstevel@tonic-gate 
246*0Sstevel@tonic-gate static bool_t
xdr_b_dirlist(XDR * xdrs,dirlist * objp)247*0Sstevel@tonic-gate xdr_b_dirlist(XDR *xdrs, dirlist *objp)
248*0Sstevel@tonic-gate {
249*0Sstevel@tonic-gate 	if (!xdr_pointer(xdrs, (char **)&objp->entries, sizeof (entry),
250*0Sstevel@tonic-gate 	    (xdrproc_t)xdr_b_entry)) {
251*0Sstevel@tonic-gate 		return (FALSE);
252*0Sstevel@tonic-gate 	}
253*0Sstevel@tonic-gate 	return (xdr_bool(xdrs, &objp->eof));
254*0Sstevel@tonic-gate }
255*0Sstevel@tonic-gate 
256*0Sstevel@tonic-gate bool_t
xdr_readdirres(XDR * xdrs,readdirres * objp)257*0Sstevel@tonic-gate xdr_readdirres(XDR *xdrs, readdirres *objp)
258*0Sstevel@tonic-gate {
259*0Sstevel@tonic-gate 	if (!xdr_b_nfsstat(xdrs, &objp->status)) {
260*0Sstevel@tonic-gate 		return (FALSE);
261*0Sstevel@tonic-gate 	}
262*0Sstevel@tonic-gate 	if (objp->status == NFS_OK) {
263*0Sstevel@tonic-gate 		return (xdr_b_dirlist(xdrs, &objp->readdirres_u.reply));
264*0Sstevel@tonic-gate 	}
265*0Sstevel@tonic-gate 	return (TRUE);
266*0Sstevel@tonic-gate }
267