mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-01 22:48:06 +00:00
btrfs-progs: don't assume checksums are always 4 bytes
Pass pointer to a generic buffer instead of fixed size that crc32c currently uses. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
a38eb3d426
commit
de68086e35
@ -37,7 +37,8 @@ static int check_csum_superblock(void *sb)
|
||||
u32 crc = ~(u32)0;
|
||||
|
||||
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE,
|
||||
crc, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
|
||||
(u8 *)&crc,
|
||||
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
|
||||
btrfs_csum_final(crc, result);
|
||||
|
||||
return !memcmp(sb, &result, csum_size);
|
||||
@ -50,10 +51,12 @@ static void update_block_csum(void *block, int is_sb)
|
||||
u32 crc = ~(u32)0;
|
||||
|
||||
if (is_sb) {
|
||||
crc = btrfs_csum_data((char *)block + BTRFS_CSUM_SIZE, crc,
|
||||
crc = btrfs_csum_data((char *)block + BTRFS_CSUM_SIZE,
|
||||
(u8 *)&crc,
|
||||
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
|
||||
} else {
|
||||
crc = btrfs_csum_data((char *)block + BTRFS_CSUM_SIZE, crc,
|
||||
crc = btrfs_csum_data((char *)block + BTRFS_CSUM_SIZE,
|
||||
(u8 *)&crc,
|
||||
BLOCKSIZE - BTRFS_CSUM_SIZE);
|
||||
}
|
||||
btrfs_csum_final(crc, result);
|
||||
|
@ -5660,7 +5660,7 @@ static int check_extent_csums(struct btrfs_root *root, u64 bytenr,
|
||||
tmp = offset + data_checked;
|
||||
|
||||
csum = btrfs_csum_data((char *)data + tmp,
|
||||
csum, fs_info->sectorsize);
|
||||
(u8 *)&csum, fs_info->sectorsize);
|
||||
btrfs_csum_final(csum, (u8 *)&csum);
|
||||
|
||||
csum_offset = leaf_offset +
|
||||
|
@ -41,7 +41,8 @@ static int check_csum_sblock(void *sb, int csum_size)
|
||||
u32 crc = ~(u32)0;
|
||||
|
||||
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE,
|
||||
crc, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
|
||||
(u8 *)&crc,
|
||||
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
|
||||
btrfs_csum_final(crc, result);
|
||||
|
||||
return !memcmp(sb, &result, csum_size);
|
||||
|
@ -1902,7 +1902,7 @@ static int check_one_csum(int fd, u64 start, u32 len, u32 tree_csum)
|
||||
goto out;
|
||||
}
|
||||
ret = 0;
|
||||
csum_result = btrfs_csum_data(data, csum_result, len);
|
||||
csum_result = btrfs_csum_data(data, (u8 *)&csum_result, len);
|
||||
btrfs_csum_final(csum_result, (u8 *)&csum_result);
|
||||
if (csum_result != tree_csum)
|
||||
ret = 1;
|
||||
|
@ -65,7 +65,8 @@ static inline int write_temp_super(int fd, struct btrfs_super_block *sb,
|
||||
u32 crc = ~(u32)0;
|
||||
int ret;
|
||||
|
||||
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, crc,
|
||||
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE,
|
||||
(u8 *)&crc,
|
||||
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
|
||||
btrfs_csum_final(crc, &sb->csum[0]);
|
||||
ret = pwrite(fd, sb, BTRFS_SUPER_INFO_SIZE, sb_bytenr);
|
||||
|
12
disk-io.c
12
disk-io.c
@ -138,9 +138,9 @@ static void print_tree_block_error(struct btrfs_fs_info *fs_info,
|
||||
}
|
||||
}
|
||||
|
||||
u32 btrfs_csum_data(char *data, u32 seed, size_t len)
|
||||
u32 btrfs_csum_data(char *data, u8 *seed, size_t len)
|
||||
{
|
||||
return crc32c(seed, data, len);
|
||||
return crc32c(*(u32*)seed, data, len);
|
||||
}
|
||||
|
||||
void btrfs_csum_final(u32 crc, u8 *result)
|
||||
@ -156,7 +156,7 @@ static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
|
||||
u32 crc = ~(u32)0;
|
||||
|
||||
len = buf->len - BTRFS_CSUM_SIZE;
|
||||
crc = btrfs_csum_data(buf->data + BTRFS_CSUM_SIZE, crc, len);
|
||||
crc = btrfs_csum_data(buf->data + BTRFS_CSUM_SIZE, (u8 *)&crc, len);
|
||||
btrfs_csum_final(crc, result);
|
||||
|
||||
if (verify) {
|
||||
@ -1376,7 +1376,7 @@ int btrfs_check_super(struct btrfs_super_block *sb, unsigned sbflags)
|
||||
csum_size = btrfs_csum_sizes[csum_type];
|
||||
|
||||
crc = ~(u32)0;
|
||||
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, crc,
|
||||
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, (u8 *)&crc,
|
||||
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
|
||||
btrfs_csum_final(crc, result);
|
||||
|
||||
@ -1631,7 +1631,7 @@ static int write_dev_supers(struct btrfs_fs_info *fs_info,
|
||||
if (fs_info->super_bytenr != BTRFS_SUPER_INFO_OFFSET) {
|
||||
btrfs_set_super_bytenr(sb, fs_info->super_bytenr);
|
||||
crc = ~(u32)0;
|
||||
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, crc,
|
||||
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, (u8 *)&crc,
|
||||
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
|
||||
btrfs_csum_final(crc, &sb->csum[0]);
|
||||
|
||||
@ -1667,7 +1667,7 @@ static int write_dev_supers(struct btrfs_fs_info *fs_info,
|
||||
btrfs_set_super_bytenr(sb, bytenr);
|
||||
|
||||
crc = ~(u32)0;
|
||||
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, crc,
|
||||
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, (u8 *)&crc,
|
||||
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
|
||||
btrfs_csum_final(crc, &sb->csum[0]);
|
||||
|
||||
|
@ -186,7 +186,7 @@ int btrfs_free_fs_root(struct btrfs_root *root);
|
||||
void btrfs_mark_buffer_dirty(struct extent_buffer *buf);
|
||||
int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid);
|
||||
int btrfs_set_buffer_uptodate(struct extent_buffer *buf);
|
||||
u32 btrfs_csum_data(char *data, u32 seed, size_t len);
|
||||
u32 btrfs_csum_data(char *data, u8 *seed, size_t len);
|
||||
void btrfs_csum_final(u32 crc, u8 *result);
|
||||
|
||||
int btrfs_open_device(struct btrfs_device *dev);
|
||||
|
@ -312,7 +312,7 @@ csum:
|
||||
item = (struct btrfs_csum_item *)((unsigned char *)item +
|
||||
csum_offset * csum_size);
|
||||
found:
|
||||
csum_result = btrfs_csum_data(data, csum_result, len);
|
||||
csum_result = btrfs_csum_data(data, (u8 *)&csum_result, len);
|
||||
btrfs_csum_final(csum_result, (u8 *)&csum_result);
|
||||
if (csum_result == 0) {
|
||||
printk("csum result is 0 for block %llu\n",
|
||||
|
Loading…
Reference in New Issue
Block a user