diff options
Diffstat (limited to 'fs/btrfs/file-item.c')
-rw-r--r-- | fs/btrfs/file-item.c | 46 |
1 files changed, 6 insertions, 40 deletions
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index cf894f09f6c7..68859934ae25 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c | |||
@@ -45,6 +45,8 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, | |||
45 | 45 | ||
46 | ret = btrfs_insert_empty_item(trans, root, path, &file_key, | 46 | ret = btrfs_insert_empty_item(trans, root, path, &file_key, |
47 | sizeof(*item)); | 47 | sizeof(*item)); |
48 | if (ret < 0) | ||
49 | goto out; | ||
48 | BUG_ON(ret); | 50 | BUG_ON(ret); |
49 | item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0], | 51 | item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0], |
50 | struct btrfs_file_extent_item); | 52 | struct btrfs_file_extent_item); |
@@ -55,10 +57,9 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, | |||
55 | btrfs_set_file_extent_generation(item, trans->transid); | 57 | btrfs_set_file_extent_generation(item, trans->transid); |
56 | btrfs_set_file_extent_type(item, BTRFS_FILE_EXTENT_REG); | 58 | btrfs_set_file_extent_type(item, BTRFS_FILE_EXTENT_REG); |
57 | btrfs_mark_buffer_dirty(path->nodes[0]); | 59 | btrfs_mark_buffer_dirty(path->nodes[0]); |
58 | 60 | out: | |
59 | btrfs_release_path(root, path); | ||
60 | btrfs_free_path(path); | 61 | btrfs_free_path(path); |
61 | return 0; | 62 | return ret; |
62 | } | 63 | } |
63 | 64 | ||
64 | struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, | 65 | struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, |
@@ -213,6 +214,8 @@ insert: | |||
213 | csum_offset = 0; | 214 | csum_offset = 0; |
214 | ret = btrfs_insert_empty_item(trans, root, path, &file_key, | 215 | ret = btrfs_insert_empty_item(trans, root, path, &file_key, |
215 | BTRFS_CRC32_SIZE); | 216 | BTRFS_CRC32_SIZE); |
217 | if (ret < 0) | ||
218 | goto fail; | ||
216 | if (ret != 0) { | 219 | if (ret != 0) { |
217 | WARN_ON(1); | 220 | WARN_ON(1); |
218 | goto fail; | 221 | goto fail; |
@@ -261,40 +264,3 @@ int btrfs_csum_truncate(struct btrfs_trans_handle *trans, | |||
261 | return ret; | 264 | return ret; |
262 | } | 265 | } |
263 | 266 | ||
264 | int btrfs_csum_verify_file_block(struct btrfs_root *root, | ||
265 | u64 objectid, u64 offset, | ||
266 | char *data, size_t len) | ||
267 | { | ||
268 | int ret; | ||
269 | struct btrfs_key file_key; | ||
270 | struct btrfs_path *path; | ||
271 | struct btrfs_csum_item *item; | ||
272 | char result[BTRFS_CRC32_SIZE]; | ||
273 | |||
274 | path = btrfs_alloc_path(); | ||
275 | BUG_ON(!path); | ||
276 | file_key.objectid = objectid; | ||
277 | file_key.offset = offset; | ||
278 | file_key.flags = 0; | ||
279 | btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); | ||
280 | mutex_lock(&root->fs_info->fs_mutex); | ||
281 | |||
282 | item = btrfs_lookup_csum(NULL, root, path, objectid, offset, 0); | ||
283 | if (IS_ERR(item)) { | ||
284 | ret = PTR_ERR(item); | ||
285 | /* a csum that isn't present is a preallocated region. */ | ||
286 | if (ret == -ENOENT || ret == -EFBIG) | ||
287 | ret = -ENOENT; | ||
288 | goto fail; | ||
289 | } | ||
290 | |||
291 | ret = btrfs_csum_data(root, data, len, result); | ||
292 | WARN_ON(ret); | ||
293 | if (memcmp(result, &item->csum, BTRFS_CRC32_SIZE)) | ||
294 | ret = 1; | ||
295 | fail: | ||
296 | btrfs_release_path(root, path); | ||
297 | btrfs_free_path(path); | ||
298 | mutex_unlock(&root->fs_info->fs_mutex); | ||
299 | return ret; | ||
300 | } | ||