2004-08-16 02:00:12 +04:00
|
|
|
/* $NetBSD: installboot.c,v 1.17 2004/08/15 22:00:12 dsl Exp $ */
|
2002-04-03 09:21:16 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Luke Mewburn of Wasabi Systems.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2004-06-21 02:20:14 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
2002-04-03 09:21:16 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#if defined(__RCSID) && !defined(__lint)
|
2004-08-16 02:00:12 +04:00
|
|
|
__RCSID("$NetBSD: installboot.c,v 1.17 2004/08/15 22:00:12 dsl Exp $");
|
2002-04-03 09:21:16 +04:00
|
|
|
#endif /* !__lint */
|
|
|
|
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <fcntl.h>
|
2002-04-04 07:27:53 +04:00
|
|
|
#include <limits.h>
|
2002-04-03 09:21:16 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2003-04-15 18:22:13 +04:00
|
|
|
#include <stddef.h>
|
2002-04-03 09:21:16 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "installboot.h"
|
|
|
|
|
|
|
|
int main(int, char *[]);
|
2003-04-15 18:22:13 +04:00
|
|
|
static void getmachine(ib_params *, const char *, const char *);
|
|
|
|
static void getfstype(ib_params *, const char *, const char *);
|
|
|
|
static void parseoptions(ib_params *, const char *);
|
2002-04-03 09:21:16 +04:00
|
|
|
static void usage(void);
|
2003-04-15 18:22:13 +04:00
|
|
|
static void options_usage(void);
|
|
|
|
static void machine_usage(void);
|
|
|
|
static void fstype_usage(void);
|
2002-04-03 09:21:16 +04:00
|
|
|
|
|
|
|
static ib_params installboot_params;
|
|
|
|
|
2003-04-15 18:22:13 +04:00
|
|
|
#define OFFSET(field) offsetof(ib_params, field)
|
|
|
|
const struct option {
|
|
|
|
const char *name; /* Name of option */
|
|
|
|
ib_flags flag; /* Corresponding IB_xxx flag */
|
|
|
|
enum { /* Type of option value... */
|
|
|
|
OPT_BOOL, /* no value */
|
|
|
|
OPT_INT, /* numeric value */
|
|
|
|
OPT_WORD, /* space/tab/, terminated */
|
|
|
|
OPT_STRING /* null terminated */
|
|
|
|
} type;
|
|
|
|
int offset; /* of field in ib_params */
|
|
|
|
} options[] = {
|
|
|
|
{ "alphasum", IB_ALPHASUM, OPT_BOOL },
|
|
|
|
{ "append", IB_APPEND, OPT_BOOL },
|
|
|
|
{ "command", IB_COMMAND, OPT_STRING, OFFSET(command) },
|
|
|
|
{ "console", IB_CONSOLE, OPT_WORD, OFFSET(console) },
|
2004-08-16 02:00:12 +04:00
|
|
|
{ "ioaddr", IB_CONSADDR, OPT_INT, OFFSET(consaddr) },
|
2004-03-14 01:51:50 +03:00
|
|
|
{ "keymap", IB_KEYMAP, OPT_WORD, OFFSET(keymap) },
|
2003-04-15 18:22:13 +04:00
|
|
|
{ "password", IB_PASSWORD, OPT_WORD, OFFSET(password) },
|
|
|
|
{ "resetvideo", IB_RESETVIDEO, OPT_BOOL },
|
|
|
|
{ "speed", IB_CONSPEED, OPT_INT, OFFSET(conspeed) },
|
|
|
|
{ "sunsum", IB_SUNSUM, OPT_BOOL },
|
|
|
|
{ "timeout", IB_TIMEOUT, OPT_INT, OFFSET(timeout) },
|
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
#undef OFFSET
|
|
|
|
#define OPTION(params, type, opt) (*(type *)((char *)(params) + (opt)->offset))
|
|
|
|
|
2002-04-03 09:21:16 +04:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct utsname utsname;
|
|
|
|
ib_params *params;
|
2002-04-19 11:08:51 +04:00
|
|
|
unsigned long lval;
|
2002-04-03 09:21:16 +04:00
|
|
|
int ch, rv, mode;
|
|
|
|
char *p;
|
|
|
|
const char *op;
|
2003-04-15 18:22:13 +04:00
|
|
|
ib_flags unsupported_flags;
|
2002-04-03 09:21:16 +04:00
|
|
|
|
|
|
|
setprogname(argv[0]);
|
|
|
|
params = &installboot_params;
|
|
|
|
memset(params, 0, sizeof(*params));
|
user visible stuff:
- add `-B s2bno', to provide the starting block for the secondary bootstrap.
intended for use on platforms where the blocks of the stage2 bootstrap
are hardcoded into the stage1 bootstrap (currently: sparc, sun2)
- don't support `-b s1bno' for sparc or sun2, since the primary is always
at a fixed location on the disk.
- if `filesystem' is a regular file, use fsync(2) instead of sync(2)
code changes:
- add hardcode_stage2(), which uses -B s2bno and the size of the
provided secondary bootstrap (as an actual file, not as part of the
`filesystem' argument) to provide a sequential list of blocks from s2bno,
each block being the appropriate file system size (from
params->fstype->blocksize)
- add blocksize and needswap run-time parameters to ib_fs
- in *_match(), set params->fstype->blocksize to the underlying block size
(8KB for raw), and params->fstype->needswap as appropriate
- rename IB_STARTBLOCK to IB_STAGE1START, and add IB_STAGE2START
- use hardcode_stage2() to implement raw_findstage2() and IB_STAGE2BLOCK
support for ffs_findstage2()
- improve some comments, add some prototypes, ...
2002-05-14 10:18:50 +04:00
|
|
|
params->fsfd = -1;
|
|
|
|
params->s1fd = -1;
|
2002-04-03 09:21:16 +04:00
|
|
|
if ((p = getenv("MACHINE")) != NULL)
|
2003-04-15 18:22:13 +04:00
|
|
|
getmachine(params, p, "$MACHINE");
|
2002-04-03 09:21:16 +04:00
|
|
|
|
user visible stuff:
- add `-B s2bno', to provide the starting block for the secondary bootstrap.
intended for use on platforms where the blocks of the stage2 bootstrap
are hardcoded into the stage1 bootstrap (currently: sparc, sun2)
- don't support `-b s1bno' for sparc or sun2, since the primary is always
at a fixed location on the disk.
- if `filesystem' is a regular file, use fsync(2) instead of sync(2)
code changes:
- add hardcode_stage2(), which uses -B s2bno and the size of the
provided secondary bootstrap (as an actual file, not as part of the
`filesystem' argument) to provide a sequential list of blocks from s2bno,
each block being the appropriate file system size (from
params->fstype->blocksize)
- add blocksize and needswap run-time parameters to ib_fs
- in *_match(), set params->fstype->blocksize to the underlying block size
(8KB for raw), and params->fstype->needswap as appropriate
- rename IB_STARTBLOCK to IB_STAGE1START, and add IB_STAGE2START
- use hardcode_stage2() to implement raw_findstage2() and IB_STAGE2BLOCK
support for ffs_findstage2()
- improve some comments, add some prototypes, ...
2002-05-14 10:18:50 +04:00
|
|
|
while ((ch = getopt(argc, argv, "b:B:cm:no:t:v")) != -1) {
|
2002-04-03 09:21:16 +04:00
|
|
|
switch (ch) {
|
|
|
|
|
|
|
|
case 'b':
|
user visible stuff:
- add `-B s2bno', to provide the starting block for the secondary bootstrap.
intended for use on platforms where the blocks of the stage2 bootstrap
are hardcoded into the stage1 bootstrap (currently: sparc, sun2)
- don't support `-b s1bno' for sparc or sun2, since the primary is always
at a fixed location on the disk.
- if `filesystem' is a regular file, use fsync(2) instead of sync(2)
code changes:
- add hardcode_stage2(), which uses -B s2bno and the size of the
provided secondary bootstrap (as an actual file, not as part of the
`filesystem' argument) to provide a sequential list of blocks from s2bno,
each block being the appropriate file system size (from
params->fstype->blocksize)
- add blocksize and needswap run-time parameters to ib_fs
- in *_match(), set params->fstype->blocksize to the underlying block size
(8KB for raw), and params->fstype->needswap as appropriate
- rename IB_STARTBLOCK to IB_STAGE1START, and add IB_STAGE2START
- use hardcode_stage2() to implement raw_findstage2() and IB_STAGE2BLOCK
support for ffs_findstage2()
- improve some comments, add some prototypes, ...
2002-05-14 10:18:50 +04:00
|
|
|
case 'B':
|
2002-04-03 09:21:16 +04:00
|
|
|
if (*optarg == '\0')
|
|
|
|
goto badblock;
|
2002-04-19 11:08:51 +04:00
|
|
|
lval = strtoul(optarg, &p, 0);
|
|
|
|
if (lval > UINT32_MAX || *p != '\0') {
|
2002-04-03 09:21:16 +04:00
|
|
|
badblock:
|
|
|
|
errx(1, "Invalid block number `%s'", optarg);
|
|
|
|
}
|
user visible stuff:
- add `-B s2bno', to provide the starting block for the secondary bootstrap.
intended for use on platforms where the blocks of the stage2 bootstrap
are hardcoded into the stage1 bootstrap (currently: sparc, sun2)
- don't support `-b s1bno' for sparc or sun2, since the primary is always
at a fixed location on the disk.
- if `filesystem' is a regular file, use fsync(2) instead of sync(2)
code changes:
- add hardcode_stage2(), which uses -B s2bno and the size of the
provided secondary bootstrap (as an actual file, not as part of the
`filesystem' argument) to provide a sequential list of blocks from s2bno,
each block being the appropriate file system size (from
params->fstype->blocksize)
- add blocksize and needswap run-time parameters to ib_fs
- in *_match(), set params->fstype->blocksize to the underlying block size
(8KB for raw), and params->fstype->needswap as appropriate
- rename IB_STARTBLOCK to IB_STAGE1START, and add IB_STAGE2START
- use hardcode_stage2() to implement raw_findstage2() and IB_STAGE2BLOCK
support for ffs_findstage2()
- improve some comments, add some prototypes, ...
2002-05-14 10:18:50 +04:00
|
|
|
if (ch == 'b') {
|
|
|
|
params->s1start = (uint32_t)lval;
|
|
|
|
params->flags |= IB_STAGE1START;
|
|
|
|
} else {
|
|
|
|
params->s2start = (uint32_t)lval;
|
|
|
|
params->flags |= IB_STAGE2START;
|
|
|
|
}
|
2002-04-03 09:21:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
params->flags |= IB_CLEAR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
2003-04-15 18:22:13 +04:00
|
|
|
getmachine(params, optarg, "-m");
|
2002-04-03 09:21:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
params->flags |= IB_NOWRITE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'o':
|
2003-04-15 18:22:13 +04:00
|
|
|
parseoptions(params, optarg);
|
2002-04-03 09:21:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
2003-04-15 18:22:13 +04:00
|
|
|
getfstype(params, optarg, "-t");
|
2002-04-03 09:21:16 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
params->flags |= IB_VERBOSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (((params->flags & IB_CLEAR) != 0 && argc != 1) ||
|
2002-04-12 10:50:41 +04:00
|
|
|
((params->flags & IB_CLEAR) == 0 && (argc < 2 || argc > 3)))
|
2002-04-03 09:21:16 +04:00
|
|
|
usage();
|
|
|
|
|
|
|
|
/* set missing defaults */
|
|
|
|
if (params->machine == NULL) {
|
|
|
|
if (uname(&utsname) == -1)
|
|
|
|
err(1, "Determine uname");
|
2003-04-15 18:22:13 +04:00
|
|
|
getmachine(params, utsname.machine, "uname()");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that options are supported by this system */
|
|
|
|
unsupported_flags = params->flags & ~params->machine->valid_flags;
|
|
|
|
unsupported_flags &= ~(IB_VERBOSE | IB_NOWRITE |IB_CLEAR);
|
|
|
|
if (unsupported_flags != 0) {
|
|
|
|
int ndx;
|
|
|
|
for (ndx = 0; options[ndx].name != NULL; ndx++) {
|
|
|
|
if (unsupported_flags & options[ndx].flag)
|
|
|
|
warnx("`-o %s' is not supported for %s",
|
|
|
|
options[ndx].name, params->machine->name);
|
|
|
|
}
|
|
|
|
if (unsupported_flags & IB_STAGE1START)
|
|
|
|
warnx("`-b bno' is not supported for %s",
|
|
|
|
params->machine->name);
|
|
|
|
if (unsupported_flags & IB_STAGE2START)
|
|
|
|
warnx("`-B bno' is not supported for %s",
|
|
|
|
params->machine->name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
/* and some illegal combinations */
|
|
|
|
if (params->flags & IB_STAGE1START && params->flags & IB_APPEND) {
|
|
|
|
warnx("Can't use `-b bno' with `-o append'");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (params->flags & IB_CLEAR &&
|
|
|
|
params->flags & (IB_STAGE1START | IB_STAGE2START | IB_APPEND)) {
|
|
|
|
warnx("Can't use `-b bno', `-B bno' or `-o append' with `-c'");
|
|
|
|
exit(1);
|
2002-04-03 09:21:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
params->filesystem = argv[0];
|
|
|
|
if (params->flags & IB_NOWRITE) {
|
|
|
|
op = "only";
|
|
|
|
mode = O_RDONLY;
|
|
|
|
} else {
|
|
|
|
op = "write";
|
|
|
|
mode = O_RDWR;
|
|
|
|
}
|
|
|
|
if ((params->fsfd = open(params->filesystem, mode, 0600)) == -1)
|
|
|
|
err(1, "Opening file system `%s' read-%s",
|
|
|
|
params->filesystem, op);
|
2002-05-15 06:18:22 +04:00
|
|
|
if (fstat(params->fsfd, ¶ms->fsstat) == -1)
|
|
|
|
err(1, "Examining file system `%s'", params->filesystem);
|
2002-04-19 11:08:51 +04:00
|
|
|
if (params->fstype != NULL) {
|
|
|
|
if (! params->fstype->match(params))
|
|
|
|
err(1, "File system `%s' is not of type %s",
|
|
|
|
params->filesystem, params->fstype->name);
|
|
|
|
} else {
|
|
|
|
params->fstype = &fstypes[0];
|
|
|
|
while (params->fstype->name != NULL &&
|
|
|
|
! params->fstype->match(params))
|
|
|
|
params->fstype++;
|
|
|
|
if (params->fstype->name == NULL)
|
2002-04-30 18:21:17 +04:00
|
|
|
errx(1, "File system `%s' is of an unknown type",
|
2002-04-19 11:08:51 +04:00
|
|
|
params->filesystem);
|
|
|
|
}
|
2002-04-03 09:21:16 +04:00
|
|
|
|
2002-04-12 10:50:41 +04:00
|
|
|
if (argc >= 2) {
|
|
|
|
params->stage1 = argv[1];
|
|
|
|
if ((params->s1fd = open(params->stage1, O_RDONLY, 0600))
|
2002-04-03 09:21:16 +04:00
|
|
|
== -1)
|
2002-04-12 10:50:41 +04:00
|
|
|
err(1, "Opening primary bootstrap `%s'",
|
|
|
|
params->stage1);
|
2002-05-15 06:18:22 +04:00
|
|
|
if (fstat(params->s1fd, ¶ms->s1stat) == -1)
|
|
|
|
err(1, "Examining primary bootstrap `%s'",
|
|
|
|
params->stage1);
|
|
|
|
if (!S_ISREG(params->s1stat.st_mode))
|
|
|
|
err(1, "`%s' must be a regular file", params->stage1);
|
2002-04-12 10:50:41 +04:00
|
|
|
}
|
|
|
|
if (argc == 3) {
|
|
|
|
params->stage2 = argv[2];
|
2002-04-03 09:21:16 +04:00
|
|
|
}
|
|
|
|
assert(params->machine != NULL);
|
|
|
|
|
|
|
|
if (params->flags & IB_VERBOSE) {
|
2002-04-12 10:50:41 +04:00
|
|
|
printf("File system: %s\n", params->filesystem);
|
user visible stuff:
- add `-B s2bno', to provide the starting block for the secondary bootstrap.
intended for use on platforms where the blocks of the stage2 bootstrap
are hardcoded into the stage1 bootstrap (currently: sparc, sun2)
- don't support `-b s1bno' for sparc or sun2, since the primary is always
at a fixed location on the disk.
- if `filesystem' is a regular file, use fsync(2) instead of sync(2)
code changes:
- add hardcode_stage2(), which uses -B s2bno and the size of the
provided secondary bootstrap (as an actual file, not as part of the
`filesystem' argument) to provide a sequential list of blocks from s2bno,
each block being the appropriate file system size (from
params->fstype->blocksize)
- add blocksize and needswap run-time parameters to ib_fs
- in *_match(), set params->fstype->blocksize to the underlying block size
(8KB for raw), and params->fstype->needswap as appropriate
- rename IB_STARTBLOCK to IB_STAGE1START, and add IB_STAGE2START
- use hardcode_stage2() to implement raw_findstage2() and IB_STAGE2BLOCK
support for ffs_findstage2()
- improve some comments, add some prototypes, ...
2002-05-14 10:18:50 +04:00
|
|
|
printf("File system type: %s (blocksize %u, needswap %d)\n",
|
|
|
|
params->fstype->name,
|
|
|
|
params->fstype->blocksize, params->fstype->needswap);
|
2002-04-12 10:50:41 +04:00
|
|
|
printf("Primary bootstrap: %s\n",
|
2002-04-03 09:21:16 +04:00
|
|
|
(params->flags & IB_CLEAR) ? "(to be cleared)"
|
2002-04-12 10:50:41 +04:00
|
|
|
: params->stage1);
|
|
|
|
if (params->stage2 != NULL)
|
|
|
|
printf("Secondary bootstrap: %s\n", params->stage2);
|
2002-04-03 09:21:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (params->flags & IB_CLEAR) {
|
|
|
|
op = "Clear";
|
|
|
|
rv = params->machine->clearboot(params);
|
|
|
|
} else {
|
|
|
|
op = "Set";
|
|
|
|
rv = params->machine->setboot(params);
|
|
|
|
}
|
|
|
|
if (rv == 0)
|
2002-04-12 10:50:41 +04:00
|
|
|
errx(1, "%s bootstrap operation failed", op);
|
2002-04-03 09:21:16 +04:00
|
|
|
|
2002-05-15 06:18:22 +04:00
|
|
|
if (S_ISREG(params->fsstat.st_mode)) {
|
|
|
|
if (fsync(params->fsfd) == -1)
|
|
|
|
err(1, "Synchronising file system `%s'",
|
|
|
|
params->filesystem);
|
|
|
|
} else {
|
|
|
|
/* Sync filesystems (to clean in-memory superblock?) */
|
|
|
|
sync();
|
|
|
|
}
|
2002-04-03 09:21:16 +04:00
|
|
|
if (close(params->fsfd) == -1)
|
|
|
|
err(1, "Closing file system `%s'", params->filesystem);
|
|
|
|
if (argc == 2)
|
2002-04-12 10:50:41 +04:00
|
|
|
if (close(params->s1fd) == -1)
|
|
|
|
err(1, "Closing primary bootstrap `%s'",
|
|
|
|
params->stage1);
|
2002-04-03 09:21:16 +04:00
|
|
|
|
|
|
|
exit(0);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2003-04-15 18:22:13 +04:00
|
|
|
static void
|
|
|
|
parseoptions(ib_params *params, const char *option)
|
2002-04-03 09:21:16 +04:00
|
|
|
{
|
2003-04-15 18:22:13 +04:00
|
|
|
char *cp;
|
|
|
|
const struct option *opt;
|
|
|
|
int len;
|
2003-04-29 13:39:23 +04:00
|
|
|
unsigned long val;
|
2002-04-03 09:21:16 +04:00
|
|
|
|
|
|
|
assert(params != NULL);
|
|
|
|
assert(option != NULL);
|
|
|
|
|
2003-04-15 18:22:13 +04:00
|
|
|
for (;; option += len) {
|
|
|
|
option += strspn(option, ", \t");
|
|
|
|
if (*option == 0)
|
|
|
|
return;
|
|
|
|
len = strcspn(option, "=,");
|
|
|
|
for (opt = options; opt->name != NULL; opt++) {
|
|
|
|
if (memcmp(option, opt->name, len) == 0
|
|
|
|
&& opt->name[len] == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (opt->name == NULL) {
|
|
|
|
len = strcspn(option, ",");
|
|
|
|
warnx("Unknown option `-o %.*s'", len, option);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
params->flags |= opt->flag;
|
|
|
|
if (opt->type == OPT_BOOL) {
|
|
|
|
if (option[len] != '=')
|
|
|
|
continue;
|
|
|
|
warnx("Option `%s' must not have a value", opt->name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (option[len] != '=') {
|
|
|
|
warnx("Option `%s' must have a value", opt->name);
|
|
|
|
break;
|
2002-04-03 09:21:16 +04:00
|
|
|
}
|
2003-04-15 18:22:13 +04:00
|
|
|
option += len + 1;
|
|
|
|
len = strcspn(option, ",");
|
|
|
|
switch (opt->type) {
|
|
|
|
case OPT_STRING:
|
|
|
|
len = strlen(option);
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case OPT_WORD:
|
|
|
|
cp = strdup(option);
|
|
|
|
if (cp == NULL)
|
|
|
|
err(1, "strdup");
|
|
|
|
cp[len] = 0;
|
|
|
|
OPTION(params, char *, opt) = cp;
|
|
|
|
continue;
|
|
|
|
case OPT_INT:
|
|
|
|
val = strtoul(option, &cp, 0);
|
|
|
|
if (cp > option + len || (*cp != 0 && *cp != ','))
|
|
|
|
break;
|
|
|
|
OPTION(params, int, opt) = val;
|
|
|
|
if (OPTION(params, int, opt) != val)
|
|
|
|
/* value got truncated on int convertion */
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
default:
|
2003-05-09 00:33:44 +04:00
|
|
|
errx(1, "Internal error: option `%s' has invalid type %d",
|
2003-04-15 18:22:13 +04:00
|
|
|
opt->name, opt->type);
|
|
|
|
}
|
|
|
|
warnx("Invalid option value `%s=%.*s'", opt->name, len, option);
|
|
|
|
break;
|
2002-04-03 09:21:16 +04:00
|
|
|
}
|
2003-04-15 18:22:13 +04:00
|
|
|
options_usage();
|
|
|
|
exit(1);
|
2002-04-03 09:21:16 +04:00
|
|
|
}
|
|
|
|
|
2003-04-15 18:22:13 +04:00
|
|
|
static void
|
|
|
|
options_usage(void)
|
2002-04-11 11:56:13 +04:00
|
|
|
{
|
2003-04-15 18:22:13 +04:00
|
|
|
int ndx;
|
|
|
|
const char *pfx;
|
|
|
|
|
|
|
|
warnx("Valid options are:");
|
|
|
|
pfx = "\t";
|
|
|
|
for (ndx = 0; options[ndx].name != 0; ndx++) {
|
|
|
|
fprintf(stderr, "%s%s", pfx, options[ndx].name);
|
|
|
|
switch (options[ndx].type) {
|
|
|
|
case OPT_INT:
|
|
|
|
fprintf(stderr, "=number");
|
|
|
|
break;
|
|
|
|
case OPT_WORD:
|
|
|
|
fprintf(stderr, "=word");
|
|
|
|
break;
|
|
|
|
case OPT_STRING:
|
|
|
|
fprintf(stderr, "=string");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((ndx % 5) == 4)
|
|
|
|
pfx = ",\n\t";
|
|
|
|
else
|
|
|
|
pfx = ", ";
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
2002-04-11 11:56:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
no_setboot(ib_params *params)
|
|
|
|
{
|
|
|
|
|
2002-04-30 18:21:17 +04:00
|
|
|
assert(params != NULL);
|
|
|
|
|
2002-04-12 10:50:41 +04:00
|
|
|
/* bootstrap installation is not supported */
|
|
|
|
warnx("%s: bootstrap installation is not supported",
|
2002-04-11 11:56:13 +04:00
|
|
|
params->machine->name);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
no_clearboot(ib_params *params)
|
|
|
|
{
|
|
|
|
|
2002-04-30 18:21:17 +04:00
|
|
|
assert(params != NULL);
|
|
|
|
|
2002-04-12 10:50:41 +04:00
|
|
|
/* bootstrap removal is not supported */
|
|
|
|
warnx("%s: bootstrap removal is not supported",
|
2002-04-11 11:56:13 +04:00
|
|
|
params->machine->name);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-04-03 09:21:16 +04:00
|
|
|
|
2003-04-15 18:22:13 +04:00
|
|
|
static void
|
2002-04-03 09:21:16 +04:00
|
|
|
getmachine(ib_params *param, const char *mach, const char *provider)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2003-04-15 18:22:13 +04:00
|
|
|
assert(param != NULL);
|
|
|
|
assert(mach != NULL);
|
|
|
|
assert(provider != NULL);
|
|
|
|
|
|
|
|
for (i = 0; machines[i].name != NULL; i++) {
|
|
|
|
if (strcmp(machines[i].name, mach) == 0) {
|
|
|
|
param->machine = &machines[i];
|
|
|
|
return;
|
2002-04-03 09:21:16 +04:00
|
|
|
}
|
|
|
|
}
|
2003-04-15 18:22:13 +04:00
|
|
|
warnx("Invalid machine `%s' from %s", mach, provider);
|
|
|
|
machine_usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
machine_usage(void)
|
|
|
|
{
|
|
|
|
const char *prefix;
|
|
|
|
int i;
|
|
|
|
|
2002-04-03 09:21:16 +04:00
|
|
|
warnx("Supported machines are:");
|
2002-05-20 18:38:38 +04:00
|
|
|
#define MACHS_PER_LINE 9
|
|
|
|
prefix="";
|
2002-04-03 09:21:16 +04:00
|
|
|
for (i = 0; machines[i].name != NULL; i++) {
|
2002-05-20 18:38:38 +04:00
|
|
|
if (i == 0)
|
|
|
|
prefix="\t";
|
|
|
|
else if (i % MACHS_PER_LINE)
|
|
|
|
prefix=", ";
|
|
|
|
else
|
|
|
|
prefix=",\n\t";
|
|
|
|
fprintf(stderr, "%s%s", prefix, machines[i].name);
|
2002-04-03 09:21:16 +04:00
|
|
|
}
|
2002-05-20 18:38:38 +04:00
|
|
|
fputs("\n", stderr);
|
2002-04-03 09:21:16 +04:00
|
|
|
}
|
|
|
|
|
2003-04-15 18:22:13 +04:00
|
|
|
static void
|
2002-04-19 11:08:51 +04:00
|
|
|
getfstype(ib_params *param, const char *fstype, const char *provider)
|
|
|
|
{
|
2003-04-15 18:22:13 +04:00
|
|
|
int i;
|
2002-04-19 11:08:51 +04:00
|
|
|
|
2003-04-15 18:22:13 +04:00
|
|
|
assert(param != NULL);
|
|
|
|
assert(fstype != NULL);
|
|
|
|
assert(provider != NULL);
|
|
|
|
|
|
|
|
for (i = 0; fstypes[i].name != NULL; i++) {
|
|
|
|
if (strcmp(fstypes[i].name, fstype) == 0) {
|
|
|
|
param->fstype = &fstypes[i];
|
|
|
|
return;
|
2002-04-19 11:08:51 +04:00
|
|
|
}
|
|
|
|
}
|
2003-04-15 18:22:13 +04:00
|
|
|
warnx("Invalid file system type `%s' from %s", fstype, provider);
|
|
|
|
fstype_usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fstype_usage(void)
|
|
|
|
{
|
|
|
|
const char *prefix;
|
|
|
|
int i;
|
|
|
|
|
2002-04-19 11:08:51 +04:00
|
|
|
warnx("Supported file system types are:");
|
2002-05-20 18:38:38 +04:00
|
|
|
#define FSTYPES_PER_LINE 9
|
|
|
|
prefix="";
|
2002-04-19 11:08:51 +04:00
|
|
|
for (i = 0; fstypes[i].name != NULL; i++) {
|
2002-05-20 18:38:38 +04:00
|
|
|
if (i == 0)
|
|
|
|
prefix="\t";
|
|
|
|
else if (i % FSTYPES_PER_LINE)
|
|
|
|
prefix=", ";
|
|
|
|
else
|
|
|
|
prefix=",\n\t";
|
|
|
|
fprintf(stderr, "%s%s", prefix, fstypes[i].name);
|
2002-04-19 11:08:51 +04:00
|
|
|
}
|
2002-05-20 18:38:38 +04:00
|
|
|
fputs("\n", stderr);
|
2002-04-19 11:08:51 +04:00
|
|
|
}
|
|
|
|
|
2002-04-03 09:21:16 +04:00
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
const char *prog;
|
|
|
|
|
|
|
|
prog = getprogname();
|
|
|
|
fprintf(stderr,
|
2004-01-06 02:23:32 +03:00
|
|
|
"usage: %s [-nv] [-m machine] [-o options] [-t fstype]\n"
|
user visible stuff:
- add `-B s2bno', to provide the starting block for the secondary bootstrap.
intended for use on platforms where the blocks of the stage2 bootstrap
are hardcoded into the stage1 bootstrap (currently: sparc, sun2)
- don't support `-b s1bno' for sparc or sun2, since the primary is always
at a fixed location on the disk.
- if `filesystem' is a regular file, use fsync(2) instead of sync(2)
code changes:
- add hardcode_stage2(), which uses -B s2bno and the size of the
provided secondary bootstrap (as an actual file, not as part of the
`filesystem' argument) to provide a sequential list of blocks from s2bno,
each block being the appropriate file system size (from
params->fstype->blocksize)
- add blocksize and needswap run-time parameters to ib_fs
- in *_match(), set params->fstype->blocksize to the underlying block size
(8KB for raw), and params->fstype->needswap as appropriate
- rename IB_STARTBLOCK to IB_STAGE1START, and add IB_STAGE2START
- use hardcode_stage2() to implement raw_findstage2() and IB_STAGE2BLOCK
support for ffs_findstage2()
- improve some comments, add some prototypes, ...
2002-05-14 10:18:50 +04:00
|
|
|
"\t\t [-b s1start] [-B s2start] filesystem primary [secondary]\n"
|
2004-01-06 02:23:32 +03:00
|
|
|
"usage: %s -c [-nv] [-m machine] [-o options] [-t fstype] filesystem\n",
|
2002-04-03 09:21:16 +04:00
|
|
|
prog, prog);
|
2003-04-15 18:22:13 +04:00
|
|
|
machine_usage();
|
|
|
|
fstype_usage();
|
|
|
|
options_usage();
|
2002-04-03 09:21:16 +04:00
|
|
|
exit(1);
|
|
|
|
}
|