11e51764aSArtem Bityutskiy /* 21e51764aSArtem Bityutskiy * This file is part of UBIFS. 31e51764aSArtem Bityutskiy * 41e51764aSArtem Bityutskiy * Copyright (C) 2006-2008 Nokia Corporation 51e51764aSArtem Bityutskiy * 61e51764aSArtem Bityutskiy * This program is free software; you can redistribute it and/or modify it 71e51764aSArtem Bityutskiy * under the terms of the GNU General Public License version 2 as published by 81e51764aSArtem Bityutskiy * the Free Software Foundation. 91e51764aSArtem Bityutskiy * 101e51764aSArtem Bityutskiy * This program is distributed in the hope that it will be useful, but WITHOUT 111e51764aSArtem Bityutskiy * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 121e51764aSArtem Bityutskiy * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 131e51764aSArtem Bityutskiy * more details. 141e51764aSArtem Bityutskiy * 151e51764aSArtem Bityutskiy * You should have received a copy of the GNU General Public License along with 161e51764aSArtem Bityutskiy * this program; if not, write to the Free Software Foundation, Inc., 51 171e51764aSArtem Bityutskiy * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 181e51764aSArtem Bityutskiy * 191e51764aSArtem Bityutskiy * Authors: Artem Bityutskiy (Битюцкий Артём) 201e51764aSArtem Bityutskiy * Adrian Hunter 211e51764aSArtem Bityutskiy */ 221e51764aSArtem Bityutskiy 231e51764aSArtem Bityutskiy /* 241e51764aSArtem Bityutskiy * This file implements most of the debugging stuff which is compiled in only 251e51764aSArtem Bityutskiy * when it is enabled. But some debugging check functions are implemented in 261e51764aSArtem Bityutskiy * corresponding subsystem, just because they are closely related and utilize 271e51764aSArtem Bityutskiy * various local functions of those subsystems. 281e51764aSArtem Bityutskiy */ 291e51764aSArtem Bityutskiy 301e51764aSArtem Bityutskiy #define UBIFS_DBG_PRESERVE_UBI 311e51764aSArtem Bityutskiy 321e51764aSArtem Bityutskiy #include "ubifs.h" 331e51764aSArtem Bityutskiy #include <linux/module.h> 341e51764aSArtem Bityutskiy #include <linux/moduleparam.h> 351e51764aSArtem Bityutskiy 361e51764aSArtem Bityutskiy #ifdef CONFIG_UBIFS_FS_DEBUG 371e51764aSArtem Bityutskiy 381e51764aSArtem Bityutskiy DEFINE_SPINLOCK(dbg_lock); 391e51764aSArtem Bityutskiy 401e51764aSArtem Bityutskiy static char dbg_key_buf0[128]; 411e51764aSArtem Bityutskiy static char dbg_key_buf1[128]; 421e51764aSArtem Bityutskiy 431e51764aSArtem Bityutskiy unsigned int ubifs_msg_flags = UBIFS_MSG_FLAGS_DEFAULT; 441e51764aSArtem Bityutskiy unsigned int ubifs_chk_flags = UBIFS_CHK_FLAGS_DEFAULT; 451e51764aSArtem Bityutskiy unsigned int ubifs_tst_flags; 461e51764aSArtem Bityutskiy 471e51764aSArtem Bityutskiy module_param_named(debug_msgs, ubifs_msg_flags, uint, S_IRUGO | S_IWUSR); 481e51764aSArtem Bityutskiy module_param_named(debug_chks, ubifs_chk_flags, uint, S_IRUGO | S_IWUSR); 491e51764aSArtem Bityutskiy module_param_named(debug_tsts, ubifs_tst_flags, uint, S_IRUGO | S_IWUSR); 501e51764aSArtem Bityutskiy 511e51764aSArtem Bityutskiy MODULE_PARM_DESC(debug_msgs, "Debug message type flags"); 521e51764aSArtem Bityutskiy MODULE_PARM_DESC(debug_chks, "Debug check flags"); 531e51764aSArtem Bityutskiy MODULE_PARM_DESC(debug_tsts, "Debug special test flags"); 541e51764aSArtem Bityutskiy 551e51764aSArtem Bityutskiy static const char *get_key_fmt(int fmt) 561e51764aSArtem Bityutskiy { 571e51764aSArtem Bityutskiy switch (fmt) { 581e51764aSArtem Bityutskiy case UBIFS_SIMPLE_KEY_FMT: 591e51764aSArtem Bityutskiy return "simple"; 601e51764aSArtem Bityutskiy default: 611e51764aSArtem Bityutskiy return "unknown/invalid format"; 621e51764aSArtem Bityutskiy } 631e51764aSArtem Bityutskiy } 641e51764aSArtem Bityutskiy 651e51764aSArtem Bityutskiy static const char *get_key_hash(int hash) 661e51764aSArtem Bityutskiy { 671e51764aSArtem Bityutskiy switch (hash) { 681e51764aSArtem Bityutskiy case UBIFS_KEY_HASH_R5: 691e51764aSArtem Bityutskiy return "R5"; 701e51764aSArtem Bityutskiy case UBIFS_KEY_HASH_TEST: 711e51764aSArtem Bityutskiy return "test"; 721e51764aSArtem Bityutskiy default: 731e51764aSArtem Bityutskiy return "unknown/invalid name hash"; 741e51764aSArtem Bityutskiy } 751e51764aSArtem Bityutskiy } 761e51764aSArtem Bityutskiy 771e51764aSArtem Bityutskiy static const char *get_key_type(int type) 781e51764aSArtem Bityutskiy { 791e51764aSArtem Bityutskiy switch (type) { 801e51764aSArtem Bityutskiy case UBIFS_INO_KEY: 811e51764aSArtem Bityutskiy return "inode"; 821e51764aSArtem Bityutskiy case UBIFS_DENT_KEY: 831e51764aSArtem Bityutskiy return "direntry"; 841e51764aSArtem Bityutskiy case UBIFS_XENT_KEY: 851e51764aSArtem Bityutskiy return "xentry"; 861e51764aSArtem Bityutskiy case UBIFS_DATA_KEY: 871e51764aSArtem Bityutskiy return "data"; 881e51764aSArtem Bityutskiy case UBIFS_TRUN_KEY: 891e51764aSArtem Bityutskiy return "truncate"; 901e51764aSArtem Bityutskiy default: 911e51764aSArtem Bityutskiy return "unknown/invalid key"; 921e51764aSArtem Bityutskiy } 931e51764aSArtem Bityutskiy } 941e51764aSArtem Bityutskiy 951e51764aSArtem Bityutskiy static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key, 961e51764aSArtem Bityutskiy char *buffer) 971e51764aSArtem Bityutskiy { 981e51764aSArtem Bityutskiy char *p = buffer; 991e51764aSArtem Bityutskiy int type = key_type(c, key); 1001e51764aSArtem Bityutskiy 1011e51764aSArtem Bityutskiy if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) { 1021e51764aSArtem Bityutskiy switch (type) { 1031e51764aSArtem Bityutskiy case UBIFS_INO_KEY: 1041e51764aSArtem Bityutskiy sprintf(p, "(%lu, %s)", key_inum(c, key), 1051e51764aSArtem Bityutskiy get_key_type(type)); 1061e51764aSArtem Bityutskiy break; 1071e51764aSArtem Bityutskiy case UBIFS_DENT_KEY: 1081e51764aSArtem Bityutskiy case UBIFS_XENT_KEY: 1091e51764aSArtem Bityutskiy sprintf(p, "(%lu, %s, %#08x)", key_inum(c, key), 1101e51764aSArtem Bityutskiy get_key_type(type), key_hash(c, key)); 1111e51764aSArtem Bityutskiy break; 1121e51764aSArtem Bityutskiy case UBIFS_DATA_KEY: 1131e51764aSArtem Bityutskiy sprintf(p, "(%lu, %s, %u)", key_inum(c, key), 1141e51764aSArtem Bityutskiy get_key_type(type), key_block(c, key)); 1151e51764aSArtem Bityutskiy break; 1161e51764aSArtem Bityutskiy case UBIFS_TRUN_KEY: 1171e51764aSArtem Bityutskiy sprintf(p, "(%lu, %s)", 1181e51764aSArtem Bityutskiy key_inum(c, key), get_key_type(type)); 1191e51764aSArtem Bityutskiy break; 1201e51764aSArtem Bityutskiy default: 1211e51764aSArtem Bityutskiy sprintf(p, "(bad key type: %#08x, %#08x)", 1221e51764aSArtem Bityutskiy key->u32[0], key->u32[1]); 1231e51764aSArtem Bityutskiy } 1241e51764aSArtem Bityutskiy } else 1251e51764aSArtem Bityutskiy sprintf(p, "bad key format %d", c->key_fmt); 1261e51764aSArtem Bityutskiy } 1271e51764aSArtem Bityutskiy 1281e51764aSArtem Bityutskiy const char *dbg_key_str0(const struct ubifs_info *c, const union ubifs_key *key) 1291e51764aSArtem Bityutskiy { 1301e51764aSArtem Bityutskiy /* dbg_lock must be held */ 1311e51764aSArtem Bityutskiy sprintf_key(c, key, dbg_key_buf0); 1321e51764aSArtem Bityutskiy return dbg_key_buf0; 1331e51764aSArtem Bityutskiy } 1341e51764aSArtem Bityutskiy 1351e51764aSArtem Bityutskiy const char *dbg_key_str1(const struct ubifs_info *c, const union ubifs_key *key) 1361e51764aSArtem Bityutskiy { 1371e51764aSArtem Bityutskiy /* dbg_lock must be held */ 1381e51764aSArtem Bityutskiy sprintf_key(c, key, dbg_key_buf1); 1391e51764aSArtem Bityutskiy return dbg_key_buf1; 1401e51764aSArtem Bityutskiy } 1411e51764aSArtem Bityutskiy 1421e51764aSArtem Bityutskiy const char *dbg_ntype(int type) 1431e51764aSArtem Bityutskiy { 1441e51764aSArtem Bityutskiy switch (type) { 1451e51764aSArtem Bityutskiy case UBIFS_PAD_NODE: 1461e51764aSArtem Bityutskiy return "padding node"; 1471e51764aSArtem Bityutskiy case UBIFS_SB_NODE: 1481e51764aSArtem Bityutskiy return "superblock node"; 1491e51764aSArtem Bityutskiy case UBIFS_MST_NODE: 1501e51764aSArtem Bityutskiy return "master node"; 1511e51764aSArtem Bityutskiy case UBIFS_REF_NODE: 1521e51764aSArtem Bityutskiy return "reference node"; 1531e51764aSArtem Bityutskiy case UBIFS_INO_NODE: 1541e51764aSArtem Bityutskiy return "inode node"; 1551e51764aSArtem Bityutskiy case UBIFS_DENT_NODE: 1561e51764aSArtem Bityutskiy return "direntry node"; 1571e51764aSArtem Bityutskiy case UBIFS_XENT_NODE: 1581e51764aSArtem Bityutskiy return "xentry node"; 1591e51764aSArtem Bityutskiy case UBIFS_DATA_NODE: 1601e51764aSArtem Bityutskiy return "data node"; 1611e51764aSArtem Bityutskiy case UBIFS_TRUN_NODE: 1621e51764aSArtem Bityutskiy return "truncate node"; 1631e51764aSArtem Bityutskiy case UBIFS_IDX_NODE: 1641e51764aSArtem Bityutskiy return "indexing node"; 1651e51764aSArtem Bityutskiy case UBIFS_CS_NODE: 1661e51764aSArtem Bityutskiy return "commit start node"; 1671e51764aSArtem Bityutskiy case UBIFS_ORPH_NODE: 1681e51764aSArtem Bityutskiy return "orphan node"; 1691e51764aSArtem Bityutskiy default: 1701e51764aSArtem Bityutskiy return "unknown node"; 1711e51764aSArtem Bityutskiy } 1721e51764aSArtem Bityutskiy } 1731e51764aSArtem Bityutskiy 1741e51764aSArtem Bityutskiy static const char *dbg_gtype(int type) 1751e51764aSArtem Bityutskiy { 1761e51764aSArtem Bityutskiy switch (type) { 1771e51764aSArtem Bityutskiy case UBIFS_NO_NODE_GROUP: 1781e51764aSArtem Bityutskiy return "no node group"; 1791e51764aSArtem Bityutskiy case UBIFS_IN_NODE_GROUP: 1801e51764aSArtem Bityutskiy return "in node group"; 1811e51764aSArtem Bityutskiy case UBIFS_LAST_OF_NODE_GROUP: 1821e51764aSArtem Bityutskiy return "last of node group"; 1831e51764aSArtem Bityutskiy default: 1841e51764aSArtem Bityutskiy return "unknown"; 1851e51764aSArtem Bityutskiy } 1861e51764aSArtem Bityutskiy } 1871e51764aSArtem Bityutskiy 1881e51764aSArtem Bityutskiy const char *dbg_cstate(int cmt_state) 1891e51764aSArtem Bityutskiy { 1901e51764aSArtem Bityutskiy switch (cmt_state) { 1911e51764aSArtem Bityutskiy case COMMIT_RESTING: 1921e51764aSArtem Bityutskiy return "commit resting"; 1931e51764aSArtem Bityutskiy case COMMIT_BACKGROUND: 1941e51764aSArtem Bityutskiy return "background commit requested"; 1951e51764aSArtem Bityutskiy case COMMIT_REQUIRED: 1961e51764aSArtem Bityutskiy return "commit required"; 1971e51764aSArtem Bityutskiy case COMMIT_RUNNING_BACKGROUND: 1981e51764aSArtem Bityutskiy return "BACKGROUND commit running"; 1991e51764aSArtem Bityutskiy case COMMIT_RUNNING_REQUIRED: 2001e51764aSArtem Bityutskiy return "commit running and required"; 2011e51764aSArtem Bityutskiy case COMMIT_BROKEN: 2021e51764aSArtem Bityutskiy return "broken commit"; 2031e51764aSArtem Bityutskiy default: 2041e51764aSArtem Bityutskiy return "unknown commit state"; 2051e51764aSArtem Bityutskiy } 2061e51764aSArtem Bityutskiy } 2071e51764aSArtem Bityutskiy 2081e51764aSArtem Bityutskiy static void dump_ch(const struct ubifs_ch *ch) 2091e51764aSArtem Bityutskiy { 2101e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tmagic %#x\n", le32_to_cpu(ch->magic)); 2111e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tcrc %#x\n", le32_to_cpu(ch->crc)); 2121e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tnode_type %d (%s)\n", ch->node_type, 2131e51764aSArtem Bityutskiy dbg_ntype(ch->node_type)); 2141e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tgroup_type %d (%s)\n", ch->group_type, 2151e51764aSArtem Bityutskiy dbg_gtype(ch->group_type)); 2161e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tsqnum %llu\n", 2171e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(ch->sqnum)); 2181e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tlen %u\n", le32_to_cpu(ch->len)); 2191e51764aSArtem Bityutskiy } 2201e51764aSArtem Bityutskiy 2211e51764aSArtem Bityutskiy void dbg_dump_inode(const struct ubifs_info *c, const struct inode *inode) 2221e51764aSArtem Bityutskiy { 2231e51764aSArtem Bityutskiy const struct ubifs_inode *ui = ubifs_inode(inode); 2241e51764aSArtem Bityutskiy 225b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "Dump in-memory inode:"); 226b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tinode %lu\n", inode->i_ino); 227b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tsize %llu\n", 2281e51764aSArtem Bityutskiy (unsigned long long)i_size_read(inode)); 229b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tnlink %u\n", inode->i_nlink); 230b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tuid %u\n", (unsigned int)inode->i_uid); 231b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tgid %u\n", (unsigned int)inode->i_gid); 232b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tatime %u.%u\n", 2331e51764aSArtem Bityutskiy (unsigned int)inode->i_atime.tv_sec, 2341e51764aSArtem Bityutskiy (unsigned int)inode->i_atime.tv_nsec); 235b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tmtime %u.%u\n", 2361e51764aSArtem Bityutskiy (unsigned int)inode->i_mtime.tv_sec, 2371e51764aSArtem Bityutskiy (unsigned int)inode->i_mtime.tv_nsec); 238b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tctime %u.%u\n", 2391e51764aSArtem Bityutskiy (unsigned int)inode->i_ctime.tv_sec, 2401e51764aSArtem Bityutskiy (unsigned int)inode->i_ctime.tv_nsec); 241b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tcreat_sqnum %llu\n", ui->creat_sqnum); 242b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\txattr_size %u\n", ui->xattr_size); 243b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\txattr_cnt %u\n", ui->xattr_cnt); 244b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\txattr_names %u\n", ui->xattr_names); 245b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tdirty %u\n", ui->dirty); 246b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\txattr %u\n", ui->xattr); 247b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tbulk_read %u\n", ui->xattr); 248b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tsynced_i_size %llu\n", 249b5e426e9SArtem Bityutskiy (unsigned long long)ui->synced_i_size); 250b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tui_size %llu\n", 251b5e426e9SArtem Bityutskiy (unsigned long long)ui->ui_size); 252b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tflags %d\n", ui->flags); 253b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tcompr_type %d\n", ui->compr_type); 254b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tlast_page_read %lu\n", ui->last_page_read); 255b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tread_in_a_row %lu\n", ui->read_in_a_row); 256b5e426e9SArtem Bityutskiy printk(KERN_DEBUG "\tdata_len %d\n", ui->data_len); 2571e51764aSArtem Bityutskiy } 2581e51764aSArtem Bityutskiy 2591e51764aSArtem Bityutskiy void dbg_dump_node(const struct ubifs_info *c, const void *node) 2601e51764aSArtem Bityutskiy { 2611e51764aSArtem Bityutskiy int i, n; 2621e51764aSArtem Bityutskiy union ubifs_key key; 2631e51764aSArtem Bityutskiy const struct ubifs_ch *ch = node; 2641e51764aSArtem Bityutskiy 2651e51764aSArtem Bityutskiy if (dbg_failure_mode) 2661e51764aSArtem Bityutskiy return; 2671e51764aSArtem Bityutskiy 2681e51764aSArtem Bityutskiy /* If the magic is incorrect, just hexdump the first bytes */ 2691e51764aSArtem Bityutskiy if (le32_to_cpu(ch->magic) != UBIFS_NODE_MAGIC) { 2701e51764aSArtem Bityutskiy printk(KERN_DEBUG "Not a node, first %zu bytes:", UBIFS_CH_SZ); 2711e51764aSArtem Bityutskiy print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 2721e51764aSArtem Bityutskiy (void *)node, UBIFS_CH_SZ, 1); 2731e51764aSArtem Bityutskiy return; 2741e51764aSArtem Bityutskiy } 2751e51764aSArtem Bityutskiy 2761e51764aSArtem Bityutskiy spin_lock(&dbg_lock); 2771e51764aSArtem Bityutskiy dump_ch(node); 2781e51764aSArtem Bityutskiy 2791e51764aSArtem Bityutskiy switch (ch->node_type) { 2801e51764aSArtem Bityutskiy case UBIFS_PAD_NODE: 2811e51764aSArtem Bityutskiy { 2821e51764aSArtem Bityutskiy const struct ubifs_pad_node *pad = node; 2831e51764aSArtem Bityutskiy 2841e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tpad_len %u\n", 2851e51764aSArtem Bityutskiy le32_to_cpu(pad->pad_len)); 2861e51764aSArtem Bityutskiy break; 2871e51764aSArtem Bityutskiy } 2881e51764aSArtem Bityutskiy case UBIFS_SB_NODE: 2891e51764aSArtem Bityutskiy { 2901e51764aSArtem Bityutskiy const struct ubifs_sb_node *sup = node; 2911e51764aSArtem Bityutskiy unsigned int sup_flags = le32_to_cpu(sup->flags); 2921e51764aSArtem Bityutskiy 2931e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tkey_hash %d (%s)\n", 2941e51764aSArtem Bityutskiy (int)sup->key_hash, get_key_hash(sup->key_hash)); 2951e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tkey_fmt %d (%s)\n", 2961e51764aSArtem Bityutskiy (int)sup->key_fmt, get_key_fmt(sup->key_fmt)); 2971e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tflags %#x\n", sup_flags); 2981e51764aSArtem Bityutskiy printk(KERN_DEBUG "\t big_lpt %u\n", 2991e51764aSArtem Bityutskiy !!(sup_flags & UBIFS_FLG_BIGLPT)); 3001e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tmin_io_size %u\n", 3011e51764aSArtem Bityutskiy le32_to_cpu(sup->min_io_size)); 3021e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tleb_size %u\n", 3031e51764aSArtem Bityutskiy le32_to_cpu(sup->leb_size)); 3041e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tleb_cnt %u\n", 3051e51764aSArtem Bityutskiy le32_to_cpu(sup->leb_cnt)); 3061e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tmax_leb_cnt %u\n", 3071e51764aSArtem Bityutskiy le32_to_cpu(sup->max_leb_cnt)); 3081e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tmax_bud_bytes %llu\n", 3091e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(sup->max_bud_bytes)); 3101e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tlog_lebs %u\n", 3111e51764aSArtem Bityutskiy le32_to_cpu(sup->log_lebs)); 3121e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tlpt_lebs %u\n", 3131e51764aSArtem Bityutskiy le32_to_cpu(sup->lpt_lebs)); 3141e51764aSArtem Bityutskiy printk(KERN_DEBUG "\torph_lebs %u\n", 3151e51764aSArtem Bityutskiy le32_to_cpu(sup->orph_lebs)); 3161e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tjhead_cnt %u\n", 3171e51764aSArtem Bityutskiy le32_to_cpu(sup->jhead_cnt)); 3181e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tfanout %u\n", 3191e51764aSArtem Bityutskiy le32_to_cpu(sup->fanout)); 3201e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tlsave_cnt %u\n", 3211e51764aSArtem Bityutskiy le32_to_cpu(sup->lsave_cnt)); 3221e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tdefault_compr %u\n", 3231e51764aSArtem Bityutskiy (int)le16_to_cpu(sup->default_compr)); 3241e51764aSArtem Bityutskiy printk(KERN_DEBUG "\trp_size %llu\n", 3251e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(sup->rp_size)); 3261e51764aSArtem Bityutskiy printk(KERN_DEBUG "\trp_uid %u\n", 3271e51764aSArtem Bityutskiy le32_to_cpu(sup->rp_uid)); 3281e51764aSArtem Bityutskiy printk(KERN_DEBUG "\trp_gid %u\n", 3291e51764aSArtem Bityutskiy le32_to_cpu(sup->rp_gid)); 3301e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tfmt_version %u\n", 3311e51764aSArtem Bityutskiy le32_to_cpu(sup->fmt_version)); 3321e51764aSArtem Bityutskiy printk(KERN_DEBUG "\ttime_gran %u\n", 3331e51764aSArtem Bityutskiy le32_to_cpu(sup->time_gran)); 3341e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tUUID %02X%02X%02X%02X-%02X%02X" 3351e51764aSArtem Bityutskiy "-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X\n", 3361e51764aSArtem Bityutskiy sup->uuid[0], sup->uuid[1], sup->uuid[2], sup->uuid[3], 3371e51764aSArtem Bityutskiy sup->uuid[4], sup->uuid[5], sup->uuid[6], sup->uuid[7], 3381e51764aSArtem Bityutskiy sup->uuid[8], sup->uuid[9], sup->uuid[10], sup->uuid[11], 3391e51764aSArtem Bityutskiy sup->uuid[12], sup->uuid[13], sup->uuid[14], 3401e51764aSArtem Bityutskiy sup->uuid[15]); 3411e51764aSArtem Bityutskiy break; 3421e51764aSArtem Bityutskiy } 3431e51764aSArtem Bityutskiy case UBIFS_MST_NODE: 3441e51764aSArtem Bityutskiy { 3451e51764aSArtem Bityutskiy const struct ubifs_mst_node *mst = node; 3461e51764aSArtem Bityutskiy 3471e51764aSArtem Bityutskiy printk(KERN_DEBUG "\thighest_inum %llu\n", 3481e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(mst->highest_inum)); 3491e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tcommit number %llu\n", 3501e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(mst->cmt_no)); 3511e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tflags %#x\n", 3521e51764aSArtem Bityutskiy le32_to_cpu(mst->flags)); 3531e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tlog_lnum %u\n", 3541e51764aSArtem Bityutskiy le32_to_cpu(mst->log_lnum)); 3551e51764aSArtem Bityutskiy printk(KERN_DEBUG "\troot_lnum %u\n", 3561e51764aSArtem Bityutskiy le32_to_cpu(mst->root_lnum)); 3571e51764aSArtem Bityutskiy printk(KERN_DEBUG "\troot_offs %u\n", 3581e51764aSArtem Bityutskiy le32_to_cpu(mst->root_offs)); 3591e51764aSArtem Bityutskiy printk(KERN_DEBUG "\troot_len %u\n", 3601e51764aSArtem Bityutskiy le32_to_cpu(mst->root_len)); 3611e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tgc_lnum %u\n", 3621e51764aSArtem Bityutskiy le32_to_cpu(mst->gc_lnum)); 3631e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tihead_lnum %u\n", 3641e51764aSArtem Bityutskiy le32_to_cpu(mst->ihead_lnum)); 3651e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tihead_offs %u\n", 3661e51764aSArtem Bityutskiy le32_to_cpu(mst->ihead_offs)); 3671e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tindex_size %u\n", 3681e51764aSArtem Bityutskiy le32_to_cpu(mst->index_size)); 3691e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tlpt_lnum %u\n", 3701e51764aSArtem Bityutskiy le32_to_cpu(mst->lpt_lnum)); 3711e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tlpt_offs %u\n", 3721e51764aSArtem Bityutskiy le32_to_cpu(mst->lpt_offs)); 3731e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tnhead_lnum %u\n", 3741e51764aSArtem Bityutskiy le32_to_cpu(mst->nhead_lnum)); 3751e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tnhead_offs %u\n", 3761e51764aSArtem Bityutskiy le32_to_cpu(mst->nhead_offs)); 3771e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tltab_lnum %u\n", 3781e51764aSArtem Bityutskiy le32_to_cpu(mst->ltab_lnum)); 3791e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tltab_offs %u\n", 3801e51764aSArtem Bityutskiy le32_to_cpu(mst->ltab_offs)); 3811e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tlsave_lnum %u\n", 3821e51764aSArtem Bityutskiy le32_to_cpu(mst->lsave_lnum)); 3831e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tlsave_offs %u\n", 3841e51764aSArtem Bityutskiy le32_to_cpu(mst->lsave_offs)); 3851e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tlscan_lnum %u\n", 3861e51764aSArtem Bityutskiy le32_to_cpu(mst->lscan_lnum)); 3871e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tleb_cnt %u\n", 3881e51764aSArtem Bityutskiy le32_to_cpu(mst->leb_cnt)); 3891e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tempty_lebs %u\n", 3901e51764aSArtem Bityutskiy le32_to_cpu(mst->empty_lebs)); 3911e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tidx_lebs %u\n", 3921e51764aSArtem Bityutskiy le32_to_cpu(mst->idx_lebs)); 3931e51764aSArtem Bityutskiy printk(KERN_DEBUG "\ttotal_free %llu\n", 3941e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(mst->total_free)); 3951e51764aSArtem Bityutskiy printk(KERN_DEBUG "\ttotal_dirty %llu\n", 3961e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(mst->total_dirty)); 3971e51764aSArtem Bityutskiy printk(KERN_DEBUG "\ttotal_used %llu\n", 3981e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(mst->total_used)); 3991e51764aSArtem Bityutskiy printk(KERN_DEBUG "\ttotal_dead %llu\n", 4001e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(mst->total_dead)); 4011e51764aSArtem Bityutskiy printk(KERN_DEBUG "\ttotal_dark %llu\n", 4021e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(mst->total_dark)); 4031e51764aSArtem Bityutskiy break; 4041e51764aSArtem Bityutskiy } 4051e51764aSArtem Bityutskiy case UBIFS_REF_NODE: 4061e51764aSArtem Bityutskiy { 4071e51764aSArtem Bityutskiy const struct ubifs_ref_node *ref = node; 4081e51764aSArtem Bityutskiy 4091e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tlnum %u\n", 4101e51764aSArtem Bityutskiy le32_to_cpu(ref->lnum)); 4111e51764aSArtem Bityutskiy printk(KERN_DEBUG "\toffs %u\n", 4121e51764aSArtem Bityutskiy le32_to_cpu(ref->offs)); 4131e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tjhead %u\n", 4141e51764aSArtem Bityutskiy le32_to_cpu(ref->jhead)); 4151e51764aSArtem Bityutskiy break; 4161e51764aSArtem Bityutskiy } 4171e51764aSArtem Bityutskiy case UBIFS_INO_NODE: 4181e51764aSArtem Bityutskiy { 4191e51764aSArtem Bityutskiy const struct ubifs_ino_node *ino = node; 4201e51764aSArtem Bityutskiy 4211e51764aSArtem Bityutskiy key_read(c, &ino->key, &key); 4221e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); 4231e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tcreat_sqnum %llu\n", 4241e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(ino->creat_sqnum)); 4251e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tsize %llu\n", 4261e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(ino->size)); 4271e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tnlink %u\n", 4281e51764aSArtem Bityutskiy le32_to_cpu(ino->nlink)); 4291e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tatime %lld.%u\n", 4301e51764aSArtem Bityutskiy (long long)le64_to_cpu(ino->atime_sec), 4311e51764aSArtem Bityutskiy le32_to_cpu(ino->atime_nsec)); 4321e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tmtime %lld.%u\n", 4331e51764aSArtem Bityutskiy (long long)le64_to_cpu(ino->mtime_sec), 4341e51764aSArtem Bityutskiy le32_to_cpu(ino->mtime_nsec)); 4351e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tctime %lld.%u\n", 4361e51764aSArtem Bityutskiy (long long)le64_to_cpu(ino->ctime_sec), 4371e51764aSArtem Bityutskiy le32_to_cpu(ino->ctime_nsec)); 4381e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tuid %u\n", 4391e51764aSArtem Bityutskiy le32_to_cpu(ino->uid)); 4401e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tgid %u\n", 4411e51764aSArtem Bityutskiy le32_to_cpu(ino->gid)); 4421e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tmode %u\n", 4431e51764aSArtem Bityutskiy le32_to_cpu(ino->mode)); 4441e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tflags %#x\n", 4451e51764aSArtem Bityutskiy le32_to_cpu(ino->flags)); 4461e51764aSArtem Bityutskiy printk(KERN_DEBUG "\txattr_cnt %u\n", 4471e51764aSArtem Bityutskiy le32_to_cpu(ino->xattr_cnt)); 4481e51764aSArtem Bityutskiy printk(KERN_DEBUG "\txattr_size %u\n", 4491e51764aSArtem Bityutskiy le32_to_cpu(ino->xattr_size)); 4501e51764aSArtem Bityutskiy printk(KERN_DEBUG "\txattr_names %u\n", 4511e51764aSArtem Bityutskiy le32_to_cpu(ino->xattr_names)); 4521e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tcompr_type %#x\n", 4531e51764aSArtem Bityutskiy (int)le16_to_cpu(ino->compr_type)); 4541e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tdata len %u\n", 4551e51764aSArtem Bityutskiy le32_to_cpu(ino->data_len)); 4561e51764aSArtem Bityutskiy break; 4571e51764aSArtem Bityutskiy } 4581e51764aSArtem Bityutskiy case UBIFS_DENT_NODE: 4591e51764aSArtem Bityutskiy case UBIFS_XENT_NODE: 4601e51764aSArtem Bityutskiy { 4611e51764aSArtem Bityutskiy const struct ubifs_dent_node *dent = node; 4621e51764aSArtem Bityutskiy int nlen = le16_to_cpu(dent->nlen); 4631e51764aSArtem Bityutskiy 4641e51764aSArtem Bityutskiy key_read(c, &dent->key, &key); 4651e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); 4661e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tinum %llu\n", 4671e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(dent->inum)); 4681e51764aSArtem Bityutskiy printk(KERN_DEBUG "\ttype %d\n", (int)dent->type); 4691e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tnlen %d\n", nlen); 4701e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tname "); 4711e51764aSArtem Bityutskiy 4721e51764aSArtem Bityutskiy if (nlen > UBIFS_MAX_NLEN) 4731e51764aSArtem Bityutskiy printk(KERN_DEBUG "(bad name length, not printing, " 4741e51764aSArtem Bityutskiy "bad or corrupted node)"); 4751e51764aSArtem Bityutskiy else { 4761e51764aSArtem Bityutskiy for (i = 0; i < nlen && dent->name[i]; i++) 4771e51764aSArtem Bityutskiy printk("%c", dent->name[i]); 4781e51764aSArtem Bityutskiy } 4791e51764aSArtem Bityutskiy printk("\n"); 4801e51764aSArtem Bityutskiy 4811e51764aSArtem Bityutskiy break; 4821e51764aSArtem Bityutskiy } 4831e51764aSArtem Bityutskiy case UBIFS_DATA_NODE: 4841e51764aSArtem Bityutskiy { 4851e51764aSArtem Bityutskiy const struct ubifs_data_node *dn = node; 4861e51764aSArtem Bityutskiy int dlen = le32_to_cpu(ch->len) - UBIFS_DATA_NODE_SZ; 4871e51764aSArtem Bityutskiy 4881e51764aSArtem Bityutskiy key_read(c, &dn->key, &key); 4891e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); 4901e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tsize %u\n", 4911e51764aSArtem Bityutskiy le32_to_cpu(dn->size)); 4921e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tcompr_typ %d\n", 4931e51764aSArtem Bityutskiy (int)le16_to_cpu(dn->compr_type)); 4941e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tdata size %d\n", 4951e51764aSArtem Bityutskiy dlen); 4961e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tdata:\n"); 4971e51764aSArtem Bityutskiy print_hex_dump(KERN_DEBUG, "\t", DUMP_PREFIX_OFFSET, 32, 1, 4981e51764aSArtem Bityutskiy (void *)&dn->data, dlen, 0); 4991e51764aSArtem Bityutskiy break; 5001e51764aSArtem Bityutskiy } 5011e51764aSArtem Bityutskiy case UBIFS_TRUN_NODE: 5021e51764aSArtem Bityutskiy { 5031e51764aSArtem Bityutskiy const struct ubifs_trun_node *trun = node; 5041e51764aSArtem Bityutskiy 5051e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tinum %u\n", 5061e51764aSArtem Bityutskiy le32_to_cpu(trun->inum)); 5071e51764aSArtem Bityutskiy printk(KERN_DEBUG "\told_size %llu\n", 5081e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(trun->old_size)); 5091e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tnew_size %llu\n", 5101e51764aSArtem Bityutskiy (unsigned long long)le64_to_cpu(trun->new_size)); 5111e51764aSArtem Bityutskiy break; 5121e51764aSArtem Bityutskiy } 5131e51764aSArtem Bityutskiy case UBIFS_IDX_NODE: 5141e51764aSArtem Bityutskiy { 5151e51764aSArtem Bityutskiy const struct ubifs_idx_node *idx = node; 5161e51764aSArtem Bityutskiy 5171e51764aSArtem Bityutskiy n = le16_to_cpu(idx->child_cnt); 5181e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tchild_cnt %d\n", n); 5191e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tlevel %d\n", 5201e51764aSArtem Bityutskiy (int)le16_to_cpu(idx->level)); 5211e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tBranches:\n"); 5221e51764aSArtem Bityutskiy 5231e51764aSArtem Bityutskiy for (i = 0; i < n && i < c->fanout - 1; i++) { 5241e51764aSArtem Bityutskiy const struct ubifs_branch *br; 5251e51764aSArtem Bityutskiy 5261e51764aSArtem Bityutskiy br = ubifs_idx_branch(c, idx, i); 5271e51764aSArtem Bityutskiy key_read(c, &br->key, &key); 5281e51764aSArtem Bityutskiy printk(KERN_DEBUG "\t%d: LEB %d:%d len %d key %s\n", 5291e51764aSArtem Bityutskiy i, le32_to_cpu(br->lnum), le32_to_cpu(br->offs), 5301e51764aSArtem Bityutskiy le32_to_cpu(br->len), DBGKEY(&key)); 5311e51764aSArtem Bityutskiy } 5321e51764aSArtem Bityutskiy break; 5331e51764aSArtem Bityutskiy } 5341e51764aSArtem Bityutskiy case UBIFS_CS_NODE: 5351e51764aSArtem Bityutskiy break; 5361e51764aSArtem Bityutskiy case UBIFS_ORPH_NODE: 5371e51764aSArtem Bityutskiy { 5381e51764aSArtem Bityutskiy const struct ubifs_orph_node *orph = node; 5391e51764aSArtem Bityutskiy 5401e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tcommit number %llu\n", 5411e51764aSArtem Bityutskiy (unsigned long long) 5421e51764aSArtem Bityutskiy le64_to_cpu(orph->cmt_no) & LLONG_MAX); 5431e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tlast node flag %llu\n", 5441e51764aSArtem Bityutskiy (unsigned long long)(le64_to_cpu(orph->cmt_no)) >> 63); 5451e51764aSArtem Bityutskiy n = (le32_to_cpu(ch->len) - UBIFS_ORPH_NODE_SZ) >> 3; 5461e51764aSArtem Bityutskiy printk(KERN_DEBUG "\t%d orphan inode numbers:\n", n); 5471e51764aSArtem Bityutskiy for (i = 0; i < n; i++) 5481e51764aSArtem Bityutskiy printk(KERN_DEBUG "\t ino %llu\n", 5497424bac8SAlexander Beregalov (unsigned long long)le64_to_cpu(orph->inos[i])); 5501e51764aSArtem Bityutskiy break; 5511e51764aSArtem Bityutskiy } 5521e51764aSArtem Bityutskiy default: 5531e51764aSArtem Bityutskiy printk(KERN_DEBUG "node type %d was not recognized\n", 5541e51764aSArtem Bityutskiy (int)ch->node_type); 5551e51764aSArtem Bityutskiy } 5561e51764aSArtem Bityutskiy spin_unlock(&dbg_lock); 5571e51764aSArtem Bityutskiy } 5581e51764aSArtem Bityutskiy 5591e51764aSArtem Bityutskiy void dbg_dump_budget_req(const struct ubifs_budget_req *req) 5601e51764aSArtem Bityutskiy { 5611e51764aSArtem Bityutskiy spin_lock(&dbg_lock); 5621e51764aSArtem Bityutskiy printk(KERN_DEBUG "Budgeting request: new_ino %d, dirtied_ino %d\n", 5631e51764aSArtem Bityutskiy req->new_ino, req->dirtied_ino); 5641e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tnew_ino_d %d, dirtied_ino_d %d\n", 5651e51764aSArtem Bityutskiy req->new_ino_d, req->dirtied_ino_d); 5661e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tnew_page %d, dirtied_page %d\n", 5671e51764aSArtem Bityutskiy req->new_page, req->dirtied_page); 5681e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tnew_dent %d, mod_dent %d\n", 5691e51764aSArtem Bityutskiy req->new_dent, req->mod_dent); 5701e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tidx_growth %d\n", req->idx_growth); 5711e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tdata_growth %d dd_growth %d\n", 5721e51764aSArtem Bityutskiy req->data_growth, req->dd_growth); 5731e51764aSArtem Bityutskiy spin_unlock(&dbg_lock); 5741e51764aSArtem Bityutskiy } 5751e51764aSArtem Bityutskiy 5761e51764aSArtem Bityutskiy void dbg_dump_lstats(const struct ubifs_lp_stats *lst) 5771e51764aSArtem Bityutskiy { 5781e51764aSArtem Bityutskiy spin_lock(&dbg_lock); 5791de94159SArtem Bityutskiy printk(KERN_DEBUG "(pid %d) Lprops statistics: empty_lebs %d, " 5801de94159SArtem Bityutskiy "idx_lebs %d\n", current->pid, lst->empty_lebs, lst->idx_lebs); 5811e51764aSArtem Bityutskiy printk(KERN_DEBUG "\ttaken_empty_lebs %d, total_free %lld, " 5821e51764aSArtem Bityutskiy "total_dirty %lld\n", lst->taken_empty_lebs, lst->total_free, 5831e51764aSArtem Bityutskiy lst->total_dirty); 5841e51764aSArtem Bityutskiy printk(KERN_DEBUG "\ttotal_used %lld, total_dark %lld, " 5851e51764aSArtem Bityutskiy "total_dead %lld\n", lst->total_used, lst->total_dark, 5861e51764aSArtem Bityutskiy lst->total_dead); 5871e51764aSArtem Bityutskiy spin_unlock(&dbg_lock); 5881e51764aSArtem Bityutskiy } 5891e51764aSArtem Bityutskiy 5901e51764aSArtem Bityutskiy void dbg_dump_budg(struct ubifs_info *c) 5911e51764aSArtem Bityutskiy { 5921e51764aSArtem Bityutskiy int i; 5931e51764aSArtem Bityutskiy struct rb_node *rb; 5941e51764aSArtem Bityutskiy struct ubifs_bud *bud; 5951e51764aSArtem Bityutskiy struct ubifs_gced_idx_leb *idx_gc; 5961e51764aSArtem Bityutskiy 5971e51764aSArtem Bityutskiy spin_lock(&dbg_lock); 5981de94159SArtem Bityutskiy printk(KERN_DEBUG "(pid %d) Budgeting info: budg_data_growth %lld, " 5991de94159SArtem Bityutskiy "budg_dd_growth %lld, budg_idx_growth %lld\n", current->pid, 6001e51764aSArtem Bityutskiy c->budg_data_growth, c->budg_dd_growth, c->budg_idx_growth); 6011e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tdata budget sum %lld, total budget sum %lld, " 6021e51764aSArtem Bityutskiy "freeable_cnt %d\n", c->budg_data_growth + c->budg_dd_growth, 6031e51764aSArtem Bityutskiy c->budg_data_growth + c->budg_dd_growth + c->budg_idx_growth, 6041e51764aSArtem Bityutskiy c->freeable_cnt); 6051e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tmin_idx_lebs %d, old_idx_sz %lld, " 6061e51764aSArtem Bityutskiy "calc_idx_sz %lld, idx_gc_cnt %d\n", c->min_idx_lebs, 6071e51764aSArtem Bityutskiy c->old_idx_sz, c->calc_idx_sz, c->idx_gc_cnt); 6081e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tdirty_pg_cnt %ld, dirty_zn_cnt %ld, " 6091e51764aSArtem Bityutskiy "clean_zn_cnt %ld\n", atomic_long_read(&c->dirty_pg_cnt), 6101e51764aSArtem Bityutskiy atomic_long_read(&c->dirty_zn_cnt), 6111e51764aSArtem Bityutskiy atomic_long_read(&c->clean_zn_cnt)); 6121e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tdark_wm %d, dead_wm %d, max_idx_node_sz %d\n", 6131e51764aSArtem Bityutskiy c->dark_wm, c->dead_wm, c->max_idx_node_sz); 6141e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tgc_lnum %d, ihead_lnum %d\n", 6151e51764aSArtem Bityutskiy c->gc_lnum, c->ihead_lnum); 6161e51764aSArtem Bityutskiy for (i = 0; i < c->jhead_cnt; i++) 6171e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tjhead %d\t LEB %d\n", 6181e51764aSArtem Bityutskiy c->jheads[i].wbuf.jhead, c->jheads[i].wbuf.lnum); 6191e51764aSArtem Bityutskiy for (rb = rb_first(&c->buds); rb; rb = rb_next(rb)) { 6201e51764aSArtem Bityutskiy bud = rb_entry(rb, struct ubifs_bud, rb); 6211e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tbud LEB %d\n", bud->lnum); 6221e51764aSArtem Bityutskiy } 6231e51764aSArtem Bityutskiy list_for_each_entry(bud, &c->old_buds, list) 6241e51764aSArtem Bityutskiy printk(KERN_DEBUG "\told bud LEB %d\n", bud->lnum); 6251e51764aSArtem Bityutskiy list_for_each_entry(idx_gc, &c->idx_gc, list) 6261e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tGC'ed idx LEB %d unmap %d\n", 6271e51764aSArtem Bityutskiy idx_gc->lnum, idx_gc->unmap); 6281e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tcommit state %d\n", c->cmt_state); 6291e51764aSArtem Bityutskiy spin_unlock(&dbg_lock); 6301e51764aSArtem Bityutskiy } 6311e51764aSArtem Bityutskiy 6321e51764aSArtem Bityutskiy void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp) 6331e51764aSArtem Bityutskiy { 6341e51764aSArtem Bityutskiy printk(KERN_DEBUG "LEB %d lprops: free %d, dirty %d (used %d), " 6351e51764aSArtem Bityutskiy "flags %#x\n", lp->lnum, lp->free, lp->dirty, 6361e51764aSArtem Bityutskiy c->leb_size - lp->free - lp->dirty, lp->flags); 6371e51764aSArtem Bityutskiy } 6381e51764aSArtem Bityutskiy 6391e51764aSArtem Bityutskiy void dbg_dump_lprops(struct ubifs_info *c) 6401e51764aSArtem Bityutskiy { 6411e51764aSArtem Bityutskiy int lnum, err; 6421e51764aSArtem Bityutskiy struct ubifs_lprops lp; 6431e51764aSArtem Bityutskiy struct ubifs_lp_stats lst; 6441e51764aSArtem Bityutskiy 6451de94159SArtem Bityutskiy printk(KERN_DEBUG "(pid %d) Dumping LEB properties\n", current->pid); 6461e51764aSArtem Bityutskiy ubifs_get_lp_stats(c, &lst); 6471e51764aSArtem Bityutskiy dbg_dump_lstats(&lst); 6481e51764aSArtem Bityutskiy 6491e51764aSArtem Bityutskiy for (lnum = c->main_first; lnum < c->leb_cnt; lnum++) { 6501e51764aSArtem Bityutskiy err = ubifs_read_one_lp(c, lnum, &lp); 6511e51764aSArtem Bityutskiy if (err) 6521e51764aSArtem Bityutskiy ubifs_err("cannot read lprops for LEB %d", lnum); 6531e51764aSArtem Bityutskiy 6541e51764aSArtem Bityutskiy dbg_dump_lprop(c, &lp); 6551e51764aSArtem Bityutskiy } 6561e51764aSArtem Bityutskiy } 6571e51764aSArtem Bityutskiy 658*73944a6dSAdrian Hunter void dbg_dump_lpt_info(struct ubifs_info *c) 659*73944a6dSAdrian Hunter { 660*73944a6dSAdrian Hunter int i; 661*73944a6dSAdrian Hunter 662*73944a6dSAdrian Hunter spin_lock(&dbg_lock); 663*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tlpt_sz: %lld\n", c->lpt_sz); 664*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tpnode_sz: %d\n", c->pnode_sz); 665*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tnnode_sz: %d\n", c->nnode_sz); 666*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tltab_sz: %d\n", c->ltab_sz); 667*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tlsave_sz: %d\n", c->lsave_sz); 668*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tbig_lpt: %d\n", c->big_lpt); 669*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tlpt_hght: %d\n", c->lpt_hght); 670*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tpnode_cnt: %d\n", c->pnode_cnt); 671*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tnnode_cnt: %d\n", c->nnode_cnt); 672*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tdirty_pn_cnt: %d\n", c->dirty_pn_cnt); 673*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tdirty_nn_cnt: %d\n", c->dirty_nn_cnt); 674*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tlsave_cnt: %d\n", c->lsave_cnt); 675*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tspace_bits: %d\n", c->space_bits); 676*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tlpt_lnum_bits: %d\n", c->lpt_lnum_bits); 677*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tlpt_offs_bits: %d\n", c->lpt_offs_bits); 678*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tlpt_spc_bits: %d\n", c->lpt_spc_bits); 679*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tpcnt_bits: %d\n", c->pcnt_bits); 680*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tlnum_bits: %d\n", c->lnum_bits); 681*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tLPT root is at %d:%d\n", c->lpt_lnum, c->lpt_offs); 682*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tLPT head is at %d:%d\n", 683*73944a6dSAdrian Hunter c->nhead_lnum, c->nhead_offs); 684*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tLPT ltab is at %d:%d\n", c->ltab_lnum, c->ltab_offs); 685*73944a6dSAdrian Hunter if (c->big_lpt) 686*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tLPT lsave is at %d:%d\n", 687*73944a6dSAdrian Hunter c->lsave_lnum, c->lsave_offs); 688*73944a6dSAdrian Hunter for (i = 0; i < c->lpt_lebs; i++) 689*73944a6dSAdrian Hunter printk(KERN_DEBUG "\tLPT LEB %d free %d dirty %d tgc %d " 690*73944a6dSAdrian Hunter "cmt %d\n", i + c->lpt_first, c->ltab[i].free, 691*73944a6dSAdrian Hunter c->ltab[i].dirty, c->ltab[i].tgc, c->ltab[i].cmt); 692*73944a6dSAdrian Hunter spin_unlock(&dbg_lock); 693*73944a6dSAdrian Hunter } 694*73944a6dSAdrian Hunter 6951e51764aSArtem Bityutskiy void dbg_dump_leb(const struct ubifs_info *c, int lnum) 6961e51764aSArtem Bityutskiy { 6971e51764aSArtem Bityutskiy struct ubifs_scan_leb *sleb; 6981e51764aSArtem Bityutskiy struct ubifs_scan_node *snod; 6991e51764aSArtem Bityutskiy 7001e51764aSArtem Bityutskiy if (dbg_failure_mode) 7011e51764aSArtem Bityutskiy return; 7021e51764aSArtem Bityutskiy 7031de94159SArtem Bityutskiy printk(KERN_DEBUG "(pid %d) Dumping LEB %d\n", current->pid, lnum); 7041e51764aSArtem Bityutskiy 7051e51764aSArtem Bityutskiy sleb = ubifs_scan(c, lnum, 0, c->dbg_buf); 7061e51764aSArtem Bityutskiy if (IS_ERR(sleb)) { 7071e51764aSArtem Bityutskiy ubifs_err("scan error %d", (int)PTR_ERR(sleb)); 7081e51764aSArtem Bityutskiy return; 7091e51764aSArtem Bityutskiy } 7101e51764aSArtem Bityutskiy 7111e51764aSArtem Bityutskiy printk(KERN_DEBUG "LEB %d has %d nodes ending at %d\n", lnum, 7121e51764aSArtem Bityutskiy sleb->nodes_cnt, sleb->endpt); 7131e51764aSArtem Bityutskiy 7141e51764aSArtem Bityutskiy list_for_each_entry(snod, &sleb->nodes, list) { 7151e51764aSArtem Bityutskiy cond_resched(); 7161e51764aSArtem Bityutskiy printk(KERN_DEBUG "Dumping node at LEB %d:%d len %d\n", lnum, 7171e51764aSArtem Bityutskiy snod->offs, snod->len); 7181e51764aSArtem Bityutskiy dbg_dump_node(c, snod->node); 7191e51764aSArtem Bityutskiy } 7201e51764aSArtem Bityutskiy 7211e51764aSArtem Bityutskiy ubifs_scan_destroy(sleb); 7221e51764aSArtem Bityutskiy return; 7231e51764aSArtem Bityutskiy } 7241e51764aSArtem Bityutskiy 7251e51764aSArtem Bityutskiy void dbg_dump_znode(const struct ubifs_info *c, 7261e51764aSArtem Bityutskiy const struct ubifs_znode *znode) 7271e51764aSArtem Bityutskiy { 7281e51764aSArtem Bityutskiy int n; 7291e51764aSArtem Bityutskiy const struct ubifs_zbranch *zbr; 7301e51764aSArtem Bityutskiy 7311e51764aSArtem Bityutskiy spin_lock(&dbg_lock); 7321e51764aSArtem Bityutskiy if (znode->parent) 7331e51764aSArtem Bityutskiy zbr = &znode->parent->zbranch[znode->iip]; 7341e51764aSArtem Bityutskiy else 7351e51764aSArtem Bityutskiy zbr = &c->zroot; 7361e51764aSArtem Bityutskiy 7371e51764aSArtem Bityutskiy printk(KERN_DEBUG "znode %p, LEB %d:%d len %d parent %p iip %d level %d" 7381e51764aSArtem Bityutskiy " child_cnt %d flags %lx\n", znode, zbr->lnum, zbr->offs, 7391e51764aSArtem Bityutskiy zbr->len, znode->parent, znode->iip, znode->level, 7401e51764aSArtem Bityutskiy znode->child_cnt, znode->flags); 7411e51764aSArtem Bityutskiy 7421e51764aSArtem Bityutskiy if (znode->child_cnt <= 0 || znode->child_cnt > c->fanout) { 7431e51764aSArtem Bityutskiy spin_unlock(&dbg_lock); 7441e51764aSArtem Bityutskiy return; 7451e51764aSArtem Bityutskiy } 7461e51764aSArtem Bityutskiy 7471e51764aSArtem Bityutskiy printk(KERN_DEBUG "zbranches:\n"); 7481e51764aSArtem Bityutskiy for (n = 0; n < znode->child_cnt; n++) { 7491e51764aSArtem Bityutskiy zbr = &znode->zbranch[n]; 7501e51764aSArtem Bityutskiy if (znode->level > 0) 7511e51764aSArtem Bityutskiy printk(KERN_DEBUG "\t%d: znode %p LEB %d:%d len %d key " 7521e51764aSArtem Bityutskiy "%s\n", n, zbr->znode, zbr->lnum, 7531e51764aSArtem Bityutskiy zbr->offs, zbr->len, 7541e51764aSArtem Bityutskiy DBGKEY(&zbr->key)); 7551e51764aSArtem Bityutskiy else 7561e51764aSArtem Bityutskiy printk(KERN_DEBUG "\t%d: LNC %p LEB %d:%d len %d key " 7571e51764aSArtem Bityutskiy "%s\n", n, zbr->znode, zbr->lnum, 7581e51764aSArtem Bityutskiy zbr->offs, zbr->len, 7591e51764aSArtem Bityutskiy DBGKEY(&zbr->key)); 7601e51764aSArtem Bityutskiy } 7611e51764aSArtem Bityutskiy spin_unlock(&dbg_lock); 7621e51764aSArtem Bityutskiy } 7631e51764aSArtem Bityutskiy 7641e51764aSArtem Bityutskiy void dbg_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat) 7651e51764aSArtem Bityutskiy { 7661e51764aSArtem Bityutskiy int i; 7671e51764aSArtem Bityutskiy 7681de94159SArtem Bityutskiy printk(KERN_DEBUG "(pid %d) Dumping heap cat %d (%d elements)\n", 7691de94159SArtem Bityutskiy current->pid, cat, heap->cnt); 7701e51764aSArtem Bityutskiy for (i = 0; i < heap->cnt; i++) { 7711e51764aSArtem Bityutskiy struct ubifs_lprops *lprops = heap->arr[i]; 7721e51764aSArtem Bityutskiy 7731e51764aSArtem Bityutskiy printk(KERN_DEBUG "\t%d. LEB %d hpos %d free %d dirty %d " 7741e51764aSArtem Bityutskiy "flags %d\n", i, lprops->lnum, lprops->hpos, 7751e51764aSArtem Bityutskiy lprops->free, lprops->dirty, lprops->flags); 7761e51764aSArtem Bityutskiy } 7771e51764aSArtem Bityutskiy } 7781e51764aSArtem Bityutskiy 7791e51764aSArtem Bityutskiy void dbg_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode, 7801e51764aSArtem Bityutskiy struct ubifs_nnode *parent, int iip) 7811e51764aSArtem Bityutskiy { 7821e51764aSArtem Bityutskiy int i; 7831e51764aSArtem Bityutskiy 7841de94159SArtem Bityutskiy printk(KERN_DEBUG "(pid %d) Dumping pnode:\n", current->pid); 7851e51764aSArtem Bityutskiy printk(KERN_DEBUG "\taddress %zx parent %zx cnext %zx\n", 7861e51764aSArtem Bityutskiy (size_t)pnode, (size_t)parent, (size_t)pnode->cnext); 7871e51764aSArtem Bityutskiy printk(KERN_DEBUG "\tflags %lu iip %d level %d num %d\n", 7881e51764aSArtem Bityutskiy pnode->flags, iip, pnode->level, pnode->num); 7891e51764aSArtem Bityutskiy for (i = 0; i < UBIFS_LPT_FANOUT; i++) { 7901e51764aSArtem Bityutskiy struct ubifs_lprops *lp = &pnode->lprops[i]; 7911e51764aSArtem Bityutskiy 7921e51764aSArtem Bityutskiy printk(KERN_DEBUG "\t%d: free %d dirty %d flags %d lnum %d\n", 7931e51764aSArtem Bityutskiy i, lp->free, lp->dirty, lp->flags, lp->lnum); 7941e51764aSArtem Bityutskiy } 7951e51764aSArtem Bityutskiy } 7961e51764aSArtem Bityutskiy 7971e51764aSArtem Bityutskiy void dbg_dump_tnc(struct ubifs_info *c) 7981e51764aSArtem Bityutskiy { 7991e51764aSArtem Bityutskiy struct ubifs_znode *znode; 8001e51764aSArtem Bityutskiy int level; 8011e51764aSArtem Bityutskiy 8021e51764aSArtem Bityutskiy printk(KERN_DEBUG "\n"); 8031de94159SArtem Bityutskiy printk(KERN_DEBUG "(pid %d) Dumping the TNC tree\n", current->pid); 8041e51764aSArtem Bityutskiy znode = ubifs_tnc_levelorder_next(c->zroot.znode, NULL); 8051e51764aSArtem Bityutskiy level = znode->level; 8061e51764aSArtem Bityutskiy printk(KERN_DEBUG "== Level %d ==\n", level); 8071e51764aSArtem Bityutskiy while (znode) { 8081e51764aSArtem Bityutskiy if (level != znode->level) { 8091e51764aSArtem Bityutskiy level = znode->level; 8101e51764aSArtem Bityutskiy printk(KERN_DEBUG "== Level %d ==\n", level); 8111e51764aSArtem Bityutskiy } 8121e51764aSArtem Bityutskiy dbg_dump_znode(c, znode); 8131e51764aSArtem Bityutskiy znode = ubifs_tnc_levelorder_next(c->zroot.znode, znode); 8141e51764aSArtem Bityutskiy } 8151e51764aSArtem Bityutskiy 8161e51764aSArtem Bityutskiy printk(KERN_DEBUG "\n"); 8171e51764aSArtem Bityutskiy } 8181e51764aSArtem Bityutskiy 8191e51764aSArtem Bityutskiy static int dump_znode(struct ubifs_info *c, struct ubifs_znode *znode, 8201e51764aSArtem Bityutskiy void *priv) 8211e51764aSArtem Bityutskiy { 8221e51764aSArtem Bityutskiy dbg_dump_znode(c, znode); 8231e51764aSArtem Bityutskiy return 0; 8241e51764aSArtem Bityutskiy } 8251e51764aSArtem Bityutskiy 8261e51764aSArtem Bityutskiy /** 8271e51764aSArtem Bityutskiy * dbg_dump_index - dump the on-flash index. 8281e51764aSArtem Bityutskiy * @c: UBIFS file-system description object 8291e51764aSArtem Bityutskiy * 8301e51764aSArtem Bityutskiy * This function dumps whole UBIFS indexing B-tree, unlike 'dbg_dump_tnc()' 8311e51764aSArtem Bityutskiy * which dumps only in-memory znodes and does not read znodes which from flash. 8321e51764aSArtem Bityutskiy */ 8331e51764aSArtem Bityutskiy void dbg_dump_index(struct ubifs_info *c) 8341e51764aSArtem Bityutskiy { 8351e51764aSArtem Bityutskiy dbg_walk_index(c, NULL, dump_znode, NULL); 8361e51764aSArtem Bityutskiy } 8371e51764aSArtem Bityutskiy 8381e51764aSArtem Bityutskiy /** 8391e51764aSArtem Bityutskiy * dbg_check_synced_i_size - check synchronized inode size. 8401e51764aSArtem Bityutskiy * @inode: inode to check 8411e51764aSArtem Bityutskiy * 8421e51764aSArtem Bityutskiy * If inode is clean, synchronized inode size has to be equivalent to current 8431e51764aSArtem Bityutskiy * inode size. This function has to be called only for locked inodes (@i_mutex 8441e51764aSArtem Bityutskiy * has to be locked). Returns %0 if synchronized inode size if correct, and 8451e51764aSArtem Bityutskiy * %-EINVAL if not. 8461e51764aSArtem Bityutskiy */ 8471e51764aSArtem Bityutskiy int dbg_check_synced_i_size(struct inode *inode) 8481e51764aSArtem Bityutskiy { 8491e51764aSArtem Bityutskiy int err = 0; 8501e51764aSArtem Bityutskiy struct ubifs_inode *ui = ubifs_inode(inode); 8511e51764aSArtem Bityutskiy 8521e51764aSArtem Bityutskiy if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) 8531e51764aSArtem Bityutskiy return 0; 8541e51764aSArtem Bityutskiy if (!S_ISREG(inode->i_mode)) 8551e51764aSArtem Bityutskiy return 0; 8561e51764aSArtem Bityutskiy 8571e51764aSArtem Bityutskiy mutex_lock(&ui->ui_mutex); 8581e51764aSArtem Bityutskiy spin_lock(&ui->ui_lock); 8591e51764aSArtem Bityutskiy if (ui->ui_size != ui->synced_i_size && !ui->dirty) { 8601e51764aSArtem Bityutskiy ubifs_err("ui_size is %lld, synced_i_size is %lld, but inode " 8611e51764aSArtem Bityutskiy "is clean", ui->ui_size, ui->synced_i_size); 8621e51764aSArtem Bityutskiy ubifs_err("i_ino %lu, i_mode %#x, i_size %lld", inode->i_ino, 8631e51764aSArtem Bityutskiy inode->i_mode, i_size_read(inode)); 8641e51764aSArtem Bityutskiy dbg_dump_stack(); 8651e51764aSArtem Bityutskiy err = -EINVAL; 8661e51764aSArtem Bityutskiy } 8671e51764aSArtem Bityutskiy spin_unlock(&ui->ui_lock); 8681e51764aSArtem Bityutskiy mutex_unlock(&ui->ui_mutex); 8691e51764aSArtem Bityutskiy return err; 8701e51764aSArtem Bityutskiy } 8711e51764aSArtem Bityutskiy 8721e51764aSArtem Bityutskiy /* 8731e51764aSArtem Bityutskiy * dbg_check_dir - check directory inode size and link count. 8741e51764aSArtem Bityutskiy * @c: UBIFS file-system description object 8751e51764aSArtem Bityutskiy * @dir: the directory to calculate size for 8761e51764aSArtem Bityutskiy * @size: the result is returned here 8771e51764aSArtem Bityutskiy * 8781e51764aSArtem Bityutskiy * This function makes sure that directory size and link count are correct. 8791e51764aSArtem Bityutskiy * Returns zero in case of success and a negative error code in case of 8801e51764aSArtem Bityutskiy * failure. 8811e51764aSArtem Bityutskiy * 8821e51764aSArtem Bityutskiy * Note, it is good idea to make sure the @dir->i_mutex is locked before 8831e51764aSArtem Bityutskiy * calling this function. 8841e51764aSArtem Bityutskiy */ 8851e51764aSArtem Bityutskiy int dbg_check_dir_size(struct ubifs_info *c, const struct inode *dir) 8861e51764aSArtem Bityutskiy { 8871e51764aSArtem Bityutskiy unsigned int nlink = 2; 8881e51764aSArtem Bityutskiy union ubifs_key key; 8891e51764aSArtem Bityutskiy struct ubifs_dent_node *dent, *pdent = NULL; 8901e51764aSArtem Bityutskiy struct qstr nm = { .name = NULL }; 8911e51764aSArtem Bityutskiy loff_t size = UBIFS_INO_NODE_SZ; 8921e51764aSArtem Bityutskiy 8931e51764aSArtem Bityutskiy if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) 8941e51764aSArtem Bityutskiy return 0; 8951e51764aSArtem Bityutskiy 8961e51764aSArtem Bityutskiy if (!S_ISDIR(dir->i_mode)) 8971e51764aSArtem Bityutskiy return 0; 8981e51764aSArtem Bityutskiy 8991e51764aSArtem Bityutskiy lowest_dent_key(c, &key, dir->i_ino); 9001e51764aSArtem Bityutskiy while (1) { 9011e51764aSArtem Bityutskiy int err; 9021e51764aSArtem Bityutskiy 9031e51764aSArtem Bityutskiy dent = ubifs_tnc_next_ent(c, &key, &nm); 9041e51764aSArtem Bityutskiy if (IS_ERR(dent)) { 9051e51764aSArtem Bityutskiy err = PTR_ERR(dent); 9061e51764aSArtem Bityutskiy if (err == -ENOENT) 9071e51764aSArtem Bityutskiy break; 9081e51764aSArtem Bityutskiy return err; 9091e51764aSArtem Bityutskiy } 9101e51764aSArtem Bityutskiy 9111e51764aSArtem Bityutskiy nm.name = dent->name; 9121e51764aSArtem Bityutskiy nm.len = le16_to_cpu(dent->nlen); 9131e51764aSArtem Bityutskiy size += CALC_DENT_SIZE(nm.len); 9141e51764aSArtem Bityutskiy if (dent->type == UBIFS_ITYPE_DIR) 9151e51764aSArtem Bityutskiy nlink += 1; 9161e51764aSArtem Bityutskiy kfree(pdent); 9171e51764aSArtem Bityutskiy pdent = dent; 9181e51764aSArtem Bityutskiy key_read(c, &dent->key, &key); 9191e51764aSArtem Bityutskiy } 9201e51764aSArtem Bityutskiy kfree(pdent); 9211e51764aSArtem Bityutskiy 9221e51764aSArtem Bityutskiy if (i_size_read(dir) != size) { 9231e51764aSArtem Bityutskiy ubifs_err("directory inode %lu has size %llu, " 9241e51764aSArtem Bityutskiy "but calculated size is %llu", dir->i_ino, 9251e51764aSArtem Bityutskiy (unsigned long long)i_size_read(dir), 9261e51764aSArtem Bityutskiy (unsigned long long)size); 9271e51764aSArtem Bityutskiy dump_stack(); 9281e51764aSArtem Bityutskiy return -EINVAL; 9291e51764aSArtem Bityutskiy } 9301e51764aSArtem Bityutskiy if (dir->i_nlink != nlink) { 9311e51764aSArtem Bityutskiy ubifs_err("directory inode %lu has nlink %u, but calculated " 9321e51764aSArtem Bityutskiy "nlink is %u", dir->i_ino, dir->i_nlink, nlink); 9331e51764aSArtem Bityutskiy dump_stack(); 9341e51764aSArtem Bityutskiy return -EINVAL; 9351e51764aSArtem Bityutskiy } 9361e51764aSArtem Bityutskiy 9371e51764aSArtem Bityutskiy return 0; 9381e51764aSArtem Bityutskiy } 9391e51764aSArtem Bityutskiy 9401e51764aSArtem Bityutskiy /** 9411e51764aSArtem Bityutskiy * dbg_check_key_order - make sure that colliding keys are properly ordered. 9421e51764aSArtem Bityutskiy * @c: UBIFS file-system description object 9431e51764aSArtem Bityutskiy * @zbr1: first zbranch 9441e51764aSArtem Bityutskiy * @zbr2: following zbranch 9451e51764aSArtem Bityutskiy * 9461e51764aSArtem Bityutskiy * In UBIFS indexing B-tree colliding keys has to be sorted in binary order of 9471e51764aSArtem Bityutskiy * names of the direntries/xentries which are referred by the keys. This 9481e51764aSArtem Bityutskiy * function reads direntries/xentries referred by @zbr1 and @zbr2 and makes 9491e51764aSArtem Bityutskiy * sure the name of direntry/xentry referred by @zbr1 is less than 9501e51764aSArtem Bityutskiy * direntry/xentry referred by @zbr2. Returns zero if this is true, %1 if not, 9511e51764aSArtem Bityutskiy * and a negative error code in case of failure. 9521e51764aSArtem Bityutskiy */ 9531e51764aSArtem Bityutskiy static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1, 9541e51764aSArtem Bityutskiy struct ubifs_zbranch *zbr2) 9551e51764aSArtem Bityutskiy { 9561e51764aSArtem Bityutskiy int err, nlen1, nlen2, cmp; 9571e51764aSArtem Bityutskiy struct ubifs_dent_node *dent1, *dent2; 9581e51764aSArtem Bityutskiy union ubifs_key key; 9591e51764aSArtem Bityutskiy 9601e51764aSArtem Bityutskiy ubifs_assert(!keys_cmp(c, &zbr1->key, &zbr2->key)); 9611e51764aSArtem Bityutskiy dent1 = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS); 9621e51764aSArtem Bityutskiy if (!dent1) 9631e51764aSArtem Bityutskiy return -ENOMEM; 9641e51764aSArtem Bityutskiy dent2 = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS); 9651e51764aSArtem Bityutskiy if (!dent2) { 9661e51764aSArtem Bityutskiy err = -ENOMEM; 9671e51764aSArtem Bityutskiy goto out_free; 9681e51764aSArtem Bityutskiy } 9691e51764aSArtem Bityutskiy 9701e51764aSArtem Bityutskiy err = ubifs_tnc_read_node(c, zbr1, dent1); 9711e51764aSArtem Bityutskiy if (err) 9721e51764aSArtem Bityutskiy goto out_free; 9731e51764aSArtem Bityutskiy err = ubifs_validate_entry(c, dent1); 9741e51764aSArtem Bityutskiy if (err) 9751e51764aSArtem Bityutskiy goto out_free; 9761e51764aSArtem Bityutskiy 9771e51764aSArtem Bityutskiy err = ubifs_tnc_read_node(c, zbr2, dent2); 9781e51764aSArtem Bityutskiy if (err) 9791e51764aSArtem Bityutskiy goto out_free; 9801e51764aSArtem Bityutskiy err = ubifs_validate_entry(c, dent2); 9811e51764aSArtem Bityutskiy if (err) 9821e51764aSArtem Bityutskiy goto out_free; 9831e51764aSArtem Bityutskiy 9841e51764aSArtem Bityutskiy /* Make sure node keys are the same as in zbranch */ 9851e51764aSArtem Bityutskiy err = 1; 9861e51764aSArtem Bityutskiy key_read(c, &dent1->key, &key); 9871e51764aSArtem Bityutskiy if (keys_cmp(c, &zbr1->key, &key)) { 9881e51764aSArtem Bityutskiy dbg_err("1st entry at %d:%d has key %s", zbr1->lnum, 9891e51764aSArtem Bityutskiy zbr1->offs, DBGKEY(&key)); 9901e51764aSArtem Bityutskiy dbg_err("but it should have key %s according to tnc", 9911e51764aSArtem Bityutskiy DBGKEY(&zbr1->key)); 9921e51764aSArtem Bityutskiy dbg_dump_node(c, dent1); 9931e51764aSArtem Bityutskiy goto out_free; 9941e51764aSArtem Bityutskiy } 9951e51764aSArtem Bityutskiy 9961e51764aSArtem Bityutskiy key_read(c, &dent2->key, &key); 9971e51764aSArtem Bityutskiy if (keys_cmp(c, &zbr2->key, &key)) { 9981e51764aSArtem Bityutskiy dbg_err("2nd entry at %d:%d has key %s", zbr1->lnum, 9991e51764aSArtem Bityutskiy zbr1->offs, DBGKEY(&key)); 10001e51764aSArtem Bityutskiy dbg_err("but it should have key %s according to tnc", 10011e51764aSArtem Bityutskiy DBGKEY(&zbr2->key)); 10021e51764aSArtem Bityutskiy dbg_dump_node(c, dent2); 10031e51764aSArtem Bityutskiy goto out_free; 10041e51764aSArtem Bityutskiy } 10051e51764aSArtem Bityutskiy 10061e51764aSArtem Bityutskiy nlen1 = le16_to_cpu(dent1->nlen); 10071e51764aSArtem Bityutskiy nlen2 = le16_to_cpu(dent2->nlen); 10081e51764aSArtem Bityutskiy 10091e51764aSArtem Bityutskiy cmp = memcmp(dent1->name, dent2->name, min_t(int, nlen1, nlen2)); 10101e51764aSArtem Bityutskiy if (cmp < 0 || (cmp == 0 && nlen1 < nlen2)) { 10111e51764aSArtem Bityutskiy err = 0; 10121e51764aSArtem Bityutskiy goto out_free; 10131e51764aSArtem Bityutskiy } 10141e51764aSArtem Bityutskiy if (cmp == 0 && nlen1 == nlen2) 10151e51764aSArtem Bityutskiy dbg_err("2 xent/dent nodes with the same name"); 10161e51764aSArtem Bityutskiy else 10171e51764aSArtem Bityutskiy dbg_err("bad order of colliding key %s", 10181e51764aSArtem Bityutskiy DBGKEY(&key)); 10191e51764aSArtem Bityutskiy 10201e51764aSArtem Bityutskiy dbg_msg("first node at %d:%d\n", zbr1->lnum, zbr1->offs); 10211e51764aSArtem Bityutskiy dbg_dump_node(c, dent1); 10221e51764aSArtem Bityutskiy dbg_msg("second node at %d:%d\n", zbr2->lnum, zbr2->offs); 10231e51764aSArtem Bityutskiy dbg_dump_node(c, dent2); 10241e51764aSArtem Bityutskiy 10251e51764aSArtem Bityutskiy out_free: 10261e51764aSArtem Bityutskiy kfree(dent2); 10271e51764aSArtem Bityutskiy kfree(dent1); 10281e51764aSArtem Bityutskiy return err; 10291e51764aSArtem Bityutskiy } 10301e51764aSArtem Bityutskiy 10311e51764aSArtem Bityutskiy /** 10321e51764aSArtem Bityutskiy * dbg_check_znode - check if znode is all right. 10331e51764aSArtem Bityutskiy * @c: UBIFS file-system description object 10341e51764aSArtem Bityutskiy * @zbr: zbranch which points to this znode 10351e51764aSArtem Bityutskiy * 10361e51764aSArtem Bityutskiy * This function makes sure that znode referred to by @zbr is all right. 10371e51764aSArtem Bityutskiy * Returns zero if it is, and %-EINVAL if it is not. 10381e51764aSArtem Bityutskiy */ 10391e51764aSArtem Bityutskiy static int dbg_check_znode(struct ubifs_info *c, struct ubifs_zbranch *zbr) 10401e51764aSArtem Bityutskiy { 10411e51764aSArtem Bityutskiy struct ubifs_znode *znode = zbr->znode; 10421e51764aSArtem Bityutskiy struct ubifs_znode *zp = znode->parent; 10431e51764aSArtem Bityutskiy int n, err, cmp; 10441e51764aSArtem Bityutskiy 10451e51764aSArtem Bityutskiy if (znode->child_cnt <= 0 || znode->child_cnt > c->fanout) { 10461e51764aSArtem Bityutskiy err = 1; 10471e51764aSArtem Bityutskiy goto out; 10481e51764aSArtem Bityutskiy } 10491e51764aSArtem Bityutskiy if (znode->level < 0) { 10501e51764aSArtem Bityutskiy err = 2; 10511e51764aSArtem Bityutskiy goto out; 10521e51764aSArtem Bityutskiy } 10531e51764aSArtem Bityutskiy if (znode->iip < 0 || znode->iip >= c->fanout) { 10541e51764aSArtem Bityutskiy err = 3; 10551e51764aSArtem Bityutskiy goto out; 10561e51764aSArtem Bityutskiy } 10571e51764aSArtem Bityutskiy 10581e51764aSArtem Bityutskiy if (zbr->len == 0) 10591e51764aSArtem Bityutskiy /* Only dirty zbranch may have no on-flash nodes */ 10601e51764aSArtem Bityutskiy if (!ubifs_zn_dirty(znode)) { 10611e51764aSArtem Bityutskiy err = 4; 10621e51764aSArtem Bityutskiy goto out; 10631e51764aSArtem Bityutskiy } 10641e51764aSArtem Bityutskiy 10651e51764aSArtem Bityutskiy if (ubifs_zn_dirty(znode)) { 10661e51764aSArtem Bityutskiy /* 10671e51764aSArtem Bityutskiy * If znode is dirty, its parent has to be dirty as well. The 10681e51764aSArtem Bityutskiy * order of the operation is important, so we have to have 10691e51764aSArtem Bityutskiy * memory barriers. 10701e51764aSArtem Bityutskiy */ 10711e51764aSArtem Bityutskiy smp_mb(); 10721e51764aSArtem Bityutskiy if (zp && !ubifs_zn_dirty(zp)) { 10731e51764aSArtem Bityutskiy /* 10741e51764aSArtem Bityutskiy * The dirty flag is atomic and is cleared outside the 10751e51764aSArtem Bityutskiy * TNC mutex, so znode's dirty flag may now have 10761e51764aSArtem Bityutskiy * been cleared. The child is always cleared before the 10771e51764aSArtem Bityutskiy * parent, so we just need to check again. 10781e51764aSArtem Bityutskiy */ 10791e51764aSArtem Bityutskiy smp_mb(); 10801e51764aSArtem Bityutskiy if (ubifs_zn_dirty(znode)) { 10811e51764aSArtem Bityutskiy err = 5; 10821e51764aSArtem Bityutskiy goto out; 10831e51764aSArtem Bityutskiy } 10841e51764aSArtem Bityutskiy } 10851e51764aSArtem Bityutskiy } 10861e51764aSArtem Bityutskiy 10871e51764aSArtem Bityutskiy if (zp) { 10881e51764aSArtem Bityutskiy const union ubifs_key *min, *max; 10891e51764aSArtem Bityutskiy 10901e51764aSArtem Bityutskiy if (znode->level != zp->level - 1) { 10911e51764aSArtem Bityutskiy err = 6; 10921e51764aSArtem Bityutskiy goto out; 10931e51764aSArtem Bityutskiy } 10941e51764aSArtem Bityutskiy 10951e51764aSArtem Bityutskiy /* Make sure the 'parent' pointer in our znode is correct */ 10961e51764aSArtem Bityutskiy err = ubifs_search_zbranch(c, zp, &zbr->key, &n); 10971e51764aSArtem Bityutskiy if (!err) { 10981e51764aSArtem Bityutskiy /* This zbranch does not exist in the parent */ 10991e51764aSArtem Bityutskiy err = 7; 11001e51764aSArtem Bityutskiy goto out; 11011e51764aSArtem Bityutskiy } 11021e51764aSArtem Bityutskiy 11031e51764aSArtem Bityutskiy if (znode->iip >= zp->child_cnt) { 11041e51764aSArtem Bityutskiy err = 8; 11051e51764aSArtem Bityutskiy goto out; 11061e51764aSArtem Bityutskiy } 11071e51764aSArtem Bityutskiy 11081e51764aSArtem Bityutskiy if (znode->iip != n) { 11091e51764aSArtem Bityutskiy /* This may happen only in case of collisions */ 11101e51764aSArtem Bityutskiy if (keys_cmp(c, &zp->zbranch[n].key, 11111e51764aSArtem Bityutskiy &zp->zbranch[znode->iip].key)) { 11121e51764aSArtem Bityutskiy err = 9; 11131e51764aSArtem Bityutskiy goto out; 11141e51764aSArtem Bityutskiy } 11151e51764aSArtem Bityutskiy n = znode->iip; 11161e51764aSArtem Bityutskiy } 11171e51764aSArtem Bityutskiy 11181e51764aSArtem Bityutskiy /* 11191e51764aSArtem Bityutskiy * Make sure that the first key in our znode is greater than or 11201e51764aSArtem Bityutskiy * equal to the key in the pointing zbranch. 11211e51764aSArtem Bityutskiy */ 11221e51764aSArtem Bityutskiy min = &zbr->key; 11231e51764aSArtem Bityutskiy cmp = keys_cmp(c, min, &znode->zbranch[0].key); 11241e51764aSArtem Bityutskiy if (cmp == 1) { 11251e51764aSArtem Bityutskiy err = 10; 11261e51764aSArtem Bityutskiy goto out; 11271e51764aSArtem Bityutskiy } 11281e51764aSArtem Bityutskiy 11291e51764aSArtem Bityutskiy if (n + 1 < zp->child_cnt) { 11301e51764aSArtem Bityutskiy max = &zp->zbranch[n + 1].key; 11311e51764aSArtem Bityutskiy 11321e51764aSArtem Bityutskiy /* 11331e51764aSArtem Bityutskiy * Make sure the last key in our znode is less or 11341e51764aSArtem Bityutskiy * equivalent than the the key in zbranch which goes 11351e51764aSArtem Bityutskiy * after our pointing zbranch. 11361e51764aSArtem Bityutskiy */ 11371e51764aSArtem Bityutskiy cmp = keys_cmp(c, max, 11381e51764aSArtem Bityutskiy &znode->zbranch[znode->child_cnt - 1].key); 11391e51764aSArtem Bityutskiy if (cmp == -1) { 11401e51764aSArtem Bityutskiy err = 11; 11411e51764aSArtem Bityutskiy goto out; 11421e51764aSArtem Bityutskiy } 11431e51764aSArtem Bityutskiy } 11441e51764aSArtem Bityutskiy } else { 11451e51764aSArtem Bityutskiy /* This may only be root znode */ 11461e51764aSArtem Bityutskiy if (zbr != &c->zroot) { 11471e51764aSArtem Bityutskiy err = 12; 11481e51764aSArtem Bityutskiy goto out; 11491e51764aSArtem Bityutskiy } 11501e51764aSArtem Bityutskiy } 11511e51764aSArtem Bityutskiy 11521e51764aSArtem Bityutskiy /* 11531e51764aSArtem Bityutskiy * Make sure that next key is greater or equivalent then the previous 11541e51764aSArtem Bityutskiy * one. 11551e51764aSArtem Bityutskiy */ 11561e51764aSArtem Bityutskiy for (n = 1; n < znode->child_cnt; n++) { 11571e51764aSArtem Bityutskiy cmp = keys_cmp(c, &znode->zbranch[n - 1].key, 11581e51764aSArtem Bityutskiy &znode->zbranch[n].key); 11591e51764aSArtem Bityutskiy if (cmp > 0) { 11601e51764aSArtem Bityutskiy err = 13; 11611e51764aSArtem Bityutskiy goto out; 11621e51764aSArtem Bityutskiy } 11631e51764aSArtem Bityutskiy if (cmp == 0) { 11641e51764aSArtem Bityutskiy /* This can only be keys with colliding hash */ 11651e51764aSArtem Bityutskiy if (!is_hash_key(c, &znode->zbranch[n].key)) { 11661e51764aSArtem Bityutskiy err = 14; 11671e51764aSArtem Bityutskiy goto out; 11681e51764aSArtem Bityutskiy } 11691e51764aSArtem Bityutskiy 11701e51764aSArtem Bityutskiy if (znode->level != 0 || c->replaying) 11711e51764aSArtem Bityutskiy continue; 11721e51764aSArtem Bityutskiy 11731e51764aSArtem Bityutskiy /* 11741e51764aSArtem Bityutskiy * Colliding keys should follow binary order of 11751e51764aSArtem Bityutskiy * corresponding xentry/dentry names. 11761e51764aSArtem Bityutskiy */ 11771e51764aSArtem Bityutskiy err = dbg_check_key_order(c, &znode->zbranch[n - 1], 11781e51764aSArtem Bityutskiy &znode->zbranch[n]); 11791e51764aSArtem Bityutskiy if (err < 0) 11801e51764aSArtem Bityutskiy return err; 11811e51764aSArtem Bityutskiy if (err) { 11821e51764aSArtem Bityutskiy err = 15; 11831e51764aSArtem Bityutskiy goto out; 11841e51764aSArtem Bityutskiy } 11851e51764aSArtem Bityutskiy } 11861e51764aSArtem Bityutskiy } 11871e51764aSArtem Bityutskiy 11881e51764aSArtem Bityutskiy for (n = 0; n < znode->child_cnt; n++) { 11891e51764aSArtem Bityutskiy if (!znode->zbranch[n].znode && 11901e51764aSArtem Bityutskiy (znode->zbranch[n].lnum == 0 || 11911e51764aSArtem Bityutskiy znode->zbranch[n].len == 0)) { 11921e51764aSArtem Bityutskiy err = 16; 11931e51764aSArtem Bityutskiy goto out; 11941e51764aSArtem Bityutskiy } 11951e51764aSArtem Bityutskiy 11961e51764aSArtem Bityutskiy if (znode->zbranch[n].lnum != 0 && 11971e51764aSArtem Bityutskiy znode->zbranch[n].len == 0) { 11981e51764aSArtem Bityutskiy err = 17; 11991e51764aSArtem Bityutskiy goto out; 12001e51764aSArtem Bityutskiy } 12011e51764aSArtem Bityutskiy 12021e51764aSArtem Bityutskiy if (znode->zbranch[n].lnum == 0 && 12031e51764aSArtem Bityutskiy znode->zbranch[n].len != 0) { 12041e51764aSArtem Bityutskiy err = 18; 12051e51764aSArtem Bityutskiy goto out; 12061e51764aSArtem Bityutskiy } 12071e51764aSArtem Bityutskiy 12081e51764aSArtem Bityutskiy if (znode->zbranch[n].lnum == 0 && 12091e51764aSArtem Bityutskiy znode->zbranch[n].offs != 0) { 12101e51764aSArtem Bityutskiy err = 19; 12111e51764aSArtem Bityutskiy goto out; 12121e51764aSArtem Bityutskiy } 12131e51764aSArtem Bityutskiy 12141e51764aSArtem Bityutskiy if (znode->level != 0 && znode->zbranch[n].znode) 12151e51764aSArtem Bityutskiy if (znode->zbranch[n].znode->parent != znode) { 12161e51764aSArtem Bityutskiy err = 20; 12171e51764aSArtem Bityutskiy goto out; 12181e51764aSArtem Bityutskiy } 12191e51764aSArtem Bityutskiy } 12201e51764aSArtem Bityutskiy 12211e51764aSArtem Bityutskiy return 0; 12221e51764aSArtem Bityutskiy 12231e51764aSArtem Bityutskiy out: 12241e51764aSArtem Bityutskiy ubifs_err("failed, error %d", err); 12251e51764aSArtem Bityutskiy ubifs_msg("dump of the znode"); 12261e51764aSArtem Bityutskiy dbg_dump_znode(c, znode); 12271e51764aSArtem Bityutskiy if (zp) { 12281e51764aSArtem Bityutskiy ubifs_msg("dump of the parent znode"); 12291e51764aSArtem Bityutskiy dbg_dump_znode(c, zp); 12301e51764aSArtem Bityutskiy } 12311e51764aSArtem Bityutskiy dump_stack(); 12321e51764aSArtem Bityutskiy return -EINVAL; 12331e51764aSArtem Bityutskiy } 12341e51764aSArtem Bityutskiy 12351e51764aSArtem Bityutskiy /** 12361e51764aSArtem Bityutskiy * dbg_check_tnc - check TNC tree. 12371e51764aSArtem Bityutskiy * @c: UBIFS file-system description object 12381e51764aSArtem Bityutskiy * @extra: do extra checks that are possible at start commit 12391e51764aSArtem Bityutskiy * 12401e51764aSArtem Bityutskiy * This function traverses whole TNC tree and checks every znode. Returns zero 12411e51764aSArtem Bityutskiy * if everything is all right and %-EINVAL if something is wrong with TNC. 12421e51764aSArtem Bityutskiy */ 12431e51764aSArtem Bityutskiy int dbg_check_tnc(struct ubifs_info *c, int extra) 12441e51764aSArtem Bityutskiy { 12451e51764aSArtem Bityutskiy struct ubifs_znode *znode; 12461e51764aSArtem Bityutskiy long clean_cnt = 0, dirty_cnt = 0; 12471e51764aSArtem Bityutskiy int err, last; 12481e51764aSArtem Bityutskiy 12491e51764aSArtem Bityutskiy if (!(ubifs_chk_flags & UBIFS_CHK_TNC)) 12501e51764aSArtem Bityutskiy return 0; 12511e51764aSArtem Bityutskiy 12521e51764aSArtem Bityutskiy ubifs_assert(mutex_is_locked(&c->tnc_mutex)); 12531e51764aSArtem Bityutskiy if (!c->zroot.znode) 12541e51764aSArtem Bityutskiy return 0; 12551e51764aSArtem Bityutskiy 12561e51764aSArtem Bityutskiy znode = ubifs_tnc_postorder_first(c->zroot.znode); 12571e51764aSArtem Bityutskiy while (1) { 12581e51764aSArtem Bityutskiy struct ubifs_znode *prev; 12591e51764aSArtem Bityutskiy struct ubifs_zbranch *zbr; 12601e51764aSArtem Bityutskiy 12611e51764aSArtem Bityutskiy if (!znode->parent) 12621e51764aSArtem Bityutskiy zbr = &c->zroot; 12631e51764aSArtem Bityutskiy else 12641e51764aSArtem Bityutskiy zbr = &znode->parent->zbranch[znode->iip]; 12651e51764aSArtem Bityutskiy 12661e51764aSArtem Bityutskiy err = dbg_check_znode(c, zbr); 12671e51764aSArtem Bityutskiy if (err) 12681e51764aSArtem Bityutskiy return err; 12691e51764aSArtem Bityutskiy 12701e51764aSArtem Bityutskiy if (extra) { 12711e51764aSArtem Bityutskiy if (ubifs_zn_dirty(znode)) 12721e51764aSArtem Bityutskiy dirty_cnt += 1; 12731e51764aSArtem Bityutskiy else 12741e51764aSArtem Bityutskiy clean_cnt += 1; 12751e51764aSArtem Bityutskiy } 12761e51764aSArtem Bityutskiy 12771e51764aSArtem Bityutskiy prev = znode; 12781e51764aSArtem Bityutskiy znode = ubifs_tnc_postorder_next(znode); 12791e51764aSArtem Bityutskiy if (!znode) 12801e51764aSArtem Bityutskiy break; 12811e51764aSArtem Bityutskiy 12821e51764aSArtem Bityutskiy /* 12831e51764aSArtem Bityutskiy * If the last key of this znode is equivalent to the first key 12841e51764aSArtem Bityutskiy * of the next znode (collision), then check order of the keys. 12851e51764aSArtem Bityutskiy */ 12861e51764aSArtem Bityutskiy last = prev->child_cnt - 1; 12871e51764aSArtem Bityutskiy if (prev->level == 0 && znode->level == 0 && !c->replaying && 12881e51764aSArtem Bityutskiy !keys_cmp(c, &prev->zbranch[last].key, 12891e51764aSArtem Bityutskiy &znode->zbranch[0].key)) { 12901e51764aSArtem Bityutskiy err = dbg_check_key_order(c, &prev->zbranch[last], 12911e51764aSArtem Bityutskiy &znode->zbranch[0]); 12921e51764aSArtem Bityutskiy if (err < 0) 12931e51764aSArtem Bityutskiy return err; 12941e51764aSArtem Bityutskiy if (err) { 12951e51764aSArtem Bityutskiy ubifs_msg("first znode"); 12961e51764aSArtem Bityutskiy dbg_dump_znode(c, prev); 12971e51764aSArtem Bityutskiy ubifs_msg("second znode"); 12981e51764aSArtem Bityutskiy dbg_dump_znode(c, znode); 12991e51764aSArtem Bityutskiy return -EINVAL; 13001e51764aSArtem Bityutskiy } 13011e51764aSArtem Bityutskiy } 13021e51764aSArtem Bityutskiy } 13031e51764aSArtem Bityutskiy 13041e51764aSArtem Bityutskiy if (extra) { 13051e51764aSArtem Bityutskiy if (clean_cnt != atomic_long_read(&c->clean_zn_cnt)) { 13061e51764aSArtem Bityutskiy ubifs_err("incorrect clean_zn_cnt %ld, calculated %ld", 13071e51764aSArtem Bityutskiy atomic_long_read(&c->clean_zn_cnt), 13081e51764aSArtem Bityutskiy clean_cnt); 13091e51764aSArtem Bityutskiy return -EINVAL; 13101e51764aSArtem Bityutskiy } 13111e51764aSArtem Bityutskiy if (dirty_cnt != atomic_long_read(&c->dirty_zn_cnt)) { 13121e51764aSArtem Bityutskiy ubifs_err("incorrect dirty_zn_cnt %ld, calculated %ld", 13131e51764aSArtem Bityutskiy atomic_long_read(&c->dirty_zn_cnt), 13141e51764aSArtem Bityutskiy dirty_cnt); 13151e51764aSArtem Bityutskiy return -EINVAL; 13161e51764aSArtem Bityutskiy } 13171e51764aSArtem Bityutskiy } 13181e51764aSArtem Bityutskiy 13191e51764aSArtem Bityutskiy return 0; 13201e51764aSArtem Bityutskiy } 13211e51764aSArtem Bityutskiy 13221e51764aSArtem Bityutskiy /** 13231e51764aSArtem Bityutskiy * dbg_walk_index - walk the on-flash index. 13241e51764aSArtem Bityutskiy * @c: UBIFS file-system description object 13251e51764aSArtem Bityutskiy * @leaf_cb: called for each leaf node 13261e51764aSArtem Bityutskiy * @znode_cb: called for each indexing node 13271e51764aSArtem Bityutskiy * @priv: private date which is passed to callbacks 13281e51764aSArtem Bityutskiy * 13291e51764aSArtem Bityutskiy * This function walks the UBIFS index and calls the @leaf_cb for each leaf 13301e51764aSArtem Bityutskiy * node and @znode_cb for each indexing node. Returns zero in case of success 13311e51764aSArtem Bityutskiy * and a negative error code in case of failure. 13321e51764aSArtem Bityutskiy * 13331e51764aSArtem Bityutskiy * It would be better if this function removed every znode it pulled to into 13341e51764aSArtem Bityutskiy * the TNC, so that the behavior more closely matched the non-debugging 13351e51764aSArtem Bityutskiy * behavior. 13361e51764aSArtem Bityutskiy */ 13371e51764aSArtem Bityutskiy int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb, 13381e51764aSArtem Bityutskiy dbg_znode_callback znode_cb, void *priv) 13391e51764aSArtem Bityutskiy { 13401e51764aSArtem Bityutskiy int err; 13411e51764aSArtem Bityutskiy struct ubifs_zbranch *zbr; 13421e51764aSArtem Bityutskiy struct ubifs_znode *znode, *child; 13431e51764aSArtem Bityutskiy 13441e51764aSArtem Bityutskiy mutex_lock(&c->tnc_mutex); 13451e51764aSArtem Bityutskiy /* If the root indexing node is not in TNC - pull it */ 13461e51764aSArtem Bityutskiy if (!c->zroot.znode) { 13471e51764aSArtem Bityutskiy c->zroot.znode = ubifs_load_znode(c, &c->zroot, NULL, 0); 13481e51764aSArtem Bityutskiy if (IS_ERR(c->zroot.znode)) { 13491e51764aSArtem Bityutskiy err = PTR_ERR(c->zroot.znode); 13501e51764aSArtem Bityutskiy c->zroot.znode = NULL; 13511e51764aSArtem Bityutskiy goto out_unlock; 13521e51764aSArtem Bityutskiy } 13531e51764aSArtem Bityutskiy } 13541e51764aSArtem Bityutskiy 13551e51764aSArtem Bityutskiy /* 13561e51764aSArtem Bityutskiy * We are going to traverse the indexing tree in the postorder manner. 13571e51764aSArtem Bityutskiy * Go down and find the leftmost indexing node where we are going to 13581e51764aSArtem Bityutskiy * start from. 13591e51764aSArtem Bityutskiy */ 13601e51764aSArtem Bityutskiy znode = c->zroot.znode; 13611e51764aSArtem Bityutskiy while (znode->level > 0) { 13621e51764aSArtem Bityutskiy zbr = &znode->zbranch[0]; 13631e51764aSArtem Bityutskiy child = zbr->znode; 13641e51764aSArtem Bityutskiy if (!child) { 13651e51764aSArtem Bityutskiy child = ubifs_load_znode(c, zbr, znode, 0); 13661e51764aSArtem Bityutskiy if (IS_ERR(child)) { 13671e51764aSArtem Bityutskiy err = PTR_ERR(child); 13681e51764aSArtem Bityutskiy goto out_unlock; 13691e51764aSArtem Bityutskiy } 13701e51764aSArtem Bityutskiy zbr->znode = child; 13711e51764aSArtem Bityutskiy } 13721e51764aSArtem Bityutskiy 13731e51764aSArtem Bityutskiy znode = child; 13741e51764aSArtem Bityutskiy } 13751e51764aSArtem Bityutskiy 13761e51764aSArtem Bityutskiy /* Iterate over all indexing nodes */ 13771e51764aSArtem Bityutskiy while (1) { 13781e51764aSArtem Bityutskiy int idx; 13791e51764aSArtem Bityutskiy 13801e51764aSArtem Bityutskiy cond_resched(); 13811e51764aSArtem Bityutskiy 13821e51764aSArtem Bityutskiy if (znode_cb) { 13831e51764aSArtem Bityutskiy err = znode_cb(c, znode, priv); 13841e51764aSArtem Bityutskiy if (err) { 13851e51764aSArtem Bityutskiy ubifs_err("znode checking function returned " 13861e51764aSArtem Bityutskiy "error %d", err); 13871e51764aSArtem Bityutskiy dbg_dump_znode(c, znode); 13881e51764aSArtem Bityutskiy goto out_dump; 13891e51764aSArtem Bityutskiy } 13901e51764aSArtem Bityutskiy } 13911e51764aSArtem Bityutskiy if (leaf_cb && znode->level == 0) { 13921e51764aSArtem Bityutskiy for (idx = 0; idx < znode->child_cnt; idx++) { 13931e51764aSArtem Bityutskiy zbr = &znode->zbranch[idx]; 13941e51764aSArtem Bityutskiy err = leaf_cb(c, zbr, priv); 13951e51764aSArtem Bityutskiy if (err) { 13961e51764aSArtem Bityutskiy ubifs_err("leaf checking function " 13971e51764aSArtem Bityutskiy "returned error %d, for leaf " 13981e51764aSArtem Bityutskiy "at LEB %d:%d", 13991e51764aSArtem Bityutskiy err, zbr->lnum, zbr->offs); 14001e51764aSArtem Bityutskiy goto out_dump; 14011e51764aSArtem Bityutskiy } 14021e51764aSArtem Bityutskiy } 14031e51764aSArtem Bityutskiy } 14041e51764aSArtem Bityutskiy 14051e51764aSArtem Bityutskiy if (!znode->parent) 14061e51764aSArtem Bityutskiy break; 14071e51764aSArtem Bityutskiy 14081e51764aSArtem Bityutskiy idx = znode->iip + 1; 14091e51764aSArtem Bityutskiy znode = znode->parent; 14101e51764aSArtem Bityutskiy if (idx < znode->child_cnt) { 14111e51764aSArtem Bityutskiy /* Switch to the next index in the parent */ 14121e51764aSArtem Bityutskiy zbr = &znode->zbranch[idx]; 14131e51764aSArtem Bityutskiy child = zbr->znode; 14141e51764aSArtem Bityutskiy if (!child) { 14151e51764aSArtem Bityutskiy child = ubifs_load_znode(c, zbr, znode, idx); 14161e51764aSArtem Bityutskiy if (IS_ERR(child)) { 14171e51764aSArtem Bityutskiy err = PTR_ERR(child); 14181e51764aSArtem Bityutskiy goto out_unlock; 14191e51764aSArtem Bityutskiy } 14201e51764aSArtem Bityutskiy zbr->znode = child; 14211e51764aSArtem Bityutskiy } 14221e51764aSArtem Bityutskiy znode = child; 14231e51764aSArtem Bityutskiy } else 14241e51764aSArtem Bityutskiy /* 14251e51764aSArtem Bityutskiy * This is the last child, switch to the parent and 14261e51764aSArtem Bityutskiy * continue. 14271e51764aSArtem Bityutskiy */ 14281e51764aSArtem Bityutskiy continue; 14291e51764aSArtem Bityutskiy 14301e51764aSArtem Bityutskiy /* Go to the lowest leftmost znode in the new sub-tree */ 14311e51764aSArtem Bityutskiy while (znode->level > 0) { 14321e51764aSArtem Bityutskiy zbr = &znode->zbranch[0]; 14331e51764aSArtem Bityutskiy child = zbr->znode; 14341e51764aSArtem Bityutskiy if (!child) { 14351e51764aSArtem Bityutskiy child = ubifs_load_znode(c, zbr, znode, 0); 14361e51764aSArtem Bityutskiy if (IS_ERR(child)) { 14371e51764aSArtem Bityutskiy err = PTR_ERR(child); 14381e51764aSArtem Bityutskiy goto out_unlock; 14391e51764aSArtem Bityutskiy } 14401e51764aSArtem Bityutskiy zbr->znode = child; 14411e51764aSArtem Bityutskiy } 14421e51764aSArtem Bityutskiy znode = child; 14431e51764aSArtem Bityutskiy } 14441e51764aSArtem Bityutskiy } 14451e51764aSArtem Bityutskiy 14461e51764aSArtem Bityutskiy mutex_unlock(&c->tnc_mutex); 14471e51764aSArtem Bityutskiy return 0; 14481e51764aSArtem Bityutskiy 14491e51764aSArtem Bityutskiy out_dump: 14501e51764aSArtem Bityutskiy if (znode->parent) 14511e51764aSArtem Bityutskiy zbr = &znode->parent->zbranch[znode->iip]; 14521e51764aSArtem Bityutskiy else 14531e51764aSArtem Bityutskiy zbr = &c->zroot; 14541e51764aSArtem Bityutskiy ubifs_msg("dump of znode at LEB %d:%d", zbr->lnum, zbr->offs); 14551e51764aSArtem Bityutskiy dbg_dump_znode(c, znode); 14561e51764aSArtem Bityutskiy out_unlock: 14571e51764aSArtem Bityutskiy mutex_unlock(&c->tnc_mutex); 14581e51764aSArtem Bityutskiy return err; 14591e51764aSArtem Bityutskiy } 14601e51764aSArtem Bityutskiy 14611e51764aSArtem Bityutskiy /** 14621e51764aSArtem Bityutskiy * add_size - add znode size to partially calculated index size. 14631e51764aSArtem Bityutskiy * @c: UBIFS file-system description object 14641e51764aSArtem Bityutskiy * @znode: znode to add size for 14651e51764aSArtem Bityutskiy * @priv: partially calculated index size 14661e51764aSArtem Bityutskiy * 14671e51764aSArtem Bityutskiy * This is a helper function for 'dbg_check_idx_size()' which is called for 14681e51764aSArtem Bityutskiy * every indexing node and adds its size to the 'long long' variable pointed to 14691e51764aSArtem Bityutskiy * by @priv. 14701e51764aSArtem Bityutskiy */ 14711e51764aSArtem Bityutskiy static int add_size(struct ubifs_info *c, struct ubifs_znode *znode, void *priv) 14721e51764aSArtem Bityutskiy { 14731e51764aSArtem Bityutskiy long long *idx_size = priv; 14741e51764aSArtem Bityutskiy int add; 14751e51764aSArtem Bityutskiy 14761e51764aSArtem Bityutskiy add = ubifs_idx_node_sz(c, znode->child_cnt); 14771e51764aSArtem Bityutskiy add = ALIGN(add, 8); 14781e51764aSArtem Bityutskiy *idx_size += add; 14791e51764aSArtem Bityutskiy return 0; 14801e51764aSArtem Bityutskiy } 14811e51764aSArtem Bityutskiy 14821e51764aSArtem Bityutskiy /** 14831e51764aSArtem Bityutskiy * dbg_check_idx_size - check index size. 14841e51764aSArtem Bityutskiy * @c: UBIFS file-system description object 14851e51764aSArtem Bityutskiy * @idx_size: size to check 14861e51764aSArtem Bityutskiy * 14871e51764aSArtem Bityutskiy * This function walks the UBIFS index, calculates its size and checks that the 14881e51764aSArtem Bityutskiy * size is equivalent to @idx_size. Returns zero in case of success and a 14891e51764aSArtem Bityutskiy * negative error code in case of failure. 14901e51764aSArtem Bityutskiy */ 14911e51764aSArtem Bityutskiy int dbg_check_idx_size(struct ubifs_info *c, long long idx_size) 14921e51764aSArtem Bityutskiy { 14931e51764aSArtem Bityutskiy int err; 14941e51764aSArtem Bityutskiy long long calc = 0; 14951e51764aSArtem Bityutskiy 14961e51764aSArtem Bityutskiy if (!(ubifs_chk_flags & UBIFS_CHK_IDX_SZ)) 14971e51764aSArtem Bityutskiy return 0; 14981e51764aSArtem Bityutskiy 14991e51764aSArtem Bityutskiy err = dbg_walk_index(c, NULL, add_size, &calc); 15001e51764aSArtem Bityutskiy if (err) { 15011e51764aSArtem Bityutskiy ubifs_err("error %d while walking the index", err); 15021e51764aSArtem Bityutskiy return err; 15031e51764aSArtem Bityutskiy } 15041e51764aSArtem Bityutskiy 15051e51764aSArtem Bityutskiy if (calc != idx_size) { 15061e51764aSArtem Bityutskiy ubifs_err("index size check failed: calculated size is %lld, " 15071e51764aSArtem Bityutskiy "should be %lld", calc, idx_size); 15081e51764aSArtem Bityutskiy dump_stack(); 15091e51764aSArtem Bityutskiy return -EINVAL; 15101e51764aSArtem Bityutskiy } 15111e51764aSArtem Bityutskiy 15121e51764aSArtem Bityutskiy return 0; 15131e51764aSArtem Bityutskiy } 15141e51764aSArtem Bityutskiy 15151e51764aSArtem Bityutskiy /** 15161e51764aSArtem Bityutskiy * struct fsck_inode - information about an inode used when checking the file-system. 15171e51764aSArtem Bityutskiy * @rb: link in the RB-tree of inodes 15181e51764aSArtem Bityutskiy * @inum: inode number 15191e51764aSArtem Bityutskiy * @mode: inode type, permissions, etc 15201e51764aSArtem Bityutskiy * @nlink: inode link count 15211e51764aSArtem Bityutskiy * @xattr_cnt: count of extended attributes 15221e51764aSArtem Bityutskiy * @references: how many directory/xattr entries refer this inode (calculated 15231e51764aSArtem Bityutskiy * while walking the index) 15241e51764aSArtem Bityutskiy * @calc_cnt: for directory inode count of child directories 15251e51764aSArtem Bityutskiy * @size: inode size (read from on-flash inode) 15261e51764aSArtem Bityutskiy * @xattr_sz: summary size of all extended attributes (read from on-flash 15271e51764aSArtem Bityutskiy * inode) 15281e51764aSArtem Bityutskiy * @calc_sz: for directories calculated directory size 15291e51764aSArtem Bityutskiy * @calc_xcnt: count of extended attributes 15301e51764aSArtem Bityutskiy * @calc_xsz: calculated summary size of all extended attributes 15311e51764aSArtem Bityutskiy * @xattr_nms: sum of lengths of all extended attribute names belonging to this 15321e51764aSArtem Bityutskiy * inode (read from on-flash inode) 15331e51764aSArtem Bityutskiy * @calc_xnms: calculated sum of lengths of all extended attribute names 15341e51764aSArtem Bityutskiy */ 15351e51764aSArtem Bityutskiy struct fsck_inode { 15361e51764aSArtem Bityutskiy struct rb_node rb; 15371e51764aSArtem Bityutskiy ino_t inum; 15381e51764aSArtem Bityutskiy umode_t mode; 15391e51764aSArtem Bityutskiy unsigned int nlink; 15401e51764aSArtem Bityutskiy unsigned int xattr_cnt; 15411e51764aSArtem Bityutskiy int references; 15421e51764aSArtem Bityutskiy int calc_cnt; 15431e51764aSArtem Bityutskiy long long size; 15441e51764aSArtem Bityutskiy unsigned int xattr_sz; 15451e51764aSArtem Bityutskiy long long calc_sz; 15461e51764aSArtem Bityutskiy long long calc_xcnt; 15471e51764aSArtem Bityutskiy long long calc_xsz; 15481e51764aSArtem Bityutskiy unsigned int xattr_nms; 15491e51764aSArtem Bityutskiy long long calc_xnms; 15501e51764aSArtem Bityutskiy }; 15511e51764aSArtem Bityutskiy 15521e51764aSArtem Bityutskiy /** 15531e51764aSArtem Bityutskiy * struct fsck_data - private FS checking information. 15541e51764aSArtem Bityutskiy * @inodes: RB-tree of all inodes (contains @struct fsck_inode objects) 15551e51764aSArtem Bityutskiy */ 15561e51764aSArtem Bityutskiy struct fsck_data { 15571e51764aSArtem Bityutskiy struct rb_root inodes; 15581e51764aSArtem Bityutskiy }; 15591e51764aSArtem Bityutskiy 15601e51764aSArtem Bityutskiy /** 15611e51764aSArtem Bityutskiy * add_inode - add inode information to RB-tree of inodes. 15621e51764aSArtem Bityutskiy * @c: UBIFS file-system description object 15631e51764aSArtem Bityutskiy * @fsckd: FS checking information 15641e51764aSArtem Bityutskiy * @ino: raw UBIFS inode to add 15651e51764aSArtem Bityutskiy * 15661e51764aSArtem Bityutskiy * This is a helper function for 'check_leaf()' which adds information about 15671e51764aSArtem Bityutskiy * inode @ino to the RB-tree of inodes. Returns inode information pointer in 15681e51764aSArtem Bityutskiy * case of success and a negative error code in case of failure. 15691e51764aSArtem Bityutskiy */ 15701e51764aSArtem Bityutskiy static struct fsck_inode *add_inode(struct ubifs_info *c, 15711e51764aSArtem Bityutskiy struct fsck_data *fsckd, 15721e51764aSArtem Bityutskiy struct ubifs_ino_node *ino) 15731e51764aSArtem Bityutskiy { 15741e51764aSArtem Bityutskiy struct rb_node **p, *parent = NULL; 15751e51764aSArtem Bityutskiy struct fsck_inode *fscki; 15761e51764aSArtem Bityutskiy ino_t inum = key_inum_flash(c, &ino->key); 15771e51764aSArtem Bityutskiy 15781e51764aSArtem Bityutskiy p = &fsckd->inodes.rb_node; 15791e51764aSArtem Bityutskiy while (*p) { 15801e51764aSArtem Bityutskiy parent = *p; 15811e51764aSArtem Bityutskiy fscki = rb_entry(parent, struct fsck_inode, rb); 15821e51764aSArtem Bityutskiy if (inum < fscki->inum) 15831e51764aSArtem Bityutskiy p = &(*p)->rb_left; 15841e51764aSArtem Bityutskiy else if (inum > fscki->inum) 15851e51764aSArtem Bityutskiy p = &(*p)->rb_right; 15861e51764aSArtem Bityutskiy else 15871e51764aSArtem Bityutskiy return fscki; 15881e51764aSArtem Bityutskiy } 15891e51764aSArtem Bityutskiy 15901e51764aSArtem Bityutskiy if (inum > c->highest_inum) { 15911e51764aSArtem Bityutskiy ubifs_err("too high inode number, max. is %lu", 15921e51764aSArtem Bityutskiy c->highest_inum); 15931e51764aSArtem Bityutskiy return ERR_PTR(-EINVAL); 15941e51764aSArtem Bityutskiy } 15951e51764aSArtem Bityutskiy 15961e51764aSArtem Bityutskiy fscki = kzalloc(sizeof(struct fsck_inode), GFP_NOFS); 15971e51764aSArtem Bityutskiy if (!fscki) 15981e51764aSArtem Bityutskiy return ERR_PTR(-ENOMEM); 15991e51764aSArtem Bityutskiy 16001e51764aSArtem Bityutskiy fscki->inum = inum; 16011e51764aSArtem Bityutskiy fscki->nlink = le32_to_cpu(ino->nlink); 16021e51764aSArtem Bityutskiy fscki->size = le64_to_cpu(ino->size); 16031e51764aSArtem Bityutskiy fscki->xattr_cnt = le32_to_cpu(ino->xattr_cnt); 16041e51764aSArtem Bityutskiy fscki->xattr_sz = le32_to_cpu(ino->xattr_size); 16051e51764aSArtem Bityutskiy fscki->xattr_nms = le32_to_cpu(ino->xattr_names); 16061e51764aSArtem Bityutskiy fscki->mode = le32_to_cpu(ino->mode); 16071e51764aSArtem Bityutskiy if (S_ISDIR(fscki->mode)) { 16081e51764aSArtem Bityutskiy fscki->calc_sz = UBIFS_INO_NODE_SZ; 16091e51764aSArtem Bityutskiy fscki->calc_cnt = 2; 16101e51764aSArtem Bityutskiy } 16111e51764aSArtem Bityutskiy rb_link_node(&fscki->rb, parent, p); 16121e51764aSArtem Bityutskiy rb_insert_color(&fscki->rb, &fsckd->inodes); 16131e51764aSArtem Bityutskiy return fscki; 16141e51764aSArtem Bityutskiy } 16151e51764aSArtem Bityutskiy 16161e51764aSArtem Bityutskiy /** 16171e51764aSArtem Bityutskiy * search_inode - search inode in the RB-tree of inodes. 16181e51764aSArtem Bityutskiy * @fsckd: FS checking information 16191e51764aSArtem Bityutskiy * @inum: inode number to search 16201e51764aSArtem Bityutskiy * 16211e51764aSArtem Bityutskiy * This is a helper function for 'check_leaf()' which searches inode @inum in 16221e51764aSArtem Bityutskiy * the RB-tree of inodes and returns an inode information pointer or %NULL if 16231e51764aSArtem Bityutskiy * the inode was not found. 16241e51764aSArtem Bityutskiy */ 16251e51764aSArtem Bityutskiy static struct fsck_inode *search_inode(struct fsck_data *fsckd, ino_t inum) 16261e51764aSArtem Bityutskiy { 16271e51764aSArtem Bityutskiy struct rb_node *p; 16281e51764aSArtem Bityutskiy struct fsck_inode *fscki; 16291e51764aSArtem Bityutskiy 16301e51764aSArtem Bityutskiy p = fsckd->inodes.rb_node; 16311e51764aSArtem Bityutskiy while (p) { 16321e51764aSArtem Bityutskiy fscki = rb_entry(p, struct fsck_inode, rb); 16331e51764aSArtem Bityutskiy if (inum < fscki->inum) 16341e51764aSArtem Bityutskiy p = p->rb_left; 16351e51764aSArtem Bityutskiy else if (inum > fscki->inum) 16361e51764aSArtem Bityutskiy p = p->rb_right; 16371e51764aSArtem Bityutskiy else 16381e51764aSArtem Bityutskiy return fscki; 16391e51764aSArtem Bityutskiy } 16401e51764aSArtem Bityutskiy return NULL; 16411e51764aSArtem Bityutskiy } 16421e51764aSArtem Bityutskiy 16431e51764aSArtem Bityutskiy /** 16441e51764aSArtem Bityutskiy * read_add_inode - read inode node and add it to RB-tree of inodes. 16451e51764aSArtem Bityutskiy * @c: UBIFS file-system description object 16461e51764aSArtem Bityutskiy * @fsckd: FS checking information 16471e51764aSArtem Bityutskiy * @inum: inode number to read 16481e51764aSArtem Bityutskiy * 16491e51764aSArtem Bityutskiy * This is a helper function for 'check_leaf()' which finds inode node @inum in 16501e51764aSArtem Bityutskiy * the index, reads it, and adds it to the RB-tree of inodes. Returns inode 16511e51764aSArtem Bityutskiy * information pointer in case of success and a negative error code in case of 16521e51764aSArtem Bityutskiy * failure. 16531e51764aSArtem Bityutskiy */ 16541e51764aSArtem Bityutskiy static struct fsck_inode *read_add_inode(struct ubifs_info *c, 16551e51764aSArtem Bityutskiy struct fsck_data *fsckd, ino_t inum) 16561e51764aSArtem Bityutskiy { 16571e51764aSArtem Bityutskiy int n, err; 16581e51764aSArtem Bityutskiy union ubifs_key key; 16591e51764aSArtem Bityutskiy struct ubifs_znode *znode; 16601e51764aSArtem Bityutskiy struct ubifs_zbranch *zbr; 16611e51764aSArtem Bityutskiy struct ubifs_ino_node *ino; 16621e51764aSArtem Bityutskiy struct fsck_inode *fscki; 16631e51764aSArtem Bityutskiy 16641e51764aSArtem Bityutskiy fscki = search_inode(fsckd, inum); 16651e51764aSArtem Bityutskiy if (fscki) 16661e51764aSArtem Bityutskiy return fscki; 16671e51764aSArtem Bityutskiy 16681e51764aSArtem Bityutskiy ino_key_init(c, &key, inum); 16691e51764aSArtem Bityutskiy err = ubifs_lookup_level0(c, &key, &znode, &n); 16701e51764aSArtem Bityutskiy if (!err) { 16711e51764aSArtem Bityutskiy ubifs_err("inode %lu not found in index", inum); 16721e51764aSArtem Bityutskiy return ERR_PTR(-ENOENT); 16731e51764aSArtem Bityutskiy } else if (err < 0) { 16741e51764aSArtem Bityutskiy ubifs_err("error %d while looking up inode %lu", err, inum); 16751e51764aSArtem Bityutskiy return ERR_PTR(err); 16761e51764aSArtem Bityutskiy } 16771e51764aSArtem Bityutskiy 16781e51764aSArtem Bityutskiy zbr = &znode->zbranch[n]; 16791e51764aSArtem Bityutskiy if (zbr->len < UBIFS_INO_NODE_SZ) { 16801e51764aSArtem Bityutskiy ubifs_err("bad node %lu node length %d", inum, zbr->len); 16811e51764aSArtem Bityutskiy return ERR_PTR(-EINVAL); 16821e51764aSArtem Bityutskiy } 16831e51764aSArtem Bityutskiy 16841e51764aSArtem Bityutskiy ino = kmalloc(zbr->len, GFP_NOFS); 16851e51764aSArtem Bityutskiy if (!ino) 16861e51764aSArtem Bityutskiy return ERR_PTR(-ENOMEM); 16871e51764aSArtem Bityutskiy 16881e51764aSArtem Bityutskiy err = ubifs_tnc_read_node(c, zbr, ino); 16891e51764aSArtem Bityutskiy if (err) { 16901e51764aSArtem Bityutskiy ubifs_err("cannot read inode node at LEB %d:%d, error %d", 16911e51764aSArtem Bityutskiy zbr->lnum, zbr->offs, err); 16921e51764aSArtem Bityutskiy kfree(ino); 16931e51764aSArtem Bityutskiy return ERR_PTR(err); 16941e51764aSArtem Bityutskiy } 16951e51764aSArtem Bityutskiy 16961e51764aSArtem Bityutskiy fscki = add_inode(c, fsckd, ino); 16971e51764aSArtem Bityutskiy kfree(ino); 16981e51764aSArtem Bityutskiy if (IS_ERR(fscki)) { 16991e51764aSArtem Bityutskiy ubifs_err("error %ld while adding inode %lu node", 17001e51764aSArtem Bityutskiy PTR_ERR(fscki), inum); 17011e51764aSArtem Bityutskiy return fscki; 17021e51764aSArtem Bityutskiy } 17031e51764aSArtem Bityutskiy 17041e51764aSArtem Bityutskiy return fscki; 17051e51764aSArtem Bityutskiy } 17061e51764aSArtem Bityutskiy 17071e51764aSArtem Bityutskiy /** 17081e51764aSArtem Bityutskiy * check_leaf - check leaf node. 17091e51764aSArtem Bityutskiy * @c: UBIFS file-system description object 17101e51764aSArtem Bityutskiy * @zbr: zbranch of the leaf node to check 17111e51764aSArtem Bityutskiy * @priv: FS checking information 17121e51764aSArtem Bityutskiy * 17131e51764aSArtem Bityutskiy * This is a helper function for 'dbg_check_filesystem()' which is called for 17141e51764aSArtem Bityutskiy * every single leaf node while walking the indexing tree. It checks that the 17151e51764aSArtem Bityutskiy * leaf node referred from the indexing tree exists, has correct CRC, and does 17161e51764aSArtem Bityutskiy * some other basic validation. This function is also responsible for building 17171e51764aSArtem Bityutskiy * an RB-tree of inodes - it adds all inodes into the RB-tree. It also 17181e51764aSArtem Bityutskiy * calculates reference count, size, etc for each inode in order to later 17191e51764aSArtem Bityutskiy * compare them to the information stored inside the inodes and detect possible 17201e51764aSArtem Bityutskiy * inconsistencies. Returns zero in case of success and a negative error code 17211e51764aSArtem Bityutskiy * in case of failure. 17221e51764aSArtem Bityutskiy */ 17231e51764aSArtem Bityutskiy static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr, 17241e51764aSArtem Bityutskiy void *priv) 17251e51764aSArtem Bityutskiy { 17261e51764aSArtem Bityutskiy ino_t inum; 17271e51764aSArtem Bityutskiy void *node; 17281e51764aSArtem Bityutskiy struct ubifs_ch *ch; 17291e51764aSArtem Bityutskiy int err, type = key_type(c, &zbr->key); 17301e51764aSArtem Bityutskiy struct fsck_inode *fscki; 17311e51764aSArtem Bityutskiy 17321e51764aSArtem Bityutskiy if (zbr->len < UBIFS_CH_SZ) { 17331e51764aSArtem Bityutskiy ubifs_err("bad leaf length %d (LEB %d:%d)", 17341e51764aSArtem Bityutskiy zbr->len, zbr->lnum, zbr->offs); 17351e51764aSArtem Bityutskiy return -EINVAL; 17361e51764aSArtem Bityutskiy } 17371e51764aSArtem Bityutskiy 17381e51764aSArtem Bityutskiy node = kmalloc(zbr->len, GFP_NOFS); 17391e51764aSArtem Bityutskiy if (!node) 17401e51764aSArtem Bityutskiy return -ENOMEM; 17411e51764aSArtem Bityutskiy 17421e51764aSArtem Bityutskiy err = ubifs_tnc_read_node(c, zbr, node); 17431e51764aSArtem Bityutskiy if (err) { 17441e51764aSArtem Bityutskiy ubifs_err("cannot read leaf node at LEB %d:%d, error %d", 17451e51764aSArtem Bityutskiy zbr->lnum, zbr->offs, err); 17461e51764aSArtem Bityutskiy goto out_free; 17471e51764aSArtem Bityutskiy } 17481e51764aSArtem Bityutskiy 17491e51764aSArtem Bityutskiy /* If this is an inode node, add it to RB-tree of inodes */ 17501e51764aSArtem Bityutskiy if (type == UBIFS_INO_KEY) { 17511e51764aSArtem Bityutskiy fscki = add_inode(c, priv, node); 17521e51764aSArtem Bityutskiy if (IS_ERR(fscki)) { 17531e51764aSArtem Bityutskiy err = PTR_ERR(fscki); 17541e51764aSArtem Bityutskiy ubifs_err("error %d while adding inode node", err); 17551e51764aSArtem Bityutskiy goto out_dump; 17561e51764aSArtem Bityutskiy } 17571e51764aSArtem Bityutskiy goto out; 17581e51764aSArtem Bityutskiy } 17591e51764aSArtem Bityutskiy 17601e51764aSArtem Bityutskiy if (type != UBIFS_DENT_KEY && type != UBIFS_XENT_KEY && 17611e51764aSArtem Bityutskiy type != UBIFS_DATA_KEY) { 17621e51764aSArtem Bityutskiy ubifs_err("unexpected node type %d at LEB %d:%d", 17631e51764aSArtem Bityutskiy type, zbr->lnum, zbr->offs); 17641e51764aSArtem Bityutskiy err = -EINVAL; 17651e51764aSArtem Bityutskiy goto out_free; 17661e51764aSArtem Bityutskiy } 17671e51764aSArtem Bityutskiy 17681e51764aSArtem Bityutskiy ch = node; 17691e51764aSArtem Bityutskiy if (le64_to_cpu(ch->sqnum) > c->max_sqnum) { 17701e51764aSArtem Bityutskiy ubifs_err("too high sequence number, max. is %llu", 17711e51764aSArtem Bityutskiy c->max_sqnum); 17721e51764aSArtem Bityutskiy err = -EINVAL; 17731e51764aSArtem Bityutskiy goto out_dump; 17741e51764aSArtem Bityutskiy } 17751e51764aSArtem Bityutskiy 17761e51764aSArtem Bityutskiy if (type == UBIFS_DATA_KEY) { 17771e51764aSArtem Bityutskiy long long blk_offs; 17781e51764aSArtem Bityutskiy struct ubifs_data_node *dn = node; 17791e51764aSArtem Bityutskiy 17801e51764aSArtem Bityutskiy /* 17811e51764aSArtem Bityutskiy * Search the inode node this data node belongs to and insert 17821e51764aSArtem Bityutskiy * it to the RB-tree of inodes. 17831e51764aSArtem Bityutskiy */ 17841e51764aSArtem Bityutskiy inum = key_inum_flash(c, &dn->key); 17851e51764aSArtem Bityutskiy fscki = read_add_inode(c, priv, inum); 17861e51764aSArtem Bityutskiy if (IS_ERR(fscki)) { 17871e51764aSArtem Bityutskiy err = PTR_ERR(fscki); 17881e51764aSArtem Bityutskiy ubifs_err("error %d while processing data node and " 17891e51764aSArtem Bityutskiy "trying to find inode node %lu", err, inum); 17901e51764aSArtem Bityutskiy goto out_dump; 17911e51764aSArtem Bityutskiy } 17921e51764aSArtem Bityutskiy 17931e51764aSArtem Bityutskiy /* Make sure the data node is within inode size */ 17941e51764aSArtem Bityutskiy blk_offs = key_block_flash(c, &dn->key); 17951e51764aSArtem Bityutskiy blk_offs <<= UBIFS_BLOCK_SHIFT; 17961e51764aSArtem Bityutskiy blk_offs += le32_to_cpu(dn->size); 17971e51764aSArtem Bityutskiy if (blk_offs > fscki->size) { 17981e51764aSArtem Bityutskiy ubifs_err("data node at LEB %d:%d is not within inode " 17991e51764aSArtem Bityutskiy "size %lld", zbr->lnum, zbr->offs, 18001e51764aSArtem Bityutskiy fscki->size); 18011e51764aSArtem Bityutskiy err = -EINVAL; 18021e51764aSArtem Bityutskiy goto out_dump; 18031e51764aSArtem Bityutskiy } 18041e51764aSArtem Bityutskiy } else { 18051e51764aSArtem Bityutskiy int nlen; 18061e51764aSArtem Bityutskiy struct ubifs_dent_node *dent = node; 18071e51764aSArtem Bityutskiy struct fsck_inode *fscki1; 18081e51764aSArtem Bityutskiy 18091e51764aSArtem Bityutskiy err = ubifs_validate_entry(c, dent); 18101e51764aSArtem Bityutskiy if (err) 18111e51764aSArtem Bityutskiy goto out_dump; 18121e51764aSArtem Bityutskiy 18131e51764aSArtem Bityutskiy /* 18141e51764aSArtem Bityutskiy * Search the inode node this entry refers to and the parent 18151e51764aSArtem Bityutskiy * inode node and insert them to the RB-tree of inodes. 18161e51764aSArtem Bityutskiy */ 18171e51764aSArtem Bityutskiy inum = le64_to_cpu(dent->inum); 18181e51764aSArtem Bityutskiy fscki = read_add_inode(c, priv, inum); 18191e51764aSArtem Bityutskiy if (IS_ERR(fscki)) { 18201e51764aSArtem Bityutskiy err = PTR_ERR(fscki); 18211e51764aSArtem Bityutskiy ubifs_err("error %d while processing entry node and " 18221e51764aSArtem Bityutskiy "trying to find inode node %lu", err, inum); 18231e51764aSArtem Bityutskiy goto out_dump; 18241e51764aSArtem Bityutskiy } 18251e51764aSArtem Bityutskiy 18261e51764aSArtem Bityutskiy /* Count how many direntries or xentries refers this inode */ 18271e51764aSArtem Bityutskiy fscki->references += 1; 18281e51764aSArtem Bityutskiy 18291e51764aSArtem Bityutskiy inum = key_inum_flash(c, &dent->key); 18301e51764aSArtem Bityutskiy fscki1 = read_add_inode(c, priv, inum); 18311e51764aSArtem Bityutskiy if (IS_ERR(fscki1)) { 18321e51764aSArtem Bityutskiy err = PTR_ERR(fscki); 18331e51764aSArtem Bityutskiy ubifs_err("error %d while processing entry node and " 18341e51764aSArtem Bityutskiy "trying to find parent inode node %lu", 18351e51764aSArtem Bityutskiy err, inum); 18361e51764aSArtem Bityutskiy goto out_dump; 18371e51764aSArtem Bityutskiy } 18381e51764aSArtem Bityutskiy 18391e51764aSArtem Bityutskiy nlen = le16_to_cpu(dent->nlen); 18401e51764aSArtem Bityutskiy if (type == UBIFS_XENT_KEY) { 18411e51764aSArtem Bityutskiy fscki1->calc_xcnt += 1; 18421e51764aSArtem Bityutskiy fscki1->calc_xsz += CALC_DENT_SIZE(nlen); 18431e51764aSArtem Bityutskiy fscki1->calc_xsz += CALC_XATTR_BYTES(fscki->size); 18441e51764aSArtem Bityutskiy fscki1->calc_xnms += nlen; 18451e51764aSArtem Bityutskiy } else { 18461e51764aSArtem Bityutskiy fscki1->calc_sz += CALC_DENT_SIZE(nlen); 18471e51764aSArtem Bityutskiy if (dent->type == UBIFS_ITYPE_DIR) 18481e51764aSArtem Bityutskiy fscki1->calc_cnt += 1; 18491e51764aSArtem Bityutskiy } 18501e51764aSArtem Bityutskiy } 18511e51764aSArtem Bityutskiy 18521e51764aSArtem Bityutskiy out: 18531e51764aSArtem Bityutskiy kfree(node); 18541e51764aSArtem Bityutskiy return 0; 18551e51764aSArtem Bityutskiy 18561e51764aSArtem Bityutskiy out_dump: 18571e51764aSArtem Bityutskiy ubifs_msg("dump of node at LEB %d:%d", zbr->lnum, zbr->offs); 18581e51764aSArtem Bityutskiy dbg_dump_node(c, node); 18591e51764aSArtem Bityutskiy out_free: 18601e51764aSArtem Bityutskiy kfree(node); 18611e51764aSArtem Bityutskiy return err; 18621e51764aSArtem Bityutskiy } 18631e51764aSArtem Bityutskiy 18641e51764aSArtem Bityutskiy /** 18651e51764aSArtem Bityutskiy * free_inodes - free RB-tree of inodes. 18661e51764aSArtem Bityutskiy * @fsckd: FS checking information 18671e51764aSArtem Bityutskiy */ 18681e51764aSArtem Bityutskiy static void free_inodes(struct fsck_data *fsckd) 18691e51764aSArtem Bityutskiy { 18701e51764aSArtem Bityutskiy struct rb_node *this = fsckd->inodes.rb_node; 18711e51764aSArtem Bityutskiy struct fsck_inode *fscki; 18721e51764aSArtem Bityutskiy 18731e51764aSArtem Bityutskiy while (this) { 18741e51764aSArtem Bityutskiy if (this->rb_left) 18751e51764aSArtem Bityutskiy this = this->rb_left; 18761e51764aSArtem Bityutskiy else if (this->rb_right) 18771e51764aSArtem Bityutskiy this = this->rb_right; 18781e51764aSArtem Bityutskiy else { 18791e51764aSArtem Bityutskiy fscki = rb_entry(this, struct fsck_inode, rb); 18801e51764aSArtem Bityutskiy this = rb_parent(this); 18811e51764aSArtem Bityutskiy if (this) { 18821e51764aSArtem Bityutskiy if (this->rb_left == &fscki->rb) 18831e51764aSArtem Bityutskiy this->rb_left = NULL; 18841e51764aSArtem Bityutskiy else 18851e51764aSArtem Bityutskiy this->rb_right = NULL; 18861e51764aSArtem Bityutskiy } 18871e51764aSArtem Bityutskiy kfree(fscki); 18881e51764aSArtem Bityutskiy } 18891e51764aSArtem Bityutskiy } 18901e51764aSArtem Bityutskiy } 18911e51764aSArtem Bityutskiy 18921e51764aSArtem Bityutskiy /** 18931e51764aSArtem Bityutskiy * check_inodes - checks all inodes. 18941e51764aSArtem Bityutskiy * @c: UBIFS file-system description object 18951e51764aSArtem Bityutskiy * @fsckd: FS checking information 18961e51764aSArtem Bityutskiy * 18971e51764aSArtem Bityutskiy * This is a helper function for 'dbg_check_filesystem()' which walks the 18981e51764aSArtem Bityutskiy * RB-tree of inodes after the index scan has been finished, and checks that 18991e51764aSArtem Bityutskiy * inode nlink, size, etc are correct. Returns zero if inodes are fine, 19001e51764aSArtem Bityutskiy * %-EINVAL if not, and a negative error code in case of failure. 19011e51764aSArtem Bityutskiy */ 19021e51764aSArtem Bityutskiy static int check_inodes(struct ubifs_info *c, struct fsck_data *fsckd) 19031e51764aSArtem Bityutskiy { 19041e51764aSArtem Bityutskiy int n, err; 19051e51764aSArtem Bityutskiy union ubifs_key key; 19061e51764aSArtem Bityutskiy struct ubifs_znode *znode; 19071e51764aSArtem Bityutskiy struct ubifs_zbranch *zbr; 19081e51764aSArtem Bityutskiy struct ubifs_ino_node *ino; 19091e51764aSArtem Bityutskiy struct fsck_inode *fscki; 19101e51764aSArtem Bityutskiy struct rb_node *this = rb_first(&fsckd->inodes); 19111e51764aSArtem Bityutskiy 19121e51764aSArtem Bityutskiy while (this) { 19131e51764aSArtem Bityutskiy fscki = rb_entry(this, struct fsck_inode, rb); 19141e51764aSArtem Bityutskiy this = rb_next(this); 19151e51764aSArtem Bityutskiy 19161e51764aSArtem Bityutskiy if (S_ISDIR(fscki->mode)) { 19171e51764aSArtem Bityutskiy /* 19181e51764aSArtem Bityutskiy * Directories have to have exactly one reference (they 19191e51764aSArtem Bityutskiy * cannot have hardlinks), although root inode is an 19201e51764aSArtem Bityutskiy * exception. 19211e51764aSArtem Bityutskiy */ 19221e51764aSArtem Bityutskiy if (fscki->inum != UBIFS_ROOT_INO && 19231e51764aSArtem Bityutskiy fscki->references != 1) { 19241e51764aSArtem Bityutskiy ubifs_err("directory inode %lu has %d " 19251e51764aSArtem Bityutskiy "direntries which refer it, but " 19261e51764aSArtem Bityutskiy "should be 1", fscki->inum, 19271e51764aSArtem Bityutskiy fscki->references); 19281e51764aSArtem Bityutskiy goto out_dump; 19291e51764aSArtem Bityutskiy } 19301e51764aSArtem Bityutskiy if (fscki->inum == UBIFS_ROOT_INO && 19311e51764aSArtem Bityutskiy fscki->references != 0) { 19321e51764aSArtem Bityutskiy ubifs_err("root inode %lu has non-zero (%d) " 19331e51764aSArtem Bityutskiy "direntries which refer it", 19341e51764aSArtem Bityutskiy fscki->inum, fscki->references); 19351e51764aSArtem Bityutskiy goto out_dump; 19361e51764aSArtem Bityutskiy } 19371e51764aSArtem Bityutskiy if (fscki->calc_sz != fscki->size) { 19381e51764aSArtem Bityutskiy ubifs_err("directory inode %lu size is %lld, " 19391e51764aSArtem Bityutskiy "but calculated size is %lld", 19401e51764aSArtem Bityutskiy fscki->inum, fscki->size, 19411e51764aSArtem Bityutskiy fscki->calc_sz); 19421e51764aSArtem Bityutskiy goto out_dump; 19431e51764aSArtem Bityutskiy } 19441e51764aSArtem Bityutskiy if (fscki->calc_cnt != fscki->nlink) { 19451e51764aSArtem Bityutskiy ubifs_err("directory inode %lu nlink is %d, " 19461e51764aSArtem Bityutskiy "but calculated nlink is %d", 19471e51764aSArtem Bityutskiy fscki->inum, fscki->nlink, 19481e51764aSArtem Bityutskiy fscki->calc_cnt); 19491e51764aSArtem Bityutskiy goto out_dump; 19501e51764aSArtem Bityutskiy } 19511e51764aSArtem Bityutskiy } else { 19521e51764aSArtem Bityutskiy if (fscki->references != fscki->nlink) { 19531e51764aSArtem Bityutskiy ubifs_err("inode %lu nlink is %d, but " 19541e51764aSArtem Bityutskiy "calculated nlink is %d", fscki->inum, 19551e51764aSArtem Bityutskiy fscki->nlink, fscki->references); 19561e51764aSArtem Bityutskiy goto out_dump; 19571e51764aSArtem Bityutskiy } 19581e51764aSArtem Bityutskiy } 19591e51764aSArtem Bityutskiy if (fscki->xattr_sz != fscki->calc_xsz) { 19601e51764aSArtem Bityutskiy ubifs_err("inode %lu has xattr size %u, but " 19611e51764aSArtem Bityutskiy "calculated size is %lld", 19621e51764aSArtem Bityutskiy fscki->inum, fscki->xattr_sz, 19631e51764aSArtem Bityutskiy fscki->calc_xsz); 19641e51764aSArtem Bityutskiy goto out_dump; 19651e51764aSArtem Bityutskiy } 19661e51764aSArtem Bityutskiy if (fscki->xattr_cnt != fscki->calc_xcnt) { 19671e51764aSArtem Bityutskiy ubifs_err("inode %lu has %u xattrs, but " 19681e51764aSArtem Bityutskiy "calculated count is %lld", fscki->inum, 19691e51764aSArtem Bityutskiy fscki->xattr_cnt, fscki->calc_xcnt); 19701e51764aSArtem Bityutskiy goto out_dump; 19711e51764aSArtem Bityutskiy } 19721e51764aSArtem Bityutskiy if (fscki->xattr_nms != fscki->calc_xnms) { 19731e51764aSArtem Bityutskiy ubifs_err("inode %lu has xattr names' size %u, but " 19741e51764aSArtem Bityutskiy "calculated names' size is %lld", 19751e51764aSArtem Bityutskiy fscki->inum, fscki->xattr_nms, 19761e51764aSArtem Bityutskiy fscki->calc_xnms); 19771e51764aSArtem Bityutskiy goto out_dump; 19781e51764aSArtem Bityutskiy } 19791e51764aSArtem Bityutskiy } 19801e51764aSArtem Bityutskiy 19811e51764aSArtem Bityutskiy return 0; 19821e51764aSArtem Bityutskiy 19831e51764aSArtem Bityutskiy out_dump: 19841e51764aSArtem Bityutskiy /* Read the bad inode and dump it */ 19851e51764aSArtem Bityutskiy ino_key_init(c, &key, fscki->inum); 19861e51764aSArtem Bityutskiy err = ubifs_lookup_level0(c, &key, &znode, &n); 19871e51764aSArtem Bityutskiy if (!err) { 19881e51764aSArtem Bityutskiy ubifs_err("inode %lu not found in index", fscki->inum); 19891e51764aSArtem Bityutskiy return -ENOENT; 19901e51764aSArtem Bityutskiy } else if (err < 0) { 19911e51764aSArtem Bityutskiy ubifs_err("error %d while looking up inode %lu", 19921e51764aSArtem Bityutskiy err, fscki->inum); 19931e51764aSArtem Bityutskiy return err; 19941e51764aSArtem Bityutskiy } 19951e51764aSArtem Bityutskiy 19961e51764aSArtem Bityutskiy zbr = &znode->zbranch[n]; 19971e51764aSArtem Bityutskiy ino = kmalloc(zbr->len, GFP_NOFS); 19981e51764aSArtem Bityutskiy if (!ino) 19991e51764aSArtem Bityutskiy return -ENOMEM; 20001e51764aSArtem Bityutskiy 20011e51764aSArtem Bityutskiy err = ubifs_tnc_read_node(c, zbr, ino); 20021e51764aSArtem Bityutskiy if (err) { 20031e51764aSArtem Bityutskiy ubifs_err("cannot read inode node at LEB %d:%d, error %d", 20041e51764aSArtem Bityutskiy zbr->lnum, zbr->offs, err); 20051e51764aSArtem Bityutskiy kfree(ino); 20061e51764aSArtem Bityutskiy return err; 20071e51764aSArtem Bityutskiy } 20081e51764aSArtem Bityutskiy 20091e51764aSArtem Bityutskiy ubifs_msg("dump of the inode %lu sitting in LEB %d:%d", 20101e51764aSArtem Bityutskiy fscki->inum, zbr->lnum, zbr->offs); 20111e51764aSArtem Bityutskiy dbg_dump_node(c, ino); 20121e51764aSArtem Bityutskiy kfree(ino); 20131e51764aSArtem Bityutskiy return -EINVAL; 20141e51764aSArtem Bityutskiy } 20151e51764aSArtem Bityutskiy 20161e51764aSArtem Bityutskiy /** 20171e51764aSArtem Bityutskiy * dbg_check_filesystem - check the file-system. 20181e51764aSArtem Bityutskiy * @c: UBIFS file-system description object 20191e51764aSArtem Bityutskiy * 20201e51764aSArtem Bityutskiy * This function checks the file system, namely: 20211e51764aSArtem Bityutskiy * o makes sure that all leaf nodes exist and their CRCs are correct; 20221e51764aSArtem Bityutskiy * o makes sure inode nlink, size, xattr size/count are correct (for all 20231e51764aSArtem Bityutskiy * inodes). 20241e51764aSArtem Bityutskiy * 20251e51764aSArtem Bityutskiy * The function reads whole indexing tree and all nodes, so it is pretty 20261e51764aSArtem Bityutskiy * heavy-weight. Returns zero if the file-system is consistent, %-EINVAL if 20271e51764aSArtem Bityutskiy * not, and a negative error code in case of failure. 20281e51764aSArtem Bityutskiy */ 20291e51764aSArtem Bityutskiy int dbg_check_filesystem(struct ubifs_info *c) 20301e51764aSArtem Bityutskiy { 20311e51764aSArtem Bityutskiy int err; 20321e51764aSArtem Bityutskiy struct fsck_data fsckd; 20331e51764aSArtem Bityutskiy 20341e51764aSArtem Bityutskiy if (!(ubifs_chk_flags & UBIFS_CHK_FS)) 20351e51764aSArtem Bityutskiy return 0; 20361e51764aSArtem Bityutskiy 20371e51764aSArtem Bityutskiy fsckd.inodes = RB_ROOT; 20381e51764aSArtem Bityutskiy err = dbg_walk_index(c, check_leaf, NULL, &fsckd); 20391e51764aSArtem Bityutskiy if (err) 20401e51764aSArtem Bityutskiy goto out_free; 20411e51764aSArtem Bityutskiy 20421e51764aSArtem Bityutskiy err = check_inodes(c, &fsckd); 20431e51764aSArtem Bityutskiy if (err) 20441e51764aSArtem Bityutskiy goto out_free; 20451e51764aSArtem Bityutskiy 20461e51764aSArtem Bityutskiy free_inodes(&fsckd); 20471e51764aSArtem Bityutskiy return 0; 20481e51764aSArtem Bityutskiy 20491e51764aSArtem Bityutskiy out_free: 20501e51764aSArtem Bityutskiy ubifs_err("file-system check failed with error %d", err); 20511e51764aSArtem Bityutskiy dump_stack(); 20521e51764aSArtem Bityutskiy free_inodes(&fsckd); 20531e51764aSArtem Bityutskiy return err; 20541e51764aSArtem Bityutskiy } 20551e51764aSArtem Bityutskiy 20561e51764aSArtem Bityutskiy static int invocation_cnt; 20571e51764aSArtem Bityutskiy 20581e51764aSArtem Bityutskiy int dbg_force_in_the_gaps(void) 20591e51764aSArtem Bityutskiy { 20601e51764aSArtem Bityutskiy if (!dbg_force_in_the_gaps_enabled) 20611e51764aSArtem Bityutskiy return 0; 20621e51764aSArtem Bityutskiy /* Force in-the-gaps every 8th commit */ 20631e51764aSArtem Bityutskiy return !((invocation_cnt++) & 0x7); 20641e51764aSArtem Bityutskiy } 20651e51764aSArtem Bityutskiy 20661e51764aSArtem Bityutskiy /* Failure mode for recovery testing */ 20671e51764aSArtem Bityutskiy 20681e51764aSArtem Bityutskiy #define chance(n, d) (simple_rand() <= (n) * 32768LL / (d)) 20691e51764aSArtem Bityutskiy 20701e51764aSArtem Bityutskiy struct failure_mode_info { 20711e51764aSArtem Bityutskiy struct list_head list; 20721e51764aSArtem Bityutskiy struct ubifs_info *c; 20731e51764aSArtem Bityutskiy }; 20741e51764aSArtem Bityutskiy 20751e51764aSArtem Bityutskiy static LIST_HEAD(fmi_list); 20761e51764aSArtem Bityutskiy static DEFINE_SPINLOCK(fmi_lock); 20771e51764aSArtem Bityutskiy 20781e51764aSArtem Bityutskiy static unsigned int next; 20791e51764aSArtem Bityutskiy 20801e51764aSArtem Bityutskiy static int simple_rand(void) 20811e51764aSArtem Bityutskiy { 20821e51764aSArtem Bityutskiy if (next == 0) 20831e51764aSArtem Bityutskiy next = current->pid; 20841e51764aSArtem Bityutskiy next = next * 1103515245 + 12345; 20851e51764aSArtem Bityutskiy return (next >> 16) & 32767; 20861e51764aSArtem Bityutskiy } 20871e51764aSArtem Bityutskiy 20881e51764aSArtem Bityutskiy void dbg_failure_mode_registration(struct ubifs_info *c) 20891e51764aSArtem Bityutskiy { 20901e51764aSArtem Bityutskiy struct failure_mode_info *fmi; 20911e51764aSArtem Bityutskiy 20921e51764aSArtem Bityutskiy fmi = kmalloc(sizeof(struct failure_mode_info), GFP_NOFS); 20931e51764aSArtem Bityutskiy if (!fmi) { 20941e51764aSArtem Bityutskiy dbg_err("Failed to register failure mode - no memory"); 20951e51764aSArtem Bityutskiy return; 20961e51764aSArtem Bityutskiy } 20971e51764aSArtem Bityutskiy fmi->c = c; 20981e51764aSArtem Bityutskiy spin_lock(&fmi_lock); 20991e51764aSArtem Bityutskiy list_add_tail(&fmi->list, &fmi_list); 21001e51764aSArtem Bityutskiy spin_unlock(&fmi_lock); 21011e51764aSArtem Bityutskiy } 21021e51764aSArtem Bityutskiy 21031e51764aSArtem Bityutskiy void dbg_failure_mode_deregistration(struct ubifs_info *c) 21041e51764aSArtem Bityutskiy { 21051e51764aSArtem Bityutskiy struct failure_mode_info *fmi, *tmp; 21061e51764aSArtem Bityutskiy 21071e51764aSArtem Bityutskiy spin_lock(&fmi_lock); 21081e51764aSArtem Bityutskiy list_for_each_entry_safe(fmi, tmp, &fmi_list, list) 21091e51764aSArtem Bityutskiy if (fmi->c == c) { 21101e51764aSArtem Bityutskiy list_del(&fmi->list); 21111e51764aSArtem Bityutskiy kfree(fmi); 21121e51764aSArtem Bityutskiy } 21131e51764aSArtem Bityutskiy spin_unlock(&fmi_lock); 21141e51764aSArtem Bityutskiy } 21151e51764aSArtem Bityutskiy 21161e51764aSArtem Bityutskiy static struct ubifs_info *dbg_find_info(struct ubi_volume_desc *desc) 21171e51764aSArtem Bityutskiy { 21181e51764aSArtem Bityutskiy struct failure_mode_info *fmi; 21191e51764aSArtem Bityutskiy 21201e51764aSArtem Bityutskiy spin_lock(&fmi_lock); 21211e51764aSArtem Bityutskiy list_for_each_entry(fmi, &fmi_list, list) 21221e51764aSArtem Bityutskiy if (fmi->c->ubi == desc) { 21231e51764aSArtem Bityutskiy struct ubifs_info *c = fmi->c; 21241e51764aSArtem Bityutskiy 21251e51764aSArtem Bityutskiy spin_unlock(&fmi_lock); 21261e51764aSArtem Bityutskiy return c; 21271e51764aSArtem Bityutskiy } 21281e51764aSArtem Bityutskiy spin_unlock(&fmi_lock); 21291e51764aSArtem Bityutskiy return NULL; 21301e51764aSArtem Bityutskiy } 21311e51764aSArtem Bityutskiy 21321e51764aSArtem Bityutskiy static int in_failure_mode(struct ubi_volume_desc *desc) 21331e51764aSArtem Bityutskiy { 21341e51764aSArtem Bityutskiy struct ubifs_info *c = dbg_find_info(desc); 21351e51764aSArtem Bityutskiy 21361e51764aSArtem Bityutskiy if (c && dbg_failure_mode) 21371e51764aSArtem Bityutskiy return c->failure_mode; 21381e51764aSArtem Bityutskiy return 0; 21391e51764aSArtem Bityutskiy } 21401e51764aSArtem Bityutskiy 21411e51764aSArtem Bityutskiy static int do_fail(struct ubi_volume_desc *desc, int lnum, int write) 21421e51764aSArtem Bityutskiy { 21431e51764aSArtem Bityutskiy struct ubifs_info *c = dbg_find_info(desc); 21441e51764aSArtem Bityutskiy 21451e51764aSArtem Bityutskiy if (!c || !dbg_failure_mode) 21461e51764aSArtem Bityutskiy return 0; 21471e51764aSArtem Bityutskiy if (c->failure_mode) 21481e51764aSArtem Bityutskiy return 1; 21491e51764aSArtem Bityutskiy if (!c->fail_cnt) { 21501e51764aSArtem Bityutskiy /* First call - decide delay to failure */ 21511e51764aSArtem Bityutskiy if (chance(1, 2)) { 21521e51764aSArtem Bityutskiy unsigned int delay = 1 << (simple_rand() >> 11); 21531e51764aSArtem Bityutskiy 21541e51764aSArtem Bityutskiy if (chance(1, 2)) { 21551e51764aSArtem Bityutskiy c->fail_delay = 1; 21561e51764aSArtem Bityutskiy c->fail_timeout = jiffies + 21571e51764aSArtem Bityutskiy msecs_to_jiffies(delay); 21581e51764aSArtem Bityutskiy dbg_rcvry("failing after %ums", delay); 21591e51764aSArtem Bityutskiy } else { 21601e51764aSArtem Bityutskiy c->fail_delay = 2; 21611e51764aSArtem Bityutskiy c->fail_cnt_max = delay; 21621e51764aSArtem Bityutskiy dbg_rcvry("failing after %u calls", delay); 21631e51764aSArtem Bityutskiy } 21641e51764aSArtem Bityutskiy } 21651e51764aSArtem Bityutskiy c->fail_cnt += 1; 21661e51764aSArtem Bityutskiy } 21671e51764aSArtem Bityutskiy /* Determine if failure delay has expired */ 21681e51764aSArtem Bityutskiy if (c->fail_delay == 1) { 21691e51764aSArtem Bityutskiy if (time_before(jiffies, c->fail_timeout)) 21701e51764aSArtem Bityutskiy return 0; 21711e51764aSArtem Bityutskiy } else if (c->fail_delay == 2) 21721e51764aSArtem Bityutskiy if (c->fail_cnt++ < c->fail_cnt_max) 21731e51764aSArtem Bityutskiy return 0; 21741e51764aSArtem Bityutskiy if (lnum == UBIFS_SB_LNUM) { 21751e51764aSArtem Bityutskiy if (write) { 21761e51764aSArtem Bityutskiy if (chance(1, 2)) 21771e51764aSArtem Bityutskiy return 0; 21781e51764aSArtem Bityutskiy } else if (chance(19, 20)) 21791e51764aSArtem Bityutskiy return 0; 21801e51764aSArtem Bityutskiy dbg_rcvry("failing in super block LEB %d", lnum); 21811e51764aSArtem Bityutskiy } else if (lnum == UBIFS_MST_LNUM || lnum == UBIFS_MST_LNUM + 1) { 21821e51764aSArtem Bityutskiy if (chance(19, 20)) 21831e51764aSArtem Bityutskiy return 0; 21841e51764aSArtem Bityutskiy dbg_rcvry("failing in master LEB %d", lnum); 21851e51764aSArtem Bityutskiy } else if (lnum >= UBIFS_LOG_LNUM && lnum <= c->log_last) { 21861e51764aSArtem Bityutskiy if (write) { 21871e51764aSArtem Bityutskiy if (chance(99, 100)) 21881e51764aSArtem Bityutskiy return 0; 21891e51764aSArtem Bityutskiy } else if (chance(399, 400)) 21901e51764aSArtem Bityutskiy return 0; 21911e51764aSArtem Bityutskiy dbg_rcvry("failing in log LEB %d", lnum); 21921e51764aSArtem Bityutskiy } else if (lnum >= c->lpt_first && lnum <= c->lpt_last) { 21931e51764aSArtem Bityutskiy if (write) { 21941e51764aSArtem Bityutskiy if (chance(7, 8)) 21951e51764aSArtem Bityutskiy return 0; 21961e51764aSArtem Bityutskiy } else if (chance(19, 20)) 21971e51764aSArtem Bityutskiy return 0; 21981e51764aSArtem Bityutskiy dbg_rcvry("failing in LPT LEB %d", lnum); 21991e51764aSArtem Bityutskiy } else if (lnum >= c->orph_first && lnum <= c->orph_last) { 22001e51764aSArtem Bityutskiy if (write) { 22011e51764aSArtem Bityutskiy if (chance(1, 2)) 22021e51764aSArtem Bityutskiy return 0; 22031e51764aSArtem Bityutskiy } else if (chance(9, 10)) 22041e51764aSArtem Bityutskiy return 0; 22051e51764aSArtem Bityutskiy dbg_rcvry("failing in orphan LEB %d", lnum); 22061e51764aSArtem Bityutskiy } else if (lnum == c->ihead_lnum) { 22071e51764aSArtem Bityutskiy if (chance(99, 100)) 22081e51764aSArtem Bityutskiy return 0; 22091e51764aSArtem Bityutskiy dbg_rcvry("failing in index head LEB %d", lnum); 22101e51764aSArtem Bityutskiy } else if (c->jheads && lnum == c->jheads[GCHD].wbuf.lnum) { 22111e51764aSArtem Bityutskiy if (chance(9, 10)) 22121e51764aSArtem Bityutskiy return 0; 22131e51764aSArtem Bityutskiy dbg_rcvry("failing in GC head LEB %d", lnum); 22141e51764aSArtem Bityutskiy } else if (write && !RB_EMPTY_ROOT(&c->buds) && 22151e51764aSArtem Bityutskiy !ubifs_search_bud(c, lnum)) { 22161e51764aSArtem Bityutskiy if (chance(19, 20)) 22171e51764aSArtem Bityutskiy return 0; 22181e51764aSArtem Bityutskiy dbg_rcvry("failing in non-bud LEB %d", lnum); 22191e51764aSArtem Bityutskiy } else if (c->cmt_state == COMMIT_RUNNING_BACKGROUND || 22201e51764aSArtem Bityutskiy c->cmt_state == COMMIT_RUNNING_REQUIRED) { 22211e51764aSArtem Bityutskiy if (chance(999, 1000)) 22221e51764aSArtem Bityutskiy return 0; 22231e51764aSArtem Bityutskiy dbg_rcvry("failing in bud LEB %d commit running", lnum); 22241e51764aSArtem Bityutskiy } else { 22251e51764aSArtem Bityutskiy if (chance(9999, 10000)) 22261e51764aSArtem Bityutskiy return 0; 22271e51764aSArtem Bityutskiy dbg_rcvry("failing in bud LEB %d commit not running", lnum); 22281e51764aSArtem Bityutskiy } 22291e51764aSArtem Bityutskiy ubifs_err("*** SETTING FAILURE MODE ON (LEB %d) ***", lnum); 22301e51764aSArtem Bityutskiy c->failure_mode = 1; 22311e51764aSArtem Bityutskiy dump_stack(); 22321e51764aSArtem Bityutskiy return 1; 22331e51764aSArtem Bityutskiy } 22341e51764aSArtem Bityutskiy 22351e51764aSArtem Bityutskiy static void cut_data(const void *buf, int len) 22361e51764aSArtem Bityutskiy { 22371e51764aSArtem Bityutskiy int flen, i; 22381e51764aSArtem Bityutskiy unsigned char *p = (void *)buf; 22391e51764aSArtem Bityutskiy 22401e51764aSArtem Bityutskiy flen = (len * (long long)simple_rand()) >> 15; 22411e51764aSArtem Bityutskiy for (i = flen; i < len; i++) 22421e51764aSArtem Bityutskiy p[i] = 0xff; 22431e51764aSArtem Bityutskiy } 22441e51764aSArtem Bityutskiy 22451e51764aSArtem Bityutskiy int dbg_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset, 22461e51764aSArtem Bityutskiy int len, int check) 22471e51764aSArtem Bityutskiy { 22481e51764aSArtem Bityutskiy if (in_failure_mode(desc)) 22491e51764aSArtem Bityutskiy return -EIO; 22501e51764aSArtem Bityutskiy return ubi_leb_read(desc, lnum, buf, offset, len, check); 22511e51764aSArtem Bityutskiy } 22521e51764aSArtem Bityutskiy 22531e51764aSArtem Bityutskiy int dbg_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf, 22541e51764aSArtem Bityutskiy int offset, int len, int dtype) 22551e51764aSArtem Bityutskiy { 225616dfd804SAdrian Hunter int err, failing; 22571e51764aSArtem Bityutskiy 22581e51764aSArtem Bityutskiy if (in_failure_mode(desc)) 22591e51764aSArtem Bityutskiy return -EIO; 226016dfd804SAdrian Hunter failing = do_fail(desc, lnum, 1); 226116dfd804SAdrian Hunter if (failing) 22621e51764aSArtem Bityutskiy cut_data(buf, len); 22631e51764aSArtem Bityutskiy err = ubi_leb_write(desc, lnum, buf, offset, len, dtype); 22641e51764aSArtem Bityutskiy if (err) 22651e51764aSArtem Bityutskiy return err; 226616dfd804SAdrian Hunter if (failing) 22671e51764aSArtem Bityutskiy return -EIO; 22681e51764aSArtem Bityutskiy return 0; 22691e51764aSArtem Bityutskiy } 22701e51764aSArtem Bityutskiy 22711e51764aSArtem Bityutskiy int dbg_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, 22721e51764aSArtem Bityutskiy int len, int dtype) 22731e51764aSArtem Bityutskiy { 22741e51764aSArtem Bityutskiy int err; 22751e51764aSArtem Bityutskiy 22761e51764aSArtem Bityutskiy if (do_fail(desc, lnum, 1)) 22771e51764aSArtem Bityutskiy return -EIO; 22781e51764aSArtem Bityutskiy err = ubi_leb_change(desc, lnum, buf, len, dtype); 22791e51764aSArtem Bityutskiy if (err) 22801e51764aSArtem Bityutskiy return err; 22811e51764aSArtem Bityutskiy if (do_fail(desc, lnum, 1)) 22821e51764aSArtem Bityutskiy return -EIO; 22831e51764aSArtem Bityutskiy return 0; 22841e51764aSArtem Bityutskiy } 22851e51764aSArtem Bityutskiy 22861e51764aSArtem Bityutskiy int dbg_leb_erase(struct ubi_volume_desc *desc, int lnum) 22871e51764aSArtem Bityutskiy { 22881e51764aSArtem Bityutskiy int err; 22891e51764aSArtem Bityutskiy 22901e51764aSArtem Bityutskiy if (do_fail(desc, lnum, 0)) 22911e51764aSArtem Bityutskiy return -EIO; 22921e51764aSArtem Bityutskiy err = ubi_leb_erase(desc, lnum); 22931e51764aSArtem Bityutskiy if (err) 22941e51764aSArtem Bityutskiy return err; 22951e51764aSArtem Bityutskiy if (do_fail(desc, lnum, 0)) 22961e51764aSArtem Bityutskiy return -EIO; 22971e51764aSArtem Bityutskiy return 0; 22981e51764aSArtem Bityutskiy } 22991e51764aSArtem Bityutskiy 23001e51764aSArtem Bityutskiy int dbg_leb_unmap(struct ubi_volume_desc *desc, int lnum) 23011e51764aSArtem Bityutskiy { 23021e51764aSArtem Bityutskiy int err; 23031e51764aSArtem Bityutskiy 23041e51764aSArtem Bityutskiy if (do_fail(desc, lnum, 0)) 23051e51764aSArtem Bityutskiy return -EIO; 23061e51764aSArtem Bityutskiy err = ubi_leb_unmap(desc, lnum); 23071e51764aSArtem Bityutskiy if (err) 23081e51764aSArtem Bityutskiy return err; 23091e51764aSArtem Bityutskiy if (do_fail(desc, lnum, 0)) 23101e51764aSArtem Bityutskiy return -EIO; 23111e51764aSArtem Bityutskiy return 0; 23121e51764aSArtem Bityutskiy } 23131e51764aSArtem Bityutskiy 23141e51764aSArtem Bityutskiy int dbg_is_mapped(struct ubi_volume_desc *desc, int lnum) 23151e51764aSArtem Bityutskiy { 23161e51764aSArtem Bityutskiy if (in_failure_mode(desc)) 23171e51764aSArtem Bityutskiy return -EIO; 23181e51764aSArtem Bityutskiy return ubi_is_mapped(desc, lnum); 23191e51764aSArtem Bityutskiy } 23201e51764aSArtem Bityutskiy 23211e51764aSArtem Bityutskiy int dbg_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype) 23221e51764aSArtem Bityutskiy { 23231e51764aSArtem Bityutskiy int err; 23241e51764aSArtem Bityutskiy 23251e51764aSArtem Bityutskiy if (do_fail(desc, lnum, 0)) 23261e51764aSArtem Bityutskiy return -EIO; 23271e51764aSArtem Bityutskiy err = ubi_leb_map(desc, lnum, dtype); 23281e51764aSArtem Bityutskiy if (err) 23291e51764aSArtem Bityutskiy return err; 23301e51764aSArtem Bityutskiy if (do_fail(desc, lnum, 0)) 23311e51764aSArtem Bityutskiy return -EIO; 23321e51764aSArtem Bityutskiy return 0; 23331e51764aSArtem Bityutskiy } 23341e51764aSArtem Bityutskiy 23351e51764aSArtem Bityutskiy #endif /* CONFIG_UBIFS_FS_DEBUG */ 2336