From: Daeho Jeong <daeho43@gmail.com>
To: linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com
Cc: Daeho Jeong <daehojeong@google.com>
Subject: [PATCH] f2fs_io: add lseek command to execute lseek()
Date: Thu, 15 Feb 2024 12:10:53 -0800 [thread overview]
Message-ID: <20240215201053.2364270-1-daeho43@gmail.com> (raw)
From: Daeho Jeong <daehojeong@google.com>
Added lseek command to support lseek() for SEEK_DATA and SEEK_HOLE.
Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
tools/f2fs_io/f2fs_io.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index e7d286a..b5c5b97 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -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 }
};
--
2.43.0.687.g38aa6559b0-goog
next reply other threads:[~2024-02-15 20:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-15 20:10 Daeho Jeong [this message]
2024-02-15 20:36 ` [PATCH] f2fs_io: add lseek command to execute lseek() Jaegeuk Kim
2024-02-15 20:39 ` Daeho Jeong
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=20240215201053.2364270-1-daeho43@gmail.com \
--to=daeho43@gmail.com \
--cc=daehojeong@google.com \
--cc=kernel-team@android.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/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