aboutsummaryrefslogtreecommitdiff
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 7990b574211..0782e924dde 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -2,6 +2,7 @@
#include "ctree.h"
#include "disk-io.h"
#include "transaction.h"
+#include "print-tree.h"
#define MAX_CSUM_ITEMS(r) ((((BTRFS_LEAF_DATA_SIZE(r) - \
sizeof(struct btrfs_item) * 2) / \
@@ -27,6 +28,10 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
ret = btrfs_insert_empty_item(trans, root, path, &file_key,
sizeof(*item));
+ if (ret) {
+printk("failed to insert %Lu %Lu ret %d\n", objectid, pos, ret);
+btrfs_print_leaf(root, btrfs_buffer_leaf(path->nodes[0]));
+ }
BUG_ON(ret);
item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0],
struct btrfs_file_extent_item);
@@ -218,6 +223,31 @@ fail:
return ret;
}
+int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root, struct btrfs_path *path,
+ u64 isize)
+{
+ struct btrfs_key key;
+ struct btrfs_leaf *leaf = btrfs_buffer_leaf(path->nodes[0]);
+ int slot = path->slots[0];
+ int ret;
+ u32 new_item_size;
+ u64 new_item_span;
+ u64 blocks;
+
+ btrfs_disk_key_to_cpu(&key, &leaf->items[slot].key);
+ if (isize <= key.offset)
+ return 0;
+ new_item_span = isize - key.offset;
+ blocks = (new_item_span + root->blocksize - 1) / root->blocksize;
+ new_item_size = blocks * BTRFS_CRC32_SIZE;
+ if (new_item_size >= btrfs_item_size(leaf->items + slot))
+ return 0;
+ ret = btrfs_truncate_item(trans, root, path, new_item_size);
+ BUG_ON(ret);
+ return ret;
+}
+
int btrfs_csum_verify_file_block(struct btrfs_root *root,
u64 objectid, u64 offset,
char *data, size_t len)