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