mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
synced 2024-12-14 06:33:21 +08:00
btrfs-progs: image: Verify the superblock before restore
This patch will export disk-io.c::check_super() as btrfs_check_super() and use it in btrfs-image for extra verification. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
686e86d82d
commit
ab5079c19a
@ -1347,7 +1347,7 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
|
||||
* - number of devices - something sane
|
||||
* - sys array size - maximum
|
||||
*/
|
||||
static int check_super(struct btrfs_super_block *sb, unsigned sbflags)
|
||||
int btrfs_check_super(struct btrfs_super_block *sb, unsigned sbflags)
|
||||
{
|
||||
u8 result[BTRFS_CSUM_SIZE];
|
||||
u32 crc;
|
||||
@ -1547,7 +1547,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
|
||||
if (btrfs_super_bytenr(buf) != sb_bytenr)
|
||||
return -EIO;
|
||||
|
||||
ret = check_super(buf, sbflags);
|
||||
ret = btrfs_check_super(buf, sbflags);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
memcpy(sb, buf, BTRFS_SUPER_INFO_SIZE);
|
||||
@ -1572,7 +1572,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
|
||||
/* if magic is NULL, the device was removed */
|
||||
if (btrfs_super_magic(buf) == 0 && i == 0)
|
||||
break;
|
||||
if (check_super(buf, sbflags))
|
||||
if (btrfs_check_super(buf, sbflags))
|
||||
continue;
|
||||
|
||||
if (!fsid_is_initialized) {
|
||||
|
@ -171,6 +171,7 @@ static inline int close_ctree(struct btrfs_root *root)
|
||||
|
||||
int write_all_supers(struct btrfs_fs_info *fs_info);
|
||||
int write_ctree_super(struct btrfs_trans_handle *trans);
|
||||
int btrfs_check_super(struct btrfs_super_block *sb, unsigned sbflags);
|
||||
int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
|
||||
unsigned sbflags);
|
||||
int btrfs_map_bh_to_logical(struct btrfs_root *root, struct extent_buffer *bh,
|
||||
|
@ -1983,6 +1983,11 @@ static int build_chunk_tree(struct mdrestore_struct *mdres,
|
||||
|
||||
pthread_mutex_lock(&mdres->mutex);
|
||||
super = (struct btrfs_super_block *)buffer;
|
||||
ret = btrfs_check_super(super, 0);
|
||||
if (ret < 0) {
|
||||
error("invalid superblock");
|
||||
return ret;
|
||||
}
|
||||
chunk_root_bytenr = btrfs_super_chunk_root(super);
|
||||
mdres->nodesize = btrfs_super_nodesize(super);
|
||||
if (btrfs_super_incompat_flags(super) &
|
||||
|
Loading…
Reference in New Issue
Block a user