1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_COMPRESS_H
3 #define _BCACHEFS_COMPRESS_H
5 #include "extents_types.h"
7 static const unsigned __bch2_compression_opt_to_type[] = {
8 #define x(t, n) [BCH_COMPRESSION_OPT_##t] = BCH_COMPRESSION_TYPE_##t,
13 struct bch_compression_opt {
18 static inline struct bch_compression_opt __bch2_compression_decode(unsigned v)
20 return (struct bch_compression_opt) {
26 static inline bool bch2_compression_opt_valid(unsigned v)
28 struct bch_compression_opt opt = __bch2_compression_decode(v);
30 return opt.type < ARRAY_SIZE(__bch2_compression_opt_to_type) && !(!opt.type && opt.level);
33 static inline struct bch_compression_opt bch2_compression_decode(unsigned v)
35 return bch2_compression_opt_valid(v)
36 ? __bch2_compression_decode(v)
37 : (struct bch_compression_opt) { 0 };
40 static inline unsigned bch2_compression_encode(struct bch_compression_opt opt)
42 return opt.type|(opt.level << 4);
45 static inline enum bch_compression_type bch2_compression_opt_to_type(unsigned v)
47 return __bch2_compression_opt_to_type[bch2_compression_decode(v).type];
50 static inline void bch2_prt_compression_type(struct printbuf *out, enum bch_compression_type type)
52 if (type < BCH_COMPRESSION_TYPE_NR)
53 prt_str(out, __bch2_compression_types[type]);
55 prt_printf(out, "(invalid compression type %u)", type);
58 int bch2_bio_uncompress_inplace(struct bch_fs *, struct bio *,
59 struct bch_extent_crc_unpacked *);
60 int bch2_bio_uncompress(struct bch_fs *, struct bio *, struct bio *,
61 struct bvec_iter, struct bch_extent_crc_unpacked);
62 unsigned bch2_bio_compress(struct bch_fs *, struct bio *, size_t *,
63 struct bio *, size_t *, unsigned);
65 int bch2_check_set_has_compressed_data(struct bch_fs *, unsigned);
66 void bch2_fs_compress_exit(struct bch_fs *);
67 int bch2_fs_compress_init(struct bch_fs *);
69 void bch2_compression_opt_to_text(struct printbuf *, u64);
71 int bch2_opt_compression_parse(struct bch_fs *, const char *, u64 *, struct printbuf *);
72 void bch2_opt_compression_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
73 int bch2_opt_compression_validate(u64, struct printbuf *);
75 #define bch2_opt_compression (struct bch_opt_fn) { \
76 .parse = bch2_opt_compression_parse, \
77 .to_text = bch2_opt_compression_to_text, \
78 .validate = bch2_opt_compression_validate, \
81 #endif /* _BCACHEFS_COMPRESS_H */