2 Unix SMB/CIFS implementation.
5 Copyright (C) Stefan Metzmacher 2009
6 Copyright (C) David Disseldorp 2013-2015
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "smbd/smbd.h"
24 #include "smbd/globals.h"
25 #include "../libcli/smb/smb_common.h"
26 #include "../libcli/security/security.h"
27 #include "../lib/util/tevent_ntstatus.h"
28 #include "rpc_server/srv_pipe_hnd.h"
29 #include "include/ntioctl.h"
30 #include "../librpc/ndr/libndr.h"
31 #include "librpc/gen_ndr/ndr_ioctl.h"
32 #include "smb2_ioctl_private.h"
35 * XXX this may reduce dup_extents->byte_count so that it's less than the
38 static NTSTATUS fsctl_dup_extents_check_lengths(struct files_struct *src_fsp,
39 struct files_struct *dst_fsp,
40 struct fsctl_dup_extents_to_file *dup_extents)
44 if ((dup_extents->source_off + dup_extents->byte_count
45 < dup_extents->source_off)
46 || (dup_extents->target_off + dup_extents->byte_count
47 < dup_extents->target_off)) {
48 return NT_STATUS_INVALID_PARAMETER; /* wrap */
51 status = vfs_stat_fsp(src_fsp);
52 if (!NT_STATUS_IS_OK(status)) {
57 * XXX vfs_btrfs and vfs_default have size checks in the copychunk
58 * handler, as this needs to be rechecked after the src has potentially
59 * been extended by a previous chunk in the compound copychunk req.
61 if (src_fsp->fsp_name->st.st_ex_size
62 < dup_extents->source_off + dup_extents->byte_count) {
63 DEBUG(2, ("dup_extents req exceeds src size\n"));
64 return NT_STATUS_NOT_SUPPORTED;
67 status = vfs_stat_fsp(dst_fsp);
68 if (!NT_STATUS_IS_OK(status)) {
72 if (dst_fsp->fsp_name->st.st_ex_size
73 < dup_extents->target_off + dup_extents->byte_count) {
75 if (dst_fsp->fsp_name->st.st_ex_size - dup_extents->target_off
76 > dst_fsp->fsp_name->st.st_ex_size) {
77 return NT_STATUS_INVALID_PARAMETER; /* wrap */
81 * this server behaviour is pretty hairy, but we need to match
84 DEBUG(2, ("dup_extents req exceeds target size, capping\n"));
85 dup_extents->byte_count = dst_fsp->fsp_name->st.st_ex_size
86 - dup_extents->target_off;
92 static NTSTATUS fsctl_dup_extents_check_overlap(struct files_struct *src_fsp,
93 struct files_struct *dst_fsp,
94 struct fsctl_dup_extents_to_file *dup_extents)
96 uint64_t src_off_last;
97 uint64_t tgt_off_last;
99 if (!file_id_equal(&src_fsp->file_id, &dst_fsp->file_id)) {
100 /* src and dest refer to different files */
104 if (dup_extents->byte_count == 0) {
105 /* no range to overlap */
110 * [MS-FSCC] 2.3.8 FSCTL_DUPLICATE_EXTENTS_TO_FILE Reply
111 * STATUS_NOT_SUPPORTED:
112 * The source and target destination ranges overlap on the same file.
115 src_off_last = dup_extents->source_off + dup_extents->byte_count - 1;
116 if ((dup_extents->target_off >= dup_extents->source_off)
117 && (dup_extents->target_off <= src_off_last)) {
122 return NT_STATUS_NOT_SUPPORTED;
126 tgt_off_last = dup_extents->target_off + dup_extents->byte_count - 1;
127 if ((tgt_off_last >= dup_extents->source_off)
128 && (tgt_off_last <= src_off_last)) {
133 return NT_STATUS_NOT_SUPPORTED;
139 static NTSTATUS fsctl_dup_extents_check_sparse(struct files_struct *src_fsp,
140 struct files_struct *dst_fsp)
143 * 2.3.8 FSCTL_DUPLICATE_EXTENTS_TO_FILE Reply...
144 * STATUS_NOT_SUPPORTED: Target file is sparse, while source
145 * is a non-sparse file.
147 * WS2016 has the following behaviour (MS are in the process of fixing
149 * STATUS_NOT_SUPPORTED is returned if the source is sparse, while the
150 * target is non-sparse. However, if target is sparse while the source
151 * is non-sparse, then FSCTL_DUPLICATE_EXTENTS_TO_FILE completes
154 if ((src_fsp->is_sparse) && (!dst_fsp->is_sparse)) {
155 return NT_STATUS_NOT_SUPPORTED;
161 struct fsctl_dup_extents_state {
162 struct tevent_context *ev;
163 struct connection_struct *conn;
164 struct files_struct *src_fsp;
165 struct files_struct *dst_fsp;
166 struct fsctl_dup_extents_to_file dup_extents;
169 static void fsctl_dup_extents_offload_read_done(struct tevent_req *subreq);
170 static void fsctl_dup_extents_vfs_done(struct tevent_req *subreq);
172 static struct tevent_req *fsctl_dup_extents_send(TALLOC_CTX *mem_ctx,
173 struct tevent_context *ev,
174 struct files_struct *dst_fsp,
176 struct smbd_smb2_request *smb2req)
178 struct tevent_req *req = NULL;
179 struct tevent_req *subreq = NULL;
180 struct fsctl_dup_extents_state *state = NULL;
181 uint64_t src_fid_persistent = 0;
182 uint64_t src_fid_volatile = 0;
183 struct files_struct *src_fsp = NULL;
187 req = tevent_req_create(mem_ctx, &state,
188 struct fsctl_dup_extents_state);
193 if (dst_fsp == NULL) {
194 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
195 return tevent_req_post(req, ev);
198 *state = (struct fsctl_dup_extents_state) {
199 .conn = dst_fsp->conn,
204 if ((dst_fsp->conn->fs_capabilities
205 & FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0) {
206 DBG_INFO("FS does not advertise block refcounting support\n");
207 tevent_req_nterror(req, NT_STATUS_INVALID_DEVICE_REQUEST);
208 return tevent_req_post(req, ev);
211 ndr_ret = ndr_pull_struct_blob(in_input, state, &state->dup_extents,
212 (ndr_pull_flags_fn_t)ndr_pull_fsctl_dup_extents_to_file);
213 if (ndr_ret != NDR_ERR_SUCCESS) {
214 DBG_ERR("failed to unmarshall dup extents to file req\n");
215 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
216 return tevent_req_post(req, ev);
219 src_fid_persistent = BVAL(state->dup_extents.source_fid, 0);
220 src_fid_volatile = BVAL(state->dup_extents.source_fid, 8);
221 src_fsp = file_fsp_get(smb2req, src_fid_persistent, src_fid_volatile);
222 if ((src_fsp == NULL)
223 || (src_fsp->file_id.devid != dst_fsp->file_id.devid)) {
225 * [MS-FSCC] 2.3.8 FSCTL_DUPLICATE_EXTENTS_TO_FILE Reply
226 * STATUS_INVALID_PARAMETER:
227 * The FileHandle parameter is either invalid or does not
228 * represent a handle to an opened file on the same volume.
230 * Windows Server responds with NT_STATUS_INVALID_HANDLE instead
231 * of STATUS_INVALID_PARAMETER here, despite the above spec.
233 DBG_ERR("invalid src_fsp for dup_extents\n");
234 tevent_req_nterror(req, NT_STATUS_INVALID_HANDLE);
235 return tevent_req_post(req, ev);
237 state->src_fsp = src_fsp;
239 status = fsctl_dup_extents_check_lengths(src_fsp, dst_fsp,
240 &state->dup_extents);
241 if (!NT_STATUS_IS_OK(status)) {
242 tevent_req_nterror(req, status);
243 return tevent_req_post(req, ev);
246 if (state->dup_extents.byte_count == 0) {
247 DBG_ERR("skipping zero length dup extents\n");
248 tevent_req_done(req);
249 return tevent_req_post(req, ev);
252 status = fsctl_dup_extents_check_overlap(src_fsp, dst_fsp,
253 &state->dup_extents);
254 if (!NT_STATUS_IS_OK(status)) {
255 tevent_req_nterror(req, status);
256 return tevent_req_post(req, ev);
259 status = fsctl_dup_extents_check_sparse(src_fsp, dst_fsp);
260 if (!NT_STATUS_IS_OK(status)) {
261 tevent_req_nterror(req, status);
262 return tevent_req_post(req, ev);
265 subreq = SMB_VFS_OFFLOAD_READ_SEND(state, ev, src_fsp,
266 FSCTL_DUP_EXTENTS_TO_FILE,
268 if (tevent_req_nomem(subreq, req)) {
269 return tevent_req_post(req, ev);
271 tevent_req_set_callback(subreq, fsctl_dup_extents_offload_read_done,
276 static void fsctl_dup_extents_offload_read_done(struct tevent_req *subreq)
278 struct tevent_req *req = tevent_req_callback_data(
279 subreq, struct tevent_req);
280 struct fsctl_dup_extents_state *state = tevent_req_data(
281 req, struct fsctl_dup_extents_state);
282 DATA_BLOB token_blob;
285 status = SMB_VFS_OFFLOAD_READ_RECV(subreq, state->dst_fsp->conn,
287 if (tevent_req_nterror(req, status)) {
291 /* tell the VFS to ignore locks across the clone, matching ReFS */
292 subreq = SMB_VFS_OFFLOAD_WRITE_SEND(state->dst_fsp->conn,
296 state->dup_extents.source_off,
298 state->dup_extents.target_off,
299 state->dup_extents.byte_count,
300 VFS_OFFLOAD_WRITE_FL_MUST_CLONE
301 | VFS_OFFLOAD_WRITE_FL_IGNORE_LOCKS);
302 if (tevent_req_nomem(subreq, req)) {
305 tevent_req_set_callback(subreq, fsctl_dup_extents_vfs_done, req);
309 static void fsctl_dup_extents_vfs_done(struct tevent_req *subreq)
311 struct tevent_req *req = tevent_req_callback_data(
312 subreq, struct tevent_req);
313 struct fsctl_dup_extents_state *state = tevent_req_data(
314 req, struct fsctl_dup_extents_state);
318 status = SMB_VFS_OFFLOAD_WRITE_RECV(state->conn, subreq, &nb_chunk);
320 if (tevent_req_nterror(req, status)) {
324 if (nb_chunk != state->dup_extents.byte_count) {
325 tevent_req_nterror(req, NT_STATUS_IO_DEVICE_ERROR);
329 tevent_req_done(req);
332 static NTSTATUS fsctl_dup_extents_recv(struct tevent_req *req)
334 return tevent_req_simple_recv_ntstatus(req);
337 static NTSTATUS fsctl_get_cmprn(TALLOC_CTX *mem_ctx,
338 struct tevent_context *ev,
339 struct files_struct *fsp,
340 size_t in_max_output,
341 DATA_BLOB *out_output)
343 struct compression_state cmpr_state;
344 enum ndr_err_code ndr_ret;
349 return NT_STATUS_FILE_CLOSED;
352 /* Windows doesn't check for SEC_FILE_READ_ATTRIBUTE permission here */
354 ZERO_STRUCT(cmpr_state);
355 if (fsp->conn->fs_capabilities & FILE_FILE_COMPRESSION) {
356 status = SMB_VFS_GET_COMPRESSION(fsp->conn,
361 if (!NT_STATUS_IS_OK(status)) {
366 * bso#12144: The underlying filesystem doesn't support
367 * compression, so we should respond with "not-compressed"
368 * (like WS2016 ReFS) instead of STATUS_NOT_SUPPORTED or
369 * NT_STATUS_INVALID_DEVICE_REQUEST.
371 cmpr_state.format = COMPRESSION_FORMAT_NONE;
374 ndr_ret = ndr_push_struct_blob(&output, mem_ctx,
376 (ndr_push_flags_fn_t)ndr_push_compression_state);
377 if (ndr_ret != NDR_ERR_SUCCESS) {
378 return NT_STATUS_INTERNAL_ERROR;
381 if (in_max_output < output.length) {
382 DEBUG(1, ("max output %u too small for compression state %ld\n",
383 (unsigned int)in_max_output, (long int)output.length));
384 return NT_STATUS_INVALID_USER_BUFFER;
386 *out_output = output;
391 static NTSTATUS fsctl_set_cmprn(TALLOC_CTX *mem_ctx,
392 struct tevent_context *ev,
393 struct files_struct *fsp,
396 struct compression_state cmpr_state;
397 enum ndr_err_code ndr_ret;
401 return NT_STATUS_FILE_CLOSED;
404 /* WRITE_DATA permission is required, WRITE_ATTRIBUTES is not */
405 status = check_access_fsp(fsp, FILE_WRITE_DATA);
406 if (!NT_STATUS_IS_OK(status)) {
410 ndr_ret = ndr_pull_struct_blob(in_input, mem_ctx, &cmpr_state,
411 (ndr_pull_flags_fn_t)ndr_pull_compression_state);
412 if (ndr_ret != NDR_ERR_SUCCESS) {
413 DEBUG(0, ("failed to unmarshall set compression req\n"));
414 return NT_STATUS_INVALID_PARAMETER;
417 status = NT_STATUS_NOT_SUPPORTED;
418 if (fsp->conn->fs_capabilities & FILE_FILE_COMPRESSION) {
419 status = SMB_VFS_SET_COMPRESSION(fsp->conn,
423 } else if (cmpr_state.format == COMPRESSION_FORMAT_NONE) {
425 * bso#12144: The underlying filesystem doesn't support
426 * compression. We should still accept set(FORMAT_NONE) requests
427 * (like WS2016 ReFS).
429 status = NT_STATUS_OK;
435 static NTSTATUS fsctl_zero_data(TALLOC_CTX *mem_ctx,
436 struct tevent_context *ev,
437 struct files_struct *fsp,
440 struct file_zero_data_info zdata_info;
441 enum ndr_err_code ndr_ret;
442 struct lock_struct lck;
449 return NT_STATUS_FILE_CLOSED;
452 /* WRITE_DATA permission is required */
453 status = check_access_fsp(fsp, FILE_WRITE_DATA);
454 if (!NT_STATUS_IS_OK(status)) {
458 /* allow regardless of whether FS supports sparse or not */
460 ndr_ret = ndr_pull_struct_blob(in_input, mem_ctx, &zdata_info,
461 (ndr_pull_flags_fn_t)ndr_pull_file_zero_data_info);
462 if (ndr_ret != NDR_ERR_SUCCESS) {
463 DEBUG(0, ("failed to unmarshall zero data request\n"));
464 return NT_STATUS_INVALID_PARAMETER;
467 if (zdata_info.beyond_final_zero < zdata_info.file_off) {
468 DEBUG(0, ("invalid zero data params: off %lu, bfz, %lu\n",
469 (unsigned long)zdata_info.file_off,
470 (unsigned long)zdata_info.beyond_final_zero));
471 return NT_STATUS_INVALID_PARAMETER;
474 /* convert strange "beyond final zero" param into length */
475 len = zdata_info.beyond_final_zero - zdata_info.file_off;
478 DEBUG(2, ("zero data called with zero length range\n"));
482 init_strict_lock_struct(fsp,
483 fsp->op->global->open_persistent_id,
489 if (!SMB_VFS_STRICT_LOCK(fsp->conn, fsp, &lck)) {
490 DEBUG(2, ("failed to lock range for zero-data\n"));
491 return NT_STATUS_FILE_LOCK_CONFLICT;
495 * MS-FSCC <58> Section 2.3.67
496 * This FSCTL sets the range of bytes to zero (0) without extending the
499 * The VFS_FALLOCATE_FL_KEEP_SIZE flag is used to satisfy this
503 mode = VFS_FALLOCATE_FL_PUNCH_HOLE | VFS_FALLOCATE_FL_KEEP_SIZE;
504 ret = SMB_VFS_FALLOCATE(fsp, mode, zdata_info.file_off, len);
506 status = map_nt_error_from_unix_common(errno);
507 DEBUG(2, ("zero-data fallocate(0x%x) failed: %s\n", mode,
509 SMB_VFS_STRICT_UNLOCK(fsp->conn, fsp, &lck);
513 if (!fsp->is_sparse && lp_strict_allocate(SNUM(fsp->conn))) {
515 * File marked non-sparse and "strict allocate" is enabled -
516 * allocate the range that we just punched out.
517 * In future FALLOC_FL_ZERO_RANGE could be used exclusively for
518 * this, but it's currently only supported on XFS and ext4.
520 * The newly allocated range still won't be found by SEEK_DATA
521 * for QAR, but stat.st_blocks will reflect it.
523 ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_FL_KEEP_SIZE,
524 zdata_info.file_off, len);
526 status = map_nt_error_from_unix_common(errno);
527 DEBUG(0, ("fallocate failed: %s\n", strerror(errno)));
528 SMB_VFS_STRICT_UNLOCK(fsp->conn, fsp, &lck);
533 SMB_VFS_STRICT_UNLOCK(fsp->conn, fsp, &lck);
537 static NTSTATUS fsctl_qar_buf_push(TALLOC_CTX *mem_ctx,
538 struct file_alloced_range_buf *qar_buf,
539 DATA_BLOB *qar_array_blob)
542 enum ndr_err_code ndr_ret;
545 ndr_ret = ndr_push_struct_blob(&new_slot, mem_ctx, qar_buf,
546 (ndr_push_flags_fn_t)ndr_push_file_alloced_range_buf);
547 if (ndr_ret != NDR_ERR_SUCCESS) {
548 DEBUG(0, ("failed to marshall QAR buf\n"));
549 return NT_STATUS_INVALID_PARAMETER;
552 /* TODO should be able to avoid copy by pushing into prealloced buf */
553 ok = data_blob_append(mem_ctx, qar_array_blob, new_slot.data,
555 data_blob_free(&new_slot);
557 return NT_STATUS_NO_MEMORY;
563 static NTSTATUS fsctl_qar_seek_fill(TALLOC_CTX *mem_ctx,
564 struct files_struct *fsp,
567 DATA_BLOB *qar_array_blob)
569 NTSTATUS status = NT_STATUS_NOT_SUPPORTED;
571 #ifdef HAVE_LSEEK_HOLE_DATA
572 while (curr_off <= max_off) {
575 struct file_alloced_range_buf qar_buf;
578 data_off = SMB_VFS_LSEEK(fsp, curr_off, SEEK_DATA);
579 if ((data_off == -1) && (errno == ENXIO)) {
580 /* no data from curr_off to EOF */
582 } else if (data_off == -1) {
583 status = map_nt_error_from_unix_common(errno);
584 DEBUG(1, ("lseek data failed: %s\n", strerror(errno)));
588 if (data_off > max_off) {
589 /* found something, but passed range of interest */
593 hole_off = SMB_VFS_LSEEK(fsp, data_off, SEEK_HOLE);
594 if (hole_off == -1) {
595 status = map_nt_error_from_unix_common(errno);
596 DEBUG(1, ("lseek hole failed: %s\n", strerror(errno)));
600 if (hole_off <= data_off) {
601 DEBUG(1, ("lseek inconsistent: hole %lu at or before "
602 "data %lu\n", (unsigned long)hole_off,
603 (unsigned long)data_off));
604 return NT_STATUS_INTERNAL_ERROR;
607 qar_buf.file_off = data_off;
608 /* + 1 to convert maximum offset to length */
609 qar_buf.len = MIN(hole_off, max_off + 1) - data_off;
611 status = fsctl_qar_buf_push(mem_ctx, &qar_buf, qar_array_blob);
612 if (!NT_STATUS_IS_OK(status)) {
613 return NT_STATUS_NO_MEMORY;
618 status = NT_STATUS_OK;
624 static NTSTATUS fsctl_qar(TALLOC_CTX *mem_ctx,
625 struct tevent_context *ev,
626 struct files_struct *fsp,
628 size_t in_max_output,
629 DATA_BLOB *out_output)
631 struct fsctl_query_alloced_ranges_req qar_req;
632 struct fsctl_query_alloced_ranges_rsp qar_rsp;
633 DATA_BLOB qar_array_blob = data_blob_null;
635 enum ndr_err_code ndr_ret;
638 SMB_STRUCT_STAT sbuf;
641 return NT_STATUS_FILE_CLOSED;
644 /* READ_DATA permission is required */
645 status = check_access_fsp(fsp, FILE_READ_DATA);
646 if (!NT_STATUS_IS_OK(status)) {
650 ndr_ret = ndr_pull_struct_blob(in_input, mem_ctx, &qar_req,
651 (ndr_pull_flags_fn_t)ndr_pull_fsctl_query_alloced_ranges_req);
652 if (ndr_ret != NDR_ERR_SUCCESS) {
653 DEBUG(0, ("failed to unmarshall QAR req\n"));
654 return NT_STATUS_INVALID_PARAMETER;
658 * XXX Windows Server 2008 & 2012 servers don't return lock-conflict
659 * for QAR requests over an exclusively locked range!
662 ret = SMB_VFS_FSTAT(fsp, &sbuf);
664 status = map_nt_error_from_unix_common(errno);
665 DEBUG(2, ("fstat failed: %s\n", strerror(errno)));
669 if ((qar_req.buf.len == 0)
670 || (sbuf.st_ex_size == 0)
671 || (qar_req.buf.file_off >= sbuf.st_ex_size)) {
672 /* zero length range or after EOF, no ranges to return */
676 /* check for integer overflow */
677 if (qar_req.buf.file_off + qar_req.buf.len < qar_req.buf.file_off) {
678 return NT_STATUS_INVALID_PARAMETER;
682 * Maximum offset is either the last valid offset _before_ EOF, or the
683 * last byte offset within the requested range. -1 converts length to
684 * offset, which is easier to work with for SEEK_DATA/SEEK_HOLE, E.g.:
686 * /off=0 /off=512K /st_ex_size=1M
687 * |-------------------------------------|
689 * |-------------------------------------|
691 * |=====================================|
692 * | QAR off=512K, len=1M |
693 * |=================^===================|
696 * |==================|
697 * |QAR off=0 len=512K|
698 * |==================|
702 max_off = MIN(sbuf.st_ex_size,
703 qar_req.buf.file_off + qar_req.buf.len) - 1;
705 if (!fsp->is_sparse) {
706 struct file_alloced_range_buf qar_buf;
708 /* file is non-sparse, claim file_off->max_off is allocated */
709 qar_buf.file_off = qar_req.buf.file_off;
710 /* + 1 to convert maximum offset back to length */
711 qar_buf.len = max_off - qar_req.buf.file_off + 1;
713 status = fsctl_qar_buf_push(mem_ctx, &qar_buf, &qar_array_blob);
715 status = fsctl_qar_seek_fill(mem_ctx, fsp, qar_req.buf.file_off,
716 max_off, &qar_array_blob);
718 if (!NT_STATUS_IS_OK(status)) {
722 /* marshall response buffer. */
723 qar_rsp.far_buf_array = qar_array_blob;
725 ndr_ret = ndr_push_struct_blob(out_output, mem_ctx, &qar_rsp,
726 (ndr_push_flags_fn_t)ndr_push_fsctl_query_alloced_ranges_rsp);
727 if (ndr_ret != NDR_ERR_SUCCESS) {
728 DEBUG(0, ("failed to marshall QAR rsp\n"));
729 return NT_STATUS_INVALID_PARAMETER;
732 if (out_output->length > in_max_output) {
733 DEBUG(2, ("QAR output len %lu exceeds max %lu\n",
734 (unsigned long)out_output->length,
735 (unsigned long)in_max_output));
736 data_blob_free(out_output);
737 return NT_STATUS_BUFFER_TOO_SMALL;
743 static void smb2_ioctl_filesys_dup_extents_done(struct tevent_req *subreq);
745 struct tevent_req *smb2_ioctl_filesys(uint32_t ctl_code,
746 struct tevent_context *ev,
747 struct tevent_req *req,
748 struct smbd_smb2_ioctl_state *state)
753 case FSCTL_GET_COMPRESSION:
754 status = fsctl_get_cmprn(state, ev, state->fsp,
755 state->in_max_output,
757 if (!tevent_req_nterror(req, status)) {
758 tevent_req_done(req);
760 return tevent_req_post(req, ev);
762 case FSCTL_SET_COMPRESSION:
763 status = fsctl_set_cmprn(state, ev, state->fsp,
765 if (!tevent_req_nterror(req, status)) {
766 tevent_req_done(req);
768 return tevent_req_post(req, ev);
770 case FSCTL_SET_ZERO_DATA:
771 status = fsctl_zero_data(state, ev, state->fsp,
773 if (!tevent_req_nterror(req, status)) {
774 tevent_req_done(req);
776 return tevent_req_post(req, ev);
778 case FSCTL_QUERY_ALLOCATED_RANGES:
779 status = fsctl_qar(state, ev, state->fsp,
781 state->in_max_output,
783 if (!tevent_req_nterror(req, status)) {
784 tevent_req_done(req);
786 return tevent_req_post(req, ev);
788 case FSCTL_DUP_EXTENTS_TO_FILE: {
789 struct tevent_req *subreq = NULL;
791 subreq = fsctl_dup_extents_send(state, ev,
795 if (tevent_req_nomem(subreq, req)) {
796 return tevent_req_post(req, ev);
798 tevent_req_set_callback(subreq,
799 smb2_ioctl_filesys_dup_extents_done,
805 uint8_t *out_data = NULL;
806 uint32_t out_data_len = 0;
808 if (state->fsp == NULL) {
809 status = NT_STATUS_NOT_SUPPORTED;
811 status = SMB_VFS_FSCTL(state->fsp,
814 state->smbreq->flags2,
815 state->in_input.data,
816 state->in_input.length,
818 state->in_max_output,
820 state->out_output = data_blob_const(out_data, out_data_len);
821 if (NT_STATUS_IS_OK(status)) {
822 tevent_req_done(req);
823 return tevent_req_post(req, ev);
827 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
828 if (IS_IPC(state->smbreq->conn)) {
829 status = NT_STATUS_FS_DRIVER_REQUIRED;
831 status = NT_STATUS_INVALID_DEVICE_REQUEST;
835 tevent_req_nterror(req, status);
836 return tevent_req_post(req, ev);
841 tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
842 return tevent_req_post(req, ev);
845 static void smb2_ioctl_filesys_dup_extents_done(struct tevent_req *subreq)
847 struct tevent_req *req = tevent_req_callback_data(subreq,
851 status = fsctl_dup_extents_recv(subreq);
853 if (!tevent_req_nterror(req, status)) {
854 tevent_req_done(req);