From a062ffd74de0b6ad74ea2c9750da94e2964856a1 Mon Sep 17 00:00:00 2001 From: Anand Jain Date: Mon, 17 Mar 2014 19:59:01 +0800 Subject: btrfs-progs: avoid implicit scan for backup SB When a disk containing btrfs is overwritten with other FS, ext4 for example it doesn't overwrite 2nd and 3rd copy of the btrfs SB. And btrfs_read_dev_super() would look for backup SB when primary SB isn't found. This causes the problem as in the reproducer below. In kernel we avoid this by _not_ reading backup SB implicitly, this patch would port the same to btrfs-progs. reproducer: mkfs.btrfs /dev/sde mkfs.ext4 /dev/sde mount /dev/sde /ext4 btrfs-convert /dev/sde (is successful (bug)) with this patch :: btrfs-convert /dev/sde /dev/sde is mounted Signed-off-by: Anand Jain Signed-off-by: Chris Mason --- disk-io.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'disk-io.c') diff --git a/disk-io.c b/disk-io.c index 0bd1bb01..19b95a72 100644 --- a/disk-io.c +++ b/disk-io.c @@ -1206,7 +1206,14 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr) return 0; } - for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { + /* + * we would like to check all the supers, but that would make + * a btrfs mount succeed after a mkfs from a different FS. + * So, we need to add a special mount option to scan for + * later supers, using BTRFS_SUPER_MIRROR_MAX instead + */ + + for (i = 0; i < 1; i++) { bytenr = btrfs_sb_offset(i); ret = pread64(fd, &buf, sizeof(buf), bytenr); if (ret < sizeof(buf)) -- cgit v1.2.3