2 * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /** @addtogroup lwext4
34 * @brief Debug printf and assert macros.
40 #include "ext4_config.h"
41 #include "ext4_errno.h"
43 #if !CONFIG_HAVE_OWN_ASSERT
50 #define DEBUG_BALLOC (1 << 0)
51 #define DEBUG_BCACHE (1 << 1)
52 #define DEBUG_BITMAP (1 << 2)
53 #define DEBUG_BLOCK_GROUP (1 << 3)
54 #define DEBUG_BLOCKDEV (1 << 4)
55 #define DEBUG_DIR_IDX (1 << 5)
56 #define DEBUG_DIR (1 << 6)
57 #define DEBUG_EXTENT (1 << 7)
58 #define DEBUG_FS (1 << 8)
59 #define DEBUG_HASH (1 << 9)
60 #define DEBUG_IALLOC (1 << 10)
61 #define DEBUG_INODE (1 << 11)
62 #define DEBUG_SUPER (1 << 12)
63 #define DEBUG_XATTR (1 << 13)
64 #define DEBUG_MKFS (1 << 14)
65 #define DEBUG_EXT4 (1 << 15)
67 #define DEBUG_ALL (0xFFFFFFFF)
69 static inline const char *ext4_dmask_id2str(uint32_t m)
73 return "ext4_balloc: ";
75 return "ext4_bcache: ";
77 return "ext4_bitmap: ";
78 case DEBUG_BLOCK_GROUP:
79 return "ext4_block_group: ";
81 return "ext4_blockdev: ";
83 return "ext4_dir_idx: ";
87 return "ext4_extent: ";
93 return "ext4_ialloc: ";
95 return "ext4_inode: ";
97 return "ext4_super: ";
99 return "ext4_xattr: ";
101 return "ext4_mkfs: ";
108 #define DBG_INFO "[info] "
109 #define DBG_WARN "[warn] "
110 #define DBG_ERROR "[error] "
112 /**@brief Global mask debug set.
113 * @brief m new debug mask.*/
114 void ext4_dmask_set(uint32_t m);
116 /**@brief Global mask debug clear.
117 * @brief m new debug mask.*/
118 void ext4_dmask_clr(uint32_t m);
120 /**@brief Global debug mask get.
121 * @return debug mask*/
122 uint32_t ext4_dmask_get(void);
124 #if CONFIG_DEBUG_PRINTF
125 /**@brief Debug printf.*/
126 #define ext4_dbg(m, ...) \
128 if (m & ext4_dmask_get()) { \
129 printf(ext4_dmask_id2str(m)); \
130 printf(__VA_ARGS__); \
135 #define ext4_dbg(m, ...) do { } while (0)
138 #if CONFIG_DEBUG_ASSERT
139 /**@brief Debug assertion.*/
140 #if CONFIG_HAVE_OWN_ASSERT
141 #define ext4_assert(_v) \
144 printf("assertion failed:\nfile: %s\nline: %d\n", \
145 __FILE__, __LINE__); \
151 #define ext4_assert(_v) assert(_v)
154 #define ext4_assert(_v)
157 #endif /* EXT4_DEBUG_H_ */