diff mbox series

btrfs-progs: For btrfs-map-logical proceed even with some extent corruption

Message ID 20210322030207.34335-1-davispuh@gmail.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: For btrfs-map-logical proceed even with some extent corruption | expand

Commit Message

Dāvis Mosāns March 22, 2021, 3:02 a.m. UTC
If extent tree is corrupted then open_ctree without OPEN_CTREE_NO_BLOCK_GROUPS
does fail preventing use of btrfs-map-logical at all.
Also even if we can't find extent it still can be useful to get physical
offset which could be correct.

Signed-off-by: Dāvis Mosāns <davispuh@gmail.com>
---
 btrfs-map-logical.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/btrfs-map-logical.c b/btrfs-map-logical.c
index 24c81b8d..d121a8c4 100644
--- a/btrfs-map-logical.c
+++ b/btrfs-map-logical.c
@@ -261,7 +261,7 @@  int main(int argc, char **argv)
 	radix_tree_init();
 	cache_tree_init(&root_cache);
 
-	root = open_ctree(dev, 0, 0);
+	root = open_ctree(dev, 0, OPEN_CTREE_NO_BLOCK_GROUPS);
 	if (!root) {
 		fprintf(stderr, "Open ctree failed\n");
 		free(output_file);
@@ -298,6 +298,9 @@  int main(int argc, char **argv)
 		errno = -ret;
 		fprintf(stderr, "Failed to find extent at [%llu,%llu): %m\n",
 			cur_logical, cur_logical + cur_len);
+		fprintf(stderr, "Trying a guess!\n");
+		print_mapping_info(root->fs_info, logical, bytes);
+
 		goto out_close_fd;
 	}
 	/*
@@ -358,6 +361,8 @@  int main(int argc, char **argv)
 	if (!found) {
 		fprintf(stderr, "No extent found at range [%llu,%llu)\n",
 			logical, logical + bytes);
+		fprintf(stderr, "Trying a guess!\n");
+		print_mapping_info(root->fs_info, logical, bytes);
 	}
 out_close_fd:
 	if (output_file && out_fd != 1)