aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Sorenson <sorenson@redhat.com>2018-10-30 18:06:50 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-10-31 11:54:14 -0400
commitd9f4d94261d52a5fe31ad2ec00a06824a150af6f (patch)
tree33c4fee1b9f21b87cf5b14976d58e9da666c258c
parenteceb8902be2910be296f00ad6662941d79c09f8e (diff)
fat: create a function to calculate the timezone offest
Patch series "fat: timestamp updates", v5. fat/msdos timestamps are stored on-disk with several different granularities, some of them lower resolution than timespec64_trunc() can provide. In addition, they are only truncated as they are written to disk, so the timestamps in-memory for new or modified files/directories may be different from the same timestamps after a remount, as the now-truncated times are re-read from the on-disk format. These patches allow finer granularity for the timestamps where possible and add fat-specific ->update_time inode operation and fat_truncate_time functions to truncate each timestamp correctly, giving consistent times across remounts. This patch (of 4): Move the calculation of the number of seconds in the timezone offset to a common function. Link: http://lkml.kernel.org/r/3671ff8cff5eeedbb85ebda5e4de0728920db4f6.1538363961.git.sorenson@redhat.com Signed-off-by: Frank Sorenson <sorenson@redhat.com> Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--fs/fat/misc.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/fs/fat/misc.c b/fs/fat/misc.c
index 573836dcaefc..2eca073fe785 100644
--- a/fs/fat/misc.c
+++ b/fs/fat/misc.c
@@ -185,6 +185,13 @@ static long days_in_year[] = {
185 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0, 0, 0, 185 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0, 0, 0,
186}; 186};
187 187
188static inline int fat_tz_offset(struct msdos_sb_info *sbi)
189{
190 return (sbi->options.tz_set ?
191 -sbi->options.time_offset :
192 sys_tz.tz_minuteswest) * SECS_PER_MIN;
193}
194
188/* Convert a FAT time/date pair to a UNIX date (seconds since 1 1 70). */ 195/* Convert a FAT time/date pair to a UNIX date (seconds since 1 1 70). */
189void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts, 196void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts,
190 __le16 __time, __le16 __date, u8 time_cs) 197 __le16 __time, __le16 __date, u8 time_cs)
@@ -210,10 +217,7 @@ void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts,
210 + days_in_year[month] + day 217 + days_in_year[month] + day
211 + DAYS_DELTA) * SECS_PER_DAY; 218 + DAYS_DELTA) * SECS_PER_DAY;
212 219
213 if (!sbi->options.tz_set) 220 second += fat_tz_offset(sbi);
214 second += sys_tz.tz_minuteswest * SECS_PER_MIN;
215 else
216 second -= sbi->options.time_offset * SECS_PER_MIN;
217 221
218 if (time_cs) { 222 if (time_cs) {
219 ts->tv_sec = second + (time_cs / 100); 223 ts->tv_sec = second + (time_cs / 100);
@@ -229,9 +233,7 @@ void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec64 *ts,
229 __le16 *time, __le16 *date, u8 *time_cs) 233 __le16 *time, __le16 *date, u8 *time_cs)
230{ 234{
231 struct tm tm; 235 struct tm tm;
232 time64_to_tm(ts->tv_sec, 236 time64_to_tm(ts->tv_sec, -fat_tz_offset(sbi), &tm);
233 (sbi->options.tz_set ? sbi->options.time_offset :
234 -sys_tz.tz_minuteswest) * SECS_PER_MIN, &tm);
235 237
236 /* FAT can only support year between 1980 to 2107 */ 238 /* FAT can only support year between 1980 to 2107 */
237 if (tm.tm_year < 1980 - 1900) { 239 if (tm.tm_year < 1980 - 1900) {