⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prints.c

📁 嵌入式系统设计与实例开发实验教材二源码 多线程应用程序设计 串行端口程序设计 AD接口实验 CAN总线通信实验 GPS通信实验 Linux内核移植与编译实验 IC卡读写实验 SD驱动使
💻 C
📖 第 1 页 / 共 2 页
字号:
void print_path (struct tree_balance * tb, struct path * path){    int h = 0;    struct buffer_head * bh;        if (tb) {	while (tb->insert_size[h]) {	    bh = PATH_H_PBUFFER (path, h);	    printk ("block %lu (level=%d), position %d\n", bh ? bh->b_blocknr : 0,		    bh ? B_LEVEL (bh) : 0, PATH_H_POSITION (path, h));	    h ++;	}  } else {      int offset = path->path_length;      struct buffer_head * bh;      printk ("Offset    Bh     (b_blocknr, b_count) Position Nr_item\n");      while ( offset > ILLEGAL_PATH_ELEMENT_OFFSET ) {	  bh = PATH_OFFSET_PBUFFER (path, offset);	  printk ("%6d %10p (%9lu, %7d) %8d %7d\n", offset, 		  bh, bh ? bh->b_blocknr : 0, bh ? atomic_read (&(bh->b_count)) : 0,		  PATH_OFFSET_POSITION (path, offset), bh ? B_NR_ITEMS (bh) : -1);	  	  offset --;      }  }}/* this prints internal nodes (4 keys/items in line) (dc_number,   dc_size)[k_dirid, k_objectid, k_offset, k_uniqueness](dc_number,   dc_size)...*/static int print_internal (struct buffer_head * bh, int first, int last){    struct key * key;    struct disk_child * dc;    int i;    int from, to;        if (!B_IS_KEYS_LEVEL (bh))	return 1;    check_internal (bh);        if (first == -1) {	from = 0;	to = B_NR_ITEMS (bh);    } else {	from = first;	to = last < B_NR_ITEMS (bh) ? last : B_NR_ITEMS (bh);    }    reiserfs_warning ("INTERNAL NODE (%ld) contains %z\n",  bh->b_blocknr, bh);        dc = B_N_CHILD (bh, from);    reiserfs_warning ("PTR %d: %y ", from, dc);        for (i = from, key = B_N_PDELIM_KEY (bh, from), dc ++; i < to; i ++, key ++, dc ++) {	reiserfs_warning ("KEY %d: %k PTR %d: %y ", i, key, i + 1, dc);	if (i && i % 4 == 0)	    printk ("\n");    }    printk ("\n");    return 0;}static int print_leaf (struct buffer_head * bh, int print_mode, int first, int last){    struct block_head * blkh;    struct item_head * ih;    int i, nr;    int from, to;    if (!B_IS_ITEMS_LEVEL (bh))	return 1;    check_leaf (bh);    blkh = B_BLK_HEAD (bh);    ih = B_N_PITEM_HEAD (bh,0);    nr = blkh_nr_item(blkh);    printk ("\n===================================================================\n");    reiserfs_warning ("LEAF NODE (%ld) contains %z\n", bh->b_blocknr, bh);    if (!(print_mode & PRINT_LEAF_ITEMS)) {	reiserfs_warning ("FIRST ITEM_KEY: %k, LAST ITEM KEY: %k\n",			  &(ih->ih_key), &((ih + nr - 1)->ih_key));	return 0;    }    if (first < 0 || first > nr - 1) 	from = 0;    else 	from = first;    if (last < 0 || last > nr )	to = nr;    else	to = last;    ih += from;    printk ("-------------------------------------------------------------------------------\n");    printk ("|##|   type    |           key           | ilen | free_space | version | loc  |\n");    for (i = from; i < to; i++, ih ++) {	printk ("-------------------------------------------------------------------------------\n");	reiserfs_warning ("|%2d| %h |\n", i, ih);	if (print_mode & PRINT_LEAF_ITEMS)	    op_print_item (ih, B_I_PITEM (bh, ih));    }    printk ("===================================================================\n");    return 0;}/* return 1 if this is not super block */static int print_super_block (struct buffer_head * bh){    struct reiserfs_super_block * rs = (struct reiserfs_super_block *)(bh->b_data);    int skipped, data_blocks;    char *version;        if (strncmp (rs->s_magic,  REISERFS_SUPER_MAGIC_STRING,                 strlen ( REISERFS_SUPER_MAGIC_STRING)) == 0) {        version = "3.5";    } else if( strncmp (rs->s_magic,  REISER2FS_SUPER_MAGIC_STRING,                        strlen ( REISER2FS_SUPER_MAGIC_STRING)) == 0) {        version = "3.6";    } else {	return 1;    }    printk ("%s\'s super block in block %ld\n======================\n",            kdevname (bh->b_dev), bh->b_blocknr);    printk ("Reiserfs version %s\n", version );    printk ("Block count %u\n", sb_block_count(rs));    printk ("Blocksize %d\n", sb_blocksize(rs));    printk ("Free blocks %u\n", sb_free_blocks(rs));    // FIXME: this would be confusing if    // someone stores reiserfs super block in some data block ;)//    skipped = (bh->b_blocknr * bh->b_size) / sb_blocksize(rs);    skipped = bh->b_blocknr;    data_blocks = sb_block_count(rs) - skipped - 1 -                  sb_bmap_nr(rs) - (sb_orig_journal_size(rs) + 1) -                  sb_free_blocks(rs);    printk ("Busy blocks (skipped %d, bitmaps - %d, journal blocks - %d\n"	    "1 super blocks, %d data blocks\n", 	    skipped, sb_bmap_nr(rs), 	    (sb_orig_journal_size(rs) + 1), data_blocks);    printk ("Root block %u\n", sb_root_block(rs));    printk ("Journal block (first) %d\n", sb_journal_block(rs));    printk ("Journal dev %d\n", sb_journal_dev(rs));    printk ("Journal orig size %d\n", sb_orig_journal_size(rs));    printk ("Filesystem state %s\n", 	    (sb_state(rs) == REISERFS_VALID_FS) ? "VALID" : "ERROR");    printk ("Hash function \"%s\"\n",            sb_hash_function_code(rs) == TEA_HASH ? "tea" :	    ( sb_hash_function_code(rs) == YURA_HASH ? "rupasov" : (sb_hash_function_code(rs) == R5_HASH ? "r5" : "unknown")));    printk ("Tree height %d\n", sb_tree_height(rs));    return 0;}static int print_desc_block (struct buffer_head * bh){    struct reiserfs_journal_desc * desc;    desc = (struct reiserfs_journal_desc *)(bh->b_data);    if (memcmp(desc->j_magic, JOURNAL_DESC_MAGIC, 8))	return 1;    printk ("Desc block %lu (j_trans_id %d, j_mount_id %d, j_len %d)",	    bh->b_blocknr, desc->j_trans_id, desc->j_mount_id, desc->j_len);    return 0;}void print_block (struct buffer_head * bh, ...)//int print_mode, int first, int last){    va_list args;    int mode, first, last;    va_start (args, bh);    if ( ! bh ) {	printk("print_block: buffer is NULL\n");	return;    }    mode = va_arg (args, int);    first = va_arg (args, int);    last = va_arg (args, int);    if (print_leaf (bh, mode, first, last))	if (print_internal (bh, first, last))	    if (print_super_block (bh))		if (print_desc_block (bh))		    printk ("Block %ld contains unformatted data\n", bh->b_blocknr);}char print_tb_buf[2048];/* this stores initial state of tree balance in the print_tb_buf */void store_print_tb (struct tree_balance * tb){    int h = 0;    int i;    struct buffer_head * tbSh, * tbFh;    if (!tb)	return;    sprintf (print_tb_buf, "\n"	     "BALANCING %d\n"	     "MODE=%c, ITEM_POS=%d POS_IN_ITEM=%d\n" 	     "=====================================================================\n"	     "* h *    S    *    L    *    R    *   F   *   FL  *   FR  *  CFL  *  CFR  *\n",	     tb->tb_sb->u.reiserfs_sb.s_do_balance,	     tb->tb_mode, PATH_LAST_POSITION (tb->tb_path), tb->tb_path->pos_in_item);      for (h = 0; h < sizeof(tb->insert_size) / sizeof (tb->insert_size[0]); h ++) {	if (PATH_H_PATH_OFFSET (tb->tb_path, h) <= tb->tb_path->path_length && 	    PATH_H_PATH_OFFSET (tb->tb_path, h) > ILLEGAL_PATH_ELEMENT_OFFSET) {	    tbSh = PATH_H_PBUFFER (tb->tb_path, h);	    tbFh = PATH_H_PPARENT (tb->tb_path, h);	} else {	    tbSh = 0;	    tbFh = 0;	}	sprintf (print_tb_buf + strlen (print_tb_buf),		 "* %d * %3ld(%2d) * %3ld(%2d) * %3ld(%2d) * %5ld * %5ld * %5ld * %5ld * %5ld *\n",		 h, 		 (tbSh) ? (tbSh->b_blocknr):(-1),		 (tbSh) ? atomic_read (&(tbSh->b_count)) : -1,		 (tb->L[h]) ? (tb->L[h]->b_blocknr):(-1),		 (tb->L[h]) ? atomic_read (&(tb->L[h]->b_count)) : -1,		 (tb->R[h]) ? (tb->R[h]->b_blocknr):(-1),		 (tb->R[h]) ? atomic_read (&(tb->R[h]->b_count)) : -1,		 (tbFh) ? (tbFh->b_blocknr):(-1),		 (tb->FL[h]) ? (tb->FL[h]->b_blocknr):(-1),		 (tb->FR[h]) ? (tb->FR[h]->b_blocknr):(-1),		 (tb->CFL[h]) ? (tb->CFL[h]->b_blocknr):(-1),		 (tb->CFR[h]) ? (tb->CFR[h]->b_blocknr):(-1));    }    sprintf (print_tb_buf + strlen (print_tb_buf), 	     "=====================================================================\n"	     "* h * size * ln * lb * rn * rb * blkn * s0 * s1 * s1b * s2 * s2b * curb * lk * rk *\n"	     "* 0 * %4d * %2d * %2d * %2d * %2d * %4d * %2d * %2d * %3d * %2d * %3d * %4d * %2d * %2d *\n",	     tb->insert_size[0], tb->lnum[0], tb->lbytes, tb->rnum[0],tb->rbytes, tb->blknum[0], 	     tb->s0num, tb->s1num,tb->s1bytes,  tb->s2num, tb->s2bytes, tb->cur_blknum, tb->lkey[0], tb->rkey[0]);    /* this prints balance parameters for non-leaf levels */    h = 0;    do {	h++;	sprintf (print_tb_buf + strlen (print_tb_buf),		 "* %d * %4d * %2d *    * %2d *    * %2d *\n",		h, tb->insert_size[h], tb->lnum[h], tb->rnum[h], tb->blknum[h]);    } while (tb->insert_size[h]);    sprintf (print_tb_buf + strlen (print_tb_buf), 	     "=====================================================================\n"	     "FEB list: ");    /* print FEB list (list of buffers in form (bh (b_blocknr, b_count), that will be used for new nodes) */    h = 0;    for (i = 0; i < sizeof (tb->FEB) / sizeof (tb->FEB[0]); i ++)	sprintf (print_tb_buf + strlen (print_tb_buf),		 "%p (%lu %d)%s", tb->FEB[i], tb->FEB[i] ? tb->FEB[i]->b_blocknr : 0,		 tb->FEB[i] ? atomic_read (&(tb->FEB[i]->b_count)) : 0, 		 (i == sizeof (tb->FEB) / sizeof (tb->FEB[0]) - 1) ? "\n" : ", ");    sprintf (print_tb_buf + strlen (print_tb_buf), 	     "======================== the end ====================================\n");}void print_cur_tb (char * mes){    printk ("%s\n%s", mes, print_tb_buf);}static void check_leaf_block_head (struct buffer_head * bh){  struct block_head * blkh;  int nr;  blkh = B_BLK_HEAD (bh);  nr = blkh_nr_item(blkh);  if ( nr > (bh->b_size - BLKH_SIZE) / IH_SIZE)    reiserfs_panic (0, "vs-6010: check_leaf_block_head: invalid item number %z", bh);  if ( blkh_free_space(blkh) >       bh->b_size - BLKH_SIZE - IH_SIZE * nr )    reiserfs_panic (0, "vs-6020: check_leaf_block_head: invalid free space %z", bh);    }static void check_internal_block_head (struct buffer_head * bh){    struct block_head * blkh;        blkh = B_BLK_HEAD (bh);    if (!(B_LEVEL (bh) > DISK_LEAF_NODE_LEVEL && B_LEVEL (bh) <= MAX_HEIGHT))	reiserfs_panic (0, "vs-6025: check_internal_block_head: invalid level %z", bh);    if (B_NR_ITEMS (bh) > (bh->b_size - BLKH_SIZE) / IH_SIZE)	reiserfs_panic (0, "vs-6030: check_internal_block_head: invalid item number %z", bh);    if (B_FREE_SPACE (bh) != 	bh->b_size - BLKH_SIZE - KEY_SIZE * B_NR_ITEMS (bh) - DC_SIZE * (B_NR_ITEMS (bh) + 1))	reiserfs_panic (0, "vs-6040: check_internal_block_head: invalid free space %z", bh);}void check_leaf (struct buffer_head * bh){    int i;    struct item_head * ih;    if (!bh)	return;    check_leaf_block_head (bh);    for (i = 0, ih = B_N_PITEM_HEAD (bh, 0); i < B_NR_ITEMS (bh); i ++, ih ++)	op_check_item (ih, B_I_PITEM (bh, ih));}void check_internal (struct buffer_head * bh){  if (!bh)    return;  check_internal_block_head (bh);}void print_statistics (struct super_block * s){  /*  printk ("reiserfs_put_super: session statistics: balances %d, fix_nodes %d, \bmap with search %d, without %d, dir2ind %d, ind2dir %d\n",	  s->u.reiserfs_sb.s_do_balance, s->u.reiserfs_sb.s_fix_nodes,	  s->u.reiserfs_sb.s_bmaps, s->u.reiserfs_sb.s_bmaps_without_search,	  s->u.reiserfs_sb.s_direct2indirect, s->u.reiserfs_sb.s_indirect2direct);  */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -