^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) #ifndef __UBIFS_DEBUG_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define __UBIFS_DEBUG_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /* Checking helper functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) typedef int (*dbg_leaf_callback)(struct ubifs_info *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct ubifs_zbranch *zbr, void *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) typedef int (*dbg_znode_callback)(struct ubifs_info *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct ubifs_znode *znode, void *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * The UBIFS debugfs directory name pattern and maximum name length (3 for "ubi"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * + 1 for "_" and plus 2x2 for 2 UBI numbers and 1 for the trailing zero byte.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define UBIFS_DFS_DIR_NAME "ubi%d_%d"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define UBIFS_DFS_DIR_LEN (3 + 1 + 2*2 + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * ubifs_debug_info - per-FS debugging information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * @old_zroot: old index root - used by 'dbg_check_old_index()'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * @old_zroot_level: old index root level - used by 'dbg_check_old_index()'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * @old_zroot_sqnum: old index root sqnum - used by 'dbg_check_old_index()'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * @pc_happened: non-zero if an emulated power cut happened
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * @pc_delay: 0=>don't delay, 1=>delay a time, 2=>delay a number of calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * @pc_timeout: time in jiffies when delay of failure mode expires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * @pc_cnt: current number of calls to failure mode I/O functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * @pc_cnt_max: number of calls by which to delay failure mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * @chk_lpt_sz: used by LPT tree size checker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * @chk_lpt_sz2: used by LPT tree size checker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * @chk_lpt_wastage: used by LPT tree size checker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * @chk_lpt_lebs: used by LPT tree size checker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * @new_nhead_offs: used by LPT tree size checker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * @new_ihead_lnum: used by debugging to check @c->ihead_lnum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @new_ihead_offs: used by debugging to check @c->ihead_offs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * @saved_lst: saved lprops statistics (used by 'dbg_save_space_info()')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * @saved_bi: saved budgeting information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * @saved_free: saved amount of free space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * @saved_idx_gc_cnt: saved value of @c->idx_gc_cnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * @chk_gen: if general extra checks are enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * @chk_index: if index xtra checks are enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * @chk_orph: if orphans extra checks are enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * @chk_lprops: if lprops extra checks are enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * @chk_fs: if UBIFS contents extra checks are enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * @tst_rcvry: if UBIFS recovery testing mode enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * @dfs_dir_name: name of debugfs directory containing this file-system's files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * @dfs_dir: direntry object of the file-system debugfs directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * @dfs_dump_lprops: "dump lprops" debugfs knob
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * @dfs_dump_budg: "dump budgeting information" debugfs knob
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * @dfs_dump_tnc: "dump TNC" debugfs knob
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * @dfs_chk_gen: debugfs knob to enable UBIFS general extra checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * @dfs_chk_index: debugfs knob to enable UBIFS index extra checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * @dfs_chk_orph: debugfs knob to enable UBIFS orphans extra checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * @dfs_chk_lprops: debugfs knob to enable UBIFS LEP properties extra checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * @dfs_chk_fs: debugfs knob to enable UBIFS contents extra checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * @dfs_tst_rcvry: debugfs knob to enable UBIFS recovery testing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * @dfs_ro_error: debugfs knob to switch UBIFS to R/O mode (different to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * re-mounting to R/O mode because it does not flush any buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * and UBIFS just starts returning -EROFS on all write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * operations)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct ubifs_debug_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct ubifs_zbranch old_zroot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) int old_zroot_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) unsigned long long old_zroot_sqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int pc_happened;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int pc_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) unsigned long pc_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) unsigned int pc_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) unsigned int pc_cnt_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) long long chk_lpt_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) long long chk_lpt_sz2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) long long chk_lpt_wastage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) int chk_lpt_lebs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int new_nhead_offs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int new_ihead_lnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int new_ihead_offs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct ubifs_lp_stats saved_lst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct ubifs_budg_info saved_bi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) long long saved_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) int saved_idx_gc_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) unsigned int chk_gen:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) unsigned int chk_index:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) unsigned int chk_orph:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) unsigned int chk_lprops:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) unsigned int chk_fs:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) unsigned int tst_rcvry:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) char dfs_dir_name[UBIFS_DFS_DIR_LEN + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct dentry *dfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct dentry *dfs_dump_lprops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct dentry *dfs_dump_budg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct dentry *dfs_dump_tnc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct dentry *dfs_chk_gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct dentry *dfs_chk_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct dentry *dfs_chk_orph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct dentry *dfs_chk_lprops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct dentry *dfs_chk_fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct dentry *dfs_tst_rcvry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct dentry *dfs_ro_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * ubifs_global_debug_info - global (not per-FS) UBIFS debugging information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * @chk_gen: if general extra checks are enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * @chk_index: if index xtra checks are enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * @chk_orph: if orphans extra checks are enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * @chk_lprops: if lprops extra checks are enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * @chk_fs: if UBIFS contents extra checks are enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * @tst_rcvry: if UBIFS recovery testing mode enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct ubifs_global_debug_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unsigned int chk_gen:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) unsigned int chk_index:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) unsigned int chk_orph:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) unsigned int chk_lprops:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) unsigned int chk_fs:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) unsigned int tst_rcvry:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) void ubifs_assert_failed(struct ubifs_info *c, const char *expr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) const char *file, int line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define ubifs_assert(c, expr) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (unlikely(!(expr))) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) ubifs_assert_failed((struct ubifs_info *)c, #expr, __FILE__, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) __LINE__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #define ubifs_assert_cmt_locked(c) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (unlikely(down_write_trylock(&(c)->commit_sem))) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) up_write(&(c)->commit_sem); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ubifs_err(c, "commit lock is not locked!\n"); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ubifs_assert(c, 0); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #define ubifs_dbg_msg(type, fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) pr_debug("UBIFS DBG " type " (pid %d): " fmt "\n", current->pid, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #define DBG_KEY_BUF_LEN 48
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) #define ubifs_dbg_msg_key(type, key, fmt, ...) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) char __tmp_key_buf[DBG_KEY_BUF_LEN]; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) pr_debug("UBIFS DBG " type " (pid %d): " fmt "%s\n", current->pid, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) ##__VA_ARGS__, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) dbg_snprintf_key(c, key, __tmp_key_buf, DBG_KEY_BUF_LEN)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* General messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #define dbg_gen(fmt, ...) ubifs_dbg_msg("gen", fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* Additional journal messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #define dbg_jnl(fmt, ...) ubifs_dbg_msg("jnl", fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) #define dbg_jnlk(key, fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ubifs_dbg_msg_key("jnl", key, fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* Additional TNC messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #define dbg_tnc(fmt, ...) ubifs_dbg_msg("tnc", fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #define dbg_tnck(key, fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) ubifs_dbg_msg_key("tnc", key, fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /* Additional lprops messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #define dbg_lp(fmt, ...) ubifs_dbg_msg("lp", fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /* Additional LEB find messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #define dbg_find(fmt, ...) ubifs_dbg_msg("find", fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* Additional mount messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #define dbg_mnt(fmt, ...) ubifs_dbg_msg("mnt", fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #define dbg_mntk(key, fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ubifs_dbg_msg_key("mnt", key, fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* Additional I/O messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #define dbg_io(fmt, ...) ubifs_dbg_msg("io", fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* Additional commit messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) #define dbg_cmt(fmt, ...) ubifs_dbg_msg("cmt", fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /* Additional budgeting messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #define dbg_budg(fmt, ...) ubifs_dbg_msg("budg", fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* Additional log messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) #define dbg_log(fmt, ...) ubifs_dbg_msg("log", fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* Additional gc messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #define dbg_gc(fmt, ...) ubifs_dbg_msg("gc", fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* Additional scan messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #define dbg_scan(fmt, ...) ubifs_dbg_msg("scan", fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* Additional recovery messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #define dbg_rcvry(fmt, ...) ubifs_dbg_msg("rcvry", fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) extern struct ubifs_global_debug_info ubifs_dbg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static inline int dbg_is_chk_gen(const struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return !!(ubifs_dbg.chk_gen || c->dbg->chk_gen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static inline int dbg_is_chk_index(const struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return !!(ubifs_dbg.chk_index || c->dbg->chk_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static inline int dbg_is_chk_orph(const struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return !!(ubifs_dbg.chk_orph || c->dbg->chk_orph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static inline int dbg_is_chk_lprops(const struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return !!(ubifs_dbg.chk_lprops || c->dbg->chk_lprops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static inline int dbg_is_chk_fs(const struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return !!(ubifs_dbg.chk_fs || c->dbg->chk_fs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static inline int dbg_is_tst_rcvry(const struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return !!(ubifs_dbg.tst_rcvry || c->dbg->tst_rcvry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static inline int dbg_is_power_cut(const struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return !!c->dbg->pc_happened;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) int ubifs_debugging_init(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) void ubifs_debugging_exit(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /* Dump functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) const char *dbg_ntype(int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) const char *dbg_cstate(int cmt_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) const char *dbg_jhead(int jhead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) const char *dbg_get_key_dump(const struct ubifs_info *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) const union ubifs_key *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) const char *dbg_snprintf_key(const struct ubifs_info *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) const union ubifs_key *key, char *buffer, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) void ubifs_dump_inode(struct ubifs_info *c, const struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) void ubifs_dump_node(const struct ubifs_info *c, const void *node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) void ubifs_dump_budget_req(const struct ubifs_budget_req *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) void ubifs_dump_lstats(const struct ubifs_lp_stats *lst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) void ubifs_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) void ubifs_dump_lprop(const struct ubifs_info *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) const struct ubifs_lprops *lp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) void ubifs_dump_lprops(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) void ubifs_dump_lpt_info(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) void ubifs_dump_leb(const struct ubifs_info *c, int lnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) void ubifs_dump_sleb(const struct ubifs_info *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) const struct ubifs_scan_leb *sleb, int offs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) void ubifs_dump_znode(const struct ubifs_info *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) const struct ubifs_znode *znode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) void ubifs_dump_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) int cat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) void ubifs_dump_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct ubifs_nnode *parent, int iip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) void ubifs_dump_tnc(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) void ubifs_dump_index(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) void ubifs_dump_lpt_lebs(const struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) dbg_znode_callback znode_cb, void *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /* Checking functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) void dbg_save_space_info(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) int dbg_check_space_info(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int dbg_check_lprops(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) int dbg_old_index_check_init(struct ubifs_info *c, struct ubifs_zbranch *zroot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int dbg_check_cats(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) int dbg_check_ltab(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) int dbg_chk_lpt_free_spc(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) int dbg_check_synced_i_size(const struct ubifs_info *c, struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) int dbg_check_dir(struct ubifs_info *c, const struct inode *dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) int dbg_check_tnc(struct ubifs_info *c, int extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) int dbg_check_idx_size(struct ubifs_info *c, long long idx_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int dbg_check_filesystem(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) int add_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) int dbg_check_lpt_nodes(struct ubifs_info *c, struct ubifs_cnode *cnode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int row, int col);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) int dbg_check_inode_size(struct ubifs_info *c, const struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) loff_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) int dbg_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) int dbg_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) int dbg_leb_unmap(struct ubifs_info *c, int lnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) int dbg_leb_map(struct ubifs_info *c, int lnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /* Debugfs-related stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) void dbg_debugfs_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) void dbg_debugfs_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) void dbg_debugfs_init_fs(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) void dbg_debugfs_exit_fs(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #endif /* !__UBIFS_DEBUG_H__ */