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