Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp59993lfe; Fri, 15 Apr 2022 19:29:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzPuUsWuOrVn67cIz70R20iZ/xSwuv4haE5hmDJzxMrNjivBz0/IieJYsy228Do13/7xaX X-Received: by 2002:a05:6a00:1a10:b0:4fa:ed5a:6697 with SMTP id g16-20020a056a001a1000b004faed5a6697mr1683520pfv.81.1650076151909; Fri, 15 Apr 2022 19:29:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650076151; cv=none; d=google.com; s=arc-20160816; b=PAVJzKfBuYyAAJ09JIqN/u+4q83rFBQB2PlL4Ib9G3DO4EHbaTJ8q+gnGIaWfD5hGf zb9mOqyDwOcGlc8fm8HRGSIto6mO4FpoKV25SNWLZNkfQdB5/d5H4QZOVmA1BhyWI2MN O6QILV+z/6qWlCKqKiAmN16pYlOS4RaErVNqvxOLIslVoM3WFe1pIRGl5Ofe6Z8xr1Y4 pWBIrxCL0ppBed1K0d0WKjS/RrZjHCGYzFwhdgXa1oZ9nMKjZ7BsdZPbp+MSjYQYraK7 CcieD+Hj6Lg0Y1Kyd/upNFajUOPUsomJkZnd2NgzI6rjFie4Yexm6NnNU32UZjS5XzUX +1JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:dkim-signature:from; bh=cgVDtJki+8pbsom6DDKlteyVdmYHI7BpnhjXFO1WCOg=; b=lfEXGEeeNPG9MQzraiaXn5cqqv7V1CPGshvprVMQOaVuEjLuCpbFwsnIgWJlPjxIcG CDlvcHpnQlvIgzcfXbjMKVXrIiHyFYmRsN32VEIp1gBvIpZ2vcp0Vf1oR3ZHVIBTkhBm eiXnzawllilONpt67hCOjWy5cuoNUCUm5j+R9spSpP2bs7GRtkkKm7B/ZdVrstfWkley mIUB34ucLDYPB7uTM+KqWnEf2SsEd50iXiEKkDBZiO+uqikEIwE3FGdSkBoHGxaRMC1W r3yK2UrFfyluCnVT79fftcU4ojvdjwWAAo7bWFA0U3c8/O+izVeu6JSbk+CE76oRFJ9y Op+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synology.com header.s=123 header.b=RDJcNkfp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synology.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id z12-20020a170902708c00b0015823058edasi2494398plk.464.2022.04.15.19.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:29:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@synology.com header.s=123 header.b=RDJcNkfp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synology.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C30391255AB; Fri, 15 Apr 2022 18:41:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351817AbiDOJr4 (ORCPT + 99 others); Fri, 15 Apr 2022 05:47:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233315AbiDOJru (ORCPT ); Fri, 15 Apr 2022 05:47:50 -0400 Received: from synology.com (mail.synology.com [211.23.38.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23FFE6D979 for ; Fri, 15 Apr 2022 02:45:21 -0700 (PDT) From: Chung-Chiang Cheng DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1650015920; bh=n41AnKVpmXRGqTKFvbN45dUP3voF1ZcCyZmjVvQa2SY=; h=From:To:Cc:Subject:Date; b=RDJcNkfp+/IlHtXzqp6nt3EmXg8kxHDswJWNKysDzjYtwo6rl0R6rqp4au0NNqw29 yWQ2Ppvw/3xWaGkSoSv+gY+FM3RssUKGn2xoZNfDIkQ7bcSUlSBk8qU0pOX0dpJ3+4 o4VUYEQsoUpaVEQ0zuzCBRMv9tWO6uaINCCeHa6Q= To: hirofumi@mail.parknet.co.jp Cc: linux-kernel@vger.kernel.org, kernel@cccheng.net, shepjeng@gmail.com, Chung-Chiang Cheng Subject: [PATCH v3 1/3] fat: split fat_truncate_time() into separate functions Date: Fri, 15 Apr 2022 17:45:16 +0800 Message-Id: <20220415094518.380543-1-cccheng@synology.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Synology-MCP-Status: no X-Synology-Spam-Flag: no X-Synology-Spam-Status: score=0, required 6, WHITELIST_FROM_ADDRESS 0 X-Synology-Virus-Status: no X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Separate fat_truncate_time() to each timestamps for later creation time work. This patch does not introduce any functional changes, it's merely refactoring change. Signed-off-by: Chung-Chiang Cheng --- fs/fat/fat.h | 6 +++++ fs/fat/misc.c | 72 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 26 deletions(-) diff --git a/fs/fat/fat.h b/fs/fat/fat.h index 02d4d4234956..508b4f2a1ffb 100644 --- a/fs/fat/fat.h +++ b/fs/fat/fat.h @@ -446,6 +446,12 @@ extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts, __le16 __time, __le16 __date, u8 time_cs); extern void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec64 *ts, __le16 *time, __le16 *date, u8 *time_cs); +extern void fat_truncate_atime(struct msdos_sb_info *sbi, struct timespec64 *ts, + struct timespec64 *atime); +extern void fat_truncate_crtime(struct msdos_sb_info *sbi, struct timespec64 *ts, + struct timespec64 *crtime); +extern void fat_truncate_mtime(struct msdos_sb_info *sbi, struct timespec64 *ts, + struct timespec64 *mtime); extern int fat_truncate_time(struct inode *inode, struct timespec64 *now, int flags); extern int fat_update_time(struct inode *inode, struct timespec64 *now, diff --git a/fs/fat/misc.c b/fs/fat/misc.c index 91ca3c304211..c87df64f8b2b 100644 --- a/fs/fat/misc.c +++ b/fs/fat/misc.c @@ -282,16 +282,49 @@ static inline struct timespec64 fat_timespec64_trunc_10ms(struct timespec64 ts) return ts; } +/* + * truncate atime to 24 hour granularity (00:00:00 in local timezone) + */ +void fat_truncate_atime(struct msdos_sb_info *sbi, struct timespec64 *ts, + struct timespec64 *atime) +{ + /* to localtime */ + time64_t seconds = ts->tv_sec - fat_tz_offset(sbi); + s32 remainder; + + div_s64_rem(seconds, SECS_PER_DAY, &remainder); + /* to day boundary, and back to unix time */ + seconds = seconds + fat_tz_offset(sbi) - remainder; + + *atime = (struct timespec64){ seconds, 0 }; +} + +/* + * truncate creation time with appropriate granularity: + * msdos - 2 seconds + * vfat - 10 milliseconds + */ +void fat_truncate_crtime(struct msdos_sb_info *sbi, struct timespec64 *ts, + struct timespec64 *crtime) +{ + if (sbi->options.isvfat) + *crtime = fat_timespec64_trunc_10ms(*ts); + else + *crtime = fat_timespec64_trunc_2secs(*ts); +} + +/* + * truncate mtime to 2 second granularity + */ +void fat_truncate_mtime(struct msdos_sb_info *sbi, struct timespec64 *ts, + struct timespec64 *mtime) +{ + *mtime = fat_timespec64_trunc_2secs(*ts); +} + /* * truncate the various times with appropriate granularity: - * root inode: - * all times always 0 - * all other inodes: - * mtime - 2 seconds - * ctime - * msdos - 2 seconds - * vfat - 10 milliseconds - * atime - 24 hours (00:00:00 in local timezone) + * all times in root node are always 0 */ int fat_truncate_time(struct inode *inode, struct timespec64 *now, int flags) { @@ -306,25 +339,12 @@ int fat_truncate_time(struct inode *inode, struct timespec64 *now, int flags) ts = current_time(inode); } - if (flags & S_ATIME) { - /* to localtime */ - time64_t seconds = now->tv_sec - fat_tz_offset(sbi); - s32 remainder; - - div_s64_rem(seconds, SECS_PER_DAY, &remainder); - /* to day boundary, and back to unix time */ - seconds = seconds + fat_tz_offset(sbi) - remainder; - - inode->i_atime = (struct timespec64){ seconds, 0 }; - } - if (flags & S_CTIME) { - if (sbi->options.isvfat) - inode->i_ctime = fat_timespec64_trunc_10ms(*now); - else - inode->i_ctime = fat_timespec64_trunc_2secs(*now); - } + if (flags & S_ATIME) + fat_truncate_atime(sbi, now, &inode->i_atime); + if (flags & S_CTIME) + fat_truncate_crtime(sbi, now, &inode->i_ctime); if (flags & S_MTIME) - inode->i_mtime = fat_timespec64_trunc_2secs(*now); + fat_truncate_mtime(sbi, now, &inode->i_mtime); return 0; } -- 2.34.1