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 GET_INFO_FILE(finfo) do { \
634 _status = smb_raw_fileinfo(cli->tree, tctx, &finfo); \
635 if (!NT_STATUS_IS_OK(_status)) { \
637 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", \
638 nt_errstr(_status)); \
641 torture_comment(tctx, "fileinfo: Write time (%s)\n", \
642 nt_time_string(tctx, finfo.basic_info.out.write_time)); \
644 #define GET_INFO_PATH(pinfo) do { \
646 _status = smb_raw_pathinfo(cli2->tree, tctx, &pinfo); \
647 if (!NT_STATUS_IS_OK(_status)) { \
648 torture_result(tctx, TORTURE_FAIL, __location__": pathinfo failed: %s", \
649 nt_errstr(_status)); \
653 torture_comment(tctx, "pathinfo: Write time (%s)\n", \
654 nt_time_string(tctx, pinfo.basic_info.out.write_time)); \
656 #define GET_INFO_BOTH(finfo,pinfo) do { \
657 GET_INFO_FILE(finfo); \
658 GET_INFO_PATH(pinfo); \
659 COMPARE_WRITE_TIME_EQUAL(finfo,pinfo); \
662 #define SET_INFO_FILE_EX(finfo, wrtime, tree, tfnum) do { \
664 union smb_setfileinfo sfinfo; \
665 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO; \
666 sfinfo.basic_info.in.file.fnum = tfnum; \
667 sfinfo.basic_info.in.create_time = (finfo).basic_info.out.create_time; \
668 sfinfo.basic_info.in.access_time = (finfo).basic_info.out.access_time; \
669 unix_to_nt_time(&sfinfo.basic_info.in.write_time, (wrtime)); \
670 sfinfo.basic_info.in.change_time = finfo1.basic_info.out.change_time; \
671 sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib; \
672 _status = smb_raw_setfileinfo(tree, &sfinfo); \
673 if (!NT_STATUS_IS_OK(_status)) { \
674 torture_result(tctx, TORTURE_FAIL, __location__": setfileinfo failed: %s", \
675 nt_errstr(_status)); \
680 #define SET_INFO_FILE(finfo, wrtime) \
681 SET_INFO_FILE_EX(finfo, wrtime, cli->tree, fnum1)
683 static bool test_delayed_write_update3(struct torture_context *tctx,
684 struct smbcli_state *cli,
685 struct smbcli_state *cli2)
687 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4;
688 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5;
689 const char *fname = BASEDIR "\\torture_file.txt";
695 if (!torture_setup_dir(cli, BASEDIR)) {
699 torture_comment(tctx, "Open the file handle\n");
700 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
703 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
707 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
708 finfo0.basic_info.in.file.fnum = fnum1;
713 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
714 pinfo0.basic_info.in.file.path = fname;
721 /* get the initial times */
722 GET_INFO_BOTH(finfo0,pinfo0);
725 * make sure the write time is updated 2 seconds later
726 * calcuated from the first write
727 * (but expect upto 5 seconds extra time for a busy server)
730 while (time(NULL) < t+7) {
732 torture_comment(tctx, "Do a write on the file handle\n");
733 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
735 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
739 /* get the times after the write */
740 GET_INFO_FILE(finfo1);
742 if (finfo1.basic_info.out.write_time > finfo0.basic_info.out.write_time) {
743 int diff = time(NULL) - t;
745 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
751 torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n",
758 GET_INFO_BOTH(finfo1,pinfo1);
760 /* sure any further write doesn't update the write time */
762 while (time(NULL) < t+15) {
764 torture_comment(tctx, "Do a write on the file handle\n");
765 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
767 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
771 /* get the times after the write */
772 GET_INFO_BOTH(finfo2,pinfo2);
774 if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) {
775 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
776 (int)(time(NULL) - t));
783 GET_INFO_BOTH(finfo2,pinfo2);
784 COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1);
785 if (finfo2.basic_info.out.write_time == finfo1.basic_info.out.write_time) {
786 torture_comment(tctx, "Server did not update write_time (correct)\n");
792 GET_INFO_BOTH(finfo3,pinfo3);
793 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
796 * the close updates the write time to the time of the close
797 * and not to the time of the last write!
799 torture_comment(tctx, "Close the file handle\n");
800 smbcli_close(cli->tree, fnum1);
803 GET_INFO_PATH(pinfo4);
804 COMPARE_WRITE_TIME_GREATER(pinfo4, pinfo3);
806 if (pinfo4.basic_info.out.write_time > pinfo3.basic_info.out.write_time) {
807 torture_comment(tctx, "Server updated the write_time on close (correct)\n");
812 smbcli_close(cli->tree, fnum1);
813 smbcli_unlink(cli->tree, fname);
814 smbcli_deltree(cli->tree, BASEDIR);
819 static bool test_delayed_write_update4(struct torture_context *tctx,
820 struct smbcli_state *cli,
821 struct smbcli_state *cli2)
823 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4;
824 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5;
825 const char *fname = BASEDIR "\\torture_file.txt";
831 if (!torture_setup_dir(cli, BASEDIR)) {
835 torture_comment(tctx, "Open the file handle\n");
836 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
839 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
843 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
844 finfo0.basic_info.in.file.fnum = fnum1;
849 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
850 pinfo0.basic_info.in.file.path = fname;
857 /* get the initial times */
858 GET_INFO_BOTH(finfo0,pinfo0);
864 torture_comment(tctx, "Do a write on the file handle\n");
865 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
867 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
872 GET_INFO_BOTH(finfo1,pinfo1);
873 COMPARE_WRITE_TIME_EQUAL(finfo1,finfo0);
876 * make sure the write time is updated 2 seconds later
877 * calcuated from the first write
878 * (but expect upto 3 seconds extra time for a busy server)
881 while (time(NULL) < t+5) {
882 /* get the times after the first write */
883 GET_INFO_FILE(finfo1);
885 if (finfo1.basic_info.out.write_time > finfo0.basic_info.out.write_time) {
886 int diff = time(NULL) - t;
888 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
894 torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n",
901 GET_INFO_BOTH(finfo1,pinfo1);
903 /* sure any further write doesn't update the write time */
905 while (time(NULL) < t+15) {
907 torture_comment(tctx, "Do a write on the file handle\n");
908 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
910 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
914 /* get the times after the write */
915 GET_INFO_BOTH(finfo2,pinfo2);
917 if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) {
918 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
919 (int)(time(NULL) - t));
926 GET_INFO_BOTH(finfo2,pinfo2);
927 COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1);
928 if (finfo2.basic_info.out.write_time == finfo1.basic_info.out.write_time) {
929 torture_comment(tctx, "Server did not updatewrite_time (correct)\n");
935 GET_INFO_BOTH(finfo3,pinfo3);
936 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
939 * the close updates the write time to the time of the close
940 * and not to the time of the last write!
942 torture_comment(tctx, "Close the file handle\n");
943 smbcli_close(cli->tree, fnum1);
946 GET_INFO_PATH(pinfo4);
947 COMPARE_WRITE_TIME_GREATER(pinfo4, pinfo3);
949 if (pinfo4.basic_info.out.write_time > pinfo3.basic_info.out.write_time) {
950 torture_comment(tctx, "Server updated the write_time on close (correct)\n");
955 smbcli_close(cli->tree, fnum1);
956 smbcli_unlink(cli->tree, fname);
957 smbcli_deltree(cli->tree, BASEDIR);
962 static bool test_delayed_write_update5(struct torture_context *tctx,
963 struct smbcli_state *cli,
964 struct smbcli_state *cli2)
966 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5;
967 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6;
968 const char *fname = BASEDIR "\\torture_file.txt";
974 if (!torture_setup_dir(cli, BASEDIR)) {
978 torture_comment(tctx, "Open the file handle\n");
979 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
982 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
986 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
987 finfo0.basic_info.in.file.fnum = fnum1;
993 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
994 pinfo0.basic_info.in.file.path = fname;
1002 /* get the initial times */
1003 GET_INFO_BOTH(finfo0,pinfo0);
1006 torture_comment(tctx, "Do a write on the file handle\n");
1007 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1009 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1014 GET_INFO_BOTH(finfo1,pinfo1);
1015 COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0);
1017 torture_comment(tctx, "Set write time in the future on the file handle\n");
1018 SET_INFO_FILE(finfo0, time(NULL) + 86400);
1019 GET_INFO_BOTH(finfo2,pinfo2);
1020 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
1022 torture_comment(tctx, "Set write time in the past on the file handle\n");
1023 SET_INFO_FILE(finfo0, time(NULL) - 86400);
1024 GET_INFO_BOTH(finfo2,pinfo2);
1025 COMPARE_WRITE_TIME_LESS(finfo2, finfo1);
1027 /* make sure the 2 second delay from the first write are canceled */
1029 while (time(NULL) < t+15) {
1031 /* get the times after the first write */
1032 GET_INFO_BOTH(finfo3,pinfo3);
1034 if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) {
1035 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
1036 (int)(time(NULL) - t));
1043 GET_INFO_BOTH(finfo3,pinfo3);
1044 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
1045 if (finfo3.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1046 torture_comment(tctx, "Server did not update write_time (correct)\n");
1049 /* sure any further write doesn't update the write time */
1051 while (time(NULL) < t+15) {
1053 torture_comment(tctx, "Do a write on the file handle\n");
1054 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1056 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1060 /* get the times after the write */
1061 GET_INFO_BOTH(finfo4,pinfo4);
1063 if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) {
1064 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
1065 (int)(time(NULL) - t));
1072 GET_INFO_BOTH(finfo4,pinfo4);
1073 COMPARE_WRITE_TIME_EQUAL(finfo4, finfo3);
1074 if (finfo4.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1075 torture_comment(tctx, "Server did not update write_time (correct)\n");
1081 GET_INFO_BOTH(finfo5,pinfo5);
1082 COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4);
1085 * the close doesn't update the write time
1087 torture_comment(tctx, "Close the file handle\n");
1088 smbcli_close(cli->tree, fnum1);
1091 GET_INFO_PATH(pinfo6);
1092 COMPARE_WRITE_TIME_EQUAL(pinfo6, pinfo5);
1094 if (pinfo6.basic_info.out.write_time == pinfo5.basic_info.out.write_time) {
1095 torture_comment(tctx, "Server did not update the write_time on close (correct)\n");
1100 smbcli_close(cli->tree, fnum1);
1101 smbcli_unlink(cli->tree, fname);
1102 smbcli_deltree(cli->tree, BASEDIR);
1107 static bool test_delayed_write_update6(struct torture_context *tctx,
1108 struct smbcli_state *cli,
1109 struct smbcli_state *cli2)
1111 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5;
1112 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6, pinfo7;
1113 const char *fname = BASEDIR "\\torture_file.txt";
1121 if (!torture_setup_dir(cli, BASEDIR)) {
1125 torture_comment(tctx, "Open the file handle\n");
1126 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1129 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1134 torture_comment(tctx, "Open the 2nd file handle on 2nd connection\n");
1135 fnum2 = smbcli_open(cli2->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1138 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1143 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1144 finfo0.basic_info.in.file.fnum = fnum1;
1150 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1151 pinfo0.basic_info.in.file.path = fname;
1160 /* get the initial times */
1161 GET_INFO_BOTH(finfo0,pinfo0);
1164 torture_comment(tctx, "Do a write on the file handle\n");
1165 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1167 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1172 GET_INFO_BOTH(finfo1,pinfo1);
1173 COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0);
1175 torture_comment(tctx, "Set write time in the future on the 2nd file handle\n");
1176 SET_INFO_FILE_EX(finfo0, time(NULL) + 86400, cli2->tree, fnum2);
1177 GET_INFO_BOTH(finfo2,pinfo2);
1178 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
1180 torture_comment(tctx, "Set write time in the past on the 2nd file handle\n");
1181 SET_INFO_FILE_EX(finfo0, time(NULL) - 86400, cli2->tree, fnum2);
1182 GET_INFO_BOTH(finfo2,pinfo2);
1183 COMPARE_WRITE_TIME_LESS(finfo2, finfo1);
1185 /* make sure the 2 second delay from the first write are canceled */
1187 while (time(NULL) < t+15) {
1189 /* get the times after the first write */
1190 GET_INFO_BOTH(finfo3,pinfo3);
1192 if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) {
1193 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
1194 (int)(time(NULL) - t));
1201 GET_INFO_BOTH(finfo3,pinfo3);
1202 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
1203 if (finfo3.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1204 torture_comment(tctx, "Server did not update write_time (correct)\n");
1207 /* sure any further write doesn't update the write time */
1209 while (time(NULL) < t+15) {
1211 torture_comment(tctx, "Do a write on the file handle\n");
1212 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1214 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1218 /* get the times after the write */
1219 GET_INFO_BOTH(finfo4,pinfo4);
1221 if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) {
1222 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
1223 (int)(time(NULL) - t));
1230 GET_INFO_BOTH(finfo4,pinfo4);
1231 COMPARE_WRITE_TIME_EQUAL(finfo4, finfo3);
1232 if (finfo4.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1233 torture_comment(tctx, "Server did not update write_time (correct)\n");
1239 GET_INFO_BOTH(finfo5,pinfo5);
1240 COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4);
1243 * the close updates the write time to the time of the close
1244 * as the write time was set on the 2nd handle
1246 torture_comment(tctx, "Close the file handle\n");
1247 smbcli_close(cli->tree, fnum1);
1250 GET_INFO_PATH(pinfo6);
1251 COMPARE_WRITE_TIME_GREATER(pinfo6, pinfo5);
1253 if (pinfo6.basic_info.out.write_time > pinfo5.basic_info.out.write_time) {
1254 torture_comment(tctx, "Server updated the write_time on close (correct)\n");
1257 /* keep the 2nd handle open and rerun tests */
1264 * closing the 2nd handle will cause no write time update
1265 * as the write time was explicit set on this handle
1267 torture_comment(tctx, "Close the 2nd file handle\n");
1268 smbcli_close(cli2->tree, fnum2);
1271 GET_INFO_PATH(pinfo7);
1272 COMPARE_WRITE_TIME_EQUAL(pinfo7, pinfo6);
1274 if (pinfo7.basic_info.out.write_time == pinfo6.basic_info.out.write_time) {
1275 torture_comment(tctx, "Server did not update the write_time on close (correct)\n");
1280 smbcli_close(cli->tree, fnum1);
1282 smbcli_close(cli2->tree, fnum2);
1283 smbcli_unlink(cli->tree, fname);
1284 smbcli_deltree(cli->tree, BASEDIR);
1291 testing of delayed update of write_time
1293 struct torture_suite *torture_delay_write(void)
1295 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "DELAYWRITE");
1297 torture_suite_add_2smb_test(suite, "finfo update on close", test_finfo_after_write);
1298 torture_suite_add_1smb_test(suite, "delayed update of write time", test_delayed_write_update);
1299 torture_suite_add_2smb_test(suite, "delayed update of write time using 2 connections", test_delayed_write_update2);
1300 torture_suite_add_2smb_test(suite, "delayed update of write time 3", test_delayed_write_update3);
1301 torture_suite_add_2smb_test(suite, "delayed update of write time 4", test_delayed_write_update4);
1302 torture_suite_add_2smb_test(suite, "delayed update of write time 5", test_delayed_write_update5);
1303 torture_suite_add_2smb_test(suite, "delayed update of write time 6", test_delayed_write_update6);