0001
0002
0003
0004
0005 #include <linux/time.h>
0006 #include <linux/fs.h>
0007 #include "reiserfs.h"
0008 #include <linux/string.h>
0009 #include <linux/buffer_head.h>
0010
0011 #include <linux/stdarg.h>
0012
0013 static char error_buf[1024];
0014 static char fmt_buf[1024];
0015 static char off_buf[80];
0016
0017 static char *reiserfs_cpu_offset(struct cpu_key *key)
0018 {
0019 if (cpu_key_k_type(key) == TYPE_DIRENTRY)
0020 sprintf(off_buf, "%llu(%llu)",
0021 (unsigned long long)
0022 GET_HASH_VALUE(cpu_key_k_offset(key)),
0023 (unsigned long long)
0024 GET_GENERATION_NUMBER(cpu_key_k_offset(key)));
0025 else
0026 sprintf(off_buf, "0x%Lx",
0027 (unsigned long long)cpu_key_k_offset(key));
0028 return off_buf;
0029 }
0030
0031 static char *le_offset(struct reiserfs_key *key)
0032 {
0033 int version;
0034
0035 version = le_key_version(key);
0036 if (le_key_k_type(version, key) == TYPE_DIRENTRY)
0037 sprintf(off_buf, "%llu(%llu)",
0038 (unsigned long long)
0039 GET_HASH_VALUE(le_key_k_offset(version, key)),
0040 (unsigned long long)
0041 GET_GENERATION_NUMBER(le_key_k_offset(version, key)));
0042 else
0043 sprintf(off_buf, "0x%Lx",
0044 (unsigned long long)le_key_k_offset(version, key));
0045 return off_buf;
0046 }
0047
0048 static char *cpu_type(struct cpu_key *key)
0049 {
0050 if (cpu_key_k_type(key) == TYPE_STAT_DATA)
0051 return "SD";
0052 if (cpu_key_k_type(key) == TYPE_DIRENTRY)
0053 return "DIR";
0054 if (cpu_key_k_type(key) == TYPE_DIRECT)
0055 return "DIRECT";
0056 if (cpu_key_k_type(key) == TYPE_INDIRECT)
0057 return "IND";
0058 return "UNKNOWN";
0059 }
0060
0061 static char *le_type(struct reiserfs_key *key)
0062 {
0063 int version;
0064
0065 version = le_key_version(key);
0066
0067 if (le_key_k_type(version, key) == TYPE_STAT_DATA)
0068 return "SD";
0069 if (le_key_k_type(version, key) == TYPE_DIRENTRY)
0070 return "DIR";
0071 if (le_key_k_type(version, key) == TYPE_DIRECT)
0072 return "DIRECT";
0073 if (le_key_k_type(version, key) == TYPE_INDIRECT)
0074 return "IND";
0075 return "UNKNOWN";
0076 }
0077
0078
0079 static int scnprintf_le_key(char *buf, size_t size, struct reiserfs_key *key)
0080 {
0081 if (key)
0082 return scnprintf(buf, size, "[%d %d %s %s]",
0083 le32_to_cpu(key->k_dir_id),
0084 le32_to_cpu(key->k_objectid), le_offset(key),
0085 le_type(key));
0086 else
0087 return scnprintf(buf, size, "[NULL]");
0088 }
0089
0090
0091 static int scnprintf_cpu_key(char *buf, size_t size, struct cpu_key *key)
0092 {
0093 if (key)
0094 return scnprintf(buf, size, "[%d %d %s %s]",
0095 key->on_disk_key.k_dir_id,
0096 key->on_disk_key.k_objectid,
0097 reiserfs_cpu_offset(key), cpu_type(key));
0098 else
0099 return scnprintf(buf, size, "[NULL]");
0100 }
0101
0102 static int scnprintf_de_head(char *buf, size_t size,
0103 struct reiserfs_de_head *deh)
0104 {
0105 if (deh)
0106 return scnprintf(buf, size,
0107 "[offset=%d dir_id=%d objectid=%d location=%d state=%04x]",
0108 deh_offset(deh), deh_dir_id(deh),
0109 deh_objectid(deh), deh_location(deh),
0110 deh_state(deh));
0111 else
0112 return scnprintf(buf, size, "[NULL]");
0113
0114 }
0115
0116 static int scnprintf_item_head(char *buf, size_t size, struct item_head *ih)
0117 {
0118 if (ih) {
0119 char *p = buf;
0120 char * const end = buf + size;
0121
0122 p += scnprintf(p, end - p, "%s",
0123 (ih_version(ih) == KEY_FORMAT_3_6) ?
0124 "*3.6* " : "*3.5*");
0125
0126 p += scnprintf_le_key(p, end - p, &ih->ih_key);
0127
0128 p += scnprintf(p, end - p,
0129 ", item_len %d, item_location %d, free_space(entry_count) %d",
0130 ih_item_len(ih), ih_location(ih),
0131 ih_free_space(ih));
0132 return p - buf;
0133 } else
0134 return scnprintf(buf, size, "[NULL]");
0135 }
0136
0137 static int scnprintf_direntry(char *buf, size_t size,
0138 struct reiserfs_dir_entry *de)
0139 {
0140 char name[20];
0141
0142 memcpy(name, de->de_name, de->de_namelen > 19 ? 19 : de->de_namelen);
0143 name[de->de_namelen > 19 ? 19 : de->de_namelen] = 0;
0144 return scnprintf(buf, size, "\"%s\"==>[%d %d]",
0145 name, de->de_dir_id, de->de_objectid);
0146 }
0147
0148 static int scnprintf_block_head(char *buf, size_t size, struct buffer_head *bh)
0149 {
0150 return scnprintf(buf, size,
0151 "level=%d, nr_items=%d, free_space=%d rdkey ",
0152 B_LEVEL(bh), B_NR_ITEMS(bh), B_FREE_SPACE(bh));
0153 }
0154
0155 static int scnprintf_buffer_head(char *buf, size_t size, struct buffer_head *bh)
0156 {
0157 return scnprintf(buf, size,
0158 "dev %pg, size %zd, blocknr %llu, count %d, state 0x%lx, page %p, (%s, %s, %s)",
0159 bh->b_bdev, bh->b_size,
0160 (unsigned long long)bh->b_blocknr,
0161 atomic_read(&(bh->b_count)),
0162 bh->b_state, bh->b_page,
0163 buffer_uptodate(bh) ? "UPTODATE" : "!UPTODATE",
0164 buffer_dirty(bh) ? "DIRTY" : "CLEAN",
0165 buffer_locked(bh) ? "LOCKED" : "UNLOCKED");
0166 }
0167
0168 static int scnprintf_disk_child(char *buf, size_t size, struct disk_child *dc)
0169 {
0170 return scnprintf(buf, size, "[dc_number=%d, dc_size=%u]",
0171 dc_block_number(dc), dc_size(dc));
0172 }
0173
0174 static char *is_there_reiserfs_struct(char *fmt, int *what)
0175 {
0176 char *k = fmt;
0177
0178 while ((k = strchr(k, '%')) != NULL) {
0179 if (k[1] == 'k' || k[1] == 'K' || k[1] == 'h' || k[1] == 't' ||
0180 k[1] == 'z' || k[1] == 'b' || k[1] == 'y' || k[1] == 'a') {
0181 *what = k[1];
0182 break;
0183 }
0184 k++;
0185 }
0186 return k;
0187 }
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202 static DEFINE_SPINLOCK(error_lock);
0203 static void prepare_error_buf(const char *fmt, va_list args)
0204 {
0205 char *fmt1 = fmt_buf;
0206 char *k;
0207 char *p = error_buf;
0208 char * const end = &error_buf[sizeof(error_buf)];
0209 int what;
0210
0211 spin_lock(&error_lock);
0212
0213 if (WARN_ON(strscpy(fmt_buf, fmt, sizeof(fmt_buf)) < 0)) {
0214 strscpy(error_buf, "format string too long", end - error_buf);
0215 goto out_unlock;
0216 }
0217
0218 while ((k = is_there_reiserfs_struct(fmt1, &what)) != NULL) {
0219 *k = 0;
0220
0221 p += vscnprintf(p, end - p, fmt1, args);
0222
0223 switch (what) {
0224 case 'k':
0225 p += scnprintf_le_key(p, end - p,
0226 va_arg(args, struct reiserfs_key *));
0227 break;
0228 case 'K':
0229 p += scnprintf_cpu_key(p, end - p,
0230 va_arg(args, struct cpu_key *));
0231 break;
0232 case 'h':
0233 p += scnprintf_item_head(p, end - p,
0234 va_arg(args, struct item_head *));
0235 break;
0236 case 't':
0237 p += scnprintf_direntry(p, end - p,
0238 va_arg(args, struct reiserfs_dir_entry *));
0239 break;
0240 case 'y':
0241 p += scnprintf_disk_child(p, end - p,
0242 va_arg(args, struct disk_child *));
0243 break;
0244 case 'z':
0245 p += scnprintf_block_head(p, end - p,
0246 va_arg(args, struct buffer_head *));
0247 break;
0248 case 'b':
0249 p += scnprintf_buffer_head(p, end - p,
0250 va_arg(args, struct buffer_head *));
0251 break;
0252 case 'a':
0253 p += scnprintf_de_head(p, end - p,
0254 va_arg(args, struct reiserfs_de_head *));
0255 break;
0256 }
0257
0258 fmt1 = k + 2;
0259 }
0260 p += vscnprintf(p, end - p, fmt1, args);
0261 out_unlock:
0262 spin_unlock(&error_lock);
0263
0264 }
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277 #define do_reiserfs_warning(fmt)\
0278 {\
0279 va_list args;\
0280 va_start( args, fmt );\
0281 prepare_error_buf( fmt, args );\
0282 va_end( args );\
0283 }
0284
0285 void __reiserfs_warning(struct super_block *sb, const char *id,
0286 const char *function, const char *fmt, ...)
0287 {
0288 do_reiserfs_warning(fmt);
0289 if (sb)
0290 printk(KERN_WARNING "REISERFS warning (device %s): %s%s%s: "
0291 "%s\n", sb->s_id, id ? id : "", id ? " " : "",
0292 function, error_buf);
0293 else
0294 printk(KERN_WARNING "REISERFS warning: %s%s%s: %s\n",
0295 id ? id : "", id ? " " : "", function, error_buf);
0296 }
0297
0298
0299 void reiserfs_info(struct super_block *sb, const char *fmt, ...)
0300 {
0301 do_reiserfs_warning(fmt);
0302 if (sb)
0303 printk(KERN_NOTICE "REISERFS (device %s): %s",
0304 sb->s_id, error_buf);
0305 else
0306 printk(KERN_NOTICE "REISERFS %s:", error_buf);
0307 }
0308
0309
0310 static void reiserfs_printk(const char *fmt, ...)
0311 {
0312 do_reiserfs_warning(fmt);
0313 printk(error_buf);
0314 }
0315
0316 void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...)
0317 {
0318 #ifdef CONFIG_REISERFS_CHECK
0319 do_reiserfs_warning(fmt);
0320 if (s)
0321 printk(KERN_DEBUG "REISERFS debug (device %s): %s\n",
0322 s->s_id, error_buf);
0323 else
0324 printk(KERN_DEBUG "REISERFS debug: %s\n", error_buf);
0325 #endif
0326 }
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375 void __reiserfs_panic(struct super_block *sb, const char *id,
0376 const char *function, const char *fmt, ...)
0377 {
0378 do_reiserfs_warning(fmt);
0379
0380 #ifdef CONFIG_REISERFS_CHECK
0381 dump_stack();
0382 #endif
0383 if (sb)
0384 printk(KERN_WARNING "REISERFS panic (device %s): %s%s%s: %s\n",
0385 sb->s_id, id ? id : "", id ? " " : "",
0386 function, error_buf);
0387 else
0388 printk(KERN_WARNING "REISERFS panic: %s%s%s: %s\n",
0389 id ? id : "", id ? " " : "", function, error_buf);
0390 BUG();
0391 }
0392
0393 void __reiserfs_error(struct super_block *sb, const char *id,
0394 const char *function, const char *fmt, ...)
0395 {
0396 do_reiserfs_warning(fmt);
0397
0398 BUG_ON(sb == NULL);
0399
0400 if (reiserfs_error_panic(sb))
0401 __reiserfs_panic(sb, id, function, error_buf);
0402
0403 if (id && id[0])
0404 printk(KERN_CRIT "REISERFS error (device %s): %s %s: %s\n",
0405 sb->s_id, id, function, error_buf);
0406 else
0407 printk(KERN_CRIT "REISERFS error (device %s): %s: %s\n",
0408 sb->s_id, function, error_buf);
0409
0410 if (sb_rdonly(sb))
0411 return;
0412
0413 reiserfs_info(sb, "Remounting filesystem read-only\n");
0414 sb->s_flags |= SB_RDONLY;
0415 reiserfs_abort_journal(sb, -EIO);
0416 }
0417
0418 void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...)
0419 {
0420 do_reiserfs_warning(fmt);
0421
0422 if (reiserfs_error_panic(sb)) {
0423 panic(KERN_CRIT "REISERFS panic (device %s): %s\n", sb->s_id,
0424 error_buf);
0425 }
0426
0427 if (reiserfs_is_journal_aborted(SB_JOURNAL(sb)))
0428 return;
0429
0430 printk(KERN_CRIT "REISERFS abort (device %s): %s\n", sb->s_id,
0431 error_buf);
0432
0433 sb->s_flags |= SB_RDONLY;
0434 reiserfs_abort_journal(sb, errno);
0435 }
0436
0437
0438
0439
0440
0441
0442 static int print_internal(struct buffer_head *bh, int first, int last)
0443 {
0444 struct reiserfs_key *key;
0445 struct disk_child *dc;
0446 int i;
0447 int from, to;
0448
0449 if (!B_IS_KEYS_LEVEL(bh))
0450 return 1;
0451
0452 check_internal(bh);
0453
0454 if (first == -1) {
0455 from = 0;
0456 to = B_NR_ITEMS(bh);
0457 } else {
0458 from = first;
0459 to = last < B_NR_ITEMS(bh) ? last : B_NR_ITEMS(bh);
0460 }
0461
0462 reiserfs_printk("INTERNAL NODE (%ld) contains %z\n", bh->b_blocknr, bh);
0463
0464 dc = B_N_CHILD(bh, from);
0465 reiserfs_printk("PTR %d: %y ", from, dc);
0466
0467 for (i = from, key = internal_key(bh, from), dc++; i < to;
0468 i++, key++, dc++) {
0469 reiserfs_printk("KEY %d: %k PTR %d: %y ", i, key, i + 1, dc);
0470 if (i && i % 4 == 0)
0471 printk("\n");
0472 }
0473 printk("\n");
0474 return 0;
0475 }
0476
0477 static int print_leaf(struct buffer_head *bh, int print_mode, int first,
0478 int last)
0479 {
0480 struct block_head *blkh;
0481 struct item_head *ih;
0482 int i, nr;
0483 int from, to;
0484
0485 if (!B_IS_ITEMS_LEVEL(bh))
0486 return 1;
0487
0488 check_leaf(bh);
0489
0490 blkh = B_BLK_HEAD(bh);
0491 ih = item_head(bh, 0);
0492 nr = blkh_nr_item(blkh);
0493
0494 printk
0495 ("\n===================================================================\n");
0496 reiserfs_printk("LEAF NODE (%ld) contains %z\n", bh->b_blocknr, bh);
0497
0498 if (!(print_mode & PRINT_LEAF_ITEMS)) {
0499 reiserfs_printk("FIRST ITEM_KEY: %k, LAST ITEM KEY: %k\n",
0500 &(ih->ih_key), &((ih + nr - 1)->ih_key));
0501 return 0;
0502 }
0503
0504 if (first < 0 || first > nr - 1)
0505 from = 0;
0506 else
0507 from = first;
0508
0509 if (last < 0 || last > nr)
0510 to = nr;
0511 else
0512 to = last;
0513
0514 ih += from;
0515 printk
0516 ("-------------------------------------------------------------------------------\n");
0517 printk
0518 ("|##| type | key | ilen | free_space | version | loc |\n");
0519 for (i = from; i < to; i++, ih++) {
0520 printk
0521 ("-------------------------------------------------------------------------------\n");
0522 reiserfs_printk("|%2d| %h |\n", i, ih);
0523 if (print_mode & PRINT_LEAF_ITEMS)
0524 op_print_item(ih, ih_item_body(bh, ih));
0525 }
0526
0527 printk
0528 ("===================================================================\n");
0529
0530 return 0;
0531 }
0532
0533 char *reiserfs_hashname(int code)
0534 {
0535 if (code == YURA_HASH)
0536 return "rupasov";
0537 if (code == TEA_HASH)
0538 return "tea";
0539 if (code == R5_HASH)
0540 return "r5";
0541
0542 return "unknown";
0543 }
0544
0545
0546 static int print_super_block(struct buffer_head *bh)
0547 {
0548 struct reiserfs_super_block *rs =
0549 (struct reiserfs_super_block *)(bh->b_data);
0550 int skipped, data_blocks;
0551 char *version;
0552
0553 if (is_reiserfs_3_5(rs)) {
0554 version = "3.5";
0555 } else if (is_reiserfs_3_6(rs)) {
0556 version = "3.6";
0557 } else if (is_reiserfs_jr(rs)) {
0558 version = ((sb_version(rs) == REISERFS_VERSION_2) ?
0559 "3.6" : "3.5");
0560 } else {
0561 return 1;
0562 }
0563
0564 printk("%pg\'s super block is in block %llu\n", bh->b_bdev,
0565 (unsigned long long)bh->b_blocknr);
0566 printk("Reiserfs version %s\n", version);
0567 printk("Block count %u\n", sb_block_count(rs));
0568 printk("Blocksize %d\n", sb_blocksize(rs));
0569 printk("Free blocks %u\n", sb_free_blocks(rs));
0570
0571
0572
0573
0574
0575 skipped = bh->b_blocknr;
0576 data_blocks = sb_block_count(rs) - skipped - 1 - sb_bmap_nr(rs) -
0577 (!is_reiserfs_jr(rs) ? sb_jp_journal_size(rs) +
0578 1 : sb_reserved_for_journal(rs)) - sb_free_blocks(rs);
0579 printk
0580 ("Busy blocks (skipped %d, bitmaps - %d, journal (or reserved) blocks - %d\n"
0581 "1 super block, %d data blocks\n", skipped, sb_bmap_nr(rs),
0582 (!is_reiserfs_jr(rs) ? (sb_jp_journal_size(rs) + 1) :
0583 sb_reserved_for_journal(rs)), data_blocks);
0584 printk("Root block %u\n", sb_root_block(rs));
0585 printk("Journal block (first) %d\n", sb_jp_journal_1st_block(rs));
0586 printk("Journal dev %d\n", sb_jp_journal_dev(rs));
0587 printk("Journal orig size %d\n", sb_jp_journal_size(rs));
0588 printk("FS state %d\n", sb_fs_state(rs));
0589 printk("Hash function \"%s\"\n",
0590 reiserfs_hashname(sb_hash_function_code(rs)));
0591
0592 printk("Tree height %d\n", sb_tree_height(rs));
0593 return 0;
0594 }
0595
0596 static int print_desc_block(struct buffer_head *bh)
0597 {
0598 struct reiserfs_journal_desc *desc;
0599
0600 if (memcmp(get_journal_desc_magic(bh), JOURNAL_DESC_MAGIC, 8))
0601 return 1;
0602
0603 desc = (struct reiserfs_journal_desc *)(bh->b_data);
0604 printk("Desc block %llu (j_trans_id %d, j_mount_id %d, j_len %d)",
0605 (unsigned long long)bh->b_blocknr, get_desc_trans_id(desc),
0606 get_desc_mount_id(desc), get_desc_trans_len(desc));
0607
0608 return 0;
0609 }
0610
0611 void print_block(struct buffer_head *bh, ...)
0612 {
0613 va_list args;
0614 int mode, first, last;
0615
0616 if (!bh) {
0617 printk("print_block: buffer is NULL\n");
0618 return;
0619 }
0620
0621 va_start(args, bh);
0622
0623 mode = va_arg(args, int);
0624 first = va_arg(args, int);
0625 last = va_arg(args, int);
0626 if (print_leaf(bh, mode, first, last))
0627 if (print_internal(bh, first, last))
0628 if (print_super_block(bh))
0629 if (print_desc_block(bh))
0630 printk
0631 ("Block %llu contains unformatted data\n",
0632 (unsigned long long)bh->b_blocknr);
0633
0634 va_end(args);
0635 }
0636
0637 static char print_tb_buf[2048];
0638
0639
0640 void store_print_tb(struct tree_balance *tb)
0641 {
0642 int h = 0;
0643 int i;
0644 struct buffer_head *tbSh, *tbFh;
0645
0646 if (!tb)
0647 return;
0648
0649 sprintf(print_tb_buf, "\n"
0650 "BALANCING %d\n"
0651 "MODE=%c, ITEM_POS=%d POS_IN_ITEM=%d\n"
0652 "=====================================================================\n"
0653 "* h * S * L * R * F * FL * FR * CFL * CFR *\n",
0654 REISERFS_SB(tb->tb_sb)->s_do_balance,
0655 tb->tb_mode, PATH_LAST_POSITION(tb->tb_path),
0656 tb->tb_path->pos_in_item);
0657
0658 for (h = 0; h < ARRAY_SIZE(tb->insert_size); h++) {
0659 if (PATH_H_PATH_OFFSET(tb->tb_path, h) <=
0660 tb->tb_path->path_length
0661 && PATH_H_PATH_OFFSET(tb->tb_path,
0662 h) > ILLEGAL_PATH_ELEMENT_OFFSET) {
0663 tbSh = PATH_H_PBUFFER(tb->tb_path, h);
0664 tbFh = PATH_H_PPARENT(tb->tb_path, h);
0665 } else {
0666 tbSh = NULL;
0667 tbFh = NULL;
0668 }
0669 sprintf(print_tb_buf + strlen(print_tb_buf),
0670 "* %d * %3lld(%2d) * %3lld(%2d) * %3lld(%2d) * %5lld * %5lld * %5lld * %5lld * %5lld *\n",
0671 h,
0672 (tbSh) ? (long long)(tbSh->b_blocknr) : (-1LL),
0673 (tbSh) ? atomic_read(&tbSh->b_count) : -1,
0674 (tb->L[h]) ? (long long)(tb->L[h]->b_blocknr) : (-1LL),
0675 (tb->L[h]) ? atomic_read(&tb->L[h]->b_count) : -1,
0676 (tb->R[h]) ? (long long)(tb->R[h]->b_blocknr) : (-1LL),
0677 (tb->R[h]) ? atomic_read(&tb->R[h]->b_count) : -1,
0678 (tbFh) ? (long long)(tbFh->b_blocknr) : (-1LL),
0679 (tb->FL[h]) ? (long long)(tb->FL[h]->
0680 b_blocknr) : (-1LL),
0681 (tb->FR[h]) ? (long long)(tb->FR[h]->
0682 b_blocknr) : (-1LL),
0683 (tb->CFL[h]) ? (long long)(tb->CFL[h]->
0684 b_blocknr) : (-1LL),
0685 (tb->CFR[h]) ? (long long)(tb->CFR[h]->
0686 b_blocknr) : (-1LL));
0687 }
0688
0689 sprintf(print_tb_buf + strlen(print_tb_buf),
0690 "=====================================================================\n"
0691 "* h * size * ln * lb * rn * rb * blkn * s0 * s1 * s1b * s2 * s2b * curb * lk * rk *\n"
0692 "* 0 * %4d * %2d * %2d * %2d * %2d * %4d * %2d * %2d * %3d * %2d * %3d * %4d * %2d * %2d *\n",
0693 tb->insert_size[0], tb->lnum[0], tb->lbytes, tb->rnum[0],
0694 tb->rbytes, tb->blknum[0], tb->s0num, tb->snum[0],
0695 tb->sbytes[0], tb->snum[1], tb->sbytes[1],
0696 tb->cur_blknum, tb->lkey[0], tb->rkey[0]);
0697
0698
0699 h = 0;
0700 do {
0701 h++;
0702 sprintf(print_tb_buf + strlen(print_tb_buf),
0703 "* %d * %4d * %2d * * %2d * * %2d *\n",
0704 h, tb->insert_size[h], tb->lnum[h], tb->rnum[h],
0705 tb->blknum[h]);
0706 } while (tb->insert_size[h]);
0707
0708 sprintf(print_tb_buf + strlen(print_tb_buf),
0709 "=====================================================================\n"
0710 "FEB list: ");
0711
0712
0713 h = 0;
0714 for (i = 0; i < ARRAY_SIZE(tb->FEB); i++)
0715 sprintf(print_tb_buf + strlen(print_tb_buf),
0716 "%p (%llu %d)%s", tb->FEB[i],
0717 tb->FEB[i] ? (unsigned long long)tb->FEB[i]->
0718 b_blocknr : 0ULL,
0719 tb->FEB[i] ? atomic_read(&tb->FEB[i]->b_count) : 0,
0720 (i == ARRAY_SIZE(tb->FEB) - 1) ? "\n" : ", ");
0721
0722 sprintf(print_tb_buf + strlen(print_tb_buf),
0723 "======================== the end ====================================\n");
0724 }
0725
0726 void print_cur_tb(char *mes)
0727 {
0728 printk("%s\n%s", mes, print_tb_buf);
0729 }
0730
0731 static void check_leaf_block_head(struct buffer_head *bh)
0732 {
0733 struct block_head *blkh;
0734 int nr;
0735
0736 blkh = B_BLK_HEAD(bh);
0737 nr = blkh_nr_item(blkh);
0738 if (nr > (bh->b_size - BLKH_SIZE) / IH_SIZE)
0739 reiserfs_panic(NULL, "vs-6010", "invalid item number %z",
0740 bh);
0741 if (blkh_free_space(blkh) > bh->b_size - BLKH_SIZE - IH_SIZE * nr)
0742 reiserfs_panic(NULL, "vs-6020", "invalid free space %z",
0743 bh);
0744
0745 }
0746
0747 static void check_internal_block_head(struct buffer_head *bh)
0748 {
0749 if (!(B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL && B_LEVEL(bh) <= MAX_HEIGHT))
0750 reiserfs_panic(NULL, "vs-6025", "invalid level %z", bh);
0751
0752 if (B_NR_ITEMS(bh) > (bh->b_size - BLKH_SIZE) / IH_SIZE)
0753 reiserfs_panic(NULL, "vs-6030", "invalid item number %z", bh);
0754
0755 if (B_FREE_SPACE(bh) !=
0756 bh->b_size - BLKH_SIZE - KEY_SIZE * B_NR_ITEMS(bh) -
0757 DC_SIZE * (B_NR_ITEMS(bh) + 1))
0758 reiserfs_panic(NULL, "vs-6040", "invalid free space %z", bh);
0759
0760 }
0761
0762 void check_leaf(struct buffer_head *bh)
0763 {
0764 int i;
0765 struct item_head *ih;
0766
0767 if (!bh)
0768 return;
0769 check_leaf_block_head(bh);
0770 for (i = 0, ih = item_head(bh, 0); i < B_NR_ITEMS(bh); i++, ih++)
0771 op_check_item(ih, ih_item_body(bh, ih));
0772 }
0773
0774 void check_internal(struct buffer_head *bh)
0775 {
0776 if (!bh)
0777 return;
0778 check_internal_block_head(bh);
0779 }
0780
0781 void print_statistics(struct super_block *s)
0782 {
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792 }