From a44b26897fe945895cdaceab1334e351f45d0901 Mon Sep 17 00:00:00 2001 From: des Date: Mon, 29 Apr 2013 20:13:09 +0000 Subject: Add a -Z option which zeroes unused blocks. It can be combined with -E, in which case unused blocks are first zeroed and then erased. Reviewed by: mckusick MFC after: 3 weeks --- sbin/fsck_ffs/fsutil.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'sbin/fsck_ffs/fsutil.c') diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c index 9ebc342..f177408 100644 --- a/sbin/fsck_ffs/fsutil.c +++ b/sbin/fsck_ffs/fsutil.c @@ -618,6 +618,35 @@ blerase(int fd, ufs2_daddr_t blk, long size) return; } +void +blzero(int fd, ufs2_daddr_t blk, long size) +{ + static char *zero; + off_t offset, len; + + if (fd < 0) + return; + len = ZEROBUFSIZE; + if (zero == NULL) { + zero = calloc(len, 1); + if (zero == NULL) + errx(EEXIT, "cannot allocate buffer pool"); + } + offset = blk * dev_bsize; + if (lseek(fd, offset, 0) < 0) + rwerror("SEEK BLK", blk); + while (size > 0) { + if (size > len) + size = len; + else + len = size; + if (write(fd, zero, len) != len) + rwerror("WRITE BLK", blk); + blk += len / dev_bsize; + size -= len; + } +} + /* * Verify cylinder group's magic number and other parameters. If the * test fails, offer an option to rebuild the whole cylinder group. -- cgit v1.1