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