mirror of
https://github.com/versity/scoutfs.git
synced 2026-02-09 20:20:08 +00:00
Manifest entries and segment allocation bitmap regions are now stored in btree items instead of the ring log. This lets us work with them incrementally and share them between nodes. Signed-off-by: Zach Brown <zab@versity.com>
53 lines
1.0 KiB
C
53 lines
1.0 KiB
C
#include "crc.h"
|
|
#include "util.h"
|
|
#include "format.h"
|
|
|
|
u32 crc32c(u32 crc, const void *data, unsigned int len)
|
|
{
|
|
while (len >= 8) {
|
|
crc = __builtin_ia32_crc32di(crc, *(u64 *)data);
|
|
len -= 8;
|
|
data += 8;
|
|
}
|
|
if (len & 4) {
|
|
crc = __builtin_ia32_crc32si(crc, *(u32 *)data);
|
|
data += 4;
|
|
}
|
|
if (len & 2) {
|
|
crc = __builtin_ia32_crc32hi(crc, *(u16 *)data);
|
|
data += 2;
|
|
}
|
|
if (len & 1)
|
|
crc = __builtin_ia32_crc32qi(crc, *(u8 *)data);
|
|
|
|
return crc;
|
|
}
|
|
|
|
/* A simple hack to get reasonably solid 64bit hash values */
|
|
u64 crc32c_64(u32 crc, const void *data, unsigned int len)
|
|
{
|
|
unsigned int half = (len + 1) / 2;
|
|
|
|
return ((u64)crc32c(crc, data, half) << 32) |
|
|
crc32c(~crc, data + len - half, half);
|
|
}
|
|
|
|
u32 crc_block(struct scoutfs_block_header *hdr)
|
|
{
|
|
return crc32c(~0, (char *)hdr + sizeof(hdr->crc),
|
|
SCOUTFS_BLOCK_SIZE - sizeof(hdr->crc));
|
|
}
|
|
|
|
u32 crc_btree_block(struct scoutfs_btree_block *bt)
|
|
{
|
|
__le32 old;
|
|
u32 crc;
|
|
|
|
old = bt->crc;
|
|
bt->crc = 0;
|
|
crc = crc32c(~0, bt, SCOUTFS_BLOCK_SIZE);
|
|
bt->crc = old;
|
|
|
|
return crc;
|
|
}
|