Bug 10802 - SetInfo of times before 1970 fails
SetInfo of times before 1970 fails
Status: RESOLVED DUPLICATE of bug 7771
Product: Samba 4.1 and newer
Classification: Unclassified
Component: File services
unspecified
All All
: P5 normal
: ---
Assigned To: Samba QA Contact
Samba QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-09-08 06:37 UTC by Steve French
Modified: 2014-10-13 10:52 UTC (History)
1 user (show)

See Also:


Attachments
trace of cifs mount to samba - with incorrect request on set then query of time (3.41 KB, application/octet-stream)
2014-09-08 06:38 UTC, Steve French
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Steve French 2014-09-08 06:37:40 UTC
xfstests test generic/258 sets the time of a file before 1970 (ie to a negative number, before the epoch) e.g.

touch -t 196001010101 /mnt/testfile

This works to windows and although it appears to succeed to Samba with or without Unix extensions (ie SET_FILE_UNIX_INFO or SET_FILE_ALL_INFO) to Samba it actually sets the time to current time and does not set the time to the requested value.  If the file is updated locally (ie touch is done locally on ext4 not over a cifs mount), Samba will report the time properly to cifs clients so the problem is on the set info not the query info.

See frame 10 in the attached trace (set info request to timestamp in 1960) whih succeeds in frame 11.  The query in frame 16 though shows the wrong timestamp (ie the timestamp was the same as at file creation, instead of what we just set it to ie in 1960).

When this is fixed - note that there is a second problem (this one in the kernel cifs client) - ie that the cifs VFS can't convert negative times properly on query info (stat) but that obviously is only seen when mounted to Windows (as Samba won't let you set time before 1970).

FYI - The unrelated kernel client problem is on the conversion of negative time values and could be fixed with a change like the following:

--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -925,11 +925,19 @@ cifs_NTtimeToUnix(__le64 ntutc)
 	/* BB what about the timezone? BB */
 
 	/* Subtract the NTFS time offset, then convert to 1s intervals. */
-	u64 t;
+	s64 t;
 
 	t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET;
-	ts.tv_nsec = do_div(t, 10000000) * 100;
-	ts.tv_sec = t;
+
+	if (t < 0) {
+		t = -t;
+		ts.tv_nsec = -(do_div(t, 10000000) * 100);
+		ts.tv_sec = -t;
+	} else {
+		ts.tv_nsec = do_div(t, 10000000) * 100;
+		ts.tv_sec = t;
+	}
+
 	return ts;
 }
Comment 1 Steve French 2014-09-08 06:38:39 UTC
Created attachment 10264 [details]
trace of cifs mount to samba - with incorrect request on set then query of time
Comment 2 Björn Jacke 2014-09-08 07:39:02 UTC

*** This bug has been marked as a duplicate of bug 7771 ***