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