xref: /netbsd-src/external/bsd/am-utils/dist/amd/amq_subr.c (revision deb1251144d8c1c3a96d519fe988af9b92f12e03)
1*deb12511Schristos /*	$NetBSD: amq_subr.c,v 1.5 2022/08/24 05:01:13 christos Exp $	*/
2a53f50b9Schristos 
3a53f50b9Schristos /*
48bae5d40Schristos  * Copyright (c) 1997-2014 Erez Zadok
5a53f50b9Schristos  * Copyright (c) 1990 Jan-Simon Pendry
6a53f50b9Schristos  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
7a53f50b9Schristos  * Copyright (c) 1990 The Regents of the University of California.
8a53f50b9Schristos  * All rights reserved.
9a53f50b9Schristos  *
10a53f50b9Schristos  * This code is derived from software contributed to Berkeley by
11a53f50b9Schristos  * Jan-Simon Pendry at Imperial College, London.
12a53f50b9Schristos  *
13a53f50b9Schristos  * Redistribution and use in source and binary forms, with or without
14a53f50b9Schristos  * modification, are permitted provided that the following conditions
15a53f50b9Schristos  * are met:
16a53f50b9Schristos  * 1. Redistributions of source code must retain the above copyright
17a53f50b9Schristos  *    notice, this list of conditions and the following disclaimer.
18a53f50b9Schristos  * 2. Redistributions in binary form must reproduce the above copyright
19a53f50b9Schristos  *    notice, this list of conditions and the following disclaimer in the
20a53f50b9Schristos  *    documentation and/or other materials provided with the distribution.
218bae5d40Schristos  * 3. Neither the name of the University nor the names of its contributors
22a53f50b9Schristos  *    may be used to endorse or promote products derived from this software
23a53f50b9Schristos  *    without specific prior written permission.
24a53f50b9Schristos  *
25a53f50b9Schristos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26a53f50b9Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27a53f50b9Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28a53f50b9Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29a53f50b9Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30a53f50b9Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31a53f50b9Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32a53f50b9Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33a53f50b9Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34a53f50b9Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35a53f50b9Schristos  * SUCH DAMAGE.
36a53f50b9Schristos  *
37a53f50b9Schristos  *
38a53f50b9Schristos  * File: am-utils/amd/amq_subr.c
39a53f50b9Schristos  *
40a53f50b9Schristos  */
41a53f50b9Schristos /*
42a53f50b9Schristos  * Auxiliary routines for amq tool
43a53f50b9Schristos  */
44a53f50b9Schristos 
45a53f50b9Schristos #ifdef HAVE_CONFIG_H
46a53f50b9Schristos # include <config.h>
47a53f50b9Schristos #endif /* HAVE_CONFIG_H */
48a53f50b9Schristos #include <am_defs.h>
49a53f50b9Schristos #include <amd.h>
50a53f50b9Schristos 
51a53f50b9Schristos /* forward definitions */
52a53f50b9Schristos bool_t xdr_amq_mount_tree_node(XDR *xdrs, amq_mount_tree *objp);
53a53f50b9Schristos bool_t xdr_amq_mount_subtree(XDR *xdrs, amq_mount_tree *objp);
54a53f50b9Schristos 
55a53f50b9Schristos 
56a53f50b9Schristos voidp
amqproc_null_1_svc(voidp argp,struct svc_req * rqstp)57a53f50b9Schristos amqproc_null_1_svc(voidp argp, struct svc_req *rqstp)
58a53f50b9Schristos {
59a53f50b9Schristos   static char res;
60a53f50b9Schristos 
61a53f50b9Schristos   return (voidp) &res;
62a53f50b9Schristos }
63a53f50b9Schristos 
64a53f50b9Schristos 
65a53f50b9Schristos /*
66a53f50b9Schristos  * Return a sub-tree of mounts
67a53f50b9Schristos  */
68a53f50b9Schristos amq_mount_tree_p *
amqproc_mnttree_1_svc(voidp argp,struct svc_req * rqstp)69a53f50b9Schristos amqproc_mnttree_1_svc(voidp argp, struct svc_req *rqstp)
70a53f50b9Schristos {
71a53f50b9Schristos   static am_node *mp;
72a53f50b9Schristos 
73a53f50b9Schristos   mp = find_ap(*(char **) argp);
74a53f50b9Schristos   return (amq_mount_tree_p *) ((void *)&mp);
75a53f50b9Schristos }
76a53f50b9Schristos 
77a53f50b9Schristos 
78a53f50b9Schristos /*
79a53f50b9Schristos  * Unmount a single node
80a53f50b9Schristos  */
814bcd344eSchristos int *
amqproc_umnt_1_svc(voidp argp,struct svc_req * rqstp)82a53f50b9Schristos amqproc_umnt_1_svc(voidp argp, struct svc_req *rqstp)
83a53f50b9Schristos {
844bcd344eSchristos   static int res = AMQ_UMNT_OK;
85a53f50b9Schristos   am_node *mp = find_ap(*(char **) argp);
86a53f50b9Schristos 
87a53f50b9Schristos   if (mp)
88a53f50b9Schristos     forcibly_timeout_mp(mp);
89a53f50b9Schristos 
904bcd344eSchristos   return &res;
914bcd344eSchristos }
924bcd344eSchristos 
934bcd344eSchristos 
944bcd344eSchristos /*
954bcd344eSchristos  * Synchronously unmount a single node - parent side.
964bcd344eSchristos  */
974bcd344eSchristos int *
amqproc_sync_umnt_1_svc_parent(voidp argp,struct svc_req * rqstp)984bcd344eSchristos amqproc_sync_umnt_1_svc_parent(voidp argp, struct svc_req *rqstp)
994bcd344eSchristos {
1004bcd344eSchristos   amqproc_umnt_1_svc(argp, rqstp);
1014bcd344eSchristos   return NULL;
1024bcd344eSchristos }
1034bcd344eSchristos 
1044bcd344eSchristos 
1054bcd344eSchristos /*
1064bcd344eSchristos  * Synchronously unmount a single node - child side.
1074bcd344eSchristos  */
1084bcd344eSchristos amq_sync_umnt *
amqproc_sync_umnt_1_svc_child(voidp argp,struct svc_req * rqstp)1094bcd344eSchristos amqproc_sync_umnt_1_svc_child(voidp argp, struct svc_req *rqstp)
1104bcd344eSchristos {
1114bcd344eSchristos   static amq_sync_umnt rv;
1124bcd344eSchristos   amq_sync_umnt buf;
1134bcd344eSchristos   ssize_t n;
1144bcd344eSchristos 
1154bcd344eSchristos   am_node *mp = find_ap(*(char **) argp);
1164bcd344eSchristos 
1174bcd344eSchristos   memset(&rv, 0, sizeof(rv));
1184bcd344eSchristos   rv.au_etype = AMQ_UMNT_READ;
1194bcd344eSchristos   if (mp && mp->am_fd[0] >= 0) {
1204bcd344eSchristos     n = read(mp->am_fd[0], &buf, sizeof(buf));
1214bcd344eSchristos     if (n == sizeof(buf))
1224bcd344eSchristos       rv = buf;
1234bcd344eSchristos   }
1244bcd344eSchristos   return &rv;
1254bcd344eSchristos }
1264bcd344eSchristos 
1274bcd344eSchristos 
1284bcd344eSchristos /*
1294bcd344eSchristos  * Synchronously unmount a single node - use if we can't fork (asynchronous).
1304bcd344eSchristos  */
1314bcd344eSchristos amq_sync_umnt *
amqproc_sync_umnt_1_svc_async(voidp argp,struct svc_req * rqstp)1324bcd344eSchristos amqproc_sync_umnt_1_svc_async(voidp argp, struct svc_req *rqstp)
1334bcd344eSchristos {
1344bcd344eSchristos   static amq_sync_umnt rv;
1354bcd344eSchristos 
1364bcd344eSchristos   memset(&rv, 0, sizeof(rv));
1374bcd344eSchristos   rv.au_etype = AMQ_UMNT_FORK;
1384bcd344eSchristos   rv.au_errno = errno;
1394bcd344eSchristos 
1404bcd344eSchristos   amqproc_umnt_1_svc(argp, rqstp);
1414bcd344eSchristos 
1424bcd344eSchristos   return &rv;
143a53f50b9Schristos }
144a53f50b9Schristos 
145a53f50b9Schristos 
146a53f50b9Schristos /*
147a53f50b9Schristos  * Return global statistics
148a53f50b9Schristos  */
149a53f50b9Schristos amq_mount_stats *
amqproc_stats_1_svc(voidp argp,struct svc_req * rqstp)150a53f50b9Schristos amqproc_stats_1_svc(voidp argp, struct svc_req *rqstp)
151a53f50b9Schristos {
152a53f50b9Schristos   return (amq_mount_stats *) ((void *)&amd_stats);
153a53f50b9Schristos }
154a53f50b9Schristos 
155a53f50b9Schristos 
156a53f50b9Schristos /*
157a53f50b9Schristos  * Return the entire tree of mount nodes
158a53f50b9Schristos  */
159a53f50b9Schristos amq_mount_tree_list *
amqproc_export_1_svc(voidp argp,struct svc_req * rqstp)160a53f50b9Schristos amqproc_export_1_svc(voidp argp, struct svc_req *rqstp)
161a53f50b9Schristos {
162a53f50b9Schristos   static amq_mount_tree_list aml;
163a53f50b9Schristos   static am_node *mp;
164a53f50b9Schristos 
165a53f50b9Schristos   mp = get_exported_ap(0);
166a53f50b9Schristos   aml.amq_mount_tree_list_val = (amq_mount_tree_p *) ((void *) &mp);
167a53f50b9Schristos   aml.amq_mount_tree_list_len = 1;	/* XXX */
168a53f50b9Schristos 
169a53f50b9Schristos   return &aml;
170a53f50b9Schristos }
171a53f50b9Schristos 
172a53f50b9Schristos 
173a53f50b9Schristos int *
amqproc_setopt_1_svc(voidp argp,struct svc_req * rqstp)174a53f50b9Schristos amqproc_setopt_1_svc(voidp argp, struct svc_req *rqstp)
175a53f50b9Schristos {
176a53f50b9Schristos   static int rc;
177a53f50b9Schristos   amq_setopt *opt = (amq_setopt *) argp;
178a53f50b9Schristos 
179a53f50b9Schristos   rc = 0;
180a53f50b9Schristos 
181a53f50b9Schristos   switch (opt->as_opt) {
182a53f50b9Schristos 
183a53f50b9Schristos   case AMOPT_DEBUG:
184a53f50b9Schristos     if (debug_option(opt->as_str))
185a53f50b9Schristos       rc = EINVAL;
186a53f50b9Schristos     break;
187a53f50b9Schristos 
188a53f50b9Schristos   case AMOPT_LOGFILE:
189a53f50b9Schristos     if (gopt.logfile && opt->as_str
190a53f50b9Schristos 	&& STREQ(gopt.logfile, opt->as_str)) {
191a53f50b9Schristos       if (switch_to_logfile(opt->as_str, orig_umask, 0))
192a53f50b9Schristos 	rc = EINVAL;
193a53f50b9Schristos     } else {
194a53f50b9Schristos       rc = EACCES;
195a53f50b9Schristos     }
196a53f50b9Schristos     break;
197a53f50b9Schristos 
198a53f50b9Schristos   case AMOPT_XLOG:
199a53f50b9Schristos     if (switch_option(opt->as_str))
200a53f50b9Schristos       rc = EINVAL;
201a53f50b9Schristos     break;
202a53f50b9Schristos 
203a53f50b9Schristos   case AMOPT_FLUSHMAPC:
204a53f50b9Schristos     if (amd_state == Run) {
205a53f50b9Schristos       plog(XLOG_INFO, "amq says flush cache");
206a53f50b9Schristos       do_mapc_reload = 0;
207a53f50b9Schristos       flush_nfs_fhandle_cache((fserver *) NULL);
208a53f50b9Schristos       flush_srvr_nfs_cache((fserver *) NULL);
209a53f50b9Schristos     }
210a53f50b9Schristos     break;
211a53f50b9Schristos   }
212a53f50b9Schristos 
213a53f50b9Schristos   return &rc;
214a53f50b9Schristos }
215a53f50b9Schristos 
216a53f50b9Schristos 
217a53f50b9Schristos amq_mount_info_list *
amqproc_getmntfs_1_svc(voidp argp,struct svc_req * rqstp)218a53f50b9Schristos amqproc_getmntfs_1_svc(voidp argp, struct svc_req *rqstp)
219a53f50b9Schristos {
220a53f50b9Schristos   return (amq_mount_info_list *) ((void *)&mfhead);	/* XXX */
221a53f50b9Schristos }
222a53f50b9Schristos 
2238bae5d40Schristos extern qelem map_list_head;
2248bae5d40Schristos amq_map_info_list *
amqproc_getmapinfo_1_svc(voidp argp,struct svc_req * rqstp)2258bae5d40Schristos amqproc_getmapinfo_1_svc(voidp argp, struct svc_req *rqstp)
2268bae5d40Schristos {
2278bae5d40Schristos   return (amq_map_info_list *) ((void *)&map_list_head);	/* XXX */
2288bae5d40Schristos }
229a53f50b9Schristos 
230a53f50b9Schristos amq_string *
amqproc_getvers_1_svc(voidp argp,struct svc_req * rqstp)231a53f50b9Schristos amqproc_getvers_1_svc(voidp argp, struct svc_req *rqstp)
232a53f50b9Schristos {
233a53f50b9Schristos   static amq_string res;
234a53f50b9Schristos 
235a53f50b9Schristos   res = get_version_string();
236a53f50b9Schristos   return &res;
237a53f50b9Schristos }
238a53f50b9Schristos 
239a53f50b9Schristos 
240a53f50b9Schristos /* get PID of remote amd */
241a53f50b9Schristos int *
amqproc_getpid_1_svc(voidp argp,struct svc_req * rqstp)242a53f50b9Schristos amqproc_getpid_1_svc(voidp argp, struct svc_req *rqstp)
243a53f50b9Schristos {
244a53f50b9Schristos   static int res;
245a53f50b9Schristos 
246a53f50b9Schristos   res = getpid();
247a53f50b9Schristos   return &res;
248a53f50b9Schristos }
249a53f50b9Schristos 
250a53f50b9Schristos 
251a53f50b9Schristos /*
252a53f50b9Schristos  * Process PAWD string of remote pawd tool.
253a53f50b9Schristos  *
254a53f50b9Schristos  * We repeat the resolution of the string until the resolved string resolves
255a53f50b9Schristos  * to itself.  This ensures that we follow path resolutions through all
256a53f50b9Schristos  * possible Amd mount points until we reach some sort of convergence.  To
257a53f50b9Schristos  * prevent possible infinite loops, we break out of this loop if the strings
258a53f50b9Schristos  * do not converge after MAX_PAWD_TRIES times.
259a53f50b9Schristos  */
260a53f50b9Schristos amq_string *
amqproc_pawd_1_svc(voidp argp,struct svc_req * rqstp)261a53f50b9Schristos amqproc_pawd_1_svc(voidp argp, struct svc_req *rqstp)
262a53f50b9Schristos {
263a53f50b9Schristos   static amq_string res;
264a53f50b9Schristos #define MAX_PAWD_TRIES 10
265a53f50b9Schristos   int index, len, maxagain = MAX_PAWD_TRIES;
266a53f50b9Schristos   am_node *mp;
267a53f50b9Schristos   char *mountpoint;
268a53f50b9Schristos   char *dir = *(char **) argp;
269a53f50b9Schristos   static char tmp_buf[MAXPATHLEN];
270a53f50b9Schristos   char prev_buf[MAXPATHLEN];
271a53f50b9Schristos 
272a53f50b9Schristos   tmp_buf[0] = prev_buf[0] = '\0'; /* default is empty string: no match */
273a53f50b9Schristos   do {
274a53f50b9Schristos     for (mp = get_first_exported_ap(&index);
275a53f50b9Schristos 	 mp;
276a53f50b9Schristos 	 mp = get_next_exported_ap(&index)) {
2778bae5d40Schristos       if (STREQ(mp->am_al->al_mnt->mf_ops->fs_type, "toplvl"))
278a53f50b9Schristos 	continue;
2798bae5d40Schristos       if (STREQ(mp->am_al->al_mnt->mf_ops->fs_type, "auto"))
280a53f50b9Schristos 	continue;
2818bae5d40Schristos       mountpoint = (mp->am_link ? mp->am_link : mp->am_al->al_mnt->mf_mount);
282a53f50b9Schristos       len = strlen(mountpoint);
283a53f50b9Schristos       if (len == 0)
284a53f50b9Schristos 	continue;
285a53f50b9Schristos       if (!NSTREQ(mountpoint, dir, len))
286a53f50b9Schristos 	continue;
287a53f50b9Schristos       if (dir[len] != '\0' && dir[len] != '/')
288a53f50b9Schristos 	continue;
289a53f50b9Schristos       xstrlcpy(tmp_buf, mp->am_path, sizeof(tmp_buf));
290a53f50b9Schristos       xstrlcat(tmp_buf, &dir[len], sizeof(tmp_buf));
291a53f50b9Schristos       break;
292a53f50b9Schristos     } /* end of "for" loop */
293a53f50b9Schristos     /* once tmp_buf and prev_buf are equal, break out of "do" loop */
294a53f50b9Schristos     if (STREQ(tmp_buf, prev_buf))
295a53f50b9Schristos       break;
296a53f50b9Schristos     else
297a53f50b9Schristos       xstrlcpy(prev_buf, tmp_buf, sizeof(prev_buf));
298a53f50b9Schristos   } while (--maxagain);
299a53f50b9Schristos   /* check if we couldn't resolve the string after MAX_PAWD_TRIES times */
300a53f50b9Schristos   if (maxagain <= 0)
301a53f50b9Schristos     plog(XLOG_WARNING, "path \"%s\" did not resolve after %d tries",
302a53f50b9Schristos 	 tmp_buf, MAX_PAWD_TRIES);
303a53f50b9Schristos 
304a53f50b9Schristos   res = tmp_buf;
305a53f50b9Schristos   return &res;
306a53f50b9Schristos }
307a53f50b9Schristos 
308a53f50b9Schristos 
309a53f50b9Schristos /*
310a53f50b9Schristos  * XDR routines.
311a53f50b9Schristos  */
312a53f50b9Schristos 
313a53f50b9Schristos 
314a53f50b9Schristos bool_t
xdr_amq_setopt(XDR * xdrs,amq_setopt * objp)315a53f50b9Schristos xdr_amq_setopt(XDR *xdrs, amq_setopt *objp)
316a53f50b9Schristos {
317a53f50b9Schristos   if (!xdr_enum(xdrs, (enum_t *) ((voidp) &objp->as_opt))) {
318a53f50b9Schristos     return (FALSE);
319a53f50b9Schristos   }
320a53f50b9Schristos   if (!xdr_string(xdrs, &objp->as_str, AMQ_STRLEN)) {
321a53f50b9Schristos     return (FALSE);
322a53f50b9Schristos   }
323a53f50b9Schristos   return (TRUE);
324a53f50b9Schristos }
325a53f50b9Schristos 
326a53f50b9Schristos 
327a53f50b9Schristos /*
328a53f50b9Schristos  * More XDR routines  - Should be used for OUTPUT ONLY.
329a53f50b9Schristos  */
330a53f50b9Schristos bool_t
xdr_amq_mount_tree_node(XDR * xdrs,amq_mount_tree * objp)331a53f50b9Schristos xdr_amq_mount_tree_node(XDR *xdrs, amq_mount_tree *objp)
332a53f50b9Schristos {
333a53f50b9Schristos   am_node *mp = (am_node *) objp;
33446f3b50fSchristos   longlong_t mtime;
335a53f50b9Schristos 
3368bae5d40Schristos   if (!xdr_amq_string(xdrs, &mp->am_al->al_mnt->mf_info)) {
337a53f50b9Schristos     return (FALSE);
338a53f50b9Schristos   }
339a53f50b9Schristos   if (!xdr_amq_string(xdrs, &mp->am_path)) {
340a53f50b9Schristos     return (FALSE);
341a53f50b9Schristos   }
3428bae5d40Schristos   if (!xdr_amq_string(xdrs, mp->am_link ? &mp->am_link : &mp->am_al->al_mnt->mf_mount)) {
343a53f50b9Schristos     return (FALSE);
344a53f50b9Schristos   }
3458bae5d40Schristos   if (!xdr_amq_string(xdrs, &mp->am_al->al_mnt->mf_ops->fs_type)) {
346a53f50b9Schristos     return (FALSE);
347a53f50b9Schristos   }
348a53f50b9Schristos   mtime = mp->am_stats.s_mtime;
34946f3b50fSchristos   if (!xdr_longlong_t(xdrs, &mtime)) {
350a53f50b9Schristos     return (FALSE);
351a53f50b9Schristos   }
352a53f50b9Schristos   if (!xdr_u_short(xdrs, &mp->am_stats.s_uid)) {
353a53f50b9Schristos     return (FALSE);
354a53f50b9Schristos   }
355a53f50b9Schristos   if (!xdr_int(xdrs, &mp->am_stats.s_getattr)) {
356a53f50b9Schristos     return (FALSE);
357a53f50b9Schristos   }
358a53f50b9Schristos   if (!xdr_int(xdrs, &mp->am_stats.s_lookup)) {
359a53f50b9Schristos     return (FALSE);
360a53f50b9Schristos   }
361a53f50b9Schristos   if (!xdr_int(xdrs, &mp->am_stats.s_readdir)) {
362a53f50b9Schristos     return (FALSE);
363a53f50b9Schristos   }
364a53f50b9Schristos   if (!xdr_int(xdrs, &mp->am_stats.s_readlink)) {
365a53f50b9Schristos     return (FALSE);
366a53f50b9Schristos   }
367a53f50b9Schristos   if (!xdr_int(xdrs, &mp->am_stats.s_statfs)) {
368a53f50b9Schristos     return (FALSE);
369a53f50b9Schristos   }
370a53f50b9Schristos   return (TRUE);
371a53f50b9Schristos }
372a53f50b9Schristos 
373a53f50b9Schristos 
374a53f50b9Schristos bool_t
xdr_amq_mount_subtree(XDR * xdrs,amq_mount_tree * objp)375a53f50b9Schristos xdr_amq_mount_subtree(XDR *xdrs, amq_mount_tree *objp)
376a53f50b9Schristos {
377a53f50b9Schristos   am_node *mp = (am_node *) objp;
378a53f50b9Schristos 
379a53f50b9Schristos   if (!xdr_amq_mount_tree_node(xdrs, objp)) {
380a53f50b9Schristos     return (FALSE);
381a53f50b9Schristos   }
382a53f50b9Schristos   if (!xdr_pointer(xdrs,
383a53f50b9Schristos 		   (char **) ((voidp) &mp->am_osib),
384a53f50b9Schristos 		   sizeof(amq_mount_tree),
385a53f50b9Schristos 		   (XDRPROC_T_TYPE) xdr_amq_mount_subtree)) {
386a53f50b9Schristos     return (FALSE);
387a53f50b9Schristos   }
388a53f50b9Schristos   if (!xdr_pointer(xdrs,
389a53f50b9Schristos 		   (char **) ((voidp) &mp->am_child),
390a53f50b9Schristos 		   sizeof(amq_mount_tree),
391a53f50b9Schristos 		   (XDRPROC_T_TYPE) xdr_amq_mount_subtree)) {
392a53f50b9Schristos     return (FALSE);
393a53f50b9Schristos   }
394a53f50b9Schristos   return (TRUE);
395a53f50b9Schristos }
396a53f50b9Schristos 
397a53f50b9Schristos 
398a53f50b9Schristos bool_t
xdr_amq_mount_tree(XDR * xdrs,amq_mount_tree * objp)399a53f50b9Schristos xdr_amq_mount_tree(XDR *xdrs, amq_mount_tree *objp)
400a53f50b9Schristos {
401a53f50b9Schristos   am_node *mp = (am_node *) objp;
402a53f50b9Schristos   am_node *mnil = NULL;
403a53f50b9Schristos 
404a53f50b9Schristos   if (!xdr_amq_mount_tree_node(xdrs, objp)) {
405a53f50b9Schristos     return (FALSE);
406a53f50b9Schristos   }
407a53f50b9Schristos   if (!xdr_pointer(xdrs,
408a53f50b9Schristos 		   (char **) ((voidp) &mnil),
409a53f50b9Schristos 		   sizeof(amq_mount_tree),
410a53f50b9Schristos 		   (XDRPROC_T_TYPE) xdr_amq_mount_subtree)) {
411a53f50b9Schristos     return (FALSE);
412a53f50b9Schristos   }
413a53f50b9Schristos   if (!xdr_pointer(xdrs,
414a53f50b9Schristos 		   (char **) ((voidp) &mp->am_child),
415a53f50b9Schristos 		   sizeof(amq_mount_tree),
416a53f50b9Schristos 		   (XDRPROC_T_TYPE) xdr_amq_mount_subtree)) {
417a53f50b9Schristos     return (FALSE);
418a53f50b9Schristos   }
419a53f50b9Schristos   return (TRUE);
420a53f50b9Schristos }
421a53f50b9Schristos 
422a53f50b9Schristos 
423a53f50b9Schristos bool_t
xdr_amq_mount_tree_p(XDR * xdrs,amq_mount_tree_p * objp)424a53f50b9Schristos xdr_amq_mount_tree_p(XDR *xdrs, amq_mount_tree_p *objp)
425a53f50b9Schristos {
426a53f50b9Schristos   if (!xdr_pointer(xdrs, (char **) objp, sizeof(amq_mount_tree), (XDRPROC_T_TYPE) xdr_amq_mount_tree)) {
427a53f50b9Schristos     return (FALSE);
428a53f50b9Schristos   }
429a53f50b9Schristos   return (TRUE);
430a53f50b9Schristos }
431a53f50b9Schristos 
432a53f50b9Schristos 
433a53f50b9Schristos bool_t
xdr_amq_mount_stats(XDR * xdrs,amq_mount_stats * objp)434a53f50b9Schristos xdr_amq_mount_stats(XDR *xdrs, amq_mount_stats *objp)
435a53f50b9Schristos {
436a53f50b9Schristos   if (!xdr_int(xdrs, &objp->as_drops)) {
437a53f50b9Schristos     return (FALSE);
438a53f50b9Schristos   }
439a53f50b9Schristos   if (!xdr_int(xdrs, &objp->as_stale)) {
440a53f50b9Schristos     return (FALSE);
441a53f50b9Schristos   }
442a53f50b9Schristos   if (!xdr_int(xdrs, &objp->as_mok)) {
443a53f50b9Schristos     return (FALSE);
444a53f50b9Schristos   }
445a53f50b9Schristos   if (!xdr_int(xdrs, &objp->as_merr)) {
446a53f50b9Schristos     return (FALSE);
447a53f50b9Schristos   }
448a53f50b9Schristos   if (!xdr_int(xdrs, &objp->as_uerr)) {
449a53f50b9Schristos     return (FALSE);
450a53f50b9Schristos   }
451a53f50b9Schristos   return (TRUE);
452a53f50b9Schristos }
453a53f50b9Schristos 
454a53f50b9Schristos 
455a53f50b9Schristos 
456a53f50b9Schristos bool_t
xdr_amq_mount_tree_list(XDR * xdrs,amq_mount_tree_list * objp)457a53f50b9Schristos xdr_amq_mount_tree_list(XDR *xdrs, amq_mount_tree_list *objp)
458a53f50b9Schristos {
459a53f50b9Schristos   if (!xdr_array(xdrs,
460a53f50b9Schristos 		 (char **) ((voidp) &objp->amq_mount_tree_list_val),
461a53f50b9Schristos 		 (u_int *) &objp->amq_mount_tree_list_len,
462a53f50b9Schristos 		 ~0,
463a53f50b9Schristos 		 sizeof(amq_mount_tree_p),
464a53f50b9Schristos 		 (XDRPROC_T_TYPE) xdr_amq_mount_tree_p)) {
465a53f50b9Schristos     return (FALSE);
466a53f50b9Schristos   }
467a53f50b9Schristos   return (TRUE);
468a53f50b9Schristos }
469a53f50b9Schristos 
470a53f50b9Schristos 
471a53f50b9Schristos bool_t
xdr_amq_mount_info_qelem(XDR * xdrs,qelem * qhead)472a53f50b9Schristos xdr_amq_mount_info_qelem(XDR *xdrs, qelem *qhead)
473a53f50b9Schristos {
474a53f50b9Schristos   mntfs *mf;
475a53f50b9Schristos   u_int len = 0;
476a53f50b9Schristos 
4778bae5d40Schristos   /*
4788bae5d40Schristos    * Compute length of list
4798bae5d40Schristos    */
480a53f50b9Schristos   for (mf = AM_LAST(mntfs, qhead); mf != HEAD(mntfs, qhead); mf = PREV(mntfs, mf)) {
481a53f50b9Schristos     if (!(mf->mf_fsflags & FS_AMQINFO))
482a53f50b9Schristos       continue;
483a53f50b9Schristos     len++;
484a53f50b9Schristos   }
485a53f50b9Schristos   xdr_u_int(xdrs, &len);
486a53f50b9Schristos 
487a53f50b9Schristos   /*
488a53f50b9Schristos    * Send individual data items
489a53f50b9Schristos    */
490a53f50b9Schristos   for (mf = AM_LAST(mntfs, qhead); mf != HEAD(mntfs, qhead); mf = PREV(mntfs, mf)) {
491a53f50b9Schristos     int up;
492a53f50b9Schristos     if (!(mf->mf_fsflags & FS_AMQINFO))
493a53f50b9Schristos       continue;
494a53f50b9Schristos 
495a53f50b9Schristos     if (!xdr_amq_string(xdrs, &mf->mf_ops->fs_type)) {
496a53f50b9Schristos       return (FALSE);
497a53f50b9Schristos     }
498a53f50b9Schristos     if (!xdr_amq_string(xdrs, &mf->mf_mount)) {
499a53f50b9Schristos       return (FALSE);
500a53f50b9Schristos     }
501a53f50b9Schristos     if (!xdr_amq_string(xdrs, &mf->mf_info)) {
502a53f50b9Schristos       return (FALSE);
503a53f50b9Schristos     }
504a53f50b9Schristos     if (!xdr_amq_string(xdrs, &mf->mf_server->fs_host)) {
505a53f50b9Schristos       return (FALSE);
506a53f50b9Schristos     }
507a53f50b9Schristos     if (!xdr_int(xdrs, &mf->mf_error)) {
508a53f50b9Schristos       return (FALSE);
509a53f50b9Schristos     }
510a53f50b9Schristos     if (!xdr_int(xdrs, &mf->mf_refc)) {
511a53f50b9Schristos       return (FALSE);
512a53f50b9Schristos     }
513a53f50b9Schristos     if (FSRV_ERROR(mf->mf_server) || FSRV_ISDOWN(mf->mf_server))
514a53f50b9Schristos       up = 0;
515a53f50b9Schristos     else if (FSRV_ISUP(mf->mf_server))
516a53f50b9Schristos       up = 1;
517a53f50b9Schristos     else
518a53f50b9Schristos       up = -1;
519a53f50b9Schristos     if (!xdr_int(xdrs, &up)) {
520a53f50b9Schristos       return (FALSE);
521a53f50b9Schristos     }
522a53f50b9Schristos   }
523a53f50b9Schristos   return (TRUE);
524a53f50b9Schristos }
525a53f50b9Schristos 
5268bae5d40Schristos bool_t
xdr_amq_map_info_qelem(XDR * xdrs,qelem * qhead)5278bae5d40Schristos xdr_amq_map_info_qelem(XDR *xdrs, qelem *qhead)
5288bae5d40Schristos {
5298bae5d40Schristos   mnt_map *m;
5308bae5d40Schristos   u_int len = 0;
5318bae5d40Schristos   int x;
5328bae5d40Schristos   char *n;
53346f3b50fSchristos   longlong_t modify;
5348bae5d40Schristos 
5358bae5d40Schristos   /*
5368bae5d40Schristos    * Compute length of list
5378bae5d40Schristos    */
5388bae5d40Schristos   ITER(m, mnt_map, qhead) {
5398bae5d40Schristos      len++;
5408bae5d40Schristos   }
5418bae5d40Schristos 
5428bae5d40Schristos   if (!xdr_u_int(xdrs, &len))
5438bae5d40Schristos       return (FALSE);
5448bae5d40Schristos 
5458bae5d40Schristos   /*
5468bae5d40Schristos    * Send individual data items
5478bae5d40Schristos    */
5488bae5d40Schristos   ITER(m, mnt_map, qhead) {
5498bae5d40Schristos     if (!xdr_amq_string(xdrs, &m->map_name)) {
5508bae5d40Schristos       return (FALSE);
5518bae5d40Schristos     }
5528bae5d40Schristos 
5538bae5d40Schristos     n = m->wildcard ? m->wildcard : "";
5548bae5d40Schristos     if (!xdr_amq_string(xdrs, &n)) {
5558bae5d40Schristos       return (FALSE);
5568bae5d40Schristos     }
5578bae5d40Schristos 
558*deb12511Schristos     modify = m->modify;
55946f3b50fSchristos     if (!xdr_longlong_t(xdrs, &modify)) {
5608bae5d40Schristos       return (FALSE);
5618bae5d40Schristos     }
5628bae5d40Schristos 
5638bae5d40Schristos     x = m->flags;
5648bae5d40Schristos     if (!xdr_int(xdrs, &x)) {
5658bae5d40Schristos       return (FALSE);
5668bae5d40Schristos     }
5678bae5d40Schristos 
5688bae5d40Schristos     x = m->nentries;
5698bae5d40Schristos     if (!xdr_int(xdrs, &x)) {
5708bae5d40Schristos       return (FALSE);
5718bae5d40Schristos     }
5728bae5d40Schristos 
5738bae5d40Schristos     x = m->reloads;
5748bae5d40Schristos     if (!xdr_int(xdrs, &x)) {
5758bae5d40Schristos       return (FALSE);
5768bae5d40Schristos     }
5778bae5d40Schristos 
5788bae5d40Schristos     if (!xdr_int(xdrs, &m->refc)) {
5798bae5d40Schristos       return (FALSE);
5808bae5d40Schristos     }
5818bae5d40Schristos 
5828bae5d40Schristos     if (m->isup)
5838bae5d40Schristos       x = (*m->isup)(m, m->map_name);
5848bae5d40Schristos     else
5858bae5d40Schristos       x = -1;
5868bae5d40Schristos     if (!xdr_int(xdrs, &x)) {
5878bae5d40Schristos       return (FALSE);
5888bae5d40Schristos     }
5898bae5d40Schristos   }
5908bae5d40Schristos   return (TRUE);
5918bae5d40Schristos }
592a53f50b9Schristos 
593a53f50b9Schristos bool_t
xdr_pri_free(XDRPROC_T_TYPE xdr_args,caddr_t args_ptr)594a53f50b9Schristos xdr_pri_free(XDRPROC_T_TYPE xdr_args, caddr_t args_ptr)
595a53f50b9Schristos {
596a53f50b9Schristos   XDR xdr;
597a53f50b9Schristos 
598a53f50b9Schristos   xdr.x_op = XDR_FREE;
599a53f50b9Schristos   return ((*xdr_args) (&xdr, (caddr_t *) args_ptr));
600a53f50b9Schristos }
601