diff mbox

load_chunk_info() : wrong search key 'type'

Message ID 20170917195028.3124-2-kreijack@libero.it (mailing list archive)
State New, archived
Headers show

Commit Message

Goffredo Baroncelli Sept. 17, 2017, 7:50 p.m. UTC
From: Goffredo Baroncelli <kreijack@inwind.it>

The function load_chunk_info() doesn't initialize correctly the
sk->min/max_type when it calls the TREE_SEARCH ioctl: these keys are swapped.
Moreover this function assumes that all the items contained in the tree
BTRFS_CHUNK_TREE_OBJECTID are of type BTRFS_CHUNK_ITEM_KEY, however some
items are of type DEV_ITEM. Add an if( ) to pick only the right ones.

Signed-off-by: G.Baroncelli <kreijack@inwind.it>
---
 cmds-fi-usage.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
diff mbox

Patch

diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c
index 6c846c15..52d63524 100644
--- a/cmds-fi-usage.c
+++ b/cmds-fi-usage.c
@@ -147,8 +147,8 @@  static int load_chunk_info(int fd, struct chunk_info **info_ptr, int *info_count
 
 	sk->min_objectid = 0;
 	sk->max_objectid = (u64)-1;
-	sk->max_type = 0;
-	sk->min_type = (u8)-1;
+	sk->min_type = 0;
+	sk->max_type = (u8)-1;
 	sk->min_offset = 0;
 	sk->max_offset = (u64)-1;
 	sk->min_transid = 0;
@@ -174,20 +174,21 @@  static int load_chunk_info(int fd, struct chunk_info **info_ptr, int *info_count
 		off = 0;
 		for (i = 0; i < sk->nr_items; i++) {
 			struct btrfs_chunk *item;
+			u8 type;
 			sh = (struct btrfs_ioctl_search_header *)(args.buf +
 								  off);
-
+			type = btrfs_search_header_type(sh);
 			off += sizeof(*sh);
-			item = (struct btrfs_chunk *)(args.buf + off);
-
-			ret = add_info_to_list(info_ptr, info_count, item);
-			if (ret) {
-				*info_ptr = NULL;
-				return 1;
+			if (type == BTRFS_CHUNK_ITEM_KEY) {
+				item = (struct btrfs_chunk *)(args.buf + off);
+				ret = add_info_to_list(info_ptr, info_count, item);
+				if (ret) {
+					*info_ptr = NULL;
+					return 1;
+				}
 			}
 
 			off += btrfs_search_header_len(sh);
-
 			sk->min_objectid = btrfs_search_header_objectid(sh);
 			sk->min_type = btrfs_search_header_type(sh);
 			sk->min_offset = btrfs_search_header_offset(sh)+1;