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/>.
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)); \
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); \
44 #define CHECK_BUFFER(buf, seed, len) do { \
45 if (!check_buffer(buf, seed, len, __location__)) { \
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); \
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
)
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
)
86 printf("Buffer incorrect at %s! ofs=%d buf=0x%x correct=0x%x\n",
87 location
, i
, buf
[i
], v
);
97 static bool test_write(struct torture_context
*tctx
,
98 struct smbcli_state
*cli
)
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
)) {
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
);
121 printf("Failed to create %s - %s\n", fname
, smbcli_errstr(cli
->tree
));
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__
);
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__
);
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");
190 if (!(cli
->transport
->negotiate
.capabilities
& CAP_LARGE_FILES
)) {
191 printf("skipping large file tests - CAP_LARGE_FILES not set\n");
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__
);
212 CHECK_BUFFER(buf
, seed
, 4000);
215 smbcli_close(cli
->tree
, fnum
);
216 smb_raw_exit(cli
->session
);
217 smbcli_deltree(cli
->tree
, BASEDIR
);
225 static bool test_writex(struct torture_context
*tctx
,
226 struct smbcli_state
*cli
)
233 const int maxsize
= 90000;
234 const char *fname
= BASEDIR
"\\test.txt";
235 unsigned int seed
= time(NULL
);
236 union smb_fileinfo finfo
;
239 if (!torture_setting_bool(tctx
, "dangerous", false)) {
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");
251 if (!torture_setup_dir(cli
, BASEDIR
)) {
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
);
260 printf("Failed to create %s - %s\n", fname
, smbcli_errstr(cli
->tree
));
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__
);
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__
);
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");
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__
);
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");
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__
);
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
);
388 NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
)) {
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__
);
401 CHECK_BUFFER(buf
, seed
+1, 4000);
403 printf("limit is 2^%d\n", i
);
405 setup_buffer(buf
, seed
, maxsize
);
408 smbcli_close(cli
->tree
, fnum
);
409 smb_raw_exit(cli
->session
);
410 smbcli_deltree(cli
->tree
, BASEDIR
);
416 test write unlock ops
418 static bool test_writeunlock(struct torture_context
*tctx
,
419 struct smbcli_state
*cli
)
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");
438 if (!torture_setup_dir(cli
, BASEDIR
)) {
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
);
447 printf("Failed to create %s - %s\n", fname
, smbcli_errstr(cli
->tree
));
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__
);
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
,
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__
);
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
,
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__
);
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");
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
,
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__
);
553 CHECK_BUFFER(buf
, seed
, 4000);
556 smbcli_close(cli
->tree
, fnum
);
557 smb_raw_exit(cli
->session
);
558 smbcli_deltree(cli
->tree
, BASEDIR
);
566 static bool test_writeclose(struct torture_context
*tctx
,
567 struct smbcli_state
*cli
)
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");
586 if (!torture_setup_dir(cli
, BASEDIR
)) {
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
);
595 printf("Failed to create %s - %s\n", fname
, smbcli_errstr(cli
->tree
));
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__
);
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__
);
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__
);
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");
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__
);
715 CHECK_BUFFER(buf
, seed
, 4000);
718 smbcli_close(cli
->tree
, fnum
);
719 smb_raw_exit(cli
->session
);
720 smbcli_deltree(cli
->tree
, BASEDIR
);
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
);