diff options
author | David Sterba <dsterba@suse.com> | 2016-08-19 16:36:40 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-08-24 14:36:58 +0200 |
commit | 059832da5f533d5ddf6ba15b7a190efe5a09ea8c (patch) | |
tree | f0de7dc909f9249295d6dbf8d63bea3564bbf35f /disk-io.c | |
parent | c11bd9cfd2d4fc6501c52da968b64c6806b968a7 (diff) |
btrfs-progs: make superblock reading/scanning api more generic
We'll add more modes that affect scanning.
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'disk-io.c')
-rw-r--r-- | disk-io.c | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -1114,7 +1114,7 @@ void btrfs_cleanup_all_caches(struct btrfs_fs_info *fs_info) int btrfs_scan_fs_devices(int fd, const char *path, struct btrfs_fs_devices **fs_devices, - u64 sb_bytenr, int super_recover, + u64 sb_bytenr, unsigned sbflags, int skip_devices) { u64 total_devs; @@ -1136,7 +1136,7 @@ int btrfs_scan_fs_devices(int fd, const char *path, } ret = btrfs_scan_one_device(fd, path, fs_devices, - &total_devs, sb_bytenr, super_recover); + &total_devs, sb_bytenr, sbflags); if (ret) { fprintf(stderr, "No valid Btrfs found on %s\n", path); return ret; @@ -1248,8 +1248,8 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, fs_info->ignore_chunk_tree_error = 1; ret = btrfs_scan_fs_devices(fp, path, &fs_devices, sb_bytenr, - (flags & OPEN_CTREE_RECOVER_SUPER), - (flags & OPEN_CTREE_NO_DEVICES)); + (flags & OPEN_CTREE_RECOVER_SUPER) ? SBREAD_RECOVER : SBREAD_DEFAULT, + (flags & OPEN_CTREE_NO_DEVICES)); if (ret) goto out; @@ -1268,10 +1268,11 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, disk_super = fs_info->super_copy; if (flags & OPEN_CTREE_RECOVER_SUPER) - ret = btrfs_read_dev_super(fs_devices->latest_bdev, - disk_super, sb_bytenr, 1); + ret = btrfs_read_dev_super(fs_devices->latest_bdev, disk_super, + sb_bytenr, SBREAD_RECOVER); else - ret = btrfs_read_dev_super(fp, disk_super, sb_bytenr, 0); + ret = btrfs_read_dev_super(fp, disk_super, sb_bytenr, + SBREAD_DEFAULT); if (ret) { printk("No valid btrfs found\n"); goto out_devices; @@ -1392,7 +1393,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) +static int check_super(struct btrfs_super_block *sb, unsigned sbflags) { char result[BTRFS_CSUM_SIZE]; u32 crc; @@ -1533,7 +1534,7 @@ error_out: } int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr, - int super_recover) + unsigned sbflags) { u8 fsid[BTRFS_FSID_SIZE]; int fsid_is_initialized = 0; @@ -1541,7 +1542,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr, struct btrfs_super_block *buf = (struct btrfs_super_block *)tmp; int i; int ret; - int max_super = super_recover ? BTRFS_SUPER_MIRROR_MAX : 1; + int max_super = sbflags & SBREAD_RECOVER ? BTRFS_SUPER_MIRROR_MAX : 1; u64 transid = 0; u64 bytenr; @@ -1553,7 +1554,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr, if (btrfs_super_bytenr(buf) != sb_bytenr) return -1; - if (check_super(buf)) + if (check_super(buf, sbflags)) return -1; memcpy(sb, buf, BTRFS_SUPER_INFO_SIZE); return 0; @@ -1577,7 +1578,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)) + if (check_super(buf, sbflags)) continue; if (!fsid_is_initialized) { |