debug.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/fs/befs/debug.c
  4. *
  5. * Copyright (C) 2001 Will Dyson (will_dyson at pobox.com)
  6. *
  7. * With help from the ntfs-tng driver by Anton Altparmakov
  8. *
  9. * Copyright (C) 1999 Makoto Kato (m_kato@ga2.so-net.ne.jp)
  10. *
  11. * debug functions
  12. */
  13. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  14. #ifdef __KERNEL__
  15. #include <stdarg.h>
  16. #include <linux/string.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/kernel.h>
  19. #include <linux/fs.h>
  20. #include <linux/slab.h>
  21. #endif /* __KERNEL__ */
  22. #include "befs.h"
  23. void
  24. befs_error(const struct super_block *sb, const char *fmt, ...)
  25. {
  26. struct va_format vaf;
  27. va_list args;
  28. va_start(args, fmt);
  29. vaf.fmt = fmt;
  30. vaf.va = &args;
  31. pr_err("(%s): %pV\n", sb->s_id, &vaf);
  32. va_end(args);
  33. }
  34. void
  35. befs_warning(const struct super_block *sb, const char *fmt, ...)
  36. {
  37. struct va_format vaf;
  38. va_list args;
  39. va_start(args, fmt);
  40. vaf.fmt = fmt;
  41. vaf.va = &args;
  42. pr_warn("(%s): %pV\n", sb->s_id, &vaf);
  43. va_end(args);
  44. }
  45. void
  46. befs_debug(const struct super_block *sb, const char *fmt, ...)
  47. {
  48. #ifdef CONFIG_BEFS_DEBUG
  49. struct va_format vaf;
  50. va_list args;
  51. va_start(args, fmt);
  52. vaf.fmt = fmt;
  53. vaf.va = &args;
  54. pr_debug("(%s): %pV\n", sb->s_id, &vaf);
  55. va_end(args);
  56. #endif //CONFIG_BEFS_DEBUG
  57. }
  58. void
  59. befs_dump_inode(const struct super_block *sb, befs_inode *inode)
  60. {
  61. #ifdef CONFIG_BEFS_DEBUG
  62. befs_block_run tmp_run;
  63. befs_debug(sb, "befs_inode information");
  64. befs_debug(sb, " magic1 %08x", fs32_to_cpu(sb, inode->magic1));
  65. tmp_run = fsrun_to_cpu(sb, inode->inode_num);
  66. befs_debug(sb, " inode_num %u, %hu, %hu",
  67. tmp_run.allocation_group, tmp_run.start, tmp_run.len);
  68. befs_debug(sb, " uid %u", fs32_to_cpu(sb, inode->uid));
  69. befs_debug(sb, " gid %u", fs32_to_cpu(sb, inode->gid));
  70. befs_debug(sb, " mode %08x", fs32_to_cpu(sb, inode->mode));
  71. befs_debug(sb, " flags %08x", fs32_to_cpu(sb, inode->flags));
  72. befs_debug(sb, " create_time %llu",
  73. fs64_to_cpu(sb, inode->create_time));
  74. befs_debug(sb, " last_modified_time %llu",
  75. fs64_to_cpu(sb, inode->last_modified_time));
  76. tmp_run = fsrun_to_cpu(sb, inode->parent);
  77. befs_debug(sb, " parent [%u, %hu, %hu]",
  78. tmp_run.allocation_group, tmp_run.start, tmp_run.len);
  79. tmp_run = fsrun_to_cpu(sb, inode->attributes);
  80. befs_debug(sb, " attributes [%u, %hu, %hu]",
  81. tmp_run.allocation_group, tmp_run.start, tmp_run.len);
  82. befs_debug(sb, " type %08x", fs32_to_cpu(sb, inode->type));
  83. befs_debug(sb, " inode_size %u", fs32_to_cpu(sb, inode->inode_size));
  84. if (S_ISLNK(fs32_to_cpu(sb, inode->mode))) {
  85. befs_debug(sb, " Symbolic link [%s]", inode->data.symlink);
  86. } else {
  87. int i;
  88. for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; i++) {
  89. tmp_run =
  90. fsrun_to_cpu(sb, inode->data.datastream.direct[i]);
  91. befs_debug(sb, " direct %d [%u, %hu, %hu]", i,
  92. tmp_run.allocation_group, tmp_run.start,
  93. tmp_run.len);
  94. }
  95. befs_debug(sb, " max_direct_range %llu",
  96. fs64_to_cpu(sb,
  97. inode->data.datastream.
  98. max_direct_range));
  99. tmp_run = fsrun_to_cpu(sb, inode->data.datastream.indirect);
  100. befs_debug(sb, " indirect [%u, %hu, %hu]",
  101. tmp_run.allocation_group,
  102. tmp_run.start, tmp_run.len);
  103. befs_debug(sb, " max_indirect_range %llu",
  104. fs64_to_cpu(sb,
  105. inode->data.datastream.
  106. max_indirect_range));
  107. tmp_run =
  108. fsrun_to_cpu(sb, inode->data.datastream.double_indirect);
  109. befs_debug(sb, " double indirect [%u, %hu, %hu]",
  110. tmp_run.allocation_group, tmp_run.start,
  111. tmp_run.len);
  112. befs_debug(sb, " max_double_indirect_range %llu",
  113. fs64_to_cpu(sb,
  114. inode->data.datastream.
  115. max_double_indirect_range));
  116. befs_debug(sb, " size %llu",
  117. fs64_to_cpu(sb, inode->data.datastream.size));
  118. }
  119. #endif //CONFIG_BEFS_DEBUG
  120. }
  121. /*
  122. * Display super block structure for debug.
  123. */
  124. void
  125. befs_dump_super_block(const struct super_block *sb, befs_super_block *sup)
  126. {
  127. #ifdef CONFIG_BEFS_DEBUG
  128. befs_block_run tmp_run;
  129. befs_debug(sb, "befs_super_block information");
  130. befs_debug(sb, " name %s", sup->name);
  131. befs_debug(sb, " magic1 %08x", fs32_to_cpu(sb, sup->magic1));
  132. befs_debug(sb, " fs_byte_order %08x",
  133. fs32_to_cpu(sb, sup->fs_byte_order));
  134. befs_debug(sb, " block_size %u", fs32_to_cpu(sb, sup->block_size));
  135. befs_debug(sb, " block_shift %u", fs32_to_cpu(sb, sup->block_shift));
  136. befs_debug(sb, " num_blocks %llu", fs64_to_cpu(sb, sup->num_blocks));
  137. befs_debug(sb, " used_blocks %llu", fs64_to_cpu(sb, sup->used_blocks));
  138. befs_debug(sb, " inode_size %u", fs32_to_cpu(sb, sup->inode_size));
  139. befs_debug(sb, " magic2 %08x", fs32_to_cpu(sb, sup->magic2));
  140. befs_debug(sb, " blocks_per_ag %u",
  141. fs32_to_cpu(sb, sup->blocks_per_ag));
  142. befs_debug(sb, " ag_shift %u", fs32_to_cpu(sb, sup->ag_shift));
  143. befs_debug(sb, " num_ags %u", fs32_to_cpu(sb, sup->num_ags));
  144. befs_debug(sb, " flags %08x", fs32_to_cpu(sb, sup->flags));
  145. tmp_run = fsrun_to_cpu(sb, sup->log_blocks);
  146. befs_debug(sb, " log_blocks %u, %hu, %hu",
  147. tmp_run.allocation_group, tmp_run.start, tmp_run.len);
  148. befs_debug(sb, " log_start %lld", fs64_to_cpu(sb, sup->log_start));
  149. befs_debug(sb, " log_end %lld", fs64_to_cpu(sb, sup->log_end));
  150. befs_debug(sb, " magic3 %08x", fs32_to_cpu(sb, sup->magic3));
  151. tmp_run = fsrun_to_cpu(sb, sup->root_dir);
  152. befs_debug(sb, " root_dir %u, %hu, %hu",
  153. tmp_run.allocation_group, tmp_run.start, tmp_run.len);
  154. tmp_run = fsrun_to_cpu(sb, sup->indices);
  155. befs_debug(sb, " indices %u, %hu, %hu",
  156. tmp_run.allocation_group, tmp_run.start, tmp_run.len);
  157. #endif //CONFIG_BEFS_DEBUG
  158. }
  159. #if 0
  160. /* unused */
  161. void
  162. befs_dump_small_data(const struct super_block *sb, befs_small_data *sd)
  163. {
  164. }
  165. /* unused */
  166. void
  167. befs_dump_run(const struct super_block *sb, befs_disk_block_run run)
  168. {
  169. #ifdef CONFIG_BEFS_DEBUG
  170. befs_block_run n = fsrun_to_cpu(sb, run);
  171. befs_debug(sb, "[%u, %hu, %hu]", n.allocation_group, n.start, n.len);
  172. #endif //CONFIG_BEFS_DEBUG
  173. }
  174. #endif /* 0 */
  175. void
  176. befs_dump_index_entry(const struct super_block *sb,
  177. befs_disk_btree_super *super)
  178. {
  179. #ifdef CONFIG_BEFS_DEBUG
  180. befs_debug(sb, "Btree super structure");
  181. befs_debug(sb, " magic %08x", fs32_to_cpu(sb, super->magic));
  182. befs_debug(sb, " node_size %u", fs32_to_cpu(sb, super->node_size));
  183. befs_debug(sb, " max_depth %08x", fs32_to_cpu(sb, super->max_depth));
  184. befs_debug(sb, " data_type %08x", fs32_to_cpu(sb, super->data_type));
  185. befs_debug(sb, " root_node_pointer %016LX",
  186. fs64_to_cpu(sb, super->root_node_ptr));
  187. befs_debug(sb, " free_node_pointer %016LX",
  188. fs64_to_cpu(sb, super->free_node_ptr));
  189. befs_debug(sb, " maximum size %016LX",
  190. fs64_to_cpu(sb, super->max_size));
  191. #endif //CONFIG_BEFS_DEBUG
  192. }
  193. void
  194. befs_dump_index_node(const struct super_block *sb, befs_btree_nodehead *node)
  195. {
  196. #ifdef CONFIG_BEFS_DEBUG
  197. befs_debug(sb, "Btree node structure");
  198. befs_debug(sb, " left %016LX", fs64_to_cpu(sb, node->left));
  199. befs_debug(sb, " right %016LX", fs64_to_cpu(sb, node->right));
  200. befs_debug(sb, " overflow %016LX", fs64_to_cpu(sb, node->overflow));
  201. befs_debug(sb, " all_key_count %hu",
  202. fs16_to_cpu(sb, node->all_key_count));
  203. befs_debug(sb, " all_key_length %hu",
  204. fs16_to_cpu(sb, node->all_key_length));
  205. #endif //CONFIG_BEFS_DEBUG
  206. }