Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6296419ybl; Wed, 15 Jan 2020 02:12:19 -0800 (PST) X-Google-Smtp-Source: APXvYqw1xls1x8yJmlHqu6ApGHDWESly2Ds5aHs8xoZTBx88s1alzKJyLefpNbI4+D9H8v6rdCOX X-Received: by 2002:aca:c3c4:: with SMTP id t187mr20945383oif.89.1579083139551; Wed, 15 Jan 2020 02:12:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579083139; cv=none; d=google.com; s=arc-20160816; b=ZmM0/qFkhQLr1vKRO8P8wJNEXgIq7LuH2RsZ2Zu0m+lMDCzKRP7r1upJZuvvH9N5OJ OQw2VVNaj0/Lptqe6JKGNEn858ic3SWGhm5/vaQr+Tv8XN1WGoQk/tjvAsR/nE65KE3I aSpkyVJ/tkJfL+btnaBE1vWF0OrwtN6A9B/XD9D9I5JFWO3mLaI5yBPxFYwy/myEOpdg dUK9/ge/OHd0aJyaBzzcd5qTAJfs+M1TY6QuEdHoHeWYyha3dUeJY6SaGshgFNHrPWX4 WGBHnU+R9L2AkotJ8/tOhUyZyWR3u4MXFf155cCzIQVOPOuf2IFyi/Z1nHdXon3pKzZx 8mDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=oxuKCOoG0OVIQevMn1ecHFwvySNE87yfV3UECQF4vO4=; b=SYyrzmFbY9+TSPwnooF/g4mkVYzgCrFzIOZhjTUgE3fjf81Xui9cgASo+4ijoyP2b7 ExUs5D7rBWceQBmI1gxqc6p504A0NFkdWlHRJl+0KqlBXTHjBCgP1bpIGH3vsW5hfSxs yDxHlaPW5YjDk8BINqGhAkoD7PbQg0rgOPWLc875ED77axX+o83Y6WzEWWsQWhWCpvfM aVYBGmDvY7/Qs3CQovgbL1DkNi9LxGHb0s4agNhj3okcUNSh6BOwkc0IdagwUKHfTgUg pnj/+PvqSlxCFtr4lIpGDdy5/WNZMZtoBIxWrZvGZKvXfXPOHNE/T1DelbVc0yi0YmTR QQUw== 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 65si9636508oif.14.2020.01.15.02.12.07; Wed, 15 Jan 2020 02:12:19 -0800 (PST) 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 S1729673AbgAOKLF (ORCPT + 99 others); Wed, 15 Jan 2020 05:11:05 -0500 Received: from mout.kundenserver.de ([212.227.126.135]:34749 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729539AbgAOKLF (ORCPT ); Wed, 15 Jan 2020 05:11:05 -0500 Received: from mail-qt1-f179.google.com ([209.85.160.179]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPSA (Nemesis) id 1MwwqB-1jbPjR3RZD-00yRcW; Wed, 15 Jan 2020 11:11:03 +0100 Received: by mail-qt1-f179.google.com with SMTP id k40so15241447qtk.8; Wed, 15 Jan 2020 02:11:02 -0800 (PST) X-Gm-Message-State: APjAAAUKK4AT3ATrrzP4UHpzm32fLBONb3msFR40Lj31wc9eXXkpkFcs vcykaKGiZeTyYEZueNSQb/nL8EgXlO0uX2sJKSI= X-Received: by 2002:ac8:47d3:: with SMTP id d19mr2691571qtr.142.1579083061617; Wed, 15 Jan 2020 02:11:01 -0800 (PST) MIME-Version: 1.0 References: <20200115082447.19520-1-namjae.jeon@samsung.com> <20200115082447.19520-10-namjae.jeon@samsung.com> In-Reply-To: <20200115082447.19520-10-namjae.jeon@samsung.com> From: Arnd Bergmann Date: Wed, 15 Jan 2020 11:10:45 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v10 09/14] exfat: add misc operations To: Namjae Jeon Cc: "linux-kernel@vger.kernel.org" , Linux FS-devel Mailing List , gregkh , Valdis Kletnieks , Christoph Hellwig , sj1557.seo@samsung.com, linkinjeon@gmail.com, =?UTF-8?Q?Pali_Roh=C3=A1r?= Content-Type: text/plain; charset="UTF-8" X-Provags-ID: V03:K1:zMj7fHpmmC4v6OX5t/OWB8YWtAbKWIMqgQVeVDS3SAVH7nGq6qP HqK3uJ1MUa3EYP+R7SqXVkp2eTc2FyJEhjIQNDh8Np27M2dU6iH2krt54q0xvBAkh0394mK +XnunK5FjGveB293UoAC7QXAgQ7LyLLTJk1llYRXmpoLr/V0ajlTEemgqb1c1onO3FC1eR7 wa6TugpjSSQgAi16x0ALw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:fKc0iOiZ6uA=:/4byouMcKggKD8zS7GPPO0 6+jnUfVu8jPu8Ic94m38pxEZl2byhP88Tg0Ek7NQVEd51vSZeiPmFhSR6mz75ExDGVJQy6HbC eEmsnbA7FOWCh67K2u/sBIOPUGFNUjXdA5PjL+5v/2yPiFcClUuWTPojP+sHZCL8jRNI7ErKS lz4P1J40D/8b08UNEG1VviLwK0w79iW4GICWrRuLllyeoN2SLej9nPAhSS0lmAZQQaYkLpvlu 9FsOsm4EecnnDXA57YuvkFEEwjOCJ3Vj3I1D0s09GKNL9YTN7+dQS1ZO2Ms0i3Ufs3v85u0YD C2xczmNV+JW/fEiH16z6Z+lRljLkO8o2VYaii0P2Khw6zN/OE/LbrQzDwRm8BmlPP73oIPQGw a1eGLDzYzdbdOrQG2+6yT5ITeJTdkD12X8d0k4htNWr7yKQwJpxStlfgArZ3DrjkXoj+DgB8P QNAT0HF70JQBsrW+wOmYOLyrkdqgthSzj6VG0N8K9LTgjTI8eIFy8kbcWzI3AR04e5pIZaSDj JCtFHe1YhlaZjzwpXscSgZ/DjmnRBK2FdkgfsLfdf5iWlRkNMOIpkL5n/LxDMkupDkXDpBbl9 J9EOQMD3ClTDHMgmIYNJonsYTJdXdMUXcXXpm/LVpDaug9QIqZO8hi6/r7RNbqxP8wJD3Bjh0 a0hmQPZUmaSzh57waRvyTjU1x+FLtCfbo8oa6wgQAGms6M/zG1ATzxAOBDGJZSddTPf8Wf3Qv 75rrQU9xnfLayKUB3jKfFfgv7nbGTm+fzD+f0FcRAWRPZWUjwdDBMYfLbBoEt/ji41RRPkFay gg2v7n+khbAgbn2QeFCiIaWvkcUI6IFBQCa84bXGOwZhTzRUCTflrpq3OF34n6w2fnOXwekel E0aSt5xb3qD5EHGfKmKA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 15, 2020 at 9:28 AM Namjae Jeon wrote: > +#define SECS_PER_MIN (60) > +#define TIMEZONE_SEC(x) ((x) * 15 * SECS_PER_MIN) > + > +static void exfat_adjust_tz(struct timespec64 *ts, u8 tz_off) > +{ > + if (tz_off <= 0x3F) > + ts->tv_sec -= TIMEZONE_SEC(tz_off); > + else /* 0x40 <= (tz_off & 0x7F) <=0x7F */ > + ts->tv_sec += TIMEZONE_SEC(0x80 - tz_off); > +} > + > +static inline int exfat_tz_offset(struct exfat_sb_info *sbi) > +{ > + if (sbi->options.time_offset) > + return sbi->options.time_offset; > + return sys_tz.tz_minuteswest; > +} > + > +/* Convert a EXFAT time/date pair to a UNIX date (seconds since 1 1 70). */ > +void exfat_get_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts, > + __le16 time, __le16 date, u8 tz) > +{ > + u16 t = le16_to_cpu(time); > + u16 d = le16_to_cpu(date); > + > + ts->tv_sec = mktime64(1980 + (d >> 9), d >> 5 & 0x000F, d & 0x001F, > + t >> 11, (t >> 5) & 0x003F, (t & 0x001F) << 1); > + ts->tv_nsec = 0; This part looks good to me now. > + if (tz & EXFAT_TZ_VALID) > + /* Treat as UTC time, but need to adjust timezone to UTC0 */ > + exfat_adjust_tz(ts, tz & ~EXFAT_TZ_VALID); > + else > + /* Treat as local time */ > + ts->tv_sec -= exfat_tz_offset(sbi) * SECS_PER_MIN; > +} Whereas this seems rather complex, when it deals with three different cases: - timezone stored in inode - timezone offset passed as mount option - local time from sys_tz.tz_minuteswest Does the exfat specification require to use some notion of 'local time' here as the fallback? The problem with sys_tz.tz_minuteswest is that it is not too well-defined, so if there is a choice, falling back to UTC would be nicer. > +/* Convert linear UNIX date to a EXFAT time/date pair. */ > +void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts, > + __le16 *time, __le16 *date, u8 *tz) > +{ > + struct tm tm; > + u16 t, d; > + > + /* clamp to the range valid in the exfat on-disk representation. */ > + time64_to_tm(clamp_t(time64_t, ts->tv_sec, EXFAT_MIN_TIMESTAMP_SECS, > + EXFAT_MAX_TIMESTAMP_SECS), -exfat_tz_offset(sbi) * SECS_PER_MIN, > + &tm); I think you can drop the clamping here, as thes_time_min/s_time_max fields should take care of that. For writing out timestamps, it may be best to always encode them as UTC and set set timezone-valid bit for that. That way, the min/max values are known at compile time regardless of which time zone the machine thinks it is in. Arnd