Skip to content

Commit d9f4d94

Browse files
fsorensontorvalds
authored andcommitted
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>
1 parent eceb890 commit d9f4d94

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎fs/fat/misc.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ static long days_in_year[] = {
185185
0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0, 0, 0,
186186
};
187187

188+
static 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+
188195
/* Convert a FAT time/date pair to a UNIX date (seconds since 1 1 70). */
189196
void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts,
190197
__le16 __time, __le16 __date, u8 time_cs)
@@ -210,10 +217,7 @@ void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts,
210217
+ days_in_year[month] + day
211218
+ DAYS_DELTA) * SECS_PER_DAY;
212219

213-
if (!sbi->options.tz_set)
214-
second += sys_tz.tz_minuteswest * SECS_PER_MIN;
215-
else
216-
second -= sbi->options.time_offset * SECS_PER_MIN;
220+
second += fat_tz_offset(sbi);
217221

218222
if (time_cs) {
219223
ts->tv_sec = second + (time_cs / 100);
@@ -229,9 +233,7 @@ void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec64 *ts,
229233
__le16 *time, __le16 *date, u8 *time_cs)
230234
{
231235
struct tm tm;
232-
time64_to_tm(ts->tv_sec,
233-
(sbi->options.tz_set ? sbi->options.time_offset :
234-
-sys_tz.tz_minuteswest) * SECS_PER_MIN, &tm);
236+
time64_to_tm(ts->tv_sec, -fat_tz_offset(sbi), &tm);
235237

236238
/* FAT can only support year between 1980 to 2107 */
237239
if (tm.tm_year < 1980 - 1900) {

0 commit comments

Comments
 (0)