]> git.sesse.net Git - bcachefs-tools-debian/blob - tools-util.h
bcache in userspace; userspace fsck
[bcachefs-tools-debian] / tools-util.h
1 #ifndef _TOOLS_UTIL_H
2 #define _TOOLS_UTIL_H
3
4 #include <stdbool.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sys/types.h>
8
9 #include <linux/byteorder.h>
10 #include <linux/kernel.h>
11 #include <linux/log2.h>
12 #include <linux/string.h>
13 #include <linux/types.h>
14
15 #define die(arg, ...)                                   \
16 do {                                                    \
17         fprintf(stderr, arg "\n", ##__VA_ARGS__);       \
18         exit(EXIT_FAILURE);                             \
19 } while (0)
20
21 enum units {
22         BYTES,
23         SECTORS,
24         HUMAN_READABLE,
25 };
26
27 struct units_buf pr_units(u64, enum units);
28
29 struct units_buf {
30         char    b[20];
31 };
32
33 long strtoul_or_die(const char *, size_t, const char *);
34
35 u64 hatoi(const char *);
36 unsigned hatoi_validate(const char *, const char *);
37 unsigned nr_args(char * const *);
38
39 char *read_file_str(int, const char *);
40 u64 read_file_u64(int, const char *);
41
42 ssize_t read_string_list(const char *, const char * const[]);
43 ssize_t read_string_list_or_die(const char *, const char * const[],
44                                 const char *);
45 void print_string_list(const char * const[], size_t);
46
47 u64 get_size(const char *, int);
48 unsigned get_blocksize(const char *, int);
49
50 #include "linux/bcache.h"
51 #include "linux/bcache-ioctl.h"
52
53 int bcachectl_open(void);
54
55 struct bcache_handle {
56         int     ioctl_fd;
57         int     sysfs_fd;
58 };
59
60 struct bcache_handle bcache_fs_open(const char *);
61
62 bool ask_proceed(void);
63
64 #endif /* _TOOLS_UTIL_H */