summaryrefslogtreecommitdiffstats
path: root/sbin/fsck_ffs/fsutil.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2013-04-29 20:13:09 +0000
committerdes <des@FreeBSD.org>2013-04-29 20:13:09 +0000
commita44b26897fe945895cdaceab1334e351f45d0901 (patch)
tree76cb8332af9430e1c1556bbc8a24c5168fc2de7f /sbin/fsck_ffs/fsutil.c
parent6cfe294dedc835f600fbdf81a4eebbd6aafe7099 (diff)
downloadFreeBSD-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.c29
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.
OpenPOWER on IntegriCloud