]> git.proxmox.com Git - mirror_spl-debian.git/blob - include/sys/sysmacros.h
Add the initial vestigates of vnode support
[mirror_spl-debian.git] / include / sys / sysmacros.h
1 #ifndef _SPL_SYSMACROS_H
2 #define _SPL_SYSMACROS_H
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include <linux/module.h>
9
10 #ifndef _KERNEL
11 #define _KERNEL __KERNEL__
12 #endif
13
14 /* Missing defines.
15 */
16 #define FALSE 0
17 #define TRUE 1
18
19 #define INT32_MAX INT_MAX
20 #define INT32_MIN INT_MIN
21 #define UINT32_MAX UINT_MAX
22 #define UINT32_MIN UINT_MIN
23 #define INT64_MAX LLONG_MAX
24 #define INT64_MIN LLONG_MIN
25 #define UINT64_MAX ULLONG_MAX
26 #define UINT64_MIN ULLONG_MIN
27
28 #define NBBY 8
29 #define ENOTSUP ENOTSUPP
30
31 #define MAXNAMELEN 256
32 #define MAXPATHLEN PATH_MAX
33 #define MAXOFFSET_T 0x7fffffffffffffffl
34
35 #define MAXBSIZE 8192
36 #define DEV_BSIZE 512
37 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
38
39 #define __va_list va_list
40 #define max_ncpus 64
41 #define _NOTE(x)
42
43 /* 0..MAX_PRIO-1: Process priority
44 * 0..MAX_RT_PRIO-1: RT priority tasks
45 * MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks
46 *
47 * Treat shim tasks as SCHED_NORMAL tasks
48 */
49 #define minclsyspri (MAX_RT_PRIO)
50 #define maxclsyspri (MAX_PRIO-1)
51
52 #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
53 #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
54
55 #define kred NULL
56
57 #define FREAD 1
58 #define FWRITE 2
59 #define FCREAT O_CREAT
60 #define FTRUNC O_TRUNC
61 #define FOFFMAX O_LARGEFILE
62 #define FSYNC O_SYNC
63 #define FDSYNC O_DSYNC
64 #define FRSYNC O_RSYNC
65 #define FEXCL O_EXCL
66
67 #define FNODSYNC 0x10000 /* fsync pseudo flag */
68 #define FNOFOLLOW 0x20000 /* don't follow symlinks */
69
70 /* Missing macros
71 */
72 #define PAGESIZE PAGE_SIZE
73
74 /* from Solaris sys/byteorder.h */
75 #define BSWAP_8(x) ((x) & 0xff)
76 #define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8))
77 #define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16))
78 #define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32))
79
80 /* Map some simple functions.
81 */
82 #define bzero(ptr,size) memset(ptr,0,size)
83 #define bcopy(src,dest,size) memcpy(dest,src,size)
84 #define bcmp(src,dest,size) memcmp((src), (dest), (size_t)(size))
85 #define ASSERT(x) BUG_ON(!(x))
86 #define VERIFY(x) ASSERT(x)
87
88 #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
89 const TYPE __left = (TYPE)(LEFT); \
90 const TYPE __right = (TYPE)(RIGHT); \
91 if (!(__left OP __right)) \
92 BUG(); \
93 } while (0)
94
95 #define VERIFY3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t)
96 #define VERIFY3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t)
97 #define VERIFY3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t)
98
99 #define ASSERT3S(x, y, z) VERIFY3S(x, y, z)
100 #define ASSERT3U(x, y, z) VERIFY3U(x, y, z)
101 #define ASSERT3P(x, y, z) VERIFY3P(x, y, z)
102
103 /* Dtrace probes do not exist in the linux kernel */
104
105 #ifdef DTRACE_PROBE1
106 #undef DTRACE_PROBE1
107 #endif /* DTRACE_PROBE1 */
108 #define DTRACE_PROBE1(a, b, c) ((void)0)
109
110 #ifdef DTRACE_PROBE2
111 #undef DTRACE_PROBE2
112 #endif /* DTRACE_PROBE2 */
113 #define DTRACE_PROBE2(a, b, c, d, e) ((void)0)
114
115 #ifdef DTRACE_PROBE3
116 #undef DTRACE_PROBE3
117 #endif /* DTRACE_PROBE3 */
118 #define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0)
119
120 #ifdef DTRACE_PROBE4
121 #undef DTRACE_PROBE4
122 #endif /* DTRACE_PROBE4 */
123 #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0)
124
125 /* Missing globals */
126 extern int p0;
127
128 /* Missing misc functions */
129 extern int highbit(unsigned long i);
130
131 #define makedevice(maj,min) makedev(maj,min)
132 #define zone_dataset_visible(x, y) (1)
133 #define INGLOBALZONE(z) (1)
134 #define utsname system_utsname
135
136 /* XXX - Borrowed from zfs project libsolcompat/include/sys/sysmacros.h */
137 /* common macros */
138 #ifndef MIN
139 #define MIN(a, b) ((a) < (b) ? (a) : (b))
140 #endif
141 #ifndef MAX
142 #define MAX(a, b) ((a) < (b) ? (b) : (a))
143 #endif
144 #ifndef ABS
145 #define ABS(a) ((a) < 0 ? -(a) : (a))
146 #endif
147
148 /*
149 * Compatibility macros/typedefs needed for Solaris -> Linux port
150 */
151 #define P2ALIGN(x, align) ((x) & -(align))
152 #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
153 #define P2ROUNDUP(x, align) (-(-(x) & -(align)))
154 #define P2ROUNDUP_TYPED(x, align, type) \
155 (-(-(type)(x) & -(type)(align)))
156 #define P2PHASE(x, align) ((x) & ((align) - 1))
157 #define P2NPHASE(x, align) (-(x) & ((align) - 1))
158 #define P2NPHASE_TYPED(x, align, type) \
159 (-(type)(x) & ((type)(align) - 1))
160 #define ISP2(x) (((x) & ((x) - 1)) == 0)
161 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
162
163 /*
164 * Typed version of the P2* macros. These macros should be used to ensure
165 * that the result is correctly calculated based on the data type of (x),
166 * which is passed in as the last argument, regardless of the data
167 * type of the alignment. For example, if (x) is of type uint64_t,
168 * and we want to round it up to a page boundary using "PAGESIZE" as
169 * the alignment, we can do either
170 * P2ROUNDUP(x, (uint64_t)PAGESIZE)
171 * or
172 * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
173 */
174 #define P2ALIGN_TYPED(x, align, type) \
175 ((type)(x) & -(type)(align))
176 #define P2PHASE_TYPED(x, align, type) \
177 ((type)(x) & ((type)(align) - 1))
178 #define P2NPHASE_TYPED(x, align, type) \
179 (-(type)(x) & ((type)(align) - 1))
180 #define P2ROUNDUP_TYPED(x, align, type) \
181 (-(-(type)(x) & -(type)(align)))
182 #define P2END_TYPED(x, align, type) \
183 (-(~(type)(x) & -(type)(align)))
184 #define P2PHASEUP_TYPED(x, align, phase, type) \
185 ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
186 #define P2CROSS_TYPED(x, y, align, type) \
187 (((type)(x) ^ (type)(y)) > (type)(align) - 1)
188 #define P2SAMEHIGHBIT_TYPED(x, y, type) \
189 (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
190
191 #if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof)
192
193 /* avoid any possibility of clashing with <stddef.h> version */
194
195 #define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
196 #endif
197
198 #ifdef __cplusplus
199 }
200 #endif
201
202 #endif /* _SPL_SYSMACROS_H */