]> git.proxmox.com Git - mirror_spl.git/blob - include/sys/sysmacros.h
Give ENOTSUP a valid user space error value
[mirror_spl.git] / include / sys / sysmacros.h
1 /*****************************************************************************\
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
6 * UCRL-CODE-235197
7 *
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://github.com/behlendorf/spl/>.
10 *
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 \*****************************************************************************/
24
25 #ifndef _SPL_SYSMACROS_H
26 #define _SPL_SYSMACROS_H
27
28 #include <linux/module.h>
29 #include <linux/cpumask.h>
30 #include <sys/debug.h>
31 #include <sys/varargs.h>
32 #include <sys/zone.h>
33 #include <sys/signal.h>
34
35 #ifndef _KERNEL
36 #define _KERNEL __KERNEL__
37 #endif
38
39 #define FALSE 0
40 #define TRUE 1
41
42 #define INT8_MAX (127)
43 #define INT8_MIN (-128)
44 #define UINT8_MAX (255)
45 #define UINT8_MIN (0)
46
47 #define INT16_MAX (32767)
48 #define INT16_MIN (-32768)
49 #define UINT16_MAX (65535)
50 #define UINT16_MIN (0)
51
52 #define INT32_MAX INT_MAX
53 #define INT32_MIN INT_MIN
54 #define UINT32_MAX UINT_MAX
55 #define UINT32_MIN UINT_MIN
56
57 #define INT64_MAX LLONG_MAX
58 #define INT64_MIN LLONG_MIN
59 #define UINT64_MAX ULLONG_MAX
60 #define UINT64_MIN ULLONG_MIN
61
62 #define NBBY 8
63 #define ENOTSUP EOPNOTSUPP
64
65 #define MAXMSGLEN 256
66 #define MAXNAMELEN 256
67 #define MAXPATHLEN PATH_MAX
68
69 #ifdef _LP64
70 #define MAXOFFSET_T 0x7fffffffffffffffl
71 #else
72 #define MAXOFFSET_T 0x7fffffffl
73 #endif
74
75 #define MAXBSIZE 8192
76 #define DEV_BSIZE 512
77 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
78
79 #define proc_pageout NULL
80 #define curproc get_current()
81 #define max_ncpus num_possible_cpus()
82 #define CPU_SEQID smp_processor_id()
83 #define _NOTE(x)
84 #define is_system_labeled() 0
85
86 #ifndef RLIM64_INFINITY
87 #define RLIM64_INFINITY (~0ULL)
88 #endif
89
90 /* 0..MAX_PRIO-1: Process priority
91 * 0..MAX_RT_PRIO-1: RT priority tasks
92 * MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks
93 *
94 * Treat shim tasks as SCHED_NORMAL tasks
95 */
96 #define minclsyspri (MAX_RT_PRIO)
97 #define maxclsyspri (MAX_PRIO-1)
98
99 #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
100 #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
101
102 /* Missing macros
103 */
104 #define PAGESIZE PAGE_SIZE
105
106 /* from Solaris sys/byteorder.h */
107 #define BSWAP_8(x) ((x) & 0xff)
108 #define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8))
109 #define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16))
110 #define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32))
111
112 /* Map some simple functions.
113 */
114 #define bzero(ptr,size) memset(ptr,0,size)
115 #define bcopy(src,dest,size) memmove(dest,src,size)
116 #define bcmp(src,dest,size) memcmp((src), (dest), (size_t)(size))
117
118 /* Dtrace probes do not exist in the linux kernel */
119 #ifdef DTRACE_PROBE
120 #undef DTRACE_PROBE
121 #endif /* DTRACE_PROBE */
122 #define DTRACE_PROBE(a) ((void)0)
123
124 #ifdef DTRACE_PROBE1
125 #undef DTRACE_PROBE1
126 #endif /* DTRACE_PROBE1 */
127 #define DTRACE_PROBE1(a, b, c) ((void)0)
128
129 #ifdef DTRACE_PROBE2
130 #undef DTRACE_PROBE2
131 #endif /* DTRACE_PROBE2 */
132 #define DTRACE_PROBE2(a, b, c, d, e) ((void)0)
133
134 #ifdef DTRACE_PROBE3
135 #undef DTRACE_PROBE3
136 #endif /* DTRACE_PROBE3 */
137 #define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0)
138
139 #ifdef DTRACE_PROBE4
140 #undef DTRACE_PROBE4
141 #endif /* DTRACE_PROBE4 */
142 #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0)
143
144 /* Missing globals */
145 extern char spl_version[16];
146 extern long spl_hostid;
147 extern char hw_serial[11];
148
149 /* Missing misc functions */
150 extern int highbit(unsigned long i);
151 extern uint32_t zone_get_hostid(void *zone);
152 extern void spl_setup(void);
153 extern void spl_cleanup(void);
154
155 #define makedevice(maj,min) makedev(maj,min)
156
157 /* common macros */
158 #ifndef MIN
159 #define MIN(a, b) ((a) < (b) ? (a) : (b))
160 #endif
161 #ifndef MAX
162 #define MAX(a, b) ((a) < (b) ? (b) : (a))
163 #endif
164 #ifndef ABS
165 #define ABS(a) ((a) < 0 ? -(a) : (a))
166 #endif
167 #ifndef DIV_ROUND_UP
168 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
169 #endif
170 #ifndef roundup
171 #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
172 #endif
173
174 /*
175 * Compatibility macros/typedefs needed for Solaris -> Linux port
176 */
177 #define P2ALIGN(x, align) ((x) & -(align))
178 #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
179 #define P2ROUNDUP(x, align) (-(-(x) & -(align)))
180 #define P2PHASE(x, align) ((x) & ((align) - 1))
181 #define P2NPHASE(x, align) (-(x) & ((align) - 1))
182 #define ISP2(x) (((x) & ((x) - 1)) == 0)
183 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1))==0)
184 #define P2BOUNDARY(off, len, align) \
185 (((off) ^ ((off) + (len) - 1)) > (align) - 1)
186
187 /*
188 * Typed version of the P2* macros. These macros should be used to ensure
189 * that the result is correctly calculated based on the data type of (x),
190 * which is passed in as the last argument, regardless of the data
191 * type of the alignment. For example, if (x) is of type uint64_t,
192 * and we want to round it up to a page boundary using "PAGESIZE" as
193 * the alignment, we can do either
194 *
195 * P2ROUNDUP(x, (uint64_t)PAGESIZE)
196 * or
197 * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
198 */
199 #define P2ALIGN_TYPED(x, align, type) \
200 ((type)(x) & -(type)(align))
201 #define P2PHASE_TYPED(x, align, type) \
202 ((type)(x) & ((type)(align) - 1))
203 #define P2NPHASE_TYPED(x, align, type) \
204 (-(type)(x) & ((type)(align) - 1))
205 #define P2ROUNDUP_TYPED(x, align, type) \
206 (-(-(type)(x) & -(type)(align)))
207 #define P2END_TYPED(x, align, type) \
208 (-(~(type)(x) & -(type)(align)))
209 #define P2PHASEUP_TYPED(x, align, phase, type) \
210 ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
211 #define P2CROSS_TYPED(x, y, align, type) \
212 (((type)(x) ^ (type)(y)) > (type)(align) - 1)
213 #define P2SAMEHIGHBIT_TYPED(x, y, type) \
214 (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
215
216 #if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof)
217
218 /* avoid any possibility of clashing with <stddef.h> version */
219
220 #define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
221 #endif
222
223 #endif /* _SPL_SYSMACROS_H */