+ size = backtrace(array, MAX_BACKTRACE);
+ backtrace_symbols_fd(array, size, 2);
+}
+
+static inline void assert_trace(const char *assertion, const char *filename,
+ const char *func, unsigned line, int val)
+{
+ if (val)
+ return;
+ if (assertion)
+ fprintf(stderr, "%s:%d: %s: Assertion `%s` failed, value %d\n",
+ filename, line, func, assertion, val);
+ else
+ fprintf(stderr, "%s:%d: %s: Assertion failed, value %d.\n",
+ filename, line, func, val);
+ print_trace();
+ abort();
+ exit(1);
+}
+
+#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 0)
+#else
+#define BUG() assert(0)
+#endif
+
+static inline void warning_trace(const char *assertion, const char *filename,
+ const char *func, unsigned line, int val,
+ int trace)
+{
+ if (val)
+ return;
+ if (assertion)
+ fprintf(stderr,
+ "%s:%d: %s: Warning: assertion `%s` failed, value %d\n",
+ filename, line, func, assertion, val);
+ else
+ fprintf(stderr,
+ "%s:%d: %s: Warning: assertion failed, value %d.\n",
+ filename, line, func, val);
+#ifndef BTRFS_DISABLE_BACKTRACE
+ if (trace)
+ print_trace();
+#endif
+}
+
+
+#ifdef __CHECKER__
+#define __force __attribute__((force))
+#define __bitwise__ __attribute__((bitwise))
+#else
+#define __force
+#define __bitwise__
+#endif
+
+#ifndef __CHECKER__
+/*
+ * Since we're using primitive definitions from kernel-space, we need to
+ * define __KERNEL__ so that system header files know which definitions
+ * to use.
+ */
+#define __KERNEL__
+#include <asm/types.h>
+typedef __u32 u32;
+typedef __u64 u64;
+typedef __u16 u16;
+typedef __u8 u8;
+typedef __s64 s64;
+typedef __s32 s32;
+
+/*
+ * Continuing to define __KERNEL__ breaks others parts of the code, so
+ * we can just undefine it now that we have the correct headers...
+ */
+#undef __KERNEL__
+#else