8354 sync regcomp(3C) with upstream (fix make catalog)
[unleashed/tickless.git] / usr / src / cmd / devmgmt / cmds / getvol.c
blob553a4ba3453897a2ad5ad1d1df9e491554b05775
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 */
29 /*LINTLIBRARY*/
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <errno.h>
37 #include <signal.h>
38 #include <sys/types.h>
39 #include <devmgmt.h>
41 extern char *optarg;
42 extern int optind,
43 ckquit,
44 ckwidth;
46 char *prog;
47 char *label, *fsname;
48 char *prompt;
49 int options = 0;
50 int kpid = (-2);
51 int signo = SIGKILL;
53 static void usage(void);
56 * Given argv[0], return a pointer to the basename of the program.
58 static char *
59 prog_name(char *arg0)
61 char *str;
63 /* first strip trailing '/' characters (exec() allows these!) */
64 str = arg0 + strlen(arg0);
65 while (str > arg0 && *--str == '/')
66 *str = '\0';
67 if ((str = strrchr(arg0, '/')) != NULL)
68 return (str + 1);
69 return (arg0);
72 int
73 main(int argc, char **argv)
75 int c, n;
77 prog = prog_name(argv[0]);
79 while ((c = getopt(argc, argv, "fFownx:l:p:k:s:?QW:")) != EOF) {
80 switch (c) {
81 case 'Q':
82 ckquit = 0;
83 break;
85 case 'W':
86 ckwidth = atol(optarg);
87 break;
89 case 'f':
90 options |= DM_FORMAT;
91 break;
93 case 'F':
94 options |= DM_FORMFS;
95 break;
97 case 'o':
98 options |= DM_OLABEL;
99 break;
101 case 'n':
102 options |= DM_BATCH;
103 break;
105 case 'w':
106 options |= DM_WLABEL;
107 break;
109 case 'l':
110 if (label)
111 usage();
112 label = optarg;
113 break;
115 case 'p':
116 prompt = optarg;
117 break;
119 case 'x':
120 if (label)
121 usage();
122 label = optarg;
123 options |= DM_ELABEL;
124 break;
126 case 'k':
127 kpid = atol(optarg);
128 break;
130 case 's':
131 signo = atol(optarg);
132 break;
134 default:
135 usage();
139 if ((optind+1) != argc)
140 usage();
142 switch (n = getvol(argv[optind], label, options, prompt)) {
143 case 0:
144 break;
146 case 1:
147 (void) fprintf(stderr,
148 "%s: ERROR: unable to access device <%s>\n",
149 prog, argv[optind]);
150 break;
152 case 2:
153 (void) fprintf(stderr, "%s: ERROR: unknown device <%s>\n",
154 prog, argv[optind]);
155 break;
157 case 3:
158 if (kpid > -2)
159 (void) kill(kpid, signo);
160 break;
162 case 4:
163 (void) fprintf(stderr, "%s: ERROR: bad label on <%s>\n",
164 prog, argv[optind]);
165 break;
167 default:
168 (void) fprintf(stderr, "%s: ERROR: unknown device error\n",
169 prog);
170 break;
173 return (n);
176 static void
177 usage()
179 fprintf(stderr,
180 "usage: %s [-owfF] [-x extlabel] [-l [fsname],volname] device\n",
181 prog);
182 fprintf(stderr,
183 "usage: %s [-n] [-x extlabel] [-l [fsname],volname] device\n",
184 prog);
185 exit(1);