OLD | NEW |
1 /* Copyright (C) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (C) 2010 The Chromium OS Authors. All rights reserved. |
2 * Use of this source code is governed by the GPL v2 license that can | 2 * Use of this source code is governed by the GPL v2 license that can |
3 * be found in the LICENSE file. | 3 * be found in the LICENSE file. |
4 * | 4 * |
5 * Parts of this file are derived from the Linux kernel from the file with | 5 * Parts of this file are derived from the Linux kernel from the file with |
6 * the same name and path under include/. | 6 * the same name and path under include/. |
7 */ | 7 */ |
8 #ifndef VERITY_INCLUDE_LINUX_KERNEL_H_ | 8 #ifndef VERITY_INCLUDE_LINUX_KERNEL_H_ |
9 #define VERITY_INCLUDE_LINUX_KERNEL_H_ | 9 #define VERITY_INCLUDE_LINUX_KERNEL_H_ |
10 /* Pull in _MAX defines */ | 10 /* Pull in _MAX defines */ |
11 #include <limits.h> | 11 #include <limits.h> |
12 #include <stdint.h> | 12 #include <stdint.h> |
13 | 13 |
14 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) | 14 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) |
15 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) | 15 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) |
16 #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) | 16 #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) |
17 | 17 |
| 18 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
| 19 |
18 #define sector_div(n, b) ({ \ | 20 #define sector_div(n, b) ({ \ |
19 int _res; \ | 21 int _res; \ |
20 _res = (n) % (b); \ | 22 _res = (n) % (b); \ |
21 (n) /= (b); \ | 23 (n) /= (b); \ |
22 _res; \ | 24 _res; \ |
23 }) | 25 }) |
24 | 26 |
25 #define min(x, y) ({ \ | 27 #define min(x, y) ({ \ |
26 typeof(x) _min1 = (x); \ | 28 typeof(x) _min1 = (x); \ |
27 typeof(y) _min2 = (y); \ | 29 typeof(y) _min2 = (y); \ |
28 (void) (&_min1 == &_min2); \ | 30 (void) (&_min1 == &_min2); \ |
29 _min1 < _min2 ? _min1 : _min2; }) | 31 _min1 < _min2 ? _min1 : _min2; }) |
30 | 32 |
31 #define max(x, y) ({ \ | 33 #define max(x, y) ({ \ |
32 typeof(x) _max1 = (x); \ | 34 typeof(x) _max1 = (x); \ |
33 typeof(y) _max2 = (y); \ | 35 typeof(y) _max2 = (y); \ |
34 (void) (&_max1 == &_max2); \ | 36 (void) (&_max1 == &_max2); \ |
35 _max1 > _max2 ? _max1 : _max2; }) | 37 _max1 > _max2 ? _max1 : _max2; }) |
36 | 38 |
37 | 39 |
38 #endif /* VERITY_INCLUDE_LINUX_KERNEL_H_ */ | 40 #endif /* VERITY_INCLUDE_LINUX_KERNEL_H_ */ |
OLD | NEW |