f2fs_io: add lseek command to execute lseek()
PATCH 1/1 f2fs_io: add lseek command to execute lseek()
From: Daeho Jeong <[email protected]>
Added lseek command to support lseek() for SEEK_DATA and SEEK_HOLE.
Signed-off-by Daeho Jeong <[email protected]>
--- tools/f2fs_io/f2fs_io.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
tools/f2fs_io/f2fs_io.c +38 -0
@@ -1630,6 +1630,43 @@ static void do_removexattr(int argc, char **argv, const struct cmd_desc *cmd)exit (0 ); } +#define lseek_desc "do lseek for SEEK_DATA or SEEK_HOLE for a file" +#define lseek_help \ +"f2fs_io lseek [whence] [offset] [file_path]\n\n" \ +"Do lseek file data in file_path\n" \ +"whence can be\n" \ +" data : SEEK_DATA, return the file offset to the next data location from offset\n"\ +" hole : SEEK_HOLE, return the file offset to the next hole from offset\n" + +static void do_lseek (int argc,char **argv,const struct cmd_desc *cmd) +{ +int fd, whence; +off_t offset, ret; + +if (argc !=4 ) { +fputs ("Excess arguments\n\n" , stderr); +fputs (cmd->cmd_help, stderr); +exit (1 ); + } + + offset =atoi (argv[2 ]); + +if (!strcmp (argv[1 ],"data" )) + whence =SEEK_DATA ; +else if (!strcmp (argv[1 ],"hole" )) + whence =SEEK_HOLE ; +else +die ("Wrong whence type" ); + + fd =xopen (argv[3 ],O_RDONLY ,0 ); + + ret =lseek (fd, offset, whence); +if (ret <0 ) +die_errno ("lseek failed" ); +printf ("returned offset=%ld\n" , ret); +exit (0 ); +} +#define CMD_HIDDEN 0x0001#define CMD (name) { #name, do_##name, name##_desc, name##_help, 0 }#define _CMD (name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }
@@ -1671,6 +1708,7 @@ const struct cmd_desc cmd_list[] = {CMD (listxattr),CMD (setxattr),CMD (removexattr), +CMD (lseek), { NULL, NULL, NULL, NULL, 0 } };
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
Quoted 14 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
Added lseek command to support
lseek()forSEEK_DATAandSEEK_HOLE.Signed-off-by Daeho Jeong <[email protected]>--- tools/f2fs_io/f2fs_io.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)tools/f2fs_io/f2fs_io.c +0
-0
tools/f2fs_io/f2fs_io.c static void do_removexattr(int argc, char **argv, const struct cmd_desc *cmd) · line 1637
Quoted 8 lines
tools/f2fs_io/f2fs_io.c +5
-0@@ -1630,6 +1630,43 @@ static void do_removexattr(int argc, char **argv, const struct cmd_desc *cmd)exit (0 ); } +#define lseek_desc "do lseek for SEEK_DATA or SEEK_HOLE for a file" +#define lseek_help \ +"f2fs_io lseek [whence] [offset] [file_path]\n\n" \ +"Do lseek file data in file_path\n" \ +"whence can be\n" \
Can we also have all the other options as well?
Quoted 46 lines
tools/f2fs_io/f2fs_io.c +33
-0+" data : SEEK_DATA, return the file offset to the next data location from offset\n" \ +" hole : SEEK_HOLE, return the file offset to the next hole from offset\n" + +static void do_lseek(int argc, char **argv, const struct cmd_desc *cmd) +{ +int fd, whence; +off_t offset, ret; + +if (argc !=4 ) { +fputs ("Excess arguments\n\n" , stderr); +fputs (cmd->cmd_help, stderr); +exit (1 ); + } + + offset =atoi (argv[2 ]); + +if (!strcmp (argv[1 ],"data" )) + whence =SEEK_DATA ; +else if (!strcmp (argv[1 ],"hole" )) + whence =SEEK_HOLE ; +else +die ("Wrong whence type" ); + + fd =xopen (argv[3 ],O_RDONLY ,0 ); + + ret =lseek (fd, offset, whence); +if (ret <0 ) +die_errno ("lseek failed" ); +printf ("returned offset=%ld\n" , ret); +exit (0 ); +} +#define CMD_HIDDEN 0x0001#define CMD (name) { #name, do_##name, name##_desc, name##_help, 0 }#define _CMD (name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }@@ -1671,6 +1708,7 @@ const struct cmd_desc cmd_list[] = {CMD (listxattr),CMD (setxattr),CMD (removexattr), +CMD (lseek), { NULL, NULL, NULL, NULL, 0 } };Signature · 1 line
2.43.0.687.g38aa6559b0-goog
Quoted 19 lines · Jaegeuk Kim
Quoted 17 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
Added lseek command to support
lseek()forSEEK_DATAandSEEK_HOLE.Signed-off-by Daeho Jeong <[email protected]>--- tools/f2fs_io/f2fs_io.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)tools/f2fs_io/f2fs_io.c +0
-0@@ -1630,6 +1630,43 @@ static void do_removexattr(int argc, char **argv, const struct cmd_desc *cmd)exit (0 ); }
Quoted 7 lines
tools/f2fs_io/f2fs_io.c static void do_removexattr(int argc, char **argv, const struct cmd_desc *cmd) · line 1637
Quoted 5 lines
tools/f2fs_io/f2fs_io.c +5
-0+#define lseek_desc "do lseek for SEEK_DATA or SEEK_HOLE for a file" +#define lseek_help \ +"f2fs_io lseek [whence] [offset] [file_path]\n\n" \ +"Do lseek file data in file_path\n" \ +"whence can be\n" \Can we also have all the other options as well?
Sounds good.
Quoted 47 lines
Quoted 47 lines
tools/f2fs_io/f2fs_io.c +33
-1+" data : SEEK_DATA, return the file offset to the next data location from offset\n" \ +" hole : SEEK_HOLE, return the file offset to the next hole from offset\n" + +static void do_lseek(int argc, char **argv, const struct cmd_desc *cmd) +{ +int fd, whence; +off_t offset, ret; + +if (argc !=4 ) { +fputs ("Excess arguments\n\n" , stderr); +fputs (cmd->cmd_help, stderr); +exit (1 ); + } + + offset =atoi (argv[2 ]); + +if (!strcmp (argv[1 ],"data" )) + whence =SEEK_DATA ; +else if (!strcmp (argv[1 ],"hole" )) + whence =SEEK_HOLE ; +else +die ("Wrong whence type" ); + + fd =xopen (argv[3 ],O_RDONLY ,0 ); + + ret =lseek (fd, offset, whence); +if (ret <0 ) +die_errno ("lseek failed" ); +printf ("returned offset=%ld\n" , ret); +exit (0 ); +} +#define CMD_HIDDEN 0x0001#define CMD (name) { #name, do_##name, name##_desc, name##_help, 0 }#define _CMD (name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }@@ -1671,6 +1708,7 @@ const struct cmd_desc cmd_list[] = {CMD (listxattr),CMD (setxattr),CMD (removexattr), +CMD (lseek), { NULL, NULL, NULL, NULL, 0 } }; --2.43.0.687.g38aa6559b0-goog