2 * Copyright 2000 Hans Reiser
3 * See README for licensing and copyright details
5 * Ported to FreeBSD by Jean-Sébastien Pédron <jspedron@club-internet.fr>
10 #include <gnu/fs/reiserfs/reiserfs_fs.h>
13 static char error_buf[1024];
14 static char fmt_buf[1024];
15 static char off_buf[80];
18 reiserfs_cpu_offset(struct cpu_key *key)
21 if (cpu_key_k_type(key) == TYPE_DIRENTRY)
22 sprintf(off_buf, "%Lu(%Lu)",
23 (unsigned long long)GET_HASH_VALUE(cpu_key_k_offset(key)),
24 (unsigned long long)GET_GENERATION_NUMBER(
25 cpu_key_k_offset(key)));
27 sprintf(off_buf, "0x%Lx",
28 (unsigned long long)cpu_key_k_offset(key));
34 le_offset(struct key *key)
38 version = le_key_version(key);
39 if (le_key_k_type(version, key) == TYPE_DIRENTRY)
40 sprintf(off_buf, "%Lu(%Lu)",
41 (unsigned long long)GET_HASH_VALUE(
42 le_key_k_offset(version, key)),
43 (unsigned long long)GET_GENERATION_NUMBER(
44 le_key_k_offset(version, key)));
46 sprintf(off_buf, "0x%Lx",
47 (unsigned long long)le_key_k_offset(version, key));
53 cpu_type(struct cpu_key *key)
56 if (cpu_key_k_type(key) == TYPE_STAT_DATA)
58 if (cpu_key_k_type(key) == TYPE_DIRENTRY)
60 if (cpu_key_k_type(key) == TYPE_DIRECT)
62 if (cpu_key_k_type(key) == TYPE_INDIRECT)
69 le_type(struct key *key)
73 version = le_key_version(key);
75 if (le_key_k_type(version, key) == TYPE_STAT_DATA)
77 if (le_key_k_type(version, key) == TYPE_DIRENTRY)
79 if (le_key_k_type(version, key) == TYPE_DIRECT)
81 if (le_key_k_type(version, key) == TYPE_INDIRECT)
89 sprintf_le_key(char *buf, struct key *key)
93 sprintf(buf, "[%d %d %s %s]", le32toh(key->k_dir_id),
94 le32toh(key->k_objectid), le_offset(key), le_type(key));
96 sprintf(buf, "[NULL]");
101 sprintf_cpu_key(char *buf, struct cpu_key *key)
105 sprintf(buf, "[%d %d %s %s]", key->on_disk_key.k_dir_id,
106 key->on_disk_key.k_objectid, reiserfs_cpu_offset (key),
109 sprintf(buf, "[NULL]");
112 static void sprintf_de_head(char *buf, struct reiserfs_de_head *deh)
117 "[offset=%d dir_id=%d objectid=%d location=%d state=%04x]",
118 deh_offset(deh), deh_dir_id(deh),
119 deh_objectid(deh), deh_location(deh), deh_state(deh));
121 sprintf(buf, "[NULL]");
125 sprintf_item_head(char *buf, struct item_head *ih)
129 strcpy(buf, (ih_version(ih) == KEY_FORMAT_3_6) ?
131 sprintf_le_key(buf + strlen(buf), &(ih->ih_key));
132 sprintf(buf + strlen(buf), ", item_len %d, item_location %d, "
133 "free_space(entry_count) %d",
134 ih_item_len(ih), ih_location(ih), ih_free_space(ih));
136 sprintf(buf, "[NULL]");
140 sprintf_direntry(char *buf, struct reiserfs_dir_entry *de)
144 memcpy(name, de->de_name, de->de_namelen > 19 ? 19 : de->de_namelen);
145 name [de->de_namelen > 19 ? 19 : de->de_namelen] = 0;
146 sprintf(buf, "\"%s\" ==> [%d %d]",
147 name, de->de_dir_id, de->de_objectid);
151 sprintf_block_head(char *buf, struct buf *bp)
154 sprintf(buf, "level=%d, nr_items=%d, free_space=%d rdkey ",
155 B_LEVEL(bp), B_NR_ITEMS(bp), B_FREE_SPACE(bp));
159 sprintf_disk_child(char *buf, struct disk_child *dc)
162 sprintf (buf, "[dc_number=%d, dc_size=%u]",
163 dc_block_number(dc), dc_size(dc));
167 is_there_reiserfs_struct (char *fmt, int *what, int *skip)
174 while ((k = strchr(k, '%')) != NULL) {
175 if (k[1] == 'k' || k[1] == 'K' || k[1] == 'h' || k[1] == 't' ||
176 k[1] == 'z' || k[1] == 'b' || k[1] == 'y' || k[1] == 'a' ) {
188 prepare_error_buf(const char *fmt, va_list args)
191 int i, j, what, skip;
197 while ((k = is_there_reiserfs_struct(fmt1, &what, &skip)) != NULL) {
200 p += vsprintf (p, fmt1, args);
202 for (i = 0; i < skip; i ++)
203 j = va_arg(args, int);
207 sprintf_le_key(p, va_arg(args, struct key *));
210 sprintf_cpu_key(p, va_arg(args, struct cpu_key *));
213 sprintf_item_head(p, va_arg(args, struct item_head *));
217 va_arg(args, struct reiserfs_dir_entry *));
220 sprintf_disk_child(p,
221 va_arg(args, struct disk_child *));
224 sprintf_block_head(p,
225 va_arg(args, struct buffer_head *));
229 va_arg(args, struct reiserfs_de_head *));
237 vsprintf(p, fmt1, args);
241 * In addition to usual conversion specifiers this accepts reiserfs
242 * specific conversion specifiers:
243 * %k to print little endian key,
244 * %K to print cpu key,
245 * %h to print item_head,
246 * %t to print directory entry,
247 * %z to print block head (arg must be struct buf *)
250 #define do_reiserfs_warning(fmt) \
253 va_start(args, fmt); \
254 prepare_error_buf(fmt, args); \
259 __reiserfs_log(int level, const char * fmt, ...)
262 do_reiserfs_warning(fmt);
263 log(level, "ReiserFS/%s: %s\n", __FUNCTION__, error_buf);
269 reiserfs_hashname(int code)
272 if (code == YURA_HASH)
274 if (code == TEA_HASH)
283 reiserfs_dump_buffer(caddr_t buf, off_t len)
287 log(LOG_DEBUG, "reiserfs: dumping a buffer of %jd bytes\n",
289 for (i = 0; i < len; i += 16) {
290 log(LOG_DEBUG, "%08x: ", i);
291 for (j = 0; j < 16; j += 2) {
295 log(LOG_DEBUG, "%02x%02x ",
297 buf[i + j + 1] & 0xff);
299 for (j = 0; j < 16; ++j) {
303 isprint(buf[i + j]) ? buf[i + j] : '.');
305 log(LOG_DEBUG, "\n");