Module Name: src Committed By: tsutsui Date: Thu Jan 7 13:26:00 UTC 2010
Modified Files: src/usr.sbin/installboot: ext2fs.c ffs.c fstypes.c installboot.c installboot.h src/usr.sbin/installboot/arch: hp300.c next68k.c Log Message: Add a sectorsize parameter member in struct ib_params and use it where sector size (disk block size) is required, instead of DEV_BSIZE constant which means device I/O block size. "Looks reasonable" from dholland@, and fixes tools installboot(8) on Cygwin where DEV_BSIZE != 512 as mentioned in PR toolchain/42555. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/installboot/ext2fs.c cvs rdiff -u -r1.27 -r1.28 src/usr.sbin/installboot/ffs.c cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/installboot/fstypes.c cvs rdiff -u -r1.31 -r1.32 src/usr.sbin/installboot/installboot.c cvs rdiff -u -r1.35 -r1.36 src/usr.sbin/installboot/installboot.h cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/installboot/arch/hp300.c cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/installboot/arch/next68k.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/installboot/ext2fs.c diff -u src/usr.sbin/installboot/ext2fs.c:1.4 src/usr.sbin/installboot/ext2fs.c:1.5 --- src/usr.sbin/installboot/ext2fs.c:1.4 Mon Oct 19 18:41:17 2009 +++ src/usr.sbin/installboot/ext2fs.c Thu Jan 7 13:26:00 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: ext2fs.c,v 1.4 2009/10/19 18:41:17 bouyer Exp $ */ +/* $NetBSD: ext2fs.c,v 1.5 2010/01/07 13:26:00 tsutsui Exp $ */ /* * Copyright (c) 1997 Manuel Bouyer. @@ -59,7 +59,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(__lint) -__RCSID("$NetBSD: ext2fs.c,v 1.4 2009/10/19 18:41:17 bouyer Exp $"); +__RCSID("$NetBSD: ext2fs.c,v 1.5 2010/01/07 13:26:00 tsutsui Exp $"); #endif /* !__lint */ #include <sys/param.h> @@ -108,7 +108,7 @@ assert(size > 0); assert(blk != NULL); - rv = pread(params->fsfd, blk, size, blkno * DEV_BSIZE); + rv = pread(params->fsfd, blk, size, blkno * params->sectorsize); if (rv == -1) { warn("Reading block %llu in `%s'", (unsigned long long)blkno, params->filesystem); @@ -127,7 +127,7 @@ { uint8_t sbbuf[SBSIZE]; - if (ext2fs_read_disk_block(params, SBOFF / DEV_BSIZE, SBSIZE, + if (ext2fs_read_disk_block(params, SBOFF / params->sectorsize, SBSIZE, sbbuf) == 0) e2fs_sbload((void *)sbbuf, &fs->e2fs); Index: src/usr.sbin/installboot/ffs.c diff -u src/usr.sbin/installboot/ffs.c:1.27 src/usr.sbin/installboot/ffs.c:1.28 --- src/usr.sbin/installboot/ffs.c:1.27 Sun Apr 5 12:03:48 2009 +++ src/usr.sbin/installboot/ffs.c Thu Jan 7 13:26:00 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: ffs.c,v 1.27 2009/04/05 12:03:48 lukem Exp $ */ +/* $NetBSD: ffs.c,v 1.28 2010/01/07 13:26:00 tsutsui Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(__lint) -__RCSID("$NetBSD: ffs.c,v 1.27 2009/04/05 12:03:48 lukem Exp $"); +__RCSID("$NetBSD: ffs.c,v 1.28 2010/01/07 13:26:00 tsutsui Exp $"); #endif /* !__lint */ #include <sys/param.h> @@ -97,7 +97,7 @@ assert(size > 0); assert(blk != NULL); - rv = pread(params->fsfd, blk, size, blkno * DEV_BSIZE); + rv = pread(params->fsfd, blk, size, blkno * params->sectorsize); if (rv == -1) { warn("Reading block %llu in `%s'", (unsigned long long)blkno, params->filesystem); @@ -475,10 +475,10 @@ raid_match(ib_params *params) { /* XXX Assumes 512 bytes / sector */ - if (DEV_BSIZE != 512) { + if (params->sectorsize != 512) { warnx("Media is %d bytes/sector." " RAID is only supported on 512 bytes/sector media.", - DEV_BSIZE); + params->sectorsize); return 0; } return ffs_match_common(params, (off_t) RF_PROTECTED_SECTORS); @@ -497,7 +497,7 @@ fs = (struct fs *)sbbuf; for (i = 0; sblock_try[i] != -1; i++) { - loc = sblock_try[i] / DEV_BSIZE + offset; + loc = sblock_try[i] / params->sectorsize + offset; if (!ffs_read_disk_block(params, loc, SBLOCKSIZE, sbbuf)) continue; switch (fs->fs_magic) { Index: src/usr.sbin/installboot/fstypes.c diff -u src/usr.sbin/installboot/fstypes.c:1.11 src/usr.sbin/installboot/fstypes.c:1.12 --- src/usr.sbin/installboot/fstypes.c:1.11 Mon Apr 28 20:24:16 2008 +++ src/usr.sbin/installboot/fstypes.c Thu Jan 7 13:26:00 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fstypes.c,v 1.11 2008/04/28 20:24:16 martin Exp $ */ +/* $NetBSD: fstypes.c,v 1.12 2010/01/07 13:26:00 tsutsui Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(__lint) -__RCSID("$NetBSD: fstypes.c,v 1.11 2008/04/28 20:24:16 martin Exp $"); +__RCSID("$NetBSD: fstypes.c,v 1.12 2010/01/07 13:26:00 tsutsui Exp $"); #endif /* !__lint */ #include <sys/types.h> @@ -95,7 +95,7 @@ for (i = 0; i < nblk; i++) { blocks[i].block = params->s2start + - i * (params->fstype->blocksize / 512); + i * (params->fstype->blocksize / params->sectorsize); blocks[i].blocksize = params->fstype->blocksize; } *maxblk = nblk; Index: src/usr.sbin/installboot/installboot.c diff -u src/usr.sbin/installboot/installboot.c:1.31 src/usr.sbin/installboot/installboot.c:1.32 --- src/usr.sbin/installboot/installboot.c:1.31 Sun Apr 5 11:55:39 2009 +++ src/usr.sbin/installboot/installboot.c Thu Jan 7 13:26:00 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: installboot.c,v 1.31 2009/04/05 11:55:39 lukem Exp $ */ +/* $NetBSD: installboot.c,v 1.32 2010/01/07 13:26:00 tsutsui Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(__lint) -__RCSID("$NetBSD: installboot.c,v 1.31 2009/04/05 11:55:39 lukem Exp $"); +__RCSID("$NetBSD: installboot.c,v 1.32 2010/01/07 13:26:00 tsutsui Exp $"); #endif /* !__lint */ #include <sys/ioctl.h> @@ -92,6 +92,8 @@ #undef OFFSET #define OPTION(params, type, opt) (*(type *)((char *)(params) + (opt)->offset)) +#define DFL_SECSIZE 512 /* Don't use DEV_BSIZE. It's host's value. */ + int main(int argc, char *argv[]) { @@ -234,6 +236,8 @@ op = "write"; mode = O_RDWR; } + /* XXX should be specified via option */ + params->sectorsize = DFL_SECSIZE; if ((params->fsfd = open(params->filesystem, mode, 0600)) == -1) err(1, "Opening file system `%s' read-%s", params->filesystem, op); Index: src/usr.sbin/installboot/installboot.h diff -u src/usr.sbin/installboot/installboot.h:1.35 src/usr.sbin/installboot/installboot.h:1.36 --- src/usr.sbin/installboot/installboot.h:1.35 Mon Apr 28 20:24:16 2008 +++ src/usr.sbin/installboot/installboot.h Thu Jan 7 13:26:00 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: installboot.h,v 1.35 2008/04/28 20:24:16 martin Exp $ */ +/* $NetBSD: installboot.h,v 1.36 2010/01/07 13:26:00 tsutsui Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -80,6 +80,7 @@ uint64_t s1start; /* start block of stage1 */ const char *stage2; /* name of stage2 bootstrap */ uint64_t s2start; /* start block of stage2 */ + uint32_t sectorsize; /* sector size of target fs */ /* parsed -o option=value data */ const char *command; /* name of command string */ const char *console; /* name of console */ Index: src/usr.sbin/installboot/arch/hp300.c diff -u src/usr.sbin/installboot/arch/hp300.c:1.11 src/usr.sbin/installboot/arch/hp300.c:1.12 --- src/usr.sbin/installboot/arch/hp300.c:1.11 Sun Apr 5 11:55:39 2009 +++ src/usr.sbin/installboot/arch/hp300.c Thu Jan 7 13:26:00 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: hp300.c,v 1.11 2009/04/05 11:55:39 lukem Exp $ */ +/* $NetBSD: hp300.c,v 1.12 2010/01/07 13:26:00 tsutsui Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if !defined(__lint) -__RCSID("$NetBSD: hp300.c,v 1.11 2009/04/05 11:55:39 lukem Exp $"); +__RCSID("$NetBSD: hp300.c,v 1.12 2010/01/07 13:26:00 tsutsui Exp $"); #endif /* !__lint */ /* We need the target disklabel.h, not the hosts one..... */ @@ -78,8 +78,7 @@ int i; unsigned int secsize = HP300_SECTSIZE; uint64_t boot_size, boot_offset; - char label_buf[DEV_BSIZE]; - struct disklabel *label = (void *)label_buf; + struct disklabel *label; assert(params != NULL); assert(params->fsfd != -1); @@ -90,6 +89,12 @@ retval = 0; bootstrap = MAP_FAILED; + label = malloc(params->sectorsize); + if (label == NULL) { + warn("Failed to allocate memory for disklabel"); + goto done; + } + if (params->flags & IB_APPEND) { if (!S_ISREG(params->fsstat.st_mode)) { warnx( @@ -103,8 +108,8 @@ * The bootstrap can be well over 8k, and must go into a BOOT * partition. Read NetBSD label to locate BOOT partition. */ - if (pread(params->fsfd, label, DEV_BSIZE, 2 * DEV_BSIZE) - != DEV_BSIZE) { + if (pread(params->fsfd, label, params->sectorsize, LABELSECTOR) + != (ssize_t)params->sectorsize) { warn("reading disklabel"); goto done; } @@ -200,6 +205,8 @@ retval = 1; done: + if (label != NULL) + free(label); if (bootstrap != MAP_FAILED) munmap(bootstrap, params->s1stat.st_size); return retval; Index: src/usr.sbin/installboot/arch/next68k.c diff -u src/usr.sbin/installboot/arch/next68k.c:1.6 src/usr.sbin/installboot/arch/next68k.c:1.7 --- src/usr.sbin/installboot/arch/next68k.c:1.6 Sun Apr 5 11:55:39 2009 +++ src/usr.sbin/installboot/arch/next68k.c Thu Jan 7 13:26:00 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: next68k.c,v 1.6 2009/04/05 11:55:39 lukem Exp $ */ +/* $NetBSD: next68k.c,v 1.7 2010/01/07 13:26:00 tsutsui Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if !defined(__lint) -__RCSID("$NetBSD: next68k.c,v 1.6 2009/04/05 11:55:39 lukem Exp $"); +__RCSID("$NetBSD: next68k.c,v 1.7 2010/01/07 13:26:00 tsutsui Exp $"); #endif /* !__lint */ #include <sys/param.h> @@ -51,8 +51,6 @@ #include "installboot.h" -#define SECTOR_SIZE DEV_BSIZE - static uint16_t nextstep_checksum(const void *, const void *); static int next68k_setboot(ib_params *); @@ -106,7 +104,7 @@ * Read in the next68k disklabel */ rv = pread(params->fsfd, next68klabel, NEXT68K_LABEL_SIZE, - NEXT68K_LABEL_SECTOR * SECTOR_SIZE + NEXT68K_LABEL_OFFSET); + NEXT68K_LABEL_SECTOR * params->sectorsize + NEXT68K_LABEL_OFFSET); if (rv == -1) { warn("Reading `%s'", params->filesystem); goto done; @@ -128,7 +126,7 @@ } cd_secsize = be32toh(next68klabel->cd_secsize); - sec_netonb_mult = (cd_secsize / SECTOR_SIZE); + sec_netonb_mult = (cd_secsize / params->sectorsize); /* * Allocate a buffer, with space to round up the input file @@ -177,7 +175,8 @@ b0 = b1 = NEXT68K_LABEL_SIZE / cd_secsize; else { if (2 * bootsize > (fp * cd_secsize - - NEXT68K_LABEL_DEFAULTBOOT0_1 * SECTOR_SIZE)) + NEXT68K_LABEL_DEFAULTBOOT0_1 * + params->sectorsize)) /* can fit two copies starting after label */ b0 = NEXT68K_LABEL_SIZE / cd_secsize; else @@ -220,7 +219,8 @@ *checksum = htobe16(nextstep_checksum (next68klabel, checksum)); rv = pwrite(params->fsfd, next68klabel, NEXT68K_LABEL_SIZE, - NEXT68K_LABEL_SECTOR * SECTOR_SIZE + NEXT68K_LABEL_OFFSET); + NEXT68K_LABEL_SECTOR * params->sectorsize + + NEXT68K_LABEL_OFFSET); if (rv == -1) { warn("Writing `%s'", params->filesystem); goto done; @@ -240,7 +240,8 @@ for (;;) { if (params->flags & IB_VERBOSE) printf ("Writing boot program at %d\n", b0); - rv = pwrite(params->fsfd, bootbuf, bootsize, b0 * SECTOR_SIZE); + rv = pwrite(params->fsfd, bootbuf, bootsize, + b0 * params->sectorsize); if (rv == -1) { warn("Writing `%s' at %d", params->filesystem, b0); goto done;