]> git.sesse.net Git - bcachefs-tools-debian/blob - bcache.h
Add Apple addendums to .gitignore
[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 #define MAX_PATH                256
25 #define MAX_DEVS                MAX_CACHES_PER_SET
26
27 #define max(x, y) ({                            \
28         typeof(x) _max1 = (x);                  \
29         typeof(y) _max2 = (y);                  \
30         (void) (&_max1 == &_max2);              \
31         _max1 > _max2 ? _max1 : _max2; })
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 enum sysfs_attr {SET_ATTR, CACHE_ATTR, INTERNAL_ATTR};
61
62 static const char *set_attrs[] = {
63         "btree_flush_delay",
64         "btree_scan_ratelimit",
65         "bucket_reserve_percent",
66         "cache_reserve_percent",
67         "checksum_type",
68         "congested_read_threshold_us",
69         "congested_write_threshold_us",
70         "data_replicas",
71         "errors",
72         "foreground_target_percent",
73         "gc_sector_percent",
74         "journal_delay_ms",
75         "meta_replicas",
76         "sector_reserve_percent",
77         "tiering_percent",
78         NULL
79 };
80
81 static const char *cache_attrs[] = {
82         "cache_replacement_policy",
83         "discard",
84         "state",
85         "tier",
86         NULL
87 };
88
89 static const char *internal_attrs[] = {
90         "btree_shrinker_disabled",
91         "copy_gc_enabled",
92         "foreground_write_rate",
93         "tiering_enabled",
94         "tiering_rate",
95         NULL
96 };
97
98 enum sysfs_attr sysfs_attr_type(char *attr);
99 void sysfs_attr_list();
100
101 struct cache_sb *query_dev(char *, bool, bool, bool, char *dev_uuid);
102 char *list_cachesets(char *, bool);
103 char *parse_array_to_list(char *const *);
104 char *register_bcache(char *const *);
105 char *unregister_bcache(char *const *);
106 char *probe(char *, int);
107 char *read_stat_dir(DIR *, char *, char *, char *);
108 char *find_matching_uuid(char *, char *, const char*);
109 char *add_devices(char *const *, char *);
110 char *remove_device(const char *, bool);
111 char *bcache_get_capacity(const char *, const char *, bool);
112
113 #define csum_set(i, type)                                               \
114 ({                                                                      \
115         void *start = ((void *) (i)) + sizeof(uint64_t);                \
116         void *end = bset_bkey_last(i);                                  \
117                                                                         \
118         bch_checksum(type, start, end - start);                         \
119 })
120
121 #endif