btrfs-progs: dump-tree: pass item size instead of item

Several functions take item but use just the size, we can factor the
item size and use that.

Signed-off-by: David Sterba <dsterba@suse.com>
master
David Sterba 2016-11-02 10:15:32 +01:00
parent ae00d4a251
commit e9c1121495
1 changed files with 16 additions and 20 deletions

View File

@ -62,10 +62,9 @@ static void print_dir_item_type(struct extent_buffer *eb,
} }
} }
static int print_dir_item(struct extent_buffer *eb, struct btrfs_item *item, static int print_dir_item(struct extent_buffer *eb, u32 size,
struct btrfs_dir_item *di) struct btrfs_dir_item *di)
{ {
u32 total;
u32 cur = 0; u32 cur = 0;
u32 len; u32 len;
u32 name_len; u32 name_len;
@ -73,8 +72,7 @@ static int print_dir_item(struct extent_buffer *eb, struct btrfs_item *item,
char namebuf[BTRFS_NAME_LEN]; char namebuf[BTRFS_NAME_LEN];
struct btrfs_disk_key location; struct btrfs_disk_key location;
total = btrfs_item_size(eb, item); while (cur < size) {
while(cur < total) {
btrfs_dir_item_key(eb, di, &location); btrfs_dir_item_key(eb, di, &location);
printf("\t\tlocation "); printf("\t\tlocation ");
btrfs_print_key(&location); btrfs_print_key(&location);
@ -102,11 +100,9 @@ static int print_dir_item(struct extent_buffer *eb, struct btrfs_item *item,
return 0; return 0;
} }
static int print_inode_extref_item(struct extent_buffer *eb, static int print_inode_extref_item(struct extent_buffer *eb, u32 size,
struct btrfs_item *item, struct btrfs_inode_extref *extref)
struct btrfs_inode_extref *extref)
{ {
u32 total;
u32 cur = 0; u32 cur = 0;
u32 len; u32 len;
u32 name_len = 0; u32 name_len = 0;
@ -114,9 +110,7 @@ static int print_inode_extref_item(struct extent_buffer *eb,
u64 parent_objid; u64 parent_objid;
char namebuf[BTRFS_NAME_LEN]; char namebuf[BTRFS_NAME_LEN];
total = btrfs_item_size(eb, item); while (cur < size) {
while (cur < total) {
index = btrfs_inode_extref_index(eb, extref); index = btrfs_inode_extref_index(eb, extref);
name_len = btrfs_inode_extref_name_len(eb, extref); name_len = btrfs_inode_extref_name_len(eb, extref);
parent_objid = btrfs_inode_extref_parent(eb, extref); parent_objid = btrfs_inode_extref_parent(eb, extref);
@ -138,17 +132,16 @@ static int print_inode_extref_item(struct extent_buffer *eb,
return 0; return 0;
} }
static int print_inode_ref_item(struct extent_buffer *eb, struct btrfs_item *item, static int print_inode_ref_item(struct extent_buffer *eb, u32 size,
struct btrfs_inode_ref *ref) struct btrfs_inode_ref *ref)
{ {
u32 total;
u32 cur = 0; u32 cur = 0;
u32 len; u32 len;
u32 name_len; u32 name_len;
u64 index; u64 index;
char namebuf[BTRFS_NAME_LEN]; char namebuf[BTRFS_NAME_LEN];
total = btrfs_item_size(eb, item);
while(cur < total) { while (cur < size) {
name_len = btrfs_inode_ref_name_len(eb, ref); name_len = btrfs_inode_ref_name_len(eb, ref);
index = btrfs_inode_ref_index(eb, ref); index = btrfs_inode_ref_index(eb, ref);
len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf); len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
@ -1074,7 +1067,10 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
print_uuids(l); print_uuids(l);
fflush(stdout); fflush(stdout);
for (i = 0 ; i < nr ; i++) { for (i = 0 ; i < nr ; i++) {
u32 item_size;
item = btrfs_item_nr(i); item = btrfs_item_nr(i);
item_size = btrfs_item_size(l, item);
btrfs_item_key(l, &disk_key, i); btrfs_item_key(l, &disk_key, i);
objectid = btrfs_disk_key_objectid(&disk_key); objectid = btrfs_disk_key_objectid(&disk_key);
type = btrfs_disk_key_type(&disk_key); type = btrfs_disk_key_type(&disk_key);
@ -1095,17 +1091,17 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
break; break;
case BTRFS_INODE_REF_KEY: case BTRFS_INODE_REF_KEY:
iref = btrfs_item_ptr(l, i, struct btrfs_inode_ref); iref = btrfs_item_ptr(l, i, struct btrfs_inode_ref);
print_inode_ref_item(l, item, iref); print_inode_ref_item(l, item_size, iref);
break; break;
case BTRFS_INODE_EXTREF_KEY: case BTRFS_INODE_EXTREF_KEY:
iref2 = btrfs_item_ptr(l, i, struct btrfs_inode_extref); iref2 = btrfs_item_ptr(l, i, struct btrfs_inode_extref);
print_inode_extref_item(l, item, iref2); print_inode_extref_item(l, item_size, iref2);
break; break;
case BTRFS_DIR_ITEM_KEY: case BTRFS_DIR_ITEM_KEY:
case BTRFS_DIR_INDEX_KEY: case BTRFS_DIR_INDEX_KEY:
case BTRFS_XATTR_ITEM_KEY: case BTRFS_XATTR_ITEM_KEY:
di = btrfs_item_ptr(l, i, struct btrfs_dir_item); di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
print_dir_item(l, item, di); print_dir_item(l, item_size, di);
break; break;
case BTRFS_DIR_LOG_INDEX_KEY: case BTRFS_DIR_LOG_INDEX_KEY:
case BTRFS_DIR_LOG_ITEM_KEY: case BTRFS_DIR_LOG_ITEM_KEY:
@ -1284,7 +1280,7 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
case BTRFS_STRING_ITEM_KEY: case BTRFS_STRING_ITEM_KEY:
/* dirty, but it's simple */ /* dirty, but it's simple */
str = l->data + btrfs_item_ptr_offset(l, i); str = l->data + btrfs_item_ptr_offset(l, i);
printf("\t\titem data %.*s\n", btrfs_item_size(l, item), str); printf("\t\titem data %.*s\n", item_size, str);
break; break;
case BTRFS_PERSISTENT_ITEM_KEY: case BTRFS_PERSISTENT_ITEM_KEY:
printf("\t\tpersistent item objectid "); printf("\t\tpersistent item objectid ");
@ -1294,7 +1290,7 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
case BTRFS_DEV_STATS_OBJECTID: case BTRFS_DEV_STATS_OBJECTID:
print_dev_stats(l, btrfs_item_ptr(l, i, print_dev_stats(l, btrfs_item_ptr(l, i,
struct btrfs_dev_stats_item), struct btrfs_dev_stats_item),
btrfs_item_size(l, item)); item_size);
break; break;
default: default:
printf("\t\tunknown persistent item objectid %llu\n", printf("\t\tunknown persistent item objectid %llu\n",