Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of UBIFS. |
| 3 | * |
| 4 | * Copyright (C) 2006-2008 Nokia Corporation |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published by |
| 8 | * the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along with |
| 16 | * this program; if not, write to the Free Software Foundation, Inc., 51 |
| 17 | * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | * |
| 19 | * Authors: Artem Bityutskiy (Битюцкий Артём) |
| 20 | * Adrian Hunter |
| 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * This file implements most of the debugging stuff which is compiled in only |
| 25 | * when it is enabled. But some debugging check functions are implemented in |
| 26 | * corresponding subsystem, just because they are closely related and utilize |
| 27 | * various local functions of those subsystems. |
| 28 | */ |
| 29 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 30 | #include <linux/module.h> |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 31 | #include <linux/debugfs.h> |
Artem Bityutskiy | 4d61db4 | 2008-12-18 14:06:51 +0200 | [diff] [blame] | 32 | #include <linux/math64.h> |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 33 | #include <linux/uaccess.h> |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 34 | #include <linux/random.h> |
| 35 | #include "ubifs.h" |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 36 | |
| 37 | #ifdef CONFIG_UBIFS_FS_DEBUG |
| 38 | |
Artem Bityutskiy | b06283c | 2012-01-18 16:06:17 +0200 | [diff] [blame] | 39 | static DEFINE_SPINLOCK(dbg_lock); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 40 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 41 | static const char *get_key_fmt(int fmt) |
| 42 | { |
| 43 | switch (fmt) { |
| 44 | case UBIFS_SIMPLE_KEY_FMT: |
| 45 | return "simple"; |
| 46 | default: |
| 47 | return "unknown/invalid format"; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | static const char *get_key_hash(int hash) |
| 52 | { |
| 53 | switch (hash) { |
| 54 | case UBIFS_KEY_HASH_R5: |
| 55 | return "R5"; |
| 56 | case UBIFS_KEY_HASH_TEST: |
| 57 | return "test"; |
| 58 | default: |
| 59 | return "unknown/invalid name hash"; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | static const char *get_key_type(int type) |
| 64 | { |
| 65 | switch (type) { |
| 66 | case UBIFS_INO_KEY: |
| 67 | return "inode"; |
| 68 | case UBIFS_DENT_KEY: |
| 69 | return "direntry"; |
| 70 | case UBIFS_XENT_KEY: |
| 71 | return "xentry"; |
| 72 | case UBIFS_DATA_KEY: |
| 73 | return "data"; |
| 74 | case UBIFS_TRUN_KEY: |
| 75 | return "truncate"; |
| 76 | default: |
| 77 | return "unknown/invalid key"; |
| 78 | } |
| 79 | } |
| 80 | |
Artem Bityutskiy | 4315fb4 | 2011-05-25 17:32:42 +0300 | [diff] [blame] | 81 | static const char *get_dent_type(int type) |
| 82 | { |
| 83 | switch (type) { |
| 84 | case UBIFS_ITYPE_REG: |
| 85 | return "file"; |
| 86 | case UBIFS_ITYPE_DIR: |
| 87 | return "dir"; |
| 88 | case UBIFS_ITYPE_LNK: |
| 89 | return "symlink"; |
| 90 | case UBIFS_ITYPE_BLK: |
| 91 | return "blkdev"; |
| 92 | case UBIFS_ITYPE_CHR: |
| 93 | return "char dev"; |
| 94 | case UBIFS_ITYPE_FIFO: |
| 95 | return "fifo"; |
| 96 | case UBIFS_ITYPE_SOCK: |
| 97 | return "socket"; |
| 98 | default: |
| 99 | return "unknown/invalid type"; |
| 100 | } |
| 101 | } |
| 102 | |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 103 | const char *dbg_snprintf_key(const struct ubifs_info *c, |
| 104 | const union ubifs_key *key, char *buffer, int len) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 105 | { |
| 106 | char *p = buffer; |
| 107 | int type = key_type(c, key); |
| 108 | |
| 109 | if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) { |
| 110 | switch (type) { |
| 111 | case UBIFS_INO_KEY: |
Artem Bityutskiy | beba006 | 2012-01-11 15:52:09 +0200 | [diff] [blame] | 112 | len -= snprintf(p, len, "(%lu, %s)", |
| 113 | (unsigned long)key_inum(c, key), |
| 114 | get_key_type(type)); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 115 | break; |
| 116 | case UBIFS_DENT_KEY: |
| 117 | case UBIFS_XENT_KEY: |
Artem Bityutskiy | beba006 | 2012-01-11 15:52:09 +0200 | [diff] [blame] | 118 | len -= snprintf(p, len, "(%lu, %s, %#08x)", |
| 119 | (unsigned long)key_inum(c, key), |
| 120 | get_key_type(type), key_hash(c, key)); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 121 | break; |
| 122 | case UBIFS_DATA_KEY: |
Artem Bityutskiy | beba006 | 2012-01-11 15:52:09 +0200 | [diff] [blame] | 123 | len -= snprintf(p, len, "(%lu, %s, %u)", |
| 124 | (unsigned long)key_inum(c, key), |
| 125 | get_key_type(type), key_block(c, key)); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 126 | break; |
| 127 | case UBIFS_TRUN_KEY: |
Artem Bityutskiy | beba006 | 2012-01-11 15:52:09 +0200 | [diff] [blame] | 128 | len -= snprintf(p, len, "(%lu, %s)", |
| 129 | (unsigned long)key_inum(c, key), |
| 130 | get_key_type(type)); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 131 | break; |
| 132 | default: |
Artem Bityutskiy | beba006 | 2012-01-11 15:52:09 +0200 | [diff] [blame] | 133 | len -= snprintf(p, len, "(bad key type: %#08x, %#08x)", |
| 134 | key->u32[0], key->u32[1]); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 135 | } |
| 136 | } else |
Artem Bityutskiy | beba006 | 2012-01-11 15:52:09 +0200 | [diff] [blame] | 137 | len -= snprintf(p, len, "bad key format %d", c->key_fmt); |
| 138 | ubifs_assert(len > 0); |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 139 | return p; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | const char *dbg_ntype(int type) |
| 143 | { |
| 144 | switch (type) { |
| 145 | case UBIFS_PAD_NODE: |
| 146 | return "padding node"; |
| 147 | case UBIFS_SB_NODE: |
| 148 | return "superblock node"; |
| 149 | case UBIFS_MST_NODE: |
| 150 | return "master node"; |
| 151 | case UBIFS_REF_NODE: |
| 152 | return "reference node"; |
| 153 | case UBIFS_INO_NODE: |
| 154 | return "inode node"; |
| 155 | case UBIFS_DENT_NODE: |
| 156 | return "direntry node"; |
| 157 | case UBIFS_XENT_NODE: |
| 158 | return "xentry node"; |
| 159 | case UBIFS_DATA_NODE: |
| 160 | return "data node"; |
| 161 | case UBIFS_TRUN_NODE: |
| 162 | return "truncate node"; |
| 163 | case UBIFS_IDX_NODE: |
| 164 | return "indexing node"; |
| 165 | case UBIFS_CS_NODE: |
| 166 | return "commit start node"; |
| 167 | case UBIFS_ORPH_NODE: |
| 168 | return "orphan node"; |
| 169 | default: |
| 170 | return "unknown node"; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | static const char *dbg_gtype(int type) |
| 175 | { |
| 176 | switch (type) { |
| 177 | case UBIFS_NO_NODE_GROUP: |
| 178 | return "no node group"; |
| 179 | case UBIFS_IN_NODE_GROUP: |
| 180 | return "in node group"; |
| 181 | case UBIFS_LAST_OF_NODE_GROUP: |
| 182 | return "last of node group"; |
| 183 | default: |
| 184 | return "unknown"; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | const char *dbg_cstate(int cmt_state) |
| 189 | { |
| 190 | switch (cmt_state) { |
| 191 | case COMMIT_RESTING: |
| 192 | return "commit resting"; |
| 193 | case COMMIT_BACKGROUND: |
| 194 | return "background commit requested"; |
| 195 | case COMMIT_REQUIRED: |
| 196 | return "commit required"; |
| 197 | case COMMIT_RUNNING_BACKGROUND: |
| 198 | return "BACKGROUND commit running"; |
| 199 | case COMMIT_RUNNING_REQUIRED: |
| 200 | return "commit running and required"; |
| 201 | case COMMIT_BROKEN: |
| 202 | return "broken commit"; |
| 203 | default: |
| 204 | return "unknown commit state"; |
| 205 | } |
| 206 | } |
| 207 | |
Artem Bityutskiy | 77a7ae5 | 2009-09-15 15:03:51 +0300 | [diff] [blame] | 208 | const char *dbg_jhead(int jhead) |
| 209 | { |
| 210 | switch (jhead) { |
| 211 | case GCHD: |
| 212 | return "0 (GC)"; |
| 213 | case BASEHD: |
| 214 | return "1 (base)"; |
| 215 | case DATAHD: |
| 216 | return "2 (data)"; |
| 217 | default: |
| 218 | return "unknown journal head"; |
| 219 | } |
| 220 | } |
| 221 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 222 | static void dump_ch(const struct ubifs_ch *ch) |
| 223 | { |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 224 | printk(KERN_ERR "\tmagic %#x\n", le32_to_cpu(ch->magic)); |
| 225 | printk(KERN_ERR "\tcrc %#x\n", le32_to_cpu(ch->crc)); |
| 226 | printk(KERN_ERR "\tnode_type %d (%s)\n", ch->node_type, |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 227 | dbg_ntype(ch->node_type)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 228 | printk(KERN_ERR "\tgroup_type %d (%s)\n", ch->group_type, |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 229 | dbg_gtype(ch->group_type)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 230 | printk(KERN_ERR "\tsqnum %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 231 | (unsigned long long)le64_to_cpu(ch->sqnum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 232 | printk(KERN_ERR "\tlen %u\n", le32_to_cpu(ch->len)); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 233 | } |
| 234 | |
Artem Bityutskiy | 4315fb4 | 2011-05-25 17:32:42 +0300 | [diff] [blame] | 235 | void dbg_dump_inode(struct ubifs_info *c, const struct inode *inode) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 236 | { |
| 237 | const struct ubifs_inode *ui = ubifs_inode(inode); |
Artem Bityutskiy | 4315fb4 | 2011-05-25 17:32:42 +0300 | [diff] [blame] | 238 | struct qstr nm = { .name = NULL }; |
| 239 | union ubifs_key key; |
| 240 | struct ubifs_dent_node *dent, *pdent = NULL; |
| 241 | int count = 2; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 242 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 243 | printk(KERN_ERR "Dump in-memory inode:"); |
| 244 | printk(KERN_ERR "\tinode %lu\n", inode->i_ino); |
| 245 | printk(KERN_ERR "\tsize %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 246 | (unsigned long long)i_size_read(inode)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 247 | printk(KERN_ERR "\tnlink %u\n", inode->i_nlink); |
| 248 | printk(KERN_ERR "\tuid %u\n", (unsigned int)inode->i_uid); |
| 249 | printk(KERN_ERR "\tgid %u\n", (unsigned int)inode->i_gid); |
| 250 | printk(KERN_ERR "\tatime %u.%u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 251 | (unsigned int)inode->i_atime.tv_sec, |
| 252 | (unsigned int)inode->i_atime.tv_nsec); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 253 | printk(KERN_ERR "\tmtime %u.%u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 254 | (unsigned int)inode->i_mtime.tv_sec, |
| 255 | (unsigned int)inode->i_mtime.tv_nsec); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 256 | printk(KERN_ERR "\tctime %u.%u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 257 | (unsigned int)inode->i_ctime.tv_sec, |
| 258 | (unsigned int)inode->i_ctime.tv_nsec); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 259 | printk(KERN_ERR "\tcreat_sqnum %llu\n", ui->creat_sqnum); |
| 260 | printk(KERN_ERR "\txattr_size %u\n", ui->xattr_size); |
| 261 | printk(KERN_ERR "\txattr_cnt %u\n", ui->xattr_cnt); |
| 262 | printk(KERN_ERR "\txattr_names %u\n", ui->xattr_names); |
| 263 | printk(KERN_ERR "\tdirty %u\n", ui->dirty); |
| 264 | printk(KERN_ERR "\txattr %u\n", ui->xattr); |
| 265 | printk(KERN_ERR "\tbulk_read %u\n", ui->xattr); |
| 266 | printk(KERN_ERR "\tsynced_i_size %llu\n", |
Artem Bityutskiy | b5e426e | 2008-09-09 11:20:35 +0300 | [diff] [blame] | 267 | (unsigned long long)ui->synced_i_size); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 268 | printk(KERN_ERR "\tui_size %llu\n", |
Artem Bityutskiy | b5e426e | 2008-09-09 11:20:35 +0300 | [diff] [blame] | 269 | (unsigned long long)ui->ui_size); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 270 | printk(KERN_ERR "\tflags %d\n", ui->flags); |
| 271 | printk(KERN_ERR "\tcompr_type %d\n", ui->compr_type); |
| 272 | printk(KERN_ERR "\tlast_page_read %lu\n", ui->last_page_read); |
| 273 | printk(KERN_ERR "\tread_in_a_row %lu\n", ui->read_in_a_row); |
| 274 | printk(KERN_ERR "\tdata_len %d\n", ui->data_len); |
Artem Bityutskiy | 4315fb4 | 2011-05-25 17:32:42 +0300 | [diff] [blame] | 275 | |
| 276 | if (!S_ISDIR(inode->i_mode)) |
| 277 | return; |
| 278 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 279 | printk(KERN_ERR "List of directory entries:\n"); |
Artem Bityutskiy | 4315fb4 | 2011-05-25 17:32:42 +0300 | [diff] [blame] | 280 | ubifs_assert(!mutex_is_locked(&c->tnc_mutex)); |
| 281 | |
| 282 | lowest_dent_key(c, &key, inode->i_ino); |
| 283 | while (1) { |
| 284 | dent = ubifs_tnc_next_ent(c, &key, &nm); |
| 285 | if (IS_ERR(dent)) { |
| 286 | if (PTR_ERR(dent) != -ENOENT) |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 287 | printk(KERN_ERR "error %ld\n", PTR_ERR(dent)); |
Artem Bityutskiy | 4315fb4 | 2011-05-25 17:32:42 +0300 | [diff] [blame] | 288 | break; |
| 289 | } |
| 290 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 291 | printk(KERN_ERR "\t%d: %s (%s)\n", |
Artem Bityutskiy | 4315fb4 | 2011-05-25 17:32:42 +0300 | [diff] [blame] | 292 | count++, dent->name, get_dent_type(dent->type)); |
| 293 | |
| 294 | nm.name = dent->name; |
| 295 | nm.len = le16_to_cpu(dent->nlen); |
| 296 | kfree(pdent); |
| 297 | pdent = dent; |
| 298 | key_read(c, &dent->key, &key); |
| 299 | } |
| 300 | kfree(pdent); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | void dbg_dump_node(const struct ubifs_info *c, const void *node) |
| 304 | { |
| 305 | int i, n; |
| 306 | union ubifs_key key; |
| 307 | const struct ubifs_ch *ch = node; |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 308 | char key_buf[DBG_KEY_BUF_LEN]; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 309 | |
Artem Bityutskiy | 2b1844a | 2011-06-03 08:31:29 +0300 | [diff] [blame] | 310 | if (dbg_is_tst_rcvry(c)) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 311 | return; |
| 312 | |
| 313 | /* If the magic is incorrect, just hexdump the first bytes */ |
| 314 | if (le32_to_cpu(ch->magic) != UBIFS_NODE_MAGIC) { |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 315 | printk(KERN_ERR "Not a node, first %zu bytes:", UBIFS_CH_SZ); |
| 316 | print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 32, 1, |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 317 | (void *)node, UBIFS_CH_SZ, 1); |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | spin_lock(&dbg_lock); |
| 322 | dump_ch(node); |
| 323 | |
| 324 | switch (ch->node_type) { |
| 325 | case UBIFS_PAD_NODE: |
| 326 | { |
| 327 | const struct ubifs_pad_node *pad = node; |
| 328 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 329 | printk(KERN_ERR "\tpad_len %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 330 | le32_to_cpu(pad->pad_len)); |
| 331 | break; |
| 332 | } |
| 333 | case UBIFS_SB_NODE: |
| 334 | { |
| 335 | const struct ubifs_sb_node *sup = node; |
| 336 | unsigned int sup_flags = le32_to_cpu(sup->flags); |
| 337 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 338 | printk(KERN_ERR "\tkey_hash %d (%s)\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 339 | (int)sup->key_hash, get_key_hash(sup->key_hash)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 340 | printk(KERN_ERR "\tkey_fmt %d (%s)\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 341 | (int)sup->key_fmt, get_key_fmt(sup->key_fmt)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 342 | printk(KERN_ERR "\tflags %#x\n", sup_flags); |
| 343 | printk(KERN_ERR "\t big_lpt %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 344 | !!(sup_flags & UBIFS_FLG_BIGLPT)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 345 | printk(KERN_ERR "\t space_fixup %u\n", |
Matthew L. Creech | 9f58d35 | 2011-05-05 16:33:20 -0400 | [diff] [blame] | 346 | !!(sup_flags & UBIFS_FLG_SPACE_FIXUP)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 347 | printk(KERN_ERR "\tmin_io_size %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 348 | le32_to_cpu(sup->min_io_size)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 349 | printk(KERN_ERR "\tleb_size %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 350 | le32_to_cpu(sup->leb_size)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 351 | printk(KERN_ERR "\tleb_cnt %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 352 | le32_to_cpu(sup->leb_cnt)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 353 | printk(KERN_ERR "\tmax_leb_cnt %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 354 | le32_to_cpu(sup->max_leb_cnt)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 355 | printk(KERN_ERR "\tmax_bud_bytes %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 356 | (unsigned long long)le64_to_cpu(sup->max_bud_bytes)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 357 | printk(KERN_ERR "\tlog_lebs %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 358 | le32_to_cpu(sup->log_lebs)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 359 | printk(KERN_ERR "\tlpt_lebs %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 360 | le32_to_cpu(sup->lpt_lebs)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 361 | printk(KERN_ERR "\torph_lebs %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 362 | le32_to_cpu(sup->orph_lebs)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 363 | printk(KERN_ERR "\tjhead_cnt %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 364 | le32_to_cpu(sup->jhead_cnt)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 365 | printk(KERN_ERR "\tfanout %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 366 | le32_to_cpu(sup->fanout)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 367 | printk(KERN_ERR "\tlsave_cnt %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 368 | le32_to_cpu(sup->lsave_cnt)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 369 | printk(KERN_ERR "\tdefault_compr %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 370 | (int)le16_to_cpu(sup->default_compr)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 371 | printk(KERN_ERR "\trp_size %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 372 | (unsigned long long)le64_to_cpu(sup->rp_size)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 373 | printk(KERN_ERR "\trp_uid %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 374 | le32_to_cpu(sup->rp_uid)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 375 | printk(KERN_ERR "\trp_gid %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 376 | le32_to_cpu(sup->rp_gid)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 377 | printk(KERN_ERR "\tfmt_version %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 378 | le32_to_cpu(sup->fmt_version)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 379 | printk(KERN_ERR "\ttime_gran %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 380 | le32_to_cpu(sup->time_gran)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 381 | printk(KERN_ERR "\tUUID %pUB\n", |
Joe Perches | 7f2f4e7 | 2009-12-14 18:01:13 -0800 | [diff] [blame] | 382 | sup->uuid); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 383 | break; |
| 384 | } |
| 385 | case UBIFS_MST_NODE: |
| 386 | { |
| 387 | const struct ubifs_mst_node *mst = node; |
| 388 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 389 | printk(KERN_ERR "\thighest_inum %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 390 | (unsigned long long)le64_to_cpu(mst->highest_inum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 391 | printk(KERN_ERR "\tcommit number %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 392 | (unsigned long long)le64_to_cpu(mst->cmt_no)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 393 | printk(KERN_ERR "\tflags %#x\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 394 | le32_to_cpu(mst->flags)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 395 | printk(KERN_ERR "\tlog_lnum %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 396 | le32_to_cpu(mst->log_lnum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 397 | printk(KERN_ERR "\troot_lnum %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 398 | le32_to_cpu(mst->root_lnum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 399 | printk(KERN_ERR "\troot_offs %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 400 | le32_to_cpu(mst->root_offs)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 401 | printk(KERN_ERR "\troot_len %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 402 | le32_to_cpu(mst->root_len)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 403 | printk(KERN_ERR "\tgc_lnum %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 404 | le32_to_cpu(mst->gc_lnum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 405 | printk(KERN_ERR "\tihead_lnum %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 406 | le32_to_cpu(mst->ihead_lnum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 407 | printk(KERN_ERR "\tihead_offs %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 408 | le32_to_cpu(mst->ihead_offs)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 409 | printk(KERN_ERR "\tindex_size %llu\n", |
Harvey Harrison | 0ecb952 | 2008-10-24 10:52:57 -0700 | [diff] [blame] | 410 | (unsigned long long)le64_to_cpu(mst->index_size)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 411 | printk(KERN_ERR "\tlpt_lnum %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 412 | le32_to_cpu(mst->lpt_lnum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 413 | printk(KERN_ERR "\tlpt_offs %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 414 | le32_to_cpu(mst->lpt_offs)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 415 | printk(KERN_ERR "\tnhead_lnum %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 416 | le32_to_cpu(mst->nhead_lnum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 417 | printk(KERN_ERR "\tnhead_offs %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 418 | le32_to_cpu(mst->nhead_offs)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 419 | printk(KERN_ERR "\tltab_lnum %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 420 | le32_to_cpu(mst->ltab_lnum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 421 | printk(KERN_ERR "\tltab_offs %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 422 | le32_to_cpu(mst->ltab_offs)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 423 | printk(KERN_ERR "\tlsave_lnum %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 424 | le32_to_cpu(mst->lsave_lnum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 425 | printk(KERN_ERR "\tlsave_offs %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 426 | le32_to_cpu(mst->lsave_offs)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 427 | printk(KERN_ERR "\tlscan_lnum %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 428 | le32_to_cpu(mst->lscan_lnum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 429 | printk(KERN_ERR "\tleb_cnt %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 430 | le32_to_cpu(mst->leb_cnt)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 431 | printk(KERN_ERR "\tempty_lebs %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 432 | le32_to_cpu(mst->empty_lebs)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 433 | printk(KERN_ERR "\tidx_lebs %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 434 | le32_to_cpu(mst->idx_lebs)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 435 | printk(KERN_ERR "\ttotal_free %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 436 | (unsigned long long)le64_to_cpu(mst->total_free)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 437 | printk(KERN_ERR "\ttotal_dirty %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 438 | (unsigned long long)le64_to_cpu(mst->total_dirty)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 439 | printk(KERN_ERR "\ttotal_used %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 440 | (unsigned long long)le64_to_cpu(mst->total_used)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 441 | printk(KERN_ERR "\ttotal_dead %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 442 | (unsigned long long)le64_to_cpu(mst->total_dead)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 443 | printk(KERN_ERR "\ttotal_dark %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 444 | (unsigned long long)le64_to_cpu(mst->total_dark)); |
| 445 | break; |
| 446 | } |
| 447 | case UBIFS_REF_NODE: |
| 448 | { |
| 449 | const struct ubifs_ref_node *ref = node; |
| 450 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 451 | printk(KERN_ERR "\tlnum %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 452 | le32_to_cpu(ref->lnum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 453 | printk(KERN_ERR "\toffs %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 454 | le32_to_cpu(ref->offs)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 455 | printk(KERN_ERR "\tjhead %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 456 | le32_to_cpu(ref->jhead)); |
| 457 | break; |
| 458 | } |
| 459 | case UBIFS_INO_NODE: |
| 460 | { |
| 461 | const struct ubifs_ino_node *ino = node; |
| 462 | |
| 463 | key_read(c, &ino->key, &key); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 464 | printk(KERN_ERR "\tkey %s\n", |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 465 | dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 466 | printk(KERN_ERR "\tcreat_sqnum %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 467 | (unsigned long long)le64_to_cpu(ino->creat_sqnum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 468 | printk(KERN_ERR "\tsize %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 469 | (unsigned long long)le64_to_cpu(ino->size)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 470 | printk(KERN_ERR "\tnlink %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 471 | le32_to_cpu(ino->nlink)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 472 | printk(KERN_ERR "\tatime %lld.%u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 473 | (long long)le64_to_cpu(ino->atime_sec), |
| 474 | le32_to_cpu(ino->atime_nsec)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 475 | printk(KERN_ERR "\tmtime %lld.%u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 476 | (long long)le64_to_cpu(ino->mtime_sec), |
| 477 | le32_to_cpu(ino->mtime_nsec)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 478 | printk(KERN_ERR "\tctime %lld.%u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 479 | (long long)le64_to_cpu(ino->ctime_sec), |
| 480 | le32_to_cpu(ino->ctime_nsec)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 481 | printk(KERN_ERR "\tuid %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 482 | le32_to_cpu(ino->uid)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 483 | printk(KERN_ERR "\tgid %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 484 | le32_to_cpu(ino->gid)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 485 | printk(KERN_ERR "\tmode %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 486 | le32_to_cpu(ino->mode)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 487 | printk(KERN_ERR "\tflags %#x\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 488 | le32_to_cpu(ino->flags)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 489 | printk(KERN_ERR "\txattr_cnt %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 490 | le32_to_cpu(ino->xattr_cnt)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 491 | printk(KERN_ERR "\txattr_size %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 492 | le32_to_cpu(ino->xattr_size)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 493 | printk(KERN_ERR "\txattr_names %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 494 | le32_to_cpu(ino->xattr_names)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 495 | printk(KERN_ERR "\tcompr_type %#x\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 496 | (int)le16_to_cpu(ino->compr_type)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 497 | printk(KERN_ERR "\tdata len %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 498 | le32_to_cpu(ino->data_len)); |
| 499 | break; |
| 500 | } |
| 501 | case UBIFS_DENT_NODE: |
| 502 | case UBIFS_XENT_NODE: |
| 503 | { |
| 504 | const struct ubifs_dent_node *dent = node; |
| 505 | int nlen = le16_to_cpu(dent->nlen); |
| 506 | |
| 507 | key_read(c, &dent->key, &key); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 508 | printk(KERN_ERR "\tkey %s\n", |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 509 | dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 510 | printk(KERN_ERR "\tinum %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 511 | (unsigned long long)le64_to_cpu(dent->inum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 512 | printk(KERN_ERR "\ttype %d\n", (int)dent->type); |
| 513 | printk(KERN_ERR "\tnlen %d\n", nlen); |
| 514 | printk(KERN_ERR "\tname "); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 515 | |
| 516 | if (nlen > UBIFS_MAX_NLEN) |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 517 | printk(KERN_ERR "(bad name length, not printing, " |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 518 | "bad or corrupted node)"); |
| 519 | else { |
| 520 | for (i = 0; i < nlen && dent->name[i]; i++) |
Artem Bityutskiy | c9927c3 | 2009-03-16 09:42:03 +0200 | [diff] [blame] | 521 | printk(KERN_CONT "%c", dent->name[i]); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 522 | } |
Artem Bityutskiy | c9927c3 | 2009-03-16 09:42:03 +0200 | [diff] [blame] | 523 | printk(KERN_CONT "\n"); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 524 | |
| 525 | break; |
| 526 | } |
| 527 | case UBIFS_DATA_NODE: |
| 528 | { |
| 529 | const struct ubifs_data_node *dn = node; |
| 530 | int dlen = le32_to_cpu(ch->len) - UBIFS_DATA_NODE_SZ; |
| 531 | |
| 532 | key_read(c, &dn->key, &key); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 533 | printk(KERN_ERR "\tkey %s\n", |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 534 | dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 535 | printk(KERN_ERR "\tsize %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 536 | le32_to_cpu(dn->size)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 537 | printk(KERN_ERR "\tcompr_typ %d\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 538 | (int)le16_to_cpu(dn->compr_type)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 539 | printk(KERN_ERR "\tdata size %d\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 540 | dlen); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 541 | printk(KERN_ERR "\tdata:\n"); |
| 542 | print_hex_dump(KERN_ERR, "\t", DUMP_PREFIX_OFFSET, 32, 1, |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 543 | (void *)&dn->data, dlen, 0); |
| 544 | break; |
| 545 | } |
| 546 | case UBIFS_TRUN_NODE: |
| 547 | { |
| 548 | const struct ubifs_trun_node *trun = node; |
| 549 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 550 | printk(KERN_ERR "\tinum %u\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 551 | le32_to_cpu(trun->inum)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 552 | printk(KERN_ERR "\told_size %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 553 | (unsigned long long)le64_to_cpu(trun->old_size)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 554 | printk(KERN_ERR "\tnew_size %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 555 | (unsigned long long)le64_to_cpu(trun->new_size)); |
| 556 | break; |
| 557 | } |
| 558 | case UBIFS_IDX_NODE: |
| 559 | { |
| 560 | const struct ubifs_idx_node *idx = node; |
| 561 | |
| 562 | n = le16_to_cpu(idx->child_cnt); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 563 | printk(KERN_ERR "\tchild_cnt %d\n", n); |
| 564 | printk(KERN_ERR "\tlevel %d\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 565 | (int)le16_to_cpu(idx->level)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 566 | printk(KERN_ERR "\tBranches:\n"); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 567 | |
| 568 | for (i = 0; i < n && i < c->fanout - 1; i++) { |
| 569 | const struct ubifs_branch *br; |
| 570 | |
| 571 | br = ubifs_idx_branch(c, idx, i); |
| 572 | key_read(c, &br->key, &key); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 573 | printk(KERN_ERR "\t%d: LEB %d:%d len %d key %s\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 574 | i, le32_to_cpu(br->lnum), le32_to_cpu(br->offs), |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 575 | le32_to_cpu(br->len), |
| 576 | dbg_snprintf_key(c, &key, key_buf, |
| 577 | DBG_KEY_BUF_LEN)); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 578 | } |
| 579 | break; |
| 580 | } |
| 581 | case UBIFS_CS_NODE: |
| 582 | break; |
| 583 | case UBIFS_ORPH_NODE: |
| 584 | { |
| 585 | const struct ubifs_orph_node *orph = node; |
| 586 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 587 | printk(KERN_ERR "\tcommit number %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 588 | (unsigned long long) |
| 589 | le64_to_cpu(orph->cmt_no) & LLONG_MAX); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 590 | printk(KERN_ERR "\tlast node flag %llu\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 591 | (unsigned long long)(le64_to_cpu(orph->cmt_no)) >> 63); |
| 592 | n = (le32_to_cpu(ch->len) - UBIFS_ORPH_NODE_SZ) >> 3; |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 593 | printk(KERN_ERR "\t%d orphan inode numbers:\n", n); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 594 | for (i = 0; i < n; i++) |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 595 | printk(KERN_ERR "\t ino %llu\n", |
Alexander Beregalov | 7424bac | 2008-09-17 22:09:41 +0400 | [diff] [blame] | 596 | (unsigned long long)le64_to_cpu(orph->inos[i])); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 597 | break; |
| 598 | } |
| 599 | default: |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 600 | printk(KERN_ERR "node type %d was not recognized\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 601 | (int)ch->node_type); |
| 602 | } |
| 603 | spin_unlock(&dbg_lock); |
| 604 | } |
| 605 | |
| 606 | void dbg_dump_budget_req(const struct ubifs_budget_req *req) |
| 607 | { |
| 608 | spin_lock(&dbg_lock); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 609 | printk(KERN_ERR "Budgeting request: new_ino %d, dirtied_ino %d\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 610 | req->new_ino, req->dirtied_ino); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 611 | printk(KERN_ERR "\tnew_ino_d %d, dirtied_ino_d %d\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 612 | req->new_ino_d, req->dirtied_ino_d); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 613 | printk(KERN_ERR "\tnew_page %d, dirtied_page %d\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 614 | req->new_page, req->dirtied_page); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 615 | printk(KERN_ERR "\tnew_dent %d, mod_dent %d\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 616 | req->new_dent, req->mod_dent); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 617 | printk(KERN_ERR "\tidx_growth %d\n", req->idx_growth); |
| 618 | printk(KERN_ERR "\tdata_growth %d dd_growth %d\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 619 | req->data_growth, req->dd_growth); |
| 620 | spin_unlock(&dbg_lock); |
| 621 | } |
| 622 | |
| 623 | void dbg_dump_lstats(const struct ubifs_lp_stats *lst) |
| 624 | { |
| 625 | spin_lock(&dbg_lock); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 626 | printk(KERN_ERR "(pid %d) Lprops statistics: empty_lebs %d, " |
Artem Bityutskiy | 1de9415 | 2008-07-25 12:58:38 +0300 | [diff] [blame] | 627 | "idx_lebs %d\n", current->pid, lst->empty_lebs, lst->idx_lebs); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 628 | printk(KERN_ERR "\ttaken_empty_lebs %d, total_free %lld, " |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 629 | "total_dirty %lld\n", lst->taken_empty_lebs, lst->total_free, |
| 630 | lst->total_dirty); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 631 | printk(KERN_ERR "\ttotal_used %lld, total_dark %lld, " |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 632 | "total_dead %lld\n", lst->total_used, lst->total_dark, |
| 633 | lst->total_dead); |
| 634 | spin_unlock(&dbg_lock); |
| 635 | } |
| 636 | |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 637 | void dbg_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 638 | { |
| 639 | int i; |
| 640 | struct rb_node *rb; |
| 641 | struct ubifs_bud *bud; |
| 642 | struct ubifs_gced_idx_leb *idx_gc; |
Artem Bityutskiy | 21a6025 | 2008-12-12 11:13:17 -0500 | [diff] [blame] | 643 | long long available, outstanding, free; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 644 | |
Artem Bityutskiy | 8ff8308 | 2011-03-29 18:19:50 +0300 | [diff] [blame] | 645 | spin_lock(&c->space_lock); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 646 | spin_lock(&dbg_lock); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 647 | printk(KERN_ERR "(pid %d) Budgeting info: data budget sum %lld, " |
Artem Bityutskiy | 8c3067e | 2011-03-30 13:18:58 +0300 | [diff] [blame] | 648 | "total budget sum %lld\n", current->pid, |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 649 | bi->data_growth + bi->dd_growth, |
| 650 | bi->data_growth + bi->dd_growth + bi->idx_growth); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 651 | printk(KERN_ERR "\tbudg_data_growth %lld, budg_dd_growth %lld, " |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 652 | "budg_idx_growth %lld\n", bi->data_growth, bi->dd_growth, |
| 653 | bi->idx_growth); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 654 | printk(KERN_ERR "\tmin_idx_lebs %d, old_idx_sz %llu, " |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 655 | "uncommitted_idx %lld\n", bi->min_idx_lebs, bi->old_idx_sz, |
| 656 | bi->uncommitted_idx); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 657 | printk(KERN_ERR "\tpage_budget %d, inode_budget %d, dent_budget %d\n", |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 658 | bi->page_budget, bi->inode_budget, bi->dent_budget); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 659 | printk(KERN_ERR "\tnospace %u, nospace_rp %u\n", |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 660 | bi->nospace, bi->nospace_rp); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 661 | printk(KERN_ERR "\tdark_wm %d, dead_wm %d, max_idx_node_sz %d\n", |
Artem Bityutskiy | 8c3067e | 2011-03-30 13:18:58 +0300 | [diff] [blame] | 662 | c->dark_wm, c->dead_wm, c->max_idx_node_sz); |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 663 | |
| 664 | if (bi != &c->bi) |
| 665 | /* |
| 666 | * If we are dumping saved budgeting data, do not print |
| 667 | * additional information which is about the current state, not |
| 668 | * the old one which corresponded to the saved budgeting data. |
| 669 | */ |
| 670 | goto out_unlock; |
| 671 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 672 | printk(KERN_ERR "\tfreeable_cnt %d, calc_idx_sz %lld, idx_gc_cnt %d\n", |
Artem Bityutskiy | 8c3067e | 2011-03-30 13:18:58 +0300 | [diff] [blame] | 673 | c->freeable_cnt, c->calc_idx_sz, c->idx_gc_cnt); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 674 | printk(KERN_ERR "\tdirty_pg_cnt %ld, dirty_zn_cnt %ld, " |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 675 | "clean_zn_cnt %ld\n", atomic_long_read(&c->dirty_pg_cnt), |
| 676 | atomic_long_read(&c->dirty_zn_cnt), |
| 677 | atomic_long_read(&c->clean_zn_cnt)); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 678 | printk(KERN_ERR "\tgc_lnum %d, ihead_lnum %d\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 679 | c->gc_lnum, c->ihead_lnum); |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 680 | |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 681 | /* If we are in R/O mode, journal heads do not exist */ |
| 682 | if (c->jheads) |
| 683 | for (i = 0; i < c->jhead_cnt; i++) |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 684 | printk(KERN_ERR "\tjhead %s\t LEB %d\n", |
Artem Bityutskiy | 77a7ae5 | 2009-09-15 15:03:51 +0300 | [diff] [blame] | 685 | dbg_jhead(c->jheads[i].wbuf.jhead), |
| 686 | c->jheads[i].wbuf.lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 687 | for (rb = rb_first(&c->buds); rb; rb = rb_next(rb)) { |
| 688 | bud = rb_entry(rb, struct ubifs_bud, rb); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 689 | printk(KERN_ERR "\tbud LEB %d\n", bud->lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 690 | } |
| 691 | list_for_each_entry(bud, &c->old_buds, list) |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 692 | printk(KERN_ERR "\told bud LEB %d\n", bud->lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 693 | list_for_each_entry(idx_gc, &c->idx_gc, list) |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 694 | printk(KERN_ERR "\tGC'ed idx LEB %d unmap %d\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 695 | idx_gc->lnum, idx_gc->unmap); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 696 | printk(KERN_ERR "\tcommit state %d\n", c->cmt_state); |
Artem Bityutskiy | 21a6025 | 2008-12-12 11:13:17 -0500 | [diff] [blame] | 697 | |
| 698 | /* Print budgeting predictions */ |
Artem Bityutskiy | b137545 | 2011-03-29 18:04:05 +0300 | [diff] [blame] | 699 | available = ubifs_calc_available(c, c->bi.min_idx_lebs); |
| 700 | outstanding = c->bi.data_growth + c->bi.dd_growth; |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 701 | free = ubifs_get_free_space_nolock(c); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 702 | printk(KERN_ERR "Budgeting predictions:\n"); |
| 703 | printk(KERN_ERR "\tavailable: %lld, outstanding %lld, free %lld\n", |
Artem Bityutskiy | 21a6025 | 2008-12-12 11:13:17 -0500 | [diff] [blame] | 704 | available, outstanding, free); |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 705 | out_unlock: |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 706 | spin_unlock(&dbg_lock); |
Artem Bityutskiy | 8ff8308 | 2011-03-29 18:19:50 +0300 | [diff] [blame] | 707 | spin_unlock(&c->space_lock); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp) |
| 711 | { |
Artem Bityutskiy | be9e62a | 2008-12-28 10:17:23 +0200 | [diff] [blame] | 712 | int i, spc, dark = 0, dead = 0; |
| 713 | struct rb_node *rb; |
| 714 | struct ubifs_bud *bud; |
| 715 | |
| 716 | spc = lp->free + lp->dirty; |
| 717 | if (spc < c->dead_wm) |
| 718 | dead = spc; |
| 719 | else |
| 720 | dark = ubifs_calc_dark(c, spc); |
| 721 | |
| 722 | if (lp->flags & LPROPS_INDEX) |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 723 | printk(KERN_ERR "LEB %-7d free %-8d dirty %-8d used %-8d " |
Artem Bityutskiy | be9e62a | 2008-12-28 10:17:23 +0200 | [diff] [blame] | 724 | "free + dirty %-8d flags %#x (", lp->lnum, lp->free, |
| 725 | lp->dirty, c->leb_size - spc, spc, lp->flags); |
| 726 | else |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 727 | printk(KERN_ERR "LEB %-7d free %-8d dirty %-8d used %-8d " |
Artem Bityutskiy | be9e62a | 2008-12-28 10:17:23 +0200 | [diff] [blame] | 728 | "free + dirty %-8d dark %-4d dead %-4d nodes fit %-3d " |
| 729 | "flags %#-4x (", lp->lnum, lp->free, lp->dirty, |
| 730 | c->leb_size - spc, spc, dark, dead, |
| 731 | (int)(spc / UBIFS_MAX_NODE_SZ), lp->flags); |
| 732 | |
| 733 | if (lp->flags & LPROPS_TAKEN) { |
| 734 | if (lp->flags & LPROPS_INDEX) |
| 735 | printk(KERN_CONT "index, taken"); |
| 736 | else |
| 737 | printk(KERN_CONT "taken"); |
| 738 | } else { |
| 739 | const char *s; |
| 740 | |
| 741 | if (lp->flags & LPROPS_INDEX) { |
| 742 | switch (lp->flags & LPROPS_CAT_MASK) { |
| 743 | case LPROPS_DIRTY_IDX: |
| 744 | s = "dirty index"; |
| 745 | break; |
| 746 | case LPROPS_FRDI_IDX: |
| 747 | s = "freeable index"; |
| 748 | break; |
| 749 | default: |
| 750 | s = "index"; |
| 751 | } |
| 752 | } else { |
| 753 | switch (lp->flags & LPROPS_CAT_MASK) { |
| 754 | case LPROPS_UNCAT: |
| 755 | s = "not categorized"; |
| 756 | break; |
| 757 | case LPROPS_DIRTY: |
| 758 | s = "dirty"; |
| 759 | break; |
| 760 | case LPROPS_FREE: |
| 761 | s = "free"; |
| 762 | break; |
| 763 | case LPROPS_EMPTY: |
| 764 | s = "empty"; |
| 765 | break; |
| 766 | case LPROPS_FREEABLE: |
| 767 | s = "freeable"; |
| 768 | break; |
| 769 | default: |
| 770 | s = NULL; |
| 771 | break; |
| 772 | } |
| 773 | } |
| 774 | printk(KERN_CONT "%s", s); |
| 775 | } |
| 776 | |
| 777 | for (rb = rb_first((struct rb_root *)&c->buds); rb; rb = rb_next(rb)) { |
| 778 | bud = rb_entry(rb, struct ubifs_bud, rb); |
| 779 | if (bud->lnum == lp->lnum) { |
| 780 | int head = 0; |
| 781 | for (i = 0; i < c->jhead_cnt; i++) { |
Artem Bityutskiy | 1321657 | 2011-04-24 10:53:17 +0300 | [diff] [blame] | 782 | /* |
| 783 | * Note, if we are in R/O mode or in the middle |
| 784 | * of mounting/re-mounting, the write-buffers do |
| 785 | * not exist. |
| 786 | */ |
| 787 | if (c->jheads && |
| 788 | lp->lnum == c->jheads[i].wbuf.lnum) { |
Artem Bityutskiy | be9e62a | 2008-12-28 10:17:23 +0200 | [diff] [blame] | 789 | printk(KERN_CONT ", jhead %s", |
| 790 | dbg_jhead(i)); |
| 791 | head = 1; |
| 792 | } |
| 793 | } |
| 794 | if (!head) |
| 795 | printk(KERN_CONT ", bud of jhead %s", |
| 796 | dbg_jhead(bud->jhead)); |
| 797 | } |
| 798 | } |
| 799 | if (lp->lnum == c->gc_lnum) |
| 800 | printk(KERN_CONT ", GC LEB"); |
| 801 | printk(KERN_CONT ")\n"); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | void dbg_dump_lprops(struct ubifs_info *c) |
| 805 | { |
| 806 | int lnum, err; |
| 807 | struct ubifs_lprops lp; |
| 808 | struct ubifs_lp_stats lst; |
| 809 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 810 | printk(KERN_ERR "(pid %d) start dumping LEB properties\n", |
Artem Bityutskiy | 2ba5f7a | 2008-10-31 17:32:30 +0200 | [diff] [blame] | 811 | current->pid); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 812 | ubifs_get_lp_stats(c, &lst); |
| 813 | dbg_dump_lstats(&lst); |
| 814 | |
| 815 | for (lnum = c->main_first; lnum < c->leb_cnt; lnum++) { |
| 816 | err = ubifs_read_one_lp(c, lnum, &lp); |
| 817 | if (err) |
| 818 | ubifs_err("cannot read lprops for LEB %d", lnum); |
| 819 | |
| 820 | dbg_dump_lprop(c, &lp); |
| 821 | } |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 822 | printk(KERN_ERR "(pid %d) finish dumping LEB properties\n", |
Artem Bityutskiy | 2ba5f7a | 2008-10-31 17:32:30 +0200 | [diff] [blame] | 823 | current->pid); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 824 | } |
| 825 | |
Adrian Hunter | 73944a6 | 2008-09-12 18:13:31 +0300 | [diff] [blame] | 826 | void dbg_dump_lpt_info(struct ubifs_info *c) |
| 827 | { |
| 828 | int i; |
| 829 | |
| 830 | spin_lock(&dbg_lock); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 831 | printk(KERN_ERR "(pid %d) dumping LPT information\n", current->pid); |
| 832 | printk(KERN_ERR "\tlpt_sz: %lld\n", c->lpt_sz); |
| 833 | printk(KERN_ERR "\tpnode_sz: %d\n", c->pnode_sz); |
| 834 | printk(KERN_ERR "\tnnode_sz: %d\n", c->nnode_sz); |
| 835 | printk(KERN_ERR "\tltab_sz: %d\n", c->ltab_sz); |
| 836 | printk(KERN_ERR "\tlsave_sz: %d\n", c->lsave_sz); |
| 837 | printk(KERN_ERR "\tbig_lpt: %d\n", c->big_lpt); |
| 838 | printk(KERN_ERR "\tlpt_hght: %d\n", c->lpt_hght); |
| 839 | printk(KERN_ERR "\tpnode_cnt: %d\n", c->pnode_cnt); |
| 840 | printk(KERN_ERR "\tnnode_cnt: %d\n", c->nnode_cnt); |
| 841 | printk(KERN_ERR "\tdirty_pn_cnt: %d\n", c->dirty_pn_cnt); |
| 842 | printk(KERN_ERR "\tdirty_nn_cnt: %d\n", c->dirty_nn_cnt); |
| 843 | printk(KERN_ERR "\tlsave_cnt: %d\n", c->lsave_cnt); |
| 844 | printk(KERN_ERR "\tspace_bits: %d\n", c->space_bits); |
| 845 | printk(KERN_ERR "\tlpt_lnum_bits: %d\n", c->lpt_lnum_bits); |
| 846 | printk(KERN_ERR "\tlpt_offs_bits: %d\n", c->lpt_offs_bits); |
| 847 | printk(KERN_ERR "\tlpt_spc_bits: %d\n", c->lpt_spc_bits); |
| 848 | printk(KERN_ERR "\tpcnt_bits: %d\n", c->pcnt_bits); |
| 849 | printk(KERN_ERR "\tlnum_bits: %d\n", c->lnum_bits); |
| 850 | printk(KERN_ERR "\tLPT root is at %d:%d\n", c->lpt_lnum, c->lpt_offs); |
| 851 | printk(KERN_ERR "\tLPT head is at %d:%d\n", |
Adrian Hunter | 73944a6 | 2008-09-12 18:13:31 +0300 | [diff] [blame] | 852 | c->nhead_lnum, c->nhead_offs); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 853 | printk(KERN_ERR "\tLPT ltab is at %d:%d\n", |
Artem Bityutskiy | f92b982 | 2008-12-28 11:34:26 +0200 | [diff] [blame] | 854 | c->ltab_lnum, c->ltab_offs); |
Adrian Hunter | 73944a6 | 2008-09-12 18:13:31 +0300 | [diff] [blame] | 855 | if (c->big_lpt) |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 856 | printk(KERN_ERR "\tLPT lsave is at %d:%d\n", |
Adrian Hunter | 73944a6 | 2008-09-12 18:13:31 +0300 | [diff] [blame] | 857 | c->lsave_lnum, c->lsave_offs); |
| 858 | for (i = 0; i < c->lpt_lebs; i++) |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 859 | printk(KERN_ERR "\tLPT LEB %d free %d dirty %d tgc %d " |
Adrian Hunter | 73944a6 | 2008-09-12 18:13:31 +0300 | [diff] [blame] | 860 | "cmt %d\n", i + c->lpt_first, c->ltab[i].free, |
| 861 | c->ltab[i].dirty, c->ltab[i].tgc, c->ltab[i].cmt); |
| 862 | spin_unlock(&dbg_lock); |
| 863 | } |
| 864 | |
Artem Bityutskiy | d37854c | 2011-08-22 16:23:56 +0300 | [diff] [blame] | 865 | void dbg_dump_sleb(const struct ubifs_info *c, |
| 866 | const struct ubifs_scan_leb *sleb, int offs) |
| 867 | { |
| 868 | struct ubifs_scan_node *snod; |
| 869 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 870 | printk(KERN_ERR "(pid %d) start dumping scanned data from LEB %d:%d\n", |
Artem Bityutskiy | d37854c | 2011-08-22 16:23:56 +0300 | [diff] [blame] | 871 | current->pid, sleb->lnum, offs); |
| 872 | |
| 873 | list_for_each_entry(snod, &sleb->nodes, list) { |
| 874 | cond_resched(); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 875 | printk(KERN_ERR "Dumping node at LEB %d:%d len %d\n", sleb->lnum, |
Artem Bityutskiy | d37854c | 2011-08-22 16:23:56 +0300 | [diff] [blame] | 876 | snod->offs, snod->len); |
| 877 | dbg_dump_node(c, snod->node); |
| 878 | } |
| 879 | } |
| 880 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 881 | void dbg_dump_leb(const struct ubifs_info *c, int lnum) |
| 882 | { |
| 883 | struct ubifs_scan_leb *sleb; |
| 884 | struct ubifs_scan_node *snod; |
Artem Bityutskiy | 73d9aec | 2011-03-11 15:39:09 +0200 | [diff] [blame] | 885 | void *buf; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 886 | |
Artem Bityutskiy | 2b1844a | 2011-06-03 08:31:29 +0300 | [diff] [blame] | 887 | if (dbg_is_tst_rcvry(c)) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 888 | return; |
| 889 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 890 | printk(KERN_ERR "(pid %d) start dumping LEB %d\n", |
Artem Bityutskiy | 2ba5f7a | 2008-10-31 17:32:30 +0200 | [diff] [blame] | 891 | current->pid, lnum); |
Artem Bityutskiy | 73d9aec | 2011-03-11 15:39:09 +0200 | [diff] [blame] | 892 | |
Artem Bityutskiy | fc5e58c | 2011-03-24 16:14:26 +0200 | [diff] [blame] | 893 | buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL); |
Artem Bityutskiy | 73d9aec | 2011-03-11 15:39:09 +0200 | [diff] [blame] | 894 | if (!buf) { |
| 895 | ubifs_err("cannot allocate memory for dumping LEB %d", lnum); |
| 896 | return; |
| 897 | } |
| 898 | |
| 899 | sleb = ubifs_scan(c, lnum, 0, buf, 0); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 900 | if (IS_ERR(sleb)) { |
| 901 | ubifs_err("scan error %d", (int)PTR_ERR(sleb)); |
Artem Bityutskiy | 73d9aec | 2011-03-11 15:39:09 +0200 | [diff] [blame] | 902 | goto out; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 903 | } |
| 904 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 905 | printk(KERN_ERR "LEB %d has %d nodes ending at %d\n", lnum, |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 906 | sleb->nodes_cnt, sleb->endpt); |
| 907 | |
| 908 | list_for_each_entry(snod, &sleb->nodes, list) { |
| 909 | cond_resched(); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 910 | printk(KERN_ERR "Dumping node at LEB %d:%d len %d\n", lnum, |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 911 | snod->offs, snod->len); |
| 912 | dbg_dump_node(c, snod->node); |
| 913 | } |
| 914 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 915 | printk(KERN_ERR "(pid %d) finish dumping LEB %d\n", |
Artem Bityutskiy | 2ba5f7a | 2008-10-31 17:32:30 +0200 | [diff] [blame] | 916 | current->pid, lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 917 | ubifs_scan_destroy(sleb); |
Artem Bityutskiy | 73d9aec | 2011-03-11 15:39:09 +0200 | [diff] [blame] | 918 | |
| 919 | out: |
| 920 | vfree(buf); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 921 | return; |
| 922 | } |
| 923 | |
| 924 | void dbg_dump_znode(const struct ubifs_info *c, |
| 925 | const struct ubifs_znode *znode) |
| 926 | { |
| 927 | int n; |
| 928 | const struct ubifs_zbranch *zbr; |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 929 | char key_buf[DBG_KEY_BUF_LEN]; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 930 | |
| 931 | spin_lock(&dbg_lock); |
| 932 | if (znode->parent) |
| 933 | zbr = &znode->parent->zbranch[znode->iip]; |
| 934 | else |
| 935 | zbr = &c->zroot; |
| 936 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 937 | printk(KERN_ERR "znode %p, LEB %d:%d len %d parent %p iip %d level %d" |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 938 | " child_cnt %d flags %lx\n", znode, zbr->lnum, zbr->offs, |
| 939 | zbr->len, znode->parent, znode->iip, znode->level, |
| 940 | znode->child_cnt, znode->flags); |
| 941 | |
| 942 | if (znode->child_cnt <= 0 || znode->child_cnt > c->fanout) { |
| 943 | spin_unlock(&dbg_lock); |
| 944 | return; |
| 945 | } |
| 946 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 947 | printk(KERN_ERR "zbranches:\n"); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 948 | for (n = 0; n < znode->child_cnt; n++) { |
| 949 | zbr = &znode->zbranch[n]; |
| 950 | if (znode->level > 0) |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 951 | printk(KERN_ERR "\t%d: znode %p LEB %d:%d len %d key " |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 952 | "%s\n", n, zbr->znode, zbr->lnum, |
| 953 | zbr->offs, zbr->len, |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 954 | dbg_snprintf_key(c, &zbr->key, |
| 955 | key_buf, |
| 956 | DBG_KEY_BUF_LEN)); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 957 | else |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 958 | printk(KERN_ERR "\t%d: LNC %p LEB %d:%d len %d key " |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 959 | "%s\n", n, zbr->znode, zbr->lnum, |
| 960 | zbr->offs, zbr->len, |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 961 | dbg_snprintf_key(c, &zbr->key, |
| 962 | key_buf, |
| 963 | DBG_KEY_BUF_LEN)); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 964 | } |
| 965 | spin_unlock(&dbg_lock); |
| 966 | } |
| 967 | |
| 968 | void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat) |
| 969 | { |
| 970 | int i; |
| 971 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 972 | printk(KERN_ERR "(pid %d) start dumping heap cat %d (%d elements)\n", |
Artem Bityutskiy | 1de9415 | 2008-07-25 12:58:38 +0300 | [diff] [blame] | 973 | current->pid, cat, heap->cnt); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 974 | for (i = 0; i < heap->cnt; i++) { |
| 975 | struct ubifs_lprops *lprops = heap->arr[i]; |
| 976 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 977 | printk(KERN_ERR "\t%d. LEB %d hpos %d free %d dirty %d " |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 978 | "flags %d\n", i, lprops->lnum, lprops->hpos, |
| 979 | lprops->free, lprops->dirty, lprops->flags); |
| 980 | } |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 981 | printk(KERN_ERR "(pid %d) finish dumping heap\n", current->pid); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, |
| 985 | struct ubifs_nnode *parent, int iip) |
| 986 | { |
| 987 | int i; |
| 988 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 989 | printk(KERN_ERR "(pid %d) dumping pnode:\n", current->pid); |
| 990 | printk(KERN_ERR "\taddress %zx parent %zx cnext %zx\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 991 | (size_t)pnode, (size_t)parent, (size_t)pnode->cnext); |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 992 | printk(KERN_ERR "\tflags %lu iip %d level %d num %d\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 993 | pnode->flags, iip, pnode->level, pnode->num); |
| 994 | for (i = 0; i < UBIFS_LPT_FANOUT; i++) { |
| 995 | struct ubifs_lprops *lp = &pnode->lprops[i]; |
| 996 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 997 | printk(KERN_ERR "\t%d: free %d dirty %d flags %d lnum %d\n", |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 998 | i, lp->free, lp->dirty, lp->flags, lp->lnum); |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | void dbg_dump_tnc(struct ubifs_info *c) |
| 1003 | { |
| 1004 | struct ubifs_znode *znode; |
| 1005 | int level; |
| 1006 | |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 1007 | printk(KERN_ERR "\n"); |
| 1008 | printk(KERN_ERR "(pid %d) start dumping TNC tree\n", current->pid); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1009 | znode = ubifs_tnc_levelorder_next(c->zroot.znode, NULL); |
| 1010 | level = znode->level; |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 1011 | printk(KERN_ERR "== Level %d ==\n", level); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1012 | while (znode) { |
| 1013 | if (level != znode->level) { |
| 1014 | level = znode->level; |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 1015 | printk(KERN_ERR "== Level %d ==\n", level); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1016 | } |
| 1017 | dbg_dump_znode(c, znode); |
| 1018 | znode = ubifs_tnc_levelorder_next(c->zroot.znode, znode); |
| 1019 | } |
Artem Bityutskiy | 16c395c | 2012-01-18 15:46:13 +0200 | [diff] [blame] | 1020 | printk(KERN_ERR "(pid %d) finish dumping TNC tree\n", current->pid); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | static int dump_znode(struct ubifs_info *c, struct ubifs_znode *znode, |
| 1024 | void *priv) |
| 1025 | { |
| 1026 | dbg_dump_znode(c, znode); |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
| 1030 | /** |
| 1031 | * dbg_dump_index - dump the on-flash index. |
| 1032 | * @c: UBIFS file-system description object |
| 1033 | * |
| 1034 | * This function dumps whole UBIFS indexing B-tree, unlike 'dbg_dump_tnc()' |
| 1035 | * which dumps only in-memory znodes and does not read znodes which from flash. |
| 1036 | */ |
| 1037 | void dbg_dump_index(struct ubifs_info *c) |
| 1038 | { |
| 1039 | dbg_walk_index(c, NULL, dump_znode, NULL); |
| 1040 | } |
| 1041 | |
| 1042 | /** |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 1043 | * dbg_save_space_info - save information about flash space. |
| 1044 | * @c: UBIFS file-system description object |
| 1045 | * |
| 1046 | * This function saves information about UBIFS free space, dirty space, etc, in |
| 1047 | * order to check it later. |
| 1048 | */ |
| 1049 | void dbg_save_space_info(struct ubifs_info *c) |
| 1050 | { |
| 1051 | struct ubifs_debug_info *d = c->dbg; |
Artem Bityutskiy | 7da6443 | 2011-04-04 17:16:39 +0300 | [diff] [blame] | 1052 | int freeable_cnt; |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 1053 | |
| 1054 | spin_lock(&c->space_lock); |
Artem Bityutskiy | 7da6443 | 2011-04-04 17:16:39 +0300 | [diff] [blame] | 1055 | memcpy(&d->saved_lst, &c->lst, sizeof(struct ubifs_lp_stats)); |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 1056 | memcpy(&d->saved_bi, &c->bi, sizeof(struct ubifs_budg_info)); |
| 1057 | d->saved_idx_gc_cnt = c->idx_gc_cnt; |
Artem Bityutskiy | 7da6443 | 2011-04-04 17:16:39 +0300 | [diff] [blame] | 1058 | |
| 1059 | /* |
| 1060 | * We use a dirty hack here and zero out @c->freeable_cnt, because it |
| 1061 | * affects the free space calculations, and UBIFS might not know about |
| 1062 | * all freeable eraseblocks. Indeed, we know about freeable eraseblocks |
| 1063 | * only when we read their lprops, and we do this only lazily, upon the |
| 1064 | * need. So at any given point of time @c->freeable_cnt might be not |
| 1065 | * exactly accurate. |
| 1066 | * |
| 1067 | * Just one example about the issue we hit when we did not zero |
| 1068 | * @c->freeable_cnt. |
| 1069 | * 1. The file-system is mounted R/O, c->freeable_cnt is %0. We save the |
| 1070 | * amount of free space in @d->saved_free |
| 1071 | * 2. We re-mount R/W, which makes UBIFS to read the "lsave" |
| 1072 | * information from flash, where we cache LEBs from various |
| 1073 | * categories ('ubifs_remount_fs()' -> 'ubifs_lpt_init()' |
| 1074 | * -> 'lpt_init_wr()' -> 'read_lsave()' -> 'ubifs_lpt_lookup()' |
| 1075 | * -> 'ubifs_get_pnode()' -> 'update_cats()' |
| 1076 | * -> 'ubifs_add_to_cat()'). |
| 1077 | * 3. Lsave contains a freeable eraseblock, and @c->freeable_cnt |
| 1078 | * becomes %1. |
| 1079 | * 4. We calculate the amount of free space when the re-mount is |
| 1080 | * finished in 'dbg_check_space_info()' and it does not match |
| 1081 | * @d->saved_free. |
| 1082 | */ |
| 1083 | freeable_cnt = c->freeable_cnt; |
| 1084 | c->freeable_cnt = 0; |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 1085 | d->saved_free = ubifs_get_free_space_nolock(c); |
Artem Bityutskiy | 7da6443 | 2011-04-04 17:16:39 +0300 | [diff] [blame] | 1086 | c->freeable_cnt = freeable_cnt; |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 1087 | spin_unlock(&c->space_lock); |
| 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * dbg_check_space_info - check flash space information. |
| 1092 | * @c: UBIFS file-system description object |
| 1093 | * |
| 1094 | * This function compares current flash space information with the information |
| 1095 | * which was saved when the 'dbg_save_space_info()' function was called. |
| 1096 | * Returns zero if the information has not changed, and %-EINVAL it it has |
| 1097 | * changed. |
| 1098 | */ |
| 1099 | int dbg_check_space_info(struct ubifs_info *c) |
| 1100 | { |
| 1101 | struct ubifs_debug_info *d = c->dbg; |
| 1102 | struct ubifs_lp_stats lst; |
Artem Bityutskiy | 7da6443 | 2011-04-04 17:16:39 +0300 | [diff] [blame] | 1103 | long long free; |
| 1104 | int freeable_cnt; |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 1105 | |
| 1106 | spin_lock(&c->space_lock); |
Artem Bityutskiy | 7da6443 | 2011-04-04 17:16:39 +0300 | [diff] [blame] | 1107 | freeable_cnt = c->freeable_cnt; |
| 1108 | c->freeable_cnt = 0; |
| 1109 | free = ubifs_get_free_space_nolock(c); |
| 1110 | c->freeable_cnt = freeable_cnt; |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 1111 | spin_unlock(&c->space_lock); |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 1112 | |
| 1113 | if (free != d->saved_free) { |
| 1114 | ubifs_err("free space changed from %lld to %lld", |
| 1115 | d->saved_free, free); |
| 1116 | goto out; |
| 1117 | } |
| 1118 | |
| 1119 | return 0; |
| 1120 | |
| 1121 | out: |
| 1122 | ubifs_msg("saved lprops statistics dump"); |
| 1123 | dbg_dump_lstats(&d->saved_lst); |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 1124 | ubifs_msg("saved budgeting info dump"); |
| 1125 | dbg_dump_budg(c, &d->saved_bi); |
| 1126 | ubifs_msg("saved idx_gc_cnt %d", d->saved_idx_gc_cnt); |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 1127 | ubifs_msg("current lprops statistics dump"); |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 1128 | ubifs_get_lp_stats(c, &lst); |
Artem Bityutskiy | e055f7e | 2009-09-17 15:08:31 +0300 | [diff] [blame] | 1129 | dbg_dump_lstats(&lst); |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 1130 | ubifs_msg("current budgeting info dump"); |
| 1131 | dbg_dump_budg(c, &c->bi); |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 1132 | dump_stack(); |
| 1133 | return -EINVAL; |
| 1134 | } |
| 1135 | |
| 1136 | /** |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1137 | * dbg_check_synced_i_size - check synchronized inode size. |
Artem Bityutskiy | d808efb | 2011-05-31 18:14:38 +0300 | [diff] [blame] | 1138 | * @c: UBIFS file-system description object |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1139 | * @inode: inode to check |
| 1140 | * |
| 1141 | * If inode is clean, synchronized inode size has to be equivalent to current |
| 1142 | * inode size. This function has to be called only for locked inodes (@i_mutex |
| 1143 | * has to be locked). Returns %0 if synchronized inode size if correct, and |
| 1144 | * %-EINVAL if not. |
| 1145 | */ |
Artem Bityutskiy | d808efb | 2011-05-31 18:14:38 +0300 | [diff] [blame] | 1146 | int dbg_check_synced_i_size(const struct ubifs_info *c, struct inode *inode) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1147 | { |
| 1148 | int err = 0; |
| 1149 | struct ubifs_inode *ui = ubifs_inode(inode); |
| 1150 | |
Artem Bityutskiy | 2b1844a | 2011-06-03 08:31:29 +0300 | [diff] [blame] | 1151 | if (!dbg_is_chk_gen(c)) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1152 | return 0; |
| 1153 | if (!S_ISREG(inode->i_mode)) |
| 1154 | return 0; |
| 1155 | |
| 1156 | mutex_lock(&ui->ui_mutex); |
| 1157 | spin_lock(&ui->ui_lock); |
| 1158 | if (ui->ui_size != ui->synced_i_size && !ui->dirty) { |
| 1159 | ubifs_err("ui_size is %lld, synced_i_size is %lld, but inode " |
| 1160 | "is clean", ui->ui_size, ui->synced_i_size); |
| 1161 | ubifs_err("i_ino %lu, i_mode %#x, i_size %lld", inode->i_ino, |
| 1162 | inode->i_mode, i_size_read(inode)); |
| 1163 | dbg_dump_stack(); |
| 1164 | err = -EINVAL; |
| 1165 | } |
| 1166 | spin_unlock(&ui->ui_lock); |
| 1167 | mutex_unlock(&ui->ui_mutex); |
| 1168 | return err; |
| 1169 | } |
| 1170 | |
| 1171 | /* |
| 1172 | * dbg_check_dir - check directory inode size and link count. |
| 1173 | * @c: UBIFS file-system description object |
| 1174 | * @dir: the directory to calculate size for |
| 1175 | * @size: the result is returned here |
| 1176 | * |
| 1177 | * This function makes sure that directory size and link count are correct. |
| 1178 | * Returns zero in case of success and a negative error code in case of |
| 1179 | * failure. |
| 1180 | * |
| 1181 | * Note, it is good idea to make sure the @dir->i_mutex is locked before |
| 1182 | * calling this function. |
| 1183 | */ |
Artem Bityutskiy | 1b51e98 | 2011-05-25 17:38:29 +0300 | [diff] [blame] | 1184 | int dbg_check_dir(struct ubifs_info *c, const struct inode *dir) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1185 | { |
| 1186 | unsigned int nlink = 2; |
| 1187 | union ubifs_key key; |
| 1188 | struct ubifs_dent_node *dent, *pdent = NULL; |
| 1189 | struct qstr nm = { .name = NULL }; |
| 1190 | loff_t size = UBIFS_INO_NODE_SZ; |
| 1191 | |
Artem Bityutskiy | 2b1844a | 2011-06-03 08:31:29 +0300 | [diff] [blame] | 1192 | if (!dbg_is_chk_gen(c)) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1193 | return 0; |
| 1194 | |
| 1195 | if (!S_ISDIR(dir->i_mode)) |
| 1196 | return 0; |
| 1197 | |
| 1198 | lowest_dent_key(c, &key, dir->i_ino); |
| 1199 | while (1) { |
| 1200 | int err; |
| 1201 | |
| 1202 | dent = ubifs_tnc_next_ent(c, &key, &nm); |
| 1203 | if (IS_ERR(dent)) { |
| 1204 | err = PTR_ERR(dent); |
| 1205 | if (err == -ENOENT) |
| 1206 | break; |
| 1207 | return err; |
| 1208 | } |
| 1209 | |
| 1210 | nm.name = dent->name; |
| 1211 | nm.len = le16_to_cpu(dent->nlen); |
| 1212 | size += CALC_DENT_SIZE(nm.len); |
| 1213 | if (dent->type == UBIFS_ITYPE_DIR) |
| 1214 | nlink += 1; |
| 1215 | kfree(pdent); |
| 1216 | pdent = dent; |
| 1217 | key_read(c, &dent->key, &key); |
| 1218 | } |
| 1219 | kfree(pdent); |
| 1220 | |
| 1221 | if (i_size_read(dir) != size) { |
| 1222 | ubifs_err("directory inode %lu has size %llu, " |
| 1223 | "but calculated size is %llu", dir->i_ino, |
| 1224 | (unsigned long long)i_size_read(dir), |
| 1225 | (unsigned long long)size); |
Artem Bityutskiy | 4315fb4 | 2011-05-25 17:32:42 +0300 | [diff] [blame] | 1226 | dbg_dump_inode(c, dir); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1227 | dump_stack(); |
| 1228 | return -EINVAL; |
| 1229 | } |
| 1230 | if (dir->i_nlink != nlink) { |
| 1231 | ubifs_err("directory inode %lu has nlink %u, but calculated " |
| 1232 | "nlink is %u", dir->i_ino, dir->i_nlink, nlink); |
Artem Bityutskiy | 4315fb4 | 2011-05-25 17:32:42 +0300 | [diff] [blame] | 1233 | dbg_dump_inode(c, dir); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1234 | dump_stack(); |
| 1235 | return -EINVAL; |
| 1236 | } |
| 1237 | |
| 1238 | return 0; |
| 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * dbg_check_key_order - make sure that colliding keys are properly ordered. |
| 1243 | * @c: UBIFS file-system description object |
| 1244 | * @zbr1: first zbranch |
| 1245 | * @zbr2: following zbranch |
| 1246 | * |
| 1247 | * In UBIFS indexing B-tree colliding keys has to be sorted in binary order of |
| 1248 | * names of the direntries/xentries which are referred by the keys. This |
| 1249 | * function reads direntries/xentries referred by @zbr1 and @zbr2 and makes |
| 1250 | * sure the name of direntry/xentry referred by @zbr1 is less than |
| 1251 | * direntry/xentry referred by @zbr2. Returns zero if this is true, %1 if not, |
| 1252 | * and a negative error code in case of failure. |
| 1253 | */ |
| 1254 | static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1, |
| 1255 | struct ubifs_zbranch *zbr2) |
| 1256 | { |
| 1257 | int err, nlen1, nlen2, cmp; |
| 1258 | struct ubifs_dent_node *dent1, *dent2; |
| 1259 | union ubifs_key key; |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 1260 | char key_buf[DBG_KEY_BUF_LEN]; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1261 | |
| 1262 | ubifs_assert(!keys_cmp(c, &zbr1->key, &zbr2->key)); |
| 1263 | dent1 = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS); |
| 1264 | if (!dent1) |
| 1265 | return -ENOMEM; |
| 1266 | dent2 = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS); |
| 1267 | if (!dent2) { |
| 1268 | err = -ENOMEM; |
| 1269 | goto out_free; |
| 1270 | } |
| 1271 | |
| 1272 | err = ubifs_tnc_read_node(c, zbr1, dent1); |
| 1273 | if (err) |
| 1274 | goto out_free; |
| 1275 | err = ubifs_validate_entry(c, dent1); |
| 1276 | if (err) |
| 1277 | goto out_free; |
| 1278 | |
| 1279 | err = ubifs_tnc_read_node(c, zbr2, dent2); |
| 1280 | if (err) |
| 1281 | goto out_free; |
| 1282 | err = ubifs_validate_entry(c, dent2); |
| 1283 | if (err) |
| 1284 | goto out_free; |
| 1285 | |
| 1286 | /* Make sure node keys are the same as in zbranch */ |
| 1287 | err = 1; |
| 1288 | key_read(c, &dent1->key, &key); |
| 1289 | if (keys_cmp(c, &zbr1->key, &key)) { |
Artem Bityutskiy | 5d38b3a | 2008-12-30 17:58:42 +0200 | [diff] [blame] | 1290 | dbg_err("1st entry at %d:%d has key %s", zbr1->lnum, |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 1291 | zbr1->offs, dbg_snprintf_key(c, &key, key_buf, |
| 1292 | DBG_KEY_BUF_LEN)); |
Artem Bityutskiy | 5d38b3a | 2008-12-30 17:58:42 +0200 | [diff] [blame] | 1293 | dbg_err("but it should have key %s according to tnc", |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 1294 | dbg_snprintf_key(c, &zbr1->key, key_buf, |
| 1295 | DBG_KEY_BUF_LEN)); |
Artem Bityutskiy | 2ba5f7a | 2008-10-31 17:32:30 +0200 | [diff] [blame] | 1296 | dbg_dump_node(c, dent1); |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 1297 | goto out_free; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | key_read(c, &dent2->key, &key); |
| 1301 | if (keys_cmp(c, &zbr2->key, &key)) { |
Artem Bityutskiy | 5d38b3a | 2008-12-30 17:58:42 +0200 | [diff] [blame] | 1302 | dbg_err("2nd entry at %d:%d has key %s", zbr1->lnum, |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 1303 | zbr1->offs, dbg_snprintf_key(c, &key, key_buf, |
| 1304 | DBG_KEY_BUF_LEN)); |
Artem Bityutskiy | 5d38b3a | 2008-12-30 17:58:42 +0200 | [diff] [blame] | 1305 | dbg_err("but it should have key %s according to tnc", |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 1306 | dbg_snprintf_key(c, &zbr2->key, key_buf, |
| 1307 | DBG_KEY_BUF_LEN)); |
Artem Bityutskiy | 2ba5f7a | 2008-10-31 17:32:30 +0200 | [diff] [blame] | 1308 | dbg_dump_node(c, dent2); |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 1309 | goto out_free; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | nlen1 = le16_to_cpu(dent1->nlen); |
| 1313 | nlen2 = le16_to_cpu(dent2->nlen); |
| 1314 | |
| 1315 | cmp = memcmp(dent1->name, dent2->name, min_t(int, nlen1, nlen2)); |
| 1316 | if (cmp < 0 || (cmp == 0 && nlen1 < nlen2)) { |
| 1317 | err = 0; |
| 1318 | goto out_free; |
| 1319 | } |
| 1320 | if (cmp == 0 && nlen1 == nlen2) |
Artem Bityutskiy | 5d38b3a | 2008-12-30 17:58:42 +0200 | [diff] [blame] | 1321 | dbg_err("2 xent/dent nodes with the same name"); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1322 | else |
Artem Bityutskiy | 5d38b3a | 2008-12-30 17:58:42 +0200 | [diff] [blame] | 1323 | dbg_err("bad order of colliding key %s", |
Artem Bityutskiy | 515315a | 2012-01-13 12:33:53 +0200 | [diff] [blame] | 1324 | dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN)); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1325 | |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 1326 | ubifs_msg("first node at %d:%d\n", zbr1->lnum, zbr1->offs); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1327 | dbg_dump_node(c, dent1); |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 1328 | ubifs_msg("second node at %d:%d\n", zbr2->lnum, zbr2->offs); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1329 | dbg_dump_node(c, dent2); |
| 1330 | |
| 1331 | out_free: |
| 1332 | kfree(dent2); |
| 1333 | kfree(dent1); |
| 1334 | return err; |
| 1335 | } |
| 1336 | |
| 1337 | /** |
| 1338 | * dbg_check_znode - check if znode is all right. |
| 1339 | * @c: UBIFS file-system description object |
| 1340 | * @zbr: zbranch which points to this znode |
| 1341 | * |
| 1342 | * This function makes sure that znode referred to by @zbr is all right. |
| 1343 | * Returns zero if it is, and %-EINVAL if it is not. |
| 1344 | */ |
| 1345 | static int dbg_check_znode(struct ubifs_info *c, struct ubifs_zbranch *zbr) |
| 1346 | { |
| 1347 | struct ubifs_znode *znode = zbr->znode; |
| 1348 | struct ubifs_znode *zp = znode->parent; |
| 1349 | int n, err, cmp; |
| 1350 | |
| 1351 | if (znode->child_cnt <= 0 || znode->child_cnt > c->fanout) { |
| 1352 | err = 1; |
| 1353 | goto out; |
| 1354 | } |
| 1355 | if (znode->level < 0) { |
| 1356 | err = 2; |
| 1357 | goto out; |
| 1358 | } |
| 1359 | if (znode->iip < 0 || znode->iip >= c->fanout) { |
| 1360 | err = 3; |
| 1361 | goto out; |
| 1362 | } |
| 1363 | |
| 1364 | if (zbr->len == 0) |
| 1365 | /* Only dirty zbranch may have no on-flash nodes */ |
| 1366 | if (!ubifs_zn_dirty(znode)) { |
| 1367 | err = 4; |
| 1368 | goto out; |
| 1369 | } |
| 1370 | |
| 1371 | if (ubifs_zn_dirty(znode)) { |
| 1372 | /* |
| 1373 | * If znode is dirty, its parent has to be dirty as well. The |
| 1374 | * order of the operation is important, so we have to have |
| 1375 | * memory barriers. |
| 1376 | */ |
| 1377 | smp_mb(); |
| 1378 | if (zp && !ubifs_zn_dirty(zp)) { |
| 1379 | /* |
| 1380 | * The dirty flag is atomic and is cleared outside the |
| 1381 | * TNC mutex, so znode's dirty flag may now have |
| 1382 | * been cleared. The child is always cleared before the |
| 1383 | * parent, so we just need to check again. |
| 1384 | */ |
| 1385 | smp_mb(); |
| 1386 | if (ubifs_zn_dirty(znode)) { |
| 1387 | err = 5; |
| 1388 | goto out; |
| 1389 | } |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | if (zp) { |
| 1394 | const union ubifs_key *min, *max; |
| 1395 | |
| 1396 | if (znode->level != zp->level - 1) { |
| 1397 | err = 6; |
| 1398 | goto out; |
| 1399 | } |
| 1400 | |
| 1401 | /* Make sure the 'parent' pointer in our znode is correct */ |
| 1402 | err = ubifs_search_zbranch(c, zp, &zbr->key, &n); |
| 1403 | if (!err) { |
| 1404 | /* This zbranch does not exist in the parent */ |
| 1405 | err = 7; |
| 1406 | goto out; |
| 1407 | } |
| 1408 | |
| 1409 | if (znode->iip >= zp->child_cnt) { |
| 1410 | err = 8; |
| 1411 | goto out; |
| 1412 | } |
| 1413 | |
| 1414 | if (znode->iip != n) { |
| 1415 | /* This may happen only in case of collisions */ |
| 1416 | if (keys_cmp(c, &zp->zbranch[n].key, |
| 1417 | &zp->zbranch[znode->iip].key)) { |
| 1418 | err = 9; |
| 1419 | goto out; |
| 1420 | } |
| 1421 | n = znode->iip; |
| 1422 | } |
| 1423 | |
| 1424 | /* |
| 1425 | * Make sure that the first key in our znode is greater than or |
| 1426 | * equal to the key in the pointing zbranch. |
| 1427 | */ |
| 1428 | min = &zbr->key; |
| 1429 | cmp = keys_cmp(c, min, &znode->zbranch[0].key); |
| 1430 | if (cmp == 1) { |
| 1431 | err = 10; |
| 1432 | goto out; |
| 1433 | } |
| 1434 | |
| 1435 | if (n + 1 < zp->child_cnt) { |
| 1436 | max = &zp->zbranch[n + 1].key; |
| 1437 | |
| 1438 | /* |
| 1439 | * Make sure the last key in our znode is less or |
Artem Bityutskiy | 7d4e9cc | 2009-03-20 19:11:12 +0200 | [diff] [blame] | 1440 | * equivalent than the key in the zbranch which goes |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1441 | * after our pointing zbranch. |
| 1442 | */ |
| 1443 | cmp = keys_cmp(c, max, |
| 1444 | &znode->zbranch[znode->child_cnt - 1].key); |
| 1445 | if (cmp == -1) { |
| 1446 | err = 11; |
| 1447 | goto out; |
| 1448 | } |
| 1449 | } |
| 1450 | } else { |
| 1451 | /* This may only be root znode */ |
| 1452 | if (zbr != &c->zroot) { |
| 1453 | err = 12; |
| 1454 | goto out; |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | /* |
| 1459 | * Make sure that next key is greater or equivalent then the previous |
| 1460 | * one. |
| 1461 | */ |
| 1462 | for (n = 1; n < znode->child_cnt; n++) { |
| 1463 | cmp = keys_cmp(c, &znode->zbranch[n - 1].key, |
| 1464 | &znode->zbranch[n].key); |
| 1465 | if (cmp > 0) { |
| 1466 | err = 13; |
| 1467 | goto out; |
| 1468 | } |
| 1469 | if (cmp == 0) { |
| 1470 | /* This can only be keys with colliding hash */ |
| 1471 | if (!is_hash_key(c, &znode->zbranch[n].key)) { |
| 1472 | err = 14; |
| 1473 | goto out; |
| 1474 | } |
| 1475 | |
| 1476 | if (znode->level != 0 || c->replaying) |
| 1477 | continue; |
| 1478 | |
| 1479 | /* |
| 1480 | * Colliding keys should follow binary order of |
| 1481 | * corresponding xentry/dentry names. |
| 1482 | */ |
| 1483 | err = dbg_check_key_order(c, &znode->zbranch[n - 1], |
| 1484 | &znode->zbranch[n]); |
| 1485 | if (err < 0) |
| 1486 | return err; |
| 1487 | if (err) { |
| 1488 | err = 15; |
| 1489 | goto out; |
| 1490 | } |
| 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | for (n = 0; n < znode->child_cnt; n++) { |
| 1495 | if (!znode->zbranch[n].znode && |
| 1496 | (znode->zbranch[n].lnum == 0 || |
| 1497 | znode->zbranch[n].len == 0)) { |
| 1498 | err = 16; |
| 1499 | goto out; |
| 1500 | } |
| 1501 | |
| 1502 | if (znode->zbranch[n].lnum != 0 && |
| 1503 | znode->zbranch[n].len == 0) { |
| 1504 | err = 17; |
| 1505 | goto out; |
| 1506 | } |
| 1507 | |
| 1508 | if (znode->zbranch[n].lnum == 0 && |
| 1509 | znode->zbranch[n].len != 0) { |
| 1510 | err = 18; |
| 1511 | goto out; |
| 1512 | } |
| 1513 | |
| 1514 | if (znode->zbranch[n].lnum == 0 && |
| 1515 | znode->zbranch[n].offs != 0) { |
| 1516 | err = 19; |
| 1517 | goto out; |
| 1518 | } |
| 1519 | |
| 1520 | if (znode->level != 0 && znode->zbranch[n].znode) |
| 1521 | if (znode->zbranch[n].znode->parent != znode) { |
| 1522 | err = 20; |
| 1523 | goto out; |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | return 0; |
| 1528 | |
| 1529 | out: |
| 1530 | ubifs_err("failed, error %d", err); |
| 1531 | ubifs_msg("dump of the znode"); |
| 1532 | dbg_dump_znode(c, znode); |
| 1533 | if (zp) { |
| 1534 | ubifs_msg("dump of the parent znode"); |
| 1535 | dbg_dump_znode(c, zp); |
| 1536 | } |
| 1537 | dump_stack(); |
| 1538 | return -EINVAL; |
| 1539 | } |
| 1540 | |
| 1541 | /** |
| 1542 | * dbg_check_tnc - check TNC tree. |
| 1543 | * @c: UBIFS file-system description object |
| 1544 | * @extra: do extra checks that are possible at start commit |
| 1545 | * |
| 1546 | * This function traverses whole TNC tree and checks every znode. Returns zero |
| 1547 | * if everything is all right and %-EINVAL if something is wrong with TNC. |
| 1548 | */ |
| 1549 | int dbg_check_tnc(struct ubifs_info *c, int extra) |
| 1550 | { |
| 1551 | struct ubifs_znode *znode; |
| 1552 | long clean_cnt = 0, dirty_cnt = 0; |
| 1553 | int err, last; |
| 1554 | |
Artem Bityutskiy | 8d7819b | 2011-06-03 08:53:35 +0300 | [diff] [blame] | 1555 | if (!dbg_is_chk_index(c)) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1556 | return 0; |
| 1557 | |
| 1558 | ubifs_assert(mutex_is_locked(&c->tnc_mutex)); |
| 1559 | if (!c->zroot.znode) |
| 1560 | return 0; |
| 1561 | |
| 1562 | znode = ubifs_tnc_postorder_first(c->zroot.znode); |
| 1563 | while (1) { |
| 1564 | struct ubifs_znode *prev; |
| 1565 | struct ubifs_zbranch *zbr; |
| 1566 | |
| 1567 | if (!znode->parent) |
| 1568 | zbr = &c->zroot; |
| 1569 | else |
| 1570 | zbr = &znode->parent->zbranch[znode->iip]; |
| 1571 | |
| 1572 | err = dbg_check_znode(c, zbr); |
| 1573 | if (err) |
| 1574 | return err; |
| 1575 | |
| 1576 | if (extra) { |
| 1577 | if (ubifs_zn_dirty(znode)) |
| 1578 | dirty_cnt += 1; |
| 1579 | else |
| 1580 | clean_cnt += 1; |
| 1581 | } |
| 1582 | |
| 1583 | prev = znode; |
| 1584 | znode = ubifs_tnc_postorder_next(znode); |
| 1585 | if (!znode) |
| 1586 | break; |
| 1587 | |
| 1588 | /* |
| 1589 | * If the last key of this znode is equivalent to the first key |
| 1590 | * of the next znode (collision), then check order of the keys. |
| 1591 | */ |
| 1592 | last = prev->child_cnt - 1; |
| 1593 | if (prev->level == 0 && znode->level == 0 && !c->replaying && |
| 1594 | !keys_cmp(c, &prev->zbranch[last].key, |
| 1595 | &znode->zbranch[0].key)) { |
| 1596 | err = dbg_check_key_order(c, &prev->zbranch[last], |
| 1597 | &znode->zbranch[0]); |
| 1598 | if (err < 0) |
| 1599 | return err; |
| 1600 | if (err) { |
| 1601 | ubifs_msg("first znode"); |
| 1602 | dbg_dump_znode(c, prev); |
| 1603 | ubifs_msg("second znode"); |
| 1604 | dbg_dump_znode(c, znode); |
| 1605 | return -EINVAL; |
| 1606 | } |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | if (extra) { |
| 1611 | if (clean_cnt != atomic_long_read(&c->clean_zn_cnt)) { |
| 1612 | ubifs_err("incorrect clean_zn_cnt %ld, calculated %ld", |
| 1613 | atomic_long_read(&c->clean_zn_cnt), |
| 1614 | clean_cnt); |
| 1615 | return -EINVAL; |
| 1616 | } |
| 1617 | if (dirty_cnt != atomic_long_read(&c->dirty_zn_cnt)) { |
| 1618 | ubifs_err("incorrect dirty_zn_cnt %ld, calculated %ld", |
| 1619 | atomic_long_read(&c->dirty_zn_cnt), |
| 1620 | dirty_cnt); |
| 1621 | return -EINVAL; |
| 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | return 0; |
| 1626 | } |
| 1627 | |
| 1628 | /** |
| 1629 | * dbg_walk_index - walk the on-flash index. |
| 1630 | * @c: UBIFS file-system description object |
| 1631 | * @leaf_cb: called for each leaf node |
| 1632 | * @znode_cb: called for each indexing node |
Adrian Hunter | 227c75c | 2009-01-29 11:53:51 +0200 | [diff] [blame] | 1633 | * @priv: private data which is passed to callbacks |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1634 | * |
| 1635 | * This function walks the UBIFS index and calls the @leaf_cb for each leaf |
| 1636 | * node and @znode_cb for each indexing node. Returns zero in case of success |
| 1637 | * and a negative error code in case of failure. |
| 1638 | * |
| 1639 | * It would be better if this function removed every znode it pulled to into |
| 1640 | * the TNC, so that the behavior more closely matched the non-debugging |
| 1641 | * behavior. |
| 1642 | */ |
| 1643 | int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb, |
| 1644 | dbg_znode_callback znode_cb, void *priv) |
| 1645 | { |
| 1646 | int err; |
| 1647 | struct ubifs_zbranch *zbr; |
| 1648 | struct ubifs_znode *znode, *child; |
| 1649 | |
| 1650 | mutex_lock(&c->tnc_mutex); |
| 1651 | /* If the root indexing node is not in TNC - pull it */ |
| 1652 | if (!c->zroot.znode) { |
| 1653 | c->zroot.znode = ubifs_load_znode(c, &c->zroot, NULL, 0); |
| 1654 | if (IS_ERR(c->zroot.znode)) { |
| 1655 | err = PTR_ERR(c->zroot.znode); |
| 1656 | c->zroot.znode = NULL; |
| 1657 | goto out_unlock; |
| 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | /* |
| 1662 | * We are going to traverse the indexing tree in the postorder manner. |
| 1663 | * Go down and find the leftmost indexing node where we are going to |
| 1664 | * start from. |
| 1665 | */ |
| 1666 | znode = c->zroot.znode; |
| 1667 | while (znode->level > 0) { |
| 1668 | zbr = &znode->zbranch[0]; |
| 1669 | child = zbr->znode; |
| 1670 | if (!child) { |
| 1671 | child = ubifs_load_znode(c, zbr, znode, 0); |
| 1672 | if (IS_ERR(child)) { |
| 1673 | err = PTR_ERR(child); |
| 1674 | goto out_unlock; |
| 1675 | } |
| 1676 | zbr->znode = child; |
| 1677 | } |
| 1678 | |
| 1679 | znode = child; |
| 1680 | } |
| 1681 | |
| 1682 | /* Iterate over all indexing nodes */ |
| 1683 | while (1) { |
| 1684 | int idx; |
| 1685 | |
| 1686 | cond_resched(); |
| 1687 | |
| 1688 | if (znode_cb) { |
| 1689 | err = znode_cb(c, znode, priv); |
| 1690 | if (err) { |
| 1691 | ubifs_err("znode checking function returned " |
| 1692 | "error %d", err); |
| 1693 | dbg_dump_znode(c, znode); |
| 1694 | goto out_dump; |
| 1695 | } |
| 1696 | } |
| 1697 | if (leaf_cb && znode->level == 0) { |
| 1698 | for (idx = 0; idx < znode->child_cnt; idx++) { |
| 1699 | zbr = &znode->zbranch[idx]; |
| 1700 | err = leaf_cb(c, zbr, priv); |
| 1701 | if (err) { |
| 1702 | ubifs_err("leaf checking function " |
| 1703 | "returned error %d, for leaf " |
| 1704 | "at LEB %d:%d", |
| 1705 | err, zbr->lnum, zbr->offs); |
| 1706 | goto out_dump; |
| 1707 | } |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | if (!znode->parent) |
| 1712 | break; |
| 1713 | |
| 1714 | idx = znode->iip + 1; |
| 1715 | znode = znode->parent; |
| 1716 | if (idx < znode->child_cnt) { |
| 1717 | /* Switch to the next index in the parent */ |
| 1718 | zbr = &znode->zbranch[idx]; |
| 1719 | child = zbr->znode; |
| 1720 | if (!child) { |
| 1721 | child = ubifs_load_znode(c, zbr, znode, idx); |
| 1722 | if (IS_ERR(child)) { |
| 1723 | err = PTR_ERR(child); |
| 1724 | goto out_unlock; |
| 1725 | } |
| 1726 | zbr->znode = child; |
| 1727 | } |
| 1728 | znode = child; |
| 1729 | } else |
| 1730 | /* |
| 1731 | * This is the last child, switch to the parent and |
| 1732 | * continue. |
| 1733 | */ |
| 1734 | continue; |
| 1735 | |
| 1736 | /* Go to the lowest leftmost znode in the new sub-tree */ |
| 1737 | while (znode->level > 0) { |
| 1738 | zbr = &znode->zbranch[0]; |
| 1739 | child = zbr->znode; |
| 1740 | if (!child) { |
| 1741 | child = ubifs_load_znode(c, zbr, znode, 0); |
| 1742 | if (IS_ERR(child)) { |
| 1743 | err = PTR_ERR(child); |
| 1744 | goto out_unlock; |
| 1745 | } |
| 1746 | zbr->znode = child; |
| 1747 | } |
| 1748 | znode = child; |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | mutex_unlock(&c->tnc_mutex); |
| 1753 | return 0; |
| 1754 | |
| 1755 | out_dump: |
| 1756 | if (znode->parent) |
| 1757 | zbr = &znode->parent->zbranch[znode->iip]; |
| 1758 | else |
| 1759 | zbr = &c->zroot; |
| 1760 | ubifs_msg("dump of znode at LEB %d:%d", zbr->lnum, zbr->offs); |
| 1761 | dbg_dump_znode(c, znode); |
| 1762 | out_unlock: |
| 1763 | mutex_unlock(&c->tnc_mutex); |
| 1764 | return err; |
| 1765 | } |
| 1766 | |
| 1767 | /** |
| 1768 | * add_size - add znode size to partially calculated index size. |
| 1769 | * @c: UBIFS file-system description object |
| 1770 | * @znode: znode to add size for |
| 1771 | * @priv: partially calculated index size |
| 1772 | * |
| 1773 | * This is a helper function for 'dbg_check_idx_size()' which is called for |
| 1774 | * every indexing node and adds its size to the 'long long' variable pointed to |
| 1775 | * by @priv. |
| 1776 | */ |
| 1777 | static int add_size(struct ubifs_info *c, struct ubifs_znode *znode, void *priv) |
| 1778 | { |
| 1779 | long long *idx_size = priv; |
| 1780 | int add; |
| 1781 | |
| 1782 | add = ubifs_idx_node_sz(c, znode->child_cnt); |
| 1783 | add = ALIGN(add, 8); |
| 1784 | *idx_size += add; |
| 1785 | return 0; |
| 1786 | } |
| 1787 | |
| 1788 | /** |
| 1789 | * dbg_check_idx_size - check index size. |
| 1790 | * @c: UBIFS file-system description object |
| 1791 | * @idx_size: size to check |
| 1792 | * |
| 1793 | * This function walks the UBIFS index, calculates its size and checks that the |
| 1794 | * size is equivalent to @idx_size. Returns zero in case of success and a |
| 1795 | * negative error code in case of failure. |
| 1796 | */ |
| 1797 | int dbg_check_idx_size(struct ubifs_info *c, long long idx_size) |
| 1798 | { |
| 1799 | int err; |
| 1800 | long long calc = 0; |
| 1801 | |
Artem Bityutskiy | 8d7819b | 2011-06-03 08:53:35 +0300 | [diff] [blame] | 1802 | if (!dbg_is_chk_index(c)) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1803 | return 0; |
| 1804 | |
| 1805 | err = dbg_walk_index(c, NULL, add_size, &calc); |
| 1806 | if (err) { |
| 1807 | ubifs_err("error %d while walking the index", err); |
| 1808 | return err; |
| 1809 | } |
| 1810 | |
| 1811 | if (calc != idx_size) { |
| 1812 | ubifs_err("index size check failed: calculated size is %lld, " |
| 1813 | "should be %lld", calc, idx_size); |
| 1814 | dump_stack(); |
| 1815 | return -EINVAL; |
| 1816 | } |
| 1817 | |
| 1818 | return 0; |
| 1819 | } |
| 1820 | |
| 1821 | /** |
| 1822 | * struct fsck_inode - information about an inode used when checking the file-system. |
| 1823 | * @rb: link in the RB-tree of inodes |
| 1824 | * @inum: inode number |
| 1825 | * @mode: inode type, permissions, etc |
| 1826 | * @nlink: inode link count |
| 1827 | * @xattr_cnt: count of extended attributes |
| 1828 | * @references: how many directory/xattr entries refer this inode (calculated |
| 1829 | * while walking the index) |
| 1830 | * @calc_cnt: for directory inode count of child directories |
| 1831 | * @size: inode size (read from on-flash inode) |
| 1832 | * @xattr_sz: summary size of all extended attributes (read from on-flash |
| 1833 | * inode) |
| 1834 | * @calc_sz: for directories calculated directory size |
| 1835 | * @calc_xcnt: count of extended attributes |
| 1836 | * @calc_xsz: calculated summary size of all extended attributes |
| 1837 | * @xattr_nms: sum of lengths of all extended attribute names belonging to this |
| 1838 | * inode (read from on-flash inode) |
| 1839 | * @calc_xnms: calculated sum of lengths of all extended attribute names |
| 1840 | */ |
| 1841 | struct fsck_inode { |
| 1842 | struct rb_node rb; |
| 1843 | ino_t inum; |
| 1844 | umode_t mode; |
| 1845 | unsigned int nlink; |
| 1846 | unsigned int xattr_cnt; |
| 1847 | int references; |
| 1848 | int calc_cnt; |
| 1849 | long long size; |
| 1850 | unsigned int xattr_sz; |
| 1851 | long long calc_sz; |
| 1852 | long long calc_xcnt; |
| 1853 | long long calc_xsz; |
| 1854 | unsigned int xattr_nms; |
| 1855 | long long calc_xnms; |
| 1856 | }; |
| 1857 | |
| 1858 | /** |
| 1859 | * struct fsck_data - private FS checking information. |
| 1860 | * @inodes: RB-tree of all inodes (contains @struct fsck_inode objects) |
| 1861 | */ |
| 1862 | struct fsck_data { |
| 1863 | struct rb_root inodes; |
| 1864 | }; |
| 1865 | |
| 1866 | /** |
| 1867 | * add_inode - add inode information to RB-tree of inodes. |
| 1868 | * @c: UBIFS file-system description object |
| 1869 | * @fsckd: FS checking information |
| 1870 | * @ino: raw UBIFS inode to add |
| 1871 | * |
| 1872 | * This is a helper function for 'check_leaf()' which adds information about |
| 1873 | * inode @ino to the RB-tree of inodes. Returns inode information pointer in |
| 1874 | * case of success and a negative error code in case of failure. |
| 1875 | */ |
| 1876 | static struct fsck_inode *add_inode(struct ubifs_info *c, |
| 1877 | struct fsck_data *fsckd, |
| 1878 | struct ubifs_ino_node *ino) |
| 1879 | { |
| 1880 | struct rb_node **p, *parent = NULL; |
| 1881 | struct fsck_inode *fscki; |
| 1882 | ino_t inum = key_inum_flash(c, &ino->key); |
Artem Bityutskiy | 45cd5cd | 2011-05-02 22:34:39 +0300 | [diff] [blame] | 1883 | struct inode *inode; |
| 1884 | struct ubifs_inode *ui; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1885 | |
| 1886 | p = &fsckd->inodes.rb_node; |
| 1887 | while (*p) { |
| 1888 | parent = *p; |
| 1889 | fscki = rb_entry(parent, struct fsck_inode, rb); |
| 1890 | if (inum < fscki->inum) |
| 1891 | p = &(*p)->rb_left; |
| 1892 | else if (inum > fscki->inum) |
| 1893 | p = &(*p)->rb_right; |
| 1894 | else |
| 1895 | return fscki; |
| 1896 | } |
| 1897 | |
| 1898 | if (inum > c->highest_inum) { |
| 1899 | ubifs_err("too high inode number, max. is %lu", |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 1900 | (unsigned long)c->highest_inum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1901 | return ERR_PTR(-EINVAL); |
| 1902 | } |
| 1903 | |
| 1904 | fscki = kzalloc(sizeof(struct fsck_inode), GFP_NOFS); |
| 1905 | if (!fscki) |
| 1906 | return ERR_PTR(-ENOMEM); |
| 1907 | |
Artem Bityutskiy | 45cd5cd | 2011-05-02 22:34:39 +0300 | [diff] [blame] | 1908 | inode = ilookup(c->vfs_sb, inum); |
| 1909 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1910 | fscki->inum = inum; |
Artem Bityutskiy | 45cd5cd | 2011-05-02 22:34:39 +0300 | [diff] [blame] | 1911 | /* |
| 1912 | * If the inode is present in the VFS inode cache, use it instead of |
| 1913 | * the on-flash inode which might be out-of-date. E.g., the size might |
| 1914 | * be out-of-date. If we do not do this, the following may happen, for |
| 1915 | * example: |
| 1916 | * 1. A power cut happens |
| 1917 | * 2. We mount the file-system R/O, the replay process fixes up the |
| 1918 | * inode size in the VFS cache, but on on-flash. |
| 1919 | * 3. 'check_leaf()' fails because it hits a data node beyond inode |
| 1920 | * size. |
| 1921 | */ |
| 1922 | if (!inode) { |
| 1923 | fscki->nlink = le32_to_cpu(ino->nlink); |
| 1924 | fscki->size = le64_to_cpu(ino->size); |
| 1925 | fscki->xattr_cnt = le32_to_cpu(ino->xattr_cnt); |
| 1926 | fscki->xattr_sz = le32_to_cpu(ino->xattr_size); |
| 1927 | fscki->xattr_nms = le32_to_cpu(ino->xattr_names); |
| 1928 | fscki->mode = le32_to_cpu(ino->mode); |
| 1929 | } else { |
| 1930 | ui = ubifs_inode(inode); |
| 1931 | fscki->nlink = inode->i_nlink; |
| 1932 | fscki->size = inode->i_size; |
| 1933 | fscki->xattr_cnt = ui->xattr_cnt; |
| 1934 | fscki->xattr_sz = ui->xattr_size; |
| 1935 | fscki->xattr_nms = ui->xattr_names; |
| 1936 | fscki->mode = inode->i_mode; |
| 1937 | iput(inode); |
| 1938 | } |
| 1939 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1940 | if (S_ISDIR(fscki->mode)) { |
| 1941 | fscki->calc_sz = UBIFS_INO_NODE_SZ; |
| 1942 | fscki->calc_cnt = 2; |
| 1943 | } |
Artem Bityutskiy | 45cd5cd | 2011-05-02 22:34:39 +0300 | [diff] [blame] | 1944 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1945 | rb_link_node(&fscki->rb, parent, p); |
| 1946 | rb_insert_color(&fscki->rb, &fsckd->inodes); |
Artem Bityutskiy | 45cd5cd | 2011-05-02 22:34:39 +0300 | [diff] [blame] | 1947 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 1948 | return fscki; |
| 1949 | } |
| 1950 | |
| 1951 | /** |
| 1952 | * search_inode - search inode in the RB-tree of inodes. |
| 1953 | * @fsckd: FS checking information |
| 1954 | * @inum: inode number to search |
| 1955 | * |
| 1956 | * This is a helper function for 'check_leaf()' which searches inode @inum in |
| 1957 | * the RB-tree of inodes and returns an inode information pointer or %NULL if |
| 1958 | * the inode was not found. |
| 1959 | */ |
| 1960 | static struct fsck_inode *search_inode(struct fsck_data *fsckd, ino_t inum) |
| 1961 | { |
| 1962 | struct rb_node *p; |
| 1963 | struct fsck_inode *fscki; |
| 1964 | |
| 1965 | p = fsckd->inodes.rb_node; |
| 1966 | while (p) { |
| 1967 | fscki = rb_entry(p, struct fsck_inode, rb); |
| 1968 | if (inum < fscki->inum) |
| 1969 | p = p->rb_left; |
| 1970 | else if (inum > fscki->inum) |
| 1971 | p = p->rb_right; |
| 1972 | else |
| 1973 | return fscki; |
| 1974 | } |
| 1975 | return NULL; |
| 1976 | } |
| 1977 | |
| 1978 | /** |
| 1979 | * read_add_inode - read inode node and add it to RB-tree of inodes. |
| 1980 | * @c: UBIFS file-system description object |
| 1981 | * @fsckd: FS checking information |
| 1982 | * @inum: inode number to read |
| 1983 | * |
| 1984 | * This is a helper function for 'check_leaf()' which finds inode node @inum in |
| 1985 | * the index, reads it, and adds it to the RB-tree of inodes. Returns inode |
| 1986 | * information pointer in case of success and a negative error code in case of |
| 1987 | * failure. |
| 1988 | */ |
| 1989 | static struct fsck_inode *read_add_inode(struct ubifs_info *c, |
| 1990 | struct fsck_data *fsckd, ino_t inum) |
| 1991 | { |
| 1992 | int n, err; |
| 1993 | union ubifs_key key; |
| 1994 | struct ubifs_znode *znode; |
| 1995 | struct ubifs_zbranch *zbr; |
| 1996 | struct ubifs_ino_node *ino; |
| 1997 | struct fsck_inode *fscki; |
| 1998 | |
| 1999 | fscki = search_inode(fsckd, inum); |
| 2000 | if (fscki) |
| 2001 | return fscki; |
| 2002 | |
| 2003 | ino_key_init(c, &key, inum); |
| 2004 | err = ubifs_lookup_level0(c, &key, &znode, &n); |
| 2005 | if (!err) { |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2006 | ubifs_err("inode %lu not found in index", (unsigned long)inum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2007 | return ERR_PTR(-ENOENT); |
| 2008 | } else if (err < 0) { |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2009 | ubifs_err("error %d while looking up inode %lu", |
| 2010 | err, (unsigned long)inum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2011 | return ERR_PTR(err); |
| 2012 | } |
| 2013 | |
| 2014 | zbr = &znode->zbranch[n]; |
| 2015 | if (zbr->len < UBIFS_INO_NODE_SZ) { |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2016 | ubifs_err("bad node %lu node length %d", |
| 2017 | (unsigned long)inum, zbr->len); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2018 | return ERR_PTR(-EINVAL); |
| 2019 | } |
| 2020 | |
| 2021 | ino = kmalloc(zbr->len, GFP_NOFS); |
| 2022 | if (!ino) |
| 2023 | return ERR_PTR(-ENOMEM); |
| 2024 | |
| 2025 | err = ubifs_tnc_read_node(c, zbr, ino); |
| 2026 | if (err) { |
| 2027 | ubifs_err("cannot read inode node at LEB %d:%d, error %d", |
| 2028 | zbr->lnum, zbr->offs, err); |
| 2029 | kfree(ino); |
| 2030 | return ERR_PTR(err); |
| 2031 | } |
| 2032 | |
| 2033 | fscki = add_inode(c, fsckd, ino); |
| 2034 | kfree(ino); |
| 2035 | if (IS_ERR(fscki)) { |
| 2036 | ubifs_err("error %ld while adding inode %lu node", |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2037 | PTR_ERR(fscki), (unsigned long)inum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2038 | return fscki; |
| 2039 | } |
| 2040 | |
| 2041 | return fscki; |
| 2042 | } |
| 2043 | |
| 2044 | /** |
| 2045 | * check_leaf - check leaf node. |
| 2046 | * @c: UBIFS file-system description object |
| 2047 | * @zbr: zbranch of the leaf node to check |
| 2048 | * @priv: FS checking information |
| 2049 | * |
| 2050 | * This is a helper function for 'dbg_check_filesystem()' which is called for |
| 2051 | * every single leaf node while walking the indexing tree. It checks that the |
| 2052 | * leaf node referred from the indexing tree exists, has correct CRC, and does |
| 2053 | * some other basic validation. This function is also responsible for building |
| 2054 | * an RB-tree of inodes - it adds all inodes into the RB-tree. It also |
| 2055 | * calculates reference count, size, etc for each inode in order to later |
| 2056 | * compare them to the information stored inside the inodes and detect possible |
| 2057 | * inconsistencies. Returns zero in case of success and a negative error code |
| 2058 | * in case of failure. |
| 2059 | */ |
| 2060 | static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr, |
| 2061 | void *priv) |
| 2062 | { |
| 2063 | ino_t inum; |
| 2064 | void *node; |
| 2065 | struct ubifs_ch *ch; |
| 2066 | int err, type = key_type(c, &zbr->key); |
| 2067 | struct fsck_inode *fscki; |
| 2068 | |
| 2069 | if (zbr->len < UBIFS_CH_SZ) { |
| 2070 | ubifs_err("bad leaf length %d (LEB %d:%d)", |
| 2071 | zbr->len, zbr->lnum, zbr->offs); |
| 2072 | return -EINVAL; |
| 2073 | } |
| 2074 | |
| 2075 | node = kmalloc(zbr->len, GFP_NOFS); |
| 2076 | if (!node) |
| 2077 | return -ENOMEM; |
| 2078 | |
| 2079 | err = ubifs_tnc_read_node(c, zbr, node); |
| 2080 | if (err) { |
| 2081 | ubifs_err("cannot read leaf node at LEB %d:%d, error %d", |
| 2082 | zbr->lnum, zbr->offs, err); |
| 2083 | goto out_free; |
| 2084 | } |
| 2085 | |
| 2086 | /* If this is an inode node, add it to RB-tree of inodes */ |
| 2087 | if (type == UBIFS_INO_KEY) { |
| 2088 | fscki = add_inode(c, priv, node); |
| 2089 | if (IS_ERR(fscki)) { |
| 2090 | err = PTR_ERR(fscki); |
| 2091 | ubifs_err("error %d while adding inode node", err); |
| 2092 | goto out_dump; |
| 2093 | } |
| 2094 | goto out; |
| 2095 | } |
| 2096 | |
| 2097 | if (type != UBIFS_DENT_KEY && type != UBIFS_XENT_KEY && |
| 2098 | type != UBIFS_DATA_KEY) { |
| 2099 | ubifs_err("unexpected node type %d at LEB %d:%d", |
| 2100 | type, zbr->lnum, zbr->offs); |
| 2101 | err = -EINVAL; |
| 2102 | goto out_free; |
| 2103 | } |
| 2104 | |
| 2105 | ch = node; |
| 2106 | if (le64_to_cpu(ch->sqnum) > c->max_sqnum) { |
| 2107 | ubifs_err("too high sequence number, max. is %llu", |
| 2108 | c->max_sqnum); |
| 2109 | err = -EINVAL; |
| 2110 | goto out_dump; |
| 2111 | } |
| 2112 | |
| 2113 | if (type == UBIFS_DATA_KEY) { |
| 2114 | long long blk_offs; |
| 2115 | struct ubifs_data_node *dn = node; |
| 2116 | |
| 2117 | /* |
| 2118 | * Search the inode node this data node belongs to and insert |
| 2119 | * it to the RB-tree of inodes. |
| 2120 | */ |
| 2121 | inum = key_inum_flash(c, &dn->key); |
| 2122 | fscki = read_add_inode(c, priv, inum); |
| 2123 | if (IS_ERR(fscki)) { |
| 2124 | err = PTR_ERR(fscki); |
| 2125 | ubifs_err("error %d while processing data node and " |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2126 | "trying to find inode node %lu", |
| 2127 | err, (unsigned long)inum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2128 | goto out_dump; |
| 2129 | } |
| 2130 | |
| 2131 | /* Make sure the data node is within inode size */ |
| 2132 | blk_offs = key_block_flash(c, &dn->key); |
| 2133 | blk_offs <<= UBIFS_BLOCK_SHIFT; |
| 2134 | blk_offs += le32_to_cpu(dn->size); |
| 2135 | if (blk_offs > fscki->size) { |
| 2136 | ubifs_err("data node at LEB %d:%d is not within inode " |
| 2137 | "size %lld", zbr->lnum, zbr->offs, |
| 2138 | fscki->size); |
| 2139 | err = -EINVAL; |
| 2140 | goto out_dump; |
| 2141 | } |
| 2142 | } else { |
| 2143 | int nlen; |
| 2144 | struct ubifs_dent_node *dent = node; |
| 2145 | struct fsck_inode *fscki1; |
| 2146 | |
| 2147 | err = ubifs_validate_entry(c, dent); |
| 2148 | if (err) |
| 2149 | goto out_dump; |
| 2150 | |
| 2151 | /* |
| 2152 | * Search the inode node this entry refers to and the parent |
| 2153 | * inode node and insert them to the RB-tree of inodes. |
| 2154 | */ |
| 2155 | inum = le64_to_cpu(dent->inum); |
| 2156 | fscki = read_add_inode(c, priv, inum); |
| 2157 | if (IS_ERR(fscki)) { |
| 2158 | err = PTR_ERR(fscki); |
| 2159 | ubifs_err("error %d while processing entry node and " |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2160 | "trying to find inode node %lu", |
| 2161 | err, (unsigned long)inum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2162 | goto out_dump; |
| 2163 | } |
| 2164 | |
| 2165 | /* Count how many direntries or xentries refers this inode */ |
| 2166 | fscki->references += 1; |
| 2167 | |
| 2168 | inum = key_inum_flash(c, &dent->key); |
| 2169 | fscki1 = read_add_inode(c, priv, inum); |
| 2170 | if (IS_ERR(fscki1)) { |
Roel Kluin | b38882f | 2009-12-07 14:21:45 +0100 | [diff] [blame] | 2171 | err = PTR_ERR(fscki1); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2172 | ubifs_err("error %d while processing entry node and " |
| 2173 | "trying to find parent inode node %lu", |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2174 | err, (unsigned long)inum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2175 | goto out_dump; |
| 2176 | } |
| 2177 | |
| 2178 | nlen = le16_to_cpu(dent->nlen); |
| 2179 | if (type == UBIFS_XENT_KEY) { |
| 2180 | fscki1->calc_xcnt += 1; |
| 2181 | fscki1->calc_xsz += CALC_DENT_SIZE(nlen); |
| 2182 | fscki1->calc_xsz += CALC_XATTR_BYTES(fscki->size); |
| 2183 | fscki1->calc_xnms += nlen; |
| 2184 | } else { |
| 2185 | fscki1->calc_sz += CALC_DENT_SIZE(nlen); |
| 2186 | if (dent->type == UBIFS_ITYPE_DIR) |
| 2187 | fscki1->calc_cnt += 1; |
| 2188 | } |
| 2189 | } |
| 2190 | |
| 2191 | out: |
| 2192 | kfree(node); |
| 2193 | return 0; |
| 2194 | |
| 2195 | out_dump: |
| 2196 | ubifs_msg("dump of node at LEB %d:%d", zbr->lnum, zbr->offs); |
| 2197 | dbg_dump_node(c, node); |
| 2198 | out_free: |
| 2199 | kfree(node); |
| 2200 | return err; |
| 2201 | } |
| 2202 | |
| 2203 | /** |
| 2204 | * free_inodes - free RB-tree of inodes. |
| 2205 | * @fsckd: FS checking information |
| 2206 | */ |
| 2207 | static void free_inodes(struct fsck_data *fsckd) |
| 2208 | { |
| 2209 | struct rb_node *this = fsckd->inodes.rb_node; |
| 2210 | struct fsck_inode *fscki; |
| 2211 | |
| 2212 | while (this) { |
| 2213 | if (this->rb_left) |
| 2214 | this = this->rb_left; |
| 2215 | else if (this->rb_right) |
| 2216 | this = this->rb_right; |
| 2217 | else { |
| 2218 | fscki = rb_entry(this, struct fsck_inode, rb); |
| 2219 | this = rb_parent(this); |
| 2220 | if (this) { |
| 2221 | if (this->rb_left == &fscki->rb) |
| 2222 | this->rb_left = NULL; |
| 2223 | else |
| 2224 | this->rb_right = NULL; |
| 2225 | } |
| 2226 | kfree(fscki); |
| 2227 | } |
| 2228 | } |
| 2229 | } |
| 2230 | |
| 2231 | /** |
| 2232 | * check_inodes - checks all inodes. |
| 2233 | * @c: UBIFS file-system description object |
| 2234 | * @fsckd: FS checking information |
| 2235 | * |
| 2236 | * This is a helper function for 'dbg_check_filesystem()' which walks the |
| 2237 | * RB-tree of inodes after the index scan has been finished, and checks that |
| 2238 | * inode nlink, size, etc are correct. Returns zero if inodes are fine, |
| 2239 | * %-EINVAL if not, and a negative error code in case of failure. |
| 2240 | */ |
| 2241 | static int check_inodes(struct ubifs_info *c, struct fsck_data *fsckd) |
| 2242 | { |
| 2243 | int n, err; |
| 2244 | union ubifs_key key; |
| 2245 | struct ubifs_znode *znode; |
| 2246 | struct ubifs_zbranch *zbr; |
| 2247 | struct ubifs_ino_node *ino; |
| 2248 | struct fsck_inode *fscki; |
| 2249 | struct rb_node *this = rb_first(&fsckd->inodes); |
| 2250 | |
| 2251 | while (this) { |
| 2252 | fscki = rb_entry(this, struct fsck_inode, rb); |
| 2253 | this = rb_next(this); |
| 2254 | |
| 2255 | if (S_ISDIR(fscki->mode)) { |
| 2256 | /* |
| 2257 | * Directories have to have exactly one reference (they |
| 2258 | * cannot have hardlinks), although root inode is an |
| 2259 | * exception. |
| 2260 | */ |
| 2261 | if (fscki->inum != UBIFS_ROOT_INO && |
| 2262 | fscki->references != 1) { |
| 2263 | ubifs_err("directory inode %lu has %d " |
| 2264 | "direntries which refer it, but " |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2265 | "should be 1", |
| 2266 | (unsigned long)fscki->inum, |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2267 | fscki->references); |
| 2268 | goto out_dump; |
| 2269 | } |
| 2270 | if (fscki->inum == UBIFS_ROOT_INO && |
| 2271 | fscki->references != 0) { |
| 2272 | ubifs_err("root inode %lu has non-zero (%d) " |
| 2273 | "direntries which refer it", |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2274 | (unsigned long)fscki->inum, |
| 2275 | fscki->references); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2276 | goto out_dump; |
| 2277 | } |
| 2278 | if (fscki->calc_sz != fscki->size) { |
| 2279 | ubifs_err("directory inode %lu size is %lld, " |
| 2280 | "but calculated size is %lld", |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2281 | (unsigned long)fscki->inum, |
| 2282 | fscki->size, fscki->calc_sz); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2283 | goto out_dump; |
| 2284 | } |
| 2285 | if (fscki->calc_cnt != fscki->nlink) { |
| 2286 | ubifs_err("directory inode %lu nlink is %d, " |
| 2287 | "but calculated nlink is %d", |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2288 | (unsigned long)fscki->inum, |
| 2289 | fscki->nlink, fscki->calc_cnt); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2290 | goto out_dump; |
| 2291 | } |
| 2292 | } else { |
| 2293 | if (fscki->references != fscki->nlink) { |
| 2294 | ubifs_err("inode %lu nlink is %d, but " |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2295 | "calculated nlink is %d", |
| 2296 | (unsigned long)fscki->inum, |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2297 | fscki->nlink, fscki->references); |
| 2298 | goto out_dump; |
| 2299 | } |
| 2300 | } |
| 2301 | if (fscki->xattr_sz != fscki->calc_xsz) { |
| 2302 | ubifs_err("inode %lu has xattr size %u, but " |
| 2303 | "calculated size is %lld", |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2304 | (unsigned long)fscki->inum, fscki->xattr_sz, |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2305 | fscki->calc_xsz); |
| 2306 | goto out_dump; |
| 2307 | } |
| 2308 | if (fscki->xattr_cnt != fscki->calc_xcnt) { |
| 2309 | ubifs_err("inode %lu has %u xattrs, but " |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2310 | "calculated count is %lld", |
| 2311 | (unsigned long)fscki->inum, |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2312 | fscki->xattr_cnt, fscki->calc_xcnt); |
| 2313 | goto out_dump; |
| 2314 | } |
| 2315 | if (fscki->xattr_nms != fscki->calc_xnms) { |
| 2316 | ubifs_err("inode %lu has xattr names' size %u, but " |
| 2317 | "calculated names' size is %lld", |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2318 | (unsigned long)fscki->inum, fscki->xattr_nms, |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2319 | fscki->calc_xnms); |
| 2320 | goto out_dump; |
| 2321 | } |
| 2322 | } |
| 2323 | |
| 2324 | return 0; |
| 2325 | |
| 2326 | out_dump: |
| 2327 | /* Read the bad inode and dump it */ |
| 2328 | ino_key_init(c, &key, fscki->inum); |
| 2329 | err = ubifs_lookup_level0(c, &key, &znode, &n); |
| 2330 | if (!err) { |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2331 | ubifs_err("inode %lu not found in index", |
| 2332 | (unsigned long)fscki->inum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2333 | return -ENOENT; |
| 2334 | } else if (err < 0) { |
| 2335 | ubifs_err("error %d while looking up inode %lu", |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2336 | err, (unsigned long)fscki->inum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2337 | return err; |
| 2338 | } |
| 2339 | |
| 2340 | zbr = &znode->zbranch[n]; |
| 2341 | ino = kmalloc(zbr->len, GFP_NOFS); |
| 2342 | if (!ino) |
| 2343 | return -ENOMEM; |
| 2344 | |
| 2345 | err = ubifs_tnc_read_node(c, zbr, ino); |
| 2346 | if (err) { |
| 2347 | ubifs_err("cannot read inode node at LEB %d:%d, error %d", |
| 2348 | zbr->lnum, zbr->offs, err); |
| 2349 | kfree(ino); |
| 2350 | return err; |
| 2351 | } |
| 2352 | |
| 2353 | ubifs_msg("dump of the inode %lu sitting in LEB %d:%d", |
Artem Bityutskiy | e84461a | 2008-10-29 12:08:43 +0200 | [diff] [blame] | 2354 | (unsigned long)fscki->inum, zbr->lnum, zbr->offs); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2355 | dbg_dump_node(c, ino); |
| 2356 | kfree(ino); |
| 2357 | return -EINVAL; |
| 2358 | } |
| 2359 | |
| 2360 | /** |
| 2361 | * dbg_check_filesystem - check the file-system. |
| 2362 | * @c: UBIFS file-system description object |
| 2363 | * |
| 2364 | * This function checks the file system, namely: |
| 2365 | * o makes sure that all leaf nodes exist and their CRCs are correct; |
| 2366 | * o makes sure inode nlink, size, xattr size/count are correct (for all |
| 2367 | * inodes). |
| 2368 | * |
| 2369 | * The function reads whole indexing tree and all nodes, so it is pretty |
| 2370 | * heavy-weight. Returns zero if the file-system is consistent, %-EINVAL if |
| 2371 | * not, and a negative error code in case of failure. |
| 2372 | */ |
| 2373 | int dbg_check_filesystem(struct ubifs_info *c) |
| 2374 | { |
| 2375 | int err; |
| 2376 | struct fsck_data fsckd; |
| 2377 | |
Artem Bityutskiy | 2b1844a | 2011-06-03 08:31:29 +0300 | [diff] [blame] | 2378 | if (!dbg_is_chk_fs(c)) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2379 | return 0; |
| 2380 | |
| 2381 | fsckd.inodes = RB_ROOT; |
| 2382 | err = dbg_walk_index(c, check_leaf, NULL, &fsckd); |
| 2383 | if (err) |
| 2384 | goto out_free; |
| 2385 | |
| 2386 | err = check_inodes(c, &fsckd); |
| 2387 | if (err) |
| 2388 | goto out_free; |
| 2389 | |
| 2390 | free_inodes(&fsckd); |
| 2391 | return 0; |
| 2392 | |
| 2393 | out_free: |
| 2394 | ubifs_err("file-system check failed with error %d", err); |
| 2395 | dump_stack(); |
| 2396 | free_inodes(&fsckd); |
| 2397 | return err; |
| 2398 | } |
| 2399 | |
Artem Bityutskiy | 3bb66b4 | 2010-08-07 10:06:11 +0300 | [diff] [blame] | 2400 | /** |
| 2401 | * dbg_check_data_nodes_order - check that list of data nodes is sorted. |
| 2402 | * @c: UBIFS file-system description object |
| 2403 | * @head: the list of nodes ('struct ubifs_scan_node' objects) |
| 2404 | * |
| 2405 | * This function returns zero if the list of data nodes is sorted correctly, |
| 2406 | * and %-EINVAL if not. |
| 2407 | */ |
| 2408 | int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head) |
| 2409 | { |
| 2410 | struct list_head *cur; |
| 2411 | struct ubifs_scan_node *sa, *sb; |
| 2412 | |
Artem Bityutskiy | 2b1844a | 2011-06-03 08:31:29 +0300 | [diff] [blame] | 2413 | if (!dbg_is_chk_gen(c)) |
Artem Bityutskiy | 3bb66b4 | 2010-08-07 10:06:11 +0300 | [diff] [blame] | 2414 | return 0; |
| 2415 | |
| 2416 | for (cur = head->next; cur->next != head; cur = cur->next) { |
| 2417 | ino_t inuma, inumb; |
| 2418 | uint32_t blka, blkb; |
| 2419 | |
| 2420 | cond_resched(); |
| 2421 | sa = container_of(cur, struct ubifs_scan_node, list); |
| 2422 | sb = container_of(cur->next, struct ubifs_scan_node, list); |
| 2423 | |
| 2424 | if (sa->type != UBIFS_DATA_NODE) { |
| 2425 | ubifs_err("bad node type %d", sa->type); |
| 2426 | dbg_dump_node(c, sa->node); |
| 2427 | return -EINVAL; |
| 2428 | } |
| 2429 | if (sb->type != UBIFS_DATA_NODE) { |
| 2430 | ubifs_err("bad node type %d", sb->type); |
| 2431 | dbg_dump_node(c, sb->node); |
| 2432 | return -EINVAL; |
| 2433 | } |
| 2434 | |
| 2435 | inuma = key_inum(c, &sa->key); |
| 2436 | inumb = key_inum(c, &sb->key); |
| 2437 | |
| 2438 | if (inuma < inumb) |
| 2439 | continue; |
| 2440 | if (inuma > inumb) { |
| 2441 | ubifs_err("larger inum %lu goes before inum %lu", |
| 2442 | (unsigned long)inuma, (unsigned long)inumb); |
| 2443 | goto error_dump; |
| 2444 | } |
| 2445 | |
| 2446 | blka = key_block(c, &sa->key); |
| 2447 | blkb = key_block(c, &sb->key); |
| 2448 | |
| 2449 | if (blka > blkb) { |
| 2450 | ubifs_err("larger block %u goes before %u", blka, blkb); |
| 2451 | goto error_dump; |
| 2452 | } |
| 2453 | if (blka == blkb) { |
| 2454 | ubifs_err("two data nodes for the same block"); |
| 2455 | goto error_dump; |
| 2456 | } |
| 2457 | } |
| 2458 | |
| 2459 | return 0; |
| 2460 | |
| 2461 | error_dump: |
| 2462 | dbg_dump_node(c, sa->node); |
| 2463 | dbg_dump_node(c, sb->node); |
| 2464 | return -EINVAL; |
| 2465 | } |
| 2466 | |
| 2467 | /** |
| 2468 | * dbg_check_nondata_nodes_order - check that list of data nodes is sorted. |
| 2469 | * @c: UBIFS file-system description object |
| 2470 | * @head: the list of nodes ('struct ubifs_scan_node' objects) |
| 2471 | * |
| 2472 | * This function returns zero if the list of non-data nodes is sorted correctly, |
| 2473 | * and %-EINVAL if not. |
| 2474 | */ |
| 2475 | int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head) |
| 2476 | { |
| 2477 | struct list_head *cur; |
| 2478 | struct ubifs_scan_node *sa, *sb; |
| 2479 | |
Artem Bityutskiy | 2b1844a | 2011-06-03 08:31:29 +0300 | [diff] [blame] | 2480 | if (!dbg_is_chk_gen(c)) |
Artem Bityutskiy | 3bb66b4 | 2010-08-07 10:06:11 +0300 | [diff] [blame] | 2481 | return 0; |
| 2482 | |
| 2483 | for (cur = head->next; cur->next != head; cur = cur->next) { |
| 2484 | ino_t inuma, inumb; |
| 2485 | uint32_t hasha, hashb; |
| 2486 | |
| 2487 | cond_resched(); |
| 2488 | sa = container_of(cur, struct ubifs_scan_node, list); |
| 2489 | sb = container_of(cur->next, struct ubifs_scan_node, list); |
| 2490 | |
| 2491 | if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE && |
| 2492 | sa->type != UBIFS_XENT_NODE) { |
| 2493 | ubifs_err("bad node type %d", sa->type); |
| 2494 | dbg_dump_node(c, sa->node); |
| 2495 | return -EINVAL; |
| 2496 | } |
| 2497 | if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE && |
| 2498 | sa->type != UBIFS_XENT_NODE) { |
| 2499 | ubifs_err("bad node type %d", sb->type); |
| 2500 | dbg_dump_node(c, sb->node); |
| 2501 | return -EINVAL; |
| 2502 | } |
| 2503 | |
| 2504 | if (sa->type != UBIFS_INO_NODE && sb->type == UBIFS_INO_NODE) { |
| 2505 | ubifs_err("non-inode node goes before inode node"); |
| 2506 | goto error_dump; |
| 2507 | } |
| 2508 | |
| 2509 | if (sa->type == UBIFS_INO_NODE && sb->type != UBIFS_INO_NODE) |
| 2510 | continue; |
| 2511 | |
| 2512 | if (sa->type == UBIFS_INO_NODE && sb->type == UBIFS_INO_NODE) { |
| 2513 | /* Inode nodes are sorted in descending size order */ |
| 2514 | if (sa->len < sb->len) { |
| 2515 | ubifs_err("smaller inode node goes first"); |
| 2516 | goto error_dump; |
| 2517 | } |
| 2518 | continue; |
| 2519 | } |
| 2520 | |
| 2521 | /* |
| 2522 | * This is either a dentry or xentry, which should be sorted in |
| 2523 | * ascending (parent ino, hash) order. |
| 2524 | */ |
| 2525 | inuma = key_inum(c, &sa->key); |
| 2526 | inumb = key_inum(c, &sb->key); |
| 2527 | |
| 2528 | if (inuma < inumb) |
| 2529 | continue; |
| 2530 | if (inuma > inumb) { |
| 2531 | ubifs_err("larger inum %lu goes before inum %lu", |
| 2532 | (unsigned long)inuma, (unsigned long)inumb); |
| 2533 | goto error_dump; |
| 2534 | } |
| 2535 | |
| 2536 | hasha = key_block(c, &sa->key); |
| 2537 | hashb = key_block(c, &sb->key); |
| 2538 | |
| 2539 | if (hasha > hashb) { |
Artem Bityutskiy | c436157 | 2011-03-25 15:27:40 +0200 | [diff] [blame] | 2540 | ubifs_err("larger hash %u goes before %u", |
| 2541 | hasha, hashb); |
Artem Bityutskiy | 3bb66b4 | 2010-08-07 10:06:11 +0300 | [diff] [blame] | 2542 | goto error_dump; |
| 2543 | } |
| 2544 | } |
| 2545 | |
| 2546 | return 0; |
| 2547 | |
| 2548 | error_dump: |
| 2549 | ubifs_msg("dumping first node"); |
| 2550 | dbg_dump_node(c, sa->node); |
| 2551 | ubifs_msg("dumping second node"); |
| 2552 | dbg_dump_node(c, sb->node); |
| 2553 | return -EINVAL; |
| 2554 | return 0; |
| 2555 | } |
| 2556 | |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2557 | static inline int chance(unsigned int n, unsigned int out_of) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2558 | { |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2559 | return !!((random32() % out_of) + 1 <= n); |
| 2560 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2561 | } |
| 2562 | |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2563 | static int power_cut_emulated(struct ubifs_info *c, int lnum, int write) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2564 | { |
Artem Bityutskiy | f57cb18 | 2011-06-03 14:51:41 +0300 | [diff] [blame] | 2565 | struct ubifs_debug_info *d = c->dbg; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2566 | |
Artem Bityutskiy | f57cb18 | 2011-06-03 14:51:41 +0300 | [diff] [blame] | 2567 | ubifs_assert(dbg_is_tst_rcvry(c)); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2568 | |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2569 | if (!d->pc_cnt) { |
| 2570 | /* First call - decide delay to the power cut */ |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2571 | if (chance(1, 2)) { |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2572 | unsigned long delay; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2573 | |
| 2574 | if (chance(1, 2)) { |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2575 | d->pc_delay = 1; |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2576 | /* Fail withing 1 minute */ |
| 2577 | delay = random32() % 60000; |
| 2578 | d->pc_timeout = jiffies; |
| 2579 | d->pc_timeout += msecs_to_jiffies(delay); |
| 2580 | ubifs_warn("failing after %lums", delay); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2581 | } else { |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2582 | d->pc_delay = 2; |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2583 | delay = random32() % 10000; |
| 2584 | /* Fail within 10000 operations */ |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2585 | d->pc_cnt_max = delay; |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2586 | ubifs_warn("failing after %lu calls", delay); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2587 | } |
| 2588 | } |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2589 | |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2590 | d->pc_cnt += 1; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2591 | } |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2592 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2593 | /* Determine if failure delay has expired */ |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2594 | if (d->pc_delay == 1 && time_before(jiffies, d->pc_timeout)) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2595 | return 0; |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2596 | if (d->pc_delay == 2 && d->pc_cnt++ < d->pc_cnt_max) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2597 | return 0; |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2598 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2599 | if (lnum == UBIFS_SB_LNUM) { |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2600 | if (write && chance(1, 2)) |
| 2601 | return 0; |
| 2602 | if (chance(19, 20)) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2603 | return 0; |
Artem Bityutskiy | 24a4f80 | 2011-06-01 15:23:25 +0300 | [diff] [blame] | 2604 | ubifs_warn("failing in super block LEB %d", lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2605 | } else if (lnum == UBIFS_MST_LNUM || lnum == UBIFS_MST_LNUM + 1) { |
| 2606 | if (chance(19, 20)) |
| 2607 | return 0; |
Artem Bityutskiy | 24a4f80 | 2011-06-01 15:23:25 +0300 | [diff] [blame] | 2608 | ubifs_warn("failing in master LEB %d", lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2609 | } else if (lnum >= UBIFS_LOG_LNUM && lnum <= c->log_last) { |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2610 | if (write && chance(99, 100)) |
| 2611 | return 0; |
| 2612 | if (chance(399, 400)) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2613 | return 0; |
Artem Bityutskiy | 24a4f80 | 2011-06-01 15:23:25 +0300 | [diff] [blame] | 2614 | ubifs_warn("failing in log LEB %d", lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2615 | } else if (lnum >= c->lpt_first && lnum <= c->lpt_last) { |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2616 | if (write && chance(7, 8)) |
| 2617 | return 0; |
| 2618 | if (chance(19, 20)) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2619 | return 0; |
Artem Bityutskiy | 24a4f80 | 2011-06-01 15:23:25 +0300 | [diff] [blame] | 2620 | ubifs_warn("failing in LPT LEB %d", lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2621 | } else if (lnum >= c->orph_first && lnum <= c->orph_last) { |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2622 | if (write && chance(1, 2)) |
| 2623 | return 0; |
| 2624 | if (chance(9, 10)) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2625 | return 0; |
Artem Bityutskiy | 24a4f80 | 2011-06-01 15:23:25 +0300 | [diff] [blame] | 2626 | ubifs_warn("failing in orphan LEB %d", lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2627 | } else if (lnum == c->ihead_lnum) { |
| 2628 | if (chance(99, 100)) |
| 2629 | return 0; |
Artem Bityutskiy | 24a4f80 | 2011-06-01 15:23:25 +0300 | [diff] [blame] | 2630 | ubifs_warn("failing in index head LEB %d", lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2631 | } else if (c->jheads && lnum == c->jheads[GCHD].wbuf.lnum) { |
| 2632 | if (chance(9, 10)) |
| 2633 | return 0; |
Artem Bityutskiy | 24a4f80 | 2011-06-01 15:23:25 +0300 | [diff] [blame] | 2634 | ubifs_warn("failing in GC head LEB %d", lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2635 | } else if (write && !RB_EMPTY_ROOT(&c->buds) && |
| 2636 | !ubifs_search_bud(c, lnum)) { |
| 2637 | if (chance(19, 20)) |
| 2638 | return 0; |
Artem Bityutskiy | 24a4f80 | 2011-06-01 15:23:25 +0300 | [diff] [blame] | 2639 | ubifs_warn("failing in non-bud LEB %d", lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2640 | } else if (c->cmt_state == COMMIT_RUNNING_BACKGROUND || |
| 2641 | c->cmt_state == COMMIT_RUNNING_REQUIRED) { |
| 2642 | if (chance(999, 1000)) |
| 2643 | return 0; |
Artem Bityutskiy | 24a4f80 | 2011-06-01 15:23:25 +0300 | [diff] [blame] | 2644 | ubifs_warn("failing in bud LEB %d commit running", lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2645 | } else { |
| 2646 | if (chance(9999, 10000)) |
| 2647 | return 0; |
Artem Bityutskiy | 24a4f80 | 2011-06-01 15:23:25 +0300 | [diff] [blame] | 2648 | ubifs_warn("failing in bud LEB %d commit not running", lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2649 | } |
Artem Bityutskiy | 24a4f80 | 2011-06-01 15:23:25 +0300 | [diff] [blame] | 2650 | |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2651 | d->pc_happened = 1; |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2652 | ubifs_warn("========== Power cut emulated =========="); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2653 | dump_stack(); |
| 2654 | return 1; |
| 2655 | } |
| 2656 | |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2657 | static void cut_data(const void *buf, unsigned int len) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2658 | { |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2659 | unsigned int from, to, i, ffs = chance(1, 2); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2660 | unsigned char *p = (void *)buf; |
| 2661 | |
Artem Bityutskiy | a7fa94a | 2011-06-03 16:20:03 +0300 | [diff] [blame] | 2662 | from = random32() % (len + 1); |
| 2663 | if (chance(1, 2)) |
| 2664 | to = random32() % (len - from + 1); |
| 2665 | else |
| 2666 | to = len; |
| 2667 | |
| 2668 | if (from < to) |
| 2669 | ubifs_warn("filled bytes %u-%u with %s", from, to - 1, |
| 2670 | ffs ? "0xFFs" : "random data"); |
| 2671 | |
| 2672 | if (ffs) |
| 2673 | for (i = from; i < to; i++) |
| 2674 | p[i] = 0xFF; |
| 2675 | else |
| 2676 | for (i = from; i < to; i++) |
| 2677 | p[i] = random32() % 0x100; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2678 | } |
| 2679 | |
Artem Bityutskiy | f57cb18 | 2011-06-03 14:51:41 +0300 | [diff] [blame] | 2680 | int dbg_leb_write(struct ubifs_info *c, int lnum, const void *buf, |
Artem Bityutskiy | 891a54a | 2011-06-03 11:32:21 +0300 | [diff] [blame] | 2681 | int offs, int len, int dtype) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2682 | { |
Adrian Hunter | 16dfd80 | 2008-07-18 16:47:41 +0300 | [diff] [blame] | 2683 | int err, failing; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2684 | |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2685 | if (c->dbg->pc_happened) |
Artem Bityutskiy | 1a29af8 | 2011-04-20 17:06:17 +0300 | [diff] [blame] | 2686 | return -EROFS; |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2687 | |
| 2688 | failing = power_cut_emulated(c, lnum, 1); |
Adrian Hunter | 16dfd80 | 2008-07-18 16:47:41 +0300 | [diff] [blame] | 2689 | if (failing) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2690 | cut_data(buf, len); |
Artem Bityutskiy | f57cb18 | 2011-06-03 14:51:41 +0300 | [diff] [blame] | 2691 | err = ubi_leb_write(c->ubi, lnum, buf, offs, len, dtype); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2692 | if (err) |
| 2693 | return err; |
Adrian Hunter | 16dfd80 | 2008-07-18 16:47:41 +0300 | [diff] [blame] | 2694 | if (failing) |
Artem Bityutskiy | 1a29af8 | 2011-04-20 17:06:17 +0300 | [diff] [blame] | 2695 | return -EROFS; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2696 | return 0; |
| 2697 | } |
| 2698 | |
Artem Bityutskiy | f57cb18 | 2011-06-03 14:51:41 +0300 | [diff] [blame] | 2699 | int dbg_leb_change(struct ubifs_info *c, int lnum, const void *buf, |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2700 | int len, int dtype) |
| 2701 | { |
| 2702 | int err; |
| 2703 | |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2704 | if (c->dbg->pc_happened) |
| 2705 | return -EROFS; |
| 2706 | if (power_cut_emulated(c, lnum, 1)) |
Artem Bityutskiy | 1a29af8 | 2011-04-20 17:06:17 +0300 | [diff] [blame] | 2707 | return -EROFS; |
Artem Bityutskiy | f57cb18 | 2011-06-03 14:51:41 +0300 | [diff] [blame] | 2708 | err = ubi_leb_change(c->ubi, lnum, buf, len, dtype); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2709 | if (err) |
| 2710 | return err; |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2711 | if (power_cut_emulated(c, lnum, 1)) |
Artem Bityutskiy | 1a29af8 | 2011-04-20 17:06:17 +0300 | [diff] [blame] | 2712 | return -EROFS; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2713 | return 0; |
| 2714 | } |
| 2715 | |
Artem Bityutskiy | f57cb18 | 2011-06-03 14:51:41 +0300 | [diff] [blame] | 2716 | int dbg_leb_unmap(struct ubifs_info *c, int lnum) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2717 | { |
| 2718 | int err; |
| 2719 | |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2720 | if (c->dbg->pc_happened) |
| 2721 | return -EROFS; |
| 2722 | if (power_cut_emulated(c, lnum, 0)) |
Artem Bityutskiy | 1a29af8 | 2011-04-20 17:06:17 +0300 | [diff] [blame] | 2723 | return -EROFS; |
Artem Bityutskiy | f57cb18 | 2011-06-03 14:51:41 +0300 | [diff] [blame] | 2724 | err = ubi_leb_unmap(c->ubi, lnum); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2725 | if (err) |
| 2726 | return err; |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2727 | if (power_cut_emulated(c, lnum, 0)) |
Artem Bityutskiy | 1a29af8 | 2011-04-20 17:06:17 +0300 | [diff] [blame] | 2728 | return -EROFS; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2729 | return 0; |
| 2730 | } |
| 2731 | |
Artem Bityutskiy | f57cb18 | 2011-06-03 14:51:41 +0300 | [diff] [blame] | 2732 | int dbg_leb_map(struct ubifs_info *c, int lnum, int dtype) |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2733 | { |
| 2734 | int err; |
| 2735 | |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2736 | if (c->dbg->pc_happened) |
| 2737 | return -EROFS; |
| 2738 | if (power_cut_emulated(c, lnum, 0)) |
Artem Bityutskiy | 1a29af8 | 2011-04-20 17:06:17 +0300 | [diff] [blame] | 2739 | return -EROFS; |
Artem Bityutskiy | f57cb18 | 2011-06-03 14:51:41 +0300 | [diff] [blame] | 2740 | err = ubi_leb_map(c->ubi, lnum, dtype); |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2741 | if (err) |
| 2742 | return err; |
Artem Bityutskiy | d27462a | 2011-06-03 15:10:33 +0300 | [diff] [blame] | 2743 | if (power_cut_emulated(c, lnum, 0)) |
Artem Bityutskiy | 1a29af8 | 2011-04-20 17:06:17 +0300 | [diff] [blame] | 2744 | return -EROFS; |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 2745 | return 0; |
| 2746 | } |
| 2747 | |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2748 | /* |
| 2749 | * Root directory for UBIFS stuff in debugfs. Contains sub-directories which |
| 2750 | * contain the stuff specific to particular file-system mounts. |
| 2751 | */ |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 2752 | static struct dentry *dfs_rootdir; |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2753 | |
Artem Bityutskiy | 7dae997 | 2011-06-01 15:44:14 +0300 | [diff] [blame] | 2754 | static int dfs_file_open(struct inode *inode, struct file *file) |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2755 | { |
| 2756 | file->private_data = inode->i_private; |
Artem Bityutskiy | 1bbfc84 | 2011-03-21 16:26:42 +0200 | [diff] [blame] | 2757 | return nonseekable_open(inode, file); |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2758 | } |
| 2759 | |
Artem Bityutskiy | 28488fc | 2011-06-03 09:58:23 +0300 | [diff] [blame] | 2760 | /** |
| 2761 | * provide_user_output - provide output to the user reading a debugfs file. |
| 2762 | * @val: boolean value for the answer |
| 2763 | * @u: the buffer to store the answer at |
| 2764 | * @count: size of the buffer |
| 2765 | * @ppos: position in the @u output buffer |
| 2766 | * |
| 2767 | * This is a simple helper function which stores @val boolean value in the user |
| 2768 | * buffer when the user reads one of UBIFS debugfs files. Returns amount of |
| 2769 | * bytes written to @u in case of success and a negative error code in case of |
| 2770 | * failure. |
| 2771 | */ |
| 2772 | static int provide_user_output(int val, char __user *u, size_t count, |
| 2773 | loff_t *ppos) |
| 2774 | { |
| 2775 | char buf[3]; |
| 2776 | |
| 2777 | if (val) |
| 2778 | buf[0] = '1'; |
| 2779 | else |
| 2780 | buf[0] = '0'; |
| 2781 | buf[1] = '\n'; |
| 2782 | buf[2] = 0x00; |
| 2783 | |
| 2784 | return simple_read_from_buffer(u, count, ppos, buf, 2); |
| 2785 | } |
| 2786 | |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 2787 | static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count, |
| 2788 | loff_t *ppos) |
| 2789 | { |
| 2790 | struct dentry *dent = file->f_path.dentry; |
| 2791 | struct ubifs_info *c = file->private_data; |
| 2792 | struct ubifs_debug_info *d = c->dbg; |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 2793 | int val; |
| 2794 | |
| 2795 | if (dent == d->dfs_chk_gen) |
| 2796 | val = d->chk_gen; |
| 2797 | else if (dent == d->dfs_chk_index) |
| 2798 | val = d->chk_index; |
| 2799 | else if (dent == d->dfs_chk_orph) |
| 2800 | val = d->chk_orph; |
| 2801 | else if (dent == d->dfs_chk_lprops) |
| 2802 | val = d->chk_lprops; |
| 2803 | else if (dent == d->dfs_chk_fs) |
| 2804 | val = d->chk_fs; |
| 2805 | else if (dent == d->dfs_tst_rcvry) |
| 2806 | val = d->tst_rcvry; |
| 2807 | else |
| 2808 | return -EINVAL; |
| 2809 | |
Artem Bityutskiy | 28488fc | 2011-06-03 09:58:23 +0300 | [diff] [blame] | 2810 | return provide_user_output(val, u, count, ppos); |
| 2811 | } |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 2812 | |
Artem Bityutskiy | 28488fc | 2011-06-03 09:58:23 +0300 | [diff] [blame] | 2813 | /** |
| 2814 | * interpret_user_input - interpret user debugfs file input. |
| 2815 | * @u: user-provided buffer with the input |
| 2816 | * @count: buffer size |
| 2817 | * |
| 2818 | * This is a helper function which interpret user input to a boolean UBIFS |
| 2819 | * debugfs file. Returns %0 or %1 in case of success and a negative error code |
| 2820 | * in case of failure. |
| 2821 | */ |
| 2822 | static int interpret_user_input(const char __user *u, size_t count) |
| 2823 | { |
| 2824 | size_t buf_size; |
| 2825 | char buf[8]; |
| 2826 | |
| 2827 | buf_size = min_t(size_t, count, (sizeof(buf) - 1)); |
| 2828 | if (copy_from_user(buf, u, buf_size)) |
| 2829 | return -EFAULT; |
| 2830 | |
| 2831 | if (buf[0] == '1') |
| 2832 | return 1; |
| 2833 | else if (buf[0] == '0') |
| 2834 | return 0; |
| 2835 | |
| 2836 | return -EINVAL; |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | static ssize_t dfs_file_write(struct file *file, const char __user *u, |
| 2840 | size_t count, loff_t *ppos) |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2841 | { |
| 2842 | struct ubifs_info *c = file->private_data; |
| 2843 | struct ubifs_debug_info *d = c->dbg; |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 2844 | struct dentry *dent = file->f_path.dentry; |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 2845 | int val; |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2846 | |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 2847 | /* |
Artem Bityutskiy | 24a4f80 | 2011-06-01 15:23:25 +0300 | [diff] [blame] | 2848 | * TODO: this is racy - the file-system might have already been |
| 2849 | * unmounted and we'd oops in this case. The plan is to fix it with |
| 2850 | * help of 'iterate_supers_type()' which we should have in v3.0: when |
| 2851 | * a debugfs opened, we rember FS's UUID in file->private_data. Then |
| 2852 | * whenever we access the FS via a debugfs file, we iterate all UBIFS |
| 2853 | * superblocks and fine the one with the same UUID, and take the |
| 2854 | * locking right. |
| 2855 | * |
| 2856 | * The other way to go suggested by Al Viro is to create a separate |
| 2857 | * 'ubifs-debug' file-system instead. |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 2858 | */ |
| 2859 | if (file->f_path.dentry == d->dfs_dump_lprops) { |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2860 | dbg_dump_lprops(c); |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 2861 | return count; |
| 2862 | } |
| 2863 | if (file->f_path.dentry == d->dfs_dump_budg) { |
Artem Bityutskiy | f1bd66a | 2011-03-29 18:36:21 +0300 | [diff] [blame] | 2864 | dbg_dump_budg(c, &c->bi); |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 2865 | return count; |
| 2866 | } |
| 2867 | if (file->f_path.dentry == d->dfs_dump_tnc) { |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2868 | mutex_lock(&c->tnc_mutex); |
| 2869 | dbg_dump_tnc(c); |
| 2870 | mutex_unlock(&c->tnc_mutex); |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 2871 | return count; |
| 2872 | } |
| 2873 | |
Artem Bityutskiy | 28488fc | 2011-06-03 09:58:23 +0300 | [diff] [blame] | 2874 | val = interpret_user_input(u, count); |
| 2875 | if (val < 0) |
| 2876 | return val; |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 2877 | |
| 2878 | if (dent == d->dfs_chk_gen) |
| 2879 | d->chk_gen = val; |
| 2880 | else if (dent == d->dfs_chk_index) |
| 2881 | d->chk_index = val; |
| 2882 | else if (dent == d->dfs_chk_orph) |
| 2883 | d->chk_orph = val; |
| 2884 | else if (dent == d->dfs_chk_lprops) |
| 2885 | d->chk_lprops = val; |
| 2886 | else if (dent == d->dfs_chk_fs) |
| 2887 | d->chk_fs = val; |
| 2888 | else if (dent == d->dfs_tst_rcvry) |
| 2889 | d->tst_rcvry = val; |
| 2890 | else |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2891 | return -EINVAL; |
| 2892 | |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2893 | return count; |
| 2894 | } |
| 2895 | |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 2896 | static const struct file_operations dfs_fops = { |
Artem Bityutskiy | 7dae997 | 2011-06-01 15:44:14 +0300 | [diff] [blame] | 2897 | .open = dfs_file_open, |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 2898 | .read = dfs_file_read, |
| 2899 | .write = dfs_file_write, |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2900 | .owner = THIS_MODULE, |
Artem Bityutskiy | 1bbfc84 | 2011-03-21 16:26:42 +0200 | [diff] [blame] | 2901 | .llseek = no_llseek, |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2902 | }; |
| 2903 | |
| 2904 | /** |
| 2905 | * dbg_debugfs_init_fs - initialize debugfs for UBIFS instance. |
| 2906 | * @c: UBIFS file-system description object |
| 2907 | * |
| 2908 | * This function creates all debugfs files for this instance of UBIFS. Returns |
| 2909 | * zero in case of success and a negative error code in case of failure. |
| 2910 | * |
| 2911 | * Note, the only reason we have not merged this function with the |
| 2912 | * 'ubifs_debugging_init()' function is because it is better to initialize |
| 2913 | * debugfs interfaces at the very end of the mount process, and remove them at |
| 2914 | * the very beginning of the mount process. |
| 2915 | */ |
| 2916 | int dbg_debugfs_init_fs(struct ubifs_info *c) |
| 2917 | { |
Artem Bityutskiy | ae380ce | 2011-05-19 14:13:16 +0300 | [diff] [blame] | 2918 | int err, n; |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2919 | const char *fname; |
| 2920 | struct dentry *dent; |
| 2921 | struct ubifs_debug_info *d = c->dbg; |
| 2922 | |
Artem Bityutskiy | ae380ce | 2011-05-19 14:13:16 +0300 | [diff] [blame] | 2923 | n = snprintf(d->dfs_dir_name, UBIFS_DFS_DIR_LEN + 1, UBIFS_DFS_DIR_NAME, |
| 2924 | c->vi.ubi_num, c->vi.vol_id); |
| 2925 | if (n == UBIFS_DFS_DIR_LEN) { |
| 2926 | /* The array size is too small */ |
| 2927 | fname = UBIFS_DFS_DIR_NAME; |
| 2928 | dent = ERR_PTR(-EINVAL); |
| 2929 | goto out; |
| 2930 | } |
| 2931 | |
Artem Bityutskiy | cc6a86b | 2011-04-01 10:10:52 +0300 | [diff] [blame] | 2932 | fname = d->dfs_dir_name; |
| 2933 | dent = debugfs_create_dir(fname, dfs_rootdir); |
Artem Bityutskiy | 9516953 | 2011-04-01 10:16:17 +0300 | [diff] [blame] | 2934 | if (IS_ERR_OR_NULL(dent)) |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2935 | goto out; |
Artem Bityutskiy | cc6a86b | 2011-04-01 10:10:52 +0300 | [diff] [blame] | 2936 | d->dfs_dir = dent; |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2937 | |
| 2938 | fname = "dump_lprops"; |
Vasiliy Kulikov | 8c559d3 | 2011-02-04 15:24:19 +0300 | [diff] [blame] | 2939 | dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); |
Artem Bityutskiy | 9516953 | 2011-04-01 10:16:17 +0300 | [diff] [blame] | 2940 | if (IS_ERR_OR_NULL(dent)) |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2941 | goto out_remove; |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 2942 | d->dfs_dump_lprops = dent; |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2943 | |
| 2944 | fname = "dump_budg"; |
Vasiliy Kulikov | 8c559d3 | 2011-02-04 15:24:19 +0300 | [diff] [blame] | 2945 | dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); |
Artem Bityutskiy | 9516953 | 2011-04-01 10:16:17 +0300 | [diff] [blame] | 2946 | if (IS_ERR_OR_NULL(dent)) |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2947 | goto out_remove; |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 2948 | d->dfs_dump_budg = dent; |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2949 | |
| 2950 | fname = "dump_tnc"; |
Vasiliy Kulikov | 8c559d3 | 2011-02-04 15:24:19 +0300 | [diff] [blame] | 2951 | dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); |
Artem Bityutskiy | 9516953 | 2011-04-01 10:16:17 +0300 | [diff] [blame] | 2952 | if (IS_ERR_OR_NULL(dent)) |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2953 | goto out_remove; |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 2954 | d->dfs_dump_tnc = dent; |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2955 | |
Artem Bityutskiy | 81e79d3 | 2011-05-31 18:16:34 +0300 | [diff] [blame] | 2956 | fname = "chk_general"; |
| 2957 | dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, |
| 2958 | &dfs_fops); |
| 2959 | if (IS_ERR_OR_NULL(dent)) |
| 2960 | goto out_remove; |
| 2961 | d->dfs_chk_gen = dent; |
| 2962 | |
| 2963 | fname = "chk_index"; |
| 2964 | dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, |
| 2965 | &dfs_fops); |
| 2966 | if (IS_ERR_OR_NULL(dent)) |
| 2967 | goto out_remove; |
| 2968 | d->dfs_chk_index = dent; |
| 2969 | |
| 2970 | fname = "chk_orphans"; |
| 2971 | dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, |
| 2972 | &dfs_fops); |
| 2973 | if (IS_ERR_OR_NULL(dent)) |
| 2974 | goto out_remove; |
| 2975 | d->dfs_chk_orph = dent; |
| 2976 | |
| 2977 | fname = "chk_lprops"; |
| 2978 | dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, |
| 2979 | &dfs_fops); |
| 2980 | if (IS_ERR_OR_NULL(dent)) |
| 2981 | goto out_remove; |
| 2982 | d->dfs_chk_lprops = dent; |
| 2983 | |
| 2984 | fname = "chk_fs"; |
| 2985 | dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, |
| 2986 | &dfs_fops); |
| 2987 | if (IS_ERR_OR_NULL(dent)) |
| 2988 | goto out_remove; |
| 2989 | d->dfs_chk_fs = dent; |
| 2990 | |
| 2991 | fname = "tst_recovery"; |
| 2992 | dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, |
| 2993 | &dfs_fops); |
| 2994 | if (IS_ERR_OR_NULL(dent)) |
| 2995 | goto out_remove; |
| 2996 | d->dfs_tst_rcvry = dent; |
| 2997 | |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 2998 | return 0; |
| 2999 | |
| 3000 | out_remove: |
Artem Bityutskiy | cc6a86b | 2011-04-01 10:10:52 +0300 | [diff] [blame] | 3001 | debugfs_remove_recursive(d->dfs_dir); |
| 3002 | out: |
Artem Bityutskiy | 9516953 | 2011-04-01 10:16:17 +0300 | [diff] [blame] | 3003 | err = dent ? PTR_ERR(dent) : -ENODEV; |
Artem Bityutskiy | e771706 | 2011-06-01 17:43:43 +0300 | [diff] [blame] | 3004 | ubifs_err("cannot create \"%s\" debugfs file or directory, error %d\n", |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 3005 | fname, err); |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 3006 | return err; |
| 3007 | } |
| 3008 | |
| 3009 | /** |
| 3010 | * dbg_debugfs_exit_fs - remove all debugfs files. |
| 3011 | * @c: UBIFS file-system description object |
| 3012 | */ |
| 3013 | void dbg_debugfs_exit_fs(struct ubifs_info *c) |
| 3014 | { |
Artem Bityutskiy | 84abf97 | 2009-01-23 14:54:59 +0200 | [diff] [blame] | 3015 | debugfs_remove_recursive(c->dbg->dfs_dir); |
Artem Bityutskiy | 552ff31 | 2008-10-23 11:49:28 +0300 | [diff] [blame] | 3016 | } |
| 3017 | |
Artem Bityutskiy | e771706 | 2011-06-01 17:43:43 +0300 | [diff] [blame] | 3018 | struct ubifs_global_debug_info ubifs_dbg; |
| 3019 | |
| 3020 | static struct dentry *dfs_chk_gen; |
| 3021 | static struct dentry *dfs_chk_index; |
| 3022 | static struct dentry *dfs_chk_orph; |
| 3023 | static struct dentry *dfs_chk_lprops; |
| 3024 | static struct dentry *dfs_chk_fs; |
| 3025 | static struct dentry *dfs_tst_rcvry; |
| 3026 | |
| 3027 | static ssize_t dfs_global_file_read(struct file *file, char __user *u, |
| 3028 | size_t count, loff_t *ppos) |
| 3029 | { |
| 3030 | struct dentry *dent = file->f_path.dentry; |
| 3031 | int val; |
| 3032 | |
| 3033 | if (dent == dfs_chk_gen) |
| 3034 | val = ubifs_dbg.chk_gen; |
| 3035 | else if (dent == dfs_chk_index) |
| 3036 | val = ubifs_dbg.chk_index; |
| 3037 | else if (dent == dfs_chk_orph) |
| 3038 | val = ubifs_dbg.chk_orph; |
| 3039 | else if (dent == dfs_chk_lprops) |
| 3040 | val = ubifs_dbg.chk_lprops; |
| 3041 | else if (dent == dfs_chk_fs) |
| 3042 | val = ubifs_dbg.chk_fs; |
| 3043 | else if (dent == dfs_tst_rcvry) |
| 3044 | val = ubifs_dbg.tst_rcvry; |
| 3045 | else |
| 3046 | return -EINVAL; |
| 3047 | |
| 3048 | return provide_user_output(val, u, count, ppos); |
| 3049 | } |
| 3050 | |
| 3051 | static ssize_t dfs_global_file_write(struct file *file, const char __user *u, |
| 3052 | size_t count, loff_t *ppos) |
| 3053 | { |
| 3054 | struct dentry *dent = file->f_path.dentry; |
| 3055 | int val; |
| 3056 | |
| 3057 | val = interpret_user_input(u, count); |
| 3058 | if (val < 0) |
| 3059 | return val; |
| 3060 | |
| 3061 | if (dent == dfs_chk_gen) |
| 3062 | ubifs_dbg.chk_gen = val; |
| 3063 | else if (dent == dfs_chk_index) |
| 3064 | ubifs_dbg.chk_index = val; |
| 3065 | else if (dent == dfs_chk_orph) |
| 3066 | ubifs_dbg.chk_orph = val; |
| 3067 | else if (dent == dfs_chk_lprops) |
| 3068 | ubifs_dbg.chk_lprops = val; |
| 3069 | else if (dent == dfs_chk_fs) |
| 3070 | ubifs_dbg.chk_fs = val; |
| 3071 | else if (dent == dfs_tst_rcvry) |
| 3072 | ubifs_dbg.tst_rcvry = val; |
| 3073 | else |
| 3074 | return -EINVAL; |
| 3075 | |
| 3076 | return count; |
| 3077 | } |
| 3078 | |
| 3079 | static const struct file_operations dfs_global_fops = { |
| 3080 | .read = dfs_global_file_read, |
| 3081 | .write = dfs_global_file_write, |
| 3082 | .owner = THIS_MODULE, |
| 3083 | .llseek = no_llseek, |
| 3084 | }; |
| 3085 | |
Artem Bityutskiy | 7dae997 | 2011-06-01 15:44:14 +0300 | [diff] [blame] | 3086 | /** |
| 3087 | * dbg_debugfs_init - initialize debugfs file-system. |
| 3088 | * |
| 3089 | * UBIFS uses debugfs file-system to expose various debugging knobs to |
| 3090 | * user-space. This function creates "ubifs" directory in the debugfs |
| 3091 | * file-system. Returns zero in case of success and a negative error code in |
| 3092 | * case of failure. |
| 3093 | */ |
| 3094 | int dbg_debugfs_init(void) |
| 3095 | { |
Artem Bityutskiy | e771706 | 2011-06-01 17:43:43 +0300 | [diff] [blame] | 3096 | int err; |
| 3097 | const char *fname; |
| 3098 | struct dentry *dent; |
| 3099 | |
| 3100 | fname = "ubifs"; |
| 3101 | dent = debugfs_create_dir(fname, NULL); |
| 3102 | if (IS_ERR_OR_NULL(dent)) |
| 3103 | goto out; |
| 3104 | dfs_rootdir = dent; |
| 3105 | |
| 3106 | fname = "chk_general"; |
| 3107 | dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, |
| 3108 | &dfs_global_fops); |
| 3109 | if (IS_ERR_OR_NULL(dent)) |
| 3110 | goto out_remove; |
| 3111 | dfs_chk_gen = dent; |
| 3112 | |
| 3113 | fname = "chk_index"; |
| 3114 | dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, |
| 3115 | &dfs_global_fops); |
| 3116 | if (IS_ERR_OR_NULL(dent)) |
| 3117 | goto out_remove; |
| 3118 | dfs_chk_index = dent; |
| 3119 | |
| 3120 | fname = "chk_orphans"; |
| 3121 | dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, |
| 3122 | &dfs_global_fops); |
| 3123 | if (IS_ERR_OR_NULL(dent)) |
| 3124 | goto out_remove; |
| 3125 | dfs_chk_orph = dent; |
| 3126 | |
| 3127 | fname = "chk_lprops"; |
| 3128 | dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, |
| 3129 | &dfs_global_fops); |
| 3130 | if (IS_ERR_OR_NULL(dent)) |
| 3131 | goto out_remove; |
| 3132 | dfs_chk_lprops = dent; |
| 3133 | |
| 3134 | fname = "chk_fs"; |
| 3135 | dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, |
| 3136 | &dfs_global_fops); |
| 3137 | if (IS_ERR_OR_NULL(dent)) |
| 3138 | goto out_remove; |
| 3139 | dfs_chk_fs = dent; |
| 3140 | |
| 3141 | fname = "tst_recovery"; |
| 3142 | dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, |
| 3143 | &dfs_global_fops); |
| 3144 | if (IS_ERR_OR_NULL(dent)) |
| 3145 | goto out_remove; |
| 3146 | dfs_tst_rcvry = dent; |
Artem Bityutskiy | 7dae997 | 2011-06-01 15:44:14 +0300 | [diff] [blame] | 3147 | |
| 3148 | return 0; |
Artem Bityutskiy | e771706 | 2011-06-01 17:43:43 +0300 | [diff] [blame] | 3149 | |
| 3150 | out_remove: |
| 3151 | debugfs_remove_recursive(dfs_rootdir); |
| 3152 | out: |
| 3153 | err = dent ? PTR_ERR(dent) : -ENODEV; |
| 3154 | ubifs_err("cannot create \"%s\" debugfs file or directory, error %d\n", |
| 3155 | fname, err); |
| 3156 | return err; |
Artem Bityutskiy | 7dae997 | 2011-06-01 15:44:14 +0300 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | /** |
| 3160 | * dbg_debugfs_exit - remove the "ubifs" directory from debugfs file-system. |
| 3161 | */ |
| 3162 | void dbg_debugfs_exit(void) |
| 3163 | { |
Artem Bityutskiy | e771706 | 2011-06-01 17:43:43 +0300 | [diff] [blame] | 3164 | debugfs_remove_recursive(dfs_rootdir); |
Artem Bityutskiy | 7dae997 | 2011-06-01 15:44:14 +0300 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | /** |
| 3168 | * ubifs_debugging_init - initialize UBIFS debugging. |
| 3169 | * @c: UBIFS file-system description object |
| 3170 | * |
| 3171 | * This function initializes debugging-related data for the file system. |
| 3172 | * Returns zero in case of success and a negative error code in case of |
| 3173 | * failure. |
| 3174 | */ |
| 3175 | int ubifs_debugging_init(struct ubifs_info *c) |
| 3176 | { |
| 3177 | c->dbg = kzalloc(sizeof(struct ubifs_debug_info), GFP_KERNEL); |
| 3178 | if (!c->dbg) |
| 3179 | return -ENOMEM; |
| 3180 | |
Artem Bityutskiy | 7dae997 | 2011-06-01 15:44:14 +0300 | [diff] [blame] | 3181 | return 0; |
| 3182 | } |
| 3183 | |
| 3184 | /** |
| 3185 | * ubifs_debugging_exit - free debugging data. |
| 3186 | * @c: UBIFS file-system description object |
| 3187 | */ |
| 3188 | void ubifs_debugging_exit(struct ubifs_info *c) |
| 3189 | { |
Artem Bityutskiy | 7dae997 | 2011-06-01 15:44:14 +0300 | [diff] [blame] | 3190 | kfree(c->dbg); |
| 3191 | } |
| 3192 | |
Artem Bityutskiy | 1e51764 | 2008-07-14 19:08:37 +0300 | [diff] [blame] | 3193 | #endif /* CONFIG_UBIFS_FS_DEBUG */ |