mirror of
https://github.com/versity/scoutfs.git
synced 2026-01-10 05:37:25 +00:00
dev.c includes linux/fs.h which includes linux/types.h, which defines these types, __be16 etc. These are also defined in sparse.h, but I don't think these are needed. Definitions in linux/types.h includes stuff to set attr(bitwise) if __CHECKER__ is defined, so we can remove __sp_biwise. Signed-off-by: Andy Grover <agrover@versity.com>
113 lines
2.9 KiB
C
113 lines
2.9 KiB
C
#ifndef _SPARSE_H_
|
|
#define _SPARSE_H_
|
|
|
|
#include <endian.h>
|
|
#include <stdint.h>
|
|
#include <linux/types.h>
|
|
|
|
#ifdef __CHECKER__
|
|
# undef __force
|
|
# define __force __attribute__((force))
|
|
/* sparse seems to get confused by some builtins */
|
|
extern int __builtin_ia32_rdrand64_step(unsigned long long *);
|
|
extern unsigned int __builtin_ia32_crc32di(unsigned int, unsigned long long);
|
|
extern unsigned int __builtin_ia32_crc32si(unsigned int, unsigned int);
|
|
extern unsigned int __builtin_ia32_crc32hi(unsigned int, unsigned short);
|
|
extern unsigned int __builtin_ia32_crc32qi(unsigned int, unsigned char);
|
|
|
|
#else
|
|
# define __force
|
|
#endif
|
|
|
|
typedef unsigned char u8;
|
|
typedef unsigned short u16;
|
|
typedef unsigned int u32;
|
|
typedef int s32;
|
|
typedef unsigned long long u64;
|
|
typedef signed long long s64;
|
|
|
|
typedef u8 __u8;
|
|
typedef u16 __u16;
|
|
typedef u32 __u32;
|
|
typedef s32 __s32;
|
|
typedef u64 __u64;
|
|
typedef s64 __s64;
|
|
|
|
static inline u16 ___swab16(u16 x)
|
|
{
|
|
return ((x & (u16)0x00ffU) << 8) |
|
|
((x & (u16)0xff00U) >> 8);
|
|
}
|
|
|
|
static inline u32 ___swab32(u32 x)
|
|
{
|
|
return ((x & (u32)0x000000ffUL) << 24) |
|
|
((x & (u32)0x0000ff00UL) << 8) |
|
|
((x & (u32)0x00ff0000UL) >> 8) |
|
|
((x & (u32)0xff000000UL) >> 24);
|
|
}
|
|
|
|
static inline u64 ___swab64(u64 x)
|
|
{
|
|
return (u64)((x & (u64)0x00000000000000ffULL) << 56) |
|
|
(u64)((x & (u64)0x000000000000ff00ULL) << 40) |
|
|
(u64)((x & (u64)0x0000000000ff0000ULL) << 24) |
|
|
(u64)((x & (u64)0x00000000ff000000ULL) << 8) |
|
|
(u64)((x & (u64)0x000000ff00000000ULL) >> 8) |
|
|
(u64)((x & (u64)0x0000ff0000000000ULL) >> 24) |
|
|
(u64)((x & (u64)0x00ff000000000000ULL) >> 40) |
|
|
(u64)((x & (u64)0xff00000000000000ULL) >> 56);
|
|
}
|
|
|
|
#define __gen_cast_tofrom(end, size) \
|
|
static inline __##end##size cpu_to_##end##size(u##size x) \
|
|
{ \
|
|
return (__force __##end##size)x; \
|
|
} \
|
|
static inline u##size end##size##_to_cpu(__##end##size x) \
|
|
{ \
|
|
return (__force u##size)x; \
|
|
}
|
|
|
|
#define __gen_swap_tofrom(end, size) \
|
|
static inline __##end##size cpu_to_##end##size(u##size x) \
|
|
{ \
|
|
return (__force __##end##size)___swab##size(x); \
|
|
} \
|
|
static inline u##size end##size##_to_cpu(__##end##size x) \
|
|
{ \
|
|
return ___swab##size((__force u##size) x); \
|
|
}
|
|
|
|
#define __gen_functions(which, end) \
|
|
__gen_##which##_tofrom(end, 16) \
|
|
__gen_##which##_tofrom(end, 32) \
|
|
__gen_##which##_tofrom(end, 64)
|
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
#define __LITTLE_ENDIAN_BITFIELD
|
|
__gen_functions(swap, be)
|
|
__gen_functions(cast, le)
|
|
#elif __BYTE_ORDER == __BIG_ENDIAN
|
|
#define __BIG_ENDIAN_BITFIELD
|
|
__gen_functions(swap, le)
|
|
__gen_functions(cast, be)
|
|
#else
|
|
#error "machine is neither BIG_ENDIAN nor LITTLE_ENDIAN"
|
|
#endif
|
|
|
|
#define __gen_add_funcs(end, size) \
|
|
static inline void end##size##_add_cpu(__##end##size *val, u##size delta) \
|
|
{ \
|
|
*val = cpu_to_##end##size(end##size##_to_cpu(*val) + delta); \
|
|
}
|
|
|
|
__gen_add_funcs(le, 16)
|
|
__gen_add_funcs(le, 32)
|
|
__gen_add_funcs(le, 64)
|
|
__gen_add_funcs(be, 16)
|
|
__gen_add_funcs(be, 32)
|
|
__gen_add_funcs(be, 64)
|
|
|
|
#endif
|