xref: /haiku/src/add-ons/kernel/file_systems/fat/debug.h (revision 342a1b221b5bb385410f758df2c625b70cafdd03)
1 /*
2  * Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de.
3  * Copyright 2024, Haiku, Inc. All rights reserved.
4  * This file may be used under the terms of the MIT License.
5  */
6 #ifndef FAT_DEBUG_H
7 #define FAT_DEBUG_H
8 
9 
10 #ifdef FS_SHELL
11 #include "fssh_api_wrapper.h"
12 #else
13 #include <stdio.h>
14 
15 #include <SupportDefs.h>
16 #endif
17 
18 
19 #ifdef USER
20 #define __out printf
21 #else
22 #define __out dprintf
23 #endif
24 
25 // Which debugger should be used when?
26 // The DEBUGGER() macro actually has no effect if DEBUG is not defined,
27 // use the DIE() macro if you really want to die.
28 #ifdef DEBUG
29 #ifdef USER
30 #define DEBUGGER(x) debugger x
31 #else
32 #define DEBUGGER(x) kernel_debugger x
33 #endif
34 #else
35 #define DEBUGGER(x) ;
36 #endif
37 
38 #ifdef USER
39 #define DIE(x) debugger x
40 #else
41 #define DIE(x) kernel_debugger x
42 #endif
43 
44 // Short overview over the debug output macros:
45 //	PRINT()
46 //		is for general messages that very unlikely should appear in a release build
47 //	FATAL()
48 //		this is for fatal messages, when something has really gone wrong
49 //	INFORM()
50 //		general information, as disk size, etc.
51 //	REPORT_ERROR(status_t)
52 //		prints out error information
53 //	RETURN_ERROR(status_t)
54 //		calls REPORT_ERROR() and return the value
55 //	D()
56 //		the statements in D() are only included if DEBUG is defined
57 
58 #if DEBUG
59 #define PRINT(...) \
60 	{ \
61 		__out("fat[%" B_PRId32 "]: ", find_thread(NULL)); \
62 		__out(__VA_ARGS__); \
63 	}
64 #define REPORT_ERROR(status) \
65 	__out("fat[%" B_PRId32 "]: %s:%d: %s\n", find_thread(NULL), __FUNCTION__, __LINE__, \
66 		strerror(status));
67 #define RETURN_ERROR(err) \
68 	{ \
69 		status_t _status = err; \
70 		if (_status < B_OK) \
71 			REPORT_ERROR(_status); \
72 		return _status; \
73 	}
74 #define FATAL(x) \
75 	{ \
76 		__out("fat[%" B_PRId32 "]: ", find_thread(NULL)); \
77 		__out x; \
78 	}
79 #define INFORM(...) \
80 	{ \
81 		__out("fat[%" B_PRId32 "]: ", find_thread(NULL)); \
82 		__out(__VA_ARGS__); \
83 	}
84 #define FUNCTION() __out("fat[%" B_PRId32 "]: %s()\n", find_thread(NULL), __FUNCTION__);
85 #define FUNCTION_START(...) \
86 	{ \
87 		__out("fat[%" B_PRId32 "]: %s() ", find_thread(NULL), __FUNCTION__); \
88 		__out(__VA_ARGS__); \
89 	}
90 #define D(x) \
91 	{ \
92 		x; \
93 	};
94 #else // !DEBUG
95 #define PRINT(...) ;
96 #define REPORT_ERROR(status) \
97 	__out("fat[%" B_PRId32 "]: %s:%d: %s\n", find_thread(NULL), __FUNCTION__, __LINE__, \
98 		strerror(status));
99 #define RETURN_ERROR(err) \
100 	{ \
101 		return err; \
102 	}
103 #define FATAL(x) \
104 	{ \
105 		__out("fat[%" B_PRId32 "]: ", find_thread(NULL)); \
106 		__out x; \
107 	}
108 #define INFORM(...) \
109 	{ \
110 		__out("fat[%" B_PRId32 "]: ", find_thread(NULL)); \
111 		__out(__VA_ARGS__); \
112 	}
113 #define FUNCTION() ;
114 #define FUNCTION_START(...) ;
115 #define D(x) ;
116 #endif // !DEBUG
117 
118 int kprintf_volume(int argc, char** argv);
119 status_t dprintf_volume(struct mount* bsdVolume);
120 int kprintf_node(int argc, char** argv);
121 status_t dprintf_node(struct vnode* bsdNode);
122 status_t dprintf_winentry(struct msdosfsmount* fatVolume, struct winentry* entry,
123 	const uint32* index);
124 
125 
126 #endif // FAT_DEBUG_H
127