Line data Source code
1 : #ifndef __LINUX_TYPES_H__
2 : #define __LINUX_TYPES_H__
3 :
4 : #include <linux/types.h>
5 : #include <sys/types.h>
6 : #include <byteswap.h>
7 : #include <stdint.h>
8 :
9 : #include "compiler_attributes.h"
10 :
11 : typedef __u8 u8;
12 : typedef __u16 u16;
13 : typedef __u32 u32;
14 : typedef __u64 u64;
15 :
16 : typedef __s64 time64_t;
17 :
18 : struct qstr {
19 : const char *name;
20 : size_t len;
21 : };
22 :
23 : struct fscrypt_name {
24 : struct qstr disk_name;
25 : };
26 :
27 : #define fname_name(p) ((p)->disk_name.name)
28 : #define fname_len(p) ((p)->disk_name.len)
29 :
30 : #define S_IRUGO (S_IRUSR|S_IRGRP|S_IROTH)
31 : #define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)
32 :
33 : #define t16(x) ({ \
34 : uint16_t __b = (x); \
35 : (__LITTLE_ENDIAN==__BYTE_ORDER) ? __b : bswap_16(__b); \
36 : })
37 :
38 : #define t32(x) ({ \
39 : uint32_t __b = (x); \
40 : (__LITTLE_ENDIAN==__BYTE_ORDER) ? __b : bswap_32(__b); \
41 : })
42 :
43 : #define t64(x) ({ \
44 : uint64_t __b = (x); \
45 : (__LITTLE_ENDIAN==__BYTE_ORDER) ? __b : bswap_64(__b); \
46 : })
47 :
48 : #define cpu_to_le16(x) ((__le16){t16(x)})
49 : #define cpu_to_le32(x) ((__le32){t32(x)})
50 : #define cpu_to_le64(x) ((__le64){t64(x)})
51 :
52 : #define le16_to_cpu(x) (t16((x)))
53 : #define le32_to_cpu(x) (t32((x)))
54 : #define le64_to_cpu(x) (t64((x)))
55 :
56 : #define check_mul_overflow(a, b, d) ({ \
57 : typeof(a) __a = (a); \
58 : typeof(b) __b = (b); \
59 : typeof(d) __d = (d); \
60 : (void) (&__a == &__b); \
61 : (void) (&__a == __d); \
62 : __builtin_mul_overflow(__a, __b, __d); \
63 : })
64 :
65 : static inline __must_check size_t array_size(size_t a, size_t b)
66 : {
67 : size_t bytes;
68 5208 : if (check_mul_overflow(a, b, &bytes))
69 : return SIZE_MAX;
70 :
71 : return bytes;
72 : }
73 :
74 : #endif
|