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
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.
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]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
48 #include <rpc/rpcb_clnt.h>
49 #include <sys/socket.h>
54 #include <rpcsvc/mount.h>
57 #include <clnt_subr.h>
59 int sorthost(const void *, const void *);
60 int sortpath(const void *, const void *);
61 void printex(CLIENT
*, char *);
65 * Dynamically-sized array of pointers to mountlist entries. Each element
66 * points into the linked list returned by the RPC call. We use an array
67 * so that we can conveniently sort the entries.
69 static struct mountbody
**table
;
71 struct timeval rpc_totout_new
= {15, 0};
74 main(int argc
, char *argv
[])
76 int aflg
= 0, dflg
= 0, eflg
= 0;
78 struct mountbody
*result_list
= NULL
;
79 struct mountbody
*ml
= NULL
;
80 struct mountbody
**tb
; /* pointer into table */
81 char *host
, hostbuf
[256];
85 struct timeval tout
, rpc_totout_old
;
88 (void) setlocale(LC_ALL
, "");
90 #if !defined(TEXT_DOMAIN)
91 #define TEXT_DOMAIN "SYS_TEST"
93 (void) textdomain(TEXT_DOMAIN
);
95 while ((c
= getopt(argc
, argv
, "ade")) != EOF
) {
112 switch (argc
- optind
) {
113 case 0: /* no args */
114 if (gethostname(hostbuf
, sizeof (hostbuf
)) < 0) {
115 pr_err("gethostname: %s\n", strerror(errno
));
120 case 1: /* one arg */
123 default: /* too many args */
128 (void) __rpc_control(CLCR_GET_RPCB_TIMEOUT
, &rpc_totout_old
);
129 (void) __rpc_control(CLCR_SET_RPCB_TIMEOUT
, &rpc_totout_new
);
131 cl
= mountprog_client_create(host
, &rpc_totout_old
);
136 (void) __rpc_control(CLCR_SET_RPCB_TIMEOUT
, &rpc_totout_old
);
140 if (aflg
+ dflg
== 0) {
148 err
= clnt_call(cl
, MOUNTPROC_DUMP
, xdr_void
, 0, xdr_mountlist
,
149 (caddr_t
)&result_list
, tout
);
151 pr_err("%s\n", clnt_sperrno(err
));
156 * Count the number of entries in the list. If the list is empty,
160 for (ml
= result_list
; ml
!= NULL
; ml
= ml
->ml_next
)
166 * Allocate memory for the array and initialize the array.
169 table
= calloc(numentries
, sizeof (struct mountbody
*));
171 pr_err(gettext("not enough memory for %d entries\n"),
175 for (ml
= result_list
, tb
= &table
[0];
177 ml
= ml
->ml_next
, tb
++) {
182 * Sort the entries and print the results.
186 qsort(table
, numentries
, sizeof (struct mountbody
*), sortpath
);
188 qsort(table
, numentries
, sizeof (struct mountbody
*), sorthost
);
190 for (tb
= table
; tb
< table
+ numentries
; tb
++)
191 printf("%s:%s\n", (*tb
)->ml_hostname
,
192 (*tb
)->ml_directory
);
195 for (tb
= table
; tb
< table
+ numentries
; tb
++) {
196 if (strcmp(last
, (*tb
)->ml_directory
))
197 printf("%s\n", (*tb
)->ml_directory
);
198 last
= (*tb
)->ml_directory
;
202 for (tb
= table
; tb
< table
+ numentries
; tb
++) {
203 if (strcmp(last
, (*tb
)->ml_hostname
))
204 printf("%s\n", (*tb
)->ml_hostname
);
205 last
= (*tb
)->ml_hostname
;
212 sorthost(const void *_a
, const void *_b
)
214 struct mountbody
**a
= (struct mountbody
**)_a
;
215 struct mountbody
**b
= (struct mountbody
**)_b
;
217 return (strcmp((*a
)->ml_hostname
, (*b
)->ml_hostname
));
221 sortpath(const void *_a
, const void *_b
)
223 struct mountbody
**a
= (struct mountbody
**)_a
;
224 struct mountbody
**b
= (struct mountbody
**)_b
;
226 return (strcmp((*a
)->ml_directory
, (*b
)->ml_directory
));
232 (void) fprintf(stderr
,
233 gettext("Usage: showmount [-a] [-d] [-e] [host]\n"));
237 pr_err(char *fmt
, ...)
242 (void) fprintf(stderr
, "showmount: ");
243 (void) vfprintf(stderr
, fmt
, ap
);
248 printex(CLIENT
*cl
, char *host
)
250 struct exportnode
*ex
= NULL
;
251 struct exportnode
*e
;
252 struct groupnode
*gr
;
260 err
= clnt_call(cl
, MOUNTPROC_EXPORT
, xdr_void
, 0, xdr_exports
,
263 pr_err("%s\n", clnt_sperrno(err
));
268 printf(gettext("no exported file systems for %s\n"), host
);
270 printf(gettext("export list for %s:\n"), host
);
273 for (e
= ex
; e
!= NULL
; e
= e
->ex_next
) {
274 if (strlen(e
->ex_dir
) > max
) {
275 max
= strlen(e
->ex_dir
);
279 printf("%-*s ", max
, ex
->ex_dir
);
282 printf(gettext("(everyone)"));
285 printf("%s", gr
->gr_name
);