]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/checksum.h
Disable pristine-tar option in gbp.conf, since there is no pristine-tar branch.
[bcachefs-tools-debian] / libbcachefs / checksum.h
index f7ccef7a55201985fbf03a4c937e26a3fd24cac2..1b8c2c1016dc6347ce12ef3161d4723835dfa56e 100644 (file)
@@ -40,14 +40,39 @@ struct bch_csum bch2_checksum(struct bch_fs *, unsigned, struct nonce,
  */
 #define csum_vstruct(_c, _type, _nonce, _i)                            \
 ({                                                                     \
-       const void *start = ((const void *) (_i)) + sizeof((_i)->csum); \
-       const void *end = vstruct_end(_i);                              \
+       const void *_start = ((const void *) (_i)) + sizeof((_i)->csum);\
                                                                        \
-       bch2_checksum(_c, _type, _nonce, start, end - start);           \
+       bch2_checksum(_c, _type, _nonce, _start, vstruct_end(_i) - _start);\
 })
 
+static inline void bch2_csum_to_text(struct printbuf *out,
+                                    enum bch_csum_type type,
+                                    struct bch_csum csum)
+{
+       const u8 *p = (u8 *) &csum;
+       unsigned bytes = type < BCH_CSUM_NR ? bch_crc_bytes[type] : 16;
+
+       for (unsigned i = 0; i < bytes; i++)
+               prt_hex_byte(out, p[i]);
+}
+
+static inline void bch2_csum_err_msg(struct printbuf *out,
+                                    enum bch_csum_type type,
+                                    struct bch_csum expected,
+                                    struct bch_csum got)
+{
+       prt_printf(out, "checksum error: got ");
+       bch2_csum_to_text(out, type, got);
+       prt_str(out, " should be ");
+       bch2_csum_to_text(out, type, expected);
+       prt_printf(out, " type %s", bch2_csum_types[type]);
+}
+
 int bch2_chacha_encrypt_key(struct bch_key *, struct nonce, void *, size_t);
 int bch2_request_key(struct bch_sb *, struct bch_key *);
+#ifndef __KERNEL__
+int bch2_revoke_key(struct bch_sb *);
+#endif
 
 int bch2_encrypt(struct bch_fs *, unsigned, struct nonce,
                 void *data, size_t);
@@ -72,6 +97,8 @@ static inline int bch2_encrypt_bio(struct bch_fs *c, unsigned type,
                : 0;
 }
 
+extern const struct bch_sb_field_ops bch_sb_field_ops_crypt;
+
 int bch2_decrypt_sb_key(struct bch_fs *, struct bch_sb_field_crypt *,
                        struct bch_key *);
 
@@ -99,14 +126,17 @@ static inline enum bch_csum_type bch2_csum_opt_to_type(enum bch_csum_opts type,
 }
 
 static inline enum bch_csum_type bch2_data_checksum_type(struct bch_fs *c,
-                                                        unsigned opt)
+                                                        struct bch_io_opts opts)
 {
+       if (opts.nocow)
+               return 0;
+
        if (c->sb.encryption_type)
                return c->opts.wide_macs
                        ? BCH_CSUM_chacha20_poly1305_128
                        : BCH_CSUM_chacha20_poly1305_80;
 
-       return bch2_csum_opt_to_type(opt, true);
+       return bch2_csum_opt_to_type(opts.data_checksum, true);
 }
 
 static inline enum bch_csum_type bch2_meta_checksum_type(struct bch_fs *c)
@@ -117,12 +147,6 @@ static inline enum bch_csum_type bch2_meta_checksum_type(struct bch_fs *c)
        return bch2_csum_opt_to_type(c->opts.metadata_checksum, false);
 }
 
-static const unsigned bch2_compression_opt_to_type[] = {
-#define x(t, n) [BCH_COMPRESSION_OPT_##t] = BCH_COMPRESSION_TYPE_##t,
-       BCH_COMPRESSION_OPTS()
-#undef x
-};
-
 static inline bool bch2_checksum_type_valid(const struct bch_fs *c,
                                           unsigned type)
 {