Re: [PATCH v2 09/13] exfat: add misc operations

From: Arnd Bergmann
Date: Wed Jan 08 2020 - 14:53:42 EST


On Tue, Nov 19, 2019 at 8:16 AM Namjae Jeon <namjae.jeon@xxxxxxxxxxx> wrote:

> +/* <linux/time.h> externs sys_tz
> + * extern struct timezone sys_tz;
> + */
> +#define UNIX_SECS_1980 315532800L
> +
> +#if BITS_PER_LONG == 64
> +#define UNIX_SECS_2108 4354819200L
> +#endif
> +
> +/* days between 1970/01/01 and 1980/01/01 (2 leap days) */
> +#define DAYS_DELTA_DECADE (365 * 10 + 2)
> +/* 120 (2100 - 1980) isn't leap year */
> +#define NO_LEAP_YEAR_2100 (120)
> +#define IS_LEAP_YEAR(y) (!((y) & 0x3) && (y) != NO_LEAP_YEAR_2100)
> +
> +#define SECS_PER_MIN (60)
> +#define SECS_PER_HOUR (60 * SECS_PER_MIN)
> +#define SECS_PER_DAY (24 * SECS_PER_HOUR)

None of this code should exist, just use time64_to_tm() and tm_to_time64()

> + if (!sbi->options.tz_utc)
> + ts->tv_sec += sys_tz.tz_minuteswest * SECS_PER_MIN;

I would make tz_utc the default here. Not sure what windows uses or what
the specification says, but sys_tz is a rather unreliable interface, and it's
better to not use that at all if it can be avoided.

It may be useful to have a mount option for the time zone offset instead.

> + ts->tv_nsec = 0;
> +}
> +
> +/* Convert linear UNIX date to a FAT time/date pair. */
> +void exfat_time_unix2fat(struct exfat_sb_info *sbi, struct timespec64 *ts,
> + struct exfat_date_time *tp)

This is basically time64_to_tm(), just be careful about to check whether
months are counted from 1 or 0.

Arnd