2 * This file is part of UBIFS.
4 * Copyright (C) 2006-2008 Nokia Corporation
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Artem Bityutskiy (Битюцкий Артём)
24 * This file implements most of the debugging stuff which is compiled in only
25 * when it is enabled. But some debugging check functions are implemented in
26 * corresponding subsystem, just because they are closely related and utilize
27 * various local functions of those subsystems.
30 #define UBIFS_DBG_PRESERVE_UBI
34 #ifdef CONFIG_UBIFS_FS_DEBUG
36 DEFINE_SPINLOCK(dbg_lock);
38 static char dbg_key_buf0[128];
39 static char dbg_key_buf1[128];
41 unsigned int ubifs_msg_flags = UBIFS_MSG_FLAGS_DEFAULT;
42 unsigned int ubifs_chk_flags = UBIFS_CHK_FLAGS_DEFAULT;
43 unsigned int ubifs_tst_flags;
45 module_param_named(debug_msgs, ubifs_msg_flags, uint, S_IRUGO | S_IWUSR);
46 module_param_named(debug_chks, ubifs_chk_flags, uint, S_IRUGO | S_IWUSR);
47 module_param_named(debug_tsts, ubifs_tst_flags, uint, S_IRUGO | S_IWUSR);
49 MODULE_PARM_DESC(debug_msgs, "Debug message type flags");
50 MODULE_PARM_DESC(debug_chks, "Debug check flags");
51 MODULE_PARM_DESC(debug_tsts, "Debug special test flags");
53 static const char *get_key_type(int type)
67 return "unknown/invalid key";
71 static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key,
75 int type = key_type(c, key);
77 if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) {
80 sprintf(p, "(%lu, %s)", (unsigned long)key_inum(c, key),
85 sprintf(p, "(%lu, %s, %#08x)",
86 (unsigned long)key_inum(c, key),
87 get_key_type(type), key_hash(c, key));
90 sprintf(p, "(%lu, %s, %u)",
91 (unsigned long)key_inum(c, key),
92 get_key_type(type), key_block(c, key));
95 sprintf(p, "(%lu, %s)",
96 (unsigned long)key_inum(c, key),
100 sprintf(p, "(bad key type: %#08x, %#08x)",
101 key->u32[0], key->u32[1]);
104 sprintf(p, "bad key format %d", c->key_fmt);
107 const char *dbg_key_str0(const struct ubifs_info *c, const union ubifs_key *key)
109 /* dbg_lock must be held */
110 sprintf_key(c, key, dbg_key_buf0);
114 const char *dbg_key_str1(const struct ubifs_info *c, const union ubifs_key *key)
116 /* dbg_lock must be held */
117 sprintf_key(c, key, dbg_key_buf1);
122 * ubifs_debugging_init - initialize UBIFS debugging.
123 * @c: UBIFS file-system description object
125 * This function initializes debugging-related data for the file system.
126 * Returns zero in case of success and a negative error code in case of
129 int ubifs_debugging_init(struct ubifs_info *c)
131 c->dbg = kzalloc(sizeof(struct ubifs_debug_info), GFP_KERNEL);
135 c->dbg->buf = vmalloc(c->leb_size);
147 * ubifs_debugging_exit - free debugging data.
148 * @c: UBIFS file-system description object
150 void ubifs_debugging_exit(struct ubifs_info *c)
156 #endif /* CONFIG_UBIFS_FS_DEBUG */