1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#define UBIFS_DBG_PRESERVE_UBI
31
32#include "ubifs.h"
33
34#ifdef CONFIG_UBIFS_FS_DEBUG
35
36DEFINE_SPINLOCK(dbg_lock);
37
38static char dbg_key_buf0[128];
39static char dbg_key_buf1[128];
40
41unsigned int ubifs_msg_flags = UBIFS_MSG_FLAGS_DEFAULT;
42unsigned int ubifs_chk_flags = UBIFS_CHK_FLAGS_DEFAULT;
43unsigned int ubifs_tst_flags;
44
45module_param_named(debug_msgs, ubifs_msg_flags, uint, S_IRUGO | S_IWUSR);
46module_param_named(debug_chks, ubifs_chk_flags, uint, S_IRUGO | S_IWUSR);
47module_param_named(debug_tsts, ubifs_tst_flags, uint, S_IRUGO | S_IWUSR);
48
49MODULE_PARM_DESC(debug_msgs, "Debug message type flags");
50MODULE_PARM_DESC(debug_chks, "Debug check flags");
51MODULE_PARM_DESC(debug_tsts, "Debug special test flags");
52
53static const char *get_key_type(int type)
54{
55 switch (type) {
56 case UBIFS_INO_KEY:
57 return "inode";
58 case UBIFS_DENT_KEY:
59 return "direntry";
60 case UBIFS_XENT_KEY:
61 return "xentry";
62 case UBIFS_DATA_KEY:
63 return "data";
64 case UBIFS_TRUN_KEY:
65 return "truncate";
66 default:
67 return "unknown/invalid key";
68 }
69}
70
71static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key,
72 char *buffer)
73{
74 char *p = buffer;
75 int type = key_type(c, key);
76
77 if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) {
78 switch (type) {
79 case UBIFS_INO_KEY:
80 sprintf(p, "(%lu, %s)", (unsigned long)key_inum(c, key),
81 get_key_type(type));
82 break;
83 case UBIFS_DENT_KEY:
84 case UBIFS_XENT_KEY:
85 sprintf(p, "(%lu, %s, %#08x)",
86 (unsigned long)key_inum(c, key),
87 get_key_type(type), key_hash(c, key));
88 break;
89 case UBIFS_DATA_KEY:
90 sprintf(p, "(%lu, %s, %u)",
91 (unsigned long)key_inum(c, key),
92 get_key_type(type), key_block(c, key));
93 break;
94 case UBIFS_TRUN_KEY:
95 sprintf(p, "(%lu, %s)",
96 (unsigned long)key_inum(c, key),
97 get_key_type(type));
98 break;
99 default:
100 sprintf(p, "(bad key type: %#08x, %#08x)",
101 key->u32[0], key->u32[1]);
102 }
103 } else
104 sprintf(p, "bad key format %d", c->key_fmt);
105}
106
107const char *dbg_key_str0(const struct ubifs_info *c, const union ubifs_key *key)
108{
109
110 sprintf_key(c, key, dbg_key_buf0);
111 return dbg_key_buf0;
112}
113
114const char *dbg_key_str1(const struct ubifs_info *c, const union ubifs_key *key)
115{
116
117 sprintf_key(c, key, dbg_key_buf1);
118 return dbg_key_buf1;
119}
120
121
122
123
124
125
126
127
128
129int ubifs_debugging_init(struct ubifs_info *c)
130{
131 c->dbg = kzalloc(sizeof(struct ubifs_debug_info), GFP_KERNEL);
132 if (!c->dbg)
133 return -ENOMEM;
134
135 c->dbg->buf = vmalloc(c->leb_size);
136 if (!c->dbg->buf)
137 goto out;
138
139 return 0;
140
141out:
142 kfree(c->dbg);
143 return -ENOMEM;
144}
145
146
147
148
149
150void ubifs_debugging_exit(struct ubifs_info *c)
151{
152 vfree(c->dbg->buf);
153 kfree(c->dbg);
154}
155
156#endif
157