diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-05-10 12:36:17 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@hera.kernel.org> | 2007-05-10 12:36:17 -0400 |
commit | 509659cde578d891445afd67d87121dd13e71596 (patch) | |
tree | 17d663e2fed7c1674c5cd9c02f30ef3a56afcaf2 /fs/btrfs/file-item.c | |
parent | 8d7be552a733e53135a91d2d28f57ab87dc0e889 (diff) |
Btrfs: switch to crc32c instead of sha256
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/file-item.c')
-rw-r--r-- | fs/btrfs/file-item.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 10e4cf08e9ed..a66709e6d036 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c | |||
@@ -4,8 +4,8 @@ | |||
4 | #include "transaction.h" | 4 | #include "transaction.h" |
5 | 5 | ||
6 | #define MAX_CSUM_ITEMS(r) ((((BTRFS_LEAF_DATA_SIZE(r) - \ | 6 | #define MAX_CSUM_ITEMS(r) ((((BTRFS_LEAF_DATA_SIZE(r) - \ |
7 | sizeof(struct btrfs_item) * 2) / \ | 7 | sizeof(struct btrfs_item) * 2) / \ |
8 | sizeof(struct btrfs_csum_item)) - 1)) | 8 | BTRFS_CRC32_SIZE) - 1)) |
9 | int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, | 9 | int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, |
10 | struct btrfs_root *root, | 10 | struct btrfs_root *root, |
11 | u64 objectid, u64 pos, | 11 | u64 objectid, u64 pos, |
@@ -78,7 +78,7 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, | |||
78 | csum_offset = (offset - found_key.offset) >> | 78 | csum_offset = (offset - found_key.offset) >> |
79 | root->fs_info->sb->s_blocksize_bits; | 79 | root->fs_info->sb->s_blocksize_bits; |
80 | csums_in_item = btrfs_item_size(leaf->items + path->slots[0]); | 80 | csums_in_item = btrfs_item_size(leaf->items + path->slots[0]); |
81 | csums_in_item /= sizeof(struct btrfs_csum_item); | 81 | csums_in_item /= BTRFS_CRC32_SIZE; |
82 | 82 | ||
83 | if (csum_offset >= csums_in_item) { | 83 | if (csum_offset >= csums_in_item) { |
84 | ret = -EFBIG; | 84 | ret = -EFBIG; |
@@ -86,7 +86,8 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, | |||
86 | } | 86 | } |
87 | } | 87 | } |
88 | item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_csum_item); | 88 | item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_csum_item); |
89 | item += csum_offset; | 89 | item = (struct btrfs_csum_item *)((unsigned char *)item + |
90 | csum_offset * BTRFS_CRC32_SIZE); | ||
90 | return item; | 91 | return item; |
91 | fail: | 92 | fail: |
92 | if (ret > 0) | 93 | if (ret > 0) |
@@ -143,8 +144,7 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans, | |||
143 | /* we found one, but it isn't big enough yet */ | 144 | /* we found one, but it isn't big enough yet */ |
144 | leaf = btrfs_buffer_leaf(path->nodes[0]); | 145 | leaf = btrfs_buffer_leaf(path->nodes[0]); |
145 | item_size = btrfs_item_size(leaf->items + path->slots[0]); | 146 | item_size = btrfs_item_size(leaf->items + path->slots[0]); |
146 | if ((item_size / sizeof(struct btrfs_csum_item)) >= | 147 | if ((item_size / BTRFS_CRC32_SIZE) >= MAX_CSUM_ITEMS(root)) { |
147 | MAX_CSUM_ITEMS(root)) { | ||
148 | /* already at max size, make a new one */ | 148 | /* already at max size, make a new one */ |
149 | goto insert; | 149 | goto insert; |
150 | } | 150 | } |
@@ -159,7 +159,7 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans, | |||
159 | */ | 159 | */ |
160 | btrfs_release_path(root, path); | 160 | btrfs_release_path(root, path); |
161 | ret = btrfs_search_slot(trans, root, &file_key, path, | 161 | ret = btrfs_search_slot(trans, root, &file_key, path, |
162 | sizeof(struct btrfs_csum_item), 1); | 162 | BTRFS_CRC32_SIZE, 1); |
163 | if (ret < 0) | 163 | if (ret < 0) |
164 | goto fail; | 164 | goto fail; |
165 | if (ret == 0) { | 165 | if (ret == 0) { |
@@ -180,10 +180,10 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans, | |||
180 | goto insert; | 180 | goto insert; |
181 | } | 181 | } |
182 | if (csum_offset >= btrfs_item_size(leaf->items + path->slots[0]) / | 182 | if (csum_offset >= btrfs_item_size(leaf->items + path->slots[0]) / |
183 | sizeof(struct btrfs_csum_item)) { | 183 | BTRFS_CRC32_SIZE) { |
184 | u32 diff = (csum_offset + 1) * sizeof(struct btrfs_csum_item); | 184 | u32 diff = (csum_offset + 1) * BTRFS_CRC32_SIZE; |
185 | diff = diff - btrfs_item_size(leaf->items + path->slots[0]); | 185 | diff = diff - btrfs_item_size(leaf->items + path->slots[0]); |
186 | WARN_ON(diff != sizeof(struct btrfs_csum_item)); | 186 | WARN_ON(diff != BTRFS_CRC32_SIZE); |
187 | ret = btrfs_extend_item(trans, root, path, diff); | 187 | ret = btrfs_extend_item(trans, root, path, diff); |
188 | BUG_ON(ret); | 188 | BUG_ON(ret); |
189 | goto csum; | 189 | goto csum; |
@@ -193,7 +193,7 @@ insert: | |||
193 | btrfs_release_path(root, path); | 193 | btrfs_release_path(root, path); |
194 | csum_offset = 0; | 194 | csum_offset = 0; |
195 | ret = btrfs_insert_empty_item(trans, root, path, &file_key, | 195 | ret = btrfs_insert_empty_item(trans, root, path, &file_key, |
196 | sizeof(struct btrfs_csum_item)); | 196 | BTRFS_CRC32_SIZE); |
197 | if (ret != 0) { | 197 | if (ret != 0) { |
198 | printk("at insert for %Lu %u %Lu ret is %d\n", file_key.objectid, file_key.flags, file_key.offset, ret); | 198 | printk("at insert for %Lu %u %Lu ret is %d\n", file_key.objectid, file_key.flags, file_key.offset, ret); |
199 | WARN_ON(1); | 199 | WARN_ON(1); |
@@ -203,10 +203,13 @@ csum: | |||
203 | item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0], | 203 | item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0], |
204 | struct btrfs_csum_item); | 204 | struct btrfs_csum_item); |
205 | ret = 0; | 205 | ret = 0; |
206 | item += csum_offset; | 206 | item = (struct btrfs_csum_item *)((unsigned char *)item + |
207 | csum_offset * BTRFS_CRC32_SIZE); | ||
207 | found: | 208 | found: |
208 | btrfs_check_bounds(item->csum, BTRFS_CSUM_SIZE, path->nodes[0]->b_data, root->fs_info->sb->s_blocksize); | 209 | btrfs_check_bounds(&item->csum, BTRFS_CRC32_SIZE, |
209 | ret = btrfs_csum_data(root, data, len, item->csum); | 210 | path->nodes[0]->b_data, |
211 | root->fs_info->sb->s_blocksize); | ||
212 | ret = btrfs_csum_data(root, data, len, &item->csum); | ||
210 | btrfs_mark_buffer_dirty(path->nodes[0]); | 213 | btrfs_mark_buffer_dirty(path->nodes[0]); |
211 | fail: | 214 | fail: |
212 | btrfs_release_path(root, path); | 215 | btrfs_release_path(root, path); |
@@ -222,7 +225,7 @@ int btrfs_csum_verify_file_block(struct btrfs_root *root, | |||
222 | struct btrfs_key file_key; | 225 | struct btrfs_key file_key; |
223 | struct btrfs_path *path; | 226 | struct btrfs_path *path; |
224 | struct btrfs_csum_item *item; | 227 | struct btrfs_csum_item *item; |
225 | char result[BTRFS_CSUM_SIZE]; | 228 | char result[BTRFS_CRC32_SIZE]; |
226 | 229 | ||
227 | path = btrfs_alloc_path(); | 230 | path = btrfs_alloc_path(); |
228 | BUG_ON(!path); | 231 | BUG_ON(!path); |
@@ -244,7 +247,7 @@ int btrfs_csum_verify_file_block(struct btrfs_root *root, | |||
244 | 247 | ||
245 | ret = btrfs_csum_data(root, data, len, result); | 248 | ret = btrfs_csum_data(root, data, len, result); |
246 | WARN_ON(ret); | 249 | WARN_ON(ret); |
247 | if (memcmp(result, item->csum, BTRFS_CSUM_SIZE)) | 250 | if (memcmp(result, &item->csum, BTRFS_CRC32_SIZE)) |
248 | ret = 1; | 251 | ret = 1; |
249 | fail: | 252 | fail: |
250 | btrfs_release_path(root, path); | 253 | btrfs_release_path(root, path); |