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.ker...@gmail.com>
---
 include/linux/time64.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/include/linux/time64.h b/include/linux/time64.h
index 367d5af..bb574b8 100644
--- a/include/linux/time64.h
+++ b/include/linux/time64.h
@@ -13,6 +13,16 @@ typedef __s64 time64_t;
 #if __BITS_PER_LONG == 64
 # define timespec64 timespec
 #define itimerspec64 itimerspec
+
+/*
+ * Internal kernel representation of inode time fields.
+ * This structure is not exposed to userspace.
+ * Use struct timespec64 representation for all userspace.
+ */
+struct inode_time {
+       time64_t        tv_sec;
+       s32             tv_nsec;
+} __aligned(4) __packed;
 #else
 struct timespec64 {
        time64_t        tv_sec;                 /* seconds */
@@ -24,6 +34,7 @@ struct itimerspec64 {
        struct timespec64 it_value;
 };
 
+#define inode_time timespec64
 #endif
 
 /* Parameters used to convert the timespec values: */
@@ -42,6 +53,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 +109,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;
-- 
1.9.1

_______________________________________________
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038

Reply via email to