diff options
author | des <des@FreeBSD.org> | 2013-04-29 20:13:09 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2013-04-29 20:13:09 +0000 |
commit | a44b26897fe945895cdaceab1334e351f45d0901 (patch) | |
tree | 76cb8332af9430e1c1556bbc8a24c5168fc2de7f /sbin/fsck_ffs/fsutil.c | |
parent | 6cfe294dedc835f600fbdf81a4eebbd6aafe7099 (diff) | |
download | FreeBSD-src-a44b26897fe945895cdaceab1334e351f45d0901.zip FreeBSD-src-a44b26897fe945895cdaceab1334e351f45d0901.tar.gz |
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
Diffstat (limited to 'sbin/fsck_ffs/fsutil.c')
-rw-r--r-- | sbin/fsck_ffs/fsutil.c | 29 |
1 files changed, 29 insertions, 0 deletions
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. |