f2fs_io: change fibmap to fiemap
PATCH v3 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.
---
Changes in v3:
- Change to use linux/fiemap.h header
Changes in v2:
- Move declaration to header file
--- configure.ac | 1 + tools/f2fs_io/f2fs_io.c | 41 +++++++++++++++++++++-------------------- tools/f2fs_io/f2fs_io.h | 10 ++++++++++ 3 files changed, 32 insertions(+), 20 deletions(-)
configure.ac +1 -0
@@ -93,6 +93,7 @@ AC_CHECK_HEADERS(m4_flatten([ linux/posix_acl.h linux/types.h linux/xattr.h + linux/fiemap.h mach/mach_time.h mntent.h scsi/sg.h
tools/f2fs_io/f2fs_io.c +21 -20
70 lines not on this page · raw message
tools/f2fs_io/f2fs_io.h +10 -0
@@ -10,6 +10,13 @@#ifdef HAVE_LINUX_TYPES_H #include <linux/types.h> #endif +#ifdef HAVE_LINUX_FIEMAP_H +#include <linux/fiemap.h> +#endif +#ifdef HAVE_LINUX_FS_H +#include <linux/fs.h> +#endif +#include <sys/types.h> #ifdef UNUSED
@@ -38,6 +45,9 @@ typedef u16 __be16;typedef u32 __be32 ;#endif +#define F2FS_BLKSIZE 4096 +#define NEW_ADDR 0xFFFFFFFF +#ifndef FS_IOC_GETFLAGS #define FS_IOC_GETFLAGS _IOR('f', 1, long)#endif
Signature · 8 lines
2.28.0.526.ge36021eeef-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 111 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]>---
Changes in v3:
- Change to uselinux/fiemap.hheader
Changes in v2:
- Move declaration to header file--- configure.ac | 1 + tools/f2fs_io/f2fs_io.c | 41 +++++++++++++++++++++-------------------- tools/f2fs_io/f2fs_io.h | 10 ++++++++++ 3 files changed, 32 insertions(+), 20 deletions(-)configure.ac +1
-0@@ -93,6 +93,7 @@ AC_CHECK_HEADERS(m4_flatten([ linux/posix_acl.h linux/types.h linux/xattr.h + linux/fiemap.h mach/mach_time.h mntent.h scsi/sg.htools/f2fs_io/f2fs_io.c +21
-20@@ -631,27 +631,18 @@ 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; -}; - -#ifndef FIBMAP -#define FIBMAP _IO(0x00, 1)/* bmap access */ -#endif -#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; +#if defined(HAVE_LINUX_FIEMAP_H ) && defined(HAVE_LINUX_FS_H )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,22 +650,32 @@ 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 ]) *F2FS_BLKSIZE ; + fm->fm_length =F2FS_BLKSIZE ; + 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 /F2FS_BLKSIZE , count);for (i =0 ; i < count; i++) { - blknum = offset + i; - -if (ioctl (fd,FIBMAP , &blknum) <0 ) -die_errno ("FIBMAP failed" ); +if (ioctl (fd,FS_IOC_FIEMAP , fm) <0 ) +die_errno ("FIEMAP failed" ); -printf ("%u " , blknum); + phy_addr = fm->fm_extents[0 ].fe_physical /F2FS_BLKSIZE ; +if (phy_addr ==NEW_ADDR ) +printf ("NEW_ADDR " ); +else +printf ("%llu " , phy_addr); + fm->fm_start +=F2FS_BLKSIZE ; }printf ("\n" ); +free (fm);exit (0 ); +#else +die ("Not support for this platform" ); +#endif }#define gc_urgent_desc "start/end/run gc_urgent for given time period"tools/f2fs_io/f2fs_io.h +0
-0
tools/f2fs_io/f2fs_io.h line 13
Quoted 4 lines
tools/f2fs_io/f2fs_io.h +1
-0@@ -10,6 +10,13 @@#ifdef HAVE_LINUX_TYPES_H #include <linux/types.h> #endif +#ifdef HAVE_LINUX_FIEMAP_H
Should add this HAVE_LINUX_FIEMAP_H macro into include/android_config.h?
Quoted 11 lines
tools/f2fs_io/f2fs_io.h +6
-0+#include <linux/fiemap.h> +#endif +#ifdef HAVE_LINUX_FS_H +#include <linux/fs.h> +#endif +#include <sys/types.h> #ifdef UNUSED
tools/f2fs_io/f2fs_io.h typedef u16 __be16; · line 53
Quoted 9 lines
tools/f2fs_io/f2fs_io.h +3
-0@@ -38,6 +45,9 @@ typedef u16 __be16;typedef u32 __be32 ;#endif +#define F2FS_BLKSIZE 4096 +#define NEW_ADDR 0xFFFFFFFF +#ifndef FS_IOC_GETFLAGS #define FS_IOC_GETFLAGS _IOR('f', 1, long)#endif
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
I don't think it is required, since only f2fs_io.c uses fiemap and f2fs_io doesn't use include/android_config.h.
2020년 9월 11일 (금) 오후 12:36, Chao Yu <[email protected]>님이 작성:
Quoted 133 lines · Daeho Jeong
Quoted 111 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]>---
Changes in v3:
- Change to uselinux/fiemap.hheader
Changes in v2:
- Move declaration to header file--- configure.ac | 1 + tools/f2fs_io/f2fs_io.c | 41 +++++++++++++++++++++-------------------- tools/f2fs_io/f2fs_io.h | 10 ++++++++++ 3 files changed, 32 insertions(+), 20 deletions(-)configure.ac +1
-0@@ -93,6 +93,7 @@ AC_CHECK_HEADERS(m4_flatten([ linux/posix_acl.h linux/types.h linux/xattr.h + linux/fiemap.h mach/mach_time.h mntent.h scsi/sg.htools/f2fs_io/f2fs_io.c +21
-20@@ -631,27 +631,18 @@ 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; -}; - -#ifndef FIBMAP -#define FIBMAP _IO(0x00, 1)/* bmap access */ -#endif -#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; +#if defined(HAVE_LINUX_FIEMAP_H ) && defined(HAVE_LINUX_FS_H )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,22 +650,32 @@ 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 ]) *F2FS_BLKSIZE ; + fm->fm_length =F2FS_BLKSIZE ; + 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 /F2FS_BLKSIZE , count);for (i =0 ; i < count; i++) { - blknum = offset + i; - -if (ioctl (fd,FIBMAP , &blknum) <0 ) -die_errno ("FIBMAP failed" ); +if (ioctl (fd,FS_IOC_FIEMAP , fm) <0 ) +die_errno ("FIEMAP failed" ); -printf ("%u " , blknum); + phy_addr = fm->fm_extents[0 ].fe_physical /F2FS_BLKSIZE ; +if (phy_addr ==NEW_ADDR ) +printf ("NEW_ADDR " ); +else +printf ("%llu " , phy_addr); + fm->fm_start +=F2FS_BLKSIZE ; }printf ("\n" ); +free (fm);exit (0 ); +#else +die ("Not support for this platform" ); +#endif }#define gc_urgent_desc "start/end/run gc_urgent for given time period"tools/f2fs_io/f2fs_io.h +0
-0tools/f2fs_io/f2fs_io.h line 13
Quoted 4 lines
tools/f2fs_io/f2fs_io.h +1
-0@@ -10,6 +10,13 @@#ifdef HAVE_LINUX_TYPES_H #include <linux/types.h> #endif +#ifdef HAVE_LINUX_FIEMAP_H Should add this
HAVE_LINUX_FIEMAP_Hmacro intoinclude/android_config.h?Quoted 13 lines
tools/f2fs_io/f2fs_io.h +6
-0+#include <linux/fiemap.h> +#endif +#ifdef HAVE_LINUX_FS_H +#include <linux/fs.h> +#endif +#include <sys/types.h> #ifdef UNUSED @@ -38,6 +45,9 @@ typedef u16 __be16;typedef u32 __be32 ;#endif
Quoted 7 lines
tools/f2fs_io/f2fs_io.h typedef u16 __be16; · line 53
Quoted 7 lines
tools/f2fs_io/f2fs_io.h +3
-0+#define F2FS_BLKSIZE 4096 +#define NEW_ADDR 0xFFFFFFFF +#ifndef FS_IOC_GETFLAGS #define FS_IOC_GETFLAGS _IOR('f', 1, long)#endif
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
Reviewed-byQuoted 2 lines · Daeho Jeong
I don't think it is required, since only
f2fs_io.cuses fiemap andf2fs_iodoesn't useinclude/android_config.h.
Correct.
Quoted 11 lines
2020년 9월 11일 (금) 오후 12:36, Chao Yu <[email protected]>님이 작성:
Quoted 9 lines · Daeho Jeong
Quoted 7 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]>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel