prints.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. /*
  2. * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
  3. */
  4. #include <linux/config.h>
  5. #include <linux/time.h>
  6. #include <linux/fs.h>
  7. #include <linux/reiserfs_fs.h>
  8. #include <linux/string.h>
  9. #include <linux/buffer_head.h>
  10. #include <stdarg.h>
  11. static char error_buf[1024];
  12. static char fmt_buf[1024];
  13. static char off_buf[80];
  14. static char *reiserfs_cpu_offset(struct cpu_key *key)
  15. {
  16. if (cpu_key_k_type(key) == TYPE_DIRENTRY)
  17. sprintf(off_buf, "%Lu(%Lu)",
  18. (unsigned long long)
  19. GET_HASH_VALUE(cpu_key_k_offset(key)),
  20. (unsigned long long)
  21. GET_GENERATION_NUMBER(cpu_key_k_offset(key)));
  22. else
  23. sprintf(off_buf, "0x%Lx",
  24. (unsigned long long)cpu_key_k_offset(key));
  25. return off_buf;
  26. }
  27. static char *le_offset(struct reiserfs_key *key)
  28. {
  29. int version;
  30. version = le_key_version(key);
  31. if (le_key_k_type(version, key) == TYPE_DIRENTRY)
  32. sprintf(off_buf, "%Lu(%Lu)",
  33. (unsigned long long)
  34. GET_HASH_VALUE(le_key_k_offset(version, key)),
  35. (unsigned long long)
  36. GET_GENERATION_NUMBER(le_key_k_offset(version, key)));
  37. else
  38. sprintf(off_buf, "0x%Lx",
  39. (unsigned long long)le_key_k_offset(version, key));
  40. return off_buf;
  41. }
  42. static char *cpu_type(struct cpu_key *key)
  43. {
  44. if (cpu_key_k_type(key) == TYPE_STAT_DATA)
  45. return "SD";
  46. if (cpu_key_k_type(key) == TYPE_DIRENTRY)
  47. return "DIR";
  48. if (cpu_key_k_type(key) == TYPE_DIRECT)
  49. return "DIRECT";
  50. if (cpu_key_k_type(key) == TYPE_INDIRECT)
  51. return "IND";
  52. return "UNKNOWN";
  53. }
  54. static char *le_type(struct reiserfs_key *key)
  55. {
  56. int version;
  57. version = le_key_version(key);
  58. if (le_key_k_type(version, key) == TYPE_STAT_DATA)
  59. return "SD";
  60. if (le_key_k_type(version, key) == TYPE_DIRENTRY)
  61. return "DIR";
  62. if (le_key_k_type(version, key) == TYPE_DIRECT)
  63. return "DIRECT";
  64. if (le_key_k_type(version, key) == TYPE_INDIRECT)
  65. return "IND";
  66. return "UNKNOWN";
  67. }
  68. /* %k */
  69. static void sprintf_le_key(char *buf, struct reiserfs_key *key)
  70. {
  71. if (key)
  72. sprintf(buf, "[%d %d %s %s]", le32_to_cpu(key->k_dir_id),
  73. le32_to_cpu(key->k_objectid), le_offset(key),
  74. le_type(key));
  75. else
  76. sprintf(buf, "[NULL]");
  77. }
  78. /* %K */
  79. static void sprintf_cpu_key(char *buf, struct cpu_key *key)
  80. {
  81. if (key)
  82. sprintf(buf, "[%d %d %s %s]", key->on_disk_key.k_dir_id,
  83. key->on_disk_key.k_objectid, reiserfs_cpu_offset(key),
  84. cpu_type(key));
  85. else
  86. sprintf(buf, "[NULL]");
  87. }
  88. static void sprintf_de_head(char *buf, struct reiserfs_de_head *deh)
  89. {
  90. if (deh)
  91. sprintf(buf,
  92. "[offset=%d dir_id=%d objectid=%d location=%d state=%04x]",
  93. deh_offset(deh), deh_dir_id(deh), deh_objectid(deh),
  94. deh_location(deh), deh_state(deh));
  95. else
  96. sprintf(buf, "[NULL]");
  97. }
  98. static void sprintf_item_head(char *buf, struct item_head *ih)
  99. {
  100. if (ih) {
  101. strcpy(buf,
  102. (ih_version(ih) == KEY_FORMAT_3_6) ? "*3.6* " : "*3.5*");
  103. sprintf_le_key(buf + strlen(buf), &(ih->ih_key));
  104. sprintf(buf + strlen(buf), ", item_len %d, item_location %d, "
  105. "free_space(entry_count) %d",
  106. ih_item_len(ih), ih_location(ih), ih_free_space(ih));
  107. } else
  108. sprintf(buf, "[NULL]");
  109. }
  110. static void sprintf_direntry(char *buf, struct reiserfs_dir_entry *de)
  111. {
  112. char name[20];
  113. memcpy(name, de->de_name, de->de_namelen > 19 ? 19 : de->de_namelen);
  114. name[de->de_namelen > 19 ? 19 : de->de_namelen] = 0;
  115. sprintf(buf, "\"%s\"==>[%d %d]", name, de->de_dir_id, de->de_objectid);
  116. }
  117. static void sprintf_block_head(char *buf, struct buffer_head *bh)
  118. {
  119. sprintf(buf, "level=%d, nr_items=%d, free_space=%d rdkey ",
  120. B_LEVEL(bh), B_NR_ITEMS(bh), B_FREE_SPACE(bh));
  121. }
  122. static void sprintf_buffer_head(char *buf, struct buffer_head *bh)
  123. {
  124. char b[BDEVNAME_SIZE];
  125. sprintf(buf,
  126. "dev %s, size %zd, blocknr %llu, count %d, state 0x%lx, page %p, (%s, %s, %s)",
  127. bdevname(bh->b_bdev, b), bh->b_size,
  128. (unsigned long long)bh->b_blocknr, atomic_read(&(bh->b_count)),
  129. bh->b_state, bh->b_page,
  130. buffer_uptodate(bh) ? "UPTODATE" : "!UPTODATE",
  131. buffer_dirty(bh) ? "DIRTY" : "CLEAN",
  132. buffer_locked(bh) ? "LOCKED" : "UNLOCKED");
  133. }
  134. static void sprintf_disk_child(char *buf, struct disk_child *dc)
  135. {
  136. sprintf(buf, "[dc_number=%d, dc_size=%u]", dc_block_number(dc),
  137. dc_size(dc));
  138. }
  139. static char *is_there_reiserfs_struct(char *fmt, int *what, int *skip)
  140. {
  141. char *k = fmt;
  142. *skip = 0;
  143. while ((k = strchr(k, '%')) != NULL) {
  144. if (k[1] == 'k' || k[1] == 'K' || k[1] == 'h' || k[1] == 't' ||
  145. k[1] == 'z' || k[1] == 'b' || k[1] == 'y' || k[1] == 'a') {
  146. *what = k[1];
  147. break;
  148. }
  149. (*skip)++;
  150. k++;
  151. }
  152. return k;
  153. }
  154. /* debugging reiserfs we used to print out a lot of different
  155. variables, like keys, item headers, buffer heads etc. Values of
  156. most fields matter. So it took a long time just to write
  157. appropriative printk. With this reiserfs_warning you can use format
  158. specification for complex structures like you used to do with
  159. printfs for integers, doubles and pointers. For instance, to print
  160. out key structure you have to write just:
  161. reiserfs_warning ("bad key %k", key);
  162. instead of
  163. printk ("bad key %lu %lu %lu %lu", key->k_dir_id, key->k_objectid,
  164. key->k_offset, key->k_uniqueness);
  165. */
  166. static void prepare_error_buf(const char *fmt, va_list args)
  167. {
  168. char *fmt1 = fmt_buf;
  169. char *k;
  170. char *p = error_buf;
  171. int i, j, what, skip;
  172. strcpy(fmt1, fmt);
  173. while ((k = is_there_reiserfs_struct(fmt1, &what, &skip)) != NULL) {
  174. *k = 0;
  175. p += vsprintf(p, fmt1, args);
  176. for (i = 0; i < skip; i++)
  177. j = va_arg(args, int);
  178. switch (what) {
  179. case 'k':
  180. sprintf_le_key(p, va_arg(args, struct reiserfs_key *));
  181. break;
  182. case 'K':
  183. sprintf_cpu_key(p, va_arg(args, struct cpu_key *));
  184. break;
  185. case 'h':
  186. sprintf_item_head(p, va_arg(args, struct item_head *));
  187. break;
  188. case 't':
  189. sprintf_direntry(p,
  190. va_arg(args,
  191. struct reiserfs_dir_entry *));
  192. break;
  193. case 'y':
  194. sprintf_disk_child(p,
  195. va_arg(args, struct disk_child *));
  196. break;
  197. case 'z':
  198. sprintf_block_head(p,
  199. va_arg(args, struct buffer_head *));
  200. break;
  201. case 'b':
  202. sprintf_buffer_head(p,
  203. va_arg(args, struct buffer_head *));
  204. break;
  205. case 'a':
  206. sprintf_de_head(p,
  207. va_arg(args,
  208. struct reiserfs_de_head *));
  209. break;
  210. }
  211. p += strlen(p);
  212. fmt1 = k + 2;
  213. }
  214. vsprintf(p, fmt1, args);
  215. }
  216. /* in addition to usual conversion specifiers this accepts reiserfs
  217. specific conversion specifiers:
  218. %k to print little endian key,
  219. %K to print cpu key,
  220. %h to print item_head,
  221. %t to print directory entry
  222. %z to print block head (arg must be struct buffer_head *
  223. %b to print buffer_head
  224. */
  225. #define do_reiserfs_warning(fmt)\
  226. {\
  227. va_list args;\
  228. va_start( args, fmt );\
  229. prepare_error_buf( fmt, args );\
  230. va_end( args );\
  231. }
  232. void reiserfs_warning(struct super_block *sb, const char *fmt, ...)
  233. {
  234. do_reiserfs_warning(fmt);
  235. if (sb)
  236. printk(KERN_WARNING "ReiserFS: %s: warning: %s\n",
  237. reiserfs_bdevname(sb), error_buf);
  238. else
  239. printk(KERN_WARNING "ReiserFS: warning: %s\n", error_buf);
  240. }
  241. /* No newline.. reiserfs_info calls can be followed by printk's */
  242. void reiserfs_info(struct super_block *sb, const char *fmt, ...)
  243. {
  244. do_reiserfs_warning(fmt);
  245. if (sb)
  246. printk(KERN_NOTICE "ReiserFS: %s: %s",
  247. reiserfs_bdevname(sb), error_buf);
  248. else
  249. printk(KERN_NOTICE "ReiserFS: %s", error_buf);
  250. }
  251. /* No newline.. reiserfs_printk calls can be followed by printk's */
  252. static void reiserfs_printk(const char *fmt, ...)
  253. {
  254. do_reiserfs_warning(fmt);
  255. printk(error_buf);
  256. }
  257. void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...)
  258. {
  259. #ifdef CONFIG_REISERFS_CHECK
  260. do_reiserfs_warning(fmt);
  261. if (s)
  262. printk(KERN_DEBUG "ReiserFS: %s: %s\n",
  263. reiserfs_bdevname(s), error_buf);
  264. else
  265. printk(KERN_DEBUG "ReiserFS: %s\n", error_buf);
  266. #endif
  267. }
  268. /* The format:
  269. maintainer-errorid: [function-name:] message
  270. where errorid is unique to the maintainer and function-name is
  271. optional, is recommended, so that anyone can easily find the bug
  272. with a simple grep for the short to type string
  273. maintainer-errorid. Don't bother with reusing errorids, there are
  274. lots of numbers out there.
  275. Example:
  276. reiserfs_panic(
  277. p_sb, "reiser-29: reiserfs_new_blocknrs: "
  278. "one of search_start or rn(%d) is equal to MAX_B_NUM,"
  279. "which means that we are optimizing location based on the bogus location of a temp buffer (%p).",
  280. rn, bh
  281. );
  282. Regular panic()s sometimes clear the screen before the message can
  283. be read, thus the need for the while loop.
  284. Numbering scheme for panic used by Vladimir and Anatoly( Hans completely ignores this scheme, and considers it
  285. pointless complexity):
  286. panics in reiserfs_fs.h have numbers from 1000 to 1999
  287. super.c 2000 to 2999
  288. preserve.c (unused) 3000 to 3999
  289. bitmap.c 4000 to 4999
  290. stree.c 5000 to 5999
  291. prints.c 6000 to 6999
  292. namei.c 7000 to 7999
  293. fix_nodes.c 8000 to 8999
  294. dir.c 9000 to 9999
  295. lbalance.c 10000 to 10999
  296. ibalance.c 11000 to 11999 not ready
  297. do_balan.c 12000 to 12999
  298. inode.c 13000 to 13999
  299. file.c 14000 to 14999
  300. objectid.c 15000 - 15999
  301. buffer.c 16000 - 16999
  302. symlink.c 17000 - 17999
  303. . */
  304. #ifdef CONFIG_REISERFS_CHECK
  305. extern struct tree_balance *cur_tb;
  306. #endif
  307. void reiserfs_panic(struct super_block *sb, const char *fmt, ...)
  308. {
  309. do_reiserfs_warning(fmt);
  310. printk(KERN_EMERG "REISERFS: panic (device %s): %s\n",
  311. reiserfs_bdevname(sb), error_buf);
  312. BUG();
  313. /* this is not actually called, but makes reiserfs_panic() "noreturn" */
  314. panic("REISERFS: panic (device %s): %s\n",
  315. reiserfs_bdevname(sb), error_buf);
  316. }
  317. void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...)
  318. {
  319. do_reiserfs_warning(fmt);
  320. if (reiserfs_error_panic(sb)) {
  321. panic(KERN_CRIT "REISERFS: panic (device %s): %s\n",
  322. reiserfs_bdevname(sb), error_buf);
  323. }
  324. if (sb->s_flags & MS_RDONLY)
  325. return;
  326. printk(KERN_CRIT "REISERFS: abort (device %s): %s\n",
  327. reiserfs_bdevname(sb), error_buf);
  328. sb->s_flags |= MS_RDONLY;
  329. reiserfs_journal_abort(sb, errno);
  330. }
  331. /* this prints internal nodes (4 keys/items in line) (dc_number,
  332. dc_size)[k_dirid, k_objectid, k_offset, k_uniqueness](dc_number,
  333. dc_size)...*/
  334. static int print_internal(struct buffer_head *bh, int first, int last)
  335. {
  336. struct reiserfs_key *key;
  337. struct disk_child *dc;
  338. int i;
  339. int from, to;
  340. if (!B_IS_KEYS_LEVEL(bh))
  341. return 1;
  342. check_internal(bh);
  343. if (first == -1) {
  344. from = 0;
  345. to = B_NR_ITEMS(bh);
  346. } else {
  347. from = first;
  348. to = last < B_NR_ITEMS(bh) ? last : B_NR_ITEMS(bh);
  349. }
  350. reiserfs_printk("INTERNAL NODE (%ld) contains %z\n", bh->b_blocknr, bh);
  351. dc = B_N_CHILD(bh, from);
  352. reiserfs_printk("PTR %d: %y ", from, dc);
  353. for (i = from, key = B_N_PDELIM_KEY(bh, from), dc++; i < to;
  354. i++, key++, dc++) {
  355. reiserfs_printk("KEY %d: %k PTR %d: %y ", i, key, i + 1, dc);
  356. if (i && i % 4 == 0)
  357. printk("\n");
  358. }
  359. printk("\n");
  360. return 0;
  361. }
  362. static int print_leaf(struct buffer_head *bh, int print_mode, int first,
  363. int last)
  364. {
  365. struct block_head *blkh;
  366. struct item_head *ih;
  367. int i, nr;
  368. int from, to;
  369. if (!B_IS_ITEMS_LEVEL(bh))
  370. return 1;
  371. check_leaf(bh);
  372. blkh = B_BLK_HEAD(bh);
  373. ih = B_N_PITEM_HEAD(bh, 0);
  374. nr = blkh_nr_item(blkh);
  375. printk
  376. ("\n===================================================================\n");
  377. reiserfs_printk("LEAF NODE (%ld) contains %z\n", bh->b_blocknr, bh);
  378. if (!(print_mode & PRINT_LEAF_ITEMS)) {
  379. reiserfs_printk("FIRST ITEM_KEY: %k, LAST ITEM KEY: %k\n",
  380. &(ih->ih_key), &((ih + nr - 1)->ih_key));
  381. return 0;
  382. }
  383. if (first < 0 || first > nr - 1)
  384. from = 0;
  385. else
  386. from = first;
  387. if (last < 0 || last > nr)
  388. to = nr;
  389. else
  390. to = last;
  391. ih += from;
  392. printk
  393. ("-------------------------------------------------------------------------------\n");
  394. printk
  395. ("|##| type | key | ilen | free_space | version | loc |\n");
  396. for (i = from; i < to; i++, ih++) {
  397. printk
  398. ("-------------------------------------------------------------------------------\n");
  399. reiserfs_printk("|%2d| %h |\n", i, ih);
  400. if (print_mode & PRINT_LEAF_ITEMS)
  401. op_print_item(ih, B_I_PITEM(bh, ih));
  402. }
  403. printk
  404. ("===================================================================\n");
  405. return 0;
  406. }
  407. char *reiserfs_hashname(int code)
  408. {
  409. if (code == YURA_HASH)
  410. return "rupasov";
  411. if (code == TEA_HASH)
  412. return "tea";
  413. if (code == R5_HASH)
  414. return "r5";
  415. return "unknown";
  416. }
  417. /* return 1 if this is not super block */
  418. static int print_super_block(struct buffer_head *bh)
  419. {
  420. struct reiserfs_super_block *rs =
  421. (struct reiserfs_super_block *)(bh->b_data);
  422. int skipped, data_blocks;
  423. char *version;
  424. char b[BDEVNAME_SIZE];
  425. if (is_reiserfs_3_5(rs)) {
  426. version = "3.5";
  427. } else if (is_reiserfs_3_6(rs)) {
  428. version = "3.6";
  429. } else if (is_reiserfs_jr(rs)) {
  430. version = ((sb_version(rs) == REISERFS_VERSION_2) ?
  431. "3.6" : "3.5");
  432. } else {
  433. return 1;
  434. }
  435. printk("%s\'s super block is in block %llu\n", bdevname(bh->b_bdev, b),
  436. (unsigned long long)bh->b_blocknr);
  437. printk("Reiserfs version %s\n", version);
  438. printk("Block count %u\n", sb_block_count(rs));
  439. printk("Blocksize %d\n", sb_blocksize(rs));
  440. printk("Free blocks %u\n", sb_free_blocks(rs));
  441. // FIXME: this would be confusing if
  442. // someone stores reiserfs super block in some data block ;)
  443. // skipped = (bh->b_blocknr * bh->b_size) / sb_blocksize(rs);
  444. skipped = bh->b_blocknr;
  445. data_blocks = sb_block_count(rs) - skipped - 1 - sb_bmap_nr(rs) -
  446. (!is_reiserfs_jr(rs) ? sb_jp_journal_size(rs) +
  447. 1 : sb_reserved_for_journal(rs)) - sb_free_blocks(rs);
  448. printk
  449. ("Busy blocks (skipped %d, bitmaps - %d, journal (or reserved) blocks - %d\n"
  450. "1 super block, %d data blocks\n", skipped, sb_bmap_nr(rs),
  451. (!is_reiserfs_jr(rs) ? (sb_jp_journal_size(rs) + 1) :
  452. sb_reserved_for_journal(rs)), data_blocks);
  453. printk("Root block %u\n", sb_root_block(rs));
  454. printk("Journal block (first) %d\n", sb_jp_journal_1st_block(rs));
  455. printk("Journal dev %d\n", sb_jp_journal_dev(rs));
  456. printk("Journal orig size %d\n", sb_jp_journal_size(rs));
  457. printk("FS state %d\n", sb_fs_state(rs));
  458. printk("Hash function \"%s\"\n",
  459. reiserfs_hashname(sb_hash_function_code(rs)));
  460. printk("Tree height %d\n", sb_tree_height(rs));
  461. return 0;
  462. }
  463. static int print_desc_block(struct buffer_head *bh)
  464. {
  465. struct reiserfs_journal_desc *desc;
  466. if (memcmp(get_journal_desc_magic(bh), JOURNAL_DESC_MAGIC, 8))
  467. return 1;
  468. desc = (struct reiserfs_journal_desc *)(bh->b_data);
  469. printk("Desc block %llu (j_trans_id %d, j_mount_id %d, j_len %d)",
  470. (unsigned long long)bh->b_blocknr, get_desc_trans_id(desc),
  471. get_desc_mount_id(desc), get_desc_trans_len(desc));
  472. return 0;
  473. }
  474. void print_block(struct buffer_head *bh, ...) //int print_mode, int first, int last)
  475. {
  476. va_list args;
  477. int mode, first, last;
  478. va_start(args, bh);
  479. if (!bh) {
  480. printk("print_block: buffer is NULL\n");
  481. return;
  482. }
  483. mode = va_arg(args, int);
  484. first = va_arg(args, int);
  485. last = va_arg(args, int);
  486. if (print_leaf(bh, mode, first, last))
  487. if (print_internal(bh, first, last))
  488. if (print_super_block(bh))
  489. if (print_desc_block(bh))
  490. printk
  491. ("Block %llu contains unformatted data\n",
  492. (unsigned long long)bh->b_blocknr);
  493. }
  494. static char print_tb_buf[2048];
  495. /* this stores initial state of tree balance in the print_tb_buf */
  496. void store_print_tb(struct tree_balance *tb)
  497. {
  498. int h = 0;
  499. int i;
  500. struct buffer_head *tbSh, *tbFh;
  501. if (!tb)
  502. return;
  503. sprintf(print_tb_buf, "\n"
  504. "BALANCING %d\n"
  505. "MODE=%c, ITEM_POS=%d POS_IN_ITEM=%d\n"
  506. "=====================================================================\n"
  507. "* h * S * L * R * F * FL * FR * CFL * CFR *\n",
  508. REISERFS_SB(tb->tb_sb)->s_do_balance,
  509. tb->tb_mode, PATH_LAST_POSITION(tb->tb_path),
  510. tb->tb_path->pos_in_item);
  511. for (h = 0; h < ARRAY_SIZE(tb->insert_size); h++) {
  512. if (PATH_H_PATH_OFFSET(tb->tb_path, h) <=
  513. tb->tb_path->path_length
  514. && PATH_H_PATH_OFFSET(tb->tb_path,
  515. h) > ILLEGAL_PATH_ELEMENT_OFFSET) {
  516. tbSh = PATH_H_PBUFFER(tb->tb_path, h);
  517. tbFh = PATH_H_PPARENT(tb->tb_path, h);
  518. } else {
  519. tbSh = NULL;
  520. tbFh = NULL;
  521. }
  522. sprintf(print_tb_buf + strlen(print_tb_buf),
  523. "* %d * %3lld(%2d) * %3lld(%2d) * %3lld(%2d) * %5lld * %5lld * %5lld * %5lld * %5lld *\n",
  524. h,
  525. (tbSh) ? (long long)(tbSh->b_blocknr) : (-1LL),
  526. (tbSh) ? atomic_read(&(tbSh->b_count)) : -1,
  527. (tb->L[h]) ? (long long)(tb->L[h]->b_blocknr) : (-1LL),
  528. (tb->L[h]) ? atomic_read(&(tb->L[h]->b_count)) : -1,
  529. (tb->R[h]) ? (long long)(tb->R[h]->b_blocknr) : (-1LL),
  530. (tb->R[h]) ? atomic_read(&(tb->R[h]->b_count)) : -1,
  531. (tbFh) ? (long long)(tbFh->b_blocknr) : (-1LL),
  532. (tb->FL[h]) ? (long long)(tb->FL[h]->
  533. b_blocknr) : (-1LL),
  534. (tb->FR[h]) ? (long long)(tb->FR[h]->
  535. b_blocknr) : (-1LL),
  536. (tb->CFL[h]) ? (long long)(tb->CFL[h]->
  537. b_blocknr) : (-1LL),
  538. (tb->CFR[h]) ? (long long)(tb->CFR[h]->
  539. b_blocknr) : (-1LL));
  540. }
  541. sprintf(print_tb_buf + strlen(print_tb_buf),
  542. "=====================================================================\n"
  543. "* h * size * ln * lb * rn * rb * blkn * s0 * s1 * s1b * s2 * s2b * curb * lk * rk *\n"
  544. "* 0 * %4d * %2d * %2d * %2d * %2d * %4d * %2d * %2d * %3d * %2d * %3d * %4d * %2d * %2d *\n",
  545. tb->insert_size[0], tb->lnum[0], tb->lbytes, tb->rnum[0],
  546. tb->rbytes, tb->blknum[0], tb->s0num, tb->s1num, tb->s1bytes,
  547. tb->s2num, tb->s2bytes, tb->cur_blknum, tb->lkey[0],
  548. tb->rkey[0]);
  549. /* this prints balance parameters for non-leaf levels */
  550. h = 0;
  551. do {
  552. h++;
  553. sprintf(print_tb_buf + strlen(print_tb_buf),
  554. "* %d * %4d * %2d * * %2d * * %2d *\n",
  555. h, tb->insert_size[h], tb->lnum[h], tb->rnum[h],
  556. tb->blknum[h]);
  557. } while (tb->insert_size[h]);
  558. sprintf(print_tb_buf + strlen(print_tb_buf),
  559. "=====================================================================\n"
  560. "FEB list: ");
  561. /* print FEB list (list of buffers in form (bh (b_blocknr, b_count), that will be used for new nodes) */
  562. h = 0;
  563. for (i = 0; i < ARRAY_SIZE(tb->FEB); i++)
  564. sprintf(print_tb_buf + strlen(print_tb_buf),
  565. "%p (%llu %d)%s", tb->FEB[i],
  566. tb->FEB[i] ? (unsigned long long)tb->FEB[i]->
  567. b_blocknr : 0ULL,
  568. tb->FEB[i] ? atomic_read(&(tb->FEB[i]->b_count)) : 0,
  569. (i == ARRAY_SIZE(tb->FEB) - 1) ? "\n" : ", ");
  570. sprintf(print_tb_buf + strlen(print_tb_buf),
  571. "======================== the end ====================================\n");
  572. }
  573. void print_cur_tb(char *mes)
  574. {
  575. printk("%s\n%s", mes, print_tb_buf);
  576. }
  577. static void check_leaf_block_head(struct buffer_head *bh)
  578. {
  579. struct block_head *blkh;
  580. int nr;
  581. blkh = B_BLK_HEAD(bh);
  582. nr = blkh_nr_item(blkh);
  583. if (nr > (bh->b_size - BLKH_SIZE) / IH_SIZE)
  584. reiserfs_panic(NULL,
  585. "vs-6010: check_leaf_block_head: invalid item number %z",
  586. bh);
  587. if (blkh_free_space(blkh) > bh->b_size - BLKH_SIZE - IH_SIZE * nr)
  588. reiserfs_panic(NULL,
  589. "vs-6020: check_leaf_block_head: invalid free space %z",
  590. bh);
  591. }
  592. static void check_internal_block_head(struct buffer_head *bh)
  593. {
  594. struct block_head *blkh;
  595. blkh = B_BLK_HEAD(bh);
  596. if (!(B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL && B_LEVEL(bh) <= MAX_HEIGHT))
  597. reiserfs_panic(NULL,
  598. "vs-6025: check_internal_block_head: invalid level %z",
  599. bh);
  600. if (B_NR_ITEMS(bh) > (bh->b_size - BLKH_SIZE) / IH_SIZE)
  601. reiserfs_panic(NULL,
  602. "vs-6030: check_internal_block_head: invalid item number %z",
  603. bh);
  604. if (B_FREE_SPACE(bh) !=
  605. bh->b_size - BLKH_SIZE - KEY_SIZE * B_NR_ITEMS(bh) -
  606. DC_SIZE * (B_NR_ITEMS(bh) + 1))
  607. reiserfs_panic(NULL,
  608. "vs-6040: check_internal_block_head: invalid free space %z",
  609. bh);
  610. }
  611. void check_leaf(struct buffer_head *bh)
  612. {
  613. int i;
  614. struct item_head *ih;
  615. if (!bh)
  616. return;
  617. check_leaf_block_head(bh);
  618. for (i = 0, ih = B_N_PITEM_HEAD(bh, 0); i < B_NR_ITEMS(bh); i++, ih++)
  619. op_check_item(ih, B_I_PITEM(bh, ih));
  620. }
  621. void check_internal(struct buffer_head *bh)
  622. {
  623. if (!bh)
  624. return;
  625. check_internal_block_head(bh);
  626. }
  627. void print_statistics(struct super_block *s)
  628. {
  629. /*
  630. printk ("reiserfs_put_super: session statistics: balances %d, fix_nodes %d, \
  631. bmap with search %d, without %d, dir2ind %d, ind2dir %d\n",
  632. REISERFS_SB(s)->s_do_balance, REISERFS_SB(s)->s_fix_nodes,
  633. REISERFS_SB(s)->s_bmaps, REISERFS_SB(s)->s_bmaps_without_search,
  634. REISERFS_SB(s)->s_direct2indirect, REISERFS_SB(s)->s_indirect2direct);
  635. */
  636. }