debug.c 7.6 KB

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