8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / fs.d / nfs / dfshares / dfshares.c
blobc0e94add345a4041d2190f41075d65afa97f708f
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
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
33 * All Rights Reserved
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
40 #pragma ident "%Z%%M% %I% %E% SMI"
43 * nfs dfshares
45 #include <stdio.h>
46 #include <string.h>
47 #include <rpc/rpc.h>
48 #include <rpc/rpcb_clnt.h>
49 #include <sys/socket.h>
50 #include <netdb.h>
51 #include <sys/time.h>
52 #include <sys/errno.h>
53 #include <nfs/nfs.h>
54 #include <rpcsvc/mount.h>
56 int hflg;
57 void pr_exports();
58 void free_ex();
59 void usage();
61 int
62 main(int argc, char *argv[])
65 char hostbuf[256];
66 extern int optind;
67 extern char *optarg;
68 int i, c;
70 while ((c = getopt(argc, argv, "h")) != EOF) {
71 switch (c) {
72 case 'h':
73 hflg++;
74 break;
75 default:
76 usage();
77 exit(1);
81 if (optind < argc) {
82 for (i = optind; i < argc; i++)
83 pr_exports(argv[i]);
84 } else {
85 if (gethostname(hostbuf, sizeof (hostbuf)) < 0) {
86 perror("nfs dfshares: gethostname");
87 exit(1);
89 pr_exports(hostbuf);
92 return (0);
95 struct timeval rpc_totout_new = {15, 0};
97 void
98 pr_exports(host)
99 char *host;
101 CLIENT *cl;
102 struct exportnode *ex = NULL;
103 enum clnt_stat err;
104 struct timeval tout, rpc_totout_old;
106 (void) __rpc_control(CLCR_GET_RPCB_TIMEOUT, &rpc_totout_old);
107 (void) __rpc_control(CLCR_SET_RPCB_TIMEOUT, &rpc_totout_new);
110 * First try circuit, then drop back to datagram if
111 * circuit is unavailable (an old version of mountd perhaps)
112 * Using circuit is preferred because it can handle
113 * arbitrarily long export lists.
115 cl = clnt_create(host, MOUNTPROG, MOUNTVERS, "circuit_n");
116 if (cl == NULL) {
117 if (rpc_createerr.cf_stat == RPC_PROGNOTREGISTERED)
118 cl = clnt_create(host, MOUNTPROG, MOUNTVERS,
119 "datagram_n");
120 if (cl == NULL) {
121 (void) fprintf(stderr, "nfs dfshares:");
122 clnt_pcreateerror(host);
123 (void) __rpc_control(CLCR_SET_RPCB_TIMEOUT,
124 &rpc_totout_old);
125 exit(1);
129 (void) __rpc_control(CLCR_SET_RPCB_TIMEOUT, &rpc_totout_old);
130 tout.tv_sec = 10;
131 tout.tv_usec = 0;
133 if (err = clnt_call(cl, MOUNTPROC_EXPORT, xdr_void,
134 0, xdr_exports, (caddr_t)&ex, tout)) {
135 (void) fprintf(stderr, "nfs dfshares: %s\n", clnt_sperrno(err));
136 clnt_destroy(cl);
137 exit(1);
140 if (ex == NULL) {
141 clnt_destroy(cl);
142 exit(1);
145 if (!hflg) {
146 printf("%-35s %12s %-8s %s\n",
147 "RESOURCE", "SERVER", "ACCESS", "TRANSPORT");
148 hflg++;
151 while (ex) {
152 printf("%10s:%-24s %12s %-8s %s\n",
153 host, ex->ex_dir, host, " -", " -");
154 ex = ex->ex_next;
156 free_ex(ex);
157 clnt_destroy(cl);
160 void
161 free_ex(ex)
162 struct exportnode *ex;
164 struct groupnode *gr, *tmpgr;
165 struct exportnode *tmpex;
167 while (ex) {
168 free(ex->ex_dir);
169 gr = ex->ex_groups;
170 while (gr) {
171 tmpgr = gr->gr_next;
172 free((char *)gr);
173 gr = tmpgr;
175 tmpex = ex;
176 ex = ex->ex_next;
177 free((char *)tmpex);
181 void
182 usage()
184 (void) fprintf(stderr, "Usage: dfshares [-h] [host ...]\n");