From patchwork Wed Apr 4 02:37:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Sorenson X-Patchwork-Id: 10321971 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7BDD660318 for ; Wed, 4 Apr 2018 02:37:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A47628DE6 for ; Wed, 4 Apr 2018 02:37:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EDD128DF1; Wed, 4 Apr 2018 02:37: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=-6.9 required=2.0 tests=BAYES_00,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 DB17028DE6 for ; Wed, 4 Apr 2018 02:37:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753089AbeDDChN (ORCPT ); Tue, 3 Apr 2018 22:37:13 -0400 Received: from mail-io0-f194.google.com ([209.85.223.194]:45421 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752750AbeDDChN (ORCPT ); Tue, 3 Apr 2018 22:37:13 -0400 Received: by mail-io0-f194.google.com with SMTP id 141so24424790iou.12 for ; Tue, 03 Apr 2018 19:37:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=AE8VOy1R9GQRH92jj4hizOWc0+UTMTwva0NkJZ/iSak=; b=OqW+EosrlxFXq9r0RD0S0FbNdhI9G8TBNQzX1Vt2sBZGCemI9T9F2n0aQ3DbCZQ4DT +1Y702g2Eohr/a7NStdzdZl5SMds8Rwt0FLGUPA7lRuW9F+WxcxfpblZ/gVT7JQZw5N7 iLCCOqRIS/0Bxqbz3DTWLjCsXNtiz+hBANk9ZJNoMllwhXzlC5eY2VbvDLSA7IuGkQ+1 8yvybPis8sb2b0ak2a66HSdkFbeWkAojIUf2Aa/WRd4vlaLPOkxBwywQaXG5VetOQnw4 NYKNHBYav1lYCMbvt08VBU5bsm89BWX7kO6OO18gk55JSfTLfj/E7btqfvqpUBkiOGh0 ICiw== X-Gm-Message-State: ALQs6tAz0l6VBKPkxXVo1a000SoaVKR/k9TVQvnzbCTqXQ3dYJfULtnK es0zWHgtPbWJ+JZDQWuTXUeobrcPTW8= X-Google-Smtp-Source: AIpwx48VV7UF2uRa00sdFGCIm8ym2ZKJCiKpF5gg+xc/c+WtLdGtIwHwKSrgFlp1o8n7zHGTBIYdoQ== X-Received: by 10.107.129.148 with SMTP id l20mr14962062ioi.140.1522809432414; Tue, 03 Apr 2018 19:37:12 -0700 (PDT) Received: from hut.sorensonfamily.com (198-0-247-150-static.hfc.comcastbusiness.net. [198.0.247.150]) by smtp.gmail.com with ESMTPSA id g35sm2468516ioj.20.2018.04.03.19.37.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Apr 2018 19:37:11 -0700 (PDT) From: Frank Sorenson Subject: [PATCH V2 1/2] fat: implement fat_update_time for inode timestamps To: OGAWA Hirofumi , linux-fsdevel@vger.kernel.org Message-ID: <8cad6edb-95bd-1c02-1d7d-a23850b329c3@redhat.com> Date: Tue, 3 Apr 2018 21:37:10 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 Content-Language: en-US Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Author: Frank Sorenson Date: 2018-04-03 20:09:35 -0500 fat: implement fat_update_time for inode timestamps Add a fat_update_time function to update and truncate the inode's timestamps as needed for msdos/vfat filesystems. If called with the timespec pointer set to NULL, current time is used. Signed-off-by: Frank Sorenson diff --git a/fs/fat/fat.h b/fs/fat/fat.h index 8fc1093da47d..54d1b08b8ecf 100644 --- a/fs/fat/fat.h +++ b/fs/fat/fat.h @@ -410,6 +410,7 @@ extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts, __le16 __time, __le16 __date, u8 time_cs); extern void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec *ts, __le16 *time, __le16 *date, u8 *time_cs); +extern int fat_update_time(struct inode *inode, struct timespec *now, int flags); extern int fat_sync_bhs(struct buffer_head **bhs, int nr_bhs); int fat_cache_init(void); diff --git a/fs/fat/misc.c b/fs/fat/misc.c index f9bdc1e01c98..8df9409bcf66 100644 --- a/fs/fat/misc.c +++ b/fs/fat/misc.c @@ -262,6 +262,54 @@ void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec *ts, } EXPORT_SYMBOL_GPL(fat_time_unix2fat); +int fat_update_time(struct inode *inode, struct timespec *now, int flags) +{ + int iflags = I_DIRTY_TIME; + struct timespec ts; + + if (inode->i_ino == MSDOS_ROOT_INO) { + ts = (struct timespec){0, 0}; + if (flags & S_ATIME) + inode->i_atime = ts; + if (flags & S_MTIME) + inode->i_mtime = ts; + if (flags & S_CTIME) + inode->i_ctime = ts; + } else { + struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb); + __le16 time; + __le16 date; + u8 ctime_cs; + + if (now == NULL) { + now = &ts; + ts = current_time(inode); + } + + if (flags & S_ATIME) { + fat_time_unix2fat(sbi, now, &time, &date, NULL); + fat_time_fat2unix(sbi, &inode->i_atime, 0, date, 0); + } + if (flags & S_MTIME) { + fat_time_unix2fat(sbi, now, &time, &date, NULL); + fat_time_fat2unix(sbi, &inode->i_mtime, time, date, 0); + } + if (flags & S_CTIME) { + fat_time_unix2fat(sbi, now, &time, &date, + sbi->options.isvfat ? &ctime_cs : NULL); + fat_time_fat2unix(sbi, &inode->i_ctime, time, date, + sbi->options.isvfat ? ctime_cs : 0); + } + } + if ((flags & (S_ATIME | S_CTIME | S_MTIME)) && + !(inode->i_sb->s_flags & SB_LAZYTIME)) + iflags |= I_DIRTY_SYNC; + + __mark_inode_dirty(inode, iflags); + return 0; +} +EXPORT_SYMBOL_GPL(fat_update_time); + int fat_sync_bhs(struct buffer_head **bhs, int nr_bhs) { int i, err = 0; diff --git a/fs/fat/file.c b/fs/fat/file.c index 4724cc9ad650..63ec4a5bde77 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c @@ -519,4 +519,5 @@ EXPORT_SYMBOL_GPL(fat_setattr); const struct inode_operations fat_file_inode_operations = { .setattr = fat_setattr, .getattr = fat_getattr, + .update_time = fat_update_time, }; diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c index 582ca731a6c9..f157df4c1e51 100644 --- a/fs/fat/namei_msdos.c +++ b/fs/fat/namei_msdos.c @@ -641,6 +641,7 @@ static const struct inode_operations msdos_dir_inode_operations = { .rename = msdos_rename, .setattr = fat_setattr, .getattr = fat_getattr, + .update_time = fat_update_time, }; static void setup(struct super_block *sb) diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c index 2649759c478a..3d24b44cb93d 100644 --- a/fs/fat/namei_vfat.c +++ b/fs/fat/namei_vfat.c @@ -1043,6 +1043,7 @@ static const struct inode_operations vfat_dir_inode_operations = { .rename = vfat_rename, .setattr = fat_setattr, .getattr = fat_getattr, + .update_time = fat_update_time, }; static void setup(struct super_block *sb)