scoutfs-utils: calculate segment crc in mkfs

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2018-08-16 13:57:01 -07:00
committed by Zach Brown
parent c3ad8282a3
commit 7abf5c1e2b
4 changed files with 14 additions and 0 deletions

View File

@@ -37,3 +37,12 @@ u32 crc_block(struct scoutfs_block_header *hdr)
return crc32c(~0, (char *)hdr + sizeof(hdr->crc),
SCOUTFS_BLOCK_SIZE - sizeof(hdr->crc));
}
u32 crc_segment(struct scoutfs_segment_block *sblk)
{
u32 off = offsetof(struct scoutfs_segment_block, _padding) +
sizeof(sblk->_padding);
return crc32c(~0, (char *)sblk + off,
le32_to_cpu(sblk->total_bytes) - off);
}

View File

@@ -8,5 +8,6 @@
u32 crc32c(u32 crc, const void *data, unsigned int len);
u64 crc32c_64(u32 crc, const void *data, unsigned int len);
u32 crc_block(struct scoutfs_block_header *hdr);
u32 crc_segment(struct scoutfs_segment_block *seg);
#endif

View File

@@ -271,6 +271,9 @@ struct scoutfs_segment_item {
/*
* Each large segment starts with a segment block that describes the
* rest of the blocks that make up the segment.
*
* The crc covers the initial total_bytes of the segment but starts
* after the padding.
*/
struct scoutfs_segment_block {
__le32 crc;

View File

@@ -377,6 +377,7 @@ static int write_new_fs(char *path, int fd)
item = (void *)(inode + 1);
sblk->total_bytes = cpu_to_le32((long)item - (long)sblk);
sblk->crc = cpu_to_le32(crc_segment(sblk));
ret = pwrite(fd, sblk, SCOUTFS_SEGMENT_SIZE,
first_segno << SCOUTFS_SEGMENT_SHIFT);