From patchwork Tue Jan 29 17:02:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [RFC] mke2fs: wipe out old btrfs superblocks Date: Tue, 29 Jan 2013 07:02:46 -0000 From: Eric Sandeen X-Patchwork-Id: 216604 Message-Id: <510800B6.4090505@redhat.com> To: ext4 development btrfs sticks superblocks at 64k, 64M, and 256G. If we don't overwrite those, libblkid may accidentally identify an ext* filesystem with old btrfs superblocks as btrfs, and we'll be sad. libblkid provides a blkid_wipe_fs() functionality to zero all existing signatures, but that'd break our handy-dandy undo capability, I think. So I'm not sure we have any other choice but to do it ourselves. There is a slight error here in that if the mkfs does not span the entire device, we won't overwrite signatures past the end of the filesystem, but that case should be pretty rare. (The same slight error in logic applies to the existing "wipe old MD superblock" path). Signed-off-by: Eric Sandeen blocksize < 4096) + blocks = 4096 / fs->blocksize; + /* + * Wipe out any old btrfs superblocks, at + * 64k, 64M, and 256G. + */ + start = 64ULL * 1024 / fs->blocksize; + retval += ext2fs_zero_blocks2(fs, start, blocks, NULL, NULL); + start = 64ULL * 1024 * 1024 / fs->blocksize; + if (start + blocks <= ext2fs_blocks_count(fs->super)) + retval += ext2fs_zero_blocks2(fs, start, blocks, NULL, NULL); + start = 256ULL * 1024 * 1024 * 1024 / fs->blocksize; + if (start + blocks <= ext2fs_blocks_count(fs->super)) + retval += ext2fs_zero_blocks2(fs, start, blocks, NULL, NULL); + /* free the static zeroing buffer */ + ext2fs_zero_blocks2(0, 0, 0, 0, 0); + return retval; +} + static void fix_cluster_bg_counts(ext2_filsys fs) { blk64_t cluster, num_clusters, tot_free; @@ -2439,6 +2465,9 @@ int main (int argc, char *argv[]) itable_zeroed = 1; } } + retval = mke2fs_wipe_btrfs(fs); + if (retval) + printf(_("Failed to wipe old btrfs super locations\n")); sprintf(tdb_string, "tdb_data_size=%d", fs->blocksize <= 4096 ? 32768 : fs->blocksize * 8);