From patchwork Thu Feb 14 10:00:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10812285 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA59313B5 for ; Thu, 14 Feb 2019 10:01:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B6262CA1A for ; Thu, 14 Feb 2019 10:01:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F0EB2CD13; Thu, 14 Feb 2019 10:01:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31C9E2CA1A for ; Thu, 14 Feb 2019 10:01:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438177AbfBNKBQ (ORCPT ); Thu, 14 Feb 2019 05:01:16 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43719 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438161AbfBNKBN (ORCPT ); Thu, 14 Feb 2019 05:01:13 -0500 Received: by mail-pf1-f194.google.com with SMTP id q17so2837624pfh.10 for ; Thu, 14 Feb 2019 02:01:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/zlJMQVShzJL9k1uGmTZzqfsPZnaTknAh/i9pkCAsy4=; b=dIvXE9h0N0Wd3Td0GE339/VChq1N0CIZ1uionCe/SPLS1PbzR9f6SK5wdW6s6X7VZz 25gaDoZM4cK2531I1SsAxO9Yq7hNvXPEbQCC8zHufjfEcWTE8hVvCbWKFGa/tWTOJzgD NKIDgmGYeAuvMiTJYnJgd2d2zUoNd9gQAWoj/0Qss21ZPbgJwMfUI87n/91CtYaLVPBV rhIwEzXUs8rdVQos+PZVhf2eFw8fU60YlornbozjACLJzSOGD0zVOHKdBcxFj+c9IDtf ufG55FGueD3JfbVpi2hNOF16JU6dZLzkWAfgNFN3vRTcG9DQhZRFApFTaNq/woZsnrXL 3SWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/zlJMQVShzJL9k1uGmTZzqfsPZnaTknAh/i9pkCAsy4=; b=ktpd04g3Y1InkatlVNiyUaML/XsJzWvWZyImvdNTUSucAqOe9nDGIq2DHjvQDuO/eD JluDQMchPZ4U8kqypSfSHHbOSHmW82ZehizCPI32Qw8kpPexJwFU8Ts1CikVwim0ngel 0n3CzATMdsxhULGchHE8tOKF6zzPjjU1LqcbY8k1Z0Fv6/xR9Z5vATcaqFxmTZ6DMqWE f8vm5Il0r8mL7e/HIRM+4bs/k5ERgHQakmG9o83ExN0Cznk602wchcGGAof3eByK02ku YO0nUBiK/zrPdk/+YmenDOD4mYGvfZjJDy2Bq8g0/OYBHbu28EAjfZwjOudjszSFVG0a BXBA== X-Gm-Message-State: AHQUAuZuj3kVZkBFe2tTMMOz3x36BqJgZS+RPeo1cLAESIZp+bQ2AkEy cGS0ogYW9WlKh1oazcjHLvMS7g== X-Google-Smtp-Source: AHgI3IaoJoQ7v0RWU/FxKUBpUH++Bh+NK6gVEVHdFAhRL/3vNVOxPJkKlHtZWDXsogFQG78EfoG2CQ== X-Received: by 2002:a65:46cf:: with SMTP id n15mr2975477pgr.187.1550138471684; Thu, 14 Feb 2019 02:01:11 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:180::1:5849]) by smtp.gmail.com with ESMTPSA id i184sm2686952pfc.41.2019.02.14.02.01.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 02:01:10 -0800 (PST) From: Omar Sandoval To: linux-fsdevel@vger.kernel.org, Al Viro 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 Message-Id: <347edcff487b59d56844f51eb74a42220fac64c9.1550138137.git.osandov@fb.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval In order to test updating btime, make the utimes command optionally take the btime timestamp. Signed-off-by: Omar Sandoval --- 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 +#include + #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