summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/extent-map.c10
-rw-r--r--lib/extent-map.h2
-rw-r--r--src/cow-extent-map.c3
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 <error.h> /* for error(3gnu) */
#include <linux/fiemap.h> /* for all of the other fiemap stuff */
#include <linux/fs.h> /* for FS_IOC_FIEMAP */
-#include <stdlib.h> /* for calloc(3p), exit(3p), EXIT_SUCCESS, EXIT_FAILURE */
+#include <stdlib.h> /* for calloc(3p), EXIT_SUCCESS, EXIT_FAILURE */
#include <sys/ioctl.h> /* for ioctl(2) */
#include <unistd.h> /* 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 <stdint.h> /* for uint32_t */
#include <linux/fiemap.h> /* 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);
}