Add ext4_sb_set_blocks_cnt
[lwext4.git] / lwext4 / ext4_debug.h
1 /*
2  * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
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.
16  *
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.
27  */
28
29 /** @addtogroup lwext4
30  * @{
31  */
32 /**
33  * @file  ext4_debug.c
34  * @brief Debug printf and assert macros.
35  */
36
37 #ifndef EXT4_DEBUG_H_
38 #define EXT4_DEBUG_H_
39
40 #include "ext4_config.h"
41 #include "ext4_errno.h"
42
43 #if !CONFIG_HAVE_OWN_ASSERT
44 #include <assert.h>
45 #endif
46
47 #include <stdint.h>
48 #include <stdio.h>
49 #include <inttypes.h>
50
51 #ifndef PRIu64
52 #define PRIu64 "llu"
53 #endif
54
55 #ifndef PRId64
56 #define PRId64 "lld"
57 #endif
58
59
60 #define DEBUG_BALLOC (1 << 0)
61 #define DEBUG_BCACHE (1 << 1)
62 #define DEBUG_BITMAP (1 << 2)
63 #define DEBUG_BLOCK_GROUP (1 << 3)
64 #define DEBUG_BLOCKDEV (1 << 4)
65 #define DEBUG_DIR_IDX (1 << 5)
66 #define DEBUG_DIR (1 << 6)
67 #define DEBUG_EXTENT (1 << 7)
68 #define DEBUG_FS (1 << 8)
69 #define DEBUG_HASH (1 << 9)
70 #define DEBUG_IALLOC (1 << 10)
71 #define DEBUG_INODE (1 << 11)
72 #define DEBUG_SUPER (1 << 12)
73 #define DEBUG_XATTR (1 << 13)
74 #define DEBUG_MKFS (1 << 14)
75 #define DEBUG_EXT4 (1 << 15)
76
77 #define DEBUG_ALL (0xFFFFFFFF)
78
79 static inline const char *ext4_dmask_id2str(uint32_t m)
80 {
81         switch(m) {
82         case DEBUG_BALLOC:
83                 return "ext4_balloc: ";
84         case DEBUG_BCACHE:
85                 return "ext4_bcache: ";
86         case DEBUG_BITMAP:
87                 return "ext4_bitmap: ";
88         case DEBUG_BLOCK_GROUP:
89                 return "ext4_block_group: ";
90         case DEBUG_BLOCKDEV:
91                 return "ext4_blockdev: ";
92         case DEBUG_DIR_IDX:
93                 return "ext4_dir_idx: ";
94         case DEBUG_DIR:
95                 return "ext4_dir: ";
96         case DEBUG_EXTENT:
97                 return "ext4_extent: ";
98         case DEBUG_FS:
99                 return "ext4_fs: ";
100         case DEBUG_HASH:
101                 return "ext4_hash: ";
102         case DEBUG_IALLOC:
103                 return "ext4_ialloc: ";
104         case DEBUG_INODE:
105                 return "ext4_inode: ";
106         case DEBUG_SUPER:
107                 return "ext4_super: ";
108         case DEBUG_XATTR:
109                 return "ext4_xattr: ";
110         case DEBUG_MKFS:
111                 return "ext4_mkfs: ";
112         case DEBUG_EXT4:
113                 return "ext4: ";
114         }
115         return "";
116 }
117 #define DBG_NONE  "        "
118 #define DBG_INFO  "[info]  "
119 #define DBG_WARN  "[warn]  "
120 #define DBG_ERROR "[error] "
121
122 /**@brief   Global mask debug set.
123  * @brief   m new debug mask.*/
124 void ext4_dmask_set(uint32_t m);
125
126 /**@brief   Global mask debug clear.
127  * @brief   m new debug mask.*/
128 void ext4_dmask_clr(uint32_t m);
129
130 /**@brief   Global debug mask get.
131  * @return  debug mask*/
132 uint32_t ext4_dmask_get(void);
133
134 #if CONFIG_DEBUG_PRINTF
135 /**@brief   Debug printf.*/
136 #define ext4_dbg(m, ...)                                                       \
137         do {                                                                   \
138                 if (m & ext4_dmask_get()) {                                    \
139                         if (CONFIG_DEBUG_PREFIX) {                             \
140                                 printf("%s", ext4_dmask_id2str(m));            \
141                                 printf("l: %d   ", __LINE__);                  \
142                         }                                                      \
143                         printf(__VA_ARGS__);                                   \
144                         fflush(stdout);                                        \
145                 }                                                              \
146         } while (0)
147 #else
148 #define ext4_dbg(m, ...) do { } while (0)
149 #endif
150
151 #if CONFIG_DEBUG_ASSERT
152 /**@brief   Debug assertion.*/
153  #if CONFIG_HAVE_OWN_ASSERT
154  #define ext4_assert(_v)                                                       \
155         do {                                                                   \
156                 if (!(_v)) {                                                   \
157                         printf("assertion failed:\nfile: %s\nline: %d\n",      \
158                                __FILE__, __LINE__);                            \
159                                while (1)                                       \
160                                        ;                                       \
161                 }                                                              \
162         } while (0)
163  #else
164  #define ext4_assert(_v) assert(_v)
165  #endif
166 #else
167 #define ext4_assert(_v)
168 #endif
169
170 #endif /* EXT4_DEBUG_H_ */
171
172 /**
173  * @}
174  */