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 "system/time.h"
28 #include "system/filesys.h"
29 #include "libcli/libcli.h"
30 #include "torture/util.h"
32 #define BASEDIR "\\delaywrite"
34 static bool test_delayed_write_update(struct torture_context *tctx, struct smbcli_state *cli)
36 union smb_fileinfo finfo1, finfo2;
37 const char *fname = BASEDIR "\\torture_file.txt";
44 if (!torture_setup_dir(cli, BASEDIR)) {
48 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
50 torture_comment(tctx, "Failed to open %s\n", fname);
54 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
55 finfo1.basic_info.in.file.fnum = fnum1;
58 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
60 if (!NT_STATUS_IS_OK(status)) {
61 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
65 torture_comment(tctx, "Initial write time %s\n",
66 nt_time_string(tctx, finfo1.basic_info.out.write_time));
68 /* 3 second delay to ensure we get past any 2 second time
69 granularity (older systems may have that) */
72 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
75 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
76 (int)written, __location__);
82 while (time(NULL) < t+120) {
83 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
85 if (!NT_STATUS_IS_OK(status)) {
86 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
90 torture_comment(tctx, "write time %s\n",
91 nt_time_string(tctx, finfo2.basic_info.out.write_time));
92 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
93 int diff = time(NULL) - t;
95 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
101 torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n",
109 if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
110 torture_comment(tctx, "Server did not update write time (wrong!)\n");
116 smbcli_close(cli->tree, fnum1);
117 smbcli_unlink(cli->tree, fname);
118 smbcli_deltree(cli->tree, BASEDIR);
124 * Do as above, but using 2 connections.
127 static bool test_delayed_write_update2(struct torture_context *tctx, struct smbcli_state *cli,
128 struct smbcli_state *cli2)
130 union smb_fileinfo finfo1, finfo2;
131 const char *fname = BASEDIR "\\torture_file.txt";
138 union smb_flush flsh;
140 if (!torture_setup_dir(cli, BASEDIR)) {
144 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
146 torture_comment(tctx, "Failed to open %s\n", fname);
150 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
151 finfo1.basic_info.in.file.fnum = fnum1;
154 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
156 if (!NT_STATUS_IS_OK(status)) {
157 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
161 torture_comment(tctx, "Initial write time %s\n",
162 nt_time_string(tctx, finfo1.basic_info.out.write_time));
164 /* 3 second delay to ensure we get past any 2 second time
165 granularity (older systems may have that) */
169 /* Try using setfileinfo instead of write to update write time. */
170 union smb_setfileinfo sfinfo;
171 time_t t_set = time(NULL);
172 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO;
173 sfinfo.basic_info.in.file.fnum = fnum1;
174 sfinfo.basic_info.in.create_time = finfo1.basic_info.out.create_time;
175 sfinfo.basic_info.in.access_time = finfo1.basic_info.out.access_time;
177 /* I tried this with both + and - ve to see if it makes a different.
178 It doesn't - once the filetime is set via setfileinfo it stays that way. */
180 unix_to_nt_time(&sfinfo.basic_info.in.write_time, t_set - 30000);
182 unix_to_nt_time(&sfinfo.basic_info.in.write_time, t_set + 30000);
184 sfinfo.basic_info.in.change_time = finfo1.basic_info.out.change_time;
185 sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib;
187 status = smb_raw_setfileinfo(cli->tree, &sfinfo);
189 if (!NT_STATUS_IS_OK(status)) {
190 DEBUG(0, ("sfileinfo failed: %s\n", nt_errstr(status)));
195 finfo2.basic_info.in.file.path = fname;
197 status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2);
199 if (!NT_STATUS_IS_OK(status)) {
200 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
203 torture_comment(tctx, "write time %s\n",
204 nt_time_string(tctx, finfo2.basic_info.out.write_time));
206 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
207 torture_comment(tctx, "Server updated write_time (correct)\n");
209 torture_comment(tctx, "Server did not update write time (wrong!)\n");
213 /* Now try a write to see if the write time gets reset. */
215 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
216 finfo1.basic_info.in.file.fnum = fnum1;
219 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
221 if (!NT_STATUS_IS_OK(status)) {
222 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
226 torture_comment(tctx, "Modified write time %s\n",
227 nt_time_string(tctx, finfo1.basic_info.out.write_time));
230 torture_comment(tctx, "Doing a 10 byte write to extend the file and see if this changes the last write time.\n");
232 written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 1, 10);
235 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
236 (int)written, __location__);
240 /* Just to prove to tridge that the an smbflush has no effect on
241 the write time :-). The setfileinfo IS STICKY. JRA. */
243 torture_comment(tctx, "Doing flush after write\n");
245 flsh.flush.level = RAW_FLUSH_FLUSH;
246 flsh.flush.in.file.fnum = fnum1;
247 status = smb_raw_flush(cli->tree, &flsh);
248 if (!NT_STATUS_IS_OK(status)) {
249 DEBUG(0, ("smbflush failed: %s\n", nt_errstr(status)));
255 /* Once the time was set using setfileinfo then it stays set - writes
256 don't have any effect. But make sure. */
258 while (time(NULL) < t+15) {
259 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
261 if (!NT_STATUS_IS_OK(status)) {
262 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
266 torture_comment(tctx, "write time %s\n",
267 nt_time_string(tctx, finfo2.basic_info.out.write_time));
268 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
269 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
270 (int)(time(NULL) - t));
278 if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
279 torture_comment(tctx, "Server did not update write time (correct)\n");
282 fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
284 torture_comment(tctx, "Failed to open %s\n", fname);
288 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");
290 written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 11, 10);
293 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
294 (int)written, __location__);
298 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
300 if (!NT_STATUS_IS_OK(status)) {
301 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
304 torture_comment(tctx, "write time %s\n",
305 nt_time_string(tctx, finfo2.basic_info.out.write_time));
306 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
307 torture_comment(tctx, "Server updated write_time (wrong!)\n");
311 torture_comment(tctx, "Closing the first fd to see if write time updated.\n");
312 smbcli_close(cli->tree, fnum1);
315 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");
317 written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 21, 10);
320 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
321 (int)written, __location__);
325 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
326 finfo1.basic_info.in.file.fnum = fnum2;
328 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
330 if (!NT_STATUS_IS_OK(status)) {
331 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
334 torture_comment(tctx, "write time %s\n",
335 nt_time_string(tctx, finfo2.basic_info.out.write_time));
336 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
337 torture_comment(tctx, "Server updated write_time (wrong!)\n");
343 /* Once the time was set using setfileinfo then it stays set - writes
344 don't have any effect. But make sure. */
346 while (time(NULL) < t+15) {
347 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
349 if (!NT_STATUS_IS_OK(status)) {
350 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
354 torture_comment(tctx, "write time %s\n",
355 nt_time_string(tctx, finfo2.basic_info.out.write_time));
356 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
357 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
358 (int)(time(NULL) - t));
366 if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
367 torture_comment(tctx, "Server did not update write time (correct)\n");
370 torture_comment(tctx, "Closing second fd to see if write time updated.\n");
372 smbcli_close(cli->tree, fnum2);
375 fnum1 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
377 torture_comment(tctx, "Failed to open %s\n", fname);
381 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
382 finfo1.basic_info.in.file.fnum = fnum1;
385 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
387 if (!NT_STATUS_IS_OK(status)) {
388 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
392 torture_comment(tctx, "Second open initial write time %s\n",
393 nt_time_string(tctx, finfo1.basic_info.out.write_time));
396 torture_comment(tctx, "Doing a 10 byte write to extend the file to see if this changes the last write time.\n");
398 written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 31, 10);
401 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
402 (int)written, __location__);
406 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
407 finfo1.basic_info.in.file.fnum = fnum1;
409 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
411 if (!NT_STATUS_IS_OK(status)) {
412 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
415 torture_comment(tctx, "write time %s\n",
416 nt_time_string(tctx, finfo2.basic_info.out.write_time));
417 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
418 torture_comment(tctx, "Server updated write_time (wrong!)\n");
424 /* Now the write time should be updated again */
426 while (time(NULL) < t+15) {
427 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
429 if (!NT_STATUS_IS_OK(status)) {
430 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
434 torture_comment(tctx, "write time %s\n",
435 nt_time_string(tctx, finfo2.basic_info.out.write_time));
436 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
437 int diff = time(NULL) - t;
439 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
445 torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n",
453 if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
454 torture_comment(tctx, "Server did not update write time (wrong!)\n");
459 /* One more test to do. We should read the filetime via findfirst on the
460 second connection to ensure it's the same. This is very easy for a Windows
461 server but a bastard to get right on a POSIX server. JRA. */
464 smbcli_close(cli->tree, fnum1);
465 smbcli_unlink(cli->tree, fname);
466 smbcli_deltree(cli->tree, BASEDIR);
472 /* Windows does obviously not update the stat info during a write call. I
473 * *think* this is the problem causing a spurious Excel 2003 on XP error
474 * message when saving a file. Excel does a setfileinfo, writes, and then does
475 * a getpath(!)info. Or so... For Samba sometimes it displays an error message
476 * that the file might have been changed in between. What i've been able to
477 * trace down is that this happens if the getpathinfo after the write shows a
478 * different last write time than the setfileinfo showed. This is really
482 static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_state *cli,
483 struct smbcli_state *cli2)
485 union smb_fileinfo finfo1, finfo2;
486 const char *fname = BASEDIR "\\torture_file.txt";
493 if (!torture_setup_dir(cli, BASEDIR)) {
497 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
500 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
504 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
505 finfo1.basic_info.in.file.fnum = fnum1;
507 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
509 if (!NT_STATUS_IS_OK(status)) {
511 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", nt_errstr(status));
517 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
520 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
525 fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE);
527 torture_result(tctx, TORTURE_FAIL, __location__": failed to open 2nd time - %s",
528 smbcli_errstr(cli2->tree));
533 written = smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1);
536 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1",
542 finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
543 finfo2.basic_info.in.file.path = fname;
545 status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2);
547 if (!NT_STATUS_IS_OK(status)) {
548 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s",
554 if (finfo1.basic_info.out.create_time !=
555 finfo2.basic_info.out.create_time) {
556 torture_result(tctx, TORTURE_FAIL, __location__": create_time changed");
561 if (finfo1.basic_info.out.access_time !=
562 finfo2.basic_info.out.access_time) {
563 torture_result(tctx, TORTURE_FAIL, __location__": access_time changed");
568 if (finfo1.basic_info.out.write_time !=
569 finfo2.basic_info.out.write_time) {
570 torture_result(tctx, TORTURE_FAIL, __location__": write_time changed:\n"
571 "write time conn 1 = %s, conn 2 = %s",
572 nt_time_string(tctx, finfo1.basic_info.out.write_time),
573 nt_time_string(tctx, finfo2.basic_info.out.write_time));
578 if (finfo1.basic_info.out.change_time !=
579 finfo2.basic_info.out.change_time) {
580 torture_result(tctx, TORTURE_FAIL, __location__": change_time changed");
585 /* One of the two following calls updates the qpathinfo. */
587 /* If you had skipped the smbcli_write on fnum2, it would
588 * *not* have updated the stat on disk */
590 smbcli_close(cli2->tree, fnum2);
593 /* This call is only for the people looking at ethereal :-) */
594 finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
595 finfo2.basic_info.in.file.path = fname;
597 status = smb_raw_pathinfo(cli->tree, tctx, &finfo2);
599 if (!NT_STATUS_IS_OK(status)) {
600 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", nt_errstr(status));
607 smbcli_close(cli->tree, fnum1);
608 smbcli_unlink(cli->tree, fname);
609 smbcli_deltree(cli->tree, BASEDIR);
614 #define COMPARE_WRITE_TIME_CMP(given, correct, cmp) do { \
615 NTTIME g = (given).basic_info.out.write_time; \
616 NTTIME c = (correct).basic_info.out.write_time; \
618 torture_result(tctx, TORTURE_FAIL, __location__": wrong write_time (%s)%s %s (%s)%s", \
619 #given, nt_time_string(tctx, g), \
620 #cmp, #correct, nt_time_string(tctx, c)); \
625 #define COMPARE_WRITE_TIME_EQUAL(given,correct) \
626 COMPARE_WRITE_TIME_CMP(given,correct,!=)
627 #define COMPARE_WRITE_TIME_GREATER(given,correct) \
628 COMPARE_WRITE_TIME_CMP(given,correct,<=)
629 #define COMPARE_WRITE_TIME_LESS(given,correct) \
630 COMPARE_WRITE_TIME_CMP(given,correct,>=)
632 #define COMPARE_ACCESS_TIME_CMP(given, correct, cmp) do { \
633 NTTIME g = (given).basic_info.out.access_time; \
634 NTTIME c = (correct).basic_info.out.access_time; \
636 torture_result(tctx, TORTURE_FAIL, __location__": wrong access_time (%s)%s %s (%s)%s", \
637 #given, nt_time_string(tctx, g), \
638 #cmp, #correct, nt_time_string(tctx, c)); \
643 #define COMPARE_ACCESS_TIME_EQUAL(given,correct) \
644 COMPARE_ACCESS_TIME_CMP(given,correct,!=)
645 #define COMPARE_ACCESS_TIME_GREATER(given,correct) \
646 COMPARE_ACCESS_TIME_CMP(given,correct,<=)
647 #define COMPARE_ACCESS_TIME_LESS(given,correct) \
648 COMPARE_ACCESS_TIME_CMP(given,correct,>=)
650 #define COMPARE_BOTH_TIMES_EQUAL(given,correct) do { \
651 COMPARE_ACCESS_TIME_EQUAL(given,correct); \
652 COMPARE_WRITE_TIME_EQUAL(given,correct); \
654 #define COMPARE_BOTH_TIMES_GEATER(given,correct) do { \
655 COMPARE_ACCESS_TIME_GREATER(given,correct); \
656 COMPARE_WRITE_TIME_GREATER(given,correct); \
658 #define COMPARE_BOTH_TIMES_LESS(given,correct) do { \
659 COMPARE_ACCESS_TIME_LESS(given,correct); \
660 COMPARE_WRITE_TIME_LESS(given,correct); \
663 #define GET_INFO_FILE(finfo) do { \
665 _status = smb_raw_fileinfo(cli->tree, tctx, &finfo); \
666 if (!NT_STATUS_IS_OK(_status)) { \
668 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", \
669 nt_errstr(_status)); \
672 torture_comment(tctx, "fileinfo: Access(%s) Write(%s)\n", \
673 nt_time_string(tctx, finfo.basic_info.out.access_time), \
674 nt_time_string(tctx, finfo.basic_info.out.write_time)); \
676 #define GET_INFO_PATH(pinfo) do { \
678 _status = smb_raw_pathinfo(cli2->tree, tctx, &pinfo); \
679 if (!NT_STATUS_IS_OK(_status)) { \
680 torture_result(tctx, TORTURE_FAIL, __location__": pathinfo failed: %s", \
681 nt_errstr(_status)); \
685 torture_comment(tctx, "pathinfo: Access(%s) Write(%s)\n", \
686 nt_time_string(tctx, pinfo.basic_info.out.access_time), \
687 nt_time_string(tctx, pinfo.basic_info.out.write_time)); \
689 #define GET_INFO_BOTH(finfo,pinfo) do { \
690 GET_INFO_FILE(finfo); \
691 GET_INFO_PATH(pinfo); \
692 COMPARE_BOTH_TIMES_EQUAL(finfo,pinfo); \
695 #define SET_INFO_FILE_EX(finfo, wrtime, tree, tfnum) do { \
697 union smb_setfileinfo sfinfo; \
698 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO; \
699 sfinfo.basic_info.in.file.fnum = tfnum; \
700 sfinfo.basic_info.in.create_time = 0; \
701 sfinfo.basic_info.in.access_time = 0; \
702 unix_to_nt_time(&sfinfo.basic_info.in.write_time, (wrtime)); \
703 sfinfo.basic_info.in.change_time = 0; \
704 sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib; \
705 _status = smb_raw_setfileinfo(tree, &sfinfo); \
706 if (!NT_STATUS_IS_OK(_status)) { \
707 torture_result(tctx, TORTURE_FAIL, __location__": setfileinfo failed: %s", \
708 nt_errstr(_status)); \
713 #define SET_INFO_FILE(finfo, wrtime) \
714 SET_INFO_FILE_EX(finfo, wrtime, cli->tree, fnum1)
716 static bool test_delayed_write_update3(struct torture_context *tctx,
717 struct smbcli_state *cli,
718 struct smbcli_state *cli2)
720 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4;
721 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5;
722 const char *fname = BASEDIR "\\torture_file.txt";
728 if (!torture_setup_dir(cli, BASEDIR)) {
732 torture_comment(tctx, "Open the file handle\n");
733 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
736 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
740 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
741 finfo0.basic_info.in.file.fnum = fnum1;
746 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
747 pinfo0.basic_info.in.file.path = fname;
754 /* get the initial times */
755 GET_INFO_BOTH(finfo0,pinfo0);
758 * make sure the write time is updated 2 seconds later
759 * calcuated from the first write
760 * (but expect upto 5 seconds extra time for a busy server)
763 while (time(NULL) < t+7) {
765 torture_comment(tctx, "Do a write on the file handle\n");
766 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
768 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
772 /* get the times after the write */
773 GET_INFO_FILE(finfo1);
775 if (finfo1.basic_info.out.write_time > finfo0.basic_info.out.write_time) {
776 int diff = time(NULL) - t;
778 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
784 torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n",
791 GET_INFO_BOTH(finfo1,pinfo1);
793 /* sure any further write doesn't update the write time */
795 while (time(NULL) < t+15) {
797 torture_comment(tctx, "Do a write on the file handle\n");
798 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
800 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
804 /* get the times after the write */
805 GET_INFO_BOTH(finfo2,pinfo2);
807 if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) {
808 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
809 (int)(time(NULL) - t));
816 GET_INFO_BOTH(finfo2,pinfo2);
817 COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1);
818 if (finfo2.basic_info.out.write_time == finfo1.basic_info.out.write_time) {
819 torture_comment(tctx, "Server did not update write_time (correct)\n");
825 GET_INFO_BOTH(finfo3,pinfo3);
826 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
829 * the close updates the write time to the time of the close
830 * and not to the time of the last write!
832 torture_comment(tctx, "Close the file handle\n");
833 smbcli_close(cli->tree, fnum1);
836 GET_INFO_PATH(pinfo4);
837 COMPARE_WRITE_TIME_GREATER(pinfo4, pinfo3);
839 if (pinfo4.basic_info.out.write_time > pinfo3.basic_info.out.write_time) {
840 torture_comment(tctx, "Server updated the write_time on close (correct)\n");
845 smbcli_close(cli->tree, fnum1);
846 smbcli_unlink(cli->tree, fname);
847 smbcli_deltree(cli->tree, BASEDIR);
852 static bool test_delayed_write_update4(struct torture_context *tctx,
853 struct smbcli_state *cli,
854 struct smbcli_state *cli2)
856 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4;
857 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5;
858 const char *fname = BASEDIR "\\torture_file.txt";
864 if (!torture_setup_dir(cli, BASEDIR)) {
868 torture_comment(tctx, "Open the file handle\n");
869 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
872 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
876 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
877 finfo0.basic_info.in.file.fnum = fnum1;
882 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
883 pinfo0.basic_info.in.file.path = fname;
890 /* get the initial times */
891 GET_INFO_BOTH(finfo0,pinfo0);
897 torture_comment(tctx, "Do a write on the file handle\n");
898 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
900 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
905 GET_INFO_BOTH(finfo1,pinfo1);
906 COMPARE_WRITE_TIME_EQUAL(finfo1,finfo0);
909 * make sure the write time is updated 2 seconds later
910 * calcuated from the first write
911 * (but expect upto 3 seconds extra time for a busy server)
914 while (time(NULL) < t+5) {
915 /* get the times after the first write */
916 GET_INFO_FILE(finfo1);
918 if (finfo1.basic_info.out.write_time > finfo0.basic_info.out.write_time) {
919 int diff = time(NULL) - t;
921 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
927 torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n",
934 GET_INFO_BOTH(finfo1,pinfo1);
936 /* sure any further write doesn't update the write time */
938 while (time(NULL) < t+15) {
940 torture_comment(tctx, "Do a write on the file handle\n");
941 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
943 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
947 /* get the times after the write */
948 GET_INFO_BOTH(finfo2,pinfo2);
950 if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) {
951 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
952 (int)(time(NULL) - t));
959 GET_INFO_BOTH(finfo2,pinfo2);
960 COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1);
961 if (finfo2.basic_info.out.write_time == finfo1.basic_info.out.write_time) {
962 torture_comment(tctx, "Server did not updatewrite_time (correct)\n");
968 GET_INFO_BOTH(finfo3,pinfo3);
969 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
972 * the close updates the write time to the time of the close
973 * and not to the time of the last write!
975 torture_comment(tctx, "Close the file handle\n");
976 smbcli_close(cli->tree, fnum1);
979 GET_INFO_PATH(pinfo4);
980 COMPARE_WRITE_TIME_GREATER(pinfo4, pinfo3);
982 if (pinfo4.basic_info.out.write_time > pinfo3.basic_info.out.write_time) {
983 torture_comment(tctx, "Server updated the write_time on close (correct)\n");
988 smbcli_close(cli->tree, fnum1);
989 smbcli_unlink(cli->tree, fname);
990 smbcli_deltree(cli->tree, BASEDIR);
995 static bool test_delayed_write_update5(struct torture_context *tctx,
996 struct smbcli_state *cli,
997 struct smbcli_state *cli2)
999 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5;
1000 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6;
1001 const char *fname = BASEDIR "\\torture_file.txt";
1007 if (!torture_setup_dir(cli, BASEDIR)) {
1011 torture_comment(tctx, "Open the file handle\n");
1012 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1015 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1019 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1020 finfo0.basic_info.in.file.fnum = fnum1;
1026 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1027 pinfo0.basic_info.in.file.path = fname;
1035 /* get the initial times */
1036 GET_INFO_BOTH(finfo0,pinfo0);
1039 torture_comment(tctx, "Do a write on the file handle\n");
1040 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1042 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1047 GET_INFO_BOTH(finfo1,pinfo1);
1048 COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0);
1050 torture_comment(tctx, "Set write time in the future on the file handle\n");
1051 SET_INFO_FILE(finfo0, time(NULL) + 86400);
1052 GET_INFO_BOTH(finfo2,pinfo2);
1053 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
1055 torture_comment(tctx, "Set write time in the past on the file handle\n");
1056 SET_INFO_FILE(finfo0, time(NULL) - 86400);
1057 GET_INFO_BOTH(finfo2,pinfo2);
1058 COMPARE_WRITE_TIME_LESS(finfo2, finfo1);
1060 /* make sure the 2 second delay from the first write are canceled */
1062 while (time(NULL) < t+15) {
1064 /* get the times after the first write */
1065 GET_INFO_BOTH(finfo3,pinfo3);
1067 if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) {
1068 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
1069 (int)(time(NULL) - t));
1076 GET_INFO_BOTH(finfo3,pinfo3);
1077 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
1078 if (finfo3.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1079 torture_comment(tctx, "Server did not update write_time (correct)\n");
1082 /* sure any further write doesn't update the write time */
1084 while (time(NULL) < t+15) {
1086 torture_comment(tctx, "Do a write on the file handle\n");
1087 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1089 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1093 /* get the times after the write */
1094 GET_INFO_BOTH(finfo4,pinfo4);
1096 if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) {
1097 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
1098 (int)(time(NULL) - t));
1105 GET_INFO_BOTH(finfo4,pinfo4);
1106 COMPARE_WRITE_TIME_EQUAL(finfo4, finfo3);
1107 if (finfo4.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1108 torture_comment(tctx, "Server did not update write_time (correct)\n");
1114 GET_INFO_BOTH(finfo5,pinfo5);
1115 COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4);
1118 * the close doesn't update the write time
1120 torture_comment(tctx, "Close the file handle\n");
1121 smbcli_close(cli->tree, fnum1);
1124 GET_INFO_PATH(pinfo6);
1125 COMPARE_WRITE_TIME_EQUAL(pinfo6, pinfo5);
1127 if (pinfo6.basic_info.out.write_time == pinfo5.basic_info.out.write_time) {
1128 torture_comment(tctx, "Server did not update the write_time on close (correct)\n");
1133 smbcli_close(cli->tree, fnum1);
1134 smbcli_unlink(cli->tree, fname);
1135 smbcli_deltree(cli->tree, BASEDIR);
1140 static bool test_delayed_write_update6(struct torture_context *tctx,
1141 struct smbcli_state *cli,
1142 struct smbcli_state *cli2)
1144 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5;
1145 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6, pinfo7;
1146 const char *fname = BASEDIR "\\torture_file.txt";
1154 if (!torture_setup_dir(cli, BASEDIR)) {
1158 torture_comment(tctx, "Open the file handle\n");
1159 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1162 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1167 torture_comment(tctx, "Open the 2nd file handle on 2nd connection\n");
1168 fnum2 = smbcli_open(cli2->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1171 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1176 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1177 finfo0.basic_info.in.file.fnum = fnum1;
1183 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1184 pinfo0.basic_info.in.file.path = fname;
1193 /* get the initial times */
1194 GET_INFO_BOTH(finfo0,pinfo0);
1197 torture_comment(tctx, "Do a write on the file handle\n");
1198 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1200 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1205 GET_INFO_BOTH(finfo1,pinfo1);
1206 COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0);
1208 torture_comment(tctx, "Set write time in the future on the 2nd file handle\n");
1209 SET_INFO_FILE_EX(finfo0, time(NULL) + 86400, cli2->tree, fnum2);
1210 GET_INFO_BOTH(finfo2,pinfo2);
1211 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
1213 torture_comment(tctx, "Set write time in the past on the 2nd file handle\n");
1214 SET_INFO_FILE_EX(finfo0, time(NULL) - 86400, cli2->tree, fnum2);
1215 GET_INFO_BOTH(finfo2,pinfo2);
1216 COMPARE_WRITE_TIME_LESS(finfo2, finfo1);
1218 /* make sure the 2 second delay from the first write are canceled */
1220 while (time(NULL) < t+15) {
1222 /* get the times after the first write */
1223 GET_INFO_BOTH(finfo3,pinfo3);
1225 if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) {
1226 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
1227 (int)(time(NULL) - t));
1234 GET_INFO_BOTH(finfo3,pinfo3);
1235 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
1236 if (finfo3.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1237 torture_comment(tctx, "Server did not update write_time (correct)\n");
1240 /* sure any further write doesn't update the write time */
1242 while (time(NULL) < t+15) {
1244 torture_comment(tctx, "Do a write on the file handle\n");
1245 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1247 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1251 /* get the times after the write */
1252 GET_INFO_BOTH(finfo4,pinfo4);
1254 if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) {
1255 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
1256 (int)(time(NULL) - t));
1263 GET_INFO_BOTH(finfo4,pinfo4);
1264 COMPARE_WRITE_TIME_EQUAL(finfo4, finfo3);
1265 if (finfo4.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1266 torture_comment(tctx, "Server did not update write_time (correct)\n");
1272 GET_INFO_BOTH(finfo5,pinfo5);
1273 COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4);
1276 * the close updates the write time to the time of the close
1277 * as the write time was set on the 2nd handle
1279 torture_comment(tctx, "Close the file handle\n");
1280 smbcli_close(cli->tree, fnum1);
1283 GET_INFO_PATH(pinfo6);
1284 COMPARE_WRITE_TIME_GREATER(pinfo6, pinfo5);
1286 if (pinfo6.basic_info.out.write_time > pinfo5.basic_info.out.write_time) {
1287 torture_comment(tctx, "Server updated the write_time on close (correct)\n");
1290 /* keep the 2nd handle open and rerun tests */
1297 * closing the 2nd handle will cause no write time update
1298 * as the write time was explicit set on this handle
1300 torture_comment(tctx, "Close the 2nd file handle\n");
1301 smbcli_close(cli2->tree, fnum2);
1304 GET_INFO_PATH(pinfo7);
1305 COMPARE_WRITE_TIME_EQUAL(pinfo7, pinfo6);
1307 if (pinfo7.basic_info.out.write_time == pinfo6.basic_info.out.write_time) {
1308 torture_comment(tctx, "Server did not update the write_time on close (correct)\n");
1313 smbcli_close(cli->tree, fnum1);
1315 smbcli_close(cli2->tree, fnum2);
1316 smbcli_unlink(cli->tree, fname);
1317 smbcli_deltree(cli->tree, BASEDIR);
1324 testing of delayed update of write_time
1326 struct torture_suite *torture_delay_write(void)
1328 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "DELAYWRITE");
1330 torture_suite_add_2smb_test(suite, "finfo update on close", test_finfo_after_write);
1331 torture_suite_add_1smb_test(suite, "delayed update of write time", test_delayed_write_update);
1332 torture_suite_add_2smb_test(suite, "delayed update of write time using 2 connections", test_delayed_write_update2);
1333 torture_suite_add_2smb_test(suite, "delayed update of write time 3", test_delayed_write_update3);
1334 torture_suite_add_2smb_test(suite, "delayed update of write time 4", test_delayed_write_update4);
1335 torture_suite_add_2smb_test(suite, "delayed update of write time 5", test_delayed_write_update5);
1336 torture_suite_add_2smb_test(suite, "delayed update of write time 6", test_delayed_write_update6);