The current representation of inode times in struct inode: struct timespec is not y2038 safe.
The 64 bit counterpart of struct timespec: struct timespec64 suffers from the shortcoming that the data type sizes are different on 32 bit and 64 bit systems.
Introduce a new struct inode_time to overcome the above limitations.
Also add time conversion api's between struct timespec64 and struct inode_time. This is required as the 64-bit time functions typically return struct timespec64 types.
Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com --- include/linux/time64.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
diff --git a/include/linux/time64.h b/include/linux/time64.h index 367d5af..9523704 100644 --- a/include/linux/time64.h +++ b/include/linux/time64.h @@ -26,6 +26,20 @@ struct itimerspec64 {
#endif
+/* + * Internal kernel representation of inode fields. + * This structure is not exposed to userspace. + * Use struct timespec64 representation for all userspace. + */ +#ifdef CONFIG_FS_USES_64BIT_TIME +struct inode_time { + time64_t tv_sec; + s32 tv_nsec; +} __aligned(4) __packed; +#else +#define inode_time timespec +#endif + /* Parameters used to convert the timespec values: */ #define MSEC_PER_SEC 1000L #define USEC_PER_MSEC 1000L @@ -42,6 +56,28 @@ struct itimerspec64 {
#if __BITS_PER_LONG == 64
+static inline struct inode_time +timespec64_to_inode_time(const struct timespec64 ts64) +{ + struct inode_time ret; + + ret.tv_sec = ts64.tv_sec; + ret.tv_nsec = ts64.tv_nsec; + + return ret; +} + +static inline struct timespec64 +inode_time_to_timespec64(const struct inode_time itime) +{ + struct timespec64 ret; + + ret.tv_sec = itime.tv_sec; + ret.tv_nsec = itime.tv_nsec; + + return ret; +} + static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) { return ts64; @@ -76,6 +112,18 @@ static inline struct itimerspec64 itimerspec_to_itimerspec64(struct itimerspec *
#else
+static inline struct inode_time +timespec64_to_inode_time(const struct timespec64 ts64) +{ + return ts64; +} + +static inline struct timespec64 +inode_time_to_timespec64(const struct inode_time itime) +{ + return itime; +} + static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) { struct timespec ret;