btrfs-progs: print-tree: Add leaf flags and backref revision output
diff mbox

Message ID 20170508073810.2811-1-quwenruo@cn.fujitsu.com
State New
Headers show

Commit Message

Qu Wenruo May 8, 2017, 7:38 a.m. UTC
Btrfs header has a u64 member flags, whose lowest 56 bits are for header
flags like WRITTEN and RELOC.
And its highest 8 bits are for backref revision.

Manually checking btrfs_header_flags() will be a pain, so add such leaf
flags and backref revision output for print-tree.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 print-tree.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

David Sterba May 9, 2017, 5:44 p.m. UTC | #1
On Mon, May 08, 2017 at 03:38:10PM +0800, Qu Wenruo wrote:
> Btrfs header has a u64 member flags, whose lowest 56 bits are for header
> flags like WRITTEN and RELOC.
> And its highest 8 bits are for backref revision.
> 
> Manually checking btrfs_header_flags() will be a pain, so add such leaf
> flags and backref revision output for print-tree.
> 
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/print-tree.c b/print-tree.c
index 5af80e87..823b87c1 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -938,13 +938,35 @@  static void print_dev_stats(struct extent_buffer *eb,
 	}
 }
 
+/* Caller must ensure sizeof(*ret) >= 14 "WRITTEN|RELOC" */
+static void header_flags_to_str(u64 flags, char *ret)
+{
+	int empty = 1;
+
+	if (flags & BTRFS_HEADER_FLAG_WRITTEN) {
+		empty = 0;
+		strcpy(ret, "WRITTEN");
+	}
+	if (flags & BTRFS_HEADER_FLAG_RELOC) {
+		if (!empty)
+			strcat(ret, "|");
+		strcat(ret, "RELOC");
+	}
+}
+
 void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb)
 {
 	struct btrfs_item *item;
 	struct btrfs_disk_key disk_key;
+	char flags_str[128];
 	u32 i;
 	u32 nr;
+	u64 flags;
+	u8 backref_rev;
 
+	flags = btrfs_header_flags(eb) & ~BTRFS_BACKREF_REV_MASK;
+	backref_rev = btrfs_header_flags(eb) >> BTRFS_BACKREF_REV_SHIFT;
+	header_flags_to_str(flags, flags_str);
 	nr = btrfs_header_nritems(eb);
 
 	printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
@@ -952,6 +974,8 @@  void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb)
 		btrfs_leaf_free_space(root, eb),
 		(unsigned long long)btrfs_header_generation(eb),
 		(unsigned long long)btrfs_header_owner(eb));
+	printf("leaf %llu flags 0x%llx(%s) backref revision %d\n",
+		btrfs_header_bytenr(eb), flags, flags_str, backref_rev);
 	print_uuids(eb);
 	fflush(stdout);