Skip to content

Commit eca152e

Browse files
lorddoskiaskdave
authored andcommitted
btrfs: Manually implement device_total_bytes getter/setter
The device->total_bytes member needs to always be rounded down to sectorsize so that it corresponds to the value of super->total_bytes. However, there are multiple places where the setter is fed a value which is not rounded which can cause a fs to be unmountable due to the check introduced in 99e3ecf ("Btrfs: add more validation checks for superblock"). This patch implements the getter/setter manually so that in a later patch I can add necessary code to catch offenders. Signed-off-by: Nikolay Borisov <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 0d0c71b commit eca152e

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

fs/btrfs/ctree.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1541,8 +1541,26 @@ static inline void btrfs_set_##name(type *s, u##bits val) \
15411541
s->member = cpu_to_le##bits(val); \
15421542
}
15431543

1544+
1545+
static inline u64 btrfs_device_total_bytes(struct extent_buffer *eb,
1546+
struct btrfs_dev_item *s)
1547+
{
1548+
BUILD_BUG_ON(sizeof(u64) !=
1549+
sizeof(((struct btrfs_dev_item *)0))->total_bytes);
1550+
return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item,
1551+
total_bytes));
1552+
}
1553+
static inline void btrfs_set_device_total_bytes(struct extent_buffer *eb,
1554+
struct btrfs_dev_item *s,
1555+
u64 val)
1556+
{
1557+
BUILD_BUG_ON(sizeof(u64) !=
1558+
sizeof(((struct btrfs_dev_item *)0))->total_bytes);
1559+
btrfs_set_64(eb, s, offsetof(struct btrfs_dev_item, total_bytes), val);
1560+
}
1561+
1562+
15441563
BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
1545-
BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
15461564
BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
15471565
BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
15481566
BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);

0 commit comments

Comments
 (0)