mmc: omap: don't set wrong voltage select for mmc2
[pandora-u-boot.git] / fs / ubifs / debug.c
1 /*
2  * This file is part of UBIFS.
3  *
4  * Copyright (C) 2006-2008 Nokia Corporation
5  *
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.
9  *
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
13  * more details.
14  *
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
18  *
19  * Authors: Artem Bityutskiy (Битюцкий Артём)
20  *          Adrian Hunter
21  */
22
23 /*
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.
28  */
29
30 #define UBIFS_DBG_PRESERVE_UBI
31
32 #include "ubifs.h"
33
34 #ifdef CONFIG_UBIFS_FS_DEBUG
35
36 DEFINE_SPINLOCK(dbg_lock);
37
38 static char dbg_key_buf0[128];
39 static char dbg_key_buf1[128];
40
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;
44
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);
48
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");
52
53 static 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
71 static 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
107 const char *dbg_key_str0(const struct ubifs_info *c, const union ubifs_key *key)
108 {
109         /* dbg_lock must be held */
110         sprintf_key(c, key, dbg_key_buf0);
111         return dbg_key_buf0;
112 }
113
114 const char *dbg_key_str1(const struct ubifs_info *c, const union ubifs_key *key)
115 {
116         /* dbg_lock must be held */
117         sprintf_key(c, key, dbg_key_buf1);
118         return dbg_key_buf1;
119 }
120
121 /**
122  * ubifs_debugging_init - initialize UBIFS debugging.
123  * @c: UBIFS file-system description object
124  *
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
127  * failure.
128  */
129 int 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
141 out:
142         kfree(c->dbg);
143         return -ENOMEM;
144 }
145
146 /**
147  * ubifs_debugging_exit - free debugging data.
148  * @c: UBIFS file-system description object
149  */
150 void ubifs_debugging_exit(struct ubifs_info *c)
151 {
152         vfree(c->dbg->buf);
153         kfree(c->dbg);
154 }
155
156 #endif /* CONFIG_UBIFS_FS_DEBUG */