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