static int test_fiemap(const char *path) { _cleanup_free_ struct fiemap *fiemap = NULL; _cleanup_close_ int fd = -1; int r; log_info("/* %s */", __func__); fd = open(path, O_RDONLY | O_CLOEXEC | O_NONBLOCK); if (fd < 0) return log_error_errno(errno, "failed to open %s: %m", path); r = read_fiemap(fd, &fiemap); if (r == -EOPNOTSUPP) exit(log_tests_skipped("Not supported")); if (r < 0) return log_error_errno(r, "Unable to read extent map for '%s': %m", path); log_info("extent map information for %s:", path); log_info("\t start: %" PRIu64, (uint64_t) fiemap->fm_start); log_info("\t length: %" PRIu64, (uint64_t) fiemap->fm_length); log_info("\t flags: %" PRIu32, fiemap->fm_flags); log_info("\t number of mapped extents: %" PRIu32, fiemap->fm_mapped_extents); log_info("\t extent count: %" PRIu32, fiemap->fm_extent_count); if (fiemap->fm_extent_count > 0) log_info("\t first extent location: %" PRIu64, (uint64_t) (fiemap->fm_extents[0].fe_physical / page_size())); return 0; }
static int test_fiemap(const char *path) { _cleanup_free_ struct fiemap *fiemap = NULL; _cleanup_close_ int fd = -1; int r; fd = open(path, O_RDONLY | O_CLOEXEC | O_NONBLOCK); if (fd < 0) return log_error_errno(errno, "failed to open %s: %m", path); r = read_fiemap(fd, &fiemap); if (r == -EOPNOTSUPP) { log_info("Skipping test, not supported"); exit(EXIT_TEST_SKIP); } if (r < 0) return log_error_errno(r, "Unable to read extent map for '%s': %m", path); log_info("extent map information for %s:", path); log_info("\t start: %llu", fiemap->fm_start); log_info("\t length: %llu", fiemap->fm_length); log_info("\t flags: %u", fiemap->fm_flags); log_info("\t number of mapped extents: %u", fiemap->fm_mapped_extents); log_info("\t extent count: %u", fiemap->fm_extent_count); if (fiemap->fm_extent_count > 0) log_info("\t first extent location: %llu", fiemap->fm_extents[0].fe_physical / page_size()); return 0; }
/* * Use FIEMAP to determine the extents that make up a file. * Allocate eblocks_used array based on length of file, and then mark * the set of eblocks that contain data based on the extents. * Returns the index of the last occupied eblock. */ static long read_extents(FILE *infile) { int i; struct fiemap *fiemap = read_fiemap(fileno(infile)); long ret = 0; LTC_ARGCHK(fiemap != NULL); eblocks_used = malloc(eblocks); LTC_ARGCHK(eblocks_used != 0); memset(eblocks_used, 0, eblocks); for (i=0; i < fiemap->fm_mapped_extents; i++) ret = process_extent(&fiemap->fm_extents[i]); return ret; }