Reorder extent back refs to differentiate file data from btree blocks
[btrfs-progs-unstable.git] / kerncompat.h
blob18f508f32ea88b493ca9d58b133e4c8fa623dfda
1 /*
2 * Copyright (C) 2007 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
19 #ifndef __KERNCOMPAT
20 #define __KERNCOMPAT
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <errno.h>
24 #include <string.h>
25 #include <endian.h>
26 #include <byteswap.h>
28 #define gfp_t int
29 #define get_cpu_var(p) (p)
30 #define __get_cpu_var(p) (p)
31 #define BITS_PER_LONG (sizeof(long) * 8)
32 #define __GFP_BITS_SHIFT 20
33 #define __GFP_BITS_MASK ((int)((1 << __GFP_BITS_SHIFT) - 1))
34 #define GFP_KERNEL 0
35 #define GFP_NOFS 0
36 #define __read_mostly
37 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
38 #define ULONG_MAX (~0UL)
39 #define BUG() abort()
40 #ifdef __CHECKER__
41 #define __force __attribute__((force))
42 #define __bitwise__ __attribute__((bitwise))
43 #else
44 #define __force
45 #define __bitwise__
46 #endif
48 #ifndef __CHECKER__
49 #include <asm/types.h>
50 typedef __u32 u32;
51 typedef __u64 u64;
52 typedef __u16 u16;
53 typedef __u8 u8;
54 #else
55 typedef unsigned int u32;
56 typedef unsigned int __u32;
57 typedef unsigned long long u64;
58 typedef unsigned char u8;
59 typedef unsigned short u16;
60 #endif
63 struct vma_shared { int prio_tree_node; };
64 struct vm_area_struct {
65 unsigned long vm_pgoff;
66 unsigned long vm_start;
67 unsigned long vm_end;
68 struct vma_shared shared;
70 struct page {
71 unsigned long index;
74 #define preempt_enable() do { } while (0)
75 #define preempt_disable() do { } while (0)
77 #define BITOP_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
78 #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
80 /**
81 * __set_bit - Set a bit in memory
82 * @nr: the bit to set
83 * @addr: the address to start counting from
85 * Unlike set_bit(), this function is non-atomic and may be reordered.
86 * If it's called on the same region of memory simultaneously, the effect
87 * may be that only one operation succeeds.
89 static inline void __set_bit(int nr, volatile unsigned long *addr)
91 unsigned long mask = BITOP_MASK(nr);
92 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
94 *p |= mask;
97 static inline void __clear_bit(int nr, volatile unsigned long *addr)
99 unsigned long mask = BITOP_MASK(nr);
100 unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr);
102 *p &= ~mask;
106 * test_bit - Determine whether a bit is set
107 * @nr: bit number to test
108 * @addr: Address to start counting from
110 static inline int test_bit(int nr, const volatile unsigned long *addr)
112 return 1UL & (addr[BITOP_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
115 #define BUG_ON(c) do { if (c) abort(); } while (0)
117 #undef offsetof
118 #ifdef __compiler_offsetof
119 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
120 #else
121 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
122 #endif
124 #define container_of(ptr, type, member) ({ \
125 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
126 (type *)( (char *)__mptr - offsetof(type,member) );})
127 #ifdef __CHECKER__
128 #define __CHECK_ENDIAN__
129 #define __bitwise __bitwise__
130 #else
131 #define __bitwise
132 #endif
134 typedef u16 __bitwise __le16;
135 typedef u16 __bitwise __be16;
136 typedef u32 __bitwise __le32;
137 typedef u32 __bitwise __be32;
138 typedef u64 __bitwise __le64;
139 typedef u64 __bitwise __be64;
141 /* Macros to generate set/get funcs for the struct fields
142 * assume there is a lefoo_to_cpu for every type, so lets make a simple
143 * one for u8:
145 #define le8_to_cpu(v) (v)
146 #define cpu_to_le8(v) (v)
147 #define __le8 u8
149 #if __BYTE_ORDER == __BIG_ENDIAN
150 #define cpu_to_le64(x) ((__force __le64)(u64)(bswap_64(x)))
151 #define le64_to_cpu(x) ((__force u64)(__le64)(bswap_64(x)))
152 #define cpu_to_le32(x) ((__force __le32)(u32)(bswap_32(x)))
153 #define le32_to_cpu(x) ((__force u32)(__le32)(bswap_32(x)))
154 #define cpu_to_le16(x) ((__force __le16)(u16)(bswap_16(x)))
155 #define le16_to_cpu(x) ((__force u16)(__le16)(bswap_16(x)))
156 #else
157 #define cpu_to_le64(x) ((__force __le64)(u64)(x))
158 #define le64_to_cpu(x) ((__force u64)(__le64)(x))
159 #define cpu_to_le32(x) ((__force __le32)(u32)(x))
160 #define le32_to_cpu(x) ((__force u32)(__le32)(x))
161 #define cpu_to_le16(x) ((__force __le16)(u16)(x))
162 #define le16_to_cpu(x) ((__force u16)(__le16)(x))
163 #endif
164 #endif