1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
14  * Copyright 2016 Syneto S.R.L. All rights reserved.
15  * Copyright 2023 RackTop Systems, Inc.
16  */
17 
18 /*
19  * Dispatch function for SMB2_FLUSH
20  */
21 
22 #include <smbsrv/smb2_kproto.h>
23 #include <smbsrv/smb_fsops.h>
24 
25 smb_sdrc_t
smb2_flush(smb_request_t * sr)26 smb2_flush(smb_request_t *sr)
27 {
28 	uint16_t StructSize;
29 	uint16_t reserved1;
30 	uint32_t reserved2;
31 	smb2fid_t smb2fid;
32 	uint32_t status;
33 	int rc = 0;
34 
35 	/*
36 	 * Decode SMB2 Flush request
37 	 */
38 	rc = smb_mbc_decodef(
39 	    &sr->smb_data, "wwlqq",
40 	    &StructSize,		/* w */
41 	    &reserved1,			/* w */
42 	    &reserved2,			/* l */
43 	    &smb2fid.persistent,	/* q */
44 	    &smb2fid.temporal);		/* q */
45 	if (rc || StructSize != 24)
46 		return (SDRC_ERROR);
47 
48 	/*
49 	 * Want FID lookup before the start probe.
50 	 */
51 	status = smb2sr_lookup_fid(sr, &smb2fid);
52 	DTRACE_SMB2_START(op__Flush, smb_request_t *, sr);
53 
54 	if (status == 0)
55 		smb_ofile_flush(sr, sr->fid_ofile);
56 
57 	sr->smb2_status = status;
58 	DTRACE_SMB2_DONE(op__Flush, smb_request_t *, sr);
59 
60 	if (status) {
61 		smb2sr_put_error(sr, status);
62 		return (SDRC_SUCCESS);
63 	}
64 
65 	/*
66 	 * SMB2 Flush reply
67 	 */
68 	(void) smb_mbc_encodef(
69 	    &sr->reply, "ww",
70 	    4,	/* StructSize */	/* w */
71 	    0); /* reserved */		/* w */
72 
73 	return (SDRC_SUCCESS);
74 }
75