int blocksize; /* Use specified blocksize (default 1kB) */
int sync_file = 0; /* fsync file before getting the mapping */
int xattr_map = 0; /* get xattr mapping */
-int force_bmap; /* force use of FIBMAP instead of FIEMAP */
+int force_bmap; /* force use of FIBMAP instead of FIEMAP */
int force_extent; /* print output in extent format always */
+int device_offset; /* extents report device-relative offsets */
int logical_width = 8;
int physical_width = 10;
char *ext_fmt = "%4d: %*llu..%*llu: %*llu..%*llu: %6llu: %s\n";
char *hex_fmt = "%4d: %*llx..%*llx: %*llx..%*llx: %6llx: %s\n";
-#define FILEFRAG_FIEMAP_FLAGS_COMPAT (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR)
+#define FILEFRAG_FIEMAP_FLAGS_COMPAT (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR |\
+ FIEMAP_FLAG_DEVICE_ORDER)
#define FIBMAP _IO(0x00, 1) /* bmap access */
#define FIGETBSZ _IO(0x00, 2) /* get the block size used for bmap */
{
printf(" ext: %*s %*s length: %*s flags:\n",
logical_width * 2 + 3,
- "logical_offset:",
+ device_offset ? "device_logical:" : "logical_offset:",
physical_width * 2 + 3, "physical_offset:",
- physical_width + 1,
- "expected:");
+ device_offset ? 5 : physical_width + 1,
+ device_offset ? " dev:" : "expected:");
}
static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex,
logical_blk = fm_extent->fe_logical >> blk_shift;
physical_blk = fm_extent->fe_physical >> blk_shift;
- if (expected)
- sprintf(flags, ext_fmt == hex_fmt ? "%*llx: " : "%*llu: ",
+ if (device_offset)
+ sprintf(flags, "%04x: ", fm_extent->fe_device);
+ else if (expected)
+ sprintf(flags, ext_fmt == hex_fmt ? "%*llx:" : "%*llu: ",
physical_width, expected >> blk_shift);
- else
- sprintf(flags, "%.*s ", physical_width, " ");
if (fm_extent->fe_flags & FIEMAP_EXTENT_UNKNOWN)
strcat(flags, "unknown,");
strcat(flags, "unwritten,");
if (fm_extent->fe_flags & FIEMAP_EXTENT_MERGED)
strcat(flags, "merged,");
+ if (fm_extent->fe_flags & FIEMAP_EXTENT_NET)
+ strcat(flags, "network,");
+ if (fm_extent->fe_flags & FIEMAP_EXTENT_NO_DIRECT)
+ strcat(flags, "no_direct,");
if (fm_extent->fe_logical + fm_extent->fe_length >= st->st_size)
strcat(flags, "eof,");
static int fiemap_incompat_printed;
int fiemap_header_printed = 0;
int tot_extents = 0, n = 0;
+ int previous_device = 0;
int last = 0;
int rc;
if (xattr_map)
flags |= FIEMAP_FLAG_XATTR;
+ if (device_offset) {
+ flags |= FIEMAP_FLAG_DEVICE_ORDER;
+ memset(fm_ext, 0, sizeof(struct fiemap_extent));
+ }
+
+retry_wo_device_order:
do {
fiemap->fm_length = ~0ULL;
fiemap->fm_flags = flags;
printf("FIEMAP failed with unsupported "
"flags %x\n", fiemap->fm_flags);
fiemap_incompat_printed = 1;
+ } else if (rc == EBADR && (fiemap->fm_flags &
+ FIEMAP_FLAG_DEVICE_ORDER)) {
+ flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
+ goto retry_wo_device_order;
}
return rc;
}
}
for (i = 0; i < fiemap->fm_mapped_extents; i++) {
+ if (previous_device != fm_ext[i].fe_device)
+ previous_device = fm_ext[i].fe_device;
+
if (fm_ext[i].fe_logical != 0 &&
fm_ext[i].fe_physical != expected) {
tot_extents++;
n++;
}
- fiemap->fm_start = (fm_ext[i - 1].fe_logical +
- fm_ext[i - 1].fe_length);
+ /* For DEVICE_ORDER mappings, if EXTENT_LAST not yet found then
+ * fm_start needs to be the same as it was for earlier ioctl.
+ * The first extent is used to pass the end offset and device
+ * of the last FIEMAP call. Otherwise, we ask for extents
+ * starting from where the last mapping ended. */
+ if (flags & FIEMAP_FLAG_DEVICE_ORDER) {
+ fm_ext[0].fe_logical = fm_ext[i - 1].fe_logical +
+ fm_ext[i - 1].fe_length;
+ fm_ext[0].fe_device = fm_ext[i - 1].fe_device;
+ fiemap->fm_start = 0;
+ } else {
+ fiemap->fm_start = fm_ext[i - 1].fe_logical +
+ fm_ext[i - 1].fe_length;
+ }
} while (last == 0);
*num_extents = tot_extents;
if (force_extent) {
memset(&fm_ext, 0, sizeof(fm_ext));
+ fm_ext.fe_device = st->st_dev;
fm_ext.fe_flags = FIEMAP_EXTENT_MERGED;
}
(fsinfo.f_type == 0xef53)))
is_ext2++;
+ /* Check if filesystem is Lustre. Always print in extent format
+ * with 1kB blocks, using the device-relative logical offsets. */
+ if (fsinfo.f_type == LUSTRE_SUPER_MAGIC) {
+ device_offset = 1;
+ blocksize = blocksize ?: 1024;
+ }
+
if (is_ext2) {
long cylgroups = div_ceil(fsinfo.f_blocks, fsinfo.f_bsize * 8);
char **cpp;
int c;
- while ((c = getopt(argc, argv, "Bb::eksvxX")) != EOF)
+ while ((c = getopt(argc, argv, "Bb::eklsvxX")) != EOF)
switch (c) {
case 'B':
force_bmap++;
+ force_extent = 0;
break;
case 'b':
if (optarg) {
case 'k':
blocksize = 1024;
break;
+ case 'l':
+ device_offset++;
+ break;
case 's':
sync_file++;
break;