9 /* linux kernel style types: */
11 #include <asm/types.h>
12 #include <asm/byteorder.h>
24 #define cpu_to_le16 __cpu_to_le16
25 #define cpu_to_le32 __cpu_to_le32
26 #define cpu_to_le64 __cpu_to_le64
28 #define le16_to_cpu __le16_to_cpu
29 #define le32_to_cpu __le32_to_cpu
30 #define le64_to_cpu __le64_to_cpu
32 static inline void le16_add_cpu(__le16 *var, u16 val)
34 *var = cpu_to_le16(le16_to_cpu(*var) + val);
37 static inline void le32_add_cpu(__le32 *var, u32 val)
39 *var = cpu_to_le32(le32_to_cpu(*var) + val);
42 static inline void le64_add_cpu(__le64 *var, u64 val)
44 *var = cpu_to_le64(le64_to_cpu(*var) + val);
47 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
49 #define min(x, y) ({ \
50 typeof(x) _min1 = (x); \
51 typeof(y) _min2 = (y); \
52 (void) (&_min1 == &_min2); \
53 _min1 < _min2 ? _min1 : _min2; })
55 #define max(x, y) ({ \
56 typeof(x) _max1 = (x); \
57 typeof(y) _max2 = (y); \
58 (void) (&_max1 == &_max2); \
59 _max1 > _max2 ? _max1 : _max2; })
61 #define die(arg, ...) \
63 fprintf(stderr, arg "\n", ##__VA_ARGS__); \
67 u64 rounddown_pow_of_two(u64);
70 char *skip_spaces(const char *str);
79 struct units_buf pr_units(u64, enum units);
85 long strtoul_or_die(const char *, size_t, const char *);
87 u64 hatoi(const char *);
88 unsigned hatoi_validate(const char *, const char *);
89 unsigned nr_args(char * const *);
91 char *read_file_str(int, const char *);
92 u64 read_file_u64(int, const char *);
94 ssize_t read_string_list(const char *, const char * const[]);
95 ssize_t read_string_list_or_die(const char *, const char * const[],
97 void print_string_list(const char * const[], size_t);
99 u64 get_size(const char *, int);
100 unsigned get_blocksize(const char *, int);
102 #include "bcache-ondisk.h"
103 #include "bcache-ioctl.h"
105 u64 bch_checksum(unsigned, const void *, size_t);
107 #define __bkey_idx(_set, _offset) \
108 ((_set)->_data + (_offset))
110 #define __bset_bkey_last(_set) \
111 __bkey_idx((_set), (_set)->u64s)
113 #define __csum_set(i, u64s, type) \
115 const void *start = ((const void *) (i)) + sizeof(i->csum); \
116 const void *end = __bkey_idx(i, u64s); \
118 bch_checksum(type, start, end - start); \
121 #define csum_set(i, type) __csum_set(i, (i)->u64s, type)
123 int bcachectl_open(void);
127 struct bcache_handle {
132 struct bcache_handle bcache_fs_open(const char *);
134 bool ask_proceed(void);
136 void memzero_explicit(void *, size_t);