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