2 Unix SMB/CIFS implementation.
4 test suite for delayed write update
6 Copyright (C) Volker Lendecke 2004
7 Copyright (C) Andrew Tridgell 2004
8 Copyright (C) Jeremy Allison 2004
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "torture/torture.h"
26 #include "libcli/raw/libcliraw.h"
27 #include "libcli/raw/raw_proto.h"
28 #include "system/time.h"
29 #include "system/filesys.h"
30 #include "libcli/libcli.h"
31 #include "torture/util.h"
33 #define BASEDIR "\\delaywrite"
35 static bool test_delayed_write_update(struct torture_context *tctx, struct smbcli_state *cli)
37 union smb_fileinfo finfo1, finfo2;
38 const char *fname = BASEDIR "\\torture_file.txt";
45 int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
46 int normal_delay = 2000000;
47 double sec = ((double)used_delay) / ((double)normal_delay);
48 int msec = 1000 * sec;
50 if (!torture_setup_dir(cli, BASEDIR)) {
54 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
56 torture_comment(tctx, "Failed to open %s\n", fname);
60 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
61 finfo1.basic_info.in.file.fnum = fnum1;
64 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
66 if (!NT_STATUS_IS_OK(status)) {
67 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
71 torture_comment(tctx, "Initial write time %s\n",
72 nt_time_string(tctx, finfo1.basic_info.out.write_time));
74 /* 3 second delay to ensure we get past any 2 second time
75 granularity (older systems may have that) */
78 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
81 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
82 (int)written, __location__);
86 start = timeval_current();
87 end = timeval_add(&start, (120*sec), 0);
88 while (!timeval_expired(&end)) {
89 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
91 if (!NT_STATUS_IS_OK(status)) {
92 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
96 torture_comment(tctx, "write time %s\n",
97 nt_time_string(tctx, finfo2.basic_info.out.write_time));
98 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
99 double diff = timeval_elapsed(&start);
100 if (diff < (2 * sec * 0.75)) { /* 0.75 to cope with vmware timing */
101 torture_comment(tctx, "Server updated write_time after %.2f seconds"
102 "(1 sec == %.2f)(wrong!)\n",
108 torture_comment(tctx, "Server updated write_time after %.2f seconds"
109 "(1 sec == %.2f)(correct)\n",
117 if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
118 torture_comment(tctx, "Server did not update write time (wrong!)\n");
124 smbcli_close(cli->tree, fnum1);
125 smbcli_unlink(cli->tree, fname);
126 smbcli_deltree(cli->tree, BASEDIR);
132 * Do as above, but using 2 connections.
135 static bool test_delayed_write_update2(struct torture_context *tctx, struct smbcli_state *cli,
136 struct smbcli_state *cli2)
138 union smb_fileinfo finfo1, finfo2;
139 const char *fname = BASEDIR "\\torture_file.txt";
145 struct timeval start;
147 int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
148 int normal_delay = 2000000;
149 double sec = ((double)used_delay) / ((double)normal_delay);
150 int msec = 1000 * sec;
151 union smb_flush flsh;
153 if (!torture_setup_dir(cli, BASEDIR)) {
157 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
159 torture_comment(tctx, "Failed to open %s\n", fname);
163 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
164 finfo1.basic_info.in.file.fnum = fnum1;
167 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
169 if (!NT_STATUS_IS_OK(status)) {
170 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
174 torture_comment(tctx, "Initial write time %s\n",
175 nt_time_string(tctx, finfo1.basic_info.out.write_time));
177 /* 3 second delay to ensure we get past any 2 second time
178 granularity (older systems may have that) */
182 /* Try using setfileinfo instead of write to update write time. */
183 union smb_setfileinfo sfinfo;
184 time_t t_set = time(NULL);
185 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO;
186 sfinfo.basic_info.in.file.fnum = fnum1;
187 sfinfo.basic_info.in.create_time = finfo1.basic_info.out.create_time;
188 sfinfo.basic_info.in.access_time = finfo1.basic_info.out.access_time;
190 /* I tried this with both + and - ve to see if it makes a different.
191 It doesn't - once the filetime is set via setfileinfo it stays that way. */
193 unix_to_nt_time(&sfinfo.basic_info.in.write_time, t_set - 30000);
195 unix_to_nt_time(&sfinfo.basic_info.in.write_time, t_set + 30000);
197 sfinfo.basic_info.in.change_time = finfo1.basic_info.out.change_time;
198 sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib;
200 status = smb_raw_setfileinfo(cli->tree, &sfinfo);
202 if (!NT_STATUS_IS_OK(status)) {
203 DEBUG(0, ("sfileinfo failed: %s\n", nt_errstr(status)));
208 finfo2.basic_info.in.file.path = fname;
210 status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2);
212 if (!NT_STATUS_IS_OK(status)) {
213 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
216 torture_comment(tctx, "write time %s\n",
217 nt_time_string(tctx, finfo2.basic_info.out.write_time));
219 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
220 torture_comment(tctx, "Server updated write_time (correct)\n");
222 torture_comment(tctx, "Server did not update write time (wrong!)\n");
226 /* Now try a write to see if the write time gets reset. */
228 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
229 finfo1.basic_info.in.file.fnum = fnum1;
232 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
234 if (!NT_STATUS_IS_OK(status)) {
235 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
239 torture_comment(tctx, "Modified write time %s\n",
240 nt_time_string(tctx, finfo1.basic_info.out.write_time));
243 torture_comment(tctx, "Doing a 10 byte write to extend the file and see if this changes the last write time.\n");
245 written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 1, 10);
248 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
249 (int)written, __location__);
253 /* Just to prove to tridge that the an smbflush has no effect on
254 the write time :-). The setfileinfo IS STICKY. JRA. */
256 torture_comment(tctx, "Doing flush after write\n");
258 flsh.flush.level = RAW_FLUSH_FLUSH;
259 flsh.flush.in.file.fnum = fnum1;
260 status = smb_raw_flush(cli->tree, &flsh);
261 if (!NT_STATUS_IS_OK(status)) {
262 DEBUG(0, ("smbflush failed: %s\n", nt_errstr(status)));
266 /* Once the time was set using setfileinfo then it stays set - writes
267 don't have any effect. But make sure. */
268 start = timeval_current();
269 end = timeval_add(&start, (15*sec), 0);
270 while (!timeval_expired(&end)) {
271 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
273 if (!NT_STATUS_IS_OK(status)) {
274 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
278 torture_comment(tctx, "write time %s\n",
279 nt_time_string(tctx, finfo2.basic_info.out.write_time));
280 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
281 double diff = timeval_elapsed(&start);
282 torture_comment(tctx, "Server updated write_time after %.2f seconds"
283 "(1sec == %.2f) (wrong!)\n",
292 if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
293 torture_comment(tctx, "Server did not update write time (correct)\n");
296 fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
298 torture_comment(tctx, "Failed to open %s\n", fname);
302 torture_comment(tctx, "Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n");
304 written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 11, 10);
307 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
308 (int)written, __location__);
312 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
314 if (!NT_STATUS_IS_OK(status)) {
315 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
318 torture_comment(tctx, "write time %s\n",
319 nt_time_string(tctx, finfo2.basic_info.out.write_time));
320 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
321 torture_comment(tctx, "Server updated write_time (wrong!)\n");
325 torture_comment(tctx, "Closing the first fd to see if write time updated.\n");
326 smbcli_close(cli->tree, fnum1);
329 torture_comment(tctx, "Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n");
331 written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 21, 10);
334 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
335 (int)written, __location__);
339 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
340 finfo1.basic_info.in.file.fnum = fnum2;
342 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
344 if (!NT_STATUS_IS_OK(status)) {
345 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
348 torture_comment(tctx, "write time %s\n",
349 nt_time_string(tctx, finfo2.basic_info.out.write_time));
350 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
351 torture_comment(tctx, "Server updated write_time (wrong!)\n");
355 /* Once the time was set using setfileinfo then it stays set - writes
356 don't have any effect. But make sure. */
357 start = timeval_current();
358 end = timeval_add(&start, (15*sec), 0);
359 while (!timeval_expired(&end)) {
360 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
362 if (!NT_STATUS_IS_OK(status)) {
363 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
367 torture_comment(tctx, "write time %s\n",
368 nt_time_string(tctx, finfo2.basic_info.out.write_time));
369 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
370 double diff = timeval_elapsed(&start);
371 torture_comment(tctx, "Server updated write_time after %.2f seconds "
372 "(1sec == %.2f) (wrong!)\n",
381 if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
382 torture_comment(tctx, "Server did not update write time (correct)\n");
385 torture_comment(tctx, "Closing second fd to see if write time updated.\n");
387 smbcli_close(cli->tree, fnum2);
390 fnum1 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
392 torture_comment(tctx, "Failed to open %s\n", fname);
396 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
397 finfo1.basic_info.in.file.fnum = fnum1;
400 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
402 if (!NT_STATUS_IS_OK(status)) {
403 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
407 torture_comment(tctx, "Second open initial write time %s\n",
408 nt_time_string(tctx, finfo1.basic_info.out.write_time));
411 torture_comment(tctx, "Doing a 10 byte write to extend the file to see if this changes the last write time.\n");
413 written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 31, 10);
416 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
417 (int)written, __location__);
421 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
422 finfo1.basic_info.in.file.fnum = fnum1;
424 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
426 if (!NT_STATUS_IS_OK(status)) {
427 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
430 torture_comment(tctx, "write time %s\n",
431 nt_time_string(tctx, finfo2.basic_info.out.write_time));
432 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
433 torture_comment(tctx, "Server updated write_time (wrong!)\n");
437 /* Now the write time should be updated again */
438 start = timeval_current();
439 end = timeval_add(&start, (15*sec), 0);
440 while (!timeval_expired(&end)) {
441 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
443 if (!NT_STATUS_IS_OK(status)) {
444 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
448 torture_comment(tctx, "write time %s\n",
449 nt_time_string(tctx, finfo2.basic_info.out.write_time));
450 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
451 double diff = timeval_elapsed(&start);
452 if (diff < (2 * sec * 0.75)) { /* 0.75 to cope with vmware timing */
453 torture_comment(tctx, "Server updated write_time after %.2f seconds"
454 "(1sec == %.2f) (wrong!)\n",
460 torture_comment(tctx, "Server updated write_time after %.2f seconds"
461 "(1sec == %.2f) (correct)\n",
469 if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
470 torture_comment(tctx, "Server did not update write time (wrong!)\n");
475 /* One more test to do. We should read the filetime via findfirst on the
476 second connection to ensure it's the same. This is very easy for a Windows
477 server but a bastard to get right on a POSIX server. JRA. */
480 smbcli_close(cli->tree, fnum1);
481 smbcli_unlink(cli->tree, fname);
482 smbcli_deltree(cli->tree, BASEDIR);
488 /* Windows does obviously not update the stat info during a write call. I
489 * *think* this is the problem causing a spurious Excel 2003 on XP error
490 * message when saving a file. Excel does a setfileinfo, writes, and then does
491 * a getpath(!)info. Or so... For Samba sometimes it displays an error message
492 * that the file might have been changed in between. What i've been able to
493 * trace down is that this happens if the getpathinfo after the write shows a
494 * different last write time than the setfileinfo showed. This is really
498 static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_state *cli,
499 struct smbcli_state *cli2)
501 union smb_fileinfo finfo1, finfo2;
502 const char *fname = BASEDIR "\\torture_file.txt";
508 int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
509 int normal_delay = 2000000;
510 double sec = ((double)used_delay) / ((double)normal_delay);
511 int msec = 1000 * sec;
513 if (!torture_setup_dir(cli, BASEDIR)) {
517 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
520 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
524 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
525 finfo1.basic_info.in.file.fnum = fnum1;
527 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
529 if (!NT_STATUS_IS_OK(status)) {
531 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", nt_errstr(status));
537 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
540 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
545 fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE);
547 torture_result(tctx, TORTURE_FAIL, __location__": failed to open 2nd time - %s",
548 smbcli_errstr(cli2->tree));
553 written = smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1);
556 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1",
562 finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
563 finfo2.basic_info.in.file.path = fname;
565 status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2);
567 if (!NT_STATUS_IS_OK(status)) {
568 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s",
574 if (finfo1.basic_info.out.create_time !=
575 finfo2.basic_info.out.create_time) {
576 torture_result(tctx, TORTURE_FAIL, __location__": create_time changed");
581 if (finfo1.basic_info.out.access_time !=
582 finfo2.basic_info.out.access_time) {
583 torture_result(tctx, TORTURE_FAIL, __location__": access_time changed");
588 if (finfo1.basic_info.out.write_time !=
589 finfo2.basic_info.out.write_time) {
590 torture_result(tctx, TORTURE_FAIL, __location__": write_time changed:\n"
591 "write time conn 1 = %s, conn 2 = %s",
592 nt_time_string(tctx, finfo1.basic_info.out.write_time),
593 nt_time_string(tctx, finfo2.basic_info.out.write_time));
598 if (finfo1.basic_info.out.change_time !=
599 finfo2.basic_info.out.change_time) {
600 torture_result(tctx, TORTURE_FAIL, __location__": change_time changed");
605 /* One of the two following calls updates the qpathinfo. */
607 /* If you had skipped the smbcli_write on fnum2, it would
608 * *not* have updated the stat on disk */
610 smbcli_close(cli2->tree, fnum2);
613 /* This call is only for the people looking at ethereal :-) */
614 finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
615 finfo2.basic_info.in.file.path = fname;
617 status = smb_raw_pathinfo(cli->tree, tctx, &finfo2);
619 if (!NT_STATUS_IS_OK(status)) {
620 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", nt_errstr(status));
627 smbcli_close(cli->tree, fnum1);
628 smbcli_unlink(cli->tree, fname);
629 smbcli_deltree(cli->tree, BASEDIR);
634 #define COMPARE_WRITE_TIME_CMP(given, correct, cmp) do { \
635 uint64_t r = 10*1000*1000; \
636 NTTIME g = (given).basic_info.out.write_time; \
637 NTTIME gr = (g / r) * r; \
638 NTTIME c = (correct).basic_info.out.write_time; \
639 NTTIME cr = (c / r) * r; \
640 bool strict = torture_setting_bool(tctx, "strict mode", false); \
642 if (strict && (g cmp c)) { \
644 } else if (gr cmp cr) { \
645 /* handle filesystem without high resolution timestamps */ \
649 torture_result(tctx, TORTURE_FAIL, __location__": wrong write_time (%s)%s(%llu) %s (%s)%s(%llu)", \
650 #given, nt_time_string(tctx, g), (unsigned long long)g, \
651 #cmp, #correct, nt_time_string(tctx, c), (unsigned long long)c); \
656 #define COMPARE_WRITE_TIME_EQUAL(given,correct) \
657 COMPARE_WRITE_TIME_CMP(given,correct,!=)
658 #define COMPARE_WRITE_TIME_GREATER(given,correct) \
659 COMPARE_WRITE_TIME_CMP(given,correct,<=)
660 #define COMPARE_WRITE_TIME_LESS(given,correct) \
661 COMPARE_WRITE_TIME_CMP(given,correct,>=)
663 #define COMPARE_ACCESS_TIME_CMP(given, correct, cmp) do { \
664 NTTIME g = (given).basic_info.out.access_time; \
665 NTTIME c = (correct).basic_info.out.access_time; \
667 torture_result(tctx, TORTURE_FAIL, __location__": wrong access_time (%s)%s %s (%s)%s", \
668 #given, nt_time_string(tctx, g), \
669 #cmp, #correct, nt_time_string(tctx, c)); \
674 #define COMPARE_ACCESS_TIME_EQUAL(given,correct) \
675 COMPARE_ACCESS_TIME_CMP(given,correct,!=)
676 #define COMPARE_ACCESS_TIME_GREATER(given,correct) \
677 COMPARE_ACCESS_TIME_CMP(given,correct,<=)
678 #define COMPARE_ACCESS_TIME_LESS(given,correct) \
679 COMPARE_ACCESS_TIME_CMP(given,correct,>=)
681 #define COMPARE_BOTH_TIMES_EQUAL(given,correct) do { \
682 COMPARE_ACCESS_TIME_EQUAL(given,correct); \
683 COMPARE_WRITE_TIME_EQUAL(given,correct); \
685 #define COMPARE_BOTH_TIMES_GEATER(given,correct) do { \
686 COMPARE_ACCESS_TIME_GREATER(given,correct); \
687 COMPARE_WRITE_TIME_GREATER(given,correct); \
689 #define COMPARE_BOTH_TIMES_LESS(given,correct) do { \
690 COMPARE_ACCESS_TIME_LESS(given,correct); \
691 COMPARE_WRITE_TIME_LESS(given,correct); \
694 #define GET_INFO_FILE(finfo) do { \
696 _status = smb_raw_fileinfo(cli->tree, tctx, &finfo); \
697 if (!NT_STATUS_IS_OK(_status)) { \
699 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", \
700 nt_errstr(_status)); \
703 torture_comment(tctx, "fileinfo: Access(%s) Write(%s)\n", \
704 nt_time_string(tctx, finfo.basic_info.out.access_time), \
705 nt_time_string(tctx, finfo.basic_info.out.write_time)); \
707 #define GET_INFO_PATH(pinfo) do { \
709 _status = smb_raw_pathinfo(cli2->tree, tctx, &pinfo); \
710 if (!NT_STATUS_IS_OK(_status)) { \
711 torture_result(tctx, TORTURE_FAIL, __location__": pathinfo failed: %s", \
712 nt_errstr(_status)); \
716 torture_comment(tctx, "pathinfo: Access(%s) Write(%s)\n", \
717 nt_time_string(tctx, pinfo.basic_info.out.access_time), \
718 nt_time_string(tctx, pinfo.basic_info.out.write_time)); \
720 #define GET_INFO_BOTH(finfo,pinfo) do { \
721 GET_INFO_FILE(finfo); \
722 GET_INFO_PATH(pinfo); \
723 COMPARE_BOTH_TIMES_EQUAL(finfo,pinfo); \
726 #define SET_INFO_FILE_EX(finfo, wrtime, tree, tfnum) do { \
728 union smb_setfileinfo sfinfo; \
729 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO; \
730 sfinfo.basic_info.in.file.fnum = tfnum; \
731 sfinfo.basic_info.in.create_time = 0; \
732 sfinfo.basic_info.in.access_time = 0; \
733 unix_to_nt_time(&sfinfo.basic_info.in.write_time, (wrtime)); \
734 sfinfo.basic_info.in.change_time = 0; \
735 sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib; \
736 _status = smb_raw_setfileinfo(tree, &sfinfo); \
737 if (!NT_STATUS_IS_OK(_status)) { \
738 torture_result(tctx, TORTURE_FAIL, __location__": setfileinfo failed: %s", \
739 nt_errstr(_status)); \
744 #define SET_INFO_FILE(finfo, wrtime) \
745 SET_INFO_FILE_EX(finfo, wrtime, cli->tree, fnum1)
747 static bool test_delayed_write_update3(struct torture_context *tctx,
748 struct smbcli_state *cli,
749 struct smbcli_state *cli2)
751 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4;
752 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5;
753 const char *fname = BASEDIR "\\torture_file.txt";
757 struct timeval start;
759 int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
760 int normal_delay = 2000000;
761 double sec = ((double)used_delay) / ((double)normal_delay);
762 int msec = 1000 * sec;
764 if (!torture_setup_dir(cli, BASEDIR)) {
768 torture_comment(tctx, "Open the file handle\n");
769 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
772 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
776 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
777 finfo0.basic_info.in.file.fnum = fnum1;
782 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
783 pinfo0.basic_info.in.file.path = fname;
790 /* get the initial times */
791 GET_INFO_BOTH(finfo0,pinfo0);
794 * make sure the write time is updated 2 seconds later
795 * calcuated from the first write
796 * (but expect upto 5 seconds extra time for a busy server)
798 start = timeval_current();
799 end = timeval_add(&start, 7 * sec, 0);
800 while (!timeval_expired(&end)) {
802 torture_comment(tctx, "Do a write on the file handle\n");
803 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
805 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
809 /* get the times after the write */
810 GET_INFO_FILE(finfo1);
812 if (finfo1.basic_info.out.write_time > finfo0.basic_info.out.write_time) {
813 double diff = timeval_elapsed(&start);
814 if (diff < (2 * sec * 0.75)) { /* 0.75 to cope with vmware timing */
815 torture_comment(tctx, "Server updated write_time after %.2f seconds "
816 "(1sec == %.2f) (wrong!)\n",
822 torture_comment(tctx, "Server updated write_time after %.2f seconds "
823 "(1sec == %.2f) (correct)\n",
830 GET_INFO_BOTH(finfo1,pinfo1);
832 /* sure any further write doesn't update the write time */
833 start = timeval_current();
834 end = timeval_add(&start, 15 * sec, 0);
835 while (!timeval_expired(&end)) {
837 torture_comment(tctx, "Do a write on the file handle\n");
838 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
840 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
844 /* get the times after the write */
845 GET_INFO_BOTH(finfo2,pinfo2);
847 if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) {
848 double diff = timeval_elapsed(&start);
849 torture_comment(tctx, "Server updated write_time after %.2f seconds "
850 "(1sec == %.2f) (wrong!)\n",
858 GET_INFO_BOTH(finfo2,pinfo2);
859 COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1);
860 if (finfo2.basic_info.out.write_time == finfo1.basic_info.out.write_time) {
861 torture_comment(tctx, "Server did not update write_time (correct)\n");
867 GET_INFO_BOTH(finfo3,pinfo3);
868 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
871 * the close updates the write time to the time of the close
872 * and not to the time of the last write!
874 torture_comment(tctx, "Close the file handle\n");
875 smbcli_close(cli->tree, fnum1);
878 GET_INFO_PATH(pinfo4);
879 COMPARE_WRITE_TIME_GREATER(pinfo4, pinfo3);
881 if (pinfo4.basic_info.out.write_time > pinfo3.basic_info.out.write_time) {
882 torture_comment(tctx, "Server updated the write_time on close (correct)\n");
887 smbcli_close(cli->tree, fnum1);
888 smbcli_unlink(cli->tree, fname);
889 smbcli_deltree(cli->tree, BASEDIR);
894 static bool test_delayed_write_update4(struct torture_context *tctx,
895 struct smbcli_state *cli,
896 struct smbcli_state *cli2)
898 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4;
899 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5;
900 const char *fname = BASEDIR "\\torture_file.txt";
904 struct timeval start;
906 int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
907 int normal_delay = 2000000;
908 double sec = ((double)used_delay) / ((double)normal_delay);
909 int msec = 1000 * sec;
911 if (!torture_setup_dir(cli, BASEDIR)) {
915 torture_comment(tctx, "Open the file handle\n");
916 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
919 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
923 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
924 finfo0.basic_info.in.file.fnum = fnum1;
929 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
930 pinfo0.basic_info.in.file.path = fname;
937 /* get the initial times */
938 GET_INFO_BOTH(finfo0,pinfo0);
944 torture_comment(tctx, "Do a write on the file handle\n");
945 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
947 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
952 GET_INFO_BOTH(finfo1,pinfo1);
953 COMPARE_WRITE_TIME_EQUAL(finfo1,finfo0);
956 * make sure the write time is updated 2 seconds later
957 * calcuated from the first write
958 * (but expect upto 3 seconds extra time for a busy server)
960 start = timeval_current();
961 end = timeval_add(&start, 5 * sec, 0);
962 while (!timeval_expired(&end)) {
963 /* get the times after the first write */
964 GET_INFO_FILE(finfo1);
966 if (finfo1.basic_info.out.write_time > finfo0.basic_info.out.write_time) {
967 double diff = timeval_elapsed(&start);
968 if (diff < (2 * sec * 0.75)) { /* 0.75 to cope with vmware timing */
969 torture_comment(tctx, "Server updated write_time after %.2f seconds "
970 "(1sec == %.2f) (wrong!)\n",
976 torture_comment(tctx, "Server updated write_time after %.2f seconds "
977 "(1sec == %.2f) (correct)\n",
984 GET_INFO_BOTH(finfo1,pinfo1);
986 /* sure any further write doesn't update the write time */
987 start = timeval_current();
988 end = timeval_add(&start, 15 * sec, 0);
989 while (!timeval_expired(&end)) {
991 torture_comment(tctx, "Do a write on the file handle\n");
992 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
994 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
998 /* get the times after the write */
999 GET_INFO_BOTH(finfo2,pinfo2);
1001 if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) {
1002 double diff = timeval_elapsed(&start);
1003 torture_comment(tctx, "Server updated write_time after %.2f seconds "
1004 "(1sec == %.2f) (wrong!)\n",
1012 GET_INFO_BOTH(finfo2,pinfo2);
1013 COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1);
1014 if (finfo2.basic_info.out.write_time == finfo1.basic_info.out.write_time) {
1015 torture_comment(tctx, "Server did not updatewrite_time (correct)\n");
1021 GET_INFO_BOTH(finfo3,pinfo3);
1022 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
1025 * the close updates the write time to the time of the close
1026 * and not to the time of the last write!
1028 torture_comment(tctx, "Close the file handle\n");
1029 smbcli_close(cli->tree, fnum1);
1032 GET_INFO_PATH(pinfo4);
1033 COMPARE_WRITE_TIME_GREATER(pinfo4, pinfo3);
1035 if (pinfo4.basic_info.out.write_time > pinfo3.basic_info.out.write_time) {
1036 torture_comment(tctx, "Server updated the write_time on close (correct)\n");
1041 smbcli_close(cli->tree, fnum1);
1042 smbcli_unlink(cli->tree, fname);
1043 smbcli_deltree(cli->tree, BASEDIR);
1048 static bool test_delayed_write_update5(struct torture_context *tctx,
1049 struct smbcli_state *cli,
1050 struct smbcli_state *cli2)
1052 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5;
1053 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6;
1054 const char *fname = BASEDIR "\\torture_file.txt";
1058 struct timeval start;
1060 int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
1061 int normal_delay = 2000000;
1062 double sec = ((double)used_delay) / ((double)normal_delay);
1063 int msec = 1000 * sec;
1065 if (!torture_setup_dir(cli, BASEDIR)) {
1069 torture_comment(tctx, "Open the file handle\n");
1070 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1073 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1077 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1078 finfo0.basic_info.in.file.fnum = fnum1;
1084 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1085 pinfo0.basic_info.in.file.path = fname;
1093 /* get the initial times */
1094 GET_INFO_BOTH(finfo0,pinfo0);
1097 torture_comment(tctx, "Do a write on the file handle\n");
1098 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1100 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1105 GET_INFO_BOTH(finfo1,pinfo1);
1106 COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0);
1108 torture_comment(tctx, "Set write time in the future on the file handle\n");
1109 SET_INFO_FILE(finfo0, time(NULL) + 86400);
1110 GET_INFO_BOTH(finfo2,pinfo2);
1111 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
1113 torture_comment(tctx, "Set write time in the past on the file handle\n");
1114 SET_INFO_FILE(finfo0, time(NULL) - 86400);
1115 GET_INFO_BOTH(finfo2,pinfo2);
1116 COMPARE_WRITE_TIME_LESS(finfo2, finfo1);
1118 /* make sure the 2 second delay from the first write are canceled */
1119 start = timeval_current();
1120 end = timeval_add(&start, 15 * sec, 0);
1121 while (!timeval_expired(&end)) {
1123 /* get the times after the first write */
1124 GET_INFO_BOTH(finfo3,pinfo3);
1126 if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) {
1127 double diff = timeval_elapsed(&start);
1128 torture_comment(tctx, "Server updated write_time after %.2f seconds "
1129 "(1sec == %.2f) (wrong!)\n",
1137 GET_INFO_BOTH(finfo3,pinfo3);
1138 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
1139 if (finfo3.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1140 torture_comment(tctx, "Server did not update write_time (correct)\n");
1143 /* sure any further write doesn't update the write time */
1144 start = timeval_current();
1145 end = timeval_add(&start, 15 * sec, 0);
1146 while (!timeval_expired(&end)) {
1148 torture_comment(tctx, "Do a write on the file handle\n");
1149 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1151 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1155 /* get the times after the write */
1156 GET_INFO_BOTH(finfo4,pinfo4);
1158 if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) {
1159 double diff = timeval_elapsed(&start);
1160 torture_comment(tctx, "Server updated write_time after %.2f seconds "
1161 "(1sec == %.2f) (wrong!)\n",
1169 GET_INFO_BOTH(finfo4,pinfo4);
1170 COMPARE_WRITE_TIME_EQUAL(finfo4, finfo3);
1171 if (finfo4.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1172 torture_comment(tctx, "Server did not update write_time (correct)\n");
1178 GET_INFO_BOTH(finfo5,pinfo5);
1179 COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4);
1182 * the close doesn't update the write time
1184 torture_comment(tctx, "Close the file handle\n");
1185 smbcli_close(cli->tree, fnum1);
1188 GET_INFO_PATH(pinfo6);
1189 COMPARE_WRITE_TIME_EQUAL(pinfo6, pinfo5);
1191 if (pinfo6.basic_info.out.write_time == pinfo5.basic_info.out.write_time) {
1192 torture_comment(tctx, "Server did not update the write_time on close (correct)\n");
1197 smbcli_close(cli->tree, fnum1);
1198 smbcli_unlink(cli->tree, fname);
1199 smbcli_deltree(cli->tree, BASEDIR);
1204 static bool test_delayed_write_update6(struct torture_context *tctx,
1205 struct smbcli_state *cli,
1206 struct smbcli_state *cli2)
1208 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5;
1209 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6, pinfo7;
1210 const char *fname = BASEDIR "\\torture_file.txt";
1215 struct timeval start;
1217 int used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
1218 int normal_delay = 2000000;
1219 double sec = ((double)used_delay) / ((double)normal_delay);
1220 int msec = 1000 * sec;
1223 if (!torture_setup_dir(cli, BASEDIR)) {
1227 torture_comment(tctx, "Open the file handle\n");
1228 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1231 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1236 torture_comment(tctx, "Open the 2nd file handle on 2nd connection\n");
1237 fnum2 = smbcli_open(cli2->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1240 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1245 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1246 finfo0.basic_info.in.file.fnum = fnum1;
1252 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1253 pinfo0.basic_info.in.file.path = fname;
1262 /* get the initial times */
1263 GET_INFO_BOTH(finfo0,pinfo0);
1266 torture_comment(tctx, "Do a write on the file handle\n");
1267 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1269 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1274 GET_INFO_BOTH(finfo1,pinfo1);
1275 COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0);
1277 torture_comment(tctx, "Set write time in the future on the 2nd file handle\n");
1278 SET_INFO_FILE_EX(finfo0, time(NULL) + 86400, cli2->tree, fnum2);
1279 GET_INFO_BOTH(finfo2,pinfo2);
1280 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
1282 torture_comment(tctx, "Set write time in the past on the 2nd file handle\n");
1283 SET_INFO_FILE_EX(finfo0, time(NULL) - 86400, cli2->tree, fnum2);
1284 GET_INFO_BOTH(finfo2,pinfo2);
1285 COMPARE_WRITE_TIME_LESS(finfo2, finfo1);
1287 /* make sure the 2 second delay from the first write are canceled */
1288 start = timeval_current();
1289 end = timeval_add(&start, 15 * sec, 0);
1290 while (!timeval_expired(&end)) {
1292 /* get the times after the first write */
1293 GET_INFO_BOTH(finfo3,pinfo3);
1295 if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) {
1296 double diff = timeval_elapsed(&start);
1297 torture_comment(tctx, "Server updated write_time after %.2f seconds "
1298 "(1sec == %.2f) (wrong!)\n",
1306 GET_INFO_BOTH(finfo3,pinfo3);
1307 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
1308 if (finfo3.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1309 torture_comment(tctx, "Server did not update write_time (correct)\n");
1312 /* sure any further write doesn't update the write time */
1313 start = timeval_current();
1314 end = timeval_add(&start, 15 * sec, 0);
1315 while (!timeval_expired(&end)) {
1317 torture_comment(tctx, "Do a write on the file handle\n");
1318 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1320 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1324 /* get the times after the write */
1325 GET_INFO_BOTH(finfo4,pinfo4);
1327 if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) {
1328 double diff = timeval_elapsed(&start);
1329 torture_comment(tctx, "Server updated write_time after %.2f seconds "
1330 "(1sec == %.2f) (wrong!)\n",
1338 GET_INFO_BOTH(finfo4,pinfo4);
1339 COMPARE_WRITE_TIME_EQUAL(finfo4, finfo3);
1340 if (finfo4.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1341 torture_comment(tctx, "Server did not update write_time (correct)\n");
1347 GET_INFO_BOTH(finfo5,pinfo5);
1348 COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4);
1351 * the close updates the write time to the time of the close
1352 * as the write time was set on the 2nd handle
1354 torture_comment(tctx, "Close the file handle\n");
1355 smbcli_close(cli->tree, fnum1);
1358 GET_INFO_PATH(pinfo6);
1359 COMPARE_WRITE_TIME_GREATER(pinfo6, pinfo5);
1361 if (pinfo6.basic_info.out.write_time > pinfo5.basic_info.out.write_time) {
1362 torture_comment(tctx, "Server updated the write_time on close (correct)\n");
1365 /* keep the 2nd handle open and rerun tests */
1372 * closing the 2nd handle will cause no write time update
1373 * as the write time was explicit set on this handle
1375 torture_comment(tctx, "Close the 2nd file handle\n");
1376 smbcli_close(cli2->tree, fnum2);
1379 GET_INFO_PATH(pinfo7);
1380 COMPARE_WRITE_TIME_EQUAL(pinfo7, pinfo6);
1382 if (pinfo7.basic_info.out.write_time == pinfo6.basic_info.out.write_time) {
1383 torture_comment(tctx, "Server did not update the write_time on close (correct)\n");
1388 smbcli_close(cli->tree, fnum1);
1390 smbcli_close(cli2->tree, fnum2);
1391 smbcli_unlink(cli->tree, fname);
1392 smbcli_deltree(cli->tree, BASEDIR);
1399 testing of delayed update of write_time
1401 struct torture_suite *torture_delay_write(void)
1403 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "DELAYWRITE");
1405 torture_suite_add_2smb_test(suite, "finfo update on close", test_finfo_after_write);
1406 torture_suite_add_1smb_test(suite, "delayed update of write time", test_delayed_write_update);
1407 torture_suite_add_2smb_test(suite, "delayed update of write time using 2 connections", test_delayed_write_update2);
1408 torture_suite_add_2smb_test(suite, "delayed update of write time 3", test_delayed_write_update3);
1409 torture_suite_add_2smb_test(suite, "delayed update of write time 4", test_delayed_write_update4);
1410 torture_suite_add_2smb_test(suite, "delayed update of write time 5", test_delayed_write_update5);
1411 torture_suite_add_2smb_test(suite, "delayed update of write time 6", test_delayed_write_update6);