diff --git a/usr.sbin/makefs/ffs.c b/usr.sbin/makefs/ffs.c index c3de69e754b3..7fd44cb974a3 100644 --- a/usr.sbin/makefs/ffs.c +++ b/usr.sbin/makefs/ffs.c @@ -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 #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 @@ -466,13 +466,15 @@ ffs_create_image(const char *image, fsinfo_t *fsopts) 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, fsinfo_t *fsopts) } } + 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 --git a/usr.sbin/makefs/ffs/buf.c b/usr.sbin/makefs/ffs/buf.c index f37d7c6088da..1917c3ac0035 100644 --- a/usr.sbin/makefs/ffs/buf.c +++ b/usr.sbin/makefs/ffs/buf.c @@ -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 #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 @@ -78,18 +78,18 @@ bread(struct vnode *vp, daddr_t blkno, int size, struct kauth_cred *u1 __unused, (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 --git a/usr.sbin/makefs/ffs/mkfs.c b/usr.sbin/makefs/ffs/mkfs.c index 0b16efdb2002..35263910e40e 100644 --- a/usr.sbin/makefs/ffs/mkfs.c +++ b/usr.sbin/makefs/ffs/mkfs.c @@ -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, const fsinfo_t *fsopts) 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, const fsinfo_t *fsopts) 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); } diff --git a/usr.sbin/makefs/msdos.c b/usr.sbin/makefs/msdos.c index 4bf5aea11bda..5a7b10310caf 100644 --- a/usr.sbin/makefs/msdos.c +++ b/usr.sbin/makefs/msdos.c @@ -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 #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 @@ -149,6 +149,7 @@ msdos_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts) * 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;