From 8ce80d4bd44cb6d3b2ec398655ee7e321eb045e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Tue, 20 Aug 2013 07:19:58 +0000 Subject: [PATCH] Fix the zeroing loop. I must have been drunk when I wrote this... MFC after: 3 days --- sbin/fsck_ffs/fsutil.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c index abc987afe20b..16ef8193fd89 100644 --- a/sbin/fsck_ffs/fsutil.c +++ b/sbin/fsck_ffs/fsutil.c @@ -629,6 +629,10 @@ blerase(int fd, ufs2_daddr_t blk, long size) return; } +/* + * Fill a contiguous region with all-zeroes. Note ZEROBUFSIZE is by + * definition a multiple of dev_bsize. + */ void blzero(int fd, ufs2_daddr_t blk, long size) { @@ -637,9 +641,8 @@ blzero(int fd, ufs2_daddr_t blk, long size) if (fd < 0) return; - len = ZEROBUFSIZE; if (zero == NULL) { - zero = calloc(len, 1); + zero = calloc(ZEROBUFSIZE, 1); if (zero == NULL) errx(EEXIT, "cannot allocate buffer pool"); } @@ -647,10 +650,7 @@ blzero(int fd, ufs2_daddr_t blk, long size) if (lseek(fd, offset, 0) < 0) rwerror("SEEK BLK", blk); while (size > 0) { - if (size > len) - size = len; - else - len = size; + len = size > ZEROBUFSIZE ? ZEROBUFSIZE : size; if (write(fd, zero, len) != len) rwerror("WRITE BLK", blk); blk += len / dev_bsize;