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