add leaf data casting helper
[btrfs-progs-unstable.git] / kerncompat.h
blob56239b922ba654c80007be8b5a669930d5c50500
1 #ifndef __KERNCOMPAT
2 #define __KERNCOMPAT
3 #define gfp_t int
4 #define get_cpu_var(p) (p)
5 #define __get_cpu_var(p) (p)
6 #define BITS_PER_LONG 64
7 #define __GFP_BITS_SHIFT 20
8 #define __GFP_BITS_MASK ((int)((1 << __GFP_BITS_SHIFT) - 1))
9 #define GFP_KERNEL 0
10 #define __read_mostly
11 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
12 #define PAGE_SHIFT 12
13 #define ULONG_MAX (~0UL)
14 #define BUG() abort()
15 #ifdef __CHECKER__
16 #define __force __attribute__((force))
17 #define __bitwise__ __attribute__((bitwise))
18 #else
19 #define __force
20 #define __bitwise__
21 #endif
23 typedef unsigned int u32;
24 typedef unsigned long long u64;
25 typedef unsigned char u8;
26 typedef unsigned short u16;
28 typedef unsigned long pgoff_t;
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
34 struct vma_shared { int prio_tree_node; };
35 struct vm_area_struct {
36 unsigned long vm_pgoff;
37 unsigned long vm_start;
38 unsigned long vm_end;
39 struct vma_shared shared;
42 struct page {
43 unsigned long index;
46 static inline void preempt_enable(void) { do {; } while(0);}
47 static inline void preempt_disable(void) { do {; } while(0);}
49 static inline void __set_bit(int bit, unsigned long *map) {
50 unsigned long *p = map + bit / BITS_PER_LONG;
51 bit = bit & (BITS_PER_LONG -1);
52 *p |= 1UL << bit;
55 static inline int test_bit(int bit, unsigned long *map) {
56 unsigned long *p = map + bit / BITS_PER_LONG;
57 bit = bit & (BITS_PER_LONG -1);
58 return *p & (1UL << bit) ? 1 : 0;
61 static inline void __clear_bit(int bit, unsigned long *map) {
62 unsigned long *p = map + bit / BITS_PER_LONG;
63 bit = bit & (BITS_PER_LONG -1);
64 *p &= ~(1UL << bit);
66 #define BUG_ON(c) do { if (c) abort(); } while (0)
68 #define container_of(ptr, type, member) ({ \
69 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
70 (type *)( (char *)__mptr - __builtin_offsetof(type,member) );})
72 #define ENOMEM 5
73 #define EEXIST 6
75 #define __CHECK_ENDIAN__
76 #ifdef __CHECK_ENDIAN__
77 #define __bitwise __bitwise__
78 #else
79 #define __bitwise
80 #endif
82 typedef u16 __bitwise __le16;
83 typedef u16 __bitwise __be16;
84 typedef u32 __bitwise __le32;
85 typedef u32 __bitwise __be32;
86 typedef u64 __bitwise __le64;
87 typedef u64 __bitwise __be64;
89 #define cpu_to_le64(x) ((__force __le64)(u64)(x))
90 #define le64_to_cpu(x) ((__force u64)(__le64)(x))
91 #define cpu_to_le32(x) ((__force __le32)(u32)(x))
92 #define le32_to_cpu(x) ((__force u32)(__le32)(x))
93 #define cpu_to_le16(x) ((__force __le16)(u16)(x))
94 #define le16_to_cpu(x) ((__force u16)(__le16)(x))
95 #endif