ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / fs / befs / debug.c
1 /*
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"
24 #include "endian.h"
25
26 #define ERRBUFSIZE 1024
27
28 void
29 befs_error(const struct super_block *sb, const char *fmt, ...)
30 {
31         va_list args;
32         char err_buf[ERRBUFSIZE];
33
34         va_start(args, fmt);
35         vsnprintf(err_buf, ERRBUFSIZE, fmt, args);
36         va_end(args);
37
38         printk(KERN_ERR "BeFS(%s): %s\n", sb->s_id, err_buf);
39
40         befs_debug(sb, err_buf);
41 }
42
43 void
44 befs_warning(const struct super_block *sb, const char *fmt, ...)
45 {
46         va_list args;
47         char err_buf[ERRBUFSIZE];
48
49         va_start(args, fmt);
50         vsnprintf(err_buf, ERRBUFSIZE, fmt, args);
51         va_end(args);
52
53         printk(KERN_WARNING "BeFS(%s): %s\n", sb->s_id, err_buf);
54
55         befs_debug(sb, err_buf);
56 }
57
58 void
59 befs_debug(const struct super_block *sb, const char *fmt, ...)
60 {
61 #ifdef CONFIG_BEFS_DEBUG
62
63         va_list args;
64         char err_buf[ERRBUFSIZE];
65
66         if (BEFS_SB(sb)->mount_opts.debug) {
67                 va_start(args, fmt);
68                 vsnprintf(err_buf, ERRBUFSIZE, fmt, args);
69                 va_end(args);
70
71                 printk(KERN_DEBUG "BeFS(%s): %s\n", sb->s_id, err_buf);
72         }
73 #endif                          //CONFIG_BEFS_DEBUG
74 }
75
76 void
77 befs_dump_inode(const struct super_block *sb, befs_inode * inode)
78 {
79 #ifdef CONFIG_BEFS_DEBUG
80
81         befs_block_run tmp_run;
82
83         befs_debug(sb, "befs_inode information");
84
85         befs_debug(sb, "  magic1 %08x", fs32_to_cpu(sb, inode->magic1));
86
87         tmp_run = fsrun_to_cpu(sb, inode->inode_num);
88         befs_debug(sb, "  inode_num %u, %hu, %hu",
89                    tmp_run.allocation_group, tmp_run.start, tmp_run.len);
90
91         befs_debug(sb, "  uid %u", fs32_to_cpu(sb, inode->uid));
92         befs_debug(sb, "  gid %u", fs32_to_cpu(sb, inode->gid));
93         befs_debug(sb, "  mode %08x", fs32_to_cpu(sb, inode->mode));
94         befs_debug(sb, "  flags %08x", fs32_to_cpu(sb, inode->flags));
95         befs_debug(sb, "  create_time %Lu",
96                    fs64_to_cpu(sb, inode->create_time));
97         befs_debug(sb, "  last_modified_time %Lu",
98                    fs64_to_cpu(sb, inode->last_modified_time));
99
100         tmp_run = fsrun_to_cpu(sb, inode->parent);
101         befs_debug(sb, "  parent [%u, %hu, %hu]",
102                    tmp_run.allocation_group, tmp_run.start, tmp_run.len);
103
104         tmp_run = fsrun_to_cpu(sb, inode->attributes);
105         befs_debug(sb, "  attributes [%u, %hu, %hu]",
106                    tmp_run.allocation_group, tmp_run.start, tmp_run.len);
107
108         befs_debug(sb, "  type %08x", fs32_to_cpu(sb, inode->type));
109         befs_debug(sb, "  inode_size %u", fs32_to_cpu(sb, inode->inode_size));
110
111         if (S_ISLNK(inode->mode)) {
112                 befs_debug(sb, "  Symbolic link [%s]", inode->data.symlink);
113         } else {
114                 int i;
115
116                 for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; i++) {
117                         tmp_run =
118                             fsrun_to_cpu(sb, inode->data.datastream.direct[i]);
119                         befs_debug(sb, "  direct %d [%u, %hu, %hu]", i,
120                                    tmp_run.allocation_group, tmp_run.start,
121                                    tmp_run.len);
122                 }
123                 befs_debug(sb, "  max_direct_range %Lu",
124                            fs64_to_cpu(sb,
125                                        inode->data.datastream.
126                                        max_direct_range));
127
128                 tmp_run = fsrun_to_cpu(sb, inode->data.datastream.indirect);
129                 befs_debug(sb, "  indirect [%u, %hu, %hu]",
130                            tmp_run.allocation_group,
131                            tmp_run.start, tmp_run.len);
132
133                 befs_debug(sb, "  max_indirect_range %Lu",
134                            fs64_to_cpu(sb,
135                                        inode->data.datastream.
136                                        max_indirect_range));
137
138                 tmp_run =
139                     fsrun_to_cpu(sb, inode->data.datastream.double_indirect);
140                 befs_debug(sb, "  double indirect [%u, %hu, %hu]",
141                            tmp_run.allocation_group, tmp_run.start,
142                            tmp_run.len);
143
144                 befs_debug(sb, "  max_double_indirect_range %Lu",
145                            fs64_to_cpu(sb,
146                                        inode->data.datastream.
147                                        max_double_indirect_range));
148
149                 befs_debug(sb, "  size %Lu",
150                            fs64_to_cpu(sb, inode->data.datastream.size));
151         }
152
153 #endif                          //CONFIG_BEFS_DEBUG
154 }
155
156 /*
157  * Display super block structure for debug.
158  */
159
160 void
161 befs_dump_super_block(const struct super_block *sb, befs_super_block * sup)
162 {
163 #ifdef CONFIG_BEFS_DEBUG
164
165         befs_block_run tmp_run;
166
167         befs_debug(sb, "befs_super_block information");
168
169         befs_debug(sb, "  name %s", sup->name);
170         befs_debug(sb, "  magic1 %08x", fs32_to_cpu(sb, sup->magic1));
171         befs_debug(sb, "  fs_byte_order %08x",
172                    fs32_to_cpu(sb, sup->fs_byte_order));
173
174         befs_debug(sb, "  block_size %u", fs32_to_cpu(sb, sup->block_size));
175         befs_debug(sb, "  block_shift %u", fs32_to_cpu(sb, sup->block_shift));
176
177         befs_debug(sb, "  num_blocks %Lu", fs64_to_cpu(sb, sup->num_blocks));
178         befs_debug(sb, "  used_blocks %Lu", fs64_to_cpu(sb, sup->used_blocks));
179
180         befs_debug(sb, "  magic2 %08x", fs32_to_cpu(sb, sup->magic2));
181         befs_debug(sb, "  blocks_per_ag %u",
182                    fs32_to_cpu(sb, sup->blocks_per_ag));
183         befs_debug(sb, "  ag_shift %u", fs32_to_cpu(sb, sup->ag_shift));
184         befs_debug(sb, "  num_ags %u", fs32_to_cpu(sb, sup->num_ags));
185
186         befs_debug(sb, "  flags %08x", fs32_to_cpu(sb, sup->flags));
187
188         tmp_run = fsrun_to_cpu(sb, sup->log_blocks);
189         befs_debug(sb, "  log_blocks %u, %hu, %hu",
190                    tmp_run.allocation_group, tmp_run.start, tmp_run.len);
191
192         befs_debug(sb, "  log_start %Ld", fs64_to_cpu(sb, sup->log_start));
193         befs_debug(sb, "  log_end %Ld", fs64_to_cpu(sb, sup->log_end));
194
195         befs_debug(sb, "  magic3 %08x", fs32_to_cpu(sb, sup->magic3));
196
197         tmp_run = fsrun_to_cpu(sb, sup->root_dir);
198         befs_debug(sb, "  root_dir %u, %hu, %hu",
199                    tmp_run.allocation_group, tmp_run.start, tmp_run.len);
200
201         tmp_run = fsrun_to_cpu(sb, sup->indices);
202         befs_debug(sb, "  indices %u, %hu, %hu",
203                    tmp_run.allocation_group, tmp_run.start, tmp_run.len);
204
205 #endif                          //CONFIG_BEFS_DEBUG
206 }
207
208 void
209 befs_dump_small_data(const struct super_block *sb, befs_small_data * sd)
210 {
211 }
212
213 void
214 befs_dump_run(const struct super_block *sb, befs_block_run run)
215 {
216 #ifdef CONFIG_BEFS_DEBUG
217
218         run = fsrun_to_cpu(sb, run);
219
220         befs_debug(sb, "[%u, %hu, %hu]",
221                    run.allocation_group, run.start, run.len);
222
223 #endif                          //CONFIG_BEFS_DEBUG
224 }
225
226 void
227 befs_dump_index_entry(const struct super_block *sb, befs_btree_super * super)
228 {
229 #ifdef CONFIG_BEFS_DEBUG
230
231         befs_debug(sb, "Btree super structure");
232         befs_debug(sb, "  magic %08x", fs32_to_cpu(sb, super->magic));
233         befs_debug(sb, "  node_size %u", fs32_to_cpu(sb, super->node_size));
234         befs_debug(sb, "  max_depth %08x", fs32_to_cpu(sb, super->max_depth));
235
236         befs_debug(sb, "  data_type %08x", fs32_to_cpu(sb, super->data_type));
237         befs_debug(sb, "  root_node_pointer %016LX",
238                    fs64_to_cpu(sb, super->root_node_ptr));
239         befs_debug(sb, "  free_node_pointer %016LX",
240                    fs64_to_cpu(sb, super->free_node_ptr));
241         befs_debug(sb, "  maximum size %016LX",
242                    fs64_to_cpu(sb, super->max_size));
243
244 #endif                          //CONFIG_BEFS_DEBUG
245 }
246
247 void
248 befs_dump_index_node(const struct super_block *sb, befs_btree_nodehead * node)
249 {
250 #ifdef CONFIG_BEFS_DEBUG
251
252         befs_debug(sb, "Btree node structure");
253         befs_debug(sb, "  left %016LX", fs64_to_cpu(sb, node->left));
254         befs_debug(sb, "  right %016LX", fs64_to_cpu(sb, node->right));
255         befs_debug(sb, "  overflow %016LX", fs64_to_cpu(sb, node->overflow));
256         befs_debug(sb, "  all_key_count %hu",
257                    fs16_to_cpu(sb, node->all_key_count));
258         befs_debug(sb, "  all_key_length %hu",
259                    fs16_to_cpu(sb, node->all_key_length));
260
261 #endif                          //CONFIG_BEFS_DEBUG
262 }