linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH v2] f2fs_io: change fibmap to fiemap
@ 2020-09-03  2:44 Daeho Jeong
  2020-09-04  3:11 ` Chao Yu
  0 siblings, 1 reply; 6+ messages in thread
From: Daeho Jeong @ 2020-09-03  2:44 UTC (permalink / raw)
  To: linux-f2fs-devel; +Cc: Daeho Jeong

From: Daeho Jeong <daehojeong@google.com>

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 <daehojeong@google.com>
---
Changes in v2:
 - Move declaration to header file
---
 tools/f2fs_io/f2fs_io.c | 37 +++++++++++++++++--------------------
 tools/f2fs_io/f2fs_io.h | 26 ++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index abb655a..9a651c0 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -631,27 +631,17 @@ 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;
 	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 +649,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]) * 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, FIEMAP, fm) < 0)
+			die_errno("FIEMAP failed");
 
-		printf("%u ", blknum);
+		phy_addr = fm->fm_extent[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);
 }
 
diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
index bd19ff9..62d6e7b 100644
--- a/tools/f2fs_io/f2fs_io.h
+++ b/tools/f2fs_io/f2fs_io.h
@@ -38,6 +38,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
@@ -132,6 +135,29 @@ typedef u32	__be32;
 #define FS_CASEFOLD_FL			0x40000000 /* Folder is case insensitive */
 #endif
 
+struct fiemap_extent {
+	u64 fe_logical;
+	u64 fe_physical;
+	u64 fe_length;
+	u64 fe_reserved64[2];
+	u32 fe_flags;
+	u32 fe_reserved[3];
+};
+
+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
+
 struct f2fs_gc_range {
 	u32 sync;
 	u64 start;
-- 
2.28.0.526.ge36021eeef-goog



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [f2fs-dev] [PATCH v2] f2fs_io: change fibmap to fiemap
  2020-09-03  2:44 [f2fs-dev] [PATCH v2] f2fs_io: change fibmap to fiemap Daeho Jeong
@ 2020-09-04  3:11 ` Chao Yu
       [not found]   ` <CACOAw_xAjUEyVo0Jm4yPvg7KB4G=Mz=tSEQ_wz6OH-P+e_cP8Q@mail.gmail.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Chao Yu @ 2020-09-04  3:11 UTC (permalink / raw)
  To: Daeho Jeong, linux-f2fs-devel; +Cc: Daeho Jeong



On 2020/9/3 10:44, Daeho Jeong wrote:
> From: Daeho Jeong <daehojeong@google.com>
> 
> 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 <daehojeong@google.com>
> ---
> Changes in v2:
>   - Move declaration to header file
> ---
>   tools/f2fs_io/f2fs_io.c | 37 +++++++++++++++++--------------------
>   tools/f2fs_io/f2fs_io.h | 26 ++++++++++++++++++++++++++
>   2 files changed, 43 insertions(+), 20 deletions(-)
> 
> diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
> index abb655a..9a651c0 100644
> --- a/tools/f2fs_io/f2fs_io.c
> +++ b/tools/f2fs_io/f2fs_io.c
> @@ -631,27 +631,17 @@ 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;
>   	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 +649,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]) * 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, FIEMAP, fm) < 0)
> +			die_errno("FIEMAP failed");
>   
> -		printf("%u ", blknum);
> +		phy_addr = fm->fm_extent[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);
>   }
>   
> diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
> index bd19ff9..62d6e7b 100644
> --- a/tools/f2fs_io/f2fs_io.h
> +++ b/tools/f2fs_io/f2fs_io.h
> @@ -38,6 +38,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
> @@ -132,6 +135,29 @@ typedef u32	__be32;
>   #define FS_CASEFOLD_FL			0x40000000 /* Folder is case insensitive */
>   #endif
>   
> +struct fiemap_extent {
> +	u64 fe_logical;
> +	u64 fe_physical;
> +	u64 fe_length;
> +	u64 fe_reserved64[2];
> +	u32 fe_flags;
> +	u32 fe_reserved[3];
> +};
> +
> +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];
> +};

We don't need to copy & paste fiemap related structure here.

Let's just include <linux/fiemap.h> in f2fs_io.h

Thanks,

> +
> +#ifndef FIEMAP
> +#define FIEMAP				_IOWR('f', 11, struct fiemap)
> +#endif
> +
>   struct f2fs_gc_range {
>   	u32 sync;
>   	u64 start;
> 


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [f2fs-dev] [PATCH v2] f2fs_io: change fibmap to fiemap
       [not found]   ` <CACOAw_xAjUEyVo0Jm4yPvg7KB4G=Mz=tSEQ_wz6OH-P+e_cP8Q@mail.gmail.com>
