]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - tools-util.h
nix: fix build add overlay and formatter to flake
[bcachefs-tools-debian] / tools-util.h
index aa7c0270331e1cf07be5efdf3eb18374121ae8d9..7a04c1080beb9ae5dc0df82ae40579ad3c20c7d4 100644 (file)
@@ -62,9 +62,10 @@ u64 read_file_u64(int, const char *);
 ssize_t read_string_list_or_die(const char *, const char * const[],
                                const char *);
 
-u64 get_size(const char *, int);
-unsigned get_blocksize(const char *, int);
-int open_for_format(const char *, bool);
+u64 get_size(int);
+unsigned get_blocksize(int);
+struct dev_opts;
+int open_for_format(struct dev_opts *, bool);
 
 bool ask_yn(void);
 
@@ -115,8 +116,7 @@ static inline struct range hole_iter_next(struct hole_iter *iter)
 #include <linux/fiemap.h>
 
 struct fiemap_iter {
-       struct fiemap           f;
-       struct fiemap_extent    fe[1024];
+       struct fiemap           *f;
        unsigned                idx;
        int                     fd;
 };
@@ -125,11 +125,20 @@ static inline void fiemap_iter_init(struct fiemap_iter *iter, int fd)
 {
        memset(iter, 0, sizeof(*iter));
 
-       iter->f.fm_extent_count = ARRAY_SIZE(iter->fe);
-       iter->f.fm_length       = FIEMAP_MAX_OFFSET;
+       iter->f = xmalloc(sizeof(struct fiemap) +
+                         sizeof(struct fiemap_extent) * 1024);
+
+       iter->f->fm_extent_count        = 1024;
+       iter->f->fm_length      = FIEMAP_MAX_OFFSET;
        iter->fd                = fd;
 }
 
+static inline void fiemap_iter_exit(struct fiemap_iter *iter)
+{
+       free(iter->f);
+       memset(iter, 0, sizeof(*iter));
+}
+
 struct fiemap_extent fiemap_iter_next(struct fiemap_iter *);
 
 #define fiemap_for_each(fd, iter, extent)                              \