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]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * This file can not be automatically generated by rpcgen from
28 * autofs_prot.x because of the xdr routines that provide readdir
29 * support, its own implementation of xdr_autofs_netbuf(). rpcgen will
30 * also generate xdr routines with recursion which should not be used
34 #include <sys/param.h>
36 #include <sys/errno.h>
39 #include <sys/vnode.h>
40 #include <sys/pathname.h>
42 #include <sys/mount.h>
43 #include <sys/cmn_err.h>
44 #include <sys/debug.h>
45 #include <sys/systm.h>
46 #include <rpc/types.h>
50 #include <sys/ticotsord.h>
51 #include <sys/dirent.h>
52 #include <sys/sysmacros.h>
53 #include <sys/fs_subr.h>
54 #include <sys/fs/autofs.h>
56 bool_t
xdr_autofs_netbuf(XDR
*, struct netbuf
*);
57 bool_t
xdr_mounta(XDR
*, struct mounta
*);
60 xdr_umntrequest(XDR
*xdrs
, umntrequest
*objp
)
64 ASSERT(xdrs
->x_op
== XDR_ENCODE
);
66 for (; objp
!= NULL
; objp
= objp
->next
) {
67 if (!xdr_bool_t(xdrs
, &objp
->isdirect
))
69 if (!xdr_string(xdrs
, &objp
->mntresource
, AUTOFS_MAXPATHLEN
))
71 if (!xdr_string(xdrs
, &objp
->mntpnt
, AUTOFS_MAXPATHLEN
))
73 if (!xdr_string(xdrs
, &objp
->fstype
, AUTOFS_MAXCOMPONENTLEN
))
75 if (!xdr_string(xdrs
, &objp
->mntopts
, AUTOFS_MAXOPTSLEN
))
78 if (objp
->next
!= NULL
)
83 if (!xdr_bool(xdrs
, &more_data
))
90 xdr_umntres(XDR
*xdrs
, umntres
*objp
)
92 return (xdr_int(xdrs
, &objp
->status
));
96 xdr_autofs_stat(XDR
*xdrs
, autofs_stat
*objp
)
98 if (!xdr_enum(xdrs
, (enum_t
*)objp
))
104 xdr_autofs_action(XDR
*xdrs
, autofs_action
*objp
)
106 if (!xdr_enum(xdrs
, (enum_t
*)objp
))
112 xdr_linka(XDR
*xdrs
, linka
*objp
)
114 if (!xdr_string(xdrs
, &objp
->dir
, AUTOFS_MAXPATHLEN
))
116 if (!xdr_string(xdrs
, &objp
->link
, AUTOFS_MAXPATHLEN
))
122 xdr_autofs_args(XDR
*xdrs
, autofs_args
*objp
)
124 if (!xdr_autofs_netbuf(xdrs
, &objp
->addr
))
126 if (!xdr_string(xdrs
, &objp
->path
, AUTOFS_MAXPATHLEN
))
128 if (!xdr_string(xdrs
, &objp
->opts
, AUTOFS_MAXOPTSLEN
))
130 if (!xdr_string(xdrs
, &objp
->map
, AUTOFS_MAXPATHLEN
))
132 if (!xdr_string(xdrs
, &objp
->subdir
, AUTOFS_MAXPATHLEN
))
134 if (!xdr_string(xdrs
, &objp
->key
, AUTOFS_MAXCOMPONENTLEN
))
136 if (!xdr_int(xdrs
, &objp
->mount_to
))
138 if (!xdr_int(xdrs
, &objp
->rpc_to
))
140 if (!xdr_int(xdrs
, &objp
->direct
))
146 xdr_action_list_entry(XDR
*xdrs
, action_list_entry
*objp
)
148 if (!xdr_autofs_action(xdrs
, &objp
->action
))
150 switch (objp
->action
) {
151 case AUTOFS_MOUNT_RQ
:
152 if (!xdr_mounta(xdrs
, &objp
->action_list_entry_u
.mounta
))
156 if (!xdr_linka(xdrs
, &objp
->action_list_entry_u
.linka
))
166 xdr_action_list(XDR
*xdrs
, action_list
*objp
)
168 bool_t more_data
= TRUE
;
169 bool_t status
= TRUE
;
170 action_list
*p
, *last
;
172 ASSERT((xdrs
->x_op
== XDR_DECODE
) || (xdrs
->x_op
== XDR_FREE
));
174 more_data
= (objp
!= NULL
);
177 if (xdrs
->x_op
== XDR_FREE
) {
179 if (!xdr_action_list_entry(xdrs
, &p
->action
))
180 cmn_err(CE_WARN
, "xdr_action_list: "
181 "action_list_entry free failed %p\n",
185 kmem_free(last
, sizeof (*last
));
191 if (!xdr_action_list_entry(xdrs
, &p
->action
)) {
196 if (!xdr_bool(xdrs
, &more_data
)) {
202 p
->next
= kmem_zalloc(sizeof (action_list
), KM_SLEEP
);
215 xdr_autofs_netbuf(XDR
*xdrs
, struct netbuf
*objp
)
219 if (!xdr_u_int(xdrs
, (uint_t
*)&objp
->maxlen
))
221 dummy
= xdr_bytes(xdrs
, (char **)&(objp
->buf
),
222 (uint_t
*)&(objp
->len
), objp
->maxlen
);
227 xdr_mounta(XDR
*xdrs
, struct mounta
*objp
)
229 if (!xdr_string(xdrs
, &objp
->spec
, AUTOFS_MAXPATHLEN
))
231 if (!xdr_string(xdrs
, &objp
->dir
, AUTOFS_MAXPATHLEN
))
233 if (!xdr_int(xdrs
, &objp
->flags
))
235 if (!xdr_string(xdrs
, &objp
->fstype
, AUTOFS_MAXCOMPONENTLEN
))
237 if (!xdr_pointer(xdrs
, (char **)&objp
->dataptr
, sizeof (autofs_args
),
238 (xdrproc_t
)xdr_autofs_args
))
241 * The length is the original user-land length, not the
242 * length of the native kernel autofs_args structure provided
243 * after we decode the xdr buffer. So passing the user's idea of
244 * the length is wrong and we need to stuff the length field with
245 * the length of the native structure.
247 if (!xdr_int(xdrs
, &objp
->datalen
))
249 if (xdrs
->x_op
== XDR_DECODE
)
250 objp
->datalen
= sizeof (struct autofs_args
);
251 if (!xdr_string(xdrs
, &objp
->optptr
, AUTOFS_MAXOPTSLEN
))
253 if (!xdr_int(xdrs
, &objp
->optlen
))
255 ASSERT((xdrs
->x_op
== XDR_DECODE
) || (xdrs
->x_op
== XDR_FREE
));
260 xdr_autofs_res(XDR
*xdrs
, autofs_res
*objp
)
262 if (!xdr_enum(xdrs
, (enum_t
*)objp
))
268 xdr_autofs_lookupargs(XDR
*xdrs
, autofs_lookupargs
*objp
)
270 if (!xdr_string(xdrs
, &objp
->map
, AUTOFS_MAXPATHLEN
))
272 if (!xdr_string(xdrs
, &objp
->path
, AUTOFS_MAXPATHLEN
))
274 if (!xdr_string(xdrs
, &objp
->name
, AUTOFS_MAXCOMPONENTLEN
))
276 if (!xdr_string(xdrs
, &objp
->subdir
, AUTOFS_MAXPATHLEN
))
278 if (!xdr_string(xdrs
, &objp
->opts
, AUTOFS_MAXOPTSLEN
))
280 if (!xdr_bool_t(xdrs
, &objp
->isdirect
))
282 if (!xdr_u_int(xdrs
, (uint_t
*)&objp
->uid
))
288 xdr_mount_result_type(XDR
*xdrs
, mount_result_type
*objp
)
290 if (!xdr_autofs_stat(xdrs
, &objp
->status
))
292 switch (objp
->status
) {
294 if (!xdr_pointer(xdrs
,
295 (char **)&objp
->mount_result_type_u
.list
,
296 sizeof (action_list
), (xdrproc_t
)xdr_action_list
))
300 if (!xdr_int(xdrs
, &objp
->mount_result_type_u
.error
))
308 xdr_autofs_mountres(XDR
*xdrs
, autofs_mountres
*objp
)
310 if (!xdr_mount_result_type(xdrs
, &objp
->mr_type
))
312 if (!xdr_int(xdrs
, &objp
->mr_verbose
))
318 xdr_lookup_result_type(XDR
*xdrs
, lookup_result_type
*objp
)
320 if (!xdr_autofs_action(xdrs
, &objp
->action
))
322 switch (objp
->action
) {
324 if (!xdr_linka(xdrs
, &objp
->lookup_result_type_u
.lt_linka
))
334 xdr_autofs_lookupres(XDR
*xdrs
, autofs_lookupres
*objp
)
336 if (!xdr_autofs_res(xdrs
, &objp
->lu_res
))
338 if (!xdr_lookup_result_type(xdrs
, &objp
->lu_type
))
340 if (!xdr_int(xdrs
, &objp
->lu_verbose
))
346 xdr_autofs_rddirargs(XDR
*xdrs
, autofs_rddirargs
*objp
)
348 if (!xdr_string(xdrs
, &objp
->rda_map
, AUTOFS_MAXPATHLEN
))
350 if (!xdr_u_int(xdrs
, &objp
->rda_offset
))
352 if (!xdr_u_int(xdrs
, &objp
->rda_count
))
354 if (!xdr_u_int(xdrs
, (uint_t
*)&objp
->uid
))
360 * Directory read reply:
361 * union (enum autofs_res) {
362 * AUTOFS_OK: entlist;
369 * off_t d_off; * offset of next entry *
370 * u_long d_fileno; * inode number of entry *
371 * ushort_t d_reclen; * length of this record *
372 * ushort_t d_namlen; * length of string in d_name *
373 * char d_name[MAXNAMLEN + 1]; * name no longer than this *
375 * are on the wire as:
376 * union entlist (boolean valid) {
377 * TRUE: struct otw_dirent;
382 * where otw_dirent is:
385 * string de_name<AUTOFS_MAXPATHLEN>;
392 #define nextdp(dp) ((struct dirent *)((char *)(dp) + (dp)->d_reclen))
398 xdr_autofs_putrddirres(XDR
*xdrs
, struct autofsrddir
*rddir
, uint_t reqsize
)
411 bufsize
= 1 * BYTES_PER_XDR_UNIT
;
412 for (size
= rddir
->rddir_size
, dp
= rddir
->rddir_entries
;
414 /* LINTED pointer alignment */
415 size
-= dp
->d_reclen
, dp
= nextdp(dp
)) {
416 if (dp
->d_reclen
== 0 /* || DIRSIZ(dp) > dp->d_reclen */)
421 namlen
= (uint_t
)strlen(name
);
422 ino
= (uint_t
)dp
->d_ino
;
423 off
= (uint_t
)dp
->d_off
;
424 entrysz
= (1 + 1 + 1 + 1) * BYTES_PER_XDR_UNIT
+
425 roundup(namlen
, BYTES_PER_XDR_UNIT
);
426 tofit
= entrysz
+ 2 * BYTES_PER_XDR_UNIT
;
427 if (bufsize
+ tofit
> reqsize
) {
428 rddir
->rddir_eof
= FALSE
;
431 if (!xdr_bool(xdrs
, &t
) ||
432 !xdr_u_int(xdrs
, &ino
) ||
433 !xdr_bytes(xdrs
, &name
, &namlen
, AUTOFS_MAXPATHLEN
) ||
434 !xdr_u_int(xdrs
, &off
)) {
439 if (!xdr_bool(xdrs
, &f
))
441 if (!xdr_bool(xdrs
, &rddir
->rddir_eof
))
451 xdr_autofs_getrddirres(XDR
*xdrs
, struct autofsrddir
*rddir
)
462 size
= rddir
->rddir_size
;
463 dp
= rddir
->rddir_entries
;
465 if (!xdr_bool(xdrs
, &valid
))
469 if (!xdr_u_int(xdrs
, &fileid
) ||
470 !xdr_u_int(xdrs
, &namlen
))
472 if (DIRENT_RECLEN(namlen
) > size
) {
473 rddir
->rddir_eof
= FALSE
;
476 if (!xdr_opaque(xdrs
, dp
->d_name
, namlen
)||
477 !xdr_u_int(xdrs
, &offset
))
480 dp
->d_reclen
= (ushort_t
)DIRENT_RECLEN(namlen
);
481 bzero(&dp
->d_name
[namlen
],
482 DIRENT_NAMELEN(dp
->d_reclen
) - namlen
);
484 size
-= dp
->d_reclen
;
485 /* LINTED pointer alignment */
488 if (!xdr_bool(xdrs
, &rddir
->rddir_eof
))
491 rddir
->rddir_size
= (uint_t
)((char *)dp
- (char *)rddir
->rddir_entries
);
492 rddir
->rddir_offset
= offset
;
497 xdr_autofs_rddirres(XDR
*xdrs
, autofs_rddirres
*objp
)
499 if (!xdr_enum(xdrs
, (enum_t
*)&objp
->rd_status
))
501 if (objp
->rd_status
!= AUTOFS_OK
)
503 if (xdrs
->x_op
== XDR_ENCODE
)
504 return (xdr_autofs_putrddirres(xdrs
,
505 (struct autofsrddir
*)&objp
->rd_rddir
, objp
->rd_bufsize
));
506 else if (xdrs
->x_op
== XDR_DECODE
)
507 return (xdr_autofs_getrddirres(xdrs
,
508 (struct autofsrddir
*)&objp
->rd_rddir
));