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 if (!torture_setup_dir(cli, BASEDIR)) {
49 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
51 torture_comment(tctx, "Failed to open %s\n", fname);
55 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
56 finfo1.basic_info.in.file.fnum = fnum1;
59 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
61 if (!NT_STATUS_IS_OK(status)) {
62 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
66 torture_comment(tctx, "Initial write time %s\n",
67 nt_time_string(tctx, finfo1.basic_info.out.write_time));
69 /* 3 second delay to ensure we get past any 2 second time
70 granularity (older systems may have that) */
73 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
76 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
77 (int)written, __location__);
83 while (time(NULL) < t+120) {
84 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
86 if (!NT_STATUS_IS_OK(status)) {
87 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
91 torture_comment(tctx, "write time %s\n",
92 nt_time_string(tctx, finfo2.basic_info.out.write_time));
93 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
94 int diff = time(NULL) - t;
96 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
102 torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n",
110 if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
111 torture_comment(tctx, "Server did not update write time (wrong!)\n");
117 smbcli_close(cli->tree, fnum1);
118 smbcli_unlink(cli->tree, fname);
119 smbcli_deltree(cli->tree, BASEDIR);
125 * Do as above, but using 2 connections.
128 static bool test_delayed_write_update2(struct torture_context *tctx, struct smbcli_state *cli,
129 struct smbcli_state *cli2)
131 union smb_fileinfo finfo1, finfo2;
132 const char *fname = BASEDIR "\\torture_file.txt";
139 union smb_flush flsh;
141 if (!torture_setup_dir(cli, BASEDIR)) {
145 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
147 torture_comment(tctx, "Failed to open %s\n", fname);
151 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
152 finfo1.basic_info.in.file.fnum = fnum1;
155 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
157 if (!NT_STATUS_IS_OK(status)) {
158 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
162 torture_comment(tctx, "Initial write time %s\n",
163 nt_time_string(tctx, finfo1.basic_info.out.write_time));
165 /* 3 second delay to ensure we get past any 2 second time
166 granularity (older systems may have that) */
170 /* Try using setfileinfo instead of write to update write time. */
171 union smb_setfileinfo sfinfo;
172 time_t t_set = time(NULL);
173 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO;
174 sfinfo.basic_info.in.file.fnum = fnum1;
175 sfinfo.basic_info.in.create_time = finfo1.basic_info.out.create_time;
176 sfinfo.basic_info.in.access_time = finfo1.basic_info.out.access_time;
178 /* I tried this with both + and - ve to see if it makes a different.
179 It doesn't - once the filetime is set via setfileinfo it stays that way. */
181 unix_to_nt_time(&sfinfo.basic_info.in.write_time, t_set - 30000);
183 unix_to_nt_time(&sfinfo.basic_info.in.write_time, t_set + 30000);
185 sfinfo.basic_info.in.change_time = finfo1.basic_info.out.change_time;
186 sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib;
188 status = smb_raw_setfileinfo(cli->tree, &sfinfo);
190 if (!NT_STATUS_IS_OK(status)) {
191 DEBUG(0, ("sfileinfo failed: %s\n", nt_errstr(status)));
196 finfo2.basic_info.in.file.path = fname;
198 status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2);
200 if (!NT_STATUS_IS_OK(status)) {
201 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
204 torture_comment(tctx, "write time %s\n",
205 nt_time_string(tctx, finfo2.basic_info.out.write_time));
207 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
208 torture_comment(tctx, "Server updated write_time (correct)\n");
210 torture_comment(tctx, "Server did not update write time (wrong!)\n");
214 /* Now try a write to see if the write time gets reset. */
216 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
217 finfo1.basic_info.in.file.fnum = fnum1;
220 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
222 if (!NT_STATUS_IS_OK(status)) {
223 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
227 torture_comment(tctx, "Modified write time %s\n",
228 nt_time_string(tctx, finfo1.basic_info.out.write_time));
231 torture_comment(tctx, "Doing a 10 byte write to extend the file and see if this changes the last write time.\n");
233 written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 1, 10);
236 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
237 (int)written, __location__);
241 /* Just to prove to tridge that the an smbflush has no effect on
242 the write time :-). The setfileinfo IS STICKY. JRA. */
244 torture_comment(tctx, "Doing flush after write\n");
246 flsh.flush.level = RAW_FLUSH_FLUSH;
247 flsh.flush.in.file.fnum = fnum1;
248 status = smb_raw_flush(cli->tree, &flsh);
249 if (!NT_STATUS_IS_OK(status)) {
250 DEBUG(0, ("smbflush failed: %s\n", nt_errstr(status)));
256 /* Once the time was set using setfileinfo then it stays set - writes
257 don't have any effect. But make sure. */
259 while (time(NULL) < t+15) {
260 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
262 if (!NT_STATUS_IS_OK(status)) {
263 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
267 torture_comment(tctx, "write time %s\n",
268 nt_time_string(tctx, finfo2.basic_info.out.write_time));
269 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
270 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
271 (int)(time(NULL) - t));
279 if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
280 torture_comment(tctx, "Server did not update write time (correct)\n");
283 fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
285 torture_comment(tctx, "Failed to open %s\n", fname);
289 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");
291 written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 11, 10);
294 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
295 (int)written, __location__);
299 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
301 if (!NT_STATUS_IS_OK(status)) {
302 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
305 torture_comment(tctx, "write time %s\n",
306 nt_time_string(tctx, finfo2.basic_info.out.write_time));
307 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
308 torture_comment(tctx, "Server updated write_time (wrong!)\n");
312 torture_comment(tctx, "Closing the first fd to see if write time updated.\n");
313 smbcli_close(cli->tree, fnum1);
316 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");
318 written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 21, 10);
321 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
322 (int)written, __location__);
326 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
327 finfo1.basic_info.in.file.fnum = fnum2;
329 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
331 if (!NT_STATUS_IS_OK(status)) {
332 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
335 torture_comment(tctx, "write time %s\n",
336 nt_time_string(tctx, finfo2.basic_info.out.write_time));
337 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
338 torture_comment(tctx, "Server updated write_time (wrong!)\n");
344 /* Once the time was set using setfileinfo then it stays set - writes
345 don't have any effect. But make sure. */
347 while (time(NULL) < t+15) {
348 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
350 if (!NT_STATUS_IS_OK(status)) {
351 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
355 torture_comment(tctx, "write time %s\n",
356 nt_time_string(tctx, finfo2.basic_info.out.write_time));
357 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
358 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
359 (int)(time(NULL) - t));
367 if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
368 torture_comment(tctx, "Server did not update write time (correct)\n");
371 torture_comment(tctx, "Closing second fd to see if write time updated.\n");
373 smbcli_close(cli->tree, fnum2);
376 fnum1 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
378 torture_comment(tctx, "Failed to open %s\n", fname);
382 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
383 finfo1.basic_info.in.file.fnum = fnum1;
386 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
388 if (!NT_STATUS_IS_OK(status)) {
389 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
393 torture_comment(tctx, "Second open initial write time %s\n",
394 nt_time_string(tctx, finfo1.basic_info.out.write_time));
397 torture_comment(tctx, "Doing a 10 byte write to extend the file to see if this changes the last write time.\n");
399 written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 31, 10);
402 torture_comment(tctx, "write failed - wrote %d bytes (%s)\n",
403 (int)written, __location__);
407 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
408 finfo1.basic_info.in.file.fnum = fnum1;
410 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
412 if (!NT_STATUS_IS_OK(status)) {
413 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
416 torture_comment(tctx, "write time %s\n",
417 nt_time_string(tctx, finfo2.basic_info.out.write_time));
418 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
419 torture_comment(tctx, "Server updated write_time (wrong!)\n");
425 /* Now the write time should be updated again */
427 while (time(NULL) < t+15) {
428 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
430 if (!NT_STATUS_IS_OK(status)) {
431 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
435 torture_comment(tctx, "write time %s\n",
436 nt_time_string(tctx, finfo2.basic_info.out.write_time));
437 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
438 int diff = time(NULL) - t;
440 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
446 torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n",
454 if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
455 torture_comment(tctx, "Server did not update write time (wrong!)\n");
460 /* One more test to do. We should read the filetime via findfirst on the
461 second connection to ensure it's the same. This is very easy for a Windows
462 server but a bastard to get right on a POSIX server. JRA. */
465 smbcli_close(cli->tree, fnum1);
466 smbcli_unlink(cli->tree, fname);
467 smbcli_deltree(cli->tree, BASEDIR);
473 /* Windows does obviously not update the stat info during a write call. I
474 * *think* this is the problem causing a spurious Excel 2003 on XP error
475 * message when saving a file. Excel does a setfileinfo, writes, and then does
476 * a getpath(!)info. Or so... For Samba sometimes it displays an error message
477 * that the file might have been changed in between. What i've been able to
478 * trace down is that this happens if the getpathinfo after the write shows a
479 * different last write time than the setfileinfo showed. This is really
483 static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_state *cli,
484 struct smbcli_state *cli2)
486 union smb_fileinfo finfo1, finfo2;
487 const char *fname = BASEDIR "\\torture_file.txt";
494 if (!torture_setup_dir(cli, BASEDIR)) {
498 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
501 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
505 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
506 finfo1.basic_info.in.file.fnum = fnum1;
508 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
510 if (!NT_STATUS_IS_OK(status)) {
512 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", nt_errstr(status));
518 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
521 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
526 fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE);
528 torture_result(tctx, TORTURE_FAIL, __location__": failed to open 2nd time - %s",
529 smbcli_errstr(cli2->tree));
534 written = smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1);
537 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1",
543 finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
544 finfo2.basic_info.in.file.path = fname;
546 status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2);
548 if (!NT_STATUS_IS_OK(status)) {
549 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s",
555 if (finfo1.basic_info.out.create_time !=
556 finfo2.basic_info.out.create_time) {
557 torture_result(tctx, TORTURE_FAIL, __location__": create_time changed");
562 if (finfo1.basic_info.out.access_time !=
563 finfo2.basic_info.out.access_time) {
564 torture_result(tctx, TORTURE_FAIL, __location__": access_time changed");
569 if (finfo1.basic_info.out.write_time !=
570 finfo2.basic_info.out.write_time) {
571 torture_result(tctx, TORTURE_FAIL, __location__": write_time changed:\n"
572 "write time conn 1 = %s, conn 2 = %s",
573 nt_time_string(tctx, finfo1.basic_info.out.write_time),
574 nt_time_string(tctx, finfo2.basic_info.out.write_time));
579 if (finfo1.basic_info.out.change_time !=
580 finfo2.basic_info.out.change_time) {
581 torture_result(tctx, TORTURE_FAIL, __location__": change_time changed");
586 /* One of the two following calls updates the qpathinfo. */
588 /* If you had skipped the smbcli_write on fnum2, it would
589 * *not* have updated the stat on disk */
591 smbcli_close(cli2->tree, fnum2);
594 /* This call is only for the people looking at ethereal :-) */
595 finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
596 finfo2.basic_info.in.file.path = fname;
598 status = smb_raw_pathinfo(cli->tree, tctx, &finfo2);
600 if (!NT_STATUS_IS_OK(status)) {
601 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", nt_errstr(status));
608 smbcli_close(cli->tree, fnum1);
609 smbcli_unlink(cli->tree, fname);
610 smbcli_deltree(cli->tree, BASEDIR);
615 #define COMPARE_WRITE_TIME_CMP(given, correct, cmp) do { \
616 NTTIME g = (given).basic_info.out.write_time; \
617 NTTIME c = (correct).basic_info.out.write_time; \
619 torture_result(tctx, TORTURE_FAIL, __location__": wrong write_time (%s)%s %s (%s)%s", \
620 #given, nt_time_string(tctx, g), \
621 #cmp, #correct, nt_time_string(tctx, c)); \
626 #define COMPARE_WRITE_TIME_EQUAL(given,correct) \
627 COMPARE_WRITE_TIME_CMP(given,correct,!=)
628 #define COMPARE_WRITE_TIME_GREATER(given,correct) \
629 COMPARE_WRITE_TIME_CMP(given,correct,<=)
630 #define COMPARE_WRITE_TIME_LESS(given,correct) \
631 COMPARE_WRITE_TIME_CMP(given,correct,>=)
633 #define COMPARE_ACCESS_TIME_CMP(given, correct, cmp) do { \
634 NTTIME g = (given).basic_info.out.access_time; \
635 NTTIME c = (correct).basic_info.out.access_time; \
637 torture_result(tctx, TORTURE_FAIL, __location__": wrong access_time (%s)%s %s (%s)%s", \
638 #given, nt_time_string(tctx, g), \
639 #cmp, #correct, nt_time_string(tctx, c)); \
644 #define COMPARE_ACCESS_TIME_EQUAL(given,correct) \
645 COMPARE_ACCESS_TIME_CMP(given,correct,!=)
646 #define COMPARE_ACCESS_TIME_GREATER(given,correct) \
647 COMPARE_ACCESS_TIME_CMP(given,correct,<=)
648 #define COMPARE_ACCESS_TIME_LESS(given,correct) \
649 COMPARE_ACCESS_TIME_CMP(given,correct,>=)
651 #define COMPARE_BOTH_TIMES_EQUAL(given,correct) do { \
652 COMPARE_ACCESS_TIME_EQUAL(given,correct); \
653 COMPARE_WRITE_TIME_EQUAL(given,correct); \
655 #define COMPARE_BOTH_TIMES_GEATER(given,correct) do { \
656 COMPARE_ACCESS_TIME_GREATER(given,correct); \
657 COMPARE_WRITE_TIME_GREATER(given,correct); \
659 #define COMPARE_BOTH_TIMES_LESS(given,correct) do { \
660 COMPARE_ACCESS_TIME_LESS(given,correct); \
661 COMPARE_WRITE_TIME_LESS(given,correct); \
664 #define GET_INFO_FILE(finfo) do { \
666 _status = smb_raw_fileinfo(cli->tree, tctx, &finfo); \
667 if (!NT_STATUS_IS_OK(_status)) { \
669 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", \
670 nt_errstr(_status)); \
673 torture_comment(tctx, "fileinfo: Access(%s) Write(%s)\n", \
674 nt_time_string(tctx, finfo.basic_info.out.access_time), \
675 nt_time_string(tctx, finfo.basic_info.out.write_time)); \
677 #define GET_INFO_PATH(pinfo) do { \
679 _status = smb_raw_pathinfo(cli2->tree, tctx, &pinfo); \
680 if (!NT_STATUS_IS_OK(_status)) { \
681 torture_result(tctx, TORTURE_FAIL, __location__": pathinfo failed: %s", \
682 nt_errstr(_status)); \
686 torture_comment(tctx, "pathinfo: Access(%s) Write(%s)\n", \
687 nt_time_string(tctx, pinfo.basic_info.out.access_time), \
688 nt_time_string(tctx, pinfo.basic_info.out.write_time)); \
690 #define GET_INFO_BOTH(finfo,pinfo) do { \
691 GET_INFO_FILE(finfo); \
692 GET_INFO_PATH(pinfo); \
693 COMPARE_BOTH_TIMES_EQUAL(finfo,pinfo); \
696 #define SET_INFO_FILE_EX(finfo, wrtime, tree, tfnum) do { \
698 union smb_setfileinfo sfinfo; \
699 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO; \
700 sfinfo.basic_info.in.file.fnum = tfnum; \
701 sfinfo.basic_info.in.create_time = 0; \
702 sfinfo.basic_info.in.access_time = 0; \
703 unix_to_nt_time(&sfinfo.basic_info.in.write_time, (wrtime)); \
704 sfinfo.basic_info.in.change_time = 0; \
705 sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib; \
706 _status = smb_raw_setfileinfo(tree, &sfinfo); \
707 if (!NT_STATUS_IS_OK(_status)) { \
708 torture_result(tctx, TORTURE_FAIL, __location__": setfileinfo failed: %s", \
709 nt_errstr(_status)); \
714 #define SET_INFO_FILE(finfo, wrtime) \
715 SET_INFO_FILE_EX(finfo, wrtime, cli->tree, fnum1)
717 static bool test_delayed_write_update3(struct torture_context *tctx,
718 struct smbcli_state *cli,
719 struct smbcli_state *cli2)
721 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4;
722 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5;
723 const char *fname = BASEDIR "\\torture_file.txt";
729 if (!torture_setup_dir(cli, BASEDIR)) {
733 torture_comment(tctx, "Open the file handle\n");
734 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
737 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
741 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
742 finfo0.basic_info.in.file.fnum = fnum1;
747 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
748 pinfo0.basic_info.in.file.path = fname;
755 /* get the initial times */
756 GET_INFO_BOTH(finfo0,pinfo0);
759 * make sure the write time is updated 2 seconds later
760 * calcuated from the first write
761 * (but expect upto 5 seconds extra time for a busy server)
764 while (time(NULL) < t+7) {
766 torture_comment(tctx, "Do a write on the file handle\n");
767 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
769 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
773 /* get the times after the write */
774 GET_INFO_FILE(finfo1);
776 if (finfo1.basic_info.out.write_time > finfo0.basic_info.out.write_time) {
777 int diff = time(NULL) - t;
779 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
785 torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n",
792 GET_INFO_BOTH(finfo1,pinfo1);
794 /* sure any further write doesn't update the write time */
796 while (time(NULL) < t+15) {
798 torture_comment(tctx, "Do a write on the file handle\n");
799 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
801 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
805 /* get the times after the write */
806 GET_INFO_BOTH(finfo2,pinfo2);
808 if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) {
809 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
810 (int)(time(NULL) - t));
817 GET_INFO_BOTH(finfo2,pinfo2);
818 COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1);
819 if (finfo2.basic_info.out.write_time == finfo1.basic_info.out.write_time) {
820 torture_comment(tctx, "Server did not update write_time (correct)\n");
826 GET_INFO_BOTH(finfo3,pinfo3);
827 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
830 * the close updates the write time to the time of the close
831 * and not to the time of the last write!
833 torture_comment(tctx, "Close the file handle\n");
834 smbcli_close(cli->tree, fnum1);
837 GET_INFO_PATH(pinfo4);
838 COMPARE_WRITE_TIME_GREATER(pinfo4, pinfo3);
840 if (pinfo4.basic_info.out.write_time > pinfo3.basic_info.out.write_time) {
841 torture_comment(tctx, "Server updated the write_time on close (correct)\n");
846 smbcli_close(cli->tree, fnum1);
847 smbcli_unlink(cli->tree, fname);
848 smbcli_deltree(cli->tree, BASEDIR);
853 static bool test_delayed_write_update4(struct torture_context *tctx,
854 struct smbcli_state *cli,
855 struct smbcli_state *cli2)
857 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4;
858 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5;
859 const char *fname = BASEDIR "\\torture_file.txt";
865 if (!torture_setup_dir(cli, BASEDIR)) {
869 torture_comment(tctx, "Open the file handle\n");
870 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
873 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
877 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
878 finfo0.basic_info.in.file.fnum = fnum1;
883 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
884 pinfo0.basic_info.in.file.path = fname;
891 /* get the initial times */
892 GET_INFO_BOTH(finfo0,pinfo0);
898 torture_comment(tctx, "Do a write on the file handle\n");
899 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
901 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
906 GET_INFO_BOTH(finfo1,pinfo1);
907 COMPARE_WRITE_TIME_EQUAL(finfo1,finfo0);
910 * make sure the write time is updated 2 seconds later
911 * calcuated from the first write
912 * (but expect upto 3 seconds extra time for a busy server)
915 while (time(NULL) < t+5) {
916 /* get the times after the first write */
917 GET_INFO_FILE(finfo1);
919 if (finfo1.basic_info.out.write_time > finfo0.basic_info.out.write_time) {
920 int diff = time(NULL) - t;
922 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
928 torture_comment(tctx, "Server updated write_time after %d seconds (correct)\n",
935 GET_INFO_BOTH(finfo1,pinfo1);
937 /* sure any further write doesn't update the write time */
939 while (time(NULL) < t+15) {
941 torture_comment(tctx, "Do a write on the file handle\n");
942 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
944 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
948 /* get the times after the write */
949 GET_INFO_BOTH(finfo2,pinfo2);
951 if (finfo2.basic_info.out.write_time > finfo1.basic_info.out.write_time) {
952 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
953 (int)(time(NULL) - t));
960 GET_INFO_BOTH(finfo2,pinfo2);
961 COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1);
962 if (finfo2.basic_info.out.write_time == finfo1.basic_info.out.write_time) {
963 torture_comment(tctx, "Server did not updatewrite_time (correct)\n");
969 GET_INFO_BOTH(finfo3,pinfo3);
970 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
973 * the close updates the write time to the time of the close
974 * and not to the time of the last write!
976 torture_comment(tctx, "Close the file handle\n");
977 smbcli_close(cli->tree, fnum1);
980 GET_INFO_PATH(pinfo4);
981 COMPARE_WRITE_TIME_GREATER(pinfo4, pinfo3);
983 if (pinfo4.basic_info.out.write_time > pinfo3.basic_info.out.write_time) {
984 torture_comment(tctx, "Server updated the write_time on close (correct)\n");
989 smbcli_close(cli->tree, fnum1);
990 smbcli_unlink(cli->tree, fname);
991 smbcli_deltree(cli->tree, BASEDIR);
996 static bool test_delayed_write_update5(struct torture_context *tctx,
997 struct smbcli_state *cli,
998 struct smbcli_state *cli2)
1000 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5;
1001 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6;
1002 const char *fname = BASEDIR "\\torture_file.txt";
1008 if (!torture_setup_dir(cli, BASEDIR)) {
1012 torture_comment(tctx, "Open the file handle\n");
1013 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1016 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1020 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1021 finfo0.basic_info.in.file.fnum = fnum1;
1027 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1028 pinfo0.basic_info.in.file.path = fname;
1036 /* get the initial times */
1037 GET_INFO_BOTH(finfo0,pinfo0);
1040 torture_comment(tctx, "Do a write on the file handle\n");
1041 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1043 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1048 GET_INFO_BOTH(finfo1,pinfo1);
1049 COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0);
1051 torture_comment(tctx, "Set write time in the future on the file handle\n");
1052 SET_INFO_FILE(finfo0, time(NULL) + 86400);
1053 GET_INFO_BOTH(finfo2,pinfo2);
1054 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
1056 torture_comment(tctx, "Set write time in the past on the file handle\n");
1057 SET_INFO_FILE(finfo0, time(NULL) - 86400);
1058 GET_INFO_BOTH(finfo2,pinfo2);
1059 COMPARE_WRITE_TIME_LESS(finfo2, finfo1);
1061 /* make sure the 2 second delay from the first write are canceled */
1063 while (time(NULL) < t+15) {
1065 /* get the times after the first write */
1066 GET_INFO_BOTH(finfo3,pinfo3);
1068 if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) {
1069 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
1070 (int)(time(NULL) - t));
1077 GET_INFO_BOTH(finfo3,pinfo3);
1078 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
1079 if (finfo3.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1080 torture_comment(tctx, "Server did not update write_time (correct)\n");
1083 /* sure any further write doesn't update the write time */
1085 while (time(NULL) < t+15) {
1087 torture_comment(tctx, "Do a write on the file handle\n");
1088 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1090 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1094 /* get the times after the write */
1095 GET_INFO_BOTH(finfo4,pinfo4);
1097 if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) {
1098 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
1099 (int)(time(NULL) - t));
1106 GET_INFO_BOTH(finfo4,pinfo4);
1107 COMPARE_WRITE_TIME_EQUAL(finfo4, finfo3);
1108 if (finfo4.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1109 torture_comment(tctx, "Server did not update write_time (correct)\n");
1115 GET_INFO_BOTH(finfo5,pinfo5);
1116 COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4);
1119 * the close doesn't update the write time
1121 torture_comment(tctx, "Close the file handle\n");
1122 smbcli_close(cli->tree, fnum1);
1125 GET_INFO_PATH(pinfo6);
1126 COMPARE_WRITE_TIME_EQUAL(pinfo6, pinfo5);
1128 if (pinfo6.basic_info.out.write_time == pinfo5.basic_info.out.write_time) {
1129 torture_comment(tctx, "Server did not update the write_time on close (correct)\n");
1134 smbcli_close(cli->tree, fnum1);
1135 smbcli_unlink(cli->tree, fname);
1136 smbcli_deltree(cli->tree, BASEDIR);
1141 static bool test_delayed_write_update6(struct torture_context *tctx,
1142 struct smbcli_state *cli,
1143 struct smbcli_state *cli2)
1145 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5;
1146 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6, pinfo7;
1147 const char *fname = BASEDIR "\\torture_file.txt";
1155 if (!torture_setup_dir(cli, BASEDIR)) {
1159 torture_comment(tctx, "Open the file handle\n");
1160 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1163 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1168 torture_comment(tctx, "Open the 2nd file handle on 2nd connection\n");
1169 fnum2 = smbcli_open(cli2->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1172 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1177 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1178 finfo0.basic_info.in.file.fnum = fnum1;
1184 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1185 pinfo0.basic_info.in.file.path = fname;
1194 /* get the initial times */
1195 GET_INFO_BOTH(finfo0,pinfo0);
1198 torture_comment(tctx, "Do a write on the file handle\n");
1199 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1201 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1206 GET_INFO_BOTH(finfo1,pinfo1);
1207 COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0);
1209 torture_comment(tctx, "Set write time in the future on the 2nd file handle\n");
1210 SET_INFO_FILE_EX(finfo0, time(NULL) + 86400, cli2->tree, fnum2);
1211 GET_INFO_BOTH(finfo2,pinfo2);
1212 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
1214 torture_comment(tctx, "Set write time in the past on the 2nd file handle\n");
1215 SET_INFO_FILE_EX(finfo0, time(NULL) - 86400, cli2->tree, fnum2);
1216 GET_INFO_BOTH(finfo2,pinfo2);
1217 COMPARE_WRITE_TIME_LESS(finfo2, finfo1);
1219 /* make sure the 2 second delay from the first write are canceled */
1221 while (time(NULL) < t+15) {
1223 /* get the times after the first write */
1224 GET_INFO_BOTH(finfo3,pinfo3);
1226 if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) {
1227 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
1228 (int)(time(NULL) - t));
1235 GET_INFO_BOTH(finfo3,pinfo3);
1236 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
1237 if (finfo3.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1238 torture_comment(tctx, "Server did not update write_time (correct)\n");
1241 /* sure any further write doesn't update the write time */
1243 while (time(NULL) < t+15) {
1245 torture_comment(tctx, "Do a write on the file handle\n");
1246 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1248 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1252 /* get the times after the write */
1253 GET_INFO_BOTH(finfo4,pinfo4);
1255 if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) {
1256 torture_comment(tctx, "Server updated write_time after %d seconds (wrong!)\n",
1257 (int)(time(NULL) - t));
1264 GET_INFO_BOTH(finfo4,pinfo4);
1265 COMPARE_WRITE_TIME_EQUAL(finfo4, finfo3);
1266 if (finfo4.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
1267 torture_comment(tctx, "Server did not update write_time (correct)\n");
1273 GET_INFO_BOTH(finfo5,pinfo5);
1274 COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4);
1277 * the close updates the write time to the time of the close
1278 * as the write time was set on the 2nd handle
1280 torture_comment(tctx, "Close the file handle\n");
1281 smbcli_close(cli->tree, fnum1);
1284 GET_INFO_PATH(pinfo6);
1285 COMPARE_WRITE_TIME_GREATER(pinfo6, pinfo5);
1287 if (pinfo6.basic_info.out.write_time > pinfo5.basic_info.out.write_time) {
1288 torture_comment(tctx, "Server updated the write_time on close (correct)\n");
1291 /* keep the 2nd handle open and rerun tests */
1298 * closing the 2nd handle will cause no write time update
1299 * as the write time was explicit set on this handle
1301 torture_comment(tctx, "Close the 2nd file handle\n");
1302 smbcli_close(cli2->tree, fnum2);
1305 GET_INFO_PATH(pinfo7);
1306 COMPARE_WRITE_TIME_EQUAL(pinfo7, pinfo6);
1308 if (pinfo7.basic_info.out.write_time == pinfo6.basic_info.out.write_time) {
1309 torture_comment(tctx, "Server did not update the write_time on close (correct)\n");
1314 smbcli_close(cli->tree, fnum1);
1316 smbcli_close(cli2->tree, fnum2);
1317 smbcli_unlink(cli->tree, fname);
1318 smbcli_deltree(cli->tree, BASEDIR);
1325 testing of delayed update of write_time
1327 struct torture_suite *torture_delay_write(void)
1329 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "DELAYWRITE");
1331 torture_suite_add_2smb_test(suite, "finfo update on close", test_finfo_after_write);
1332 torture_suite_add_1smb_test(suite, "delayed update of write time", test_delayed_write_update);
1333 torture_suite_add_2smb_test(suite, "delayed update of write time using 2 connections", test_delayed_write_update2);
1334 torture_suite_add_2smb_test(suite, "delayed update of write time 3", test_delayed_write_update3);
1335 torture_suite_add_2smb_test(suite, "delayed update of write time 4", test_delayed_write_update4);
1336 torture_suite_add_2smb_test(suite, "delayed update of write time 5", test_delayed_write_update5);
1337 torture_suite_add_2smb_test(suite, "delayed update of write time 6", test_delayed_write_update6);