debug.c 7.5 KB

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