4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
24 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
29 * This file can not be automatically generated by rpcgen from
30 * autofs_prot.x because of the xdr routines that provide readdir
31 * support, and my own implementation of xdr_autofs_netbuf().
35 #include <sys/sysmacros.h> /* includes roundup() */
37 #include <rpcsvc/autofs_prot.h>
39 #include <rpcsvc/nfs4_prot.h>
45 xdr_autofs_stat(register XDR
*xdrs
, autofs_stat
*objp
)
47 if (!xdr_enum(xdrs
, (enum_t
*)objp
))
53 xdr_autofs_action(register XDR
*xdrs
, autofs_action
*objp
)
55 if (!xdr_enum(xdrs
, (enum_t
*)objp
))
61 xdr_linka(register XDR
*xdrs
, linka
*objp
)
63 if (!xdr_string(xdrs
, &objp
->dir
, AUTOFS_MAXPATHLEN
))
65 if (!xdr_string(xdrs
, &objp
->link
, AUTOFS_MAXPATHLEN
))
71 xdr_autofs_netbuf(xdrs
, objp
)
77 if (!xdr_u_int(xdrs
, &objp
->maxlen
)) {
80 dummy
= xdr_bytes(xdrs
, (char **)&(objp
->buf
),
81 (uint_t
*)&(objp
->len
), objp
->maxlen
);
86 xdr_autofs_args(register XDR
*xdrs
, autofs_args
*objp
)
88 if (!xdr_autofs_netbuf(xdrs
, &objp
->addr
))
90 if (!xdr_string(xdrs
, &objp
->path
, AUTOFS_MAXPATHLEN
))
92 if (!xdr_string(xdrs
, &objp
->opts
, AUTOFS_MAXOPTSLEN
))
94 if (!xdr_string(xdrs
, &objp
->map
, AUTOFS_MAXPATHLEN
))
96 if (!xdr_string(xdrs
, &objp
->subdir
, AUTOFS_MAXPATHLEN
))
98 if (!xdr_string(xdrs
, &objp
->key
, AUTOFS_MAXCOMPONENTLEN
))
100 if (!xdr_int(xdrs
, &objp
->mount_to
))
102 if (!xdr_int(xdrs
, &objp
->rpc_to
))
104 if (!xdr_int(xdrs
, &objp
->direct
))
110 xdr_mounta(register XDR
*xdrs
, struct mounta
*objp
)
112 if (!xdr_string(xdrs
, &objp
->spec
, AUTOFS_MAXPATHLEN
))
114 if (!xdr_string(xdrs
, &objp
->dir
, AUTOFS_MAXPATHLEN
))
116 if (!xdr_int(xdrs
, &objp
->flags
))
118 if (!xdr_string(xdrs
, &objp
->fstype
, AUTOFS_MAXCOMPONENTLEN
))
120 if (!xdr_pointer(xdrs
, (char **)&objp
->dataptr
, sizeof (autofs_args
),
121 (xdrproc_t
)xdr_autofs_args
))
123 if (!xdr_int(xdrs
, &objp
->datalen
))
125 if (!xdr_string(xdrs
, &objp
->optptr
, AUTOFS_MAXOPTSLEN
))
127 if (!xdr_int(xdrs
, &objp
->optlen
))
133 xdr_action_list_entry(register XDR
*xdrs
, action_list_entry
*objp
)
135 if (!xdr_autofs_action(xdrs
, &objp
->action
))
137 switch (objp
->action
) {
138 case AUTOFS_MOUNT_RQ
:
139 if (!xdr_mounta(xdrs
, &objp
->action_list_entry_u
.mounta
))
143 if (!xdr_linka(xdrs
, &objp
->action_list_entry_u
.linka
))
151 xdr_action_list(XDR
*xdrs
, action_list
*objp
)
153 action_list
*tmp_action_list
;
154 bool_t more_data
= TRUE
;
155 bool_t first_objp
= TRUE
;
157 if (xdrs
->x_op
== XDR_DECODE
) {
159 if (!xdr_action_list_entry(xdrs
, &objp
->action
))
161 if (!xdr_bool(xdrs
, &more_data
))
167 if (objp
->next
== NULL
) {
168 objp
->next
= (action_list
*)
169 mem_alloc(sizeof (action_list
));
170 if (objp
->next
== NULL
)
172 bzero(objp
->next
, sizeof (action_list
));
176 } else if (xdrs
->x_op
== XDR_ENCODE
) {
178 if (!xdr_action_list_entry(xdrs
, &objp
->action
))
183 if (!xdr_bool(xdrs
, &more_data
))
188 if (!xdr_action_list_entry(xdrs
, &objp
->action
))
190 tmp_action_list
= objp
;
195 mem_free(tmp_action_list
, sizeof (action_list
));
204 xdr_umntrequest(register XDR
*xdrs
, umntrequest
*objp
)
206 if (!xdr_bool_t(xdrs
, &objp
->isdirect
))
208 if (!xdr_string(xdrs
, &objp
->mntresource
, AUTOFS_MAXPATHLEN
))
210 if (!xdr_string(xdrs
, &objp
->mntpnt
, AUTOFS_MAXPATHLEN
))
212 if (!xdr_string(xdrs
, &objp
->fstype
, AUTOFS_MAXCOMPONENTLEN
))
214 if (!xdr_string(xdrs
, &objp
->mntopts
, AUTOFS_MAXOPTSLEN
))
216 if (!xdr_pointer(xdrs
, (char **)&objp
->next
, sizeof (umntrequest
),
217 (xdrproc_t
)xdr_umntrequest
))
223 xdr_umntres(register XDR
*xdrs
, umntres
*objp
)
225 if (!xdr_int(xdrs
, &objp
->status
))
231 xdr_autofs_res(xdrs
, objp
)
235 if (!xdr_enum(xdrs
, (enum_t
*)objp
))
241 xdr_autofs_lookupargs(xdrs
, objp
)
243 autofs_lookupargs
*objp
;
245 if (!xdr_string(xdrs
, &objp
->map
, AUTOFS_MAXPATHLEN
))
247 if (!xdr_string(xdrs
, &objp
->path
, AUTOFS_MAXPATHLEN
))
249 if (!xdr_string(xdrs
, &objp
->name
, AUTOFS_MAXCOMPONENTLEN
))
251 if (!xdr_string(xdrs
, &objp
->subdir
, AUTOFS_MAXPATHLEN
))
253 if (!xdr_string(xdrs
, &objp
->opts
, AUTOFS_MAXOPTSLEN
))
255 if (!xdr_bool_t(xdrs
, &objp
->isdirect
))
257 if (!xdr_u_int(xdrs
, (uint_t
*)&objp
->uid
))
263 xdr_mount_result_type(xdrs
, objp
)
265 mount_result_type
*objp
;
267 if (!xdr_autofs_stat(xdrs
, &objp
->status
))
269 switch (objp
->status
) {
271 if (!xdr_pointer(xdrs
,
272 (char **)&objp
->mount_result_type_u
.list
,
273 sizeof (action_list
), (xdrproc_t
)xdr_action_list
))
277 if (!xdr_int(xdrs
, &objp
->mount_result_type_u
.error
))
285 xdr_autofs_mountres(xdrs
, objp
)
287 autofs_mountres
*objp
;
289 if (!xdr_mount_result_type(xdrs
, &objp
->mr_type
))
291 if (!xdr_int(xdrs
, &objp
->mr_verbose
))
296 xdr_lookup_result_type(xdrs
, objp
)
298 lookup_result_type
*objp
;
300 if (!xdr_autofs_action(xdrs
, &objp
->action
))
302 switch (objp
->action
) {
304 if (!xdr_linka(xdrs
, &objp
->lookup_result_type_u
.lt_linka
))
312 xdr_autofs_lookupres(xdrs
, objp
)
314 autofs_lookupres
*objp
;
316 if (!xdr_autofs_res(xdrs
, &objp
->lu_res
))
318 if (!xdr_lookup_result_type(xdrs
, &objp
->lu_type
))
320 if (!xdr_int(xdrs
, &objp
->lu_verbose
))
326 * ******************************************************
327 * Readdir XDR support
328 * ******************************************************
332 xdr_autofs_rddirargs(xdrs
, objp
)
334 autofs_rddirargs
*objp
;
336 if (!xdr_string(xdrs
, &objp
->rda_map
, AUTOFS_MAXPATHLEN
))
338 if (!xdr_u_int(xdrs
, &objp
->rda_offset
))
340 if (!xdr_u_int(xdrs
, &objp
->rda_count
))
342 if (!xdr_u_int(xdrs
, (uint_t
*)&objp
->uid
))
348 * Directory read reply:
349 * union (enum autofs_res) {
350 * AUTOFS_OK: entlist;
357 * off_t d_off; * offset of next entry *
358 * u_long d_fileno; * inode number of entry *
359 * u_short d_reclen; * length of this record *
360 * u_short d_namlen; * length of string in d_name *
361 * char d_name[MAXNAMLEN + 1]; * name no longer than this *
363 * are on the wire as:
364 * union entlist (boolean valid) {
365 * TRUE: struct otw_dirent;
370 * where otw_dirent is:
373 * string de_name<AUTOFS_MAXPATHLEN>;
380 #define nextdp(dp) ((struct dirent64 *)((char *)(dp) + (dp)->d_reclen))
386 xdr_autofs_putrddirres(xdrs
, rddir
, reqsize
)
388 struct autofsrddir
*rddir
;
389 uint_t reqsize
; /* requested size */
402 bufsize
= 1 * BYTES_PER_XDR_UNIT
;
403 for (size
= rddir
->rddir_size
, dp
= rddir
->rddir_entries
;
405 /* LINTED pointer alignment */
406 size
-= dp
->d_reclen
, dp
= nextdp(dp
)) {
407 if (dp
->d_reclen
== 0 /* || DIRSIZ(dp) > dp->d_reclen */) {
410 if (dp
->d_ino
== 0) {
414 namlen
= strlen(name
);
415 ino
= (uint_t
)dp
->d_ino
;
416 off
= (uint_t
)dp
->d_off
;
417 entrysz
= (1 + 1 + 1 + 1) * BYTES_PER_XDR_UNIT
+
418 roundup(namlen
, BYTES_PER_XDR_UNIT
);
419 tofit
= entrysz
+ 2 * BYTES_PER_XDR_UNIT
;
420 if (bufsize
+ tofit
> reqsize
) {
421 rddir
->rddir_eof
= FALSE
;
424 if (!xdr_bool(xdrs
, &t
) ||
425 !xdr_u_int(xdrs
, &ino
) ||
426 !xdr_bytes(xdrs
, &name
, &namlen
, AUTOFS_MAXPATHLEN
) ||
427 !xdr_u_int(xdrs
, &off
)) {
432 if (!xdr_bool(xdrs
, &f
)) {
435 if (!xdr_bool(xdrs
, &rddir
->rddir_eof
)) {
441 #define DIRENT64_RECLEN(namelen) \
442 (((int)(((dirent64_t *)0)->d_name) + 1 + (namelen) + 7) & ~ 7)
443 #define reclen(namlen) DIRENT64_RECLEN((namlen))
449 xdr_autofs_getrddirres(xdrs
, rddir
)
451 struct autofsrddir
*rddir
;
460 size
= rddir
->rddir_size
;
461 dp
= rddir
->rddir_entries
;
463 if (!xdr_bool(xdrs
, &valid
)) {
469 if (!xdr_u_int(xdrs
, &fileid
) ||
470 !xdr_u_int(xdrs
, &namlen
)) {
473 if (reclen(namlen
) > size
) {
474 rddir
->rddir_eof
= FALSE
;
477 if (!xdr_opaque(xdrs
, dp
->d_name
, namlen
)||
478 !xdr_int(xdrs
, &offset
)) {
482 dp
->d_reclen
= reclen(namlen
);
483 dp
->d_name
[namlen
] = '\0';
485 size
-= dp
->d_reclen
;
486 /* LINTED pointer alignment */
489 if (!xdr_bool(xdrs
, &rddir
->rddir_eof
)) {
493 rddir
->rddir_size
= (char *)dp
- (char *)(rddir
->rddir_entries
);
494 rddir
->rddir_offset
= offset
;
499 xdr_autofs_rddirres(register XDR
*xdrs
, autofs_rddirres
*objp
)
501 if (!xdr_enum(xdrs
, (enum_t
*)&objp
->rd_status
))
503 if (objp
->rd_status
!= AUTOFS_OK
)
505 if (xdrs
->x_op
== XDR_ENCODE
)
506 return (xdr_autofs_putrddirres(
507 xdrs
, (struct autofsrddir
*)&objp
->rd_rddir
,
509 else if (xdrs
->x_op
== XDR_DECODE
)
510 return (xdr_autofs_getrddirres(xdrs
,
511 (struct autofsrddir
*)&objp
->rd_rddir
));