4 #include <linux/uuid.h>
7 #include "libbcachefs/bcachefs_format.h"
8 #include "libbcachefs/bcachefs_ioctl.h"
9 #include "tools-util.h"
10 #include "libbcachefs/vstructs.h"
16 unsigned on_error_action;
19 unsigned btree_node_size;
20 unsigned encoded_extent_max;
22 unsigned meta_replicas;
23 unsigned data_replicas;
25 unsigned meta_replicas_required;
26 unsigned data_replicas_required;
28 unsigned meta_csum_type;
29 unsigned data_csum_type;
30 unsigned compression_type;
36 static inline struct format_opts format_opts_default()
38 return (struct format_opts) {
39 .on_error_action = BCH_ON_ERROR_RO,
40 .encoded_extent_max = 128,
41 .meta_csum_type = BCH_CSUM_OPT_CRC32C,
42 .data_csum_type = BCH_CSUM_OPT_CRC32C,
45 .meta_replicas_required = 1,
46 .data_replicas_required = 1,
53 u64 size; /* 512 byte sectors */
56 unsigned data_allowed;
65 static inline struct dev_opts dev_opts_default()
67 return (struct dev_opts) {
68 .data_allowed = ~0U << 2,
72 void bch2_pick_bucket_size(struct format_opts, struct dev_opts *);
73 struct bch_sb *bch2_format(struct format_opts, struct dev_opts *, size_t);
75 void bch2_super_write(int, struct bch_sb *);
76 struct bch_sb *__bch2_super_read(int, u64);
78 void bch2_super_print(struct bch_sb *, int);
80 /* ioctl interface: */
82 int bcachectl_open(void);
90 void bcache_fs_close(struct bchfs_handle);
91 struct bchfs_handle bcache_fs_open(const char *);
93 static inline void bchu_disk_add(struct bchfs_handle fs, char *dev)
95 struct bch_ioctl_disk i = { .dev = (__u64) dev, };
97 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_ADD, &i);
100 static inline void bchu_disk_set_state(struct bchfs_handle fs, const char *dev,
101 unsigned new_state, unsigned flags)
103 struct bch_ioctl_disk_set_state i = {
105 .new_state = new_state,
108 if (!kstrtoull(dev, 10, &i.dev))
109 i.flags |= BCH_BY_INDEX;
113 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_SET_STATE, &i);
116 static inline struct bch_ioctl_usage *bchu_usage(struct bchfs_handle fs)
118 struct bch_ioctl_usage *u = NULL;
119 unsigned nr_devices = 4;
122 u = xrealloc(u, sizeof(*u) + sizeof(u->devs[0]) * nr_devices);
123 u->nr_devices = nr_devices;
125 if (!ioctl(fs.ioctl_fd, BCH_IOCTL_USAGE, u))
129 die("BCH_IOCTL_USAGE error: %m");
134 static inline struct bch_sb *bchu_read_super(struct bchfs_handle fs, unsigned idx)
137 struct bch_sb *sb = NULL;
140 sb = xrealloc(sb, size);
141 struct bch_ioctl_read_super i = {
147 i.flags |= BCH_READ_DEV|BCH_BY_INDEX;
151 if (!ioctl(fs.ioctl_fd, BCH_IOCTL_READ_SUPER, &i))
154 die("BCH_IOCTL_READ_SUPER error: %m");
159 static inline unsigned bchu_disk_get_idx(struct bchfs_handle fs, dev_t dev)
161 struct bch_ioctl_disk_get_idx i = { .dev = dev };
163 return xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_GET_IDX, &i);
166 static inline void bchu_disk_resize(struct bchfs_handle fs,
170 struct bch_ioctl_disk_resize i = {
171 .flags = BCH_BY_INDEX,
173 .nbuckets = nbuckets,
176 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_RESIZE, &i);
179 #endif /* _LIBBCACHE_H */