Skip to content

Commit

Permalink
[CIFS] Fix setting time before epoch (negative time values)
Browse files Browse the repository at this point in the history
xfstest generic/258 sets the time on a file to a negative value
(before 1970) which fails since do_div can not handle negative
numbers.  In addition 'normal' division of 64 bit values does
not build on 32 bit arch so have to workaround this by special
casing negative values in cifs_NTtimeToUnix

Samba server also has a bug with this (see samba bugzilla 7771)
but it works to Windows server.

Signed-off-by: Steve French <[email protected]>
  • Loading branch information
smfrench committed Sep 14, 2014
1 parent 1536340 commit 2ae83bf
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions fs/cifs/netmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,11 +925,23 @@ cifs_NTtimeToUnix(__le64 ntutc)
/* BB what about the timezone? BB */

/* Subtract the NTFS time offset, then convert to 1s intervals. */
u64 t;
s64 t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET;

/*
* Unfortunately can not use normal 64 bit division on 32 bit arch, but
* the alternative, do_div, does not work with negative numbers so have
* to special case them
*/
if (t < 0) {
t = -t;
ts.tv_nsec = (long)(do_div(t, 10000000) * 100);
ts.tv_nsec = -ts.tv_nsec;
ts.tv_sec = -t;
} else {
ts.tv_nsec = (long)do_div(t, 10000000) * 100;
ts.tv_sec = t;
}

t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET;
ts.tv_nsec = do_div(t, 10000000) * 100;
ts.tv_sec = t;
return ts;
}

Expand Down

0 comments on commit 2ae83bf

Please sign in to comment.