📄 prints.c
字号:
/* * Copyright 1996-2004 by Hans Reiser, licensing governed by * reiserfsprogs/README */#define _GNU_SOURCE#include "includes.h"#include <stdarg.h>#include <limits.h>#include <printf.h>#if defined(HAVE_LIBUUID) && defined(HAVE_UUID_UUID_H)# include <uuid/uuid.h>#endif#define PA_KEY (PA_LAST)#define PA_BUFFER_HEAD (PA_LAST + 1)#define PA_ITEM_HEAD (PA_LAST + 2)#define PA_DISK_CHILD (PA_LAST + 3)static int _arginfo_b (const struct printf_info *info, size_t n, int *argtypes) { if (n > 0) argtypes[0] = PA_BUFFER_HEAD | PA_FLAG_PTR; return 1;}static int _arginfo_K (const struct printf_info *info, size_t n, int *argtypes) { if (n > 0) argtypes[0] = PA_KEY | PA_FLAG_PTR; return 1;}static int _arginfo_H (const struct printf_info *info, size_t n, int *argtypes) { if (n > 0) argtypes[0] = PA_ITEM_HEAD | PA_FLAG_PTR; return 1;}static int _arginfo_y (const struct printf_info *info, size_t n, int *argtypes) { if (n > 0) argtypes[0] = PA_DISK_CHILD | PA_FLAG_PTR; return 1;}static int _arginfo_M (const struct printf_info *info, size_t n, int *argtypes) { if (n > 0) argtypes[0] = PA_INT | PA_FLAG_SHORT | PA_FLAG_PTR; return 1;}static int _arginfo_U (const struct printf_info *info, size_t n, int *argtypes) { if (n > 0) argtypes[0] = (PA_CHAR|PA_FLAG_PTR); return 1;}#define FPRINTF \ if (len == -1) {\ return -1;\ }\ len = fprintf (stream, "%*s",\ info->left ? -info->width : info->width, buffer);\ free (buffer);\ return len;\/* %b */static int print_block_head (FILE * stream, const struct printf_info *info, const void *const *args){ const struct buffer_head * bh; char * buffer; int len; bh = *((const struct buffer_head **)(args[0])); len = asprintf (&buffer, "level=%d, nr_items=%d, free_space=%d rdkey", B_LEVEL (bh), B_NR_ITEMS (bh), B_FREE_SPACE (bh)); FPRINTF;}/* %K */static int print_short_key (FILE * stream, const struct printf_info *info, const void *const *args){ const struct key * key; char * buffer; int len; key = *((const struct key **)(args[0])); len = asprintf (&buffer, "[%u %u]", get_key_dirid (key), get_key_objectid (key)); FPRINTF;}/* %k */static int print_key (FILE * stream, const struct printf_info *info, const void *const *args){ const struct key * key; char * buffer; int len; key = *((const struct key **)(args[0])); len = asprintf (&buffer, "[%u %u 0x%Lx %s (%d)]", get_key_dirid (key), get_key_objectid (key), (unsigned long long)get_offset (key), key_of_what (key), get_type (key)); FPRINTF;}/* %H */static int print_item_head (FILE * stream, const struct printf_info *info, const void *const *args){ const struct item_head * ih; char * buffer; int len; ih = *((const struct item_head **)(args[0])); len = asprintf (&buffer, "%u %u 0x%Lx %s (%d), " "len %u, location %u entry count %u, fsck need %u, format %s", get_key_dirid (&ih->ih_key), get_key_objectid (&ih->ih_key), (unsigned long long)get_offset (&ih->ih_key), key_of_what (&ih->ih_key), get_type (&ih->ih_key), get_ih_item_len (ih), get_ih_location (ih), get_ih_entry_count (ih), get_ih_flags (ih), get_ih_key_format (ih) == KEY_FORMAT_2 ? "new" : ((get_ih_key_format (ih) == KEY_FORMAT_1) ? "old" : "BAD")); FPRINTF;}static int print_disk_child (FILE * stream, const struct printf_info *info, const void *const *args){ const struct disk_child * dc; char * buffer; int len; dc = *((const struct disk_child **)(args[0])); len = asprintf (&buffer, "[dc_number=%u, dc_size=%u]", get_dc_child_blocknr (dc), get_dc_child_size (dc)); FPRINTF;}char ftypelet (mode_t mode){ if (S_ISBLK (mode)) return 'b'; if (S_ISCHR (mode)) return 'c'; if (S_ISDIR (mode)) return 'd'; if (S_ISREG (mode)) return '-'; if (S_ISFIFO (mode)) return 'p'; if (S_ISLNK (mode)) return 'l'; if (S_ISSOCK (mode)) return 's'; return '?';}static int rwx (FILE * stream, mode_t mode){ return fprintf (stream, "%c%c%c", (mode & S_IRUSR) ? 'r' : '-', (mode & S_IWUSR) ? 'w' : '-', (mode & S_IXUSR) ? 'x' : '-');}/* %M */static int print_sd_mode (FILE * stream, const struct printf_info *info, const void *const *args){ int len = 0; __u16 mode; mode = *(mode_t *)args[0]; len = fprintf (stream, "%c", ftypelet (mode)); len += rwx (stream, (mode & 0700) << 0); len += rwx (stream, (mode & 0070) << 3); len += rwx (stream, (mode & 0007) << 6); return len;}/* %U */static int print_sd_uuid (FILE * stream, const struct printf_info *info, const void *const *args){#if defined(HAVE_LIBUUID) && defined(HAVE_UUID_UUID_H) const unsigned char *uuid = *((const unsigned char **)(args[0])); char buf[37]; buf[36] = '\0'; uuid_unparse(uuid, buf); return fprintf(stream, "%s", buf);#else return fprintf(stream, "<no libuuid installed>");#endif}void reiserfs_warning (FILE * fp, const char * fmt, ...) { static int registered = 0; va_list args; if (!registered) { registered = 1; register_printf_function ('K', print_short_key, _arginfo_K); register_printf_function ('k', print_key, _arginfo_K); register_printf_function ('H', print_item_head, _arginfo_H); register_printf_function ('b', print_block_head, _arginfo_b); register_printf_function ('y', print_disk_child, _arginfo_y); register_printf_function ('M', print_sd_mode, _arginfo_M); register_printf_function ('U', print_sd_uuid, _arginfo_U); } va_start (args, fmt); vfprintf (fp, fmt, args); va_end (args);}static char * vi_type (struct virtual_item * vi){ static char *types[]={"directory", "direct", "indirect", "stat data"}; if (vi->vi_type & VI_TYPE_STAT_DATA) return types[3]; if (vi->vi_type & VI_TYPE_INDIRECT) return types[2]; if (vi->vi_type & VI_TYPE_DIRECT) return types[1]; if (vi->vi_type & VI_TYPE_DIRECTORY) return types[0]; reiserfs_panic ("vi_type: 6000: unknown type (0x%x)", vi->vi_type); return NULL;}void print_virtual_node (struct virtual_node * vn){ int i, j; printf ("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); for (i = 0; i < vn->vn_nr_item; i ++) { printf ("%s %d %d", vi_type (&vn->vn_vi[i]), i, vn->vn_vi[i].vi_item_len); if (vn->vn_vi[i].vi_entry_sizes) { printf ("It is directory with %d entries: ", vn->vn_vi[i].vi_entry_count); for (j = 0; j < vn->vn_vi[i].vi_entry_count; j ++) printf ("%d ", vn->vn_vi[i].vi_entry_sizes[j]); } printf ("\n"); }}void print_path (struct tree_balance * tb, struct path * path){ int offset = path->path_length; struct buffer_head * bh; printf ("Offset Bh (b_blocknr, b_count) Position Nr_item\n"); while ( offset > ILLEGAL_PATH_ELEMENT_OFFSET ) { bh = PATH_OFFSET_PBUFFER (path, offset); printf ("%6d %10p (%9lu, %7d) %8d %7d\n", offset, bh, bh ? bh->b_blocknr : 0, bh ? bh->b_count : 0, PATH_OFFSET_POSITION (path, offset), bh ? B_NR_ITEMS (bh) : -1); offset --; }}void print_directory_item (FILE * fp, reiserfs_filsys_t * fs, struct buffer_head * bh, struct item_head * ih){ int i; int namelen; struct reiserfs_de_head * deh; char * name;/* static char namebuf [80];*/ if (!I_IS_DIRECTORY_ITEM (ih)) return; //printk ("\n%2%-25s%-30s%-15s%-15s%-15s\n", " Name", "length", "Object key", "Hash", "Gen number", "Status"); reiserfs_warning (fp, "%3s: %-25s%s%-22s%-12s%s\n", "###", "Name", "length", " Object key", " Hash", "Gen number"); deh = B_I_DEH (bh, ih); for (i = 0; i < get_ih_entry_count (ih); i ++, deh ++) { if (dir_entry_bad_location (deh, ih, i == 0 ? 1 : 0)) { reiserfs_warning (fp, "%3d: wrong entry location %u, deh_offset %u\n", i, get_deh_location (deh), get_deh_offset (deh)); continue; } if (i && dir_entry_bad_location (deh - 1, ih, ((i - 1) == 0) ? 1 : 0)) /* previous entry has bad location so we can not calculate entry length */ namelen = 25; else namelen = name_in_entry_length (ih, deh, i); name = name_in_entry (deh, i); reiserfs_warning (fp, "%3d: \"%-25.*s\"(%3d)%20K%12d%5d, loc %u, state %x %s\n", i, namelen, name, namelen, (struct key *)&(deh->deh2_dir_id), GET_HASH_VALUE (get_deh_offset (deh)), GET_GENERATION_NUMBER (get_deh_offset (deh)), get_deh_location (deh), get_deh_state (deh), code2name (find_hash_in_use (name, namelen, get_deh_offset (deh), fs ? get_sb_hash_code (fs->fs_ondisk_sb) : UNSET_HASH))); /*fs ? (is_properly_hashed (fs, name, namelen, deh_offset (deh)) ? "" : "(BROKEN)") : "??");*/ }}//// printing of indirect item//static void start_new_sequence (__u32 * start, int * len, __u32 new){ *start = new; *len = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -