linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [f2fs-dev] [PATCH] f2fs_io: add fallocate
Date: Wed, 17 Jul 2019 20:29:29 -0700	[thread overview]
Message-ID: <20190718032929.80184-1-jaegeuk@kernel.org> (raw)

This simply supports keep_size.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 tools/f2fs_io/f2fs_io.c | 45 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

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),
-- 
2.19.0.605.g01d371f741-goog



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

                 reply	other threads:[~2019-07-18  3:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190718032929.80184-1-jaegeuk@kernel.org \
    --to=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).