Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1034103pxb; Fri, 15 Apr 2022 19:04:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyi3QCCI4y/5UUHlKHhTCjP/Gv3DurFEtSBvQlWo0iCR9qeiPRrol5EG8YWxXhXZDwtsUFP X-Received: by 2002:a63:171f:0:b0:3a3:2115:fc65 with SMTP id x31-20020a63171f000000b003a32115fc65mr1378950pgl.80.1650074673198; Fri, 15 Apr 2022 19:04:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650074673; cv=none; d=google.com; s=arc-20160816; b=rIGMWNjC8o4QXMSn48X/2YdKwAn6cZYsedXaRJaxZPGRDrAvKkpyqd8lBGUlvrBByS dYlXUtRz/7Vb70epxtNf9LKQZmsknxe18wdH2III/JXGdutiXCUen4VVSl8I4p3u9cjx 3dM8/Gq1EYR5diev1srXWfgvN70wnmWwidC+WJ/gsMS7+Agrc5lu2JtmelXWOfCw+R5S vXz2Cz+OQCQgMLMg7hfmlnyAnCiKsizd1InQffIQh5/yMU7p5PwExthgRc7SqBWMB/Hr 8W7WR5c4zEhiRxzbBwP1ZA1aG5m4e8hRuQ+nR9pjxeoxZJs9MMS7yt13UxJzc55dQO+V Yhdw== 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 :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :from; bh=QPQ06NHtSrmXDs3vLqVlCBCePMBcrlUMuVNC3bgHkWw=; b=PtQPxLrQSDz+021elY02G6kfQON/IrfT7hhvXQECVTchgtUmoXut0yQyb3Z3xNS/4N dl2wIhxEqk+AUS+mgYOHDmnvJFcn3Tac5ZYNEKh7uh9SlHT5oniKJGKOvowTtYcUtv6W 8/34e0RqQMZW3XHYTGEXC/+kovtPZ6YuW0hLD4arU/R6F8cT/kjflOk6tXph82KaKdq2 IvlVWVF7iVG4mCsuWzH1RLRfjF2b7Ihub570rTaAJ+0bc5yth8KNTe1lwXYyTiqI48xH 4yQN+Mn4X/vgneMga3cxmd/0FbRpvLAmwU2SmLwhiLnMNz82tcm1pkad/tM33LIrk6kQ 5SNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synology.com header.s=123 header.b=pv9cWL7f; 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 z13-20020a63e54d000000b003a247aef080si2945052pgj.586.2022.04.15.19.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:04:33 -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=pv9cWL7f; 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 034F310E074; Fri, 15 Apr 2022 18:23:34 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351839AbiDOJsA (ORCPT + 99 others); Fri, 15 Apr 2022 05:48:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238815AbiDOJru (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 2BE1E72449 for ; Fri, 15 Apr 2022 02:45:22 -0700 (PDT) From: Chung-Chiang Cheng DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1650015920; bh=N6hbkxCa1QaN5V9OqMbRhd3D0RLavWNtgUhgGcwXPKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pv9cWL7foPsVZvG6DlKHLAXyQP1znP3s8Vj9Pe6HAT9MrEJTKL5WmgsN2oZMkD4H6 BZHBrQjwL51iCDkFn6YiwaMxWuEj4HmWIqqcpEdxtq4uwadJDQxFJAzxhnUtCF3Nya h1dsitinAazkmCLyY9Vzf+UvQbX0sKMcLyPBcJeo= To: hirofumi@mail.parknet.co.jp Cc: linux-kernel@vger.kernel.org, kernel@cccheng.net, shepjeng@gmail.com, Chung-Chiang Cheng Subject: [PATCH v3 2/3] fat: make ctime and mtime identical explicitly Date: Fri, 15 Apr 2022 17:45:17 +0800 Message-Id: <20220415094518.380543-2-cccheng@synology.com> In-Reply-To: <20220415094518.380543-1-cccheng@synology.com> References: <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 FAT supports creation time but not change time, and there was no corresponding timestamp for creation time in previous VFS. The original implementation took the compromise of saving the in-memory change time into the on-disk creation time field, but this would lead to compatibility issues with non-linux systems. To address this issue, this patch changes the behavior of ctime. ctime will no longer be loaded and stored from the creation time on disk. Instead of that, it'll be consistent with the in-memory mtime and share the same on-disk field. Signed-off-by: Chung-Chiang Cheng --- fs/fat/dir.c | 2 +- fs/fat/file.c | 4 ++++ fs/fat/inode.c | 11 ++++------- fs/fat/misc.c | 11 ++++++++--- fs/fat/namei_msdos.c | 6 +++--- fs/fat/namei_vfat.c | 6 +++--- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/fs/fat/dir.c b/fs/fat/dir.c index 249825017da7..0ae0dfe278fb 100644 --- a/fs/fat/dir.c +++ b/fs/fat/dir.c @@ -1068,7 +1068,7 @@ int fat_remove_entries(struct inode *dir, struct fat_slot_info *sinfo) } } - fat_truncate_time(dir, NULL, S_ATIME|S_MTIME); + fat_truncate_time(dir, NULL, S_ATIME|S_CTIME|S_MTIME); if (IS_DIRSYNC(dir)) (void)fat_sync_inode(dir); else diff --git a/fs/fat/file.c b/fs/fat/file.c index a5a309fcc7fa..178c1dde3488 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c @@ -544,6 +544,10 @@ int fat_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, /* * setattr_copy can't truncate these appropriately, so we'll * copy them ourselves + * + * fat_truncate_time() keeps ctime and mtime the same. if both + * ctime and mtime are need to update here, mtime will overwrite + * ctime */ if (attr->ia_valid & ATTR_ATIME) fat_truncate_time(inode, &attr->ia_atime, S_ATIME); diff --git a/fs/fat/inode.c b/fs/fat/inode.c index bf6051bdf1d1..f2ac55cd4ea4 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -567,12 +567,11 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) & ~((loff_t)sbi->cluster_size - 1)) >> 9; fat_time_fat2unix(sbi, &inode->i_mtime, de->time, de->date, 0); - if (sbi->options.isvfat) { - fat_time_fat2unix(sbi, &inode->i_ctime, de->ctime, - de->cdate, de->ctime_cs); + inode->i_ctime = inode->i_mtime; + if (sbi->options.isvfat) fat_time_fat2unix(sbi, &inode->i_atime, 0, de->adate, 0); - } else - fat_truncate_time(inode, &inode->i_mtime, S_ATIME|S_CTIME); + else + fat_truncate_atime(sbi, &inode->i_mtime, &inode->i_atime); return 0; } @@ -888,8 +887,6 @@ static int __fat_write_inode(struct inode *inode, int wait) &raw_entry->date, NULL); if (sbi->options.isvfat) { __le16 atime; - fat_time_unix2fat(sbi, &inode->i_ctime, &raw_entry->ctime, - &raw_entry->cdate, &raw_entry->ctime_cs); fat_time_unix2fat(sbi, &inode->i_atime, &atime, &raw_entry->adate, NULL); } diff --git a/fs/fat/misc.c b/fs/fat/misc.c index c87df64f8b2b..71e6dadf12a2 100644 --- a/fs/fat/misc.c +++ b/fs/fat/misc.c @@ -341,10 +341,15 @@ int fat_truncate_time(struct inode *inode, struct timespec64 *now, int flags) 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) + + /* + * ctime and mtime share the same on-disk field, and should be + * identical in memory. + */ + if (flags & (S_CTIME|S_MTIME)) { fat_truncate_mtime(sbi, now, &inode->i_mtime); + inode->i_ctime = inode->i_mtime; + } return 0; } diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c index efba301d68ae..b2760a716707 100644 --- a/fs/fat/namei_msdos.c +++ b/fs/fat/namei_msdos.c @@ -328,7 +328,7 @@ static int msdos_rmdir(struct inode *dir, struct dentry *dentry) drop_nlink(dir); clear_nlink(inode); - fat_truncate_time(inode, NULL, S_CTIME); + fat_truncate_time(inode, NULL, S_CTIME|S_MTIME); fat_detach(inode); out: mutex_unlock(&MSDOS_SB(sb)->s_lock); @@ -415,7 +415,7 @@ static int msdos_unlink(struct inode *dir, struct dentry *dentry) if (err) goto out; clear_nlink(inode); - fat_truncate_time(inode, NULL, S_CTIME); + fat_truncate_time(inode, NULL, S_CTIME|S_MTIME); fat_detach(inode); out: mutex_unlock(&MSDOS_SB(sb)->s_lock); @@ -550,7 +550,7 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name, drop_nlink(new_inode); if (is_dir) drop_nlink(new_inode); - fat_truncate_time(new_inode, &ts, S_CTIME); + fat_truncate_time(new_inode, &ts, S_CTIME|S_MTIME); } out: brelse(sinfo.bh); diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c index 5369d82e0bfb..b8deb859b2b5 100644 --- a/fs/fat/namei_vfat.c +++ b/fs/fat/namei_vfat.c @@ -811,7 +811,7 @@ static int vfat_rmdir(struct inode *dir, struct dentry *dentry) drop_nlink(dir); clear_nlink(inode); - fat_truncate_time(inode, NULL, S_ATIME|S_MTIME); + fat_truncate_time(inode, NULL, S_ATIME|S_CTIME|S_MTIME); fat_detach(inode); vfat_d_version_set(dentry, inode_query_iversion(dir)); out: @@ -837,7 +837,7 @@ static int vfat_unlink(struct inode *dir, struct dentry *dentry) if (err) goto out; clear_nlink(inode); - fat_truncate_time(inode, NULL, S_ATIME|S_MTIME); + fat_truncate_time(inode, NULL, S_ATIME|S_CTIME|S_MTIME); fat_detach(inode); vfat_d_version_set(dentry, inode_query_iversion(dir)); out: @@ -981,7 +981,7 @@ static int vfat_rename(struct user_namespace *mnt_userns, struct inode *old_dir, drop_nlink(new_inode); if (is_dir) drop_nlink(new_inode); - fat_truncate_time(new_inode, &ts, S_CTIME); + fat_truncate_time(new_inode, &ts, S_CTIME|S_MTIME); } out: brelse(sinfo.bh); -- 2.34.1