mirror of
https://github.com/versity/scoutfs.git
synced 2026-01-08 13:01:23 +00:00
scoutfs-utils: calculate segment crc in mkfs
Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user