3 #include "kerncompat.h"
4 #include "radix-tree.h"
8 static int print_dir_item(struct btrfs_item
*item
,
9 struct btrfs_dir_item
*di
)
14 total
= btrfs_item_size(item
);
16 printf("\t\tdir index %Lu flags %u type %u\n",
17 btrfs_disk_key_objectid(&di
->location
),
20 printf("\t\tname %.*s\n",
21 btrfs_dir_name_len(di
),(char *)(di
+ 1));
22 len
= sizeof(*di
) + btrfs_dir_name_len(di
);
23 di
= (struct btrfs_dir_item
*)((char *)di
+ len
);
28 void btrfs_print_leaf(struct btrfs_root
*root
, struct btrfs_leaf
*l
)
31 u32 nr
= btrfs_header_nritems(&l
->header
);
32 struct btrfs_item
*item
;
33 struct btrfs_extent_item
*ei
;
34 struct btrfs_root_item
*ri
;
35 struct btrfs_dir_item
*di
;
36 struct btrfs_device_item
*devi
;
37 struct btrfs_inode_item
*ii
;
38 struct btrfs_file_extent_item
*fi
;
39 struct btrfs_csum_item
*ci
;
43 printf("leaf %Lu ptrs %d free space %d generation %Lu owner %Lu\n",
44 btrfs_header_blocknr(&l
->header
), nr
,
45 btrfs_leaf_free_space(root
, l
),
46 btrfs_header_generation(&l
->header
),
47 btrfs_header_owner(&l
->header
));
49 for (i
= 0 ; i
< nr
; i
++) {
51 type
= btrfs_disk_key_type(&item
->key
);
52 printf("\titem %d key (%Lu %x %Lu) itemoff %d itemsize %d\n",
54 btrfs_disk_key_objectid(&item
->key
),
55 btrfs_disk_key_flags(&item
->key
),
56 btrfs_disk_key_offset(&item
->key
),
57 btrfs_item_offset(item
),
58 btrfs_item_size(item
));
60 case BTRFS_INODE_ITEM_KEY
:
61 ii
= btrfs_item_ptr(l
, i
, struct btrfs_inode_item
);
62 printf("\t\tinode generation %Lu size %Lu mode %o\n",
63 btrfs_inode_generation(ii
),
65 btrfs_inode_mode(ii
));
67 case BTRFS_INLINE_DATA_KEY
:
68 p
= btrfs_item_ptr(l
, i
, char);
69 printf("\t\tinline data %.*s\n", 10, p
);
71 case BTRFS_DIR_ITEM_KEY
:
72 di
= btrfs_item_ptr(l
, i
, struct btrfs_dir_item
);
73 print_dir_item(l
->items
+ i
, di
);
75 case BTRFS_DIR_INDEX_KEY
:
76 di
= btrfs_item_ptr(l
, i
, struct btrfs_dir_item
);
77 print_dir_item(l
->items
+ i
, di
);
79 case BTRFS_ROOT_ITEM_KEY
:
80 ri
= btrfs_item_ptr(l
, i
, struct btrfs_root_item
);
81 printf("\t\troot data blocknr %Lu dirid %Lu refs %u\n",
82 btrfs_root_blocknr(ri
),
86 case BTRFS_EXTENT_ITEM_KEY
:
87 ei
= btrfs_item_ptr(l
, i
, struct btrfs_extent_item
);
88 printf("\t\textent data refs %u owner %Lu\n",
89 btrfs_extent_refs(ei
),
90 btrfs_extent_owner(ei
));
92 case BTRFS_CSUM_ITEM_KEY
:
93 ci
= btrfs_item_ptr(l
, i
,
94 struct btrfs_csum_item
);
95 printf("\t\tcsum item\n");
97 case BTRFS_EXTENT_DATA_KEY
:
98 fi
= btrfs_item_ptr(l
, i
,
99 struct btrfs_file_extent_item
);
100 if (btrfs_file_extent_type(fi
) ==
101 BTRFS_FILE_EXTENT_INLINE
) {
102 printf("\t\tinline extent data size %u\n",
103 btrfs_file_extent_inline_len(l
->items
+ i
));
106 printf("\t\textent data disk block %Lu nr %Lu\n",
107 btrfs_file_extent_disk_blocknr(fi
),
108 btrfs_file_extent_disk_num_blocks(fi
));
109 printf("\t\textent data offset %Lu nr %Lu\n",
110 btrfs_file_extent_offset(fi
),
111 btrfs_file_extent_num_blocks(fi
));
113 case BTRFS_DEV_ITEM_KEY
:
114 devi
= btrfs_item_ptr(l
, i
, struct btrfs_device_item
);
115 printf("\t\tdev id %Lu namelen %u name %.*s\n",
116 btrfs_device_id(devi
),
117 btrfs_device_pathlen(devi
),
118 btrfs_device_pathlen(devi
),
121 case BTRFS_STRING_ITEM_KEY
:
122 printf("\t\titem data %.*s\n", btrfs_item_size(item
),
123 btrfs_leaf_data(l
) + btrfs_item_offset(item
));
129 void btrfs_print_tree(struct btrfs_root
*root
, struct btrfs_buffer
*t
)
133 struct btrfs_node
*c
;
138 nr
= btrfs_header_nritems(&c
->header
);
139 if (btrfs_is_leaf(c
)) {
140 btrfs_print_leaf(root
, (struct btrfs_leaf
*)c
);
143 printf("node %Lu level %d ptrs %d free %u generation %Lu owner %Lu\n",
145 btrfs_header_level(&c
->header
), nr
,
146 (u32
)BTRFS_NODEPTRS_PER_BLOCK(root
) - nr
,
147 btrfs_header_generation(&c
->header
),
148 btrfs_header_owner(&c
->header
));
150 for (i
= 0; i
< nr
; i
++) {
151 printf("\tkey %d (%Lu %x %Lu) block %Lu\n",
153 c
->ptrs
[i
].key
.objectid
,
154 c
->ptrs
[i
].key
.flags
,
155 c
->ptrs
[i
].key
.offset
,
156 btrfs_node_blockptr(c
, i
));
159 for (i
= 0; i
< nr
; i
++) {
160 struct btrfs_buffer
*next_buf
= read_tree_block(root
,
161 btrfs_node_blockptr(c
, i
));
162 struct btrfs_node
*next
= &next_buf
->node
;
163 if (btrfs_is_leaf(next
) &&
164 btrfs_header_level(&c
->header
) != 1)
166 if (btrfs_header_level(&next
->header
) !=
167 btrfs_header_level(&c
->header
) - 1)
169 btrfs_print_tree(root
, next_buf
);
170 btrfs_block_release(root
, next_buf
);