Skip to content

Commit de68086

Browse files
Johannes Thumshirnkdave
Johannes Thumshirn
authored andcommitted
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>
1 parent a38eb3d commit de68086

File tree

8 files changed

+20
-15
lines changed

8 files changed

+20
-15
lines changed

btrfs-sb-mod.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ static int check_csum_superblock(void *sb)
3737
u32 crc = ~(u32)0;
3838

3939
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE,
40-
crc, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
40+
(u8 *)&crc,
41+
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
4142
btrfs_csum_final(crc, result);
4243

4344
return !memcmp(sb, &result, csum_size);
@@ -50,10 +51,12 @@ static void update_block_csum(void *block, int is_sb)
5051
u32 crc = ~(u32)0;
5152

5253
if (is_sb) {
53-
crc = btrfs_csum_data((char *)block + BTRFS_CSUM_SIZE, crc,
54+
crc = btrfs_csum_data((char *)block + BTRFS_CSUM_SIZE,
55+
(u8 *)&crc,
5456
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
5557
} else {
56-
crc = btrfs_csum_data((char *)block + BTRFS_CSUM_SIZE, crc,
58+
crc = btrfs_csum_data((char *)block + BTRFS_CSUM_SIZE,
59+
(u8 *)&crc,
5760
BLOCKSIZE - BTRFS_CSUM_SIZE);
5861
}
5962
btrfs_csum_final(crc, result);

check/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5660,7 +5660,7 @@ static int check_extent_csums(struct btrfs_root *root, u64 bytenr,
56605660
tmp = offset + data_checked;
56615661

56625662
csum = btrfs_csum_data((char *)data + tmp,
5663-
csum, fs_info->sectorsize);
5663+
(u8 *)&csum, fs_info->sectorsize);
56645664
btrfs_csum_final(csum, (u8 *)&csum);
56655665

56665666
csum_offset = leaf_offset +

cmds/inspect-dump-super.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ static int check_csum_sblock(void *sb, int csum_size)
4141
u32 crc = ~(u32)0;
4242

4343
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE,
44-
crc, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
44+
(u8 *)&crc,
45+
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
4546
btrfs_csum_final(crc, result);
4647

4748
return !memcmp(sb, &result, csum_size);

cmds/rescue-chunk-recover.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ static int check_one_csum(int fd, u64 start, u32 len, u32 tree_csum)
19021902
goto out;
19031903
}
19041904
ret = 0;
1905-
csum_result = btrfs_csum_data(data, csum_result, len);
1905+
csum_result = btrfs_csum_data(data, (u8 *)&csum_result, len);
19061906
btrfs_csum_final(csum_result, (u8 *)&csum_result);
19071907
if (csum_result != tree_csum)
19081908
ret = 1;

convert/common.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ static inline int write_temp_super(int fd, struct btrfs_super_block *sb,
6565
u32 crc = ~(u32)0;
6666
int ret;
6767

68-
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, crc,
68+
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE,
69+
(u8 *)&crc,
6970
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
7071
btrfs_csum_final(crc, &sb->csum[0]);
7172
ret = pwrite(fd, sb, BTRFS_SUPER_INFO_SIZE, sb_bytenr);

disk-io.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ static void print_tree_block_error(struct btrfs_fs_info *fs_info,
138138
}
139139
}
140140

141-
u32 btrfs_csum_data(char *data, u32 seed, size_t len)
141+
u32 btrfs_csum_data(char *data, u8 *seed, size_t len)
142142
{
143-
return crc32c(seed, data, len);
143+
return crc32c(*(u32*)seed, data, len);
144144
}
145145

146146
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,
156156
u32 crc = ~(u32)0;
157157

158158
len = buf->len - BTRFS_CSUM_SIZE;
159-
crc = btrfs_csum_data(buf->data + BTRFS_CSUM_SIZE, crc, len);
159+
crc = btrfs_csum_data(buf->data + BTRFS_CSUM_SIZE, (u8 *)&crc, len);
160160
btrfs_csum_final(crc, result);
161161

162162
if (verify) {
@@ -1376,7 +1376,7 @@ int btrfs_check_super(struct btrfs_super_block *sb, unsigned sbflags)
13761376
csum_size = btrfs_csum_sizes[csum_type];
13771377

13781378
crc = ~(u32)0;
1379-
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, crc,
1379+
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, (u8 *)&crc,
13801380
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
13811381
btrfs_csum_final(crc, result);
13821382

@@ -1631,7 +1631,7 @@ static int write_dev_supers(struct btrfs_fs_info *fs_info,
16311631
if (fs_info->super_bytenr != BTRFS_SUPER_INFO_OFFSET) {
16321632
btrfs_set_super_bytenr(sb, fs_info->super_bytenr);
16331633
crc = ~(u32)0;
1634-
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, crc,
1634+
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, (u8 *)&crc,
16351635
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
16361636
btrfs_csum_final(crc, &sb->csum[0]);
16371637

@@ -1667,7 +1667,7 @@ static int write_dev_supers(struct btrfs_fs_info *fs_info,
16671667
btrfs_set_super_bytenr(sb, bytenr);
16681668

16691669
crc = ~(u32)0;
1670-
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, crc,
1670+
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, (u8 *)&crc,
16711671
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
16721672
btrfs_csum_final(crc, &sb->csum[0]);
16731673

disk-io.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ int btrfs_free_fs_root(struct btrfs_root *root);
186186
void btrfs_mark_buffer_dirty(struct extent_buffer *buf);
187187
int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid);
188188
int btrfs_set_buffer_uptodate(struct extent_buffer *buf);
189-
u32 btrfs_csum_data(char *data, u32 seed, size_t len);
189+
u32 btrfs_csum_data(char *data, u8 *seed, size_t len);
190190
void btrfs_csum_final(u32 crc, u8 *result);
191191

192192
int btrfs_open_device(struct btrfs_device *dev);

file-item.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
312312
item = (struct btrfs_csum_item *)((unsigned char *)item +
313313
csum_offset * csum_size);
314314
found:
315-
csum_result = btrfs_csum_data(data, csum_result, len);
315+
csum_result = btrfs_csum_data(data, (u8 *)&csum_result, len);
316316
btrfs_csum_final(csum_result, (u8 *)&csum_result);
317317
if (csum_result == 0) {
318318
printk("csum result is 0 for block %llu\n",

0 commit comments

Comments
 (0)