f2fs-tools: add ftruncate command in f2fs_io
PATCH 1/1 f2fs-tools: add ftruncate command in f2fs_io
From: Daeho Jeong <[email protected]>
add ftruncate command to do file truncate.
Signed-off-by Daeho Jeong <[email protected]>
--- tools/f2fs_io/f2fs_io.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
tools/f2fs_io/f2fs_io.c +26 -0
@@ -1887,6 +1887,31 @@ static void do_get_advise(int argc, char **argv, const struct cmd_desc *cmd)printf ("\n" ); } +#define ftruncate_desc "ftruncate a file" +#define ftruncate_help \ +"f2fs_io ftruncate [length] [file_path]\n\n" \ +"Do ftruncate a file in file_path with the length\n" \ + +static void do_ftruncate (int argc,char **argv,const struct cmd_desc *cmd) +{ +int fd, ret; +off_t length; + +if (argc !=3 ) { +fputs ("Excess arguments\n\n" , stderr); +fputs (cmd->cmd_help, stderr); +exit (1 ); + } + + length =atoll (argv[1 ]); + fd =xopen (argv[2 ],O_WRONLY ,0 ); + + ret =ftruncate (fd, length); +if (ret <0 ) +die_errno ("ftruncate failed" ); +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 }
@@ -1932,6 +1957,7 @@ const struct cmd_desc cmd_list[] = {CMD (removexattr),CMD (lseek),CMD (get_advise), +CMD (ftruncate), { NULL, NULL, NULL, NULL, 0 } };
Signature · 1 line
2.48.1.658.g4767266eb4-goog
Quoted 3 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
add ftruncate command to do file truncate.
Need to update manual of f2fs_io as well?
Thanks,
Quoted 50 lines
Signed-off-by Daeho Jeong <[email protected]>--- tools/f2fs_io/f2fs_io.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)tools/f2fs_io/f2fs_io.c +26
-0@@ -1887,6 +1887,31 @@ static void do_get_advise(int argc, char **argv, const struct cmd_desc *cmd)printf ("\n" ); } +#define ftruncate_desc "ftruncate a file" +#define ftruncate_help \ +"f2fs_io ftruncate [length] [file_path]\n\n" \ +"Do ftruncate a file in file_path with the length\n" \ + +static void do_ftruncate (int argc,char **argv,const struct cmd_desc *cmd) +{ +int fd, ret; +off_t length; + +if (argc !=3 ) { +fputs ("Excess arguments\n\n" , stderr); +fputs (cmd->cmd_help, stderr); +exit (1 ); + } + + length =atoll (argv[1 ]); + fd =xopen (argv[2 ],O_WRONLY ,0 ); + + ret =ftruncate (fd, length); +if (ret <0 ) +die_errno ("ftruncate failed" ); +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 }@@ -1932,6 +1957,7 @@ const struct cmd_desc cmd_list[] = {CMD (removexattr),CMD (lseek),CMD (get_advise), +CMD (ftruncate), { NULL, NULL, NULL, NULL, 0 } };