commands.c revision 1.1.2.3 1 1.1.2.3 yamt /* $NetBSD: commands.c,v 1.1.2.3 2006/05/24 10:56:53 yamt Exp $ */
2 1.1.2.2 yamt
3 1.1.2.2 yamt /*-
4 1.1.2.2 yamt * Copyright (c) 1998 Michael Smith <msmith (at) freebsd.org>
5 1.1.2.2 yamt * All rights reserved.
6 1.1.2.2 yamt *
7 1.1.2.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.1.2.2 yamt * modification, are permitted provided that the following conditions
9 1.1.2.2 yamt * are met:
10 1.1.2.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.1.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.1.2.2 yamt * documentation and/or other materials provided with the distribution.
15 1.1.2.2 yamt *
16 1.1.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.1.2.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1.2.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1.2.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.1.2.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1.2.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1.2.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1.2.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1.2.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1.2.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1.2.2 yamt * SUCH DAMAGE.
27 1.1.2.2 yamt */
28 1.1.2.2 yamt
29 1.1.2.2 yamt #include <sys/cdefs.h>
30 1.1.2.3 yamt /* __FBSDID("$FreeBSD: src/sys/boot/common/commands.c,v 1.19 2003/08/25 23:30:41 obrien Exp $"); */
31 1.1.2.2 yamt
32 1.1.2.2 yamt #include <lib/libsa/stand.h>
33 1.1.2.2 yamt #include <lib/libkern/libkern.h>
34 1.1.2.2 yamt
35 1.1.2.2 yamt #include "bootstrap.h"
36 1.1.2.2 yamt
37 1.1.2.2 yamt char *command_errmsg;
38 1.1.2.2 yamt char command_errbuf[256]; /* XXX should have procedural interface for setting, size limit? */
39 1.1.2.2 yamt
40 1.1.2.2 yamt static int page_file(char *filename);
41 1.1.2.2 yamt
42 1.1.2.2 yamt /*
43 1.1.2.2 yamt * Help is read from a formatted text file.
44 1.1.2.2 yamt *
45 1.1.2.2 yamt * Entries in the file are formatted as
46 1.1.2.2 yamt
47 1.1.2.2 yamt # Ttopic [Ssubtopic] Ddescription
48 1.1.2.2 yamt help
49 1.1.2.2 yamt text
50 1.1.2.2 yamt here
51 1.1.2.2 yamt #
52 1.1.2.2 yamt
53 1.1.2.2 yamt *
54 1.1.2.2 yamt * Note that for code simplicity's sake, the above format must be followed
55 1.1.2.2 yamt * exactly.
56 1.1.2.2 yamt *
57 1.1.2.2 yamt * Subtopic entries must immediately follow the topic (this is used to
58 1.1.2.2 yamt * produce the listing of subtopics).
59 1.1.2.2 yamt *
60 1.1.2.2 yamt * If no argument(s) are supplied by the user, the help for 'help' is displayed.
61 1.1.2.2 yamt */
62 1.1.2.2 yamt
63 1.1.2.2 yamt static int
64 1.1.2.2 yamt help_getnext(int fd, char **topic, char **subtopic, char **desc)
65 1.1.2.2 yamt {
66 1.1.2.2 yamt char line[81], *cp, *ep;
67 1.1.2.2 yamt
68 1.1.2.2 yamt for (;;) {
69 1.1.2.2 yamt if (fgetstr(line, 80, fd) < 0)
70 1.1.2.2 yamt return(0);
71 1.1.2.2 yamt
72 1.1.2.2 yamt if ((strlen(line) < 3) || (line[0] != '#') || (line[1] != ' '))
73 1.1.2.2 yamt continue;
74 1.1.2.2 yamt
75 1.1.2.2 yamt *topic = *subtopic = *desc = NULL;
76 1.1.2.2 yamt cp = line + 2;
77 1.1.2.2 yamt while((cp != NULL) && (*cp != 0)) {
78 1.1.2.2 yamt ep = strchr(cp, ' ');
79 1.1.2.2 yamt if ((*cp == 'T') && (*topic == NULL)) {
80 1.1.2.2 yamt if (ep != NULL)
81 1.1.2.2 yamt *ep++ = 0;
82 1.1.2.2 yamt *topic = strdup(cp + 1);
83 1.1.2.2 yamt } else if ((*cp == 'S') && (*subtopic == NULL)) {
84 1.1.2.2 yamt if (ep != NULL)
85 1.1.2.2 yamt *ep++ = 0;
86 1.1.2.2 yamt *subtopic = strdup(cp + 1);
87 1.1.2.2 yamt } else if (*cp == 'D') {
88 1.1.2.2 yamt *desc = strdup(cp + 1);
89 1.1.2.2 yamt ep = NULL;
90 1.1.2.2 yamt }
91 1.1.2.2 yamt cp = ep;
92 1.1.2.2 yamt }
93 1.1.2.2 yamt if (*topic == NULL) {
94 1.1.2.2 yamt if (*subtopic != NULL)
95 1.1.2.2 yamt free(*subtopic);
96 1.1.2.2 yamt if (*desc != NULL)
97 1.1.2.2 yamt free(*desc);
98 1.1.2.2 yamt continue;
99 1.1.2.2 yamt }
100 1.1.2.2 yamt return(1);
101 1.1.2.2 yamt }
102 1.1.2.2 yamt }
103 1.1.2.2 yamt
104 1.1.2.2 yamt static int
105 1.1.2.2 yamt help_emitsummary(char *topic, char *subtopic, char *desc)
106 1.1.2.2 yamt {
107 1.1.2.2 yamt int i;
108 1.1.2.2 yamt
109 1.1.2.2 yamt pager_output(" ");
110 1.1.2.2 yamt pager_output(topic);
111 1.1.2.2 yamt i = strlen(topic);
112 1.1.2.2 yamt if (subtopic != NULL) {
113 1.1.2.2 yamt pager_output(" ");
114 1.1.2.2 yamt pager_output(subtopic);
115 1.1.2.2 yamt i += strlen(subtopic) + 1;
116 1.1.2.2 yamt }
117 1.1.2.2 yamt if (desc != NULL) {
118 1.1.2.2 yamt do {
119 1.1.2.2 yamt pager_output(" ");
120 1.1.2.2 yamt } while (i++ < 30);
121 1.1.2.2 yamt pager_output(desc);
122 1.1.2.2 yamt }
123 1.1.2.2 yamt return (pager_output("\n"));
124 1.1.2.2 yamt }
125 1.1.2.2 yamt
126 1.1.2.2 yamt
127 1.1.2.2 yamt int
128 1.1.2.2 yamt command_help(int argc, char *argv[])
129 1.1.2.2 yamt {
130 1.1.2.2 yamt char buf[81]; /* XXX buffer size? */
131 1.1.2.2 yamt int hfd, matched, doindex;
132 1.1.2.2 yamt char *topic, *subtopic, *t, *s, *d;
133 1.1.2.2 yamt
134 1.1.2.2 yamt /* page the help text from our load path */
135 1.1.2.2 yamt sprintf(buf, "%s/boot/loader.help", getenv("loaddev"));
136 1.1.2.2 yamt if ((hfd = open(buf, O_RDONLY)) < 0) {
137 1.1.2.2 yamt printf("Verbose help not available, use '?' to list commands\n");
138 1.1.2.2 yamt return(CMD_OK);
139 1.1.2.2 yamt }
140 1.1.2.2 yamt
141 1.1.2.2 yamt /* pick up request from arguments */
142 1.1.2.2 yamt topic = subtopic = NULL;
143 1.1.2.2 yamt switch(argc) {
144 1.1.2.2 yamt case 3:
145 1.1.2.2 yamt subtopic = strdup(argv[2]);
146 1.1.2.2 yamt case 2:
147 1.1.2.2 yamt topic = strdup(argv[1]);
148 1.1.2.2 yamt break;
149 1.1.2.2 yamt case 1:
150 1.1.2.2 yamt topic = strdup("help");
151 1.1.2.2 yamt break;
152 1.1.2.2 yamt default:
153 1.1.2.2 yamt command_errmsg = "usage is 'help <topic> [<subtopic>]";
154 1.1.2.2 yamt return(CMD_ERROR);
155 1.1.2.2 yamt }
156 1.1.2.2 yamt
157 1.1.2.2 yamt /* magic "index" keyword */
158 1.1.2.2 yamt doindex = !strcmp(topic, "index");
159 1.1.2.2 yamt matched = doindex;
160 1.1.2.2 yamt
161 1.1.2.2 yamt /* Scan the helpfile looking for help matching the request */
162 1.1.2.2 yamt pager_open();
163 1.1.2.2 yamt while(help_getnext(hfd, &t, &s, &d)) {
164 1.1.2.2 yamt
165 1.1.2.2 yamt if (doindex) { /* dink around formatting */
166 1.1.2.2 yamt if (help_emitsummary(t, s, d))
167 1.1.2.2 yamt break;
168 1.1.2.2 yamt
169 1.1.2.2 yamt } else if (strcmp(topic, t)) {
170 1.1.2.2 yamt /* topic mismatch */
171 1.1.2.2 yamt if(matched) /* nothing more on this topic, stop scanning */
172 1.1.2.2 yamt break;
173 1.1.2.2 yamt
174 1.1.2.2 yamt } else {
175 1.1.2.2 yamt /* topic matched */
176 1.1.2.2 yamt matched = 1;
177 1.1.2.2 yamt if (((subtopic == NULL) && (s == NULL)) ||
178 1.1.2.2 yamt ((subtopic != NULL) && (s != NULL) && !strcmp(subtopic, s))) {
179 1.1.2.2 yamt /* exact match, print text */
180 1.1.2.2 yamt while((fgetstr(buf, 80, hfd) >= 0) && (buf[0] != '#')) {
181 1.1.2.2 yamt if (pager_output(buf))
182 1.1.2.2 yamt break;
183 1.1.2.2 yamt if (pager_output("\n"))
184 1.1.2.2 yamt break;
185 1.1.2.2 yamt }
186 1.1.2.2 yamt } else if ((subtopic == NULL) && (s != NULL)) {
187 1.1.2.2 yamt /* topic match, list subtopics */
188 1.1.2.2 yamt if (help_emitsummary(t, s, d))
189 1.1.2.2 yamt break;
190 1.1.2.2 yamt }
191 1.1.2.2 yamt }
192 1.1.2.2 yamt free(t);
193 1.1.2.2 yamt free(s);
194 1.1.2.2 yamt free(d);
195 1.1.2.2 yamt }
196 1.1.2.2 yamt pager_close();
197 1.1.2.2 yamt close(hfd);
198 1.1.2.2 yamt if (!matched) {
199 1.1.2.2 yamt sprintf(command_errbuf, "no help available for '%s'", topic);
200 1.1.2.2 yamt free(topic);
201 1.1.2.2 yamt if (subtopic)
202 1.1.2.2 yamt free(subtopic);
203 1.1.2.2 yamt return(CMD_ERROR);
204 1.1.2.2 yamt }
205 1.1.2.2 yamt free(topic);
206 1.1.2.2 yamt if (subtopic)
207 1.1.2.2 yamt free(subtopic);
208 1.1.2.2 yamt return(CMD_OK);
209 1.1.2.2 yamt }
210 1.1.2.2 yamt
211 1.1.2.2 yamt
212 1.1.2.2 yamt int
213 1.1.2.2 yamt command_commandlist(int argc, char *argv[])
214 1.1.2.2 yamt {
215 1.1.2.2 yamt struct bootblk_command *cmdp;
216 1.1.2.2 yamt int res;
217 1.1.2.2 yamt char name[20];
218 1.1.2.2 yamt int i;
219 1.1.2.2 yamt
220 1.1.2.2 yamt res = 0;
221 1.1.2.2 yamt pager_open();
222 1.1.2.2 yamt res = pager_output("Available commands:\n");
223 1.1.2.2 yamt
224 1.1.2.2 yamt for (i = 0, cmdp = commands; (cmdp->c_name != NULL) && (cmdp->c_desc != NULL ); i++, cmdp = commands + i) {
225 1.1.2.2 yamt if (res)
226 1.1.2.2 yamt break;
227 1.1.2.2 yamt if ((cmdp->c_name != NULL) && (cmdp->c_desc != NULL)) {
228 1.1.2.2 yamt sprintf(name, " %s ", cmdp->c_name);
229 1.1.2.2 yamt pager_output(name);
230 1.1.2.2 yamt pager_output(cmdp->c_desc);
231 1.1.2.2 yamt res = pager_output("\n");
232 1.1.2.2 yamt }
233 1.1.2.2 yamt }
234 1.1.2.2 yamt pager_close();
235 1.1.2.2 yamt return(CMD_OK);
236 1.1.2.2 yamt }
237 1.1.2.2 yamt
238 1.1.2.2 yamt /*
239 1.1.2.2 yamt * XXX set/show should become set/echo if we have variable
240 1.1.2.2 yamt * substitution happening.
241 1.1.2.2 yamt */
242 1.1.2.2 yamt
243 1.1.2.2 yamt int
244 1.1.2.2 yamt command_show(int argc, char *argv[])
245 1.1.2.2 yamt {
246 1.1.2.2 yamt struct env_var *ev;
247 1.1.2.2 yamt char *cp;
248 1.1.2.2 yamt
249 1.1.2.2 yamt if (argc < 2) {
250 1.1.2.2 yamt /*
251 1.1.2.2 yamt * With no arguments, print everything.
252 1.1.2.2 yamt */
253 1.1.2.2 yamt pager_open();
254 1.1.2.2 yamt for (ev = environ; ev != NULL; ev = ev->ev_next) {
255 1.1.2.2 yamt pager_output(ev->ev_name);
256 1.1.2.2 yamt cp = getenv(ev->ev_name);
257 1.1.2.2 yamt if (cp != NULL) {
258 1.1.2.2 yamt pager_output("=");
259 1.1.2.2 yamt pager_output(cp);
260 1.1.2.2 yamt }
261 1.1.2.2 yamt if (pager_output("\n"))
262 1.1.2.2 yamt break;
263 1.1.2.2 yamt }
264 1.1.2.2 yamt pager_close();
265 1.1.2.2 yamt } else {
266 1.1.2.2 yamt if ((cp = getenv(argv[1])) != NULL) {
267 1.1.2.2 yamt printf("%s\n", cp);
268 1.1.2.2 yamt } else {
269 1.1.2.2 yamt sprintf(command_errbuf, "variable '%s' not found", argv[1]);
270 1.1.2.2 yamt return(CMD_ERROR);
271 1.1.2.2 yamt }
272 1.1.2.2 yamt }
273 1.1.2.2 yamt return(CMD_OK);
274 1.1.2.2 yamt }
275 1.1.2.2 yamt
276 1.1.2.2 yamt
277 1.1.2.2 yamt int
278 1.1.2.2 yamt command_set(int argc, char *argv[])
279 1.1.2.2 yamt {
280 1.1.2.2 yamt int err;
281 1.1.2.2 yamt
282 1.1.2.2 yamt if (argc != 2) {
283 1.1.2.2 yamt command_errmsg = "wrong number of arguments";
284 1.1.2.2 yamt return(CMD_ERROR);
285 1.1.2.2 yamt } else {
286 1.1.2.2 yamt if ((err = putenv(argv[1])) != 0) {
287 1.1.2.2 yamt command_errmsg = strerror(err);
288 1.1.2.2 yamt return(CMD_ERROR);
289 1.1.2.2 yamt }
290 1.1.2.2 yamt }
291 1.1.2.2 yamt return(CMD_OK);
292 1.1.2.2 yamt }
293 1.1.2.2 yamt
294 1.1.2.2 yamt
295 1.1.2.2 yamt int
296 1.1.2.2 yamt command_unset(int argc, char *argv[])
297 1.1.2.2 yamt {
298 1.1.2.2 yamt int err;
299 1.1.2.2 yamt
300 1.1.2.2 yamt if (argc != 2) {
301 1.1.2.2 yamt command_errmsg = "wrong number of arguments";
302 1.1.2.2 yamt return(CMD_ERROR);
303 1.1.2.2 yamt } else {
304 1.1.2.2 yamt if ((err = unsetenv(argv[1])) != 0) {
305 1.1.2.2 yamt command_errmsg = strerror(err);
306 1.1.2.2 yamt return(CMD_ERROR);
307 1.1.2.2 yamt }
308 1.1.2.2 yamt }
309 1.1.2.2 yamt return(CMD_OK);
310 1.1.2.2 yamt }
311 1.1.2.2 yamt
312 1.1.2.2 yamt
313 1.1.2.2 yamt int
314 1.1.2.2 yamt command_echo(int argc, char *argv[])
315 1.1.2.2 yamt {
316 1.1.2.2 yamt char *s;
317 1.1.2.2 yamt int nl, ch;
318 1.1.2.2 yamt
319 1.1.2.2 yamt nl = 0;
320 1.1.2.2 yamt optind = 1;
321 1.1.2.2 yamt optreset = 1;
322 1.1.2.2 yamt while ((ch = getopt(argc, argv, "n")) != -1) {
323 1.1.2.2 yamt switch(ch) {
324 1.1.2.2 yamt case 'n':
325 1.1.2.2 yamt nl = 1;
326 1.1.2.2 yamt break;
327 1.1.2.2 yamt case '?':
328 1.1.2.2 yamt default:
329 1.1.2.2 yamt /* getopt has already reported an error */
330 1.1.2.2 yamt return(CMD_OK);
331 1.1.2.2 yamt }
332 1.1.2.2 yamt }
333 1.1.2.2 yamt argv += (optind);
334 1.1.2.2 yamt argc -= (optind);
335 1.1.2.2 yamt
336 1.1.2.2 yamt s = unargv(argc, argv);
337 1.1.2.2 yamt if (s != NULL) {
338 1.1.2.2 yamt printf("%s", s);
339 1.1.2.2 yamt free(s);
340 1.1.2.2 yamt }
341 1.1.2.2 yamt if (!nl)
342 1.1.2.2 yamt printf("\n");
343 1.1.2.2 yamt return(CMD_OK);
344 1.1.2.2 yamt }
345 1.1.2.2 yamt
346 1.1.2.2 yamt /*
347 1.1.2.2 yamt * A passable emulation of the sh(1) command of the same name.
348 1.1.2.2 yamt */
349 1.1.2.2 yamt
350 1.1.2.2 yamt
351 1.1.2.2 yamt int
352 1.1.2.2 yamt command_read(int argc, char *argv[])
353 1.1.2.2 yamt {
354 1.1.2.2 yamt char *prompt;
355 1.1.2.2 yamt int timeout;
356 1.1.2.2 yamt time_t when;
357 1.1.2.2 yamt char *cp;
358 1.1.2.2 yamt char *name;
359 1.1.2.2 yamt char buf[256]; /* XXX size? */
360 1.1.2.2 yamt int c;
361 1.1.2.2 yamt
362 1.1.2.2 yamt timeout = -1;
363 1.1.2.2 yamt prompt = NULL;
364 1.1.2.2 yamt optind = 1;
365 1.1.2.2 yamt optreset = 1;
366 1.1.2.2 yamt while ((c = getopt(argc, argv, "p:t:")) != -1) {
367 1.1.2.2 yamt switch(c) {
368 1.1.2.2 yamt
369 1.1.2.2 yamt case 'p':
370 1.1.2.2 yamt prompt = optarg;
371 1.1.2.2 yamt break;
372 1.1.2.2 yamt case 't':
373 1.1.2.2 yamt timeout = strtol(optarg, &cp, 0);
374 1.1.2.2 yamt if (cp == optarg) {
375 1.1.2.2 yamt sprintf(command_errbuf, "bad timeout '%s'", optarg);
376 1.1.2.2 yamt return(CMD_ERROR);
377 1.1.2.2 yamt }
378 1.1.2.2 yamt break;
379 1.1.2.2 yamt default:
380 1.1.2.2 yamt return(CMD_OK);
381 1.1.2.2 yamt }
382 1.1.2.2 yamt }
383 1.1.2.2 yamt
384 1.1.2.2 yamt argv += (optind);
385 1.1.2.2 yamt argc -= (optind);
386 1.1.2.2 yamt name = (argc > 0) ? argv[0]: NULL;
387 1.1.2.2 yamt
388 1.1.2.2 yamt if (prompt != NULL)
389 1.1.2.2 yamt printf("%s", prompt);
390 1.1.2.2 yamt if (timeout >= 0) {
391 1.1.2.2 yamt when = time(NULL) + timeout;
392 1.1.2.2 yamt while (!ischar())
393 1.1.2.2 yamt if (time(NULL) >= when)
394 1.1.2.2 yamt return(CMD_OK); /* is timeout an error? */
395 1.1.2.2 yamt }
396 1.1.2.2 yamt
397 1.1.2.2 yamt ngets(buf, sizeof(buf));
398 1.1.2.2 yamt
399 1.1.2.2 yamt if (name != NULL)
400 1.1.2.2 yamt setenv(name, buf, 1);
401 1.1.2.2 yamt return(CMD_OK);
402 1.1.2.2 yamt }
403 1.1.2.2 yamt
404 1.1.2.2 yamt /*
405 1.1.2.2 yamt * File pager
406 1.1.2.2 yamt */
407 1.1.2.2 yamt
408 1.1.2.2 yamt int
409 1.1.2.2 yamt command_more(int argc, char *argv[])
410 1.1.2.2 yamt {
411 1.1.2.2 yamt int i;
412 1.1.2.2 yamt int res;
413 1.1.2.2 yamt char line[80];
414 1.1.2.2 yamt
415 1.1.2.2 yamt res=0;
416 1.1.2.2 yamt pager_open();
417 1.1.2.2 yamt for (i = 1; (i < argc) && (res == 0); i++) {
418 1.1.2.2 yamt sprintf(line, "*** FILE %s BEGIN ***\n", argv[i]);
419 1.1.2.2 yamt if (pager_output(line))
420 1.1.2.2 yamt break;
421 1.1.2.2 yamt res = page_file(argv[i]);
422 1.1.2.2 yamt if (!res) {
423 1.1.2.2 yamt sprintf(line, "*** FILE %s END ***\n", argv[i]);
424 1.1.2.2 yamt res = pager_output(line);
425 1.1.2.2 yamt }
426 1.1.2.2 yamt }
427 1.1.2.2 yamt pager_close();
428 1.1.2.2 yamt
429 1.1.2.2 yamt if (res == 0)
430 1.1.2.2 yamt return CMD_OK;
431 1.1.2.2 yamt else
432 1.1.2.2 yamt return CMD_ERROR;
433 1.1.2.2 yamt }
434 1.1.2.2 yamt
435 1.1.2.2 yamt static int
436 1.1.2.2 yamt page_file(char *filename)
437 1.1.2.2 yamt {
438 1.1.2.2 yamt int result;
439 1.1.2.2 yamt
440 1.1.2.2 yamt result = pager_file(filename);
441 1.1.2.2 yamt
442 1.1.2.2 yamt if (result == -1)
443 1.1.2.2 yamt sprintf(command_errbuf, "error showing %s", filename);
444 1.1.2.2 yamt
445 1.1.2.2 yamt return result;
446 1.1.2.2 yamt }
447 1.1.2.2 yamt
448 1.1.2.2 yamt /*
449 1.1.2.2 yamt * List all disk-like devices
450 1.1.2.2 yamt */
451 1.1.2.2 yamt
452 1.1.2.2 yamt int
453 1.1.2.2 yamt command_lsdev(int argc, char *argv[])
454 1.1.2.2 yamt {
455 1.1.2.2 yamt int verbose, ch, i;
456 1.1.2.2 yamt char line[80];
457 1.1.2.2 yamt
458 1.1.2.2 yamt verbose = 0;
459 1.1.2.2 yamt optind = 1;
460 1.1.2.2 yamt optreset = 1;
461 1.1.2.2 yamt while ((ch = getopt(argc, argv, "v")) != -1) {
462 1.1.2.2 yamt switch(ch) {
463 1.1.2.2 yamt case 'v':
464 1.1.2.2 yamt verbose = 1;
465 1.1.2.2 yamt break;
466 1.1.2.2 yamt case '?':
467 1.1.2.2 yamt default:
468 1.1.2.2 yamt /* getopt has already reported an error */
469 1.1.2.2 yamt return(CMD_OK);
470 1.1.2.2 yamt }
471 1.1.2.2 yamt }
472 1.1.2.2 yamt argv += (optind);
473 1.1.2.2 yamt argc -= (optind);
474 1.1.2.2 yamt
475 1.1.2.2 yamt pager_open();
476 1.1.2.2 yamt
477 1.1.2.2 yamt sprintf(line, "Device Enumeration:\n");
478 1.1.2.2 yamt pager_output(line);
479 1.1.2.2 yamt
480 1.1.2.2 yamt for (i = 0; i < ndevs; i++) {
481 1.1.2.2 yamt sprintf(line, "%s\n", devsw[i].dv_name);
482 1.1.2.2 yamt if (pager_output(line))
483 1.1.2.2 yamt break;
484 1.1.2.2 yamt }
485 1.1.2.2 yamt
486 1.1.2.2 yamt pager_close();
487 1.1.2.2 yamt return(CMD_OK);
488 1.1.2.2 yamt }
489 1.1.2.2 yamt
490