blob: e831a8f30849a98a088d46394742cc3b4c476182 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/befs/debug.c
3 *
4 * Copyright (C) 2001 Will Dyson (will_dyson at pobox.com)
5 *
6 * With help from the ntfs-tng driver by Anton Altparmakov
7 *
8 * Copyright (C) 1999 Makoto Kato (m_kato@ga2.so-net.ne.jp)
9 *
10 * debug functions
11 */
12
13#ifdef __KERNEL__
14
15#include <stdarg.h>
16#include <linux/string.h>
17#include <linux/spinlock.h>
18#include <linux/kernel.h>
19#include <linux/fs.h>
20
21#endif /* __KERNEL__ */
22
23#include "befs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#define ERRBUFSIZE 1024
26
27void
28befs_error(const struct super_block *sb, const char *fmt, ...)
29{
30 va_list args;
31 char *err_buf = (char *) kmalloc(ERRBUFSIZE, GFP_KERNEL);
32 if (err_buf == NULL) {
33 printk(KERN_ERR "could not allocate %d bytes\n", ERRBUFSIZE);
34 return;
35 }
36
37 va_start(args, fmt);
38 vsnprintf(err_buf, ERRBUFSIZE, fmt, args);
39 va_end(args);
40
41 printk(KERN_ERR "BeFS(%s): %s\n", sb->s_id, err_buf);
42 kfree(err_buf);
43}
44
45void
46befs_warning(const struct super_block *sb, const char *fmt, ...)
47{
48 va_list args;
49 char *err_buf = (char *) kmalloc(ERRBUFSIZE, GFP_KERNEL);
50 if (err_buf == NULL) {
51 printk(KERN_ERR "could not allocate %d bytes\n", ERRBUFSIZE);
52 return;
53 }
54
55 va_start(args, fmt);
56 vsnprintf(err_buf, ERRBUFSIZE, fmt, args);
57 va_end(args);
58
59 printk(KERN_WARNING "BeFS(%s): %s\n", sb->s_id, err_buf);
60
61 kfree(err_buf);
62}
63
64void
65befs_debug(const struct super_block *sb, const char *fmt, ...)
66{
67#ifdef CONFIG_BEFS_DEBUG
68
69 va_list args;
70 char *err_buf = NULL;
71
72 if (BEFS_SB(sb)->mount_opts.debug) {
73 err_buf = (char *) kmalloc(ERRBUFSIZE, GFP_KERNEL);
74 if (err_buf == NULL) {
75 printk(KERN_ERR "could not allocate %d bytes\n",
76 ERRBUFSIZE);
77 return;
78 }
79
80 va_start(args, fmt);
81 vsnprintf(err_buf, ERRBUFSIZE, fmt, args);
82 va_end(args);
83
84 printk(KERN_DEBUG "BeFS(%s): %s\n", sb->s_id, err_buf);
85
86 kfree(err_buf);
87 }
88
89#endif //CONFIG_BEFS_DEBUG
90}
91
92void
93befs_dump_inode(const struct super_block *sb, befs_inode * inode)
94{
95#ifdef CONFIG_BEFS_DEBUG
96
97 befs_block_run tmp_run;
98
99 befs_debug(sb, "befs_inode information");
100
101 befs_debug(sb, " magic1 %08x", fs32_to_cpu(sb, inode->magic1));
102
103 tmp_run = fsrun_to_cpu(sb, inode->inode_num);
104 befs_debug(sb, " inode_num %u, %hu, %hu",
105 tmp_run.allocation_group, tmp_run.start, tmp_run.len);
106
107 befs_debug(sb, " uid %u", fs32_to_cpu(sb, inode->uid));
108 befs_debug(sb, " gid %u", fs32_to_cpu(sb, inode->gid));
109 befs_debug(sb, " mode %08x", fs32_to_cpu(sb, inode->mode));
110 befs_debug(sb, " flags %08x", fs32_to_cpu(sb, inode->flags));
111 befs_debug(sb, " create_time %Lu",
112 fs64_to_cpu(sb, inode->create_time));
113 befs_debug(sb, " last_modified_time %Lu",
114 fs64_to_cpu(sb, inode->last_modified_time));
115
116 tmp_run = fsrun_to_cpu(sb, inode->parent);
117 befs_debug(sb, " parent [%u, %hu, %hu]",
118 tmp_run.allocation_group, tmp_run.start, tmp_run.len);
119
120 tmp_run = fsrun_to_cpu(sb, inode->attributes);
121 befs_debug(sb, " attributes [%u, %hu, %hu]",
122 tmp_run.allocation_group, tmp_run.start, tmp_run.len);
123
124 befs_debug(sb, " type %08x", fs32_to_cpu(sb, inode->type));
125 befs_debug(sb, " inode_size %u", fs32_to_cpu(sb, inode->inode_size));
126
Al Viroe5201c52005-12-24 03:09:03 -0500127 if (S_ISLNK(fs32_to_cpu(sb, inode->mode))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 befs_debug(sb, " Symbolic link [%s]", inode->data.symlink);
129 } else {
130 int i;
131
132 for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; i++) {
133 tmp_run =
134 fsrun_to_cpu(sb, inode->data.datastream.direct[i]);
135 befs_debug(sb, " direct %d [%u, %hu, %hu]", i,
136 tmp_run.allocation_group, tmp_run.start,
137 tmp_run.len);
138 }
139 befs_debug(sb, " max_direct_range %Lu",
140 fs64_to_cpu(sb,
141 inode->data.datastream.
142 max_direct_range));
143
144 tmp_run = fsrun_to_cpu(sb, inode->data.datastream.indirect);
145 befs_debug(sb, " indirect [%u, %hu, %hu]",
146 tmp_run.allocation_group,
147 tmp_run.start, tmp_run.len);
148
149 befs_debug(sb, " max_indirect_range %Lu",
150 fs64_to_cpu(sb,
151 inode->data.datastream.
152 max_indirect_range));
153
154 tmp_run =
155 fsrun_to_cpu(sb, inode->data.datastream.double_indirect);
156 befs_debug(sb, " double indirect [%u, %hu, %hu]",
157 tmp_run.allocation_group, tmp_run.start,
158 tmp_run.len);
159
160 befs_debug(sb, " max_double_indirect_range %Lu",
161 fs64_to_cpu(sb,
162 inode->data.datastream.
163 max_double_indirect_range));
164
165 befs_debug(sb, " size %Lu",
166 fs64_to_cpu(sb, inode->data.datastream.size));
167 }
168
169#endif //CONFIG_BEFS_DEBUG
170}
171
172/*
173 * Display super block structure for debug.
174 */
175
176void
177befs_dump_super_block(const struct super_block *sb, befs_super_block * sup)
178{
179#ifdef CONFIG_BEFS_DEBUG
180
181 befs_block_run tmp_run;
182
183 befs_debug(sb, "befs_super_block information");
184
185 befs_debug(sb, " name %s", sup->name);
186 befs_debug(sb, " magic1 %08x", fs32_to_cpu(sb, sup->magic1));
187 befs_debug(sb, " fs_byte_order %08x",
188 fs32_to_cpu(sb, sup->fs_byte_order));
189
190 befs_debug(sb, " block_size %u", fs32_to_cpu(sb, sup->block_size));
191 befs_debug(sb, " block_shift %u", fs32_to_cpu(sb, sup->block_shift));
192
193 befs_debug(sb, " num_blocks %Lu", fs64_to_cpu(sb, sup->num_blocks));
194 befs_debug(sb, " used_blocks %Lu", fs64_to_cpu(sb, sup->used_blocks));
195
196 befs_debug(sb, " magic2 %08x", fs32_to_cpu(sb, sup->magic2));
197 befs_debug(sb, " blocks_per_ag %u",
198 fs32_to_cpu(sb, sup->blocks_per_ag));
199 befs_debug(sb, " ag_shift %u", fs32_to_cpu(sb, sup->ag_shift));
200 befs_debug(sb, " num_ags %u", fs32_to_cpu(sb, sup->num_ags));
201
202 befs_debug(sb, " flags %08x", fs32_to_cpu(sb, sup->flags));
203
204 tmp_run = fsrun_to_cpu(sb, sup->log_blocks);
205 befs_debug(sb, " log_blocks %u, %hu, %hu",
206 tmp_run.allocation_group, tmp_run.start, tmp_run.len);
207
208 befs_debug(sb, " log_start %Ld", fs64_to_cpu(sb, sup->log_start));
209 befs_debug(sb, " log_end %Ld", fs64_to_cpu(sb, sup->log_end));
210
211 befs_debug(sb, " magic3 %08x", fs32_to_cpu(sb, sup->magic3));
212
213 tmp_run = fsrun_to_cpu(sb, sup->root_dir);
214 befs_debug(sb, " root_dir %u, %hu, %hu",
215 tmp_run.allocation_group, tmp_run.start, tmp_run.len);
216
217 tmp_run = fsrun_to_cpu(sb, sup->indices);
218 befs_debug(sb, " indices %u, %hu, %hu",
219 tmp_run.allocation_group, tmp_run.start, tmp_run.len);
220
221#endif //CONFIG_BEFS_DEBUG
222}
223
224#if 0
225/* unused */
226void
227befs_dump_small_data(const struct super_block *sb, befs_small_data * sd)
228{
229}
230
231/* unused */
232void
Al Viroa9721f32005-12-24 14:28:55 -0500233befs_dump_run(const struct super_block *sb, befs_disk_block_run run)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
235#ifdef CONFIG_BEFS_DEBUG
236
Al Viroa9721f32005-12-24 14:28:55 -0500237 befs_block_run n = fsrun_to_cpu(sb, run);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Al Viroa9721f32005-12-24 14:28:55 -0500239 befs_debug(sb, "[%u, %hu, %hu]", n.allocation_group, n.start, n.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241#endif //CONFIG_BEFS_DEBUG
242}
243#endif /* 0 */
244
245void
Al Viroa9721f32005-12-24 14:28:55 -0500246befs_dump_index_entry(const struct super_block *sb, befs_disk_btree_super * super)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
248#ifdef CONFIG_BEFS_DEBUG
249
250 befs_debug(sb, "Btree super structure");
251 befs_debug(sb, " magic %08x", fs32_to_cpu(sb, super->magic));
252 befs_debug(sb, " node_size %u", fs32_to_cpu(sb, super->node_size));
253 befs_debug(sb, " max_depth %08x", fs32_to_cpu(sb, super->max_depth));
254
255 befs_debug(sb, " data_type %08x", fs32_to_cpu(sb, super->data_type));
256 befs_debug(sb, " root_node_pointer %016LX",
257 fs64_to_cpu(sb, super->root_node_ptr));
258 befs_debug(sb, " free_node_pointer %016LX",
259 fs64_to_cpu(sb, super->free_node_ptr));
260 befs_debug(sb, " maximum size %016LX",
261 fs64_to_cpu(sb, super->max_size));
262
263#endif //CONFIG_BEFS_DEBUG
264}
265
266void
267befs_dump_index_node(const struct super_block *sb, befs_btree_nodehead * node)
268{
269#ifdef CONFIG_BEFS_DEBUG
270
271 befs_debug(sb, "Btree node structure");
272 befs_debug(sb, " left %016LX", fs64_to_cpu(sb, node->left));
273 befs_debug(sb, " right %016LX", fs64_to_cpu(sb, node->right));
274 befs_debug(sb, " overflow %016LX", fs64_to_cpu(sb, node->overflow));
275 befs_debug(sb, " all_key_count %hu",
276 fs16_to_cpu(sb, node->all_key_count));
277 befs_debug(sb, " all_key_length %hu",
278 fs16_to_cpu(sb, node->all_key_length));
279
280#endif //CONFIG_BEFS_DEBUG
281}