Skip to content

Commit 96fb032

Browse files
fdmananakdave
authored andcommitted
btrfs: print-tree: print more information about dir items
Currently we only print the object id component of the location key from a dir item and the flags. We are missing the whole key, transid and the name and data lengths. We are also ignoring the fact that we can have multiple dir item objects encoded in a single item for a BTRFS_DIR_ITEM_KEY key, so what we print is only for the first item. Improve on this by iterating on all dir items and print the missing information. This is done with the same format as in btrfs-progs, what we miss is printing the names and data since not only that would require some processing and escaping like in btrfs-progs, but it would also reveal information that may be sensitive and users may not want to share that in case that get a leaf dumped in dmesg. Reviewed-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent ac9affd commit 96fb032

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

fs/btrfs/print-tree.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,20 +257,41 @@ static void print_inode_item(const struct extent_buffer *eb, int i)
257257
print_timespec(eb, &ii->otime, "\t\totime ", "\n");
258258
}
259259

260+
static void print_dir_item(const struct extent_buffer *eb, int i)
261+
{
262+
const u32 size = btrfs_item_size(eb, i);
263+
struct btrfs_dir_item *di = btrfs_item_ptr(eb, i, struct btrfs_dir_item);
264+
u32 cur = 0;
265+
266+
while (cur < size) {
267+
const u32 name_len = btrfs_dir_name_len(eb, di);
268+
const u32 data_len = btrfs_dir_data_len(eb, di);
269+
const u32 len = sizeof(*di) + name_len + data_len;
270+
struct btrfs_key location;
271+
272+
btrfs_dir_item_key_to_cpu(eb, di, &location);
273+
pr_info("\t\tlocation key (%llu %u %llu) type %d\n",
274+
location.objectid, location.type, location.offset,
275+
btrfs_dir_ftype(eb, di));
276+
pr_info("\t\ttransid %llu data_len %u name_len %u\n",
277+
btrfs_dir_transid(eb, di), data_len, name_len);
278+
di = (struct btrfs_dir_item *)((char *)di + len);
279+
cur += len;
280+
}
281+
}
282+
260283
void btrfs_print_leaf(const struct extent_buffer *l)
261284
{
262285
struct btrfs_fs_info *fs_info;
263286
int i;
264287
u32 type, nr;
265288
struct btrfs_root_item *ri;
266-
struct btrfs_dir_item *di;
267289
struct btrfs_block_group_item *bi;
268290
struct btrfs_file_extent_item *fi;
269291
struct btrfs_extent_data_ref *dref;
270292
struct btrfs_shared_data_ref *sref;
271293
struct btrfs_dev_extent *dev_extent;
272294
struct btrfs_key key;
273-
struct btrfs_key found_key;
274295

275296
if (!l)
276297
return;
@@ -294,11 +315,7 @@ void btrfs_print_leaf(const struct extent_buffer *l)
294315
print_inode_item(l, i);
295316
break;
296317
case BTRFS_DIR_ITEM_KEY:
297-
di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
298-
btrfs_dir_item_key_to_cpu(l, di, &found_key);
299-
pr_info("\t\tdir oid %llu flags %u\n",
300-
found_key.objectid,
301-
btrfs_dir_flags(l, di));
318+
print_dir_item(l, i);
302319
break;
303320
case BTRFS_ROOT_ITEM_KEY:
304321
ri = btrfs_item_ptr(l, i, struct btrfs_root_item);

0 commit comments

Comments
 (0)