Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/makefs - more changes to make -O work



details:   https://anonhg.NetBSD.org/src/rev/c42bdfd89a2e
branches:  trunk
changeset: 784594:c42bdfd89a2e
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Feb 03 03:21:21 2013 +0000

description:
- more changes to make -O work
- fix err* calls.

diffstat:

 usr.sbin/makefs/ffs.c      |  16 ++++++++++++----
 usr.sbin/makefs/ffs/buf.c  |  18 +++++++++---------
 usr.sbin/makefs/ffs/mkfs.c |  39 ++++++++++++++++++---------------------
 usr.sbin/makefs/msdos.c    |   5 +++--
 4 files changed, 42 insertions(+), 36 deletions(-)

diffs (199 lines):

diff -r 5d12b0a1b35a -r c42bdfd89a2e usr.sbin/makefs/ffs.c
--- a/usr.sbin/makefs/ffs.c     Sun Feb 03 02:01:19 2013 +0000
+++ b/usr.sbin/makefs/ffs.c     Sun Feb 03 03:21:21 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ffs.c,v 1.59 2013/01/30 19:19:19 christos Exp $        */
+/*     $NetBSD: ffs.c,v 1.60 2013/02/03 03:21:21 christos Exp $        */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -71,7 +71,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: ffs.c,v 1.59 2013/01/30 19:19:19 christos Exp $");
+__RCSID("$NetBSD: ffs.c,v 1.60 2013/02/03 03:21:21 christos Exp $");
 #endif /* !__lint */
 
 #include <sys/param.h>
@@ -466,13 +466,15 @@
        char    *buf;
        int     i, bufsize;
        off_t   bufrem;
+       int     oflags = O_RDWR | O_CREAT;
 
        assert (image != NULL);
        assert (fsopts != NULL);
 
                /* create image */
-       if ((fsopts->fd = open(image, O_RDWR | O_CREAT | O_TRUNC, 0666))
-           == -1) {
+       if (fsopts->offset == 0)
+               oflags |= O_TRUNC;
+       if ((fsopts->fd = open(image, oflags, 0666)) == -1) {
                warn("Can't open `%s' for writing", image);
                return (-1);
        }
@@ -500,6 +502,12 @@
                }
        }
 
+       if (fsopts->offset != 0)
+               if (lseek(fsopts->fd, fsopts->offset, SEEK_SET) == -1) {
+                       warn("can't seek");
+                       return -1;
+               }
+
        if ((debug & DEBUG_FS_CREATE_IMAGE) && fsopts->sparse == 0)
                printf(
                    "zero-ing image `%s', %lld sectors, using %d byte chunks\n",
diff -r 5d12b0a1b35a -r c42bdfd89a2e usr.sbin/makefs/ffs/buf.c
--- a/usr.sbin/makefs/ffs/buf.c Sun Feb 03 02:01:19 2013 +0000
+++ b/usr.sbin/makefs/ffs/buf.c Sun Feb 03 03:21:21 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: buf.c,v 1.20 2013/02/02 20:42:02 christos Exp $        */
+/*     $NetBSD: buf.c,v 1.21 2013/02/03 03:21:21 christos Exp $        */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -41,7 +41,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: buf.c,v 1.20 2013/02/02 20:42:02 christos Exp $");
+__RCSID("$NetBSD: buf.c,v 1.21 2013/02/03 03:21:21 christos Exp $");
 #endif /* !__lint */
 
 #include <sys/param.h>
@@ -78,18 +78,18 @@
                    (long long)(*bpp)->b_blkno, (long long) offset,
                    (*bpp)->b_bcount);
        if (lseek((*bpp)->b_fs->fd, offset, SEEK_SET) == -1)
-               err(1, "bread: lseek %lld (%lld)",
+               err(1, "%s: lseek %lld (%lld)", __func__,
                    (long long)(*bpp)->b_blkno, (long long)offset);
        rv = read((*bpp)->b_fs->fd, (*bpp)->b_data, (*bpp)->b_bcount);
        if (debug & DEBUG_BUF_BREAD)
-               printf("bread: read %ld (%lld) returned %d\n",
-                   (*bpp)->b_bcount, (long long)offset, (int)rv);
+               printf("bread: read %ld (%lld) returned %zd\n",
+                   (*bpp)->b_bcount, (long long)offset, rv);
        if (rv == -1)                           /* read error */
-               err(1, "bread: read %ld (%lld) returned %d",
-                   (*bpp)->b_bcount, (long long)offset, (int)rv);
+               err(1, "%s: read %ld (%lld) returned %zd", __func__,
+                   (*bpp)->b_bcount, (long long)offset, rv);
        else if (rv != (*bpp)->b_bcount)        /* short read */
-               err(1, "bread: read %ld (%lld) returned %d",
-                   (*bpp)->b_bcount, (long long)offset, (int)rv);
+               err(1, "%s: read %ld (%lld) returned %zd", __func__,
+                   (*bpp)->b_bcount, (long long)offset, rv);
        else
                return (0);
 }
