aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/file-item.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-05-29 15:17:08 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-05-29 15:17:08 -0400
commit1de037a43edf67f3a9f66dd197195b3c08febb16 (patch)
treeeba718d502f766f9527fcdc43961fb082641f3ac /fs/btrfs/file-item.c
parent3a686375629da5d2e2ad019265b66ef113c87455 (diff)
Btrfs: fixup various fsx failures
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/file-item.c')
-rw-r--r--fs/btrfs/file-item.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 7990b5742114..0782e924ddeb 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -2,6 +2,7 @@
2#include "ctree.h" 2#include "ctree.h"
3#include "disk-io.h" 3#include "disk-io.h"
4#include "transaction.h" 4#include "transaction.h"
5#include "print-tree.h"
5 6
6#define MAX_CSUM_ITEMS(r) ((((BTRFS_LEAF_DATA_SIZE(r) - \ 7#define MAX_CSUM_ITEMS(r) ((((BTRFS_LEAF_DATA_SIZE(r) - \
7 sizeof(struct btrfs_item) * 2) / \ 8 sizeof(struct btrfs_item) * 2) / \
@@ -27,6 +28,10 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
27 28
28 ret = btrfs_insert_empty_item(trans, root, path, &file_key, 29 ret = btrfs_insert_empty_item(trans, root, path, &file_key,
29 sizeof(*item)); 30 sizeof(*item));
31 if (ret) {
32printk("failed to insert %Lu %Lu ret %d\n", objectid, pos, ret);
33btrfs_print_leaf(root, btrfs_buffer_leaf(path->nodes[0]));
34 }
30 BUG_ON(ret); 35 BUG_ON(ret);
31 item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0], 36 item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0],
32 struct btrfs_file_extent_item); 37 struct btrfs_file_extent_item);
@@ -218,6 +223,31 @@ fail:
218 return ret; 223 return ret;
219} 224}
220 225
226int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
227 struct btrfs_root *root, struct btrfs_path *path,
228 u64 isize)
229{
230 struct btrfs_key key;
231 struct btrfs_leaf *leaf = btrfs_buffer_leaf(path->nodes[0]);
232 int slot = path->slots[0];
233 int ret;
234 u32 new_item_size;
235 u64 new_item_span;
236 u64 blocks;
237
238 btrfs_disk_key_to_cpu(&key, &leaf->items[slot].key);
239 if (isize <= key.offset)
240 return 0;
241 new_item_span = isize - key.offset;
242 blocks = (new_item_span + root->blocksize - 1) / root->blocksize;
243 new_item_size = blocks * BTRFS_CRC32_SIZE;
244 if (new_item_size >= btrfs_item_size(leaf->items + slot))
245 return 0;
246 ret = btrfs_truncate_item(trans, root, path, new_item_size);
247 BUG_ON(ret);
248 return ret;
249}
250
221int btrfs_csum_verify_file_block(struct btrfs_root *root, 251int btrfs_csum_verify_file_block(struct btrfs_root *root,
222 u64 objectid, u64 offset, 252 u64 objectid, u64 offset,
223 char *data, size_t len) 253 char *data, size_t len)