Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/befs/debug.c |
Luis de Bethencourt | a83179a | 2016-08-14 17:26:43 +0100 | [diff] [blame] | 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Copyright (C) 2001 Will Dyson (will_dyson at pobox.com) |
| 6 | * |
| 7 | * With help from the ntfs-tng driver by Anton Altparmakov |
| 8 | * |
| 9 | * Copyright (C) 1999 Makoto Kato (m_kato@ga2.so-net.ne.jp) |
| 10 | * |
| 11 | * debug functions |
| 12 | */ |
| 13 | |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #ifdef __KERNEL__ |
| 16 | |
| 17 | #include <stdarg.h> |
| 18 | #include <linux/string.h> |
| 19 | #include <linux/spinlock.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/fs.h> |
Pekka Enberg | c325962 | 2009-03-24 10:43:50 +0200 | [diff] [blame] | 22 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | #endif /* __KERNEL__ */ |
| 25 | |
| 26 | #include "befs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | void |
| 29 | befs_error(const struct super_block *sb, const char *fmt, ...) |
| 30 | { |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 31 | struct va_format vaf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | va_list args; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | va_start(args, fmt); |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 35 | vaf.fmt = fmt; |
| 36 | vaf.va = &args; |
| 37 | pr_err("(%s): %pV\n", sb->s_id, &vaf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | va_end(args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void |
| 42 | befs_warning(const struct super_block *sb, const char *fmt, ...) |
| 43 | { |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 44 | struct va_format vaf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | va_list args; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | va_start(args, fmt); |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 48 | vaf.fmt = fmt; |
| 49 | vaf.va = &args; |
| 50 | pr_warn("(%s): %pV\n", sb->s_id, &vaf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | va_end(args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void |
| 55 | befs_debug(const struct super_block *sb, const char *fmt, ...) |
| 56 | { |
| 57 | #ifdef CONFIG_BEFS_DEBUG |
| 58 | |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 59 | struct va_format vaf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | va_list args; |
Luis de Bethencourt | a83179a | 2016-08-14 17:26:43 +0100 | [diff] [blame] | 61 | |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 62 | va_start(args, fmt); |
| 63 | vaf.fmt = fmt; |
| 64 | vaf.va = &args; |
| 65 | pr_debug("(%s): %pV\n", sb->s_id, &vaf); |
| 66 | va_end(args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | #endif //CONFIG_BEFS_DEBUG |
| 69 | } |
| 70 | |
| 71 | void |
Luis de Bethencourt | a83179a | 2016-08-14 17:26:43 +0100 | [diff] [blame] | 72 | befs_dump_inode(const struct super_block *sb, befs_inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
| 74 | #ifdef CONFIG_BEFS_DEBUG |
| 75 | |
| 76 | befs_block_run tmp_run; |
| 77 | |
| 78 | befs_debug(sb, "befs_inode information"); |
| 79 | |
| 80 | befs_debug(sb, " magic1 %08x", fs32_to_cpu(sb, inode->magic1)); |
| 81 | |
| 82 | tmp_run = fsrun_to_cpu(sb, inode->inode_num); |
| 83 | befs_debug(sb, " inode_num %u, %hu, %hu", |
| 84 | tmp_run.allocation_group, tmp_run.start, tmp_run.len); |
| 85 | |
| 86 | befs_debug(sb, " uid %u", fs32_to_cpu(sb, inode->uid)); |
| 87 | befs_debug(sb, " gid %u", fs32_to_cpu(sb, inode->gid)); |
| 88 | befs_debug(sb, " mode %08x", fs32_to_cpu(sb, inode->mode)); |
| 89 | befs_debug(sb, " flags %08x", fs32_to_cpu(sb, inode->flags)); |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 90 | befs_debug(sb, " create_time %llu", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | fs64_to_cpu(sb, inode->create_time)); |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 92 | befs_debug(sb, " last_modified_time %llu", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | fs64_to_cpu(sb, inode->last_modified_time)); |
| 94 | |
| 95 | tmp_run = fsrun_to_cpu(sb, inode->parent); |
| 96 | befs_debug(sb, " parent [%u, %hu, %hu]", |
| 97 | tmp_run.allocation_group, tmp_run.start, tmp_run.len); |
| 98 | |
| 99 | tmp_run = fsrun_to_cpu(sb, inode->attributes); |
| 100 | befs_debug(sb, " attributes [%u, %hu, %hu]", |
| 101 | tmp_run.allocation_group, tmp_run.start, tmp_run.len); |
| 102 | |
| 103 | befs_debug(sb, " type %08x", fs32_to_cpu(sb, inode->type)); |
| 104 | befs_debug(sb, " inode_size %u", fs32_to_cpu(sb, inode->inode_size)); |
| 105 | |
Al Viro | e5201c5 | 2005-12-24 03:09:03 -0500 | [diff] [blame] | 106 | if (S_ISLNK(fs32_to_cpu(sb, inode->mode))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | befs_debug(sb, " Symbolic link [%s]", inode->data.symlink); |
| 108 | } else { |
| 109 | int i; |
| 110 | |
| 111 | for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; i++) { |
| 112 | tmp_run = |
| 113 | fsrun_to_cpu(sb, inode->data.datastream.direct[i]); |
| 114 | befs_debug(sb, " direct %d [%u, %hu, %hu]", i, |
| 115 | tmp_run.allocation_group, tmp_run.start, |
| 116 | tmp_run.len); |
| 117 | } |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 118 | befs_debug(sb, " max_direct_range %llu", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | fs64_to_cpu(sb, |
| 120 | inode->data.datastream. |
| 121 | max_direct_range)); |
| 122 | |
| 123 | tmp_run = fsrun_to_cpu(sb, inode->data.datastream.indirect); |
| 124 | befs_debug(sb, " indirect [%u, %hu, %hu]", |
| 125 | tmp_run.allocation_group, |
| 126 | tmp_run.start, tmp_run.len); |
| 127 | |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 128 | befs_debug(sb, " max_indirect_range %llu", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | fs64_to_cpu(sb, |
| 130 | inode->data.datastream. |
| 131 | max_indirect_range)); |
| 132 | |
| 133 | tmp_run = |
| 134 | fsrun_to_cpu(sb, inode->data.datastream.double_indirect); |
| 135 | befs_debug(sb, " double indirect [%u, %hu, %hu]", |
| 136 | tmp_run.allocation_group, tmp_run.start, |
| 137 | tmp_run.len); |
| 138 | |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 139 | befs_debug(sb, " max_double_indirect_range %llu", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | fs64_to_cpu(sb, |
| 141 | inode->data.datastream. |
| 142 | max_double_indirect_range)); |
| 143 | |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 144 | befs_debug(sb, " size %llu", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | fs64_to_cpu(sb, inode->data.datastream.size)); |
| 146 | } |
| 147 | |
| 148 | #endif //CONFIG_BEFS_DEBUG |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | * Display super block structure for debug. |
| 153 | */ |
| 154 | |
| 155 | void |
Luis de Bethencourt | a83179a | 2016-08-14 17:26:43 +0100 | [diff] [blame] | 156 | befs_dump_super_block(const struct super_block *sb, befs_super_block *sup) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
| 158 | #ifdef CONFIG_BEFS_DEBUG |
| 159 | |
| 160 | befs_block_run tmp_run; |
| 161 | |
| 162 | befs_debug(sb, "befs_super_block information"); |
| 163 | |
| 164 | befs_debug(sb, " name %s", sup->name); |
| 165 | befs_debug(sb, " magic1 %08x", fs32_to_cpu(sb, sup->magic1)); |
| 166 | befs_debug(sb, " fs_byte_order %08x", |
| 167 | fs32_to_cpu(sb, sup->fs_byte_order)); |
| 168 | |
| 169 | befs_debug(sb, " block_size %u", fs32_to_cpu(sb, sup->block_size)); |
| 170 | befs_debug(sb, " block_shift %u", fs32_to_cpu(sb, sup->block_shift)); |
| 171 | |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 172 | befs_debug(sb, " num_blocks %llu", fs64_to_cpu(sb, sup->num_blocks)); |
| 173 | befs_debug(sb, " used_blocks %llu", fs64_to_cpu(sb, sup->used_blocks)); |
Luis de Bethencourt | d1a8c70 | 2016-08-09 22:20:23 +0100 | [diff] [blame] | 174 | befs_debug(sb, " inode_size %u", fs32_to_cpu(sb, sup->inode_size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | befs_debug(sb, " magic2 %08x", fs32_to_cpu(sb, sup->magic2)); |
| 177 | befs_debug(sb, " blocks_per_ag %u", |
| 178 | fs32_to_cpu(sb, sup->blocks_per_ag)); |
| 179 | befs_debug(sb, " ag_shift %u", fs32_to_cpu(sb, sup->ag_shift)); |
| 180 | befs_debug(sb, " num_ags %u", fs32_to_cpu(sb, sup->num_ags)); |
| 181 | |
| 182 | befs_debug(sb, " flags %08x", fs32_to_cpu(sb, sup->flags)); |
| 183 | |
| 184 | tmp_run = fsrun_to_cpu(sb, sup->log_blocks); |
| 185 | befs_debug(sb, " log_blocks %u, %hu, %hu", |
| 186 | tmp_run.allocation_group, tmp_run.start, tmp_run.len); |
| 187 | |
Fabian Frederick | dac52fc | 2014-04-03 14:50:23 -0700 | [diff] [blame] | 188 | befs_debug(sb, " log_start %lld", fs64_to_cpu(sb, sup->log_start)); |
| 189 | befs_debug(sb, " log_end %lld", fs64_to_cpu(sb, sup->log_end)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | befs_debug(sb, " magic3 %08x", fs32_to_cpu(sb, sup->magic3)); |
| 192 | |
| 193 | tmp_run = fsrun_to_cpu(sb, sup->root_dir); |
| 194 | befs_debug(sb, " root_dir %u, %hu, %hu", |
| 195 | tmp_run.allocation_group, tmp_run.start, tmp_run.len); |
| 196 | |
| 197 | tmp_run = fsrun_to_cpu(sb, sup->indices); |
| 198 | befs_debug(sb, " indices %u, %hu, %hu", |
| 199 | tmp_run.allocation_group, tmp_run.start, tmp_run.len); |
| 200 | |
| 201 | #endif //CONFIG_BEFS_DEBUG |
| 202 | } |
| 203 | |
| 204 | #if 0 |
| 205 | /* unused */ |
| 206 | void |
Luis de Bethencourt | a83179a | 2016-08-14 17:26:43 +0100 | [diff] [blame] | 207 | befs_dump_small_data(const struct super_block *sb, befs_small_data *sd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { |
| 209 | } |
| 210 | |
| 211 | /* unused */ |
| 212 | void |
Al Viro | a9721f3 | 2005-12-24 14:28:55 -0500 | [diff] [blame] | 213 | befs_dump_run(const struct super_block *sb, befs_disk_block_run run) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
| 215 | #ifdef CONFIG_BEFS_DEBUG |
| 216 | |
Al Viro | a9721f3 | 2005-12-24 14:28:55 -0500 | [diff] [blame] | 217 | befs_block_run n = fsrun_to_cpu(sb, run); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Al Viro | a9721f3 | 2005-12-24 14:28:55 -0500 | [diff] [blame] | 219 | befs_debug(sb, "[%u, %hu, %hu]", n.allocation_group, n.start, n.len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | #endif //CONFIG_BEFS_DEBUG |
| 222 | } |
| 223 | #endif /* 0 */ |
| 224 | |
| 225 | void |
Luis de Bethencourt | a83179a | 2016-08-14 17:26:43 +0100 | [diff] [blame] | 226 | befs_dump_index_entry(const struct super_block *sb, |
| 227 | befs_disk_btree_super *super) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Luis de Bethencourt | a83179a | 2016-08-14 17:26:43 +0100 | [diff] [blame] | 248 | befs_dump_index_node(const struct super_block *sb, befs_btree_nodehead *node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | } |