From patchwork Sat Sep 22 20:19:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Sorenson X-Patchwork-Id: 10611559 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 861B115A6 for ; Sat, 22 Sep 2018 20:20:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 757502AEAA for ; Sat, 22 Sep 2018 20:20:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 452032AE9F; Sat, 22 Sep 2018 20:20:19 +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,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 D8F2A2AE85 for ; Sat, 22 Sep 2018 20:20:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727588AbeIWCOu (ORCPT ); Sat, 22 Sep 2018 22:14:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59490 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726226AbeIWCOu (ORCPT ); Sat, 22 Sep 2018 22:14:50 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E3B5C5F734; Sat, 22 Sep 2018 20:20:01 +0000 (UTC) Received: from hut.sorensonfamily.com.com (ovpn-116-190.phx2.redhat.com [10.3.116.190]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7809B87DE; Sat, 22 Sep 2018 20:20:01 +0000 (UTC) From: Frank Sorenson To: linux-fsdevel@vger.kernel.org Cc: hirofumi@mail.parknet.co.jp Subject: [PATCH 2/4] fat: create function to calculate timezone offset Date: Sat, 22 Sep 2018 15:19:57 -0500 Message-Id: <20180922201959.10477-3-sorenson@redhat.com> In-Reply-To: <20180922201959.10477-1-sorenson@redhat.com> References: <20180922201959.10477-1-sorenson@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 22 Sep 2018 20:20:02 +0000 (UTC) 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 Add a function to calculate the timezone offset in minutes. Signed-off-by: Frank Sorenson --- fs/fat/fat.h | 12 ++++++++++++ fs/fat/misc.c | 12 ++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/fs/fat/fat.h b/fs/fat/fat.h index 9d7d2d5da28b..c40f7e69f078 100644 --- a/fs/fat/fat.h +++ b/fs/fat/fat.h @@ -412,6 +412,18 @@ void fat_msg(struct super_block *sb, const char *level, const char *fmt, ...); } while (0) extern int fat_clusters_flush(struct super_block *sb); extern int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster); + +#define SECS_PER_MIN 60 +#define SECS_PER_HOUR (60 * 60) +#define SECS_PER_DAY (SECS_PER_HOUR * 24) + +static inline int fat_tz_offset(struct msdos_sb_info *sbi) +{ + return (sbi->options.tz_set ? + - sbi->options.time_offset : + sys_tz.tz_minuteswest) * SECS_PER_MIN; +} + 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, diff --git a/fs/fat/misc.c b/fs/fat/misc.c index 573836dcaefc..58580c7e558e 100644 --- a/fs/fat/misc.c +++ b/fs/fat/misc.c @@ -170,9 +170,6 @@ int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster) * time: 5 - 10: min (0 - 59) * time: 11 - 15: hour (0 - 23) */ -#define SECS_PER_MIN 60 -#define SECS_PER_HOUR (60 * 60) -#define SECS_PER_DAY (SECS_PER_HOUR * 24) /* days between 1.1.70 and 1.1.80 (2 leap days) */ #define DAYS_DELTA (365 * 10 + 2) /* 120 (2100 - 1980) isn't leap year */ @@ -210,10 +207,7 @@ void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts, + days_in_year[month] + day + DAYS_DELTA) * SECS_PER_DAY; - if (!sbi->options.tz_set) - second += sys_tz.tz_minuteswest * SECS_PER_MIN; - else - second -= sbi->options.time_offset * SECS_PER_MIN; + second += fat_tz_offset(sbi); if (time_cs) { ts->tv_sec = second + (time_cs / 100); @@ -229,9 +223,7 @@ void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec64 *ts, __le16 *time, __le16 *date, u8 *time_cs) { struct tm tm; - time64_to_tm(ts->tv_sec, - (sbi->options.tz_set ? sbi->options.time_offset : - -sys_tz.tz_minuteswest) * SECS_PER_MIN, &tm); + time64_to_tm(ts->tv_sec, -fat_tz_offset(sbi), &tm); /* FAT can only support year between 1980 to 2107 */ if (tm.tm_year < 1980 - 1900) {