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

📄 prints.c

📁 ARM 嵌入式 系统 设计与实例开发 实验教材 二源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README */#include <linux/config.h>#include <linux/sched.h>#include <linux/fs.h>#include <linux/reiserfs_fs.h>#include <linux/string.h>#include <stdarg.h>static char error_buf[1024];static char fmt_buf[1024];static char off_buf[80];static char * reiserfs_cpu_offset (struct cpu_key * key){  if (cpu_key_k_type(key) == TYPE_DIRENTRY)    sprintf (off_buf, "%Lu(%Lu)", 	     (unsigned long long)GET_HASH_VALUE (cpu_key_k_offset (key)),	     (unsigned long long)GET_GENERATION_NUMBER (cpu_key_k_offset (key)));  else    sprintf (off_buf, "0x%Lx", (unsigned long long)cpu_key_k_offset (key));  return off_buf;}static char * le_offset (struct key * key){  int version;  version = le_key_version (key);  if (le_key_k_type (version, key) == TYPE_DIRENTRY)    sprintf (off_buf, "%Lu(%Lu)", 	     (unsigned long long)GET_HASH_VALUE (le_key_k_offset (version, key)),	     (unsigned long long)GET_GENERATION_NUMBER (le_key_k_offset (version, key)));  else    sprintf (off_buf, "0x%Lx", (unsigned long long)le_key_k_offset (version, key));  return off_buf;}static char * cpu_type (struct cpu_key * key){    if (cpu_key_k_type (key) == TYPE_STAT_DATA)	return "SD";    if (cpu_key_k_type (key) == TYPE_DIRENTRY)	return "DIR";    if (cpu_key_k_type (key) == TYPE_DIRECT)	return "DIRECT";    if (cpu_key_k_type (key) == TYPE_INDIRECT)	return "IND";    return "UNKNOWN";}static char * le_type (struct key * key){    int version;        version = le_key_version (key);    if (le_key_k_type (version, key) == TYPE_STAT_DATA)	return "SD";    if (le_key_k_type (version, key) == TYPE_DIRENTRY)	return "DIR";    if (le_key_k_type (version, key) == TYPE_DIRECT)	return "DIRECT";    if (le_key_k_type (version, key) == TYPE_INDIRECT)	return "IND";    return "UNKNOWN";}/* %k */static void sprintf_le_key (char * buf, struct key * key){  if (key)    sprintf (buf, "[%d %d %s %s]", le32_to_cpu (key->k_dir_id),	     le32_to_cpu (key->k_objectid), le_offset (key), le_type (key));  else    sprintf (buf, "[NULL]");}/* %K */static void sprintf_cpu_key (char * buf, struct cpu_key * key){  if (key)    sprintf (buf, "[%d %d %s %s]", key->on_disk_key.k_dir_id,	     key->on_disk_key.k_objectid, reiserfs_cpu_offset (key),             cpu_type (key));  else    sprintf (buf, "[NULL]");}static void sprintf_de_head( char *buf, struct reiserfs_de_head *deh ){    if( deh )        sprintf( buf, "[offset=%d dir_id=%d objectid=%d location=%d state=%04x]", deh_offset(deh), deh_dir_id(deh),                 deh_objectid(deh), deh_location(deh), deh_state(deh) );    else        sprintf( buf, "[NULL]" );}static void sprintf_item_head (char * buf, struct item_head * ih){    if (ih) {	sprintf (buf, "%s", (ih_version (ih) == KEY_FORMAT_3_6) ? "*3.6* " : "*3.5*");	sprintf_le_key (buf + strlen (buf), &(ih->ih_key));	sprintf (buf + strlen (buf), ", item_len %d, item_location %d, "		 "free_space(entry_count) %d",		 ih_item_len(ih), ih_location(ih), ih_free_space (ih));    } else	sprintf (buf, "[NULL]");}static void sprintf_direntry (char * buf, struct reiserfs_dir_entry * de){  char name[20];  memcpy (name, de->de_name, de->de_namelen > 19 ? 19 : de->de_namelen);  name [de->de_namelen > 19 ? 19 : de->de_namelen] = 0;  sprintf (buf, "\"%s\"==>[%d %d]", name, de->de_dir_id, de->de_objectid);}static void sprintf_block_head (char * buf, struct buffer_head * bh){  sprintf (buf, "level=%d, nr_items=%d, free_space=%d rdkey ",	   B_LEVEL (bh), B_NR_ITEMS (bh), B_FREE_SPACE (bh));}static void sprintf_buffer_head (char * buf, struct buffer_head * bh) {  sprintf (buf, "dev %s, size %d, blocknr %ld, count %d, list %d, state 0x%lx, page %p, (%s, %s, %s)",	   kdevname (bh->b_dev), bh->b_size, bh->b_blocknr, atomic_read (&(bh->b_count)), bh->b_list,	   bh->b_state, bh->b_page,	   buffer_uptodate (bh) ? "UPTODATE" : "!UPTODATE",	   buffer_dirty (bh) ? "DIRTY" : "CLEAN",	   buffer_locked (bh) ? "LOCKED" : "UNLOCKED");}static void sprintf_disk_child (char * buf, struct disk_child * dc){  sprintf (buf, "[dc_number=%d, dc_size=%u]", dc_block_number(dc), dc_size(dc));}static char * is_there_reiserfs_struct (char * fmt, int * what, int * skip){  char * k = fmt;  *skip = 0;    while ((k = strstr (k, "%")) != NULL)  {    if (k[1] == 'k' || k[1] == 'K' || k[1] == 'h' || k[1] == 't' ||	      k[1] == 'z' || k[1] == 'b' || k[1] == 'y' || k[1] == 'a' ) {      *what = k[1];      break;    }    (*skip) ++;    k ++;  }  return k;}/* debugging reiserfs we used to print out a lot of different   variables, like keys, item headers, buffer heads etc. Values of   most fields matter. So it took a long time just to write   appropriative printk. With this reiserfs_warning you can use format   specification for complex structures like you used to do with   printfs for integers, doubles and pointers. For instance, to print   out key structure you have to write just:    reiserfs_warning ("bad key %k", key);    instead of    printk ("bad key %lu %lu %lu %lu", key->k_dir_id, key->k_objectid,            key->k_offset, key->k_uniqueness); */static voidprepare_error_buf( const char *fmt, va_list args ){    char * fmt1 = fmt_buf;    char * k;    char * p = error_buf;    int i, j, what, skip;    strcpy (fmt1, fmt);    while( (k = is_there_reiserfs_struct( fmt1, &what, &skip )) != NULL )    {        *k = 0;        p += vsprintf (p, fmt1, args);        for (i = 0; i < skip; i ++)            j = va_arg (args, int);        switch (what) {        case 'k':            sprintf_le_key (p, va_arg(args, struct key *));            break;        case 'K':            sprintf_cpu_key (p, va_arg(args, struct cpu_key *));            break;        case 'h':            sprintf_item_head (p, va_arg(args, struct item_head *));            break;        case 't':            sprintf_direntry (p, va_arg(args, struct reiserfs_dir_entry *));            break;        case 'y':            sprintf_disk_child (p, va_arg(args, struct disk_child *));            break;        case 'z':            sprintf_block_head (p, va_arg(args, struct buffer_head *));            break;        case 'b':            sprintf_buffer_head (p, va_arg(args, struct buffer_head *));            break;        case 'a':            sprintf_de_head (p, va_arg(args, struct reiserfs_de_head *));            break;        }        p += strlen (p);        fmt1 = k + 2;    }    vsprintf (p, fmt1, args);}/* in addition to usual conversion specifiers this accepts reiserfs   specific conversion specifiers:    %k to print little endian key,    %K to print cpu key,    %h to print item_head,   %t to print directory entry    %z to print block head (arg must be struct buffer_head *   %b to print buffer_head*/#define do_reiserfs_warning(fmt)\{\    va_list args;\    va_start( args, fmt );\    prepare_error_buf( fmt, args );\    va_end( args );\}void reiserfs_warning (const char * fmt, ...){  do_reiserfs_warning(fmt);  /* console_print (error_buf); */  printk (KERN_WARNING "%s", error_buf);}void reiserfs_debug (struct super_block *s, int level, const char * fmt, ...){#ifdef CONFIG_REISERFS_CHECK  do_reiserfs_warning(fmt);  printk (KERN_DEBUG "%s", error_buf);#else  ; #endif}/* The format:           maintainer-errorid: [function-name:] message    where errorid is unique to the maintainer and function-name is    optional, is recommended, so that anyone can easily find the bug    with a simple grep for the short to type string    maintainer-errorid.  Don't bother with reusing errorids, there are    lots of numbers out there.    Example:         reiserfs_panic(	p_sb, "reiser-29: reiserfs_new_blocknrs: "	"one of search_start or rn(%d) is equal to MAX_B_NUM,"	"which means that we are optimizing location based on the bogus location of a temp buffer (%p).", 	rn, bh    );    Regular panic()s sometimes clear the screen before the message can    be read, thus the need for the while loop.      Numbering scheme for panic used by Vladimir and Anatoly( Hans completely ignores this scheme, and considers it    pointless complexity):    panics in reiserfs_fs.h have numbers from 1000 to 1999    super.c				        2000 to 2999    preserve.c (unused)			    3000 to 3999    bitmap.c				    4000 to 4999    stree.c				        5000 to 5999    prints.c				    6000 to 6999    namei.c                     7000 to 7999    fix_nodes.c                 8000 to 8999    dir.c                       9000 to 9999	lbalance.c					10000 to 10999	ibalance.c		11000 to 11999 not ready	do_balan.c		12000 to 12999	inode.c			13000 to 13999	file.c			14000 to 14999    objectid.c                       15000 - 15999    buffer.c                         16000 - 16999    symlink.c                        17000 - 17999   .  */#ifdef CONFIG_REISERFS_CHECKextern struct tree_balance * cur_tb;#endifvoid reiserfs_panic (struct super_block * sb, const char * fmt, ...){  show_reiserfs_locks() ;  do_reiserfs_warning(fmt);  printk ( KERN_EMERG "%s", error_buf);  BUG ();  /* this is not actually called, but makes reiserfs_panic() "noreturn" */  panic ("REISERFS: panic (device %s): %s\n",	 sb ? kdevname(sb->s_dev) : "sb == 0", error_buf);}void print_virtual_node (struct virtual_node * vn){    int i;    struct virtual_item * vi;    printk ("VIRTUAL NODE CONTAINS %d items, has size %d,%s,%s, ITEM_POS=%d POS_IN_ITEM=%d MODE=\'%c\'\n",	    vn->vn_nr_item, vn->vn_size,	    (vn->vn_vi[0].vi_type & VI_TYPE_LEFT_MERGEABLE )? "left mergeable" : "", 	    (vn->vn_vi[vn->vn_nr_item - 1].vi_type & VI_TYPE_RIGHT_MERGEABLE) ? "right mergeable" : "",	    vn->vn_affected_item_num, vn->vn_pos_in_item, vn->vn_mode);        vi = vn->vn_vi;    for (i = 0; i < vn->vn_nr_item; i ++, vi ++)	op_print_vi (vi);	}

⌨️ 快捷键说明

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