installboot.c revision 1.20 1 1.20 wiz /* $NetBSD: installboot.c,v 1.20 2005/11/11 21:24:01 wiz Exp $ */
2 1.1 lukem
3 1.1 lukem /*-
4 1.1 lukem * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.1 lukem * All rights reserved.
6 1.1 lukem *
7 1.1 lukem * This code is derived from software contributed to The NetBSD Foundation
8 1.1 lukem * by Luke Mewburn of Wasabi Systems.
9 1.1 lukem *
10 1.1 lukem * Redistribution and use in source and binary forms, with or without
11 1.1 lukem * modification, are permitted provided that the following conditions
12 1.1 lukem * are met:
13 1.1 lukem * 1. Redistributions of source code must retain the above copyright
14 1.1 lukem * notice, this list of conditions and the following disclaimer.
15 1.1 lukem * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 lukem * notice, this list of conditions and the following disclaimer in the
17 1.1 lukem * documentation and/or other materials provided with the distribution.
18 1.1 lukem * 3. All advertising materials mentioning features or use of this software
19 1.1 lukem * must display the following acknowledgement:
20 1.1 lukem * This product includes software developed by the NetBSD
21 1.1 lukem * Foundation, Inc. and its contributors.
22 1.1 lukem * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 lukem * contributors may be used to endorse or promote products derived
24 1.1 lukem * from this software without specific prior written permission.
25 1.1 lukem *
26 1.1 lukem * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 lukem * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 lukem * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 lukem * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 lukem * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 lukem * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 lukem * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 lukem * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 lukem * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 lukem * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 lukem * POSSIBILITY OF SUCH DAMAGE.
37 1.1 lukem */
38 1.1 lukem
39 1.16 jmc #if HAVE_NBTOOL_CONFIG_H
40 1.16 jmc #include "nbtool_config.h"
41 1.16 jmc #endif
42 1.16 jmc
43 1.1 lukem #include <sys/cdefs.h>
44 1.1 lukem #if defined(__RCSID) && !defined(__lint)
45 1.20 wiz __RCSID("$NetBSD: installboot.c,v 1.20 2005/11/11 21:24:01 wiz Exp $");
46 1.1 lukem #endif /* !__lint */
47 1.1 lukem
48 1.1 lukem #include <sys/utsname.h>
49 1.1 lukem
50 1.1 lukem #include <assert.h>
51 1.1 lukem #include <err.h>
52 1.1 lukem #include <fcntl.h>
53 1.2 simonb #include <limits.h>
54 1.1 lukem #include <stdio.h>
55 1.1 lukem #include <stdlib.h>
56 1.11 dsl #include <stddef.h>
57 1.1 lukem #include <string.h>
58 1.1 lukem #include <unistd.h>
59 1.1 lukem
60 1.1 lukem #include "installboot.h"
61 1.1 lukem
62 1.1 lukem int main(int, char *[]);
63 1.11 dsl static void getmachine(ib_params *, const char *, const char *);
64 1.11 dsl static void getfstype(ib_params *, const char *, const char *);
65 1.11 dsl static void parseoptions(ib_params *, const char *);
66 1.1 lukem static void usage(void);
67 1.11 dsl static void options_usage(void);
68 1.11 dsl static void machine_usage(void);
69 1.11 dsl static void fstype_usage(void);
70 1.1 lukem
71 1.1 lukem static ib_params installboot_params;
72 1.1 lukem
73 1.11 dsl #define OFFSET(field) offsetof(ib_params, field)
74 1.11 dsl const struct option {
75 1.11 dsl const char *name; /* Name of option */
76 1.11 dsl ib_flags flag; /* Corresponding IB_xxx flag */
77 1.11 dsl enum { /* Type of option value... */
78 1.11 dsl OPT_BOOL, /* no value */
79 1.11 dsl OPT_INT, /* numeric value */
80 1.11 dsl OPT_WORD, /* space/tab/, terminated */
81 1.11 dsl OPT_STRING /* null terminated */
82 1.11 dsl } type;
83 1.11 dsl int offset; /* of field in ib_params */
84 1.11 dsl } options[] = {
85 1.11 dsl { "alphasum", IB_ALPHASUM, OPT_BOOL },
86 1.11 dsl { "append", IB_APPEND, OPT_BOOL },
87 1.11 dsl { "command", IB_COMMAND, OPT_STRING, OFFSET(command) },
88 1.11 dsl { "console", IB_CONSOLE, OPT_WORD, OFFSET(console) },
89 1.17 dsl { "ioaddr", IB_CONSADDR, OPT_INT, OFFSET(consaddr) },
90 1.15 dsl { "keymap", IB_KEYMAP, OPT_WORD, OFFSET(keymap) },
91 1.11 dsl { "password", IB_PASSWORD, OPT_WORD, OFFSET(password) },
92 1.11 dsl { "resetvideo", IB_RESETVIDEO, OPT_BOOL },
93 1.11 dsl { "speed", IB_CONSPEED, OPT_INT, OFFSET(conspeed) },
94 1.11 dsl { "sunsum", IB_SUNSUM, OPT_BOOL },
95 1.11 dsl { "timeout", IB_TIMEOUT, OPT_INT, OFFSET(timeout) },
96 1.11 dsl { NULL },
97 1.11 dsl };
98 1.11 dsl #undef OFFSET
99 1.11 dsl #define OPTION(params, type, opt) (*(type *)((char *)(params) + (opt)->offset))
100 1.11 dsl
101 1.1 lukem int
102 1.1 lukem main(int argc, char *argv[])
103 1.1 lukem {
104 1.1 lukem struct utsname utsname;
105 1.1 lukem ib_params *params;
106 1.6 lukem unsigned long lval;
107 1.1 lukem int ch, rv, mode;
108 1.1 lukem char *p;
109 1.1 lukem const char *op;
110 1.11 dsl ib_flags unsupported_flags;
111 1.1 lukem
112 1.1 lukem setprogname(argv[0]);
113 1.1 lukem params = &installboot_params;
114 1.1 lukem memset(params, 0, sizeof(*params));
115 1.8 lukem params->fsfd = -1;
116 1.8 lukem params->s1fd = -1;
117 1.1 lukem if ((p = getenv("MACHINE")) != NULL)
118 1.11 dsl getmachine(params, p, "$MACHINE");
119 1.1 lukem
120 1.19 dsl while ((ch = getopt(argc, argv, "b:B:cem:no:t:v")) != -1) {
121 1.1 lukem switch (ch) {
122 1.1 lukem
123 1.1 lukem case 'b':
124 1.8 lukem case 'B':
125 1.1 lukem if (*optarg == '\0')
126 1.1 lukem goto badblock;
127 1.6 lukem lval = strtoul(optarg, &p, 0);
128 1.6 lukem if (lval > UINT32_MAX || *p != '\0') {
129 1.1 lukem badblock:
130 1.1 lukem errx(1, "Invalid block number `%s'", optarg);
131 1.1 lukem }
132 1.8 lukem if (ch == 'b') {
133 1.8 lukem params->s1start = (uint32_t)lval;
134 1.8 lukem params->flags |= IB_STAGE1START;
135 1.8 lukem } else {
136 1.8 lukem params->s2start = (uint32_t)lval;
137 1.8 lukem params->flags |= IB_STAGE2START;
138 1.8 lukem }
139 1.1 lukem break;
140 1.1 lukem
141 1.1 lukem case 'c':
142 1.1 lukem params->flags |= IB_CLEAR;
143 1.1 lukem break;
144 1.1 lukem
145 1.19 dsl case 'e':
146 1.19 dsl params->flags |= IB_EDIT;
147 1.19 dsl break;
148 1.19 dsl
149 1.1 lukem case 'm':
150 1.11 dsl getmachine(params, optarg, "-m");
151 1.1 lukem break;
152 1.1 lukem
153 1.1 lukem case 'n':
154 1.1 lukem params->flags |= IB_NOWRITE;
155 1.1 lukem break;
156 1.1 lukem
157 1.1 lukem case 'o':
158 1.11 dsl parseoptions(params, optarg);
159 1.1 lukem break;
160 1.1 lukem
161 1.1 lukem case 't':
162 1.11 dsl getfstype(params, optarg, "-t");
163 1.1 lukem break;
164 1.1 lukem
165 1.1 lukem case 'v':
166 1.1 lukem params->flags |= IB_VERBOSE;
167 1.1 lukem break;
168 1.1 lukem
169 1.1 lukem case '?':
170 1.1 lukem default:
171 1.1 lukem usage();
172 1.1 lukem /* NOTREACHED */
173 1.1 lukem
174 1.1 lukem }
175 1.1 lukem }
176 1.1 lukem argc -= optind;
177 1.1 lukem argv += optind;
178 1.1 lukem
179 1.19 dsl if (params->flags & IB_CLEAR && params->flags & IB_EDIT)
180 1.19 dsl usage();
181 1.19 dsl if (argc < 1 || argc + 2 * !!(params->flags & (IB_CLEAR | IB_EDIT)) > 3)
182 1.1 lukem usage();
183 1.1 lukem
184 1.19 dsl /* set missing defaults */
185 1.1 lukem if (params->machine == NULL) {
186 1.1 lukem if (uname(&utsname) == -1)
187 1.1 lukem err(1, "Determine uname");
188 1.11 dsl getmachine(params, utsname.machine, "uname()");
189 1.11 dsl }
190 1.11 dsl
191 1.11 dsl /* Check that options are supported by this system */
192 1.11 dsl unsupported_flags = params->flags & ~params->machine->valid_flags;
193 1.19 dsl unsupported_flags &= ~(IB_VERBOSE | IB_NOWRITE | IB_CLEAR | IB_EDIT);
194 1.11 dsl if (unsupported_flags != 0) {
195 1.11 dsl int ndx;
196 1.11 dsl for (ndx = 0; options[ndx].name != NULL; ndx++) {
197 1.11 dsl if (unsupported_flags & options[ndx].flag)
198 1.11 dsl warnx("`-o %s' is not supported for %s",
199 1.11 dsl options[ndx].name, params->machine->name);
200 1.11 dsl }
201 1.11 dsl if (unsupported_flags & IB_STAGE1START)
202 1.11 dsl warnx("`-b bno' is not supported for %s",
203 1.11 dsl params->machine->name);
204 1.11 dsl if (unsupported_flags & IB_STAGE2START)
205 1.11 dsl warnx("`-B bno' is not supported for %s",
206 1.11 dsl params->machine->name);
207 1.11 dsl exit(1);
208 1.11 dsl }
209 1.11 dsl /* and some illegal combinations */
210 1.11 dsl if (params->flags & IB_STAGE1START && params->flags & IB_APPEND) {
211 1.11 dsl warnx("Can't use `-b bno' with `-o append'");
212 1.11 dsl exit(1);
213 1.11 dsl }
214 1.11 dsl if (params->flags & IB_CLEAR &&
215 1.11 dsl params->flags & (IB_STAGE1START | IB_STAGE2START | IB_APPEND)) {
216 1.11 dsl warnx("Can't use `-b bno', `-B bno' or `-o append' with `-c'");
217 1.11 dsl exit(1);
218 1.1 lukem }
219 1.1 lukem
220 1.1 lukem params->filesystem = argv[0];
221 1.1 lukem if (params->flags & IB_NOWRITE) {
222 1.1 lukem op = "only";
223 1.1 lukem mode = O_RDONLY;
224 1.1 lukem } else {
225 1.1 lukem op = "write";
226 1.1 lukem mode = O_RDWR;
227 1.1 lukem }
228 1.1 lukem if ((params->fsfd = open(params->filesystem, mode, 0600)) == -1)
229 1.1 lukem err(1, "Opening file system `%s' read-%s",
230 1.1 lukem params->filesystem, op);
231 1.9 lukem if (fstat(params->fsfd, ¶ms->fsstat) == -1)
232 1.9 lukem err(1, "Examining file system `%s'", params->filesystem);
233 1.6 lukem if (params->fstype != NULL) {
234 1.6 lukem if (! params->fstype->match(params))
235 1.18 isaki errx(1, "File system `%s' is not of type %s",
236 1.6 lukem params->filesystem, params->fstype->name);
237 1.6 lukem } else {
238 1.6 lukem params->fstype = &fstypes[0];
239 1.6 lukem while (params->fstype->name != NULL &&
240 1.6 lukem ! params->fstype->match(params))
241 1.6 lukem params->fstype++;
242 1.6 lukem if (params->fstype->name == NULL)
243 1.7 lukem errx(1, "File system `%s' is of an unknown type",
244 1.6 lukem params->filesystem);
245 1.6 lukem }
246 1.1 lukem
247 1.5 lukem if (argc >= 2) {
248 1.5 lukem params->stage1 = argv[1];
249 1.5 lukem if ((params->s1fd = open(params->stage1, O_RDONLY, 0600))
250 1.1 lukem == -1)
251 1.5 lukem err(1, "Opening primary bootstrap `%s'",
252 1.5 lukem params->stage1);
253 1.9 lukem if (fstat(params->s1fd, ¶ms->s1stat) == -1)
254 1.9 lukem err(1, "Examining primary bootstrap `%s'",
255 1.9 lukem params->stage1);
256 1.9 lukem if (!S_ISREG(params->s1stat.st_mode))
257 1.18 isaki errx(1, "`%s' must be a regular file", params->stage1);
258 1.5 lukem }
259 1.5 lukem if (argc == 3) {
260 1.5 lukem params->stage2 = argv[2];
261 1.1 lukem }
262 1.1 lukem assert(params->machine != NULL);
263 1.1 lukem
264 1.1 lukem if (params->flags & IB_VERBOSE) {
265 1.5 lukem printf("File system: %s\n", params->filesystem);
266 1.8 lukem printf("File system type: %s (blocksize %u, needswap %d)\n",
267 1.8 lukem params->fstype->name,
268 1.8 lukem params->fstype->blocksize, params->fstype->needswap);
269 1.19 dsl if (!(params->flags & IB_EDIT))
270 1.19 dsl printf("Primary bootstrap: %s\n",
271 1.19 dsl (params->flags & IB_CLEAR) ? "(to be cleared)"
272 1.19 dsl : params->stage1 ? params->stage1 : "(none)" );
273 1.5 lukem if (params->stage2 != NULL)
274 1.5 lukem printf("Secondary bootstrap: %s\n", params->stage2);
275 1.1 lukem }
276 1.1 lukem
277 1.19 dsl if (params->flags & IB_EDIT) {
278 1.19 dsl op = "Edit";
279 1.19 dsl rv = params->machine->editboot(params);
280 1.19 dsl } else if (params->flags & IB_CLEAR) {
281 1.1 lukem op = "Clear";
282 1.1 lukem rv = params->machine->clearboot(params);
283 1.1 lukem } else {
284 1.1 lukem op = "Set";
285 1.1 lukem rv = params->machine->setboot(params);
286 1.1 lukem }
287 1.1 lukem if (rv == 0)
288 1.5 lukem errx(1, "%s bootstrap operation failed", op);
289 1.1 lukem
290 1.9 lukem if (S_ISREG(params->fsstat.st_mode)) {
291 1.9 lukem if (fsync(params->fsfd) == -1)
292 1.9 lukem err(1, "Synchronising file system `%s'",
293 1.9 lukem params->filesystem);
294 1.9 lukem } else {
295 1.9 lukem /* Sync filesystems (to clean in-memory superblock?) */
296 1.9 lukem sync();
297 1.9 lukem }
298 1.1 lukem if (close(params->fsfd) == -1)
299 1.1 lukem err(1, "Closing file system `%s'", params->filesystem);
300 1.1 lukem if (argc == 2)
301 1.5 lukem if (close(params->s1fd) == -1)
302 1.5 lukem err(1, "Closing primary bootstrap `%s'",
303 1.5 lukem params->stage1);
304 1.1 lukem
305 1.1 lukem exit(0);
306 1.1 lukem /* NOTREACHED */
307 1.1 lukem }
308 1.1 lukem
309 1.11 dsl static void
310 1.11 dsl parseoptions(ib_params *params, const char *option)
311 1.1 lukem {
312 1.11 dsl char *cp;
313 1.11 dsl const struct option *opt;
314 1.11 dsl int len;
315 1.12 dsl unsigned long val;
316 1.1 lukem
317 1.1 lukem assert(params != NULL);
318 1.1 lukem assert(option != NULL);
319 1.1 lukem
320 1.11 dsl for (;; option += len) {
321 1.11 dsl option += strspn(option, ", \t");
322 1.11 dsl if (*option == 0)
323 1.11 dsl return;
324 1.11 dsl len = strcspn(option, "=,");
325 1.11 dsl for (opt = options; opt->name != NULL; opt++) {
326 1.11 dsl if (memcmp(option, opt->name, len) == 0
327 1.11 dsl && opt->name[len] == 0)
328 1.11 dsl break;
329 1.11 dsl }
330 1.11 dsl if (opt->name == NULL) {
331 1.11 dsl len = strcspn(option, ",");
332 1.11 dsl warnx("Unknown option `-o %.*s'", len, option);
333 1.11 dsl break;
334 1.11 dsl }
335 1.11 dsl params->flags |= opt->flag;
336 1.11 dsl if (opt->type == OPT_BOOL) {
337 1.11 dsl if (option[len] != '=')
338 1.11 dsl continue;
339 1.11 dsl warnx("Option `%s' must not have a value", opt->name);
340 1.11 dsl break;
341 1.11 dsl }
342 1.11 dsl if (option[len] != '=') {
343 1.11 dsl warnx("Option `%s' must have a value", opt->name);
344 1.11 dsl break;
345 1.1 lukem }
346 1.11 dsl option += len + 1;
347 1.11 dsl len = strcspn(option, ",");
348 1.11 dsl switch (opt->type) {
349 1.11 dsl case OPT_STRING:
350 1.11 dsl len = strlen(option);
351 1.11 dsl /* FALLTHROUGH */
352 1.11 dsl case OPT_WORD:
353 1.11 dsl cp = strdup(option);
354 1.11 dsl if (cp == NULL)
355 1.11 dsl err(1, "strdup");
356 1.11 dsl cp[len] = 0;
357 1.11 dsl OPTION(params, char *, opt) = cp;
358 1.11 dsl continue;
359 1.11 dsl case OPT_INT:
360 1.11 dsl val = strtoul(option, &cp, 0);
361 1.11 dsl if (cp > option + len || (*cp != 0 && *cp != ','))
362 1.11 dsl break;
363 1.11 dsl OPTION(params, int, opt) = val;
364 1.11 dsl if (OPTION(params, int, opt) != val)
365 1.11 dsl /* value got truncated on int convertion */
366 1.11 dsl break;
367 1.11 dsl continue;
368 1.11 dsl default:
369 1.13 petrov errx(1, "Internal error: option `%s' has invalid type %d",
370 1.11 dsl opt->name, opt->type);
371 1.11 dsl }
372 1.11 dsl warnx("Invalid option value `%s=%.*s'", opt->name, len, option);
373 1.11 dsl break;
374 1.1 lukem }
375 1.11 dsl options_usage();
376 1.11 dsl exit(1);
377 1.3 lukem }
378 1.3 lukem
379 1.11 dsl static void
380 1.11 dsl options_usage(void)
381 1.3 lukem {
382 1.11 dsl int ndx;
383 1.11 dsl const char *pfx;
384 1.3 lukem
385 1.11 dsl warnx("Valid options are:");
386 1.11 dsl pfx = "\t";
387 1.11 dsl for (ndx = 0; options[ndx].name != 0; ndx++) {
388 1.11 dsl fprintf(stderr, "%s%s", pfx, options[ndx].name);
389 1.11 dsl switch (options[ndx].type) {
390 1.11 dsl case OPT_INT:
391 1.11 dsl fprintf(stderr, "=number");
392 1.11 dsl break;
393 1.11 dsl case OPT_WORD:
394 1.11 dsl fprintf(stderr, "=word");
395 1.11 dsl break;
396 1.11 dsl case OPT_STRING:
397 1.11 dsl fprintf(stderr, "=string");
398 1.11 dsl break;
399 1.11 dsl default:
400 1.11 dsl break;
401 1.11 dsl }
402 1.11 dsl if ((ndx % 5) == 4)
403 1.11 dsl pfx = ",\n\t";
404 1.11 dsl else
405 1.11 dsl pfx = ", ";
406 1.11 dsl }
407 1.11 dsl fprintf(stderr, "\n");
408 1.3 lukem }
409 1.3 lukem
410 1.3 lukem int
411 1.3 lukem no_setboot(ib_params *params)
412 1.3 lukem {
413 1.3 lukem
414 1.7 lukem assert(params != NULL);
415 1.7 lukem
416 1.5 lukem warnx("%s: bootstrap installation is not supported",
417 1.3 lukem params->machine->name);
418 1.3 lukem return (0);
419 1.3 lukem }
420 1.3 lukem
421 1.3 lukem int
422 1.3 lukem no_clearboot(ib_params *params)
423 1.3 lukem {
424 1.3 lukem
425 1.7 lukem assert(params != NULL);
426 1.7 lukem
427 1.5 lukem warnx("%s: bootstrap removal is not supported",
428 1.3 lukem params->machine->name);
429 1.1 lukem return (0);
430 1.1 lukem }
431 1.1 lukem
432 1.19 dsl int
433 1.19 dsl no_editboot(ib_params *params)
434 1.19 dsl {
435 1.19 dsl
436 1.19 dsl assert(params != NULL);
437 1.19 dsl
438 1.19 dsl warnx("%s: bootstrap editing is not supported",
439 1.19 dsl params->machine->name);
440 1.19 dsl return (0);
441 1.19 dsl }
442 1.19 dsl
443 1.1 lukem
444 1.11 dsl static void
445 1.1 lukem getmachine(ib_params *param, const char *mach, const char *provider)
446 1.1 lukem {
447 1.1 lukem int i;
448 1.1 lukem
449 1.11 dsl assert(param != NULL);
450 1.11 dsl assert(mach != NULL);
451 1.11 dsl assert(provider != NULL);
452 1.11 dsl
453 1.11 dsl for (i = 0; machines[i].name != NULL; i++) {
454 1.11 dsl if (strcmp(machines[i].name, mach) == 0) {
455 1.11 dsl param->machine = &machines[i];
456 1.11 dsl return;
457 1.1 lukem }
458 1.1 lukem }
459 1.11 dsl warnx("Invalid machine `%s' from %s", mach, provider);
460 1.11 dsl machine_usage();
461 1.11 dsl exit(1);
462 1.11 dsl }
463 1.11 dsl
464 1.11 dsl static void
465 1.11 dsl machine_usage(void)
466 1.11 dsl {
467 1.11 dsl const char *prefix;
468 1.11 dsl int i;
469 1.11 dsl
470 1.1 lukem warnx("Supported machines are:");
471 1.10 lukem #define MACHS_PER_LINE 9
472 1.10 lukem prefix="";
473 1.1 lukem for (i = 0; machines[i].name != NULL; i++) {
474 1.10 lukem if (i == 0)
475 1.10 lukem prefix="\t";
476 1.10 lukem else if (i % MACHS_PER_LINE)
477 1.10 lukem prefix=", ";
478 1.10 lukem else
479 1.10 lukem prefix=",\n\t";
480 1.10 lukem fprintf(stderr, "%s%s", prefix, machines[i].name);
481 1.1 lukem }
482 1.10 lukem fputs("\n", stderr);
483 1.6 lukem }
484 1.6 lukem
485 1.11 dsl static void
486 1.6 lukem getfstype(ib_params *param, const char *fstype, const char *provider)
487 1.6 lukem {
488 1.11 dsl int i;
489 1.11 dsl
490 1.11 dsl assert(param != NULL);
491 1.11 dsl assert(fstype != NULL);
492 1.11 dsl assert(provider != NULL);
493 1.11 dsl
494 1.11 dsl for (i = 0; fstypes[i].name != NULL; i++) {
495 1.11 dsl if (strcmp(fstypes[i].name, fstype) == 0) {
496 1.11 dsl param->fstype = &fstypes[i];
497 1.11 dsl return;
498 1.11 dsl }
499 1.11 dsl }
500 1.11 dsl warnx("Invalid file system type `%s' from %s", fstype, provider);
501 1.11 dsl fstype_usage();
502 1.11 dsl exit(1);
503 1.11 dsl }
504 1.11 dsl
505 1.11 dsl static void
506 1.11 dsl fstype_usage(void)
507 1.11 dsl {
508 1.10 lukem const char *prefix;
509 1.6 lukem int i;
510 1.6 lukem
511 1.6 lukem warnx("Supported file system types are:");
512 1.10 lukem #define FSTYPES_PER_LINE 9
513 1.10 lukem prefix="";
514 1.6 lukem for (i = 0; fstypes[i].name != NULL; i++) {
515 1.10 lukem if (i == 0)
516 1.10 lukem prefix="\t";
517 1.10 lukem else if (i % FSTYPES_PER_LINE)
518 1.10 lukem prefix=", ";
519 1.10 lukem else
520 1.10 lukem prefix=",\n\t";
521 1.10 lukem fprintf(stderr, "%s%s", prefix, fstypes[i].name);
522 1.6 lukem }
523 1.10 lukem fputs("\n", stderr);
524 1.1 lukem }
525 1.1 lukem
526 1.1 lukem static void
527 1.1 lukem usage(void)
528 1.1 lukem {
529 1.1 lukem const char *prog;
530 1.1 lukem
531 1.1 lukem prog = getprogname();
532 1.1 lukem fprintf(stderr,
533 1.20 wiz "usage: %s [-nv] [-B s2bno] [-b s1bno] [-m machine] [-o options]\n"
534 1.20 wiz "\t\t [-t fstype] filesystem primary [secondary]\n"
535 1.19 dsl "usage: %s -c [-nv] [-m machine] [-o options] [-t fstype] filesystem\n"
536 1.19 dsl "usage: %s -e [-nv] [-m machine] [-o options] bootstrap\n",
537 1.19 dsl prog, prog, prog);
538 1.11 dsl machine_usage();
539 1.11 dsl fstype_usage();
540 1.11 dsl options_usage();
541 1.1 lukem exit(1);
542 1.1 lukem }
543