f2fs_io: change fibmap to fiemap
PATCH 1/1 f2fs_io: change fibmap to fiemap
From: Daeho Jeong <[email protected]>
Currently we support fiemap command using fibmap. It's simple and easy to use, but we cannot use this for compressed file. To support more different types of files, we need to change this to use fiemap.
--- tools/f2fs_io/f2fs_io.c | 56 ++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 17 deletions(-)
tools/f2fs_io/f2fs_io.c +39 -17
@@ -631,27 +631,42 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)exit (0 ); } -struct file_ext { -__u32 f_pos; -__u32 start_blk; -__u32 end_blk; -__u32 blk_count; +struct fiemap_extent { +__u64 fe_logical; +__u64 fe_physical; +__u64 fe_length; +__u64 fe_reserved64[2 ]; +__u32 fe_flags; +__u32 fe_reserved[3 ]; }; -#ifndef FIBMAP -#define FIBMAP _IO(0x00, 1)/* bmap access */ +struct fiemap { +__u64 fm_start; +__u64 fm_length; +__u32 fm_flags; +__u32 fm_mapped_extents; +__u32 fm_extent_count; +__u32 fm_reserved; +struct fiemap_extent fm_extent[0 ]; +}; + +#ifndef FIEMAP +#define FIEMAP _IOWR('f', 11, struct fiemap)#endif +#define NEW_ADDR 0xFFFFFFFF +#define fiemap_desc "get block address in file"#define fiemap_help \ "f2fs_io fiemap [offset in 4kb] [count] [file_path]\n\n"\static void do_fiemap (int argc,char **argv,const struct cmd_desc *cmd) { -u64 offset; -u32 blknum;unsigned count, i;int fd; +__u64 phy_addr; +struct fiemap *fm =xmalloc (sizeof (struct fiemap ) + +sizeof (struct fiemap_extent ));if (argc !=4 ) {fputs ("Excess arguments\n\n" , stderr);
@@ -659,21 +674,28 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)exit (1 ); } - offset =atoi (argv[1 ]); + fm->fm_start =atoi (argv[1 ]) *4096 ; + fm->fm_length =4096 ; + fm->fm_extent_count =1 ; count =atoi (argv[2 ]); fd =xopen (argv[3 ],O_RDONLY |O_LARGEFILE ,0 ); -printf ("Fiemap: offset = %08" PRIx64" len = %d\n" , offset, count); +printf ("Fiemap: offset = %08" PRIx64" len = %d\n" , + fm->fm_start /4096 , count);for (i =0 ; i < count; i++) { - blknum = offset + i; - -if (ioctl (fd,FIBMAP , &blknum) <0 ) -die_errno ("FIBMAP failed" ); - -printf ("%u " , blknum); +if (ioctl (fd,FIEMAP , fm) <0 ) +die_errno ("FIEMAP failed" ); + + phy_addr = fm->fm_extent[0 ].fe_physical /4096 ; +if (phy_addr ==NEW_ADDR ) +printf ("NEW_ADDR " ); +else +printf ("%llu " , phy_addr); + fm->fm_start +=4096 ; }printf ("\n" ); +free (fm);exit (0 ); }
Signature · 8 lines
2.28.0.402.g5ffc5be6b7-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 68 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
Currently we support fiemap command using fibmap. It's simple and easy to use, but we cannot use this for compressed file. To support more different types of files, we need to change this to use fiemap.
Signed-off-by Daeho Jeong <[email protected]>--- tools/f2fs_io/f2fs_io.c | 56 ++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 17 deletions(-)tools/f2fs_io/f2fs_io.c +24
-9@@ -631,27 +631,42 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)exit (0 ); } -struct file_ext { -__u32 f_pos; -__u32 start_blk; -__u32 end_blk; -__u32 blk_count; +struct fiemap_extent { +__u64 fe_logical; +__u64 fe_physical; +__u64 fe_length; +__u64 fe_reserved64[2 ]; +__u32 fe_flags; +__u32 fe_reserved[3 ]; }; -#ifndef FIBMAP -#define FIBMAP _IO(0x00, 1)/* bmap access */ +struct fiemap { +__u64 fm_start; +__u64 fm_length; +__u32 fm_flags; +__u32 fm_mapped_extents; +__u32 fm_extent_count; +__u32 fm_reserved; +struct fiemap_extent fm_extent[0 ]; +}; + +#ifndef FIEMAP +#define FIEMAP _IOWR('f', 11, struct fiemap)#endif +#define NEW_ADDR 0xFFFFFFFF +#define fiemap_desc "get block address in file"#define fiemap_help \ "f2fs_io fiemap [offset in 4kb] [count] [file_path]\n\n"\static void do_fiemap (int argc,char **argv,const struct cmd_desc *cmd) { -u64 offset; -u32 blknum;unsigned count, i;int fd; +__u64 phy_addr; +struct fiemap *fm =xmalloc (sizeof (struct fiemap ) + +sizeof (struct fiemap_extent ));if (argc !=4 ) {fputs ("Excess arguments\n\n" , stderr);
tools/f2fs_io/f2fs_io.c static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd) · line 678
Quoted 6 lines
tools/f2fs_io/f2fs_io.c +2
-1@@ -659,21 +674,28 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)exit (1 ); } - offset =atoi (argv[1 ]); + fm->fm_start =atoi (argv[1 ]) *4096 ; + fm->fm_length =4096 ;
F2FS_BLKSIZE
tools/f2fs_io/f2fs_io.c static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd) · line 685
Quoted 8 lines
tools/f2fs_io/f2fs_io.c +3
-1+ fm->fm_extent_count =1 ; count =atoi (argv[2 ]); fd =xopen (argv[3 ],O_RDONLY |O_LARGEFILE ,0 ); -printf ("Fiemap: offset = %08" PRIx64" len = %d\n" , offset, count); +printf ("Fiemap: offset = %08" PRIx64" len = %d\n" , + fm->fm_start /4096 , count);
F2FS_BLKSIZE
tools/f2fs_io/f2fs_io.c static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd) · line 690
Quoted 11 lines
tools/f2fs_io/f2fs_io.c +4
-6for (i =0 ; i < count; i++) { - blknum = offset + i; - -if (ioctl (fd,FIBMAP , &blknum) <0 ) -die_errno ("FIBMAP failed" ); - -printf ("%u " , blknum); +if (ioctl (fd,FIEMAP , fm) <0 ) +die_errno ("FIEMAP failed" ); + + phy_addr = fm->fm_extent[0 ].fe_physical /4096 ;
F2FS_BLKSIZE
tools/f2fs_io/f2fs_io.c static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd) · line 695
Quoted 5 lines
tools/f2fs_io/f2fs_io.c +5
-0+if (phy_addr ==NEW_ADDR ) +printf ("NEW_ADDR " ); +else +printf ("%llu " , phy_addr); + fm->fm_start +=4096 ;
F2FS_BLKSIZE
tools/f2fs_io/f2fs_io.c static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd) · line 701
Quoted 7 lines
tools/f2fs_io/f2fs_io.c +1
-0}printf ("\n" ); +free (fm);exit (0 ); }
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Yes, I just was searching for that, but failed.
Thanks,
2020년 9월 3일 (목) 오전 10:15, Chao Yu <[email protected]>님이 작성:
Quoted 104 lines · Daeho Jeong
Quoted 68 lines
From: Daeho Jeong <[email protected]>
Currently we support fiemap command using fibmap. It's simple and easy to use, but we cannot use this for compressed file. To support more different types of files, we need to change this to use fiemap.
Signed-off-by Daeho Jeong <[email protected]>--- tools/f2fs_io/f2fs_io.c | 56 ++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 17 deletions(-)tools/f2fs_io/f2fs_io.c +24
-9@@ -631,27 +631,42 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)exit (0 ); } -struct file_ext { -__u32 f_pos; -__u32 start_blk; -__u32 end_blk; -__u32 blk_count; +struct fiemap_extent { +__u64 fe_logical; +__u64 fe_physical; +__u64 fe_length; +__u64 fe_reserved64[2 ]; +__u32 fe_flags; +__u32 fe_reserved[3 ]; }; -#ifndef FIBMAP -#define FIBMAP _IO(0x00, 1)/* bmap access */ +struct fiemap { +__u64 fm_start; +__u64 fm_length; +__u32 fm_flags; +__u32 fm_mapped_extents; +__u32 fm_extent_count; +__u32 fm_reserved; +struct fiemap_extent fm_extent[0 ]; +}; + +#ifndef FIEMAP +#define FIEMAP _IOWR('f', 11, struct fiemap)#endif +#define NEW_ADDR 0xFFFFFFFF +#define fiemap_desc "get block address in file"#define fiemap_help \ "f2fs_io fiemap [offset in 4kb] [count] [file_path]\n\n"\static void do_fiemap (int argc,char **argv,const struct cmd_desc *cmd) { -u64 offset; -u32 blknum;unsigned count, i;int fd; +__u64 phy_addr; +struct fiemap *fm =xmalloc (sizeof (struct fiemap ) + +sizeof (struct fiemap_extent ));if (argc !=4 ) {fputs ("Excess arguments\n\n" , stderr);tools/f2fs_io/f2fs_io.c static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd) · line 678
Quoted 6 lines
tools/f2fs_io/f2fs_io.c +2
-1@@ -659,21 +674,28 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)exit (1 ); } - offset =atoi (argv[1 ]); + fm->fm_start =atoi (argv[1 ]) *4096 ; + fm->fm_length =4096 ;
F2FS_BLKSIZEtools/f2fs_io/f2fs_io.c static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd) · line 685
Quoted 8 lines
tools/f2fs_io/f2fs_io.c +3
-1+ fm->fm_extent_count =1 ; count =atoi (argv[2 ]); fd =xopen (argv[3 ],O_RDONLY |O_LARGEFILE ,0 ); -printf ("Fiemap: offset = %08" PRIx64" len = %d\n" , offset, count); +printf ("Fiemap: offset = %08" PRIx64" len = %d\n" , + fm->fm_start /4096 , count);
F2FS_BLKSIZEtools/f2fs_io/f2fs_io.c static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd) · line 690
Quoted 11 lines
tools/f2fs_io/f2fs_io.c +4
-6for (i =0 ; i < count; i++) { - blknum = offset + i; - -if (ioctl (fd,FIBMAP , &blknum) <0 ) -die_errno ("FIBMAP failed" ); - -printf ("%u " , blknum); +if (ioctl (fd,FIEMAP , fm) <0 ) +die_errno ("FIEMAP failed" ); + + phy_addr = fm->fm_extent[0 ].fe_physical /4096 ;
F2FS_BLKSIZE
Quoted 15 lines
tools/f2fs_io/f2fs_io.c static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd) · line 695
Quoted 5 lines
tools/f2fs_io/f2fs_io.c +5
-0+if (phy_addr ==NEW_ADDR ) +printf ("NEW_ADDR " ); +else +printf ("%llu " , phy_addr); + fm->fm_start +=4096 ;
F2FS_BLKSIZEQuoted 7 lines
tools/f2fs_io/f2fs_io.c +1
-0}printf ("\n" ); +free (fm);exit (0 ); }
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel