s4-smbtorture: Make test names lowercase and dot-separated.
[Samba.git] / source4 / torture / raw / write.c
blob12c42bf141e3cd538f3bbb14cc2be1842541be16
1 /*
2 Unix SMB/CIFS implementation.
3 test suite for various write operations
5 Copyright (C) Andrew Tridgell 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "libcli/raw/libcliraw.h"
23 #include "system/time.h"
24 #include "system/filesys.h"
25 #include "libcli/libcli.h"
26 #include "torture/util.h"
28 #define CHECK_STATUS(status, correct) do { \
29 if (!NT_STATUS_EQUAL(status, correct)) { \
30 printf("(%s) Incorrect status %s - should be %s\n", \
31 __location__, nt_errstr(status), nt_errstr(correct)); \
32 ret = false; \
33 goto done; \
34 }} while (0)
36 #define CHECK_VALUE(v, correct) do { \
37 if ((v) != (correct)) { \
38 printf("(%s) Incorrect value %s=%d - should be %d\n", \
39 __location__, #v, v, correct); \
40 ret = false; \
41 goto done; \
42 }} while (0)
44 #define CHECK_BUFFER(buf, seed, len) do { \
45 if (!check_buffer(buf, seed, len, __location__)) { \
46 ret = false; \
47 goto done; \
48 }} while (0)
50 #define CHECK_ALL_INFO(v, field) do { \
51 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
52 finfo.all_info.in.file.path = fname; \
53 status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
54 CHECK_STATUS(status, NT_STATUS_OK); \
55 if ((v) != finfo.all_info.out.field) { \
56 printf("(%s) wrong value for field %s %.0f - %.0f\n", \
57 __location__, #field, (double)v, (double)finfo.all_info.out.field); \
58 dump_all_info(tctx, &finfo); \
59 ret = false; \
60 }} while (0)
63 #define BASEDIR "\\testwrite"
67 setup a random buffer based on a seed
69 static void setup_buffer(uint8_t *buf, unsigned int seed, int len)
71 int i;
72 srandom(seed);
73 for (i=0;i<len;i++) buf[i] = random();
77 check a random buffer based on a seed
79 static bool check_buffer(uint8_t *buf, unsigned int seed, int len, const char *location)
81 int i;
82 srandom(seed);
83 for (i=0;i<len;i++) {
84 uint8_t v = random();
85 if (buf[i] != v) {
86 printf("Buffer incorrect at %s! ofs=%d buf=0x%x correct=0x%x\n",
87 location, i, buf[i], v);
88 return false;
91 return true;
95 test write ops
97 static bool test_write(struct torture_context *tctx,
98 struct smbcli_state *cli)
100 union smb_write io;
101 NTSTATUS status;
102 bool ret = true;
103 int fnum;
104 uint8_t *buf;
105 const int maxsize = 90000;
106 const char *fname = BASEDIR "\\test.txt";
107 unsigned int seed = time(NULL);
108 union smb_fileinfo finfo;
110 buf = talloc_zero_array(tctx, uint8_t, maxsize);
112 if (!torture_setup_dir(cli, BASEDIR)) {
113 return false;
116 printf("Testing RAW_WRITE_WRITE\n");
117 io.generic.level = RAW_WRITE_WRITE;
119 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
120 if (fnum == -1) {
121 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
122 ret = false;
123 goto done;
126 printf("Trying zero write\n");
127 io.write.in.file.fnum = fnum;
128 io.write.in.count = 0;
129 io.write.in.offset = 0;
130 io.write.in.remaining = 0;
131 io.write.in.data = buf;
132 status = smb_raw_write(cli->tree, &io);
133 CHECK_STATUS(status, NT_STATUS_OK);
134 CHECK_VALUE(io.write.out.nwritten, 0);
136 setup_buffer(buf, seed, maxsize);
138 printf("Trying small write\n");
139 io.write.in.count = 9;
140 io.write.in.offset = 4;
141 io.write.in.data = buf;
142 status = smb_raw_write(cli->tree, &io);
143 CHECK_STATUS(status, NT_STATUS_OK);
144 CHECK_VALUE(io.write.out.nwritten, io.write.in.count);
146 memset(buf, 0, maxsize);
147 if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
148 printf("read failed at %s\n", __location__);
149 ret = false;
150 goto done;
152 CHECK_BUFFER(buf+4, seed, 9);
153 CHECK_VALUE(IVAL(buf,0), 0);
155 setup_buffer(buf, seed, maxsize);
157 printf("Trying large write\n");
158 io.write.in.count = 4000;
159 io.write.in.offset = 0;
160 io.write.in.data = buf;
161 status = smb_raw_write(cli->tree, &io);
162 CHECK_STATUS(status, NT_STATUS_OK);
163 CHECK_VALUE(io.write.out.nwritten, 4000);
165 memset(buf, 0, maxsize);
166 if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
167 printf("read failed at %s\n", __location__);
168 ret = false;
169 goto done;
171 CHECK_BUFFER(buf, seed, 4000);
173 printf("Trying bad fnum\n");
174 io.write.in.file.fnum = fnum+1;
175 io.write.in.count = 4000;
176 io.write.in.offset = 0;
177 io.write.in.data = buf;
178 status = smb_raw_write(cli->tree, &io);
179 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
181 printf("Setting file as sparse\n");
182 status = torture_set_sparse(cli->tree, fnum);
183 CHECK_STATUS(status, NT_STATUS_OK);
185 if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
186 printf("skipping large file tests - CAP_LARGE_FILES not set\n");
187 goto done;
190 if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
191 printf("skipping large file tests - CAP_LARGE_FILES not set\n");
192 goto done;
195 printf("Trying 2^32 offset\n");
196 setup_buffer(buf, seed, maxsize);
197 io.write.in.file.fnum = fnum;
198 io.write.in.count = 4000;
199 io.write.in.offset = 0xFFFFFFFF - 2000;
200 io.write.in.data = buf;
201 status = smb_raw_write(cli->tree, &io);
202 CHECK_STATUS(status, NT_STATUS_OK);
203 CHECK_VALUE(io.write.out.nwritten, 4000);
204 CHECK_ALL_INFO(io.write.in.count + (uint64_t)io.write.in.offset, size);
206 memset(buf, 0, maxsize);
207 if (smbcli_read(cli->tree, fnum, buf, io.write.in.offset, 4000) != 4000) {
208 printf("read failed at %s\n", __location__);
209 ret = false;
210 goto done;
212 CHECK_BUFFER(buf, seed, 4000);
214 done:
215 smbcli_close(cli->tree, fnum);
216 smb_raw_exit(cli->session);
217 smbcli_deltree(cli->tree, BASEDIR);
218 return ret;
223 test writex ops
225 static bool test_writex(struct torture_context *tctx,
226 struct smbcli_state *cli)
228 union smb_write io;
229 NTSTATUS status;
230 bool ret = true;
231 int fnum, i;
232 uint8_t *buf;
233 const int maxsize = 90000;
234 const char *fname = BASEDIR "\\test.txt";
235 unsigned int seed = time(NULL);
236 union smb_fileinfo finfo;
237 int max_bits=63;
239 if (!torture_setting_bool(tctx, "dangerous", false)) {
240 max_bits=33;
241 torture_comment(tctx, "dangerous not set - limiting range of test to 2^%d\n", max_bits);
244 buf = talloc_zero_array(tctx, uint8_t, maxsize);
246 if (!cli->transport->negotiate.lockread_supported) {
247 printf("Server does not support writeunlock - skipping\n");
248 return true;
251 if (!torture_setup_dir(cli, BASEDIR)) {
252 return false;
255 printf("Testing RAW_WRITE_WRITEX\n");
256 io.generic.level = RAW_WRITE_WRITEX;
258 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
259 if (fnum == -1) {
260 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
261 ret = false;
262 goto done;
265 printf("Trying zero write\n");
266 io.writex.in.file.fnum = fnum;
267 io.writex.in.offset = 0;
268 io.writex.in.wmode = 0;
269 io.writex.in.remaining = 0;
270 io.writex.in.count = 0;
271 io.writex.in.data = buf;
272 status = smb_raw_write(cli->tree, &io);
273 CHECK_STATUS(status, NT_STATUS_OK);
274 CHECK_VALUE(io.writex.out.nwritten, 0);
276 setup_buffer(buf, seed, maxsize);
278 printf("Trying small write\n");
279 io.writex.in.count = 9;
280 io.writex.in.offset = 4;
281 io.writex.in.data = buf;
282 status = smb_raw_write(cli->tree, &io);
283 CHECK_STATUS(status, NT_STATUS_OK);
284 CHECK_VALUE(io.writex.out.nwritten, io.writex.in.count);
286 memset(buf, 0, maxsize);
287 if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
288 printf("read failed at %s\n", __location__);
289 ret = false;
290 goto done;
292 CHECK_BUFFER(buf+4, seed, 9);
293 CHECK_VALUE(IVAL(buf,0), 0);
295 setup_buffer(buf, seed, maxsize);
297 printf("Trying large write\n");
298 io.writex.in.count = 4000;
299 io.writex.in.offset = 0;
300 io.writex.in.data = buf;
301 status = smb_raw_write(cli->tree, &io);
302 CHECK_STATUS(status, NT_STATUS_OK);
303 CHECK_VALUE(io.writex.out.nwritten, 4000);
305 memset(buf, 0, maxsize);
306 if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
307 printf("read failed at %s\n", __location__);
308 ret = false;
309 goto done;
311 CHECK_BUFFER(buf, seed, 4000);
313 printf("Trying bad fnum\n");
314 io.writex.in.file.fnum = fnum+1;
315 io.writex.in.count = 4000;
316 io.writex.in.offset = 0;
317 io.writex.in.data = buf;
318 status = smb_raw_write(cli->tree, &io);
319 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
321 printf("Testing wmode\n");
322 io.writex.in.file.fnum = fnum;
323 io.writex.in.count = 1;
324 io.writex.in.offset = 0;
325 io.writex.in.wmode = 1;
326 io.writex.in.data = buf;
327 status = smb_raw_write(cli->tree, &io);
328 CHECK_STATUS(status, NT_STATUS_OK);
329 CHECK_VALUE(io.writex.out.nwritten, io.writex.in.count);
331 io.writex.in.wmode = 2;
332 status = smb_raw_write(cli->tree, &io);
333 CHECK_STATUS(status, NT_STATUS_OK);
334 CHECK_VALUE(io.writex.out.nwritten, io.writex.in.count);
337 printf("Trying locked region\n");
338 cli->session->pid++;
339 if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 3, 1, 0, WRITE_LOCK))) {
340 printf("Failed to lock file at %s\n", __location__);
341 ret = false;
342 goto done;
344 cli->session->pid--;
345 io.writex.in.wmode = 0;
346 io.writex.in.count = 4;
347 io.writex.in.offset = 0;
348 status = smb_raw_write(cli->tree, &io);
349 CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
351 printf("Setting file as sparse\n");
352 status = torture_set_sparse(cli->tree, fnum);
353 CHECK_STATUS(status, NT_STATUS_OK);
355 if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
356 printf("skipping large file tests - CAP_LARGE_FILES not set\n");
357 goto done;
360 printf("Trying 2^32 offset\n");
361 setup_buffer(buf, seed, maxsize);
362 io.writex.in.file.fnum = fnum;
363 io.writex.in.count = 4000;
364 io.writex.in.offset = 0xFFFFFFFF - 2000;
365 io.writex.in.data = buf;
366 status = smb_raw_write(cli->tree, &io);
367 CHECK_STATUS(status, NT_STATUS_OK);
368 CHECK_VALUE(io.writex.out.nwritten, 4000);
369 CHECK_ALL_INFO(io.writex.in.count + (uint64_t)io.writex.in.offset, size);
371 memset(buf, 0, maxsize);
372 if (smbcli_read(cli->tree, fnum, buf, io.writex.in.offset, 4000) != 4000) {
373 printf("read failed at %s\n", __location__);
374 ret = false;
375 goto done;
377 CHECK_BUFFER(buf, seed, 4000);
379 for (i=33;i<max_bits;i++) {
380 printf("Trying 2^%d offset\n", i);
381 setup_buffer(buf, seed+1, maxsize);
382 io.writex.in.file.fnum = fnum;
383 io.writex.in.count = 4000;
384 io.writex.in.offset = ((uint64_t)1) << i;
385 io.writex.in.data = buf;
386 status = smb_raw_write(cli->tree, &io);
387 if (i>33 &&
388 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
389 break;
391 CHECK_STATUS(status, NT_STATUS_OK);
392 CHECK_VALUE(io.writex.out.nwritten, 4000);
393 CHECK_ALL_INFO(io.writex.in.count + (uint64_t)io.writex.in.offset, size);
395 memset(buf, 0, maxsize);
396 if (smbcli_read(cli->tree, fnum, buf, io.writex.in.offset, 4000) != 4000) {
397 printf("read failed at %s\n", __location__);
398 ret = false;
399 goto done;
401 CHECK_BUFFER(buf, seed+1, 4000);
403 printf("limit is 2^%d\n", i);
405 setup_buffer(buf, seed, maxsize);
407 done:
408 smbcli_close(cli->tree, fnum);
409 smb_raw_exit(cli->session);
410 smbcli_deltree(cli->tree, BASEDIR);
411 return ret;
416 test write unlock ops
418 static bool test_writeunlock(struct torture_context *tctx,
419 struct smbcli_state *cli)
421 union smb_write io;
422 NTSTATUS status;
423 bool ret = true;
424 int fnum;
425 uint8_t *buf;
426 const int maxsize = 90000;
427 const char *fname = BASEDIR "\\test.txt";
428 unsigned int seed = time(NULL);
429 union smb_fileinfo finfo;
431 buf = talloc_zero_array(tctx, uint8_t, maxsize);
433 if (!cli->transport->negotiate.lockread_supported) {
434 printf("Server does not support writeunlock - skipping\n");
435 return true;
438 if (!torture_setup_dir(cli, BASEDIR)) {
439 return false;
442 printf("Testing RAW_WRITE_WRITEUNLOCK\n");
443 io.generic.level = RAW_WRITE_WRITEUNLOCK;
445 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
446 if (fnum == -1) {
447 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
448 ret = false;
449 goto done;
452 printf("Trying zero write\n");
453 io.writeunlock.in.file.fnum = fnum;
454 io.writeunlock.in.count = 0;
455 io.writeunlock.in.offset = 0;
456 io.writeunlock.in.remaining = 0;
457 io.writeunlock.in.data = buf;
458 status = smb_raw_write(cli->tree, &io);
459 CHECK_STATUS(status, NT_STATUS_OK);
460 CHECK_VALUE(io.writeunlock.out.nwritten, io.writeunlock.in.count);
462 setup_buffer(buf, seed, maxsize);
464 printf("Trying small write\n");
465 io.writeunlock.in.count = 9;
466 io.writeunlock.in.offset = 4;
467 io.writeunlock.in.data = buf;
468 status = smb_raw_write(cli->tree, &io);
469 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
470 if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
471 printf("read failed at %s\n", __location__);
472 ret = false;
473 goto done;
475 CHECK_BUFFER(buf+4, seed, 9);
476 CHECK_VALUE(IVAL(buf,0), 0);
478 setup_buffer(buf, seed, maxsize);
479 smbcli_lock(cli->tree, fnum, io.writeunlock.in.offset, io.writeunlock.in.count,
480 0, WRITE_LOCK);
481 status = smb_raw_write(cli->tree, &io);
482 CHECK_STATUS(status, NT_STATUS_OK);
483 CHECK_VALUE(io.writeunlock.out.nwritten, io.writeunlock.in.count);
485 memset(buf, 0, maxsize);
486 if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
487 printf("read failed at %s\n", __location__);
488 ret = false;
489 goto done;
491 CHECK_BUFFER(buf+4, seed, 9);
492 CHECK_VALUE(IVAL(buf,0), 0);
494 setup_buffer(buf, seed, maxsize);
496 printf("Trying large write\n");
497 io.writeunlock.in.count = 4000;
498 io.writeunlock.in.offset = 0;
499 io.writeunlock.in.data = buf;
500 smbcli_lock(cli->tree, fnum, io.writeunlock.in.offset, io.writeunlock.in.count,
501 0, WRITE_LOCK);
502 status = smb_raw_write(cli->tree, &io);
503 CHECK_STATUS(status, NT_STATUS_OK);
504 CHECK_VALUE(io.writeunlock.out.nwritten, 4000);
506 status = smb_raw_write(cli->tree, &io);
507 CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
509 memset(buf, 0, maxsize);
510 if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
511 printf("read failed at %s\n", __location__);
512 ret = false;
513 goto done;
515 CHECK_BUFFER(buf, seed, 4000);
517 printf("Trying bad fnum\n");
518 io.writeunlock.in.file.fnum = fnum+1;
519 io.writeunlock.in.count = 4000;
520 io.writeunlock.in.offset = 0;
521 io.writeunlock.in.data = buf;
522 status = smb_raw_write(cli->tree, &io);
523 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
525 printf("Setting file as sparse\n");
526 status = torture_set_sparse(cli->tree, fnum);
527 CHECK_STATUS(status, NT_STATUS_OK);
529 if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
530 printf("skipping large file tests - CAP_LARGE_FILES not set\n");
531 goto done;
534 printf("Trying 2^32 offset\n");
535 setup_buffer(buf, seed, maxsize);
536 io.writeunlock.in.file.fnum = fnum;
537 io.writeunlock.in.count = 4000;
538 io.writeunlock.in.offset = 0xFFFFFFFF - 2000;
539 io.writeunlock.in.data = buf;
540 smbcli_lock(cli->tree, fnum, io.writeunlock.in.offset, io.writeunlock.in.count,
541 0, WRITE_LOCK);
542 status = smb_raw_write(cli->tree, &io);
543 CHECK_STATUS(status, NT_STATUS_OK);
544 CHECK_VALUE(io.writeunlock.out.nwritten, 4000);
545 CHECK_ALL_INFO(io.writeunlock.in.count + (uint64_t)io.writeunlock.in.offset, size);
547 memset(buf, 0, maxsize);
548 if (smbcli_read(cli->tree, fnum, buf, io.writeunlock.in.offset, 4000) != 4000) {
549 printf("read failed at %s\n", __location__);
550 ret = false;
551 goto done;
553 CHECK_BUFFER(buf, seed, 4000);
555 done:
556 smbcli_close(cli->tree, fnum);
557 smb_raw_exit(cli->session);
558 smbcli_deltree(cli->tree, BASEDIR);
559 return ret;
564 test write close ops
566 static bool test_writeclose(struct torture_context *tctx,
567 struct smbcli_state *cli)
569 union smb_write io;
570 NTSTATUS status;
571 bool ret = true;
572 int fnum;
573 uint8_t *buf;
574 const int maxsize = 90000;
575 const char *fname = BASEDIR "\\test.txt";
576 unsigned int seed = time(NULL);
577 union smb_fileinfo finfo;
579 buf = talloc_zero_array(tctx, uint8_t, maxsize);
581 if (!torture_setting_bool(tctx, "writeclose_support", true)) {
582 printf("Server does not support writeclose - skipping\n");
583 return true;
586 if (!torture_setup_dir(cli, BASEDIR)) {
587 return false;
590 printf("Testing RAW_WRITE_WRITECLOSE\n");
591 io.generic.level = RAW_WRITE_WRITECLOSE;
593 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
594 if (fnum == -1) {
595 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
596 ret = false;
597 goto done;
600 printf("Trying zero write\n");
601 io.writeclose.in.file.fnum = fnum;
602 io.writeclose.in.count = 0;
603 io.writeclose.in.offset = 0;
604 io.writeclose.in.mtime = 0;
605 io.writeclose.in.data = buf;
606 status = smb_raw_write(cli->tree, &io);
607 CHECK_STATUS(status, NT_STATUS_OK);
608 CHECK_VALUE(io.writeclose.out.nwritten, io.writeclose.in.count);
610 status = smb_raw_write(cli->tree, &io);
611 CHECK_STATUS(status, NT_STATUS_OK);
612 CHECK_VALUE(io.writeclose.out.nwritten, io.writeclose.in.count);
614 setup_buffer(buf, seed, maxsize);
616 printf("Trying small write\n");
617 io.writeclose.in.count = 9;
618 io.writeclose.in.offset = 4;
619 io.writeclose.in.data = buf;
620 status = smb_raw_write(cli->tree, &io);
621 CHECK_STATUS(status, NT_STATUS_OK);
623 status = smb_raw_write(cli->tree, &io);
624 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
626 fnum = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
627 io.writeclose.in.file.fnum = fnum;
629 if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
630 printf("read failed at %s\n", __location__);
631 ret = false;
632 goto done;
634 CHECK_BUFFER(buf+4, seed, 9);
635 CHECK_VALUE(IVAL(buf,0), 0);
637 setup_buffer(buf, seed, maxsize);
638 status = smb_raw_write(cli->tree, &io);
639 CHECK_STATUS(status, NT_STATUS_OK);
640 CHECK_VALUE(io.writeclose.out.nwritten, io.writeclose.in.count);
642 fnum = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
643 io.writeclose.in.file.fnum = fnum;
645 memset(buf, 0, maxsize);
646 if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
647 printf("read failed at %s\n", __location__);
648 ret = false;
649 goto done;
651 CHECK_BUFFER(buf+4, seed, 9);
652 CHECK_VALUE(IVAL(buf,0), 0);
654 setup_buffer(buf, seed, maxsize);
656 printf("Trying large write\n");
657 io.writeclose.in.count = 4000;
658 io.writeclose.in.offset = 0;
659 io.writeclose.in.data = buf;
660 status = smb_raw_write(cli->tree, &io);
661 CHECK_STATUS(status, NT_STATUS_OK);
662 CHECK_VALUE(io.writeclose.out.nwritten, 4000);
664 status = smb_raw_write(cli->tree, &io);
665 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
667 fnum = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
668 io.writeclose.in.file.fnum = fnum;
670 memset(buf, 0, maxsize);
671 if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
672 printf("read failed at %s\n", __location__);
673 ret = false;
674 goto done;
676 CHECK_BUFFER(buf, seed, 4000);
678 printf("Trying bad fnum\n");
679 io.writeclose.in.file.fnum = fnum+1;
680 io.writeclose.in.count = 4000;
681 io.writeclose.in.offset = 0;
682 io.writeclose.in.data = buf;
683 status = smb_raw_write(cli->tree, &io);
684 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
686 printf("Setting file as sparse\n");
687 status = torture_set_sparse(cli->tree, fnum);
688 CHECK_STATUS(status, NT_STATUS_OK);
690 if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
691 printf("skipping large file tests - CAP_LARGE_FILES not set\n");
692 goto done;
695 printf("Trying 2^32 offset\n");
696 setup_buffer(buf, seed, maxsize);
697 io.writeclose.in.file.fnum = fnum;
698 io.writeclose.in.count = 4000;
699 io.writeclose.in.offset = 0xFFFFFFFF - 2000;
700 io.writeclose.in.data = buf;
701 status = smb_raw_write(cli->tree, &io);
702 CHECK_STATUS(status, NT_STATUS_OK);
703 CHECK_VALUE(io.writeclose.out.nwritten, 4000);
704 CHECK_ALL_INFO(io.writeclose.in.count + (uint64_t)io.writeclose.in.offset, size);
706 fnum = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
707 io.writeclose.in.file.fnum = fnum;
709 memset(buf, 0, maxsize);
710 if (smbcli_read(cli->tree, fnum, buf, io.writeclose.in.offset, 4000) != 4000) {
711 printf("read failed at %s\n", __location__);
712 ret = false;
713 goto done;
715 CHECK_BUFFER(buf, seed, 4000);
717 done:
718 smbcli_close(cli->tree, fnum);
719 smb_raw_exit(cli->session);
720 smbcli_deltree(cli->tree, BASEDIR);
721 return ret;
725 basic testing of write calls
727 struct torture_suite *torture_raw_write(TALLOC_CTX *mem_ctx)
729 struct torture_suite *suite = torture_suite_create(mem_ctx, "write");
731 torture_suite_add_1smb_test(suite, "write", test_write);
732 torture_suite_add_1smb_test(suite, "write unlock", test_writeunlock);
733 torture_suite_add_1smb_test(suite, "write close", test_writeclose);
734 torture_suite_add_1smb_test(suite, "writex", test_writex);
736 return suite;