2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public
4 * License v2 as published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 * General Public License for more details.
11 * You should have received a copy of the GNU General Public
12 * License along with this program; if not, write to the
13 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14 * Boston, MA 021110-1307, USA.
17 #ifndef __BTRFS_MESSAGES_H__
18 #define __BTRFS_MESSAGES_H__
20 #ifdef DEBUG_VERBOSE_ERROR
21 #define PRINT_VERBOSE_ERROR fprintf(stderr, "%s:%d:", __FILE__, __LINE__)
23 #define PRINT_VERBOSE_ERROR
26 #ifdef DEBUG_TRACE_ON_ERROR
27 #define PRINT_TRACE_ON_ERROR print_trace()
29 #define PRINT_TRACE_ON_ERROR
32 #ifdef DEBUG_ABORT_ON_ERROR
33 #define DO_ABORT_ON_ERROR abort()
35 #define DO_ABORT_ON_ERROR
38 #define error(fmt, ...) \
40 PRINT_TRACE_ON_ERROR; \
41 PRINT_VERBOSE_ERROR; \
42 __btrfs_error((fmt), ##__VA_ARGS__); \
46 #define error_on(cond, fmt, ...) \
49 PRINT_TRACE_ON_ERROR; \
51 PRINT_VERBOSE_ERROR; \
52 __btrfs_error_on((cond), (fmt), ##__VA_ARGS__); \
57 #define error_btrfs_util(err) \
59 const char *errno_str = strerror(errno); \
60 const char *lib_str = btrfs_util_strerror(err); \
61 PRINT_TRACE_ON_ERROR; \
62 PRINT_VERBOSE_ERROR; \
63 if (lib_str && strcmp(errno_str, lib_str) != 0) \
64 __btrfs_error("%s: %s", lib_str, errno_str); \
66 __btrfs_error("%s", errno_str); \
70 #define warning(fmt, ...) \
72 PRINT_TRACE_ON_ERROR; \
73 PRINT_VERBOSE_ERROR; \
74 __btrfs_warning((fmt), ##__VA_ARGS__); \
77 #define warning_on(cond, fmt, ...) \
80 PRINT_TRACE_ON_ERROR; \
82 PRINT_VERBOSE_ERROR; \
83 __btrfs_warning_on((cond), (fmt), ##__VA_ARGS__); \
86 __attribute__ ((format (printf, 1, 2)))
87 void __btrfs_warning(const char *fmt, ...);
89 __attribute__ ((format (printf, 1, 2)))
90 void __btrfs_error(const char *fmt, ...);
92 __attribute__ ((format (printf, 2, 3)))
93 int __btrfs_warning_on(int condition, const char *fmt, ...);
95 __attribute__ ((format (printf, 2, 3)))
96 int __btrfs_error_on(int condition, const char *fmt, ...);