X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=lwext4%2Fext4_debug.h;h=f3f591da36b563122e112befd23f1390a417ef39;hb=45d2d1fe5e93955080c8c24cab765d368402f6a2;hp=5a8abb760f0c76767df1b467d9b7ceb451d9739e;hpb=c91beecad10bf077412d7464d98e0618ca1cb9cd;p=lwext4.git diff --git a/lwext4/ext4_debug.h b/lwext4/ext4_debug.h index 5a8abb7..f3f591d 100644 --- a/lwext4/ext4_debug.h +++ b/lwext4/ext4_debug.h @@ -37,81 +37,150 @@ #ifndef EXT4_DEBUG_H_ #define EXT4_DEBUG_H_ -#include -#include -#include -#include - -/**@brief Debug mask: ext4_blockdev.c*/ -#define EXT4_DEBUG_BLOCKDEV (1 << 0) - -/**@brief Debug mask: ext4_fs.c*/ -#define EXT4_DEBUG_FS (1 << 1) - -/**@brief Debug mask: ext4_balloc.c*/ -#define EXT4_DEBUG_BALLOC (1 << 2) - -/**@brief Debug mask: ext4_bitmap.c*/ -#define EXT4_DEBUG_BITMAP (1 << 3) - -/**@brief Debug mask: ext4_dir_idx.c*/ -#define EXT4_DEBUG_DIR_IDX (1 << 4) - -/**@brief Debug mask: ext4_dir.c*/ -#define EXT4_DEBUG_DIR (1 << 5) - -/**@brief Debug mask: ext4_ialloc.c*/ -#define EXT4_DEBUG_IALLOC (1 << 6) - -/**@brief Debug mask: ext4_inode.c*/ -#define EXT4_DEBUG_INODE (1 << 7) - -/**@brief Debug mask: ext4_super.c*/ -#define EXT4_DEBUG_SUPER (1 << 8) +#ifdef __cplusplus +extern "C" { +#endif -/**@brief Debug mask: ext4_bcache.c*/ -#define EXT4_DEBUG_BCACHE (1 << 9) +#include "ext4_config.h" +#include "ext4_errno.h" -/**@brief Debug mask: ext4_extents.c*/ -#define EXT4_DEBUG_EXTENTS (1 << 10) +#if !CONFIG_HAVE_OWN_ASSERT +#include +#endif +#include +#include +#include +#ifndef PRIu64 +#define PRIu64 "llu" +#endif -/**@brief All debug printf enabled.*/ -#define EXT4_DEBUG_ALL (0xFFFFFFFF) +#ifndef PRId64 +#define PRId64 "lld" +#endif -/**@brief Global mask debug settings. - * @brief m new debug mask.*/ -void ext4_dmask_set(uint32_t m); -/**@brief Global debug mask get. - * @return debug mask*/ +#define DEBUG_BALLOC (1ul << 0) +#define DEBUG_BCACHE (1ul << 1) +#define DEBUG_BITMAP (1ul << 2) +#define DEBUG_BLOCK_GROUP (1ul << 3) +#define DEBUG_BLOCKDEV (1ul << 4) +#define DEBUG_DIR_IDX (1ul << 5) +#define DEBUG_DIR (1ul << 6) +#define DEBUG_EXTENT (1ul << 7) +#define DEBUG_FS (1ul << 8) +#define DEBUG_HASH (1ul << 9) +#define DEBUG_IALLOC (1ul << 10) +#define DEBUG_INODE (1ul << 11) +#define DEBUG_SUPER (1ul << 12) +#define DEBUG_XATTR (1ul << 13) +#define DEBUG_MKFS (1ul << 14) +#define DEBUG_EXT4 (1ul << 15) +#define DEBUG_JBD (1ul << 16) +#define DEBUG_MBR (1ul << 17) + +#define DEBUG_NOPREFIX (1ul << 31) +#define DEBUG_ALL (0xFFFFFFFF) + +static inline const char *ext4_dmask_id2str(uint32_t m) +{ + switch(m) { + case DEBUG_BALLOC: + return "ext4_balloc: "; + case DEBUG_BCACHE: + return "ext4_bcache: "; + case DEBUG_BITMAP: + return "ext4_bitmap: "; + case DEBUG_BLOCK_GROUP: + return "ext4_block_group: "; + case DEBUG_BLOCKDEV: + return "ext4_blockdev: "; + case DEBUG_DIR_IDX: + return "ext4_dir_idx: "; + case DEBUG_DIR: + return "ext4_dir: "; + case DEBUG_EXTENT: + return "ext4_extent: "; + case DEBUG_FS: + return "ext4_fs: "; + case DEBUG_HASH: + return "ext4_hash: "; + case DEBUG_IALLOC: + return "ext4_ialloc: "; + case DEBUG_INODE: + return "ext4_inode: "; + case DEBUG_SUPER: + return "ext4_super: "; + case DEBUG_XATTR: + return "ext4_xattr: "; + case DEBUG_MKFS: + return "ext4_mkfs: "; + case DEBUG_JBD: + return "ext4_jbd: "; + case DEBUG_MBR: + return "ext4_mbr: "; + case DEBUG_EXT4: + return "ext4: "; + } + return ""; +} +#define DBG_NONE "" +#define DBG_INFO "[info] " +#define DBG_WARN "[warn] " +#define DBG_ERROR "[error] " + +/**@brief Global mask debug set. + * @brief m new debug mask.*/ +void ext4_dmask_set(uint32_t m); + +/**@brief Global mask debug clear. + * @brief m new debug mask.*/ +void ext4_dmask_clr(uint32_t m); + +/**@brief Global debug mask get. + * @return debug mask*/ uint32_t ext4_dmask_get(void); - #if CONFIG_DEBUG_PRINTF -/**@brief Debug printf.*/ -#define ext4_dprintf(m, ...) do { \ - (m & ext4_dmask_get()) ? printf(__VA_ARGS__) : (void)0; \ - fflush(stdout); \ -}while(0) +/**@brief Debug printf.*/ +#define ext4_dbg(m, ...) \ + do { \ + if ((m) & ext4_dmask_get()) { \ + if (!((m) & DEBUG_NOPREFIX)) { \ + printf("%s", ext4_dmask_id2str(m)); \ + printf("l: %d ", __LINE__); \ + } \ + printf(__VA_ARGS__); \ + fflush(stdout); \ + } \ + } while (0) #else -#define ext4_dprintf(m, ...) +#define ext4_dbg(m, ...) do { } while (0) #endif - - #if CONFIG_DEBUG_ASSERT -#define ext4_assert(_v) do { \ - if(!(_v)){ \ - printf("Assertion failed:\nModule: %s\nFunc: %s\nLine: %d\n", \ - __FILE__, __FUNCTION__, __LINE__); \ - } \ -}while(0) +/**@brief Debug assertion.*/ +#if CONFIG_HAVE_OWN_ASSERT +#define ext4_assert(_v) \ + do { \ + if (!(_v)) { \ + printf("assertion failed:\nfile: %s\nline: %d\n", \ + __FILE__, __LINE__); \ + while (1) \ + ; \ + } \ + } while (0) #else -#define ext4_assert(_v) +#define ext4_assert(_v) assert(_v) +#endif +#else +#define ext4_assert(_v) #endif +#ifdef __cplusplus +} +#endif #endif /* EXT4_DEBUG_H_ */