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; }