Chris Mason | 2e635a2 | 2007-03-21 11:12:56 -0400 | [diff] [blame] | 1 | #include <linux/module.h> |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 2 | #include "ctree.h" |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 3 | #include "disk-io.h" |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 4 | #include "transaction.h" |
Chris Mason | 1de037a | 2007-05-29 15:17:08 -0400 | [diff] [blame] | 5 | #include "print-tree.h" |
Chris Mason | 1e1d270 | 2007-03-15 19:03:33 -0400 | [diff] [blame] | 6 | |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 7 | #define MAX_CSUM_ITEMS(r) ((((BTRFS_LEAF_DATA_SIZE(r) - \ |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 8 | sizeof(struct btrfs_item) * 2) / \ |
| 9 | BTRFS_CRC32_SIZE) - 1)) |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 10 | int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 11 | struct btrfs_root *root, |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 12 | u64 objectid, u64 pos, |
Chris Mason | 3a68637 | 2007-05-24 13:35:57 -0400 | [diff] [blame] | 13 | u64 offset, u64 disk_num_blocks, |
| 14 | u64 num_blocks) |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 15 | { |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 16 | int ret = 0; |
| 17 | struct btrfs_file_extent_item *item; |
| 18 | struct btrfs_key file_key; |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 19 | struct btrfs_path *path; |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 20 | |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 21 | path = btrfs_alloc_path(); |
| 22 | BUG_ON(!path); |
| 23 | btrfs_init_path(path); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 24 | file_key.objectid = objectid; |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 25 | file_key.offset = pos; |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 26 | file_key.flags = 0; |
| 27 | btrfs_set_key_type(&file_key, BTRFS_EXTENT_DATA_KEY); |
| 28 | |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 29 | ret = btrfs_insert_empty_item(trans, root, path, &file_key, |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 30 | sizeof(*item)); |
Chris Mason | 1de037a | 2007-05-29 15:17:08 -0400 | [diff] [blame] | 31 | if (ret) { |
| 32 | printk("failed to insert %Lu %Lu ret %d\n", objectid, pos, ret); |
| 33 | btrfs_print_leaf(root, btrfs_buffer_leaf(path->nodes[0])); |
| 34 | } |
Chris Mason | 9773a78 | 2007-03-27 11:26:26 -0400 | [diff] [blame] | 35 | BUG_ON(ret); |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 36 | item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0], |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 37 | struct btrfs_file_extent_item); |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 38 | btrfs_set_file_extent_disk_blocknr(item, offset); |
Chris Mason | 3a68637 | 2007-05-24 13:35:57 -0400 | [diff] [blame] | 39 | btrfs_set_file_extent_disk_num_blocks(item, disk_num_blocks); |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 40 | btrfs_set_file_extent_offset(item, 0); |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 41 | btrfs_set_file_extent_num_blocks(item, num_blocks); |
Chris Mason | 71951f3 | 2007-03-27 09:16:29 -0400 | [diff] [blame] | 42 | btrfs_set_file_extent_generation(item, trans->transid); |
Chris Mason | 236454df | 2007-04-19 13:37:44 -0400 | [diff] [blame] | 43 | btrfs_set_file_extent_type(item, BTRFS_FILE_EXTENT_REG); |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 44 | btrfs_mark_buffer_dirty(path->nodes[0]); |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 45 | |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 46 | btrfs_release_path(root, path); |
| 47 | btrfs_free_path(path); |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 48 | return 0; |
| 49 | } |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 50 | |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 51 | struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, |
| 52 | struct btrfs_root *root, |
| 53 | struct btrfs_path *path, |
| 54 | u64 objectid, u64 offset, |
| 55 | int cow) |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 56 | { |
| 57 | int ret; |
| 58 | struct btrfs_key file_key; |
| 59 | struct btrfs_key found_key; |
| 60 | struct btrfs_csum_item *item; |
| 61 | struct btrfs_leaf *leaf; |
| 62 | u64 csum_offset = 0; |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 63 | int csums_in_item; |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 64 | |
| 65 | file_key.objectid = objectid; |
| 66 | file_key.offset = offset; |
| 67 | file_key.flags = 0; |
| 68 | btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 69 | ret = btrfs_search_slot(trans, root, &file_key, path, 0, cow); |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 70 | if (ret < 0) |
| 71 | goto fail; |
| 72 | leaf = btrfs_buffer_leaf(path->nodes[0]); |
| 73 | if (ret > 0) { |
| 74 | ret = 1; |
Chris Mason | 70b2bef | 2007-04-17 15:39:32 -0400 | [diff] [blame] | 75 | if (path->slots[0] == 0) |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 76 | goto fail; |
| 77 | path->slots[0]--; |
| 78 | btrfs_disk_key_to_cpu(&found_key, |
| 79 | &leaf->items[path->slots[0]].key); |
| 80 | if (btrfs_key_type(&found_key) != BTRFS_CSUM_ITEM_KEY || |
| 81 | found_key.objectid != objectid) { |
| 82 | goto fail; |
| 83 | } |
| 84 | csum_offset = (offset - found_key.offset) >> |
| 85 | root->fs_info->sb->s_blocksize_bits; |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 86 | csums_in_item = btrfs_item_size(leaf->items + path->slots[0]); |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 87 | csums_in_item /= BTRFS_CRC32_SIZE; |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 88 | |
| 89 | if (csum_offset >= csums_in_item) { |
| 90 | ret = -EFBIG; |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 91 | goto fail; |
| 92 | } |
| 93 | } |
| 94 | item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_csum_item); |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 95 | item = (struct btrfs_csum_item *)((unsigned char *)item + |
| 96 | csum_offset * BTRFS_CRC32_SIZE); |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 97 | return item; |
| 98 | fail: |
| 99 | if (ret > 0) |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 100 | ret = -ENOENT; |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 101 | return ERR_PTR(ret); |
| 102 | } |
| 103 | |
| 104 | |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 105 | int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, |
| 106 | struct btrfs_root *root, |
| 107 | struct btrfs_path *path, u64 objectid, |
Chris Mason | 9773a78 | 2007-03-27 11:26:26 -0400 | [diff] [blame] | 108 | u64 offset, int mod) |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 109 | { |
| 110 | int ret; |
| 111 | struct btrfs_key file_key; |
| 112 | int ins_len = mod < 0 ? -1 : 0; |
| 113 | int cow = mod != 0; |
| 114 | |
| 115 | file_key.objectid = objectid; |
Chris Mason | 70b2bef | 2007-04-17 15:39:32 -0400 | [diff] [blame] | 116 | file_key.offset = offset; |
Chris Mason | dee26a9 | 2007-03-26 16:00:06 -0400 | [diff] [blame] | 117 | file_key.flags = 0; |
| 118 | btrfs_set_key_type(&file_key, BTRFS_EXTENT_DATA_KEY); |
| 119 | ret = btrfs_search_slot(trans, root, &file_key, path, ins_len, cow); |
| 120 | return ret; |
| 121 | } |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 122 | |
| 123 | int btrfs_csum_file_block(struct btrfs_trans_handle *trans, |
| 124 | struct btrfs_root *root, |
| 125 | u64 objectid, u64 offset, |
| 126 | char *data, size_t len) |
| 127 | { |
| 128 | int ret; |
| 129 | struct btrfs_key file_key; |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 130 | struct btrfs_key found_key; |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 131 | struct btrfs_path *path; |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 132 | struct btrfs_csum_item *item; |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 133 | struct btrfs_leaf *leaf; |
| 134 | u64 csum_offset; |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 135 | |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 136 | path = btrfs_alloc_path(); |
| 137 | BUG_ON(!path); |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 138 | |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 139 | file_key.objectid = objectid; |
| 140 | file_key.offset = offset; |
| 141 | file_key.flags = 0; |
| 142 | btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 143 | |
| 144 | item = btrfs_lookup_csum(trans, root, path, objectid, offset, 1); |
| 145 | if (!IS_ERR(item)) |
| 146 | goto found; |
| 147 | ret = PTR_ERR(item); |
| 148 | if (ret == -EFBIG) { |
| 149 | u32 item_size; |
| 150 | /* we found one, but it isn't big enough yet */ |
| 151 | leaf = btrfs_buffer_leaf(path->nodes[0]); |
| 152 | item_size = btrfs_item_size(leaf->items + path->slots[0]); |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 153 | if ((item_size / BTRFS_CRC32_SIZE) >= MAX_CSUM_ITEMS(root)) { |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 154 | /* already at max size, make a new one */ |
| 155 | goto insert; |
| 156 | } |
| 157 | } else { |
| 158 | /* we didn't find a csum item, insert one */ |
| 159 | goto insert; |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * at this point, we know the tree has an item, but it isn't big |
| 164 | * enough yet to put our csum in. Grow it |
| 165 | */ |
| 166 | btrfs_release_path(root, path); |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 167 | ret = btrfs_search_slot(trans, root, &file_key, path, |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 168 | BTRFS_CRC32_SIZE, 1); |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 169 | if (ret < 0) |
| 170 | goto fail; |
| 171 | if (ret == 0) { |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 172 | BUG(); |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 173 | } |
| 174 | if (path->slots[0] == 0) { |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 175 | goto insert; |
| 176 | } |
| 177 | path->slots[0]--; |
| 178 | leaf = btrfs_buffer_leaf(path->nodes[0]); |
| 179 | btrfs_disk_key_to_cpu(&found_key, &leaf->items[path->slots[0]].key); |
| 180 | csum_offset = (offset - found_key.offset) >> |
| 181 | root->fs_info->sb->s_blocksize_bits; |
| 182 | if (btrfs_key_type(&found_key) != BTRFS_CSUM_ITEM_KEY || |
| 183 | found_key.objectid != objectid || |
| 184 | csum_offset >= MAX_CSUM_ITEMS(root)) { |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 185 | goto insert; |
| 186 | } |
| 187 | if (csum_offset >= btrfs_item_size(leaf->items + path->slots[0]) / |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 188 | BTRFS_CRC32_SIZE) { |
| 189 | u32 diff = (csum_offset + 1) * BTRFS_CRC32_SIZE; |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 190 | diff = diff - btrfs_item_size(leaf->items + path->slots[0]); |
Chris Mason | 3a68637 | 2007-05-24 13:35:57 -0400 | [diff] [blame] | 191 | if (diff != BTRFS_CRC32_SIZE) |
| 192 | goto insert; |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 193 | ret = btrfs_extend_item(trans, root, path, diff); |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 194 | BUG_ON(ret); |
| 195 | goto csum; |
| 196 | } |
| 197 | |
| 198 | insert: |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 199 | btrfs_release_path(root, path); |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 200 | csum_offset = 0; |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 201 | ret = btrfs_insert_empty_item(trans, root, path, &file_key, |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 202 | BTRFS_CRC32_SIZE); |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 203 | if (ret != 0) { |
| 204 | printk("at insert for %Lu %u %Lu ret is %d\n", file_key.objectid, file_key.flags, file_key.offset, ret); |
| 205 | WARN_ON(1); |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 206 | goto fail; |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 207 | } |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 208 | csum: |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 209 | item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0], |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 210 | struct btrfs_csum_item); |
| 211 | ret = 0; |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 212 | item = (struct btrfs_csum_item *)((unsigned char *)item + |
| 213 | csum_offset * BTRFS_CRC32_SIZE); |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 214 | found: |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 215 | btrfs_check_bounds(&item->csum, BTRFS_CRC32_SIZE, |
| 216 | path->nodes[0]->b_data, |
| 217 | root->fs_info->sb->s_blocksize); |
| 218 | ret = btrfs_csum_data(root, data, len, &item->csum); |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 219 | btrfs_mark_buffer_dirty(path->nodes[0]); |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 220 | fail: |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 221 | btrfs_release_path(root, path); |
| 222 | btrfs_free_path(path); |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 223 | return ret; |
| 224 | } |
| 225 | |
Chris Mason | 1de037a | 2007-05-29 15:17:08 -0400 | [diff] [blame] | 226 | int 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; |
Chris Mason | 84f54cf | 2007-06-12 07:43:08 -0400 | [diff] [blame^] | 242 | blocks = (new_item_span + root->blocksize - 1) >> |
| 243 | root->fs_info->sb->s_blocksize_bits; |
Chris Mason | 1de037a | 2007-05-29 15:17:08 -0400 | [diff] [blame] | 244 | new_item_size = blocks * BTRFS_CRC32_SIZE; |
| 245 | if (new_item_size >= btrfs_item_size(leaf->items + slot)) |
| 246 | return 0; |
| 247 | ret = btrfs_truncate_item(trans, root, path, new_item_size); |
| 248 | BUG_ON(ret); |
| 249 | return ret; |
| 250 | } |
| 251 | |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 252 | int btrfs_csum_verify_file_block(struct btrfs_root *root, |
| 253 | u64 objectid, u64 offset, |
| 254 | char *data, size_t len) |
| 255 | { |
| 256 | int ret; |
| 257 | struct btrfs_key file_key; |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 258 | struct btrfs_path *path; |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 259 | struct btrfs_csum_item *item; |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 260 | char result[BTRFS_CRC32_SIZE]; |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 261 | |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 262 | path = btrfs_alloc_path(); |
| 263 | BUG_ON(!path); |
| 264 | btrfs_init_path(path); |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 265 | file_key.objectid = objectid; |
| 266 | file_key.offset = offset; |
| 267 | file_key.flags = 0; |
| 268 | btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); |
Chris Mason | 2da566e | 2007-04-02 15:43:21 -0400 | [diff] [blame] | 269 | mutex_lock(&root->fs_info->fs_mutex); |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 270 | |
Chris Mason | b18c668 | 2007-04-17 13:26:50 -0400 | [diff] [blame] | 271 | item = btrfs_lookup_csum(NULL, root, path, objectid, offset, 0); |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 272 | if (IS_ERR(item)) { |
| 273 | ret = PTR_ERR(item); |
Chris Mason | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 274 | /* a csum that isn't present is a preallocated region. */ |
| 275 | if (ret == -ENOENT || ret == -EFBIG) |
Chris Mason | 3a68637 | 2007-05-24 13:35:57 -0400 | [diff] [blame] | 276 | ret = -ENOENT; |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 277 | goto fail; |
Chris Mason | 6567e83 | 2007-04-16 09:22:45 -0400 | [diff] [blame] | 278 | } |
| 279 | |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 280 | ret = btrfs_csum_data(root, data, len, result); |
| 281 | WARN_ON(ret); |
Chris Mason | 509659c | 2007-05-10 12:36:17 -0400 | [diff] [blame] | 282 | if (memcmp(result, &item->csum, BTRFS_CRC32_SIZE)) |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 283 | ret = 1; |
| 284 | fail: |
Chris Mason | 5caf2a0 | 2007-04-02 11:20:42 -0400 | [diff] [blame] | 285 | btrfs_release_path(root, path); |
| 286 | btrfs_free_path(path); |
Chris Mason | 2da566e | 2007-04-02 15:43:21 -0400 | [diff] [blame] | 287 | mutex_unlock(&root->fs_info->fs_mutex); |
Chris Mason | f254e52 | 2007-03-29 15:15:27 -0400 | [diff] [blame] | 288 | return ret; |
| 289 | } |
| 290 | |