diff options
author | Jaegeuk Kim <jaegeuk@kernel.org> | 2019-07-12 15:25:17 -0700 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2019-08-20 11:23:51 -0700 |
commit | 7c8df9e026483da8e783e1d5bd1988ab9109ba10 (patch) | |
tree | 7afeb14b0a349627599bd76a20651838b9e1c4dc | |
parent | e8728ca25c922b7de9d85b466dda8b61bf5f11fe (diff) | |
download | f2fs-tools-7c8df9e026483da8e783e1d5bd1988ab9109ba10.tar.gz |
f2fs_io: add fallocate
This simply supports keep_size.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r-- | tools/f2fs_io/f2fs_io.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c index 7fd4425..f087da4 100644 --- a/tools/f2fs_io/f2fs_io.c +++ b/tools/f2fs_io/f2fs_io.c @@ -141,6 +141,50 @@ static void do_pinfile(int argc, char **argv, const struct cmd_desc *cmd) exit(0); } +#define fallocate_desc "fallocate" +#define fallocate_help \ +"f2fs_io fallocate [keep_size] [offset] [length] [file]\n\n" \ +"fallocate given the file\n" \ +" [keep_size] : 1 or 0\n" \ + +static void do_fallocate(int argc, char **argv, const struct cmd_desc *cmd) +{ + int fd; + off_t offset, length; + struct stat sb; + int mode = 0; + + if (argc != 5) { + fputs("Excess arguments\n\n", stderr); + fputs(cmd->cmd_help, stderr); + exit(1); + } + + if (!strcmp(argv[1], "1")) + mode |= FALLOC_FL_KEEP_SIZE; + + offset = atoi(argv[2]); + length = atoi(argv[3]); + + fd = open(argv[4], O_RDWR); + if (fd == -1) { + fputs("Open failed\n\n", stderr); + fputs(cmd->cmd_help, stderr); + exit(1); + } + + if (fallocate(fd, mode, offset, length)) { + fputs("fallocate failed\n\n", stderr); + exit(1); + } + if (fstat(fd, &sb) == -1) { + fputs("Stat failed\n\n", stderr); + exit(1); + } + printf("fallocated a file: i_size=%"PRIu64", i_blocks=%"PRIu64"\n", sb.st_size, sb.st_blocks); + exit(0); +} + #define write_desc "write data into file" #define write_help \ "f2fs_io write [chunk_size in 4kb] [offset in chunk_size] [count] [pattern] [IO] [file_path]\n\n" \ @@ -407,6 +451,7 @@ const struct cmd_desc cmd_list[] = { _CMD(help), CMD(shutdown), CMD(pinfile), + CMD(fallocate), CMD(write), CMD(read), CMD(fiemap), |