From patchwork Wed Jul 18 11:49:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 142266 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp439254ljj; Wed, 18 Jul 2018 04:50:39 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcGKT1ROwTlQha4c40lb5SBEqHzBx4ET9ryBmHrGhU+YctNWbJjvODDqPUtWXB2a6gOwkKE X-Received: by 2002:a63:e60c:: with SMTP id g12-v6mr5571302pgh.308.1531914639738; Wed, 18 Jul 2018 04:50:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531914639; cv=none; d=google.com; s=arc-20160816; b=oicoDx+N8Fa69BuA2NmiiqrVV2vZmBCEZJMgmQuCXEcSzSR3/qRxYgfKhbeFleM/mb dUltH/ghev/HNRBN+WFrV+cp2jeGpoXDs4rXPWxZmDb9w5U8Oh7HNlfZrGU6+wjHHUYS cgPI017r8nZ2HOntJREy64SGS6kAXwwGJ3mNMaK+buKE3Sl1ao0D7X93WrocD4la813i Daim0T5tG72c8ae5klwaCpLQEJL7c+7TtIDOBiel/RlClNjTrgjJDtfX+4zmKgjiIJJt n/oDwMOPGDVgvuh5K9NureZ287mIrUcYtbdoqxYfRA11WNvD+83Srz7YqvtFRHpLjZ9C 3/ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=doBexfwE/ngFs9V2dUlDsvJdkyR1txLIIpWcYgJEW4U=; b=R2tgpAdz4ABSdvu6FlnCMroHhxF/f5Q5GfqHH0jHeypYENbnvwfBARk1wddIFMJuFZ C/j0Og0V3zFvQbAEQepD5roFZ20gH39OZqN0yzgLiGEK2KRaRT/TB7FUMoUZX9YiJLAr 5qN+hI+cC4LAsgSV/tGWh123Jjqtpj8MXzzpjqvGqMlZR1EwGwRm4cINIQObs1Sl0A7Q yf0TzqbWqiZbp1hOO8JipzGaOK/UQ6kFmi/snO0t+E09my6H8ekzU+YqUe8o6cK1hUq+ DKjSoUjeaxozBs7FYxcXHtufVSME4zATN2+A8pOF95r7ULbgPpdO0fn28AcuTHA+JIx7 OePQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b14-v6si3396112pfc.216.2018.07.18.04.50.39; Wed, 18 Jul 2018 04:50:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729325AbeGRM2I (ORCPT + 31 others); Wed, 18 Jul 2018 08:28:08 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:45381 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726158AbeGRM2I (ORCPT ); Wed, 18 Jul 2018 08:28:08 -0400 Received: from wuerfel.lan ([46.223.138.35]) by mrelayeu.kundenserver.de (mreue005 [212.227.15.129]) with ESMTPA (Nemesis) id 0MUjoe-1fY6V828xY-00YAUg; Wed, 18 Jul 2018 13:50:22 +0200 From: Arnd Bergmann To: akpm@linux-foundation.org, Evgeniy Dushistov Cc: viro@zeniv.linux.org.uk, y2038@lists.linaro.org, linux-fsdevel@vger.kernel.org, Arnd Bergmann , Thomas Gleixner , Jeff Layton , David Howells , David Windsor , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] [RESEND] ufs: use ktime_get_real_seconds for sb and cg timestamps Date: Wed, 18 Jul 2018 13:49:24 +0200 Message-Id: <20180718115017.742609-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K1:uzKXm1YigPEMvmdjHlAyGCUK5yH9uK2elhy5sLfEGSW6oMXuGv7 NED5zFxCWkbLOAbWUCE+4sIHOVuGY/y3Wr3lbvCzIKiX6Q1HBcQu94NcuYJjDu0fXPdgBg3 hPC0dn/zyq7lMUGBQBsQxm3wFrUNcOR36iKycDn0KHVZasgQvN+F9hScsyJ6F8pHB/mFxso O74XPLbK/mx20+SlodhDw== X-UI-Out-Filterresults: notjunk:1; V01:K0:WE5naEZegOY=:aWCsXwLuHdd44LJvqwk7ml M34TTDLnmeed8ldeN1YEEUTAohHGG4K8LvA101QFKfxWr8p8qx/DhfYHWffrBM7eTZKPYlaHn mTWt3VI8uMC+hNci9JLKPd0cosQuk1au5ZizNE3SL3fLJB8fAsNBzZJZP7pdo5vma36Z9ZYsx JX3habK0fYs2bcSRFUPu+qqnCsUGv3VZX5VigXye4sQyMbzYSudgqCMwTuAyM0JauPJh7I2Vi VYSyxctxOJ+ZUj9ucgsPQhAGQuxJfRFDDAnSR8z6fXpSuT5Cz4hKFxJm9ImcJEDaypIl4ObYC ES6JXtbHRE9rYsKloD0Tf1oOAM1UtFK24kOeynSRdqIP9/a0Ezy00l2zghLPS4gafBaz2BhOZ 15t2D0Nr3Bhr0feA47U1qEEiP3jaStvoTfkSgrj80TE5PjmZ4i33NUUXfIVqbBymCQ47dISkn NwNcGDs3QPKEkh7KebfEQax+Oa51gNK7YHH+XH0u52qsx+CD9YuJMugh6DSGxnrjJ4xeEBnso Gjln/rdy/LIxw7UMtAEoNVc+SFlgrym0YTdzAz4GK5ryYexHymDVUw3GB1BjDxA1eu+jamuAh TieHrNdd+V3z4wh9ozMkE1Xru5O90OPEpUuyH4vcZes18hx7/HEzNoYI+3ypaBzgSDXMXk81Y h1l+m4M7e05bBUPtupahjzugTiGA5v2xiEbZ5dc5egPYK5RNTwClY+5kg3903wzqX4dY= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org get_seconds() is deprecated because of the 32-bit overflow and will be removed. All callers in ufs also truncate to a 32-bit number, so nothing changes during the conversion, but this should be harmless as the superblock and cylinder group timestamps are not visible to user space, except for checking the fs-dirty state, wich works fine across the overflow. This moves the call to get_seconds() into a new inline function, with a comment explaining the constraints, while converting it to ktime_get_real_seconds(). Acked-by: Thomas Gleixner Signed-off-by: Arnd Bergmann --- Originally sent on June 19, got an Ack but nobody picked up the patch. --- fs/ufs/balloc.c | 4 ++-- fs/ufs/ialloc.c | 2 +- fs/ufs/super.c | 4 ++-- fs/ufs/util.h | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 5 deletions(-) -- 2.9.0 diff --git a/fs/ufs/balloc.c b/fs/ufs/balloc.c index e727ee07dbe4..075d3d9114c8 100644 --- a/fs/ufs/balloc.c +++ b/fs/ufs/balloc.c @@ -547,7 +547,7 @@ static u64 ufs_add_fragments(struct inode *inode, u64 fragment, /* * Block can be extended */ - ucg->cg_time = cpu_to_fs32(sb, get_seconds()); + ucg->cg_time = ufs_get_seconds(sb); for (i = newcount; i < (uspi->s_fpb - fragoff); i++) if (ubh_isclr (UCPI_UBH(ucpi), ucpi->c_freeoff, fragno + i)) break; @@ -639,7 +639,7 @@ static u64 ufs_alloc_fragments(struct inode *inode, unsigned cgno, if (!ufs_cg_chkmagic(sb, ucg)) ufs_panic (sb, "ufs_alloc_fragments", "internal error, bad magic number on cg %u", cgno); - ucg->cg_time = cpu_to_fs32(sb, get_seconds()); + ucg->cg_time = ufs_get_seconds(sb); if (count == uspi->s_fpb) { result = ufs_alloccg_block (inode, ucpi, goal, err); diff --git a/fs/ufs/ialloc.c b/fs/ufs/ialloc.c index e1ef0f0a1353..c678fff2a04d 100644 --- a/fs/ufs/ialloc.c +++ b/fs/ufs/ialloc.c @@ -89,7 +89,7 @@ void ufs_free_inode (struct inode * inode) if (!ufs_cg_chkmagic(sb, ucg)) ufs_panic (sb, "ufs_free_fragments", "internal error, bad cg magic number"); - ucg->cg_time = cpu_to_fs32(sb, get_seconds()); + ucg->cg_time = ufs_get_seconds(sb); is_directory = S_ISDIR(inode->i_mode); diff --git a/fs/ufs/super.c b/fs/ufs/super.c index 96a20a76e3c4..f48a5b802221 100644 --- a/fs/ufs/super.c +++ b/fs/ufs/super.c @@ -698,7 +698,7 @@ static int ufs_sync_fs(struct super_block *sb, int wait) usb1 = ubh_get_usb_first(uspi); usb3 = ubh_get_usb_third(uspi); - usb1->fs_time = cpu_to_fs32(sb, get_seconds()); + usb1->fs_time = ufs_get_seconds(sb); if ((flags & UFS_ST_MASK) == UFS_ST_SUN || (flags & UFS_ST_MASK) == UFS_ST_SUNOS || (flags & UFS_ST_MASK) == UFS_ST_SUNx86) @@ -1344,7 +1344,7 @@ static int ufs_remount (struct super_block *sb, int *mount_flags, */ if (*mount_flags & SB_RDONLY) { ufs_put_super_internal(sb); - usb1->fs_time = cpu_to_fs32(sb, get_seconds()); + usb1->fs_time = ufs_get_seconds(sb); if ((flags & UFS_ST_MASK) == UFS_ST_SUN || (flags & UFS_ST_MASK) == UFS_ST_SUNOS || (flags & UFS_ST_MASK) == UFS_ST_SUNx86) diff --git a/fs/ufs/util.h b/fs/ufs/util.h index 1907be6d5808..1fd3011ea623 100644 --- a/fs/ufs/util.h +++ b/fs/ufs/util.h @@ -590,3 +590,17 @@ static inline int ufs_is_data_ptr_zero(struct ufs_sb_private_info *uspi, else return *(__fs32 *)p == 0; } + +static inline __fs32 ufs_get_seconds(struct super_block *sbp) +{ + time64_t now = ktime_get_real_seconds(); + + /* Signed 32-bit interpretation wraps around in 2038, which + * happens in ufs1 inode stamps but not ufs2 using 64-bits + * stamps. For superblock and blockgroup, let's assume + * unsigned 32-bit stamps, which are good until y2106. + * Wrap around rather than clamp here to make the dirty + * file system detection work in the superblock stamp. + */ + return cpu_to_fs32(sbp, lower_32_bits(now)); +} From patchwork Wed Jul 18 11:49:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 142267 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp439463ljj; Wed, 18 Jul 2018 04:50:53 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcv8FUGLj7+LjF7/elaI6SKbc7A4Dv9EfofJP0odT/7YbO3eINhpZIZUpJK+o232sCRsvz/ X-Received: by 2002:a17:902:9a8a:: with SMTP id w10-v6mr5603944plp.333.1531914653481; Wed, 18 Jul 2018 04:50:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531914653; cv=none; d=google.com; s=arc-20160816; b=zrCdoYTgDBloJssNdDjhWvoASrwLI61LHgw6MSNtDXJxPB9O27GMDe/QcEqkxbEnvs DMgic9NppffXWgCQTIS/wW+0u8z8oI4W84IrfiBjJgqK9xrRfjVU6T5pTyV+zkX9Z1YP Jw5yEs6u06rbXK+xtdvo3shlSNVP4Ou6UreSLU9dh9BQV816ZgbbxjoDRHCnZKleGt5I Hku3kwnEop9Iml2D00taEZXSgcslJbIEynrT+l04Z1lDcJFJFVUkU1bM84Rj3NnAHoLd HOcZqIMLQC1td6qSCyPO39X/V6l3sWHS106cwzJO97c2ac5phmTVUrbqGHsykUact+S3 RI2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=NZcfrtje0zwgtOO50psQST4DE5XEaNY3JpzFtw1VqIY=; b=imR/W5fF/MER/XNAkuBTo6rYovtRC8d7mERvumGto26fuGlQWMRtu7JwiRxnQf/bz6 dQpsgf6/OKT2QBI+0cM0pCyynltipNlbkEBifW6tD6Ptm9tOn3WwgPfZa7qODMVpaTD0 tMv7wWWlOpboQ/kUWg+KMnMuhqJToDplR3Qjt/IYWkxCv+74dV/GyEbaUdCBFO7BFkac xHFxNmMjDiBGze9qBpV10IKDZPTHLepjRZOu7DJ9fHmOKp4Z4+I7Sbt3U0G1WKVuKcoo 1/1Qcg8nQlWY8c2VHZZUT7gEYHIxF5Ry9zEvSo7DSc8ldd6+Iio6+ZmkX+41jd9d4wY9 0zpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3-v6si3006320plr.214.2018.07.18.04.50.53; Wed, 18 Jul 2018 04:50:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730053AbeGRM2X (ORCPT + 31 others); Wed, 18 Jul 2018 08:28:23 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:40520 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726180AbeGRM2W (ORCPT ); Wed, 18 Jul 2018 08:28:22 -0400 Received: from wuerfel.lan ([46.223.138.35]) by mrelayeu.kundenserver.de (mreue005 [212.227.15.129]) with ESMTPA (Nemesis) id 0Lpijq-1gHrgd01yA-00fQYG; Wed, 18 Jul 2018 13:50:33 +0200 From: Arnd Bergmann To: akpm@linux-foundation.org, Anton Altaparmakov Cc: viro@zeniv.linux.org.uk, y2038@lists.linaro.org, linux-fsdevel@vger.kernel.org, Arnd Bergmann , Deepa Dinamani , Jeff Layton , linux-ntfs-dev@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] [RESEND] ntfs: use timespec64 directly for timestamp conversion Date: Wed, 18 Jul 2018 13:49:25 +0200 Message-Id: <20180718115017.742609-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180718115017.742609-1-arnd@arndb.de> References: <20180718115017.742609-1-arnd@arndb.de> X-Provags-ID: V03:K1:48HS6bUrv82M+wTECIkvvM0e/wX0MoM1hFhZUZC8jtt8TrMTJbl dMink4CvqSzJoNiGejrjXT8dKfW58V8yv3Ddmb3AM6sDs/JTSgY6AnMLnXfDh6s53znUy9b OjhCItBi4pEtbKDvtXSAkucVGUBRc3nAHNKnepC1ucnwWLS63+rVNmtxFXIEpm0rvKNNG4D Y6l62X8H/vIaSs8nQMExw== X-UI-Out-Filterresults: notjunk:1; V01:K0:LzqsGoFDgLk=:p4bHRCyay8txTcpFNq33No zNJZSjywMEerCiTwNopQPrVbgzA/zdkxjS/P8jJ4bUfhCICcHXLW2bZg7UOLlbWMpKljKj53c 3exTiSQZWwSeu/kmMiCVIHzKbk58kkNhHcNObHppykiIRWcg4cmd3Ta3Wf5/SRzl/wy/MRDoE saW8FYeLylp08yMY71CqIPjOAzGr9rMfT4z0EV2Ex8BjfPFa4Ibcxit2dIepNDqJ8Yd9B0YJ+ x1xm6wSdmxlAUWvJkG6dmutHVVbN8Vb4SXQcYH69wHfc+ZSYTrZJ+e3UXG6ChZQk4KCMEJBG3 qEppI7mhV2yfe9ejFMGUgGlhKwp2zFfVR6ihGgysrPdK7exzgoq0NFhqdI8RS/2I80653HfH1 McG7ht8dN/V8TDXvasQU9xikYW5sv72ejwfSKdtYyf5EY/DfzSKKVP+C6hKRbVtWLybMNDIST A1ozY38lcbnTR1RB5PvCo9ElThuwAvNfDpnvncoRehebn7/lldSVn5p3HiE+VqtpKQMtYZJam XkN2s90sACKa4dRqpeiGvB10lVVsInFfCMr5HXy6O5X7P0pRXKuv5wTQvmlRdM0yaNLC5SwF+ AqpOl69oDjfeCmYY2fXdBZNjfy8byYN0zxL9fNVQQm2Jd6Zz8IofQsC9Fsv27om4SZBkYweMj UOBF7hY5RmOxqM5RyyF04pbxWo24LAZ00u5yuBTCx6Xn8ZjO72CMLGY4lGnWkBU9Aw0I= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that the VFS has been converted from timespec to timespec64 timestamps, only the conversion to/from ntfs timestamps uses 32-bit seconds. This changes that last missing piece to get the ntfs implementation y2038 safe on 32-bit architectures. Signed-off-by: Arnd Bergmann --- Originally sent on June 19, but got no reply --- fs/ntfs/inode.c | 12 ++++++------ fs/ntfs/time.h | 27 +++++++++++++++------------ 2 files changed, 21 insertions(+), 18 deletions(-) -- 2.9.0 diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index decaf75d1cd5..bd3221cbdd95 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -667,18 +667,18 @@ static int ntfs_read_locked_inode(struct inode *vi) * mtime is the last change of the data within the file. Not changed * when only metadata is changed, e.g. a rename doesn't affect mtime. */ - vi->i_mtime = timespec_to_timespec64(ntfs2utc(si->last_data_change_time)); + vi->i_mtime = ntfs2utc(si->last_data_change_time); /* * ctime is the last change of the metadata of the file. This obviously * always changes, when mtime is changed. ctime can be changed on its * own, mtime is then not changed, e.g. when a file is renamed. */ - vi->i_ctime = timespec_to_timespec64(ntfs2utc(si->last_mft_change_time)); + vi->i_ctime = ntfs2utc(si->last_mft_change_time); /* * Last access to the data within the file. Not changed during a rename * for example but changed whenever the file is written to. */ - vi->i_atime = timespec_to_timespec64(ntfs2utc(si->last_access_time)); + vi->i_atime = ntfs2utc(si->last_access_time); /* Find the attribute list attribute if present. */ ntfs_attr_reinit_search_ctx(ctx); @@ -2997,7 +2997,7 @@ int __ntfs_write_inode(struct inode *vi, int sync) si = (STANDARD_INFORMATION*)((u8*)ctx->attr + le16_to_cpu(ctx->attr->data.resident.value_offset)); /* Update the access times if they have changed. */ - nt = utc2ntfs(timespec64_to_timespec(vi->i_mtime)); + nt = utc2ntfs(vi->i_mtime); if (si->last_data_change_time != nt) { ntfs_debug("Updating mtime for inode 0x%lx: old = 0x%llx, " "new = 0x%llx", vi->i_ino, (long long) @@ -3006,7 +3006,7 @@ int __ntfs_write_inode(struct inode *vi, int sync) si->last_data_change_time = nt; modified = true; } - nt = utc2ntfs(timespec64_to_timespec(vi->i_ctime)); + nt = utc2ntfs(vi->i_ctime); if (si->last_mft_change_time != nt) { ntfs_debug("Updating ctime for inode 0x%lx: old = 0x%llx, " "new = 0x%llx", vi->i_ino, (long long) @@ -3015,7 +3015,7 @@ int __ntfs_write_inode(struct inode *vi, int sync) si->last_mft_change_time = nt; modified = true; } - nt = utc2ntfs(timespec64_to_timespec(vi->i_atime)); + nt = utc2ntfs(vi->i_atime); if (si->last_access_time != nt) { ntfs_debug("Updating atime for inode 0x%lx: old = 0x%llx, " "new = 0x%llx", vi->i_ino, diff --git a/fs/ntfs/time.h b/fs/ntfs/time.h index 01233989d5d1..24cd719f1fd2 100644 --- a/fs/ntfs/time.h +++ b/fs/ntfs/time.h @@ -36,16 +36,16 @@ * Convert the Linux UTC time @ts to its corresponding NTFS time and return * that in little endian format. * - * Linux stores time in a struct timespec consisting of a time_t (long at - * present) tv_sec and a long tv_nsec where tv_sec is the number of 1-second - * intervals since 1st January 1970, 00:00:00 UTC and tv_nsec is the number of - * 1-nano-second intervals since the value of tv_sec. + * Linux stores time in a struct timespec64 consisting of a time64_t tv_sec + * and a long tv_nsec where tv_sec is the number of 1-second intervals since + * 1st January 1970, 00:00:00 UTC and tv_nsec is the number of 1-nano-second + * intervals since the value of tv_sec. * * NTFS uses Microsoft's standard time format which is stored in a s64 and is * measured as the number of 100-nano-second intervals since 1st January 1601, * 00:00:00 UTC. */ -static inline sle64 utc2ntfs(const struct timespec ts) +static inline sle64 utc2ntfs(const struct timespec64 ts) { /* * Convert the seconds to 100ns intervals, add the nano-seconds @@ -63,7 +63,10 @@ static inline sle64 utc2ntfs(const struct timespec ts) */ static inline sle64 get_current_ntfs_time(void) { - return utc2ntfs(current_kernel_time()); + struct timespec64 ts; + + ktime_get_coarse_real_ts64(&ts); + return utc2ntfs(ts); } /** @@ -73,18 +76,18 @@ static inline sle64 get_current_ntfs_time(void) * Convert the little endian NTFS time @time to its corresponding Linux UTC * time and return that in cpu format. * - * Linux stores time in a struct timespec consisting of a time_t (long at - * present) tv_sec and a long tv_nsec where tv_sec is the number of 1-second - * intervals since 1st January 1970, 00:00:00 UTC and tv_nsec is the number of - * 1-nano-second intervals since the value of tv_sec. + * Linux stores time in a struct timespec64 consisting of a time64_t tv_sec + * and a long tv_nsec where tv_sec is the number of 1-second intervals since + * 1st January 1970, 00:00:00 UTC and tv_nsec is the number of 1-nano-second + * intervals since the value of tv_sec. * * NTFS uses Microsoft's standard time format which is stored in a s64 and is * measured as the number of 100 nano-second intervals since 1st January 1601, * 00:00:00 UTC. */ -static inline struct timespec ntfs2utc(const sle64 time) +static inline struct timespec64 ntfs2utc(const sle64 time) { - struct timespec ts; + struct timespec64 ts; /* Subtract the NTFS time offset. */ u64 t = (u64)(sle64_to_cpu(time) - NTFS_TIME_OFFSET); From patchwork Wed Jul 18 11:49:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 142268 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp439559ljj; Wed, 18 Jul 2018 04:51:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcVIhQ80jill8jnvfalIh7waotTObwo8hzoPXsOuxL6r4hdmS5XQ2RT1E8SyvCRezJm0BWN X-Received: by 2002:a17:902:5590:: with SMTP id g16-v6mr5461068pli.99.1531914660477; Wed, 18 Jul 2018 04:51:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531914660; cv=none; d=google.com; s=arc-20160816; b=FOhoAZQ9/bXJtH+Oj4b4VgqMfaPAWWi8FYov+JaD/VIUtDtYwp+7FaoJitlLBd2wE3 WO75c7JpXqpCBVYhEGtmGpmZSwfBtkJkWV5Fldfzfo08lI+EIrXhXLgcVpDP6ZwU2jYe dTpoE7nY3fWdYFbJcMcN4upx8Ob8VpK6Bwuph+L4IeR5xcCyP7CpM/dNFS5+gK6mthQd kOZohZksJTevsAvdDzC6FxiVu+0juAFYKfsZSm35U4Dv2p5YuR9m9No0RzJcrE8Btff9 /TfQvs8VVbG2FEg8Vl3ZD1SKepVsC1hz0S2RJoSmiYJ15rtVfQKoZcK1Lw4XT//nKoK9 u25w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=MD3e1NV72OsY78H/RFlLwevw+5i51/kk8zPqXhqSfhw=; b=dRYDLfoecAGekrn2GZ7oZ4jBQmhVrQOqlZm1LblYYk7I62Iiuaa2F8CSqh+qudINQK 9gjZDGM5+mEBNCuhbG4kPIxV577epdDX4JWJgpmSCsDDkhYApxV56vlTiUdSqj97qJ5J Bap2Cm4zR4TBqwVs4D5IxUH/IImsTQiiuiQYKi4nxB9PVrGm42jkyC3um+LRDcy/T+Rj 21TBP+pa7twCP3/Zbh8QWLVQAdkaCenuTj/VSgGK6WcaUciwLWkh5i1iWynN6YdeSZM3 YwzUCZ6n5HpEOlk85HO/LA1ouLi+70fsWmvITnl0wq3oLegkSILlKcuSVrxTDOktBD2a YwUA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p2-v6si3644063pli.289.2018.07.18.04.51.00; Wed, 18 Jul 2018 04:51:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730384AbeGRM23 (ORCPT + 31 others); Wed, 18 Jul 2018 08:28:29 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:58581 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726180AbeGRM23 (ORCPT ); Wed, 18 Jul 2018 08:28:29 -0400 Received: from wuerfel.lan ([46.223.138.35]) by mrelayeu.kundenserver.de (mreue005 [212.227.15.129]) with ESMTPA (Nemesis) id 0M9cAV-1fkOUL3v5j-00CwU9; Wed, 18 Jul 2018 13:50:47 +0200 From: Arnd Bergmann To: akpm@linux-foundation.org, Mikulas Patocka Cc: viro@zeniv.linux.org.uk, y2038@lists.linaro.org, linux-fsdevel@vger.kernel.org, Arnd Bergmann , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] [RESEND] hpfs: extend gmt_to_local() conversion to 64-bit times Date: Wed, 18 Jul 2018 13:49:26 +0200 Message-Id: <20180718115017.742609-3-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180718115017.742609-1-arnd@arndb.de> References: <20180718115017.742609-1-arnd@arndb.de> X-Provags-ID: V03:K1:JZwT7DxOgtYM8bHfurcaegwXpIyKn68Ug9IAHnmJ4BSmgkmal/F mjWKl5Y5dBhD5ltFygPAulTIvmGspZgN8443IC/OyB2xTVe5ITmT6o8ALcZV6oMqQmENqFd QX5dYD1vNDLAFOVAxoMhHDF4KOk/h78UiM+DxFMgOiZW4+lMfM16jothYS2IyeQKeD1MZ6/ CZlYd44C8GXz5AE96lDug== X-UI-Out-Filterresults: notjunk:1; V01:K0:TRSt9876ecw=:dKKG8faYZqu5oiH4a6JMgJ jVdw6VlvEHWwkOr0yIAP/MGiErMnT8564ldRFhkjy43fn449ez9yEZmXrbp7kzPSyCp9u8to6 TvWiMPz6uH6MtaPBpp2h9ZxA0cxvR+FMKoEu0UsrKlTzzn/hiZmhZkpfohxqikqj49VbOQ1yY pCWtSjf1RPX8zVjj69IjM24UOnGbMzqD7Tmp1sD1n+iUF1LcS/k+7c4okN3eqvoyo23LMM7ix 7Y2Pk3vc7OgTPSIb1ezAzCTqEhq6qrKuqCCQJos2cKwT9zWa/Xar/0p/iwlC7CSTBLVPjc2u0 ZiOe+W415/WG1OhoHyLzRjF1YEgIrfUuSkBn7a9RU2IsF2vPEFmvY3a44TEHpLPNIHfkTJzRG TJ+aBAf7GEELMCXa+cssiT45KIQ85utDg4LdUDAK964nh/6N1xHTH+OLkAm1tQ13wXqX7tznq 7eZS+T7f3ruM/7ZROVt6YVOcwX8ZQKNM4JfvrL1flYHyJ0dORdCAGa74kSEi23rOSxEThDjgR B1u0BMRIoHlmmCvlNRe/69+ufWNJ919vfDPSrVrqlykC73gr1Ps5XG6x+smOSKF/Cy0IqzpAY pyY+IliUwv6gdHaV8yuOZExXeFcVToFKxY9UB83ROY4/Kr6M0JjILR9jTR6OSexjRI6hsjmvx qyGD1koV/IDRNRK7oHHhZ/yowawndQSG/a2K6zKTWZbF6M9ErZTT3+vXAGYjYcpRI1x4= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The VFS timestamps are all 64-bit now, the only missing piece for hpfs is the internal conversion function. One interesting bit about hpfs is that it can already deal with moving the 136 year window of its timestamps to support a much wider range than other file systems with 32-bit timestamps. It also treats the timestamps as 'unsigned' on 64-bit architectures (but signed on 32-bit, because time_t always around to negative numbers in 2038). Changing the conversion to use time64_t makes 32-bit architectures behave the same way as 64-bit. For completeness, this also adds a clamp_t call for each conversion, so we don't wrap the timestamps but instead stay within the [0..U32_MAX] range of the on-disk timestamps. Signed-off-by: Arnd Bergmann --- Originally sent on June 19, but got no reply --- fs/hpfs/hpfs_fn.h | 13 ++++++++++--- fs/hpfs/namei.c | 12 ++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) -- 2.9.0 diff --git a/fs/hpfs/hpfs_fn.h b/fs/hpfs/hpfs_fn.h index 2a153aed4c19..ab2e7cc2ff33 100644 --- a/fs/hpfs/hpfs_fn.h +++ b/fs/hpfs/hpfs_fn.h @@ -334,16 +334,23 @@ long hpfs_ioctl(struct file *file, unsigned cmd, unsigned long arg); * local time (HPFS) to GMT (Unix) */ -static inline time_t local_to_gmt(struct super_block *s, time32_t t) +static inline time64_t local_to_gmt(struct super_block *s, time32_t t) { extern struct timezone sys_tz; return t + sys_tz.tz_minuteswest * 60 + hpfs_sb(s)->sb_timeshift; } -static inline time32_t gmt_to_local(struct super_block *s, time_t t) +static inline time32_t gmt_to_local(struct super_block *s, time64_t t) { extern struct timezone sys_tz; - return t - sys_tz.tz_minuteswest * 60 - hpfs_sb(s)->sb_timeshift; + t = t - sys_tz.tz_minuteswest * 60 - hpfs_sb(s)->sb_timeshift; + + return clamp_t(time64_t, t, 0, U32_MAX); +} + +static inline time32_t local_get_seconds(struct super_block *s) +{ + return gmt_to_local(s, ktime_get_real_seconds()); } /* diff --git a/fs/hpfs/namei.c b/fs/hpfs/namei.c index a3615e4c730d..082b7c76dd0c 100644 --- a/fs/hpfs/namei.c +++ b/fs/hpfs/namei.c @@ -11,7 +11,7 @@ static void hpfs_update_directory_times(struct inode *dir) { - time_t t = get_seconds(); + time64_t t = local_to_gmt(dir->i_sb, local_get_seconds(dir->i_sb)); if (t == dir->i_mtime.tv_sec && t == dir->i_ctime.tv_sec) return; @@ -50,7 +50,7 @@ static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) /*dee.archive = 0;*/ dee.hidden = name[0] == '.'; dee.fnode = cpu_to_le32(fno); - dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds())); + dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb)); result = new_inode(dir->i_sb); if (!result) goto bail2; @@ -91,7 +91,7 @@ static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) dnode->root_dnode = 1; dnode->up = cpu_to_le32(fno); de = hpfs_add_de(dir->i_sb, dnode, "\001\001", 2, 0); - de->creation_date = de->write_date = de->read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds())); + de->creation_date = de->write_date = de->read_date = cpu_to_le32(local_get_seconds(dir->i_sb)); if (!(mode & 0222)) de->read_only = 1; de->first = de->directory = 1; /*de->hidden = de->system = 0;*/ @@ -151,7 +151,7 @@ static int hpfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, b dee.archive = 1; dee.hidden = name[0] == '.'; dee.fnode = cpu_to_le32(fno); - dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds())); + dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb)); result = new_inode(dir->i_sb); if (!result) @@ -238,7 +238,7 @@ static int hpfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, de dee.archive = 1; dee.hidden = name[0] == '.'; dee.fnode = cpu_to_le32(fno); - dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds())); + dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb)); result = new_inode(dir->i_sb); if (!result) @@ -314,7 +314,7 @@ static int hpfs_symlink(struct inode *dir, struct dentry *dentry, const char *sy dee.archive = 1; dee.hidden = name[0] == '.'; dee.fnode = cpu_to_le32(fno); - dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds())); + dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(local_get_seconds(dir->i_sb)); result = new_inode(dir->i_sb); if (!result)