Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/installboot Add a sectorsize parameter member in st...



details:   https://anonhg.NetBSD.org/src/rev/9bdbf411ca5e
branches:  trunk
changeset: 750582:9bdbf411ca5e
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Thu Jan 07 13:26:00 2010 +0000

description:
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.

diffstat:

 usr.sbin/installboot/arch/hp300.c   |  19 +++++++++++++------
 usr.sbin/installboot/arch/next68k.c |  19 ++++++++++---------
 usr.sbin/installboot/ext2fs.c       |   8 ++++----
 usr.sbin/installboot/ffs.c          |  12 ++++++------
 usr.sbin/installboot/fstypes.c      |   6 +++---
 usr.sbin/installboot/installboot.c  |   8 ++++++--
 usr.sbin/installboot/installboot.h  |   3 ++-
 7 files changed, 44 insertions(+), 31 deletions(-)

diffs (truncated from 301 to 300 lines):

diff -r 61016c56f1cb -r 9bdbf411ca5e usr.sbin/installboot/arch/hp300.c
--- a/usr.sbin/installboot/arch/hp300.c Thu Jan 07 12:31:10 2010 +0000
+++ b/usr.sbin/installboot/arch/hp300.c Thu Jan 07 13:26:00 2010 +0000
@@ -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;
diff -r 61016c56f1cb -r 9bdbf411ca5e usr.sbin/installboot/arch/next68k.c
--- a/usr.sbin/installboot/arch/next68k.c       Thu Jan 07 12:31:10 2010 +0000
+++ b/usr.sbin/installboot/arch/next68k.c       Thu Jan 07 13:26:00 2010 +0000
@@ -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;
diff -r 61016c56f1cb -r 9bdbf411ca5e usr.sbin/installboot/ext2fs.c
--- a/usr.sbin/installboot/ext2fs.c     Thu Jan 07 12:31:10 2010 +0000
+++ b/usr.sbin/installboot/ext2fs.c     Thu Jan 07 13:26:00 2010 +0000
@@ -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);
diff -r 61016c56f1cb -r 9bdbf411ca5e usr.sbin/installboot/ffs.c
--- a/usr.sbin/installboot/ffs.c        Thu Jan 07 12:31:10 2010 +0000
+++ b/usr.sbin/installboot/ffs.c        Thu Jan 07 13:26:00 2010 +0000
@@ -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) {
diff -r 61016c56f1cb -r 9bdbf411ca5e usr.sbin/installboot/fstypes.c
--- a/usr.sbin/installboot/fstypes.c    Thu Jan 07 12:31:10 2010 +0000
+++ b/usr.sbin/installboot/fstypes.c    Thu Jan 07 13:26:00 2010 +0000
@@ -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;
diff -r 61016c56f1cb -r 9bdbf411ca5e usr.sbin/installboot/installboot.c
--- a/usr.sbin/installboot/installboot.c        Thu Jan 07 12:31:10 2010 +0000
+++ b/usr.sbin/installboot/installboot.c        Thu Jan 07 13:26:00 2010 +0000
@@ -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);
diff -r 61016c56f1cb -r 9bdbf411ca5e usr.sbin/installboot/installboot.h
--- a/usr.sbin/installboot/installboot.h        Thu Jan 07 12:31:10 2010 +0000
+++ b/usr.sbin/installboot/installboot.h        Thu Jan 07 13:26:00 2010 +0000
@@ -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 */



Home | Main Index | Thread Index | Old Index