btrfs-progs: library-test: update header inclusion
[platform/upstream/btrfs-progs.git] / cmds-inspect-dump-tree.c
index cfe7507..6c6c0e5 100644 (file)
@@ -32,6 +32,7 @@
 #include "commands.h"
 #include "utils.h"
 #include "cmds-inspect-dump-tree.h"
+#include "help.h"
 
 static void print_extents(struct btrfs_root *root, struct extent_buffer *eb)
 {
@@ -260,26 +261,27 @@ int cmd_inspect_dump_tree(int argc, char **argv)
                case 'b':
                        block_only = arg_strtou64(optarg);
                        break;
-               case 't':
-                       if (string_is_numerical(optarg)) {
-                               tree_id = arg_strtou64(optarg);
-                       } else {
-                               const char *end = NULL;
+               case 't': {
+                       const char *end = NULL;
 
+                       if (string_is_numerical(optarg))
+                               tree_id = arg_strtou64(optarg);
+                       else
                                tree_id = treeid_from_string(optarg, &end);
 
-                               if (*end) {
-                                       error("unexpected tree id suffix of '%s': %s\n",
-                                                       optarg, end);
-                                       exit(1);
-                               }
-                       }
                        if (!tree_id) {
-                               error("unrecognized tree id: %s\n",
+                               error("unrecognized tree id: %s",
                                                optarg);
                                exit(1);
                        }
+
+                       if (end && *end) {
+                               error("unexpected tree id suffix of '%s': %s",
+                                               optarg, end);
+                               exit(1);
+                       }
                        break;
+                       }
                default:
                        usage(cmd_inspect_dump_tree_usage);
                }
@@ -388,9 +390,14 @@ again:
 
        key.offset = 0;
        key.objectid = 0;
-       btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
+       key.type = BTRFS_ROOT_ITEM_KEY;
        ret = btrfs_search_slot(NULL, tree_root_scan, &key, &path, 0, 0);
-       BUG_ON(ret < 0);
+       if (ret < 0) {
+               error("cannot read ROOT_ITEM from tree %llu: %s",
+                       (unsigned long long)tree_root_scan->root_key.objectid,
+                       strerror(-ret));
+               goto close_root;
+       }
        while (1) {
                leaf = path.nodes[0];
                slot = path.slots[0];
@@ -403,7 +410,7 @@ again:
                }
                btrfs_item_key(leaf, &disk_key, path.slots[0]);
                btrfs_disk_key_to_cpu(&found_key, &disk_key);
-               if (btrfs_key_type(&found_key) == BTRFS_ROOT_ITEM_KEY) {
+               if (found_key.type == BTRFS_ROOT_ITEM_KEY) {
                        unsigned long offset;
                        struct extent_buffer *buf;
                        int skip = extent_only | device_only | uuid_tree_only;
@@ -537,8 +544,7 @@ next:
 no_node:
        btrfs_release_path(&path);
 
-       if (tree_root_scan == info->tree_root &&
-           info->log_root_tree) {
+       if (tree_root_scan == info->tree_root && info->log_root_tree) {
                tree_root_scan = info->log_root_tree;
                goto again;
        }