On Thursday 12 November 2015 21:26:03 DengChao wrote:
/*
- Since time32_t is stored into media, the range has been already lost
- for time64_t anyway. Only thing we can do is directly cast between
- time32_t and time64_t. Forunately, time32_t won't overflow until 2106.
- */
+static inline time64_t cast_to_time64(time32_t t) +{
- return (time64_t)t;
+}
+static inline time32_t cast_to_time32(time64_t t) +{
- return (time32_t)t;
+}
+/*
- local time (HPFS) to GMT (Unix)
*/ -static inline time_t local_to_gmt(struct super_block *s, time32_t t) +static inline time64_t local_to_gmt(struct super_block *s, time32_t t) { extern struct timezone sys_tz;
- return t + sys_tz.tz_minuteswest * 60 + hpfs_sb(s)->sb_timeshift;
- return cast_to_time64(t + sys_tz.tz_minuteswest * 60
+ hpfs_sb(s)->sb_timeshift);
} -static inline time32_t gmt_to_local(struct super_block *s, time_t t) +static inline time32_t gmt_to_local(struct super_block *s, time64_t t) { extern struct timezone sys_tz;
- return t - sys_tz.tz_minuteswest * 60 - hpfs_sb(s)->sb_timeshift;
- return cast_to_time32(t - sys_tz.tz_minuteswest * 60
- hpfs_sb(s)->sb_timeshift);
}
You already have conversion functions here, I would fold the new handlers into these and add the comment right above them. Note that the time of the overflow also depends on the timeshift value.
If we make change sb_timeshift to a time64_t, we could support much later times as well.
diff --git a/fs/hpfs/namei.c b/fs/hpfs/namei.c index 9fcb6f0..5fd608b 100644 --- a/fs/hpfs/namei.c +++ b/fs/hpfs/namei.c @@ -49,7 +49,9 @@ static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) /*dee.archive = 0;*/ dee.hidden = name[0] == '.'; dee.fnode = cpu_to_le32(fno);
- dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
- dee.creation_date = dee.write_date = dee.read_date =
cpu_to_le32(gmt_to_local(dir->i_sb,
result = new_inode(dir->i_sb); if (!result) goto bail2;ktime_get_real_seconds()));
I think it would be a nice change to fold the cpu_to_le32()/le32_to_cpu() into the local_to_gmt()/gmt_to_local() functions and replace time32_t with __le32.
Otherwise this looks like a useful change.
Arnd