- u64 gen = btrfs_super_generation(root->fs_info->super_copy);
- u64 objectid = search_objectid;
- u32 size = btrfs_super_nodesize(root->fs_info->super_copy);
- u8 level = root->fs_info->super_copy->root_level;
- size_t block_off = 0;
-
- while (block_off < iobuf_size) {
- void *block = iobuf + block_off;
- struct btrfs_header *header = block;
- u64 h_byte, h_level, h_gen, h_owner;
-
-// printf("searching %Lu\n", offset + block_off);
- h_byte = le64_to_cpu(header->bytenr);
- h_owner = le64_to_cpu(header->owner);
- h_level = header->level;
- h_gen = le64_to_cpu(header->generation);
-
- if (h_owner != objectid)
- goto next;
- if (h_byte != (offset + block_off))
- goto next;
- if (h_level != level)
- goto next;
- if (csum_block(block, size)) {
- fprintf(stderr, "Well block %Lu seems good, "
- "but the csum doesn't match\n",
- h_byte);
- goto next;
- }
- if (h_gen != gen) {
- fprintf(stderr, "Well block %Lu seems great, "
- "but generation doesn't match, "
- "have=%Lu, want=%Lu\n", h_byte, h_gen,
- gen);
- goto next;
- }
- printf("Found tree root at %Lu\n", h_byte);
- return 0;
-next:
- block_off += size;
- }
-
- return 1;
+ int unsure = 0;
+
+ if (filter->match_gen == (u64)-1 || filter->match_level == (u8)-1)
+ unsure = 1;
+ printf("Well block %llu(gen: %llu level: %u) seems good, ",
+ tree_block->start, generation, level);
+ if (unsure)
+ printf("but we are unsure about the correct generation/level\n");
+ else if (level == filter->match_level &&
+ generation == filter->match_gen)
+ printf("and it matches superblock\n");
+ else
+ printf("but generation/level doesn't match, want gen: %llu level: %u\n",
+ filter->match_gen, filter->match_level);