From 7cb2a7895d94db2979c29e4a20f33b5557c702d5 Mon Sep 17 00:00:00 2001 From: Brian Foster Date: Fri, 3 Nov 2023 09:09:38 -0400 Subject: bcachefs: use swab40 for bch_backpointer.bucket_offset bitfield The bucket_offset field of bch_backpointer is a 40-bit bitfield, but the bch2_backpointer_swab() helper uses swab32. This leads to inconsistency when an on-disk fs is accessed from an opposite endian machine. As it turns out, we already have an internal swab40() helper that is used from the bch_alloc_v4 swab callback. Lift it into the backpointers header file and use it consistently in both places. Signed-off-by: Brian Foster Signed-off-by: Kent Overstreet --- fs/bcachefs/backpointers.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'fs/bcachefs/backpointers.h') diff --git a/fs/bcachefs/backpointers.h b/fs/bcachefs/backpointers.h index 4ab9f3562912..ab866feeaf66 100644 --- a/fs/bcachefs/backpointers.h +++ b/fs/bcachefs/backpointers.h @@ -7,6 +7,15 @@ #include "buckets.h" #include "super.h" +static inline u64 swab40(u64 x) +{ + return (((x & 0x00000000ffULL) << 32)| + ((x & 0x000000ff00ULL) << 16)| + ((x & 0x0000ff0000ULL) >> 0)| + ((x & 0x00ff000000ULL) >> 16)| + ((x & 0xff00000000ULL) >> 32)); +} + int bch2_backpointer_invalid(struct bch_fs *, struct bkey_s_c k, enum bkey_invalid_flags, struct printbuf *); void bch2_backpointer_to_text(struct printbuf *, const struct bch_backpointer *); -- cgit v1.2.3