case BTRFS_CHUNK_TREE_OBJECTID:
level = btrfs_super_chunk_root_level(super);
gen = btrfs_super_chunk_root_generation(super);
- printf("Search for chunk root is not supported yet\n");
break;
case BTRFS_TREE_LOG_OBJECTID:
level = btrfs_super_log_root_level(super);
int main(int argc, char **argv)
{
- struct btrfs_root *root;
+ struct btrfs_fs_info *fs_info;
struct btrfs_find_root_filter filter = {0};
struct cache_tree result;
struct cache_extent *found;
exit(1);
}
- root = open_ctree(argv[optind], 0, OPEN_CTREE_CHUNK_ROOT_ONLY);
- if (!root) {
- fprintf(stderr, "Open ctree failed\n");
+ fs_info = open_ctree_fs_info(argv[optind], 0, 0,
+ OPEN_CTREE_CHUNK_ROOT_ONLY |
+ OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR);
+ if (!fs_info) {
+ error("open ctree failed");
exit(1);
}
cache_tree_init(&result);
- get_root_gen_and_level(filter.objectid, root->fs_info,
+ get_root_gen_and_level(filter.objectid, fs_info,
&filter.match_gen, &filter.match_level);
- ret = btrfs_find_root_search(root, &filter, &result, &found);
+ ret = btrfs_find_root_search(fs_info, &filter, &result, &found);
if (ret < 0) {
fprintf(stderr, "Fail to search the tree root: %s\n",
strerror(-ret));
print_find_root_result(&result, &filter);
out:
btrfs_find_root_free(&result);
- close_ctree(root);
+ close_ctree_fs_info(fs_info);
btrfs_close_all_devices();
return ret;
}
* Return 1 if found root with given gen/level and set *match to it.
* Return <0 if error happens
*/
-int btrfs_find_root_search(struct btrfs_root *chunk_root,
+int btrfs_find_root_search(struct btrfs_fs_info *fs_info,
struct btrfs_find_root_filter *filter,
struct cache_tree *result,
struct cache_extent **match)
{
- struct btrfs_fs_info *fs_info = chunk_root->fs_info;
struct extent_buffer *eb;
u64 chunk_offset = 0;
u64 chunk_size = 0;
u64 offset = 0;
- u32 leafsize = chunk_root->leafsize;
+ u32 leafsize = btrfs_super_leafsize(fs_info->super_copy);
int suppress_errors = 0;
int ret = 0;
}
for (offset = chunk_offset;
offset < chunk_offset + chunk_size;
- offset += chunk_root->leafsize) {
- eb = read_tree_block(chunk_root, offset, leafsize, 0);
+ offset += leafsize) {
+ eb = read_tree_block_fs_info(fs_info, offset, leafsize,
+ 0);
if (!eb || IS_ERR(eb))
continue;
ret = add_eb_to_result(eb, result, leafsize, filter,
* This *WILL* take *TONS* of extra time.
*/
};
-int btrfs_find_root_search(struct btrfs_root *chunk_root,
+int btrfs_find_root_search(struct btrfs_fs_info *fs_info,
struct btrfs_find_root_filter *filter,
struct cache_tree *result,
struct cache_extent **match);