diff options
author | David Disseldorp <ddiss@samba.org> | 2013-08-07 17:16:10 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2013-08-09 11:09:46 -0700 |
commit | 86c79f1ab3146ac83a3ac1fb43808997bcfe0d83 (patch) | |
tree | 8c7139ad168cd17b173401ca5faeebe311d72a49 /source4/torture | |
parent | a973b1ce7a94bd3f11432a6f32b9d9b13b868dfb (diff) | |
download | samba-86c79f1ab3146ac83a3ac1fb43808997bcfe0d83.tar.gz samba-86c79f1ab3146ac83a3ac1fb43808997bcfe0d83.tar.bz2 samba-86c79f1ab3146ac83a3ac1fb43808997bcfe0d83.zip |
torture: split out ioctl test file creation helper
Signed-off-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source4/torture')
-rw-r--r-- | source4/torture/smb2/ioctl.c | 99 |
1 files changed, 43 insertions, 56 deletions
diff --git a/source4/torture/smb2/ioctl.c b/source4/torture/smb2/ioctl.c index 501b233d5b..e8d12038e0 100644 --- a/source4/torture/smb2/ioctl.c +++ b/source4/torture/smb2/ioctl.c @@ -148,90 +148,78 @@ static bool check_pattern(struct torture_context *torture, return true; } -static bool test_setup_copy_chunk(struct torture_context *torture, - struct smb2_tree *tree, TALLOC_CTX *mem_ctx, - uint32_t nchunks, - struct smb2_handle *src_h, - uint64_t src_size, - uint32_t src_desired_access, - struct smb2_handle *dest_h, - uint64_t dest_size, - uint32_t dest_desired_access, - struct srv_copychunk_copy *cc_copy, - union smb_ioctl *ioctl) +static bool test_setup_create_fill(struct torture_context *torture, + struct smb2_tree *tree, TALLOC_CTX *mem_ctx, + const char *fname, + struct smb2_handle *fh, + uint64_t size, + uint32_t desired_access) { - struct req_resume_key_rsp res_key; struct smb2_create io; NTSTATUS status; - enum ndr_err_code ndr_ret; uint64_t i; - uint8_t *buf = talloc_zero_size(mem_ctx, MAX(src_size, dest_size)); + uint8_t *buf = talloc_zero_size(mem_ctx, size); torture_assert(torture, (buf != NULL), "no memory for file data buf"); - smb2_util_unlink(tree, FNAME); - smb2_util_unlink(tree, FNAME2); + smb2_util_unlink(tree, fname); ZERO_STRUCT(io); - io.in.desired_access = src_desired_access; + io.in.desired_access = desired_access; io.in.file_attributes = FILE_ATTRIBUTE_NORMAL; io.in.create_disposition = NTCREATEX_DISP_OPEN_IF; io.in.share_access = NTCREATEX_SHARE_ACCESS_DELETE| NTCREATEX_SHARE_ACCESS_READ| NTCREATEX_SHARE_ACCESS_WRITE; - io.in.fname = FNAME; + io.in.fname = fname; status = smb2_create(tree, mem_ctx, &io); - torture_assert_ntstatus_ok(torture, status, "src create"); + torture_assert_ntstatus_ok(torture, status, "file create"); - *src_h = io.out.file.handle; + *fh = io.out.file.handle; - if (src_size > 0) { + if (size > 0) { uint64_t cur_off = 0; - for (i = 0; i <= src_size - 8; i += 8) { + for (i = 0; i <= size - 8; i += 8) { SBVAL(buf, i, patt_hash(i)); } - while (src_size > 0) { - uint64_t io_sz = MIN(1024 * 1024, src_size); - status = smb2_util_write(tree, *src_h, + while (size > 0) { + uint64_t io_sz = MIN(1024 * 1024, size); + status = smb2_util_write(tree, *fh, buf + cur_off, cur_off, io_sz); - torture_assert_ntstatus_ok(torture, status, "src write"); + torture_assert_ntstatus_ok(torture, status, "file write"); - src_size -= io_sz; + size -= io_sz; cur_off += io_sz; } } + return true; +} - ZERO_STRUCT(io); - io.in.desired_access = dest_desired_access; - io.in.file_attributes = FILE_ATTRIBUTE_NORMAL; - io.in.create_disposition = NTCREATEX_DISP_OPEN_IF; - io.in.share_access = - NTCREATEX_SHARE_ACCESS_DELETE| - NTCREATEX_SHARE_ACCESS_READ| - NTCREATEX_SHARE_ACCESS_WRITE; - io.in.fname = FNAME2; - - status = smb2_create(tree, mem_ctx, &io); - torture_assert_ntstatus_ok(torture, status, "dest create"); - - *dest_h = io.out.file.handle; +static bool test_setup_copy_chunk(struct torture_context *torture, + struct smb2_tree *tree, TALLOC_CTX *mem_ctx, + uint32_t nchunks, + struct smb2_handle *src_h, + uint64_t src_size, + uint32_t src_desired_access, + struct smb2_handle *dest_h, + uint64_t dest_size, + uint32_t dest_desired_access, + struct srv_copychunk_copy *cc_copy, + union smb_ioctl *ioctl) +{ + struct req_resume_key_rsp res_key; + bool ok; + NTSTATUS status; + enum ndr_err_code ndr_ret; - if (dest_size > 0) { - uint64_t cur_off = 0; - for (i = 0; i <= dest_size - 8; i += 8) { - SBVAL(buf, i, patt_hash(i)); - } - while (dest_size > 0) { - uint64_t io_sz = MIN(1024 * 1024, dest_size); - status = smb2_util_write(tree, *dest_h, - buf + cur_off, cur_off, io_sz); - torture_assert_ntstatus_ok(torture, status, "dest write"); + ok = test_setup_create_fill(torture, tree, mem_ctx, FNAME, + src_h, src_size, src_desired_access); + torture_assert(torture, ok, "src file create fill"); - dest_size -= io_sz; - cur_off += io_sz; - } - } + ok = test_setup_create_fill(torture, tree, mem_ctx, FNAME2, + dest_h, dest_size, dest_desired_access); + torture_assert(torture, ok, "dest file create fill"); ZERO_STRUCTPN(ioctl); ioctl->smb2.level = RAW_IOCTL_SMB2; @@ -245,7 +233,6 @@ static bool test_setup_copy_chunk(struct torture_context *torture, torture_assert_ntstatus_ok(torture, status, "FSCTL_SRV_REQUEST_RESUME_KEY"); - ndr_ret = ndr_pull_struct_blob(&ioctl->smb2.out.out, mem_ctx, &res_key, (ndr_pull_flags_fn_t)ndr_pull_req_resume_key_rsp); |