xref: /freebsd/sbin/growfs/debug.h (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1 /*-
2  * SPDX-License-Identifier: BSD-4-Clause
3  *
4  * Copyright (c) 2000 Christoph Herrmann, Thomas-Henning von Kamptz
5  * Copyright (c) 1980, 1989, 1993 The Regents of the University of California.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * Christoph Herrmann and Thomas-Henning von Kamptz, Munich and Frankfurt.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgment:
21  *      This product includes software developed by the University of
22  *      California, Berkeley and its contributors, as well as Christoph
23  *      Herrmann and Thomas-Henning von Kamptz.
24  * 4. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  * $TSHeader: src/sbin/growfs/debug.h,v 1.2 2000/11/16 18:43:50 tom Exp $
41  * $FreeBSD$
42  *
43  */
44 
45 #ifdef FS_DEBUG
46 
47 /* ********************************************************** INCLUDES ***** */
48 #include <sys/param.h>
49 
50 #include <ufs/ufs/dinode.h>
51 #include <ufs/ffs/fs.h>
52 
53 void dbg_open(const char *);
54 void dbg_close(void);
55 void dbg_dump_hex(struct fs *, const char *, unsigned char *);
56 void dbg_dump_fs(struct fs *, const char *);
57 void dbg_dump_cg(const char *, struct cg *);
58 void dbg_dump_csum(const char *, struct csum *);
59 void dbg_dump_csum_total(const char *, struct csum_total *);
60 void dbg_dump_ufs1_ino(struct fs *, const char *, struct ufs1_dinode *);
61 void dbg_dump_ufs2_ino(struct fs *, const char *, struct ufs2_dinode *);
62 void dbg_dump_iblk(struct fs *, const char *, char *, size_t);
63 void dbg_dump_inmap(struct fs *, const char *, struct cg *);
64 void dbg_dump_frmap(struct fs *, const char *, struct cg *);
65 void dbg_dump_clmap(struct fs *, const char *, struct cg *);
66 void dbg_dump_clsum(struct fs *, const char *, struct cg *);
67 void dbg_dump_sptbl(struct fs *, const char *, struct cg *);
68 
69 #define DBG_OPEN(P) dbg_open((P))
70 #define DBG_CLOSE dbg_close()
71 #define DBG_DUMP_HEX(F,C,M) dbg_dump_hex((F),(C),(M))
72 #define DBG_DUMP_FS(F,C) dbg_dump_fs((F),(C))
73 #define DBG_DUMP_CG(F,C,M) dbg_dump_cg((C),(M))
74 #define DBG_DUMP_CSUM(F,C,M) dbg_dump_csum((C),(M))
75 #define DBG_DUMP_INO(F,C,M) (F)->fs_magic == FS_UFS1_MAGIC \
76 	? dbg_dump_ufs1_ino((F),(C),(struct ufs1_dinode *)(M)) \
77 	: dbg_dump_ufs2_ino((F),(C),(struct ufs2_dinode *)(M))
78 #define DBG_DUMP_IBLK(F,C,M,L) dbg_dump_iblk((F),(C),(M),(L))
79 #define DBG_DUMP_INMAP(F,C,M) dbg_dump_inmap((F),(C),(M))
80 #define DBG_DUMP_FRMAP(F,C,M) dbg_dump_frmap((F),(C),(M))
81 #define DBG_DUMP_CLMAP(F,C,M) dbg_dump_clmap((F),(C),(M))
82 #define DBG_DUMP_CLSUM(F,C,M) dbg_dump_clsum((F),(C),(M))
83 #ifdef NOT_CURRENTLY
84 #define DBG_DUMP_SPTBL(F,C,M) dbg_dump_sptbl((F),(C),(M))
85 #endif
86 
87 #define DL_TRC	0x01
88 #define DL_INFO	0x02
89 extern int _dbg_lvl_;
90 
91 #define DBG_FUNC(N) char __FKT__[] = {N};
92 #define DBG_ENTER if(_dbg_lvl_ & DL_TRC) {                                    \
93 	fprintf(stderr, "~>%s: %s\n", __FILE__, __FKT__ );                    \
94 	}
95 #define DBG_LEAVE if(_dbg_lvl_ & DL_TRC) {                                    \
96 	fprintf(stderr, "~<%s[%d]: %s\n", __FILE__, __LINE__, __FKT__ );      \
97 	}
98 #define DBG_TRC if(_dbg_lvl_ & DL_TRC) {                                      \
99 	fprintf(stderr, "~=%s[%d]: %s\n", __FILE__, __LINE__, __FKT__ );      \
100 	}
101 #define DBG_PRINT0(A) if(_dbg_lvl_ & DL_INFO) {                               \
102 	fprintf(stderr, "~ %s", (A));                                         \
103 	}
104 #define DBG_PRINT1(A,B) if(_dbg_lvl_ & DL_INFO) {                             \
105 	fprintf(stderr, "~ ");                                                \
106 	fprintf(stderr, (A), (B));                                            \
107 	}
108 #define DBG_PRINT2(A,B,C) if(_dbg_lvl_ & DL_INFO) {                           \
109 	fprintf(stderr, "~ ");                                                \
110 	fprintf(stderr, (A), (B), (C));                                       \
111 	}
112 #define DBG_PRINT3(A,B,C,D) if(_dbg_lvl_ & DL_INFO) {                         \
113 	fprintf(stderr, "~ ");                                                \
114 	fprintf(stderr, (A), (B), (C), (D));                                  \
115 	}
116 #define DBG_PRINT4(A,B,C,D,E) if(_dbg_lvl_ & DL_INFO) {                       \
117 	fprintf(stderr, "~ ");                                                \
118 	fprintf(stderr, (A), (B), (C), (D), (E));                             \
119 	}
120 #else /* not FS_DEBUG */
121 
122 #define DBG_OPEN(P)
123 #define DBG_CLOSE
124 #define DBG_DUMP_HEX(F,C,M)
125 #define DBG_DUMP_FS(F,C)
126 #define DBG_DUMP_CG(F,C,M)
127 #define DBG_DUMP_CSUM(F,C,M)
128 #define DBG_DUMP_INO(F,C,M)
129 #define DBG_DUMP_IBLK(F,C,M,L)
130 #define DBG_DUMP_INMAP(F,C,M)
131 #define DBG_DUMP_FRMAP(F,C,M)
132 #define DBG_DUMP_CLMAP(F,C,M)
133 #define DBG_DUMP_CLSUM(F,C,M)
134 #define DBG_DUMP_SPTBL(F,C,M)
135 #define DBG_FUNC(N)
136 #define DBG_ENTER
137 #define DBG_TRC
138 #define DBG_LEAVE
139 #define DBG_PRINT0(A)
140 #define DBG_PRINT1(A,B)
141 #define DBG_PRINT2(A,B,C)
142 #define DBG_PRINT3(A,B,C,D)
143 #define DBG_PRINT4(A,B,C,D,E)
144 
145 #endif /* FS_DEBUG */
146