From 029ebb5ef4abaff449602545f9b78294301ea9e1 Mon Sep 17 00:00:00 2001 From: mbloch Date: Mon, 8 Oct 2012 18:11:21 +0100 Subject: [PATCH] Fixed build_allocation_map in ioutil.c to correctly traverse fiemaps where there are more than 1000 extents in a 100MB file chunk. --- src/ioutil.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ioutil.c b/src/ioutil.c index 3c92c3b..92b8f5f 100644 --- a/src/ioutil.c +++ b/src/ioutil.c @@ -27,7 +27,8 @@ int build_allocation_map(struct bitset_mapping* allocation_map, int fd) memset(&fiemap_static, 0, sizeof(fiemap_static)); - for (offset = 0; offset < allocation_map->size; offset += fiemap->fm_length) { + for (offset = 0; offset < allocation_map->size; ) { + unsigned int i; fiemap->fm_start = offset; @@ -41,7 +42,7 @@ int build_allocation_map(struct bitset_mapping* allocation_map, int fd) if (ioctl(fd, FS_IOC_FIEMAP, fiemap) < 0) { debug( "Couldn't get fiemap, returning no allocation_map" ); free(allocation_map); - return NULL; + return 0; } for (i=0;ifm_mapped_extents;i++) { @@ -52,10 +53,24 @@ int build_allocation_map(struct bitset_mapping* allocation_map, int fd) ); //debug("range from %ld + %ld", fiemap->fm_extents[i].fe_logical, fiemap->fm_extents[i].fe_length); } + + /* must move the offset on, but careful not to jump max_length + * if we've actually hit max_offsets. + */ + if (fiemap->fm_mapped_extents > 0) { + struct fiemap_extent *last = &fiemap->fm_extents[ + fiemap->fm_mapped_extents-1 + ]; + offset += last->fe_logical + last->fe_length; + } + else { + offset += fiemap->fm_length; + } + } debug("Successfully built allocation map"); - return allocation_map; + return 1; }