@ 2020-09-08  0:52     ` Daeho Jeong
  2020-09-08  1:42       ` Chao Yu
  0 siblings, 1 reply; 6+ messages in thread
From: Daeho Jeong @ 2020-09-08  0:52 UTC (permalink / raw)
  To: Chao Yu; +Cc: Daeho Jeong, linux-f2fs-devel

I've thought about this.
We need to support this tool for different OS, not only for Linux.
So, is it ok to include linux/fiemap.h for this?
Actually, since FIEMAP and other stuff were defined in f2fs_io.c
directly before, I thought that there was some reason for doing that
and I followed the convention.

What do you think?

2020년 9월 4일 (금) 오후 12:39, Daeho Jeong <daeho43@gmail.com>님이 작성:
>
> It's way better~ :)
>
> 2020년 9월 4일 (금) 오후 12:11, Chao Yu <yuchao0@huawei.com>님이 작성:
>>
>>
>>
>> On 2020/9/3 10:44, Daeho Jeong wrote:
>> > From: Daeho Jeong <daehojeong@google.com>
>> >
>> > 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 <daehojeong@google.com>
>> > ---
>> > Changes in v2:
>> >   - Move declaration to header file
>> > ---
>> >   tools/f2fs_io/f2fs_io.c | 37 +++++++++++++++++--------------------
>> >   tools/f2fs_io/f2fs_io.h | 26 ++++++++++++++++++++++++++
>> >   2 files changed, 43 insertions(+), 20 deletions(-)
>> >
>> > diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
>> > index abb655a..9a651c0 100644
>> > --- a/tools/f2fs_io/f2fs_io.c
>> > +++ b/tools/f2fs_io/f2fs_io.c
>> > @@ -631,27 +631,17 @@ 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;
>> >       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 +649,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]) * 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, FIEMAP, fm) < 0)
>> > +                     die_errno("FIEMAP failed");
>> >
>> > -             printf("%u ", blknum);
>> > +             phy_addr = fm->fm_extent[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);
>> >   }
>> >
>> > diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
>> > index bd19ff9..62d6e7b 100644
>> > --- a/tools/f2fs_io/f2fs_io.h
>> > +++ b/tools/f2fs_io/f2fs_io.h
>> > @@ -38,6 +38,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
>> > @@ -132,6 +135,29 @@ typedef u32      __be32;
>> >   #define FS_CASEFOLD_FL                      0x40000000 /* Folder is case insensitive */
>> >   #endif
>> >
>> > +struct fiemap_extent {
>> > +     u64 fe_logical;
>> > +     u64 fe_physical;
>> > +     u64 fe_length;
>> > +     u64 fe_reserved64[2];
>> > +     u32 fe_flags;
>> > +     u32 fe_reserved[3];
>> > +};
>> > +
>> > +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];
>> > +};
>>
>> We don't need to copy & paste fiemap related structure here.
>>
>> Let's just include <linux/fiemap.h> in f2fs_io.h
>>
>> Thanks,
>>
>> > +
>> > +#ifndef FIEMAP
>> > +#define FIEMAP                               _IOWR('f', 11, struct fiemap)
>> > +#endif
>> > +
>> >   struct f2fs_gc_range {
>> >       u32 sync;
>> >       u64 start;
>> >


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [f2fs-dev] [PATCH v2] f2fs_io: change fibmap to fiemap
  2020-09-08  0:52     ` Daeho Jeong
@ 2020-09-08  1:42       ` Chao Yu
  2020-09-08  2:09         ` Daeho Jeong
  0 siblings, 1 reply; 6+ messages in thread
From: Chao Yu @ 2020-09-08  1:42 UTC (permalink / raw)
  To: Daeho Jeong; +Cc: Daeho Jeong, linux-f2fs-devel

On 2020/9/8 8:52, Daeho Jeong wrote:
> I've thought about this.
> We need to support this tool for different OS, not only for Linux.
> So, is it ok to include linux/fiemap.h for this?
> Actually, since FIEMAP and other stuff were defined in f2fs_io.c
> directly before, I thought that there was some reason for doing that
> and I followed the convention.
> 
> What do you think?

Yes, that's good point.

I noticed that f2fs_io.h has similar concern:

#ifdef HAVE_LINUX_TYPES_H
#include <linux/types.h>
#endif

...

#ifndef HAVE_LINUX_TYPES_H
typedef u8	__u8;
typedef u16	__u16;
typedef u32	__u32;
typedef u16	__le16;
typedef u32	__le32;
typedef u16	__be16;
typedef u32	__be32;
#endif

So how about implementing as above?

Thanks,

> 
> 2020년 9월 4일 (금) 오후 12:39, Daeho Jeong <daeho43@gmail.com>님이 작성:
>>
>> It's way better~ :)
>>
>> 2020년 9월 4일 (금) 오후 12:11, Chao Yu <yuchao0@huawei.com>님이 작성:
>>>
>>>
>>>
>>> On 2020/9/3 10:44, Daeho Jeong wrote:
>>>> From: Daeho Jeong <daehojeong@google.com>
>>>>
>>>> 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 <daehojeong@google.com>
>>>> ---
>>>> Changes in v2:
>>>>    - Move declaration to header file
>>>> ---
>>>>    tools/f2fs_io/f2fs_io.c | 37 +++++++++++++++++--------------------
>>>>    tools/f2fs_io/f2fs_io.h | 26 ++++++++++++++++++++++++++
>>>>    2 files changed, 43 insertions(+), 20 deletions(-)
>>>>
>>>> diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
>>>> index abb655a..9a651c0 100644
>>>> --- a/tools/f2fs_io/f2fs_io.c
>>>> +++ b/tools/f2fs_io/f2fs_io.c
>>>> @@ -631,27 +631,17 @@ 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;
>>>>        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 +649,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]) * 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, FIEMAP, fm) < 0)
>>>> +                     die_errno("FIEMAP failed");
>>>>
>>>> -             printf("%u ", blknum);
>>>> +             phy_addr = fm->fm_extent[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);
>>>>    }
>>>>
>>>> diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
>>>> index bd19ff9..62d6e7b 100644
>>>> --- a/tools/f2fs_io/f2fs_io.h
>>>> +++ b/tools/f2fs_io/f2fs_io.h
>>>> @@ -38,6 +38,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
>>>> @@ -132,6 +135,29 @@ typedef u32      __be32;
>>>>    #define FS_CASEFOLD_FL                      0x40000000 /* Folder is case insensitive */
>>>>    #endif
>>>>
>>>> +struct fiemap_extent {
>>>> +     u64 fe_logical;
>>>> +     u64 fe_physical;
>>>> +     u64 fe_length;
>>>> +     u64 fe_reserved64[2];
>>>> +     u32 fe_flags;
>>>> +     u32 fe_reserved[3];
>>>> +};
>>>> +
>>>> +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];
>>>> +};
>>>
>>> We don't need to copy & paste fiemap related structure here.
>>>
>>> Let's just include <linux/fiemap.h> in f2fs_io.h
>>>
>>> Thanks,
>>>
>>>> +
>>>> +#ifndef FIEMAP
>>>> +#define FIEMAP                               _IOWR('f', 11, struct fiemap)
>>>> +#endif
>>>> +
>>>>    struct f2fs_gc_range {
>>>>        u32 sync;
>>>>        u64 start;
>>>>
> .
> 


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [f2fs-dev] [PATCH v2] f2fs_io: change fibmap to fiemap
  2020-09-08  1:42       ` Chao Yu
@ 2020-09-08  2:09         ` Daeho Jeong
  2020-09-08 14:41           ` Chao Yu
  0 siblings, 1 reply; 6+ messages in thread
From: Daeho Jeong @ 2020-09-08  2:09 UTC (permalink / raw)
  To: Chao Yu; +Cc: Daeho Jeong, linux-f2fs-devel

Then, you mean like the below?
I hardly see any benefit in this way, because we still have to define
all the stuff.

#ifdef HAVE_LINUX_TYPES_H
#include <linux/fiemap.h>
#endif

#ifndef HAVE_LINUX_TYPES_H
struct fiemap_extent {
        u64 fe_logical;
        u64 fe_physical;
        u64 fe_length;
        u64 fe_reserved64[2];
        u32 fe_flags;
        u32 fe_reserved[3];
};

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];
};

