]> git.sesse.net Git - bcachefs-tools-debian/blob - bcache.h
bcacheadm: fix tiering and backing device bugs
[bcachefs-tools-debian] / bcache.h
1 /*
2  * Author: Kent Overstreet <kmo@daterainc.com>
3  *
4  * GPLv2
5  */
6
7 #ifndef _BCACHE_H
8 #define _BCACHE_H
9
10 #include <linux/bcache.h>
11 #include <dirent.h>
12
13 typedef __u8    u8;
14 typedef __u16   u16;
15 typedef __u32   u32;
16 typedef __u64   u64;
17
18 typedef __s8    s8;
19 typedef __s16   s16;
20 typedef __s32   s32;
21 typedef __s64   s64;
22
23 #define SB_START                (SB_SECTOR * 512)
24
25
26 #define max(x, y) ({                            \
27         typeof(x) _max1 = (x);                  \
28         typeof(y) _max2 = (y);                  \
29         (void) (&_max1 == &_max2);              \
30         _max1 > _max2 ? _max1 : _max2; })
31
32
33 extern const char * const cache_state[];
34 extern const char * const replacement_policies[];
35 extern const char * const csum_types[];
36 extern const char * const bdev_cache_mode[];
37 extern const char * const bdev_state[];
38
39 ssize_t read_string_list(const char *, const char * const[]);
40 ssize_t read_string_list_or_die(const char *, const char * const[],
41                                 const char *);
42 void print_string_list(const char * const[], size_t);
43
44 uint64_t bch_checksum(unsigned, const void *, size_t);
45
46 uint64_t getblocks(int);
47 uint64_t hatoi(const char *);
48 unsigned hatoi_validate(const char *, const char *);
49 void write_backingdev_sb(int, unsigned, unsigned *,     bool, uint64_t,
50                                 const char *, uuid_le);
51 int dev_open(const char *, bool);
52 void write_cache_sbs(int *, struct cache_sb *, unsigned, unsigned *, int);
53 void next_cache_device(struct cache_sb *, unsigned, int, unsigned, bool);
54 unsigned get_blocksize(const char *);
55 long strtoul_or_die(const char *, size_t, const char *);
56
57 void show_super_backingdev(struct cache_sb *, bool);
58 void show_super_cache(struct cache_sb *, bool);
59
60 struct cache_sb *query_dev(char *, bool);
61 int list_cachesets(char *);
62 char *parse_array_to_list(char *const *);
63 int register_bcache();
64 int probe(char *, int);
65 void print_dev_info(struct cache_sb *, bool);
66 void sb_state(struct cache_sb *, char *);
67 void read_stat_dir(DIR *, char *, char *, bool);
68
69
70 #define csum_set(i, type)                                               \
71 ({                                                                      \
72         void *start = ((void *) (i)) + sizeof(uint64_t);                \
73         void *end = bset_bkey_last(i);                                  \
74                                                                         \
75         bch_checksum(type, start, end - start);                         \
76 })
77
78 #endif