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
40 #pragma ident "%Z%%M% %I% %E% SMI"
48 #include <rpc/rpcb_clnt.h>
49 #include <sys/socket.h>
54 #include <rpcsvc/mount.h>
59 void pr_err(char *, ...);
64 * Dynamically-sized array of pointers to mountlist entries. Each element
65 * points into the linked list returned by the RPC call. We use an array
66 * so that we can conveniently sort the entries.
68 static struct mountbody
**table
;
70 struct timeval rpc_totout_new
= {15, 0};
73 main(int argc
, char *argv
[])
75 int aflg
= 0, dflg
= 0, eflg
= 0;
77 struct mountbody
*result_list
= NULL
;
78 struct mountbody
*ml
= NULL
;
79 struct mountbody
**tb
; /* pointer into table */
80 char *host
, hostbuf
[256];
86 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 __rpc_control(CLCR_GET_RPCB_TIMEOUT
, &rpc_totout_old
);
129 __rpc_control(CLCR_SET_RPCB_TIMEOUT
, &rpc_totout_new
);
132 * First try circuit, then drop back to datagram if
133 * circuit is unavailable (an old version of mountd perhaps)
134 * Using circuit is preferred because it can handle
135 * arbitrarily long export lists.
137 cl
= clnt_create(host
, MOUNTPROG
, MOUNTVERS
, "circuit_n");
139 if (rpc_createerr
.cf_stat
== RPC_PROGNOTREGISTERED
)
140 cl
= clnt_create(host
, MOUNTPROG
, MOUNTVERS
,
144 clnt_pcreateerror(host
);
145 __rpc_control(CLCR_SET_RPCB_TIMEOUT
, &rpc_totout_old
);
150 __rpc_control(CLCR_SET_RPCB_TIMEOUT
, &rpc_totout_old
);
154 if (aflg
+ dflg
== 0) {
162 if (err
= clnt_call(cl
, MOUNTPROC_DUMP
,
163 xdr_void
, 0, xdr_mountlist
,
164 (caddr_t
)&result_list
, tout
)) {
165 pr_err("%s\n", clnt_sperrno(err
));
170 * Count the number of entries in the list. If the list is empty,
174 for (ml
= result_list
; ml
!= NULL
; ml
= ml
->ml_next
)
180 * Allocate memory for the array and initialize the array.
183 table
= (struct mountbody
**)calloc(numentries
,
184 sizeof (struct mountbody
*));
186 pr_err(gettext("not enough memory for %d entries\n"),
190 for (ml
= result_list
, tb
= &table
[0];
192 ml
= ml
->ml_next
, tb
++) {
197 * Sort the entries and print the results.
201 qsort(table
, numentries
, sizeof (struct mountbody
*), sortpath
);
203 qsort(table
, numentries
, sizeof (struct mountbody
*), sorthost
);
205 for (tb
= table
; tb
< table
+ numentries
; tb
++)
206 printf("%s:%s\n", (*tb
)->ml_hostname
,
207 (*tb
)->ml_directory
);
210 for (tb
= table
; tb
< table
+ numentries
; tb
++) {
211 if (strcmp(last
, (*tb
)->ml_directory
))
212 printf("%s\n", (*tb
)->ml_directory
);
213 last
= (*tb
)->ml_directory
;
217 for (tb
= table
; tb
< table
+ numentries
; tb
++) {
218 if (strcmp(last
, (*tb
)->ml_hostname
))
219 printf("%s\n", (*tb
)->ml_hostname
);
220 last
= (*tb
)->ml_hostname
;
228 struct mountbody
**a
, **b
;
230 return (strcmp((*a
)->ml_hostname
, (*b
)->ml_hostname
));
235 struct mountbody
**a
, **b
;
237 return (strcmp((*a
)->ml_directory
, (*b
)->ml_directory
));
243 (void) fprintf(stderr
,
244 gettext("Usage: showmount [-a] [-d] [-e] [host]\n"));
248 pr_err(char *fmt
, ...)
253 (void) fprintf(stderr
, "showmount: ");
254 (void) vfprintf(stderr
, fmt
, ap
);
263 struct exportnode
*ex
= NULL
;
264 struct exportnode
*e
;
265 struct groupnode
*gr
;
273 if (err
= clnt_call(cl
, MOUNTPROC_EXPORT
,
274 xdr_void
, 0, xdr_exports
, (caddr_t
)&ex
, tout
)) {
275 pr_err("%s\n", clnt_sperrno(err
));
280 printf(gettext("no exported file systems for %s\n"), host
);
282 printf(gettext("export list for %s:\n"), host
);
285 for (e
= ex
; e
!= NULL
; e
= e
->ex_next
) {
286 if (strlen(e
->ex_dir
) > max
) {
287 max
= strlen(e
->ex_dir
);
291 printf("%-*s ", max
, ex
->ex_dir
);
294 printf(gettext("(everyone)"));
297 printf("%s", gr
->gr_name
);