f2fs-tools: change fiemap print out format

commit 49159df049
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

Given fiemap way to print out extents in the kernel, we can correctly
print the layout of each file in a unit of extent, not block. So, I
changed fiemap print out way like below.

Fiemap: offset = 0 len = 60
        logical addr.    physical addr.   length           flags
0       0000000000000000 00000020032df000 0000000000004000 00001008
1       0000000000004000 00000020032e0000 0000000000004000 00001008
2       0000000000008000 00000020032e1000 0000000000004000 00001008
3       000000000000c000 00000020032e2000 0000000000004000 00001008

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
This commit is contained in:
Daeho Jeong 2021-08-20 08:36:14 -07:00 committed by dongsenhao
parent c7ee479e92
commit 4f5e79faa8

View File

@ -731,11 +731,11 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)
#if defined(HAVE_LINUX_FIEMAP_H) && defined(HAVE_LINUX_FS_H) #if defined(HAVE_LINUX_FIEMAP_H) && defined(HAVE_LINUX_FS_H)
static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd) static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
{ {
unsigned count, i; unsigned int i;
int fd; int fd, extents_mem_size;
__u64 phy_addr; u64 start, length;
struct fiemap *fm = xmalloc(sizeof(struct fiemap) + u32 mapped_extents;
sizeof(struct fiemap_extent)); struct fiemap *fm = xmalloc(sizeof(struct fiemap));
if (argc != 4) { if (argc != 4) {
fputs("Excess arguments\n\n", stderr); fputs("Excess arguments\n\n", stderr);
@ -743,26 +743,40 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
exit(1); exit(1);
} }
fm->fm_start = atoi(argv[1]) * F2FS_BLKSIZE; memset(fm, 0, sizeof(struct fiemap));
fm->fm_length = F2FS_BLKSIZE; start = atoi(argv[1]) * F2FS_BLKSIZE;
fm->fm_extent_count = 1; length = atoi(argv[2]) * F2FS_BLKSIZE;
count = atoi(argv[2]); fm->fm_start = start;
fm->fm_length = length;
fd = xopen(argv[3], O_RDONLY | O_LARGEFILE, 0); fd = xopen(argv[3], O_RDONLY | O_LARGEFILE, 0);
printf("Fiemap: offset = %08"PRIx64" len = %d\n", printf("Fiemap: offset = %"PRIu64" len = %"PRIu64"\n",
(u64)fm->fm_start / F2FS_BLKSIZE, count); start / F2FS_BLKSIZE, length / F2FS_BLKSIZE);
for (i = 0; i < count; i++) { if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0) die_errno("FIEMAP failed");
die_errno("FIEMAP failed");
phy_addr = fm->fm_extents[0].fe_physical / F2FS_BLKSIZE; mapped_extents = fm->fm_mapped_extents;
printf("%llu: %llu\n", fm->fm_start / F2FS_BLKSIZE, phy_addr); extents_mem_size = sizeof(struct fiemap_extent) * mapped_extents;
free(fm);
fm = xmalloc(sizeof(struct fiemap) + extents_mem_size);
if (fm->fm_extents[0].fe_flags & FIEMAP_EXTENT_LAST) memset(fm, 0, sizeof(struct fiemap) + extents_mem_size);
fm->fm_start = start;
fm->fm_length = length;
fm->fm_extent_count = mapped_extents;
if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
die_errno("FIEMAP failed");
printf("\t%-17s%-17s%-17s%s\n", "logical addr.", "physical addr.", "length", "flags");
for (i = 0; i < fm->fm_mapped_extents; i++) {
printf("%d\t%.16llx %.16llx %.16llx %.8x\n", i,
fm->fm_extents[i].fe_logical, fm->fm_extents[i].fe_physical,
fm->fm_extents[i].fe_length, fm->fm_extents[i].fe_flags);
if (fm->fm_extents[i].fe_flags & FIEMAP_EXTENT_LAST)
break; break;
fm->fm_start += F2FS_BLKSIZE;
} }
printf("\n"); printf("\n");
free(fm); free(fm);