Module Name:    src
Committed By:   christos
Date:           Sun Feb  3 03:21:21 UTC 2013

Modified Files:
        src/usr.sbin/makefs: ffs.c msdos.c
        src/usr.sbin/makefs/ffs: buf.c mkfs.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/usr.sbin/makefs/ffs.c
cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/makefs/msdos.c
cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/makefs/ffs/buf.c
cvs rdiff -u -r1.26 -r1.27 src/usr.sbin/makefs/ffs/mkfs.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/makefs/ffs.c
diff -u src/usr.sbin/makefs/ffs.c:1.59 src/usr.sbin/makefs/ffs.c:1.60
--- src/usr.sbin/makefs/ffs.c:1.59	Wed Jan 30 14:19:19 2013
+++ src/usr.sbin/makefs/ffs.c	Sat Feb  2 22:21:21 2013
@@ -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 @@ ffs_create_image(const char *image, fsin
 	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 @@ ffs_create_image(const char *image, fsin
 		}
 	}
 
+	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",

Index: src/usr.sbin/makefs/msdos.c
diff -u src/usr.sbin/makefs/msdos.c:1.13 src/usr.sbin/makefs/msdos.c:1.14
--- src/usr.sbin/makefs/msdos.c:1.13	Wed Jan 30 14:19:19 2013
+++ src/usr.sbin/makefs/msdos.c	Sat Feb  2 22:21:21 2013
@@ -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 @@ msdos_makefs(const char *image, const ch
 	 * 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;

Index: src/usr.sbin/makefs/ffs/buf.c
diff -u src/usr.sbin/makefs/ffs/buf.c:1.20 src/usr.sbin/makefs/ffs/buf.c:1.21
--- src/usr.sbin/makefs/ffs/buf.c:1.20	Sat Feb  2 15:42:02 2013
+++ src/usr.sbin/makefs/ffs/buf.c	Sat Feb  2 22:21:21 2013
@@ -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 @@ bread(struct vnode *vp, daddr_t blkno, i
 		    (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);
 }

Index: src/usr.sbin/makefs/ffs/mkfs.c
diff -u src/usr.sbin/makefs/ffs/mkfs.c:1.26 src/usr.sbin/makefs/ffs/mkfs.c:1.27
--- src/usr.sbin/makefs/ffs/mkfs.c:1.26	Mon Jan 28 16:03:29 2013
+++ src/usr.sbin/makefs/ffs/mkfs.c	Sat Feb  2 22:21:21 2013
@@ -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 @@ ffs_rdfs(daddr_t bno, int size, void *bf
 	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 @@ ffs_wtfs(daddr_t bno, int size, void *bf
 	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 @@ ilog2(int val)
 	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);
 }

Reply via email to