From 20f4e1c33808b063f808b314479bf8abe480655f Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Tue, 20 Nov 2018 15:15:55 -0800 Subject: [PATCH] scoutfs: put magic value in block header The super block had a magic value that was used to identify that the block should contain our data structure. But it was called an 'id' which was confused with the header fsid in the past. Also, the btree blocks aren't using a similar magic value at all. This moves the magic value in to the header and creates values for the super block and btree blocks. Both are written but the btree block reads don't check the value. Signed-off-by: Zach Brown --- kmod/src/btree.c | 2 +- kmod/src/format.h | 12 +++++++----- kmod/src/super.c | 8 ++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/kmod/src/btree.c b/kmod/src/btree.c index eee9c547..a7b0f130 100644 --- a/kmod/src/btree.c +++ b/kmod/src/btree.c @@ -781,6 +781,7 @@ retry: bt->free_end = cpu_to_le16(SCOUTFS_BLOCK_SIZE); } + bt->hdr.magic = cpu_to_le32(SCOUTFS_BLOCK_MAGIC_BTREE); bt->hdr.blkno = cpu_to_le64(blkno); bt->hdr.seq = cpu_to_le64(seq); if (ref) { @@ -1646,7 +1647,6 @@ int scoutfs_btree_write_dirty(struct super_block *sb) /* checksum everything to reduce time between io submission merging */ for_each_dirty_bh(bti, bh, tmp) { bt = (void *)bh->b_data; - bt->hdr._pad = 0; bt->hdr.crc = scoutfs_block_calc_crc(&bt->hdr); } diff --git a/kmod/src/format.h b/kmod/src/format.h index a8ebb465..e2bfecfa 100644 --- a/kmod/src/format.h +++ b/kmod/src/format.h @@ -3,8 +3,10 @@ /* statfs(2) f_type */ #define SCOUTFS_SUPER_MAGIC 0x554f4353 /* "SCOU" */ -/* super block id */ -#define SCOUTFS_SUPER_ID 0x2e736674756f6373ULL /* "scoutfs." */ + +/* block header magic values, chosen at random */ +#define SCOUTFS_BLOCK_MAGIC_SUPER 0x103c428b +#define SCOUTFS_BLOCK_MAGIC_BTREE 0xe597f96d /* * The super block and btree blocks are fixed 4k. @@ -67,12 +69,12 @@ struct scoutfs_inet_addr { /* * This header is stored at the start of btree blocks and the super - * block for verification. The crc is calculated by zeroing the crc and - * padding so the buffer is large and aligned. + * block for verification. The crc field is not included in the + * calculation of the crc. */ struct scoutfs_block_header { __le32 crc; - __le32 _pad; + __le32 magic; __le64 fsid; __le64 seq; __le64 blkno; diff --git a/kmod/src/super.c b/kmod/src/super.c index 2e9e6875..8149abd1 100644 --- a/kmod/src/super.c +++ b/kmod/src/super.c @@ -191,7 +191,7 @@ int scoutfs_write_dirty_super(struct super_block *sb) super = page_address(page); memcpy(super, &sbi->super, sizeof(*super)); - super->hdr._pad = 0; + super->hdr.magic = cpu_to_le32(SCOUTFS_BLOCK_MAGIC_SUPER); super->hdr.crc = scoutfs_block_calc_crc(&super->hdr); ret = scoutfs_bio_write(sb, &page, le64_to_cpu(super->hdr.blkno), 1); @@ -226,9 +226,9 @@ int scoutfs_read_super(struct super_block *sb, super = scoutfs_page_block_address(&page, 0); - if (super->id != cpu_to_le64(SCOUTFS_SUPER_ID)) { - scoutfs_err(sb, "super block has invalid id %llx", - le64_to_cpu(super->id)); + if (super->hdr.magic != cpu_to_le32(SCOUTFS_BLOCK_MAGIC_SUPER)) { + scoutfs_err(sb, "super block has invalid magic value 0x%08x", + le32_to_cpu(super->hdr.magic)); ret = -EINVAL; goto out; }