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: 10812279 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 ADCA113B4 for ; Thu, 14 Feb 2019 10:01:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B03C2CCBE for ; Thu, 14 Feb 2019 10:01:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F5BF2CCD9; Thu, 14 Feb 2019 10:01:15 +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=ham 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 24FD62CCBE for ; Thu, 14 Feb 2019 10:01:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438158AbfBNKBN (ORCPT ); Thu, 14 Feb 2019 05:01:13 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:40032 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438164AbfBNKBM (ORCPT ); Thu, 14 Feb 2019 05:01:12 -0500 Received: by mail-pf1-f193.google.com with SMTP id h1so2847510pfo.7 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=Zurw3YIJiHTATQrVE1FGxbKaTofNwMKvm+R6EVXe5OgCZPc+hn3G9kJTXf7GHso/Ap 9oY2rMMwwXRxglwXpQ8WnEwCODQ8TOb5fAvy9bi+KxStd6J2Eigx/CWoDD5c493r4UCU ULkpEqeu7P0bZj2kUdtc+9Jwjg1JU+b/BT/VWS7yqb55mzR1n7sonCLZczWz1qqZzRG9 oZJtLuG6RKh59speqJ7/iQSrzGJFuJCBr9iWvVfO6C12wYC3LDwnLsvR8ZrEGdF1m2JB 0ZUNdZ14EThFlJ+ebozUUu+UICjkEZ3+dNQMD2bS46CiOwJ7rqNNTgdCKMum9VtIcLae ZAjw== X-Gm-Message-State: AHQUAuZ0MiX0l87MAxz46/02WnRm46+ZqdUFGqjaRsMi3poxyWnGCYHj BcxnVBHpYIz/JTWvWLtBTwd/UA== 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-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@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