diff -r 5d12b0a1b35a -r c42bdfd89a2e usr.sbin/makefs/ffs/mkfs.c
--- a/usr.sbin/makefs/ffs/mkfs.c        Sun Feb 03 02:01:19 2013 +0000
+++ b/usr.sbin/makefs/ffs/mkfs.c        Sun Feb 03 03:21:21 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkfs.c,v 1.26 2013/01/28 21:03:29 christos Exp $       */
+/*     $NetBSD: mkfs.c,v 1.27 2013/02/03 03:21:21 christos Exp $       */
 
 /*
  * Copyright (c) 2002 Networks Associates Technology, Inc.
@@ -48,7 +48,7 @@
 static char sccsid[] = "@(#)mkfs.c     8.11 (Berkeley) 5/3/95";
 #else
 #ifdef __RCSID
-__RCSID("$NetBSD: mkfs.c,v 1.26 2013/01/28 21:03:29 christos Exp $");
+__RCSID("$NetBSD: mkfs.c,v 1.27 2013/02/03 03:21:21 christos Exp $");
 #endif
 #endif
 #endif /* not lint */
@@ -786,20 +786,18 @@
        int n;
        off_t offset;
 
-       offset = bno;
-       offset *= fsopts->sectorsize;
+       offset = bno * fsopts->sectorsize + fsopts->offset;
        if (lseek(fsopts->fd, offset, SEEK_SET) < 0)
-               err(1, "ffs_rdfs: seek error for sector %lld: %s\n",
-                   (long long)bno, strerror(errno));
+               err(1, "%s: seek error for sector %lld", __func__,
+                   (long long)bno);
        n = read(fsopts->fd, bf, size);
        if (n == -1) {
-               abort();
-               err(1, "ffs_rdfs: read error bno %lld size %d", (long long)bno,
-                   size);
+               err(1, "%s: read error bno %lld size %d", __func__,
+                   (long long)bno, size);
        }
        else if (n != size)
-               errx(1, "ffs_rdfs: read error for sector %lld: %s\n",
-                   (long long)bno, strerror(errno));
+               errx(1, "%s: short read error for sector %lld", __func__,
+                   (long long)bno);
 }
 
 /*
@@ -811,18 +809,17 @@
        int n;
        off_t offset;
 
-       offset = bno;
-       offset *= fsopts->sectorsize;
-       if (lseek(fsopts->fd, offset, SEEK_SET) < 0)
-               err(1, "wtfs: seek error for sector %lld: %s\n",
-                   (long long)bno, strerror(errno));
+       offset = bno * fsopts->sectorsize + fsopts->offset;
+       if (lseek(fsopts->fd, offset, SEEK_SET) == -1)
+               err(1, "%s: seek error for sector %lld", __func__,
+                   (long long)bno);
        n = write(fsopts->fd, bf, size);
        if (n == -1)
-               err(1, "wtfs: write error for sector %lld: %s\n",
-                   (long long)bno, strerror(errno));
+               err(1, "%s: write error for sector %lld", __func__,
+                   (long long)bno);
        else if (n != size)
-               errx(1, "wtfs: write error for sector %lld: %s\n",
-                   (long long)bno, strerror(errno));
+               errx(1, "%s: short write error for sector %lld", __func__,
+                   (long long)bno);
 }
 
 
@@ -845,5 +842,5 @@
        for (n = 0; n < sizeof(n) * CHAR_BIT; n++)
                if (1 << n == val)
                        return (n);
-       errx(1, "ilog2: %d is not a power of 2\n", val);
+       errx(1, "%s: %d is not a power of 2", __func__, val);
 }
diff -r 5d12b0a1b35a -r c42bdfd89a2e usr.sbin/makefs/msdos.c
--- a/usr.sbin/makefs/msdos.c   Sun Feb 03 02:01:19 2013 +0000
+++ b/usr.sbin/makefs/msdos.c   Sun Feb 03 03:21:21 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msdos.c,v 1.13 2013/01/30 19:19:19 christos Exp $      */
+/*     $NetBSD: msdos.c,v 1.14 2013/02/03 03:21:21 christos Exp $      */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: msdos.c,v 1.13 2013/01/30 19:19:19 christos Exp $");
+__RCSID("$NetBSD: msdos.c,v 1.14 2013/02/03 03:21:21 christos Exp $");
 #endif /* !__lint */
 
 #include <sys/param.h>
@@ -149,6 +149,7 @@
         * Is minsize right here?
         */
        msdos_opt->create_size = MAX(msdos_opt->create_size, fsopts->minsize);
+       msdos_opt->offset = fsopts->offset;
        if (msdos_opt->bytes_per_sector == 0) {
                if (fsopts->sectorsize == -1)
                        fsopts->sectorsize = 512;



Home | Main Index | Thread Index | Old Index