#define FIEMAP                          _IOWR('f', 11, struct fiemap)
#endif

2020년 9월 8일 (화) 오전 10:42, Chao Yu <yuchao0@huawei.com>님이 작성:
>
> On 2020/9/8 8:52, Daeho Jeong wrote:
> > I've thought about this.
> > We need to support this tool for different OS, not only for Linux.
> > So, is it ok to include linux/fiemap.h for this?
> > Actually, since FIEMAP and other stuff were defined in f2fs_io.c
> > directly before, I thought that there was some reason for doing that
> > and I followed the convention.
> >
> > What do you think?
>
> Yes, that's good point.
>
> I noticed that f2fs_io.h has similar concern:
>
> #ifdef HAVE_LINUX_TYPES_H
> #include <linux/types.h>
> #endif
>
> ...
>
> #ifndef HAVE_LINUX_TYPES_H
> typedef u8      __u8;
> typedef u16     __u16;
> typedef u32     __u32;
> typedef u16     __le16;
> typedef u32     __le32;
> typedef u16     __be16;
> typedef u32     __be32;
> #endif
>
> So how about implementing as above?
>
> Thanks,
>
> >
> > 2020년 9월 4일 (금) 오후 12:39, Daeho Jeong <daeho43@gmail.com>님이 작성:
> >>
> >> It's way better~ :)
> >>
> >> 2020년 9월 4일 (금) 오후 12:11, Chao Yu <yuchao0@huawei.com>님이 작성:
> >>>
> >>>
> >>>
> >>> On 2020/9/3 10:44, Daeho Jeong wrote:
> >>>> From: Daeho Jeong <daehojeong@google.com>
> >>>>
> >>>> 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 <daehojeong@google.com>
> >>>> ---
> >>>> Changes in v2:
> >>>>    - Move declaration to header file
> >>>> ---
> >>>>    tools/f2fs_io/f2fs_io.c | 37 +++++++++++++++++--------------------
> >>>>    tools/f2fs_io/f2fs_io.h | 26 ++++++++++++++++++++++++++
> >>>>    2 files changed, 43 insertions(+), 20 deletions(-)
> >>>>
> >>>> diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
> >>>> index abb655a..9a651c0 100644
> >>>> --- a/tools/f2fs_io/f2fs_io.c
> >>>> +++ b/tools/f2fs_io/f2fs_io.c
> >>>> @@ -631,27 +631,17 @@ 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;
> >>>>        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 +649,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]) * 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, FIEMAP, fm) < 0)
> >>>> +                     die_errno("FIEMAP failed");
> >>>>
> >>>> -             printf("%u ", blknum);
> >>>> +             phy_addr = fm->fm_extent[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);
> >>>>    }
> >>>>
> >>>> diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
> >>>> index bd19ff9..62d6e7b 100644
> >>>> --- a/tools/f2fs_io/f2fs_io.h
> >>>> +++ b/tools/f2fs_io/f2fs_io.h
> >>>> @@ -38,6 +38,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
> >>>> @@ -132,6 +135,29 @@ typedef u32      __be32;
> >>>>    #define FS_CASEFOLD_FL                      0x40000000 /* Folder is case insensitive */
> >>>>    #endif
> >>>>
> >>>> +struct fiemap_extent {
> >>>> +     u64 fe_logical;
> >>>> +     u64 fe_physical;
> >>>> +     u64 fe_length;
> >>>> +     u64 fe_reserved64[2];
> >>>> +     u32 fe_flags;
> >>>> +     u32 fe_reserved[3];
> >>>> +};
> >>>> +
> >>>> +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];
> >>>> +};
> >>>
> >>> We don't need to copy & paste fiemap related structure here.
> >>>
> >>> Let's just include <linux/fiemap.h> in f2fs_io.h
> >>>
> >>> Thanks,
> >>>
> >>>> +
> >>>> +#ifndef FIEMAP
> >>>> +#define FIEMAP                               _IOWR('f', 11, struct fiemap)
> >>>> +#endif
> >>>> +
> >>>>    struct f2fs_gc_range {
> >>>>        u32 sync;
> >>>>        u64 start;
> >>>>
> > .
> >


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [f2fs-dev] [PATCH v2] f2fs_io: change fibmap to fiemap
  2020-09-08  2:09         ` Daeho Jeong
@ 2020-09-08 14:41           ` Chao Yu
  0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2020-09-08 14:41 UTC (permalink / raw)
  To: Daeho Jeong, Chao Yu; +Cc: Daeho Jeong, linux-f2fs-devel

On 2020-9-8 10:09, Daeho Jeong wrote:
> Then, you mean like the below?

Yup, something like this.

> I hardly see any benefit in this way, because we still have to define
> all the stuff.

Hmm.. I've no idea with previous implementation.

Jaegeuk, could you explain what's the benefit of this?

>
> #ifdef HAVE_LINUX_TYPES_H
> #include <linux/fiemap.h>
> #endif
>
> #ifndef HAVE_LINUX_TYPES_H
> struct fiemap_extent {
>         u64 fe_logical;
>         u64 fe_physical;
>         u64 fe_length;
>         u64 fe_reserved64[2];
>         u32 fe_flags;
>         u32 fe_reserved[3];
> };
>
> 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];
> };

