From 39eff20bd938bae630270a3f06b17f787663826c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 18 May 2018 12:27:35 -0400 Subject: use return codes from fiemap --- lib/extent-map.c | 10 ++++++---- lib/extent-map.h | 2 +- src/cow-extent-map.c | 3 +-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/extent-map.c b/lib/extent-map.c index b698fa1..297448c 100644 --- a/lib/extent-map.c +++ b/lib/extent-map.c @@ -2,13 +2,15 @@ #include /* for error(3gnu) */ #include /* for all of the other fiemap stuff */ #include /* for FS_IOC_FIEMAP */ -#include /* for calloc(3p), exit(3p), EXIT_SUCCESS, EXIT_FAILURE */ +#include /* for calloc(3p), EXIT_SUCCESS, EXIT_FAILURE */ #include /* for ioctl(2) */ #include /* for sysconf(3p), _SC_PAGESIZE */ #include "extent-map.h" -void fiemap(int fd, uint32_t flags, int (*handle_extent)(struct fiemap_extent)) { +#define error(_exit_code, ...) do { error(0, __VA_ARGS__); if (_exit_code) return _exit_code; } while(0) + +int fiemap(int fd, uint32_t flags, int (*handle_extent)(struct fiemap_extent)) { const size_t fm_size = sysconf(_SC_PAGESIZE);; struct fiemap *fm = calloc(1, fm_size); if (!fm) @@ -29,12 +31,12 @@ void fiemap(int fd, uint32_t flags, int (*handle_extent)(struct fiemap_extent)) int r = handle_extent(fm->fm_extents[i]); if (r) { free(fm); - exit(r); + return r; } if (fm->fm_extents[i].fe_flags & FIEMAP_EXTENT_LAST) { free(fm); - exit(EXIT_SUCCESS); + return EXIT_SUCCESS; } } } diff --git a/lib/extent-map.h b/lib/extent-map.h index 4f873a0..8b5e585 100644 --- a/lib/extent-map.h +++ b/lib/extent-map.h @@ -1,4 +1,4 @@ #include /* for uint32_t */ #include /* for struct fiemap_extent */ -void fiemap(int fd, uint32_t flags, int (*handle_extent)(struct fiemap_extent)); +int fiemap(int fd, uint32_t flags, int (*handle_extent)(struct fiemap_extent)); diff --git a/src/cow-extent-map.c b/src/cow-extent-map.c index 1d9ae2c..1a791a0 100644 --- a/src/cow-extent-map.c +++ b/src/cow-extent-map.c @@ -170,6 +170,5 @@ int main(int argc, char *argv[]) { if (fd < 0) error(EXIT_FAILURE, errno, "%s", filename); - fiemap(fd, flags, print_extent); - return EXIT_SUCCESS;; + return fiemap(fd, flags, print_extent); } -- cgit v1.2.3-2-g168b