mke2fs.c (zap_sector): Now takes a third argument, which is how
many sectors to clear out. Fixed up Andreas's patch to
make it a bit more efficient/compact.
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 3c96039..5e38c07 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -548,7 +548,7 @@
ext2fs_mark_ib_dirty(fs);
}
-static void zap_sector(ext2_filsys fs, int sect)
+static void zap_sector(ext2_filsys fs, int sect, int nsect)
{
char buf[512];
int retval;
@@ -556,7 +556,7 @@
memset(buf, 0, 512);
io_channel_set_blksize(fs->io, 512);
- retval = io_channel_write_blk(fs->io, sect, -512, buf);
+ retval = io_channel_write_blk(fs->io, sect, -512*nsect, buf);
io_channel_set_blksize(fs->io, fs->blocksize);
if (retval)
printf(_("Warning: could not erase sector %d: %s\n"), sect,
@@ -809,9 +809,8 @@
param.s_feature_ro_compat = 0;
}
#endif
- fprintf (stderr, _("mke2fs %s, %s for EXT2 FS %s, %s\n"),
- E2FSPROGS_VERSION, E2FSPROGS_DATE,
- EXT2FS_VERSION, EXT2FS_DATE);
+ fprintf (stderr, "mke2fs %s, %s for EXT2 FS %s, %s\n",
+ E2FSPROGS_VERSION, E2FSPROGS_DATE);
if (argc && *argv)
program_name = *argv;
while ((c = getopt (argc, argv,
@@ -1136,10 +1135,8 @@
/*
* Wipe out the old on-disk superblock
*/
- if (!noaction) {
- zap_sector(fs, 2);
- zap_sector(fs, 3);
- }
+ if (!noaction)
+ zap_sector(fs, 2, 6);
/*
* Generate a UUID for it...
@@ -1222,26 +1219,16 @@
fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY);
} else {
/* rsv must be a power of two (64kB is MD RAID sb alignment) */
- int rsv = 65536 / EXT2_BLOCK_SIZE(fs->super);
+ int rsv = 65536 / fs->blocksize;
unsigned long blocks = fs->super->s_blocks_count;
unsigned long start;
blk_t ret_blk;
#ifdef ZAP_BOOTBLOCK
- zap_sector(fs, 0);
- zap_sector(fs, 1);
+ zap_sector(fs, 0, 2);
#endif
/*
- * Zero out sectors after the superblock in the same fs block
- * (only needed for 4kB+ block size). We have already done
- * the superblock itself earlier, and we will overwrite the
- * following blocks with GDT/bitmap/itable also.
- */
- for (i = 4; i < (1 << fs->super->s_log_block_size + 1); i++)
- zap_sector(fs, i);
-
- /*
* Wipe out any old MD RAID (or other) metadata at the end
* of the device. This will also verify that the device is
* as large as we think. Be careful with very small devices.