Should adjust android_config.h and configure.ac as well?

Thanks,

>
> #define FIEMAP                          _IOWR('f', 11, struct fiemap)
> #endif
>
> 2020년 9월 8일 (화) 오전 10:42, Chao Yu <yuchao0@huawei.com>님이 작성:
>>
>> On 2020/9/8 8:52, Daeho Jeong wrote:
>>> I've thought about this.
>>> We need to support this tool for different OS, not only for Linux.
>>> So, is it ok to include linux/fiemap.h for this?
>>> Actually, since FIEMAP and other stuff were defined in f2fs_io.c
>>> directly before, I thought that there was some reason for doing that
>>> and I followed the convention.
>>>
>>> What do you think?
>>
>> Yes, that's good point.
>>
>> I noticed that f2fs_io.h has similar concern:
>>
>> #ifdef HAVE_LINUX_TYPES_H
>> #include <linux/types.h>
>> #endif
>>
>> ...
>>
>> #ifndef HAVE_LINUX_TYPES_H
>> typedef u8      __u8;
>> typedef u16     __u16;
>> typedef u32     __u32;
>> typedef u16     __le16;
>> typedef u32     __le32;
>> typedef u16     __be16;
>> typedef u32     __be32;
>> #endif
>>
>> So how about implementing as above?
>>
>> Thanks,
>>
>>>
>>> 2020년 9월 4일 (금) 오후 12:39, Daeho Jeong <daeho43@gmail.com>님이 작성:
>>>>
>>>> It's way better~ :)
>>>>
>>>> 2020년 9월 4일 (금) 오후 12:11, Chao Yu <yuchao0@huawei.com>님이 작성:
>>>>>
>>>>>
>>>>>
>>>>> On 2020/9/3 10:44, Daeho Jeong wrote:
>>>>>> From: Daeho Jeong <daehojeong@google.com>
>>>>>>
>>>>>> 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 <daehojeong@google.com>
>>>>>> ---
>>>>>> Changes in v2:
>>>>>>    - Move declaration to header file
>>>>>> ---
>>>>>>    tools/f2fs_io/f2fs_io.c | 37 +++++++++++++++++--------------------
>>>>>>    tools/f2fs_io/f2fs_io.h | 26 ++++++++++++++++++++++++++
>>>>>>    2 files changed, 43 insertions(+), 20 deletions(-)
>>>>>>
>>>>>> diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
>>>>>> index abb655a..9a651c0 100644
>>>>>> --- a/tools/f2fs_io/f2fs_io.c
>>>>>> +++ b/tools/f2fs_io/f2fs_io.c
>>>>>> @@ -631,27 +631,17 @@ 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;
>>>>>>        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 +649,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]) * 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, FIEMAP, fm) < 0)
>>>>>> +                     die_errno("FIEMAP failed");
>>>>>>
>>>>>> -             printf("%u ", blknum);
>>>>>> +             phy_addr = fm->fm_extent[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);
>>>>>>    }
>>>>>>
>>>>>> diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
>>>>>> index bd19ff9..62d6e7b 100644
>>>>>> --- a/tools/f2fs_io/f2fs_io.h
>>>>>> +++ b/tools/f2fs_io/f2fs_io.h
>>>>>> @@ -38,6 +38,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
>>>>>> @@ -132,6 +135,29 @@ typedef u32      __be32;
>>>>>>    #define FS_CASEFOLD_FL                      0x40000000 /* Folder is case insensitive */
>>>>>>    #endif
>>>>>>
>>>>>> +struct fiemap_extent {
>>>>>> +     u64 fe_logical;
>>>>>> +     u64 fe_physical;
>>>>>> +     u64 fe_length;
>>>>>> +     u64 fe_reserved64[2];
>>>>>> +     u32 fe_flags;
>>>>>> +     u32 fe_reserved[3];
>>>>>> +};
>>>>>> +
>>>>>> +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];
>>>>>> +};
>>>>>
>>>>> We don't need to copy & paste fiemap related structure here.
>>>>>
>>>>> Let's just include <linux/fiemap.h> in f2fs_io.h
>>>>>
>>>>> Thanks,
>>>>>
>>>>>> +
>>>>>> +#ifndef FIEMAP
>>>>>> +#define FIEMAP                               _IOWR('f', 11, struct fiemap)
>>>>>> +#endif
>>>>>> +
>>>>>>    struct f2fs_gc_range {
>>>>>>        u32 sync;
>>>>>>        u64 start;
>>>>>>
>>> .
>>>
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-09-08 14:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-03  2:44 [f2fs-dev] [PATCH v2] f2fs_io: change fibmap to fiemap Daeho Jeong
2020-09-04  3:11 ` Chao Yu
     [not found]   ` <CACOAw_xAjUEyVo0Jm4yPvg7KB4G=Mz=tSEQ_wz6OH-P+e_cP8Q@mail.gmail.com>
2020-09-08  0:52     ` Daeho Jeong
2020-09-08  1:42       ` Chao Yu
2020-09-08  2:09         ` Daeho Jeong
2020-09-08 14:41           ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).