Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 128388
b: refs/heads/master
c: 1de037a
h: refs/heads/master
v: v3
  • Loading branch information
Chris Mason authored and David Woodhouse committed May 29, 2007
1 parent 5727796 commit 062352d
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 33 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 3a686375629da5d2e2ad019265b66ef113c87455
refs/heads/master: 1de037a43edf67f3a9f66dd197195b3c08febb16
3 changes: 3 additions & 0 deletions trunk/fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1198,5 +1198,8 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
struct btrfs_path *path,
u64 objectid, u64 offset,
int cow);
int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_path *path,
u64 isize);
/* super.c */
#endif
30 changes: 30 additions & 0 deletions trunk/fs/btrfs/file-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) / \
Expand All @@ -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);
Expand Down Expand Up @@ -218,6 +223,31 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
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)
Expand Down
Loading

0 comments on commit 062352d

Please sign in to comment.