print-tree.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (C) 2007 Oracle. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License v2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public
  14. * License along with this program; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 021110-1307, USA.
  17. */
  18. #include "ctree.h"
  19. #include "disk-io.h"
  20. #include "print-tree.h"
  21. void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
  22. {
  23. int i;
  24. u32 nr = btrfs_header_nritems(l);
  25. struct btrfs_item *item;
  26. struct btrfs_extent_item *ei;
  27. struct btrfs_root_item *ri;
  28. struct btrfs_dir_item *di;
  29. struct btrfs_inode_item *ii;
  30. struct btrfs_block_group_item *bi;
  31. struct btrfs_file_extent_item *fi;
  32. struct btrfs_key key;
  33. struct btrfs_key found_key;
  34. u32 type;
  35. printk("leaf %llu total ptrs %d free space %d\n",
  36. (unsigned long long)btrfs_header_blocknr(l), nr,
  37. btrfs_leaf_free_space(root, l));
  38. for (i = 0 ; i < nr ; i++) {
  39. item = btrfs_item_nr(l, i);
  40. btrfs_item_key_to_cpu(l, &key, i);
  41. type = btrfs_key_type(&key);
  42. printk("\titem %d key (%llu %x %llu) itemoff %d itemsize %d\n",
  43. i,
  44. (unsigned long long)key.objectid, type,
  45. (unsigned long long)key.offset,
  46. btrfs_item_offset(l, item), btrfs_item_size(l, item));
  47. switch (type) {
  48. case BTRFS_INODE_ITEM_KEY:
  49. ii = btrfs_item_ptr(l, i, struct btrfs_inode_item);
  50. printk("\t\tinode generation %llu size %llu mode %o\n",
  51. (unsigned long long)btrfs_inode_generation(l, ii),
  52. (unsigned long long)btrfs_inode_size(l, ii),
  53. btrfs_inode_mode(l, ii));
  54. break;
  55. case BTRFS_DIR_ITEM_KEY:
  56. di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
  57. btrfs_dir_item_key_to_cpu(l, di, &found_key);
  58. printk("\t\tdir oid %llu flags %u type %u\n",
  59. (unsigned long long)found_key.objectid,
  60. btrfs_dir_flags(l, di),
  61. btrfs_dir_type(l, di));
  62. break;
  63. case BTRFS_ROOT_ITEM_KEY:
  64. ri = btrfs_item_ptr(l, i, struct btrfs_root_item);
  65. printk("\t\troot data blocknr %llu refs %u\n",
  66. (unsigned long long)btrfs_disk_root_blocknr(l, ri),
  67. btrfs_disk_root_refs(l, ri));
  68. break;
  69. case BTRFS_EXTENT_ITEM_KEY:
  70. ei = btrfs_item_ptr(l, i, struct btrfs_extent_item);
  71. printk("\t\textent data refs %u\n",
  72. btrfs_extent_refs(l, ei));
  73. break;
  74. case BTRFS_EXTENT_DATA_KEY:
  75. fi = btrfs_item_ptr(l, i,
  76. struct btrfs_file_extent_item);
  77. if (btrfs_file_extent_type(l, fi) ==
  78. BTRFS_FILE_EXTENT_INLINE) {
  79. printk("\t\tinline extent data size %u\n",
  80. btrfs_file_extent_inline_len(l, item));
  81. break;
  82. }
  83. printk("\t\textent data disk block %llu nr %llu\n",
  84. (unsigned long long)btrfs_file_extent_disk_blocknr(l, fi),
  85. (unsigned long long)btrfs_file_extent_disk_num_blocks(l, fi));
  86. printk("\t\textent data offset %llu nr %llu\n",
  87. (unsigned long long)btrfs_file_extent_offset(l, fi),
  88. (unsigned long long)btrfs_file_extent_num_blocks(l, fi));
  89. break;
  90. case BTRFS_BLOCK_GROUP_ITEM_KEY:
  91. bi = btrfs_item_ptr(l, i,
  92. struct btrfs_block_group_item);
  93. printk("\t\tblock group used %llu\n",
  94. (unsigned long long)btrfs_disk_block_group_used(l, bi));
  95. break;
  96. };
  97. }
  98. }
  99. void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *c)
  100. {
  101. int i;
  102. u32 nr;
  103. struct btrfs_key key;
  104. if (!c)
  105. return;
  106. nr = btrfs_header_nritems(c);
  107. if (btrfs_is_leaf(c)) {
  108. btrfs_print_leaf(root, c);
  109. return;
  110. }
  111. printk("node %llu level %d total ptrs %d free spc %u\n",
  112. (unsigned long long)btrfs_header_blocknr(c),
  113. btrfs_header_level(c), nr,
  114. (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr);
  115. for (i = 0; i < nr; i++) {
  116. btrfs_node_key_to_cpu(c, &key, i);
  117. printk("\tkey %d (%llu %u %llu) block %llu\n",
  118. i,
  119. (unsigned long long)key.objectid,
  120. key.type,
  121. (unsigned long long)key.offset,
  122. (unsigned long long)btrfs_node_blockptr(c, i));
  123. }
  124. for (i = 0; i < nr; i++) {
  125. struct extent_buffer *next = read_tree_block(root,
  126. btrfs_node_blockptr(c, i));
  127. if (btrfs_is_leaf(next) &&
  128. btrfs_header_level(c) != 1)
  129. BUG();
  130. if (btrfs_header_level(next) !=
  131. btrfs_header_level(c) - 1)
  132. BUG();
  133. btrfs_print_tree(root, next);
  134. free_extent_buffer(next);
  135. }
  136. }