extent_io.c (a583c02664eea8796e80dd192a3bcc1d521939e5) | extent_io.c (dc046b10c8b7d4f40befe457acb82340bf8b0699) |
---|---|
1#include <linux/bitops.h> 2#include <linux/slab.h> 3#include <linux/bio.h> 4#include <linux/mm.h> 5#include <linux/pagemap.h> 6#include <linux/page-flags.h> 7#include <linux/spinlock.h> 8#include <linux/blkdev.h> --- 4155 unchanged lines hidden (view full) --- 4164 offset = extent_map_end(em); 4165 free_extent_map(em); 4166 if (offset >= last) 4167 break; 4168 } 4169 return NULL; 4170} 4171 | 1#include <linux/bitops.h> 2#include <linux/slab.h> 3#include <linux/bio.h> 4#include <linux/mm.h> 5#include <linux/pagemap.h> 6#include <linux/page-flags.h> 7#include <linux/spinlock.h> 8#include <linux/blkdev.h> --- 4155 unchanged lines hidden (view full) --- 4164 offset = extent_map_end(em); 4165 free_extent_map(em); 4166 if (offset >= last) 4167 break; 4168 } 4169 return NULL; 4170} 4171 |
4172static noinline int count_ext_ref(u64 inum, u64 offset, u64 root_id, void *ctx) 4173{ 4174 unsigned long cnt = *((unsigned long *)ctx); 4175 4176 cnt++; 4177 *((unsigned long *)ctx) = cnt; 4178 4179 /* Now we're sure that the extent is shared. */ 4180 if (cnt > 1) 4181 return 1; 4182 return 0; 4183} 4184 | |
4185int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 4186 __u64 start, __u64 len, get_extent_t *get_extent) 4187{ 4188 int ret = 0; 4189 u64 off = start; 4190 u64 max = start + len; 4191 u32 flags = 0; 4192 u32 found_type; 4193 u64 last; 4194 u64 last_for_get_extent = 0; 4195 u64 disko = 0; 4196 u64 isize = i_size_read(inode); 4197 struct btrfs_key found_key; 4198 struct extent_map *em = NULL; 4199 struct extent_state *cached_state = NULL; 4200 struct btrfs_path *path; | 4172int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 4173 __u64 start, __u64 len, get_extent_t *get_extent) 4174{ 4175 int ret = 0; 4176 u64 off = start; 4177 u64 max = start + len; 4178 u32 flags = 0; 4179 u32 found_type; 4180 u64 last; 4181 u64 last_for_get_extent = 0; 4182 u64 disko = 0; 4183 u64 isize = i_size_read(inode); 4184 struct btrfs_key found_key; 4185 struct extent_map *em = NULL; 4186 struct extent_state *cached_state = NULL; 4187 struct btrfs_path *path; |
4188 struct btrfs_root *root = BTRFS_I(inode)->root; |
|
4201 int end = 0; 4202 u64 em_start = 0; 4203 u64 em_len = 0; 4204 u64 em_end = 0; 4205 4206 if (len == 0) 4207 return -EINVAL; 4208 --- 4 unchanged lines hidden (view full) --- 4213 4214 start = round_down(start, BTRFS_I(inode)->root->sectorsize); 4215 len = round_up(max, BTRFS_I(inode)->root->sectorsize) - start; 4216 4217 /* 4218 * lookup the last file extent. We're not using i_size here 4219 * because there might be preallocation past i_size 4220 */ | 4189 int end = 0; 4190 u64 em_start = 0; 4191 u64 em_len = 0; 4192 u64 em_end = 0; 4193 4194 if (len == 0) 4195 return -EINVAL; 4196 --- 4 unchanged lines hidden (view full) --- 4201 4202 start = round_down(start, BTRFS_I(inode)->root->sectorsize); 4203 len = round_up(max, BTRFS_I(inode)->root->sectorsize) - start; 4204 4205 /* 4206 * lookup the last file extent. We're not using i_size here 4207 * because there might be preallocation past i_size 4208 */ |
4221 ret = btrfs_lookup_file_extent(NULL, BTRFS_I(inode)->root, 4222 path, btrfs_ino(inode), -1, 0); | 4209 ret = btrfs_lookup_file_extent(NULL, root, path, btrfs_ino(inode), -1, 4210 0); |
4223 if (ret < 0) { 4224 btrfs_free_path(path); 4225 return ret; 4226 } 4227 WARN_ON(!ret); 4228 path->slots[0]--; 4229 btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]); 4230 found_type = found_key.type; --- 76 unchanged lines hidden (view full) --- 4307 end = 1; 4308 flags |= FIEMAP_EXTENT_LAST; 4309 } else if (em->block_start == EXTENT_MAP_INLINE) { 4310 flags |= (FIEMAP_EXTENT_DATA_INLINE | 4311 FIEMAP_EXTENT_NOT_ALIGNED); 4312 } else if (em->block_start == EXTENT_MAP_DELALLOC) { 4313 flags |= (FIEMAP_EXTENT_DELALLOC | 4314 FIEMAP_EXTENT_UNKNOWN); | 4211 if (ret < 0) { 4212 btrfs_free_path(path); 4213 return ret; 4214 } 4215 WARN_ON(!ret); 4216 path->slots[0]--; 4217 btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]); 4218 found_type = found_key.type; --- 76 unchanged lines hidden (view full) --- 4295 end = 1; 4296 flags |= FIEMAP_EXTENT_LAST; 4297 } else if (em->block_start == EXTENT_MAP_INLINE) { 4298 flags |= (FIEMAP_EXTENT_DATA_INLINE | 4299 FIEMAP_EXTENT_NOT_ALIGNED); 4300 } else if (em->block_start == EXTENT_MAP_DELALLOC) { 4301 flags |= (FIEMAP_EXTENT_DELALLOC | 4302 FIEMAP_EXTENT_UNKNOWN); |
4315 } else { 4316 unsigned long ref_cnt = 0; | 4303 } else if (fieinfo->fi_extents_max) { 4304 u64 bytenr = em->block_start - 4305 (em->start - em->orig_start); |
4317 4318 disko = em->block_start + offset_in_extent; 4319 4320 /* 4321 * As btrfs supports shared space, this information 4322 * can be exported to userspace tools via | 4306 4307 disko = em->block_start + offset_in_extent; 4308 4309 /* 4310 * As btrfs supports shared space, this information 4311 * can be exported to userspace tools via |
4323 * flag FIEMAP_EXTENT_SHARED. | 4312 * flag FIEMAP_EXTENT_SHARED. If fi_extents_max == 0 4313 * then we're just getting a count and we can skip the 4314 * lookup stuff. |
4324 */ | 4315 */ |
4325 ret = iterate_inodes_from_logical( 4326 em->block_start, 4327 BTRFS_I(inode)->root->fs_info, 4328 path, count_ext_ref, &ref_cnt); 4329 if (ret < 0 && ret != -ENOENT) | 4316 ret = btrfs_check_shared(NULL, root->fs_info, 4317 root->objectid, 4318 btrfs_ino(inode), bytenr); 4319 if (ret < 0) |
4330 goto out_free; | 4320 goto out_free; |
4331 4332 if (ref_cnt > 1) | 4321 if (ret) |
4333 flags |= FIEMAP_EXTENT_SHARED; | 4322 flags |= FIEMAP_EXTENT_SHARED; |
4323 ret = 0; |
|
4334 } 4335 if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags)) 4336 flags |= FIEMAP_EXTENT_ENCODED; 4337 4338 free_extent_map(em); 4339 em = NULL; 4340 if ((em_start >= last) || em_len == (u64)-1 || 4341 (last == (u64)-1 && isize <= em_end)) { --- 1093 unchanged lines hidden --- | 4324 } 4325 if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags)) 4326 flags |= FIEMAP_EXTENT_ENCODED; 4327 4328 free_extent_map(em); 4329 em = NULL; 4330 if ((em_start >= last) || em_len == (u64)-1 || 4331 (last == (u64)-1 && isize <= em_end)) { --- 1093 unchanged lines hidden --- |