summaryrefslogtreecommitdiffstats
path: root/sbin/fsck_ffs/fsutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/fsck_ffs/fsutil.c')
-rw-r--r--sbin/fsck_ffs/fsutil.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c
index 9ebc342..16ef819 100644
--- a/sbin/fsck_ffs/fsutil.c
+++ b/sbin/fsck_ffs/fsutil.c
@@ -549,7 +549,18 @@ blread(int fd, char *buf, ufs2_daddr_t blk, long size)
slowio_end();
return (0);
}
- rwerror("READ BLK", blk);
+
+ /*
+ * This is handled specially here instead of in rwerror because
+ * rwerror is used for all sorts of errors, not just true read/write
+ * errors. It should be refactored and fixed.
+ */
+ if (surrender) {
+ pfatal("CANNOT READ_BLK: %ld", (long)blk);
+ errx(EEXIT, "ABORTING DUE TO READ ERRORS");
+ } else
+ rwerror("READ BLK", blk);
+
if (lseek(fd, offset, 0) < 0)
rwerror("SEEK BLK", blk);
errs = 0;
@@ -619,6 +630,35 @@ blerase(int fd, ufs2_daddr_t blk, long size)
}
/*
+ * 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)
+{
+ static char *zero;
+ off_t offset, len;
+
+ if (fd < 0)
+ return;
+ if (zero == NULL) {
+ zero = calloc(ZEROBUFSIZE, 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) {
+ len = size > ZEROBUFSIZE ? ZEROBUFSIZE : 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