From: Omar Sandoval <osandov@osandov.com>
To: linux-fsdevel@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>
Cc: kernel-team@fb.com, linux-api@vger.kernel.org,
linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
linux-xfs@vger.kernel.org
Subject: [PATCH] xfs_io: add AT_UTIME_BTIME support
Date: Thu, 14 Feb 2019 02:00:16 -0800 [thread overview]
Message-ID: <347edcff487b59d56844f51eb74a42220fac64c9.1550138137.git.osandov@fb.com> (raw)
In-Reply-To: <cover.1550136164.git.osandov@fb.com>
From: Omar Sandoval <osandov@fb.com>
In order to test updating btime, make the utimes command optionally take
the btime timestamp.
Signed-off-by: Omar Sandoval <osandov@fb.com>
---
io/utimes.c | 41 +++++++++++++++++++++++++++++++----------
man/man8/xfs_io.8 | 5 +++--
2 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/io/utimes.c b/io/utimes.c
index 40117472..72ce68f3 100644
--- a/io/utimes.c
+++ b/io/utimes.c
@@ -4,11 +4,18 @@
* All Rights Reserved.
*/
+#include <fcntl.h>
+#include <sys/syscall.h>
+
#include "command.h"
#include "input.h"
#include "init.h"
#include "io.h"
+#ifndef AT_UTIME_BTIME
+#define AT_UTIME_BTIME 0x8000
+#endif
+
static cmdinfo_t utimes_cmd;
static void
@@ -16,9 +23,10 @@ utimes_help(void)
{
printf(_(
"\n"
-" Update file atime and mtime of the current file with nansecond precision.\n"
+" Update file atime, mtime, and optionally btime of the current file with\n"
+" nansecond precision.\n"
"\n"
-" Usage: utimes atime_sec atime_nsec mtime_sec mtime_nsec.\n"
+" Usage: utimes atime_sec atime_nsec mtime_sec mtime_nsec [btime_sec btime_nsec]\n"
" *_sec: Seconds elapsed since 1970-01-01 00:00:00 UTC.\n"
" *_nsec: Nanoseconds since the corresponding *_sec.\n"
"\n"));
@@ -29,9 +37,13 @@ utimes_f(
int argc,
char **argv)
{
- struct timespec t[2];
+ struct timespec t[3];
+ int flags = 0;
int result;
+ if (argc == 6)
+ return command_usage(&utimes_cmd);
+
/* Get the timestamps */
result = timespec_from_string(argv[1], argv[2], &t[0]);
if (result) {
@@ -43,13 +55,22 @@ utimes_f(
fprintf(stderr, "Bad value for mtime\n");
return 0;
}
-
- /* Call futimens to update time. */
- if (futimens(file->fd, t)) {
- perror("futimens");
- return 0;
+ if (argc == 7) {
+ result = timespec_from_string(argv[5], argv[6], &t[2]);
+ if (result) {
+ fprintf(stderr, "Bad value for btime\n");
+ return 0;
+ }
+ flags |= AT_UTIME_BTIME;
}
+ /*
+ * Use syscall() because the glibc wrapper for utimensat() disallows a
+ * NULL pathname.
+ */
+ if (syscall(SYS_utimensat, file->fd, NULL, t, flags))
+ perror("utimensat");
+
return 0;
}
@@ -59,9 +80,9 @@ utimes_init(void)
utimes_cmd.name = "utimes";
utimes_cmd.cfunc = utimes_f;
utimes_cmd.argmin = 4;
- utimes_cmd.argmax = 4;
+ utimes_cmd.argmax = 6;
utimes_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
- utimes_cmd.args = _("atime_sec atime_nsec mtime_sec mtime_nsec");
+ utimes_cmd.args = _("atime_sec atime_nsec mtime_sec mtime_nsec [btime_sec btime_nsec]");
utimes_cmd.oneline = _("Update file times of the current file");
utimes_cmd.help = utimes_help;
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index fbf50df5..dbf8098b 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -827,8 +827,9 @@ verbose output will be printed.
.RE
.PD
.TP
-.BI utimes " atime_sec atime_nsec mtime_sec mtime_nsec"
-The utimes command changes the atime and mtime of the current file.
+.BI utimes " atime_sec atime_nsec mtime_sec mtime_nsec [btime_sec btime_nsec]"
+The utimes command changes the atime, mtime, and optionally btime of the
+current file.
sec uses UNIX timestamp notation and is the seconds elapsed since
1970-01-01 00:00:00 UTC.
nsec is the nanoseconds since the sec. This value needs to be in
--
2.20.1
next prev parent reply other threads:[~2019-02-14 10:01 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-14 10:00 [RFC PATCH 0/6] Allow setting file birth time with utimensat() Omar Sandoval
2019-02-14 10:00 ` [RFC PATCH 1/6] fs: add btime to struct iattr Omar Sandoval
2019-02-14 10:00 ` [RFC PATCH 2/6] fs: add AT_UTIME_BTIME for utimensat() Omar Sandoval
2019-02-14 10:00 ` [RFC PATCH 3/6] Btrfs: add support for setting btime Omar Sandoval
2019-02-14 10:00 ` [RFC PATCH 4/6] ext4: " Omar Sandoval
2019-02-14 10:00 ` [RFC PATCH 5/6] f2fs: " Omar Sandoval
2019-02-14 10:00 ` [RFC PATCH 6/6] xfs: " Omar Sandoval
2019-02-14 10:00 ` [PATCH] generic: add a test for AT_UTIME_BTIME Omar Sandoval
2019-02-14 10:00 ` [PATCH] utimensat2: document AT_UTIME_BTIME Omar Sandoval
2019-02-14 10:00 ` Omar Sandoval [this message]
2019-02-14 22:06 ` [RFC PATCH 0/6] Allow setting file birth time with utimensat() Dave Chinner
2019-02-14 23:14 ` Omar Sandoval
2019-02-15 0:16 ` Dave Chinner
2019-02-15 6:59 ` Omar Sandoval
2019-02-15 13:57 ` David Disseldorp
2019-02-17 1:57 ` Andreas Dilger
2019-02-18 22:18 ` Dave Chinner
2019-02-22 19:00 ` Omar Sandoval
2019-02-23 18:32 ` Andreas Dilger
2019-02-17 16:35 ` Boaz Harrosh
2019-02-17 17:54 ` Adam Borowski
2019-02-17 20:40 ` Andy Lutomirski
2019-02-19 4:04 ` Matthew Wilcox
2019-02-19 4:28 ` Dave Chinner
2019-02-20 7:47 ` Andreas Dilger
2019-02-15 1:57 ` Hans van Kranenburg
2019-02-15 5:39 ` Omar Sandoval
2019-02-15 18:25 ` Hans van Kranenburg
2019-02-22 15:02 ` David Sterba
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=347edcff487b59d56844f51eb74a42220fac64c9.1550138137.git.osandov@fb.com \
--to=osandov@osandov.com \
--cc=kernel-team@fb.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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).