- more changes to make -O work

- fix err* calls.
This commit is contained in:
christos 2013-02-03 03:21:21 +00:00
parent c5775ada06
commit c5e9014781
4 changed files with 42 additions and 36 deletions

View File

@ -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. * Copyright (c) 2001 Wasabi Systems, Inc.
@ -71,7 +71,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint) #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 */ #endif /* !__lint */
#include <sys/param.h> #include <sys/param.h>
@ -466,13 +466,15 @@ ffs_create_image(const char *image, fsinfo_t *fsopts)
char *buf; char *buf;
int i, bufsize; int i, bufsize;
off_t bufrem; off_t bufrem;
int oflags = O_RDWR | O_CREAT;
assert (image != NULL); assert (image != NULL);
assert (fsopts != NULL); assert (fsopts != NULL);
/* create image */ /* create image */
if ((fsopts->fd = open(image, O_RDWR | O_CREAT | O_TRUNC, 0666)) if (fsopts->offset == 0)
== -1) { oflags |= O_TRUNC;
if ((fsopts->fd = open(image, oflags, 0666)) == -1) {
warn("Can't open `%s' for writing", image); warn("Can't open `%s' for writing", image);
return (-1); 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) if ((debug & DEBUG_FS_CREATE_IMAGE) && fsopts->sparse == 0)
printf( printf(
"zero-ing image `%s', %lld sectors, using %d byte chunks\n", "zero-ing image `%s', %lld sectors, using %d byte chunks\n",

View File

@ -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. * Copyright (c) 2001 Wasabi Systems, Inc.
@ -41,7 +41,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint) #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 */ #endif /* !__lint */
#include <sys/param.h> #include <sys/param.h>
@ -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, (long long)(*bpp)->b_blkno, (long long) offset,
(*bpp)->b_bcount); (*bpp)->b_bcount);
if (lseek((*bpp)->b_fs->fd, offset, SEEK_SET) == -1) 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); (long long)(*bpp)->b_blkno, (long long)offset);
rv = read((*bpp)->b_fs->fd, (*bpp)->b_data, (*bpp)->b_bcount); rv = read((*bpp)->b_fs->fd, (*bpp)->b_data, (*bpp)->b_bcount);
if (debug & DEBUG_BUF_BREAD) if (debug & DEBUG_BUF_BREAD)
printf("bread: read %ld (%lld) returned %d\n", printf("bread: read %ld (%lld) returned %zd\n",
(*bpp)->b_bcount, (long long)offset, (int)rv); (*bpp)->b_bcount, (long long)offset, rv);
if (rv == -1) /* read error */ if (rv == -1) /* read error */
err(1, "bread: read %ld (%lld) returned %d", err(1, "%s: read %ld (%lld) returned %zd", __func__,
(*bpp)->b_bcount, (long long)offset, (int)rv); (*bpp)->b_bcount, (long long)offset, rv);
else if (rv != (*bpp)->b_bcount) /* short read */ else if (rv != (*bpp)->b_bcount) /* short read */
err(1, "bread: read %ld (%lld) returned %d", err(1, "%s: read %ld (%lld) returned %zd", __func__,
(*bpp)->b_bcount, (long long)offset, (int)rv); (*bpp)->b_bcount, (long long)offset, rv);
else else
return (0); return (0);
} }

View File

@ -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. * Copyright (c) 2002 Networks Associates Technology, Inc.
@ -48,7 +48,7 @@
static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95"; static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
#else #else
#ifdef __RCSID #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 #endif
#endif /* not lint */ #endif /* not lint */
@ -786,20 +786,18 @@ ffs_rdfs(daddr_t bno, int size, void *bf, const fsinfo_t *fsopts)
int n; int n;
off_t offset; off_t offset;
offset = bno; offset = bno * fsopts->sectorsize + fsopts->offset;
offset *= fsopts->sectorsize;
if (lseek(fsopts->fd, offset, SEEK_SET) < 0) if (lseek(fsopts->fd, offset, SEEK_SET) < 0)
err(1, "ffs_rdfs: seek error for sector %lld: %s\n", err(1, "%s: seek error for sector %lld", __func__,
(long long)bno, strerror(errno)); (long long)bno);
n = read(fsopts->fd, bf, size); n = read(fsopts->fd, bf, size);
if (n == -1) { if (n == -1) {
abort(); err(1, "%s: read error bno %lld size %d", __func__,
err(1, "ffs_rdfs: read error bno %lld size %d", (long long)bno, (long long)bno, size);
size);
} }
else if (n != size) else if (n != size)
errx(1, "ffs_rdfs: read error for sector %lld: %s\n", errx(1, "%s: short read error for sector %lld", __func__,
(long long)bno, strerror(errno)); (long long)bno);
} }
/* /*
@ -811,18 +809,17 @@ ffs_wtfs(daddr_t bno, int size, void *bf, const fsinfo_t *fsopts)
int n; int n;
off_t offset; off_t offset;
offset = bno; offset = bno * fsopts->sectorsize + fsopts->offset;
offset *= fsopts->sectorsize; if (lseek(fsopts->fd, offset, SEEK_SET) == -1)
if (lseek(fsopts->fd, offset, SEEK_SET) < 0) err(1, "%s: seek error for sector %lld", __func__,
err(1, "wtfs: seek error for sector %lld: %s\n", (long long)bno);
(long long)bno, strerror(errno));
n = write(fsopts->fd, bf, size); n = write(fsopts->fd, bf, size);
if (n == -1) if (n == -1)
err(1, "wtfs: write error for sector %lld: %s\n", err(1, "%s: write error for sector %lld", __func__,
(long long)bno, strerror(errno)); (long long)bno);
else if (n != size) else if (n != size)
errx(1, "wtfs: write error for sector %lld: %s\n", errx(1, "%s: short write error for sector %lld", __func__,
(long long)bno, strerror(errno)); (long long)bno);
} }
@ -845,5 +842,5 @@ ilog2(int val)
for (n = 0; n < sizeof(n) * CHAR_BIT; n++) for (n = 0; n < sizeof(n) * CHAR_BIT; n++)
if (1 << n == val) if (1 << n == val)
return (n); 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);
} }

View File

@ -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. * Copyright (c) 2013 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint) #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 */ #endif /* !__lint */
#include <sys/param.h> #include <sys/param.h>
@ -149,6 +149,7 @@ msdos_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts)
* Is minsize right here? * Is minsize right here?
*/ */
msdos_opt->create_size = MAX(msdos_opt->create_size, fsopts->minsize); msdos_opt->create_size = MAX(msdos_opt->create_size, fsopts->minsize);
msdos_opt->offset = fsopts->offset;
if (msdos_opt->bytes_per_sector == 0) { if (msdos_opt->bytes_per_sector == 0) {
if (fsopts->sectorsize == -1) if (fsopts->sectorsize == -1)
fsopts->sectorsize = 512; fsopts->sectorsize = 512;