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 fsstat (fstat(2) on fsfd) and s1s...



details:   https://anonhg.NetBSD.org/src/rev/81970a0efcff
branches:  trunk
changeset: 526971:81970a0efcff
user:      lukem <lukem%NetBSD.org@localhost>
date:      Wed May 15 02:18:22 2002 +0000

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

diffstat:

 usr.sbin/installboot/arch/alpha.c   |  23 +++++++----------------
 usr.sbin/installboot/arch/pmax.c    |  24 ++++--------------------
 usr.sbin/installboot/arch/sparc.c   |  24 +++++-------------------
 usr.sbin/installboot/arch/sparc64.c |  15 ++-------------
 usr.sbin/installboot/arch/sun68k.c  |  26 ++++----------------------
 usr.sbin/installboot/arch/vax.c     |   5 ++---
 usr.sbin/installboot/installboot.c  |  22 +++++++++++++++++-----
 usr.sbin/installboot/installboot.h  |   9 ++++++++-
 8 files changed, 49 insertions(+), 99 deletions(-)

diffs (truncated from 477 to 300 lines):

diff -r 6fad575099c5 -r 81970a0efcff usr.sbin/installboot/arch/alpha.c
--- a/usr.sbin/installboot/arch/alpha.c Wed May 15 02:17:06 2002 +0000
+++ b/usr.sbin/installboot/arch/alpha.c Wed May 15 02:18:22 2002 +0000
@@ -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 @@
 #endif
 
 #include <sys/param.h>
-#include <sys/stat.h>
 
 #include <assert.h>
 #include <err.h>
@@ -222,7 +221,6 @@
 int
 alpha_setboot(ib_params *params)
 {
-       struct stat             bootstrapsb;
        struct alpha_boot_block bb;
        uint64_t                startblock;
        int                     retval;
@@ -251,20 +249,12 @@
                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 @@
        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 @@
        }
 
        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;
 
diff -r 6fad575099c5 -r 81970a0efcff usr.sbin/installboot/arch/pmax.c
--- a/usr.sbin/installboot/arch/pmax.c  Wed May 15 02:17:06 2002 +0000
+++ b/usr.sbin/installboot/arch/pmax.c  Wed May 15 02:18:22 2002 +0000
@@ -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 @@
 #endif
 
 #include <sys/param.h>
-#include <sys/stat.h>
 
 #include <assert.h>
 #include <err.h>
@@ -206,7 +205,6 @@
 int
 pmax_setboot(ib_params *params)
 {
-       struct stat             bootstrapsb;
        struct pmax_boot_block  bb;
        uint32_t                startblock;
        int                     retval;
@@ -236,14 +234,6 @@
                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 @@
 
                /* 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;
diff -r 6fad575099c5 -r 81970a0efcff usr.sbin/installboot/arch/sparc.c
--- a/usr.sbin/installboot/arch/sparc.c Wed May 15 02:17:06 2002 +0000
+++ b/usr.sbin/installboot/arch/sparc.c Wed May 15 02:18:22 2002 +0000
@@ -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 @@
 #endif
 
 #include <sys/param.h>
-#include <sys/stat.h>
 
 #include <assert.h>
 #include <err.h>
@@ -112,7 +111,6 @@
 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 @@
                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 @@
                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 @@
                warnx("Writing `%s': short write", params->filesystem);
                goto done;
        } else {
-
-               /* Sync filesystems (to clean in-memory superblock?) */
-               sync();
-
                retval = 1;
        }
 
diff -r 6fad575099c5 -r 81970a0efcff usr.sbin/installboot/arch/sparc64.c
--- a/usr.sbin/installboot/arch/sparc64.c       Wed May 15 02:17:06 2002 +0000
+++ b/usr.sbin/installboot/arch/sparc64.c       Wed May 15 02:18:22 2002 +0000
@@ -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 @@
 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 @@
                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) {
diff -r 6fad575099c5 -r 81970a0efcff usr.sbin/installboot/arch/sun68k.c
--- a/usr.sbin/installboot/arch/sun68k.c        Wed May 15 02:17:06 2002 +0000
+++ b/usr.sbin/installboot/arch/sun68k.c        Wed May 15 02:18:22 2002 +0000
@@ -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 @@
 #endif
 
 #include <sys/param.h>
-#include <sys/stat.h>
 
 #include <assert.h>
 #include <err.h>
@@ -112,7 +111,6 @@



Home | Main Index | Thread Index | Old Index