- add fsstat (fstat(2) on fsfd) and s1stat (fstat(2) on s1fd) in ib_params,
and use instead of replicating the effort in various locations - if filesystem is not a regular file, use sync(2) instead of fsync(2) after the bootstrap has been written - move <sys/stat.h> and <stdint.h> into "installboot.h"
This commit is contained in:
parent
f3c2131045
commit
932b752477
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: alpha.c,v 1.10 2002/05/14 06:40:33 lukem Exp $ */
|
||||
/* $NetBSD: alpha.c,v 1.11 2002/05/15 02:18:23 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
@ -98,7 +98,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: alpha.c,v 1.10 2002/05/14 06:40:33 lukem Exp $");
|
||||
__RCSID("$NetBSD: alpha.c,v 1.11 2002/05/15 02:18:23 lukem Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
@ -106,7 +106,6 @@ __RCSID("$NetBSD: alpha.c,v 1.10 2002/05/14 06:40:33 lukem Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
@ -222,7 +221,6 @@ alpha_clearboot(ib_params *params)
|
||||
int
|
||||
alpha_setboot(ib_params *params)
|
||||
{
|
||||
struct stat bootstrapsb;
|
||||
struct alpha_boot_block bb;
|
||||
uint64_t startblock;
|
||||
int retval;
|
||||
@ -251,20 +249,12 @@ alpha_setboot(ib_params *params)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (fstat(params->s1fd, &bootstrapsb) == -1) {
|
||||
warn("Examining `%s'", params->stage1);
|
||||
goto done;
|
||||
}
|
||||
if (!S_ISREG(bootstrapsb.st_mode)) {
|
||||
warnx("`%s' must be a regular file", params->stage1);
|
||||
goto done;
|
||||
}
|
||||
/*
|
||||
* Allocate a buffer, with space to round up the input file
|
||||
* to the next block size boundary, and with space for the boot
|
||||
* block.
|
||||
*/
|
||||
bootstrapsize = roundup(bootstrapsb.st_size,
|
||||
bootstrapsize = roundup(params->s1stat.st_size,
|
||||
ALPHA_BOOT_BLOCK_BLOCKSIZE);
|
||||
|
||||
bootstrapbuf = malloc(bootstrapsize);
|
||||
@ -275,11 +265,11 @@ alpha_setboot(ib_params *params)
|
||||
memset(bootstrapbuf, 0, bootstrapsize);
|
||||
|
||||
/* read the file into the buffer */
|
||||
rv = pread(params->s1fd, bootstrapbuf, bootstrapsb.st_size, 0);
|
||||
rv = pread(params->s1fd, bootstrapbuf, params->s1stat.st_size, 0);
|
||||
if (rv == -1) {
|
||||
warn("Reading `%s'", params->stage1);
|
||||
return (0);
|
||||
} else if (rv != bootstrapsb.st_size) {
|
||||
} else if (rv != params->s1stat.st_size) {
|
||||
warnx("Reading `%s': short read", params->stage1);
|
||||
return (0);
|
||||
}
|
||||
@ -320,7 +310,8 @@ alpha_setboot(ib_params *params)
|
||||
}
|
||||
|
||||
bb.bb_secsize =
|
||||
htole64(howmany(bootstrapsb.st_size, ALPHA_BOOT_BLOCK_BLOCKSIZE));
|
||||
htole64(howmany(params->s1stat.st_size,
|
||||
ALPHA_BOOT_BLOCK_BLOCKSIZE));
|
||||
bb.bb_secstart = htole64(startblock);
|
||||
bb.bb_flags = 0;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pmax.c,v 1.8 2002/05/14 06:40:33 lukem Exp $ */
|
||||
/* $NetBSD: pmax.c,v 1.9 2002/05/15 02:18:23 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
|
||||
@ -101,7 +101,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: pmax.c,v 1.8 2002/05/14 06:40:33 lukem Exp $");
|
||||
__RCSID("$NetBSD: pmax.c,v 1.9 2002/05/15 02:18:23 lukem Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
@ -109,7 +109,6 @@ __RCSID("$NetBSD: pmax.c,v 1.8 2002/05/14 06:40:33 lukem Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
@ -206,7 +205,6 @@ pmax_clearboot(ib_params *params)
|
||||
int
|
||||
pmax_setboot(ib_params *params)
|
||||
{
|
||||
struct stat bootstrapsb;
|
||||
struct pmax_boot_block bb;
|
||||
uint32_t startblock;
|
||||
int retval;
|
||||
@ -236,14 +234,6 @@ pmax_setboot(ib_params *params)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (fstat(params->s1fd, &bootstrapsb) == -1) {
|
||||
warn("Examining `%s'", params->stage1);
|
||||
goto done;
|
||||
}
|
||||
if (!S_ISREG(bootstrapsb.st_mode)) {
|
||||
warnx("`%s' must be a regular file", params->stage1);
|
||||
goto done;
|
||||
}
|
||||
if (! load_bootstrap(params, &bootstrapbuf, &bootstrapload,
|
||||
&bootstrapexec, &bootstrapsize))
|
||||
goto done;
|
||||
@ -259,19 +249,13 @@ pmax_setboot(ib_params *params)
|
||||
|
||||
/* fill in the updated boot block fields */
|
||||
if (params->flags & IB_APPEND) {
|
||||
struct stat filesyssb;
|
||||
|
||||
if (fstat(params->fsfd, &filesyssb) == -1) {
|
||||
warn("Examining `%s'", params->filesystem);
|
||||
goto done;
|
||||
}
|
||||
if (!S_ISREG(filesyssb.st_mode)) {
|
||||
if (! S_ISREG(params->fsstat.st_mode)) {
|
||||
warnx(
|
||||
"`%s' must be a regular file to append a bootstrap",
|
||||
params->filesystem);
|
||||
goto done;
|
||||
}
|
||||
startblock = howmany(filesyssb.st_size,
|
||||
startblock = howmany(params->fsstat.st_size,
|
||||
PMAX_BOOT_BLOCK_BLOCKSIZE);
|
||||
} else if (params->flags & IB_STAGE1START) {
|
||||
startblock = params->s1start;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: sparc.c,v 1.3 2002/05/14 06:40:33 lukem Exp $ */
|
||||
/* $NetBSD: sparc.c,v 1.4 2002/05/15 02:18:23 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
|
||||
@ -38,7 +38,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: sparc.c,v 1.3 2002/05/14 06:40:33 lukem Exp $");
|
||||
__RCSID("$NetBSD: sparc.c,v 1.4 2002/05/15 02:18:23 lukem Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
@ -46,7 +46,6 @@ __RCSID("$NetBSD: sparc.c,v 1.3 2002/05/14 06:40:33 lukem Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
@ -112,7 +111,6 @@ sparc_clearboot(ib_params *params)
|
||||
int
|
||||
sparc_setboot(ib_params *params)
|
||||
{
|
||||
struct stat filesystemsb, bootstrapsb;
|
||||
char bb[SPARC_BOOT_BLOCK_MAX_SIZE];
|
||||
int retval;
|
||||
ssize_t rv;
|
||||
@ -144,19 +142,11 @@ sparc_setboot(ib_params *params)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (fstat(params->fsfd, &filesystemsb) == -1) {
|
||||
warn("Examining `%s'", params->filesystem);
|
||||
goto done;
|
||||
}
|
||||
if (fstat(params->s1fd, &bootstrapsb) == -1) {
|
||||
warn("Examining `%s'", params->stage1);
|
||||
goto done;
|
||||
}
|
||||
if (!S_ISREG(bootstrapsb.st_mode)) {
|
||||
if (!S_ISREG(params->s1stat.st_mode)) {
|
||||
warnx("`%s' must be a regular file", params->stage1);
|
||||
goto done;
|
||||
}
|
||||
if (bootstrapsb.st_size > sizeof(bb)) {
|
||||
if (params->s1stat.st_size > sizeof(bb)) {
|
||||
warnx("`%s' cannot be larger than %lu bytes",
|
||||
params->stage1, (unsigned long)sizeof(bb));
|
||||
goto done;
|
||||
@ -211,7 +201,7 @@ sparc_setboot(ib_params *params)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (S_ISREG(filesystemsb.st_mode)) {
|
||||
if (S_ISREG(params->fsstat.st_mode)) {
|
||||
if (fsync(params->fsfd) == -1)
|
||||
warn("Synchronising file system `%s'",
|
||||
params->filesystem);
|
||||
@ -284,10 +274,6 @@ sparc_setboot(ib_params *params)
|
||||
warnx("Writing `%s': short write", params->filesystem);
|
||||
goto done;
|
||||
} else {
|
||||
|
||||
/* Sync filesystems (to clean in-memory superblock?) */
|
||||
sync();
|
||||
|
||||
retval = 1;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: sparc64.c,v 1.12 2002/05/14 06:40:33 lukem Exp $ */
|
||||
/* $NetBSD: sparc64.c,v 1.13 2002/05/15 02:18:24 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
@ -66,11 +66,10 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: sparc64.c,v 1.12 2002/05/14 06:40:33 lukem Exp $");
|
||||
__RCSID("$NetBSD: sparc64.c,v 1.13 2002/05/15 02:18:24 lukem Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
@ -132,7 +131,6 @@ sparc64_clearboot(ib_params *params)
|
||||
int
|
||||
sparc64_setboot(ib_params *params)
|
||||
{
|
||||
struct stat bootstrapsb;
|
||||
char bb[SPARC64_BOOT_BLOCK_MAX_SIZE];
|
||||
int retval;
|
||||
ssize_t rv;
|
||||
@ -151,15 +149,6 @@ sparc64_setboot(ib_params *params)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (fstat(params->s1fd, &bootstrapsb) == -1) {
|
||||
warn("Examining `%s'", params->stage1);
|
||||
goto done;
|
||||
}
|
||||
if (!S_ISREG(bootstrapsb.st_mode)) {
|
||||
warnx("`%s' must be a regular file", params->stage1);
|
||||
goto done;
|
||||
}
|
||||
|
||||
memset(&bb, 0, SPARC64_BOOT_BLOCK_MAX_SIZE);
|
||||
rv = read(params->s1fd, &bb, sizeof(bb));
|
||||
if (rv == -1) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: sun68k.c,v 1.14 2002/05/14 15:29:50 lukem Exp $ */
|
||||
/* $NetBSD: sun68k.c,v 1.15 2002/05/15 02:18:24 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
|
||||
@ -38,7 +38,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: sun68k.c,v 1.14 2002/05/14 15:29:50 lukem Exp $");
|
||||
__RCSID("$NetBSD: sun68k.c,v 1.15 2002/05/15 02:18:24 lukem Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
@ -46,7 +46,6 @@ __RCSID("$NetBSD: sun68k.c,v 1.14 2002/05/14 15:29:50 lukem Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
@ -112,7 +111,6 @@ sun68k_clearboot(ib_params *params)
|
||||
int
|
||||
sun68k_setboot(ib_params *params)
|
||||
{
|
||||
struct stat filesystemsb, bootstrapsb;
|
||||
char bb[SUN68K_BOOT_BLOCK_MAX_SIZE];
|
||||
int retval;
|
||||
ssize_t rv;
|
||||
@ -142,19 +140,7 @@ sun68k_setboot(ib_params *params)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (fstat(params->fsfd, &filesystemsb) == -1) {
|
||||
warn("Examining `%s'", params->filesystem);
|
||||
goto done;
|
||||
}
|
||||
if (fstat(params->s1fd, &bootstrapsb) == -1) {
|
||||
warn("Examining `%s'", params->stage1);
|
||||
goto done;
|
||||
}
|
||||
if (!S_ISREG(bootstrapsb.st_mode)) {
|
||||
warnx("`%s' must be a regular file", params->stage1);
|
||||
goto done;
|
||||
}
|
||||
if (bootstrapsb.st_size > sizeof(bb)) {
|
||||
if (params->s1stat.st_size > sizeof(bb)) {
|
||||
warnx("`%s' cannot be larger than %lu bytes",
|
||||
params->stage1, (unsigned long)sizeof(bb));
|
||||
goto done;
|
||||
@ -204,7 +190,7 @@ sun68k_setboot(ib_params *params)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (S_ISREG(filesystemsb.st_mode)) {
|
||||
if (S_ISREG(params->fsstat.st_mode)) {
|
||||
if (fsync(params->fsfd) == -1)
|
||||
warn("Synchronising file system `%s'",
|
||||
params->filesystem);
|
||||
@ -261,10 +247,6 @@ sun68k_setboot(ib_params *params)
|
||||
warnx("Writing `%s': short write", params->filesystem);
|
||||
goto done;
|
||||
} else {
|
||||
|
||||
/* Sync filesystems (to clean in-memory superblock?) */
|
||||
sync();
|
||||
|
||||
retval = 1;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: vax.c,v 1.7 2002/05/14 06:40:33 lukem Exp $ */
|
||||
/* $NetBSD: vax.c,v 1.8 2002/05/15 02:18:24 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
|
||||
@ -71,7 +71,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: vax.c,v 1.7 2002/05/14 06:40:33 lukem Exp $");
|
||||
__RCSID("$NetBSD: vax.c,v 1.8 2002/05/15 02:18:24 lukem Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
@ -79,7 +79,6 @@ __RCSID("$NetBSD: vax.c,v 1.7 2002/05/14 06:40:33 lukem Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: installboot.c,v 1.8 2002/05/14 06:18:51 lukem Exp $ */
|
||||
/* $NetBSD: installboot.c,v 1.9 2002/05/15 02:18:22 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
@ -38,7 +38,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: installboot.c,v 1.8 2002/05/14 06:18:51 lukem Exp $");
|
||||
__RCSID("$NetBSD: installboot.c,v 1.9 2002/05/15 02:18:22 lukem Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#include <sys/utsname.h>
|
||||
@ -48,7 +48,6 @@ __RCSID("$NetBSD: installboot.c,v 1.8 2002/05/14 06:18:51 lukem Exp $");
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@ -169,6 +168,8 @@ main(int argc, char *argv[])
|
||||
if ((params->fsfd = open(params->filesystem, mode, 0600)) == -1)
|
||||
err(1, "Opening file system `%s' read-%s",
|
||||
params->filesystem, op);
|
||||
if (fstat(params->fsfd, ¶ms->fsstat) == -1)
|
||||
err(1, "Examining file system `%s'", params->filesystem);
|
||||
if (params->fstype != NULL) {
|
||||
if (! params->fstype->match(params))
|
||||
err(1, "File system `%s' is not of type %s",
|
||||
@ -189,6 +190,11 @@ main(int argc, char *argv[])
|
||||
== -1)
|
||||
err(1, "Opening primary bootstrap `%s'",
|
||||
params->stage1);
|
||||
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);
|
||||
}
|
||||
if (argc == 3) {
|
||||
params->stage2 = argv[2];
|
||||
@ -217,8 +223,14 @@ main(int argc, char *argv[])
|
||||
if (rv == 0)
|
||||
errx(1, "%s bootstrap operation failed", op);
|
||||
|
||||
if (S_ISREG(params->fsstat.st_mode)) {
|
||||
if (fsync(params->fsfd) == -1)
|
||||
err(1, "Synchronising file system `%s'", params->filesystem);
|
||||
err(1, "Synchronising file system `%s'",
|
||||
params->filesystem);
|
||||
} else {
|
||||
/* Sync filesystems (to clean in-memory superblock?) */
|
||||
sync();
|
||||
}
|
||||
if (close(params->fsfd) == -1)
|
||||
err(1, "Closing file system `%s'", params->filesystem);
|
||||
if (argc == 2)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: installboot.h,v 1.10 2002/05/14 06:40:32 lukem Exp $ */
|
||||
/* $NetBSD: installboot.h,v 1.11 2002/05/15 02:18:22 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
@ -46,6 +46,9 @@
|
||||
#include <sys/bootblock.h>
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
/* flags from global options */
|
||||
IB_VERBOSE = 1<<0, /* verbose operation */
|
||||
@ -66,8 +69,10 @@ typedef struct {
|
||||
struct ib_fs *fstype; /* file system details (see below) */
|
||||
const char *filesystem; /* name of target file system */
|
||||
int fsfd; /* open fd to filesystem */
|
||||
struct stat fsstat; /* fstat(2) of fsfd */
|
||||
const char *stage1; /* name of stage1 bootstrap */
|
||||
int s1fd; /* open fd to stage1 */
|
||||
struct stat s1stat; /* fstat(2) of s1fd */
|
||||
uint32_t s1start; /* start block of stage1 */
|
||||
const char *stage2; /* name of stage2 bootstrap */
|
||||
uint32_t s2start; /* start block of stage2 */
|
||||
@ -117,6 +122,8 @@ int raw_findstage2(ib_params *, uint32_t *, ib_block *);
|
||||
int alpha_parseopt(ib_params *, const char *);
|
||||
int alpha_setboot(ib_params *);
|
||||
int alpha_clearboot(ib_params *);
|
||||
int macppc_setboot(ib_params *);
|
||||
int macppc_clearboot(ib_params *);
|
||||
int pmax_parseopt(ib_params *, const char *);
|
||||
int pmax_setboot(ib_params *);
|
||||
int pmax_clearboot(ib_params *);
|
||||
|
Loading…
Reference in New Issue
Block a user