1da6c28aaSamw /*
2da6c28aaSamw * CDDL HEADER START
3da6c28aaSamw *
4da6c28aaSamw * The contents of this file are subject to the terms of the
5da6c28aaSamw * Common Development and Distribution License (the "License").
6da6c28aaSamw * You may not use this file except in compliance with the License.
7da6c28aaSamw *
8da6c28aaSamw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da6c28aaSamw * or http://www.opensolaris.org/os/licensing.
10da6c28aaSamw * See the License for the specific language governing permissions
11da6c28aaSamw * and limitations under the License.
12da6c28aaSamw *
13da6c28aaSamw * When distributing Covered Code, include this CDDL HEADER in each
14da6c28aaSamw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da6c28aaSamw * If applicable, add the following below this CDDL HEADER, with the
16da6c28aaSamw * fields enclosed by brackets "[]" replaced with your own identifying
17da6c28aaSamw * information: Portions Copyright [yyyy] [name of copyright owner]
18da6c28aaSamw *
19da6c28aaSamw * CDDL HEADER END
20da6c28aaSamw */
21da6c28aaSamw /*
222c2961f8Sjose borrego * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23da6c28aaSamw * Use is subject to license terms.
245fd03bc0SGordon Ross *
25*93bc28dbSGordon Ross * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
26da6c28aaSamw */
27da6c28aaSamw
28bbf6f00cSJordan Brown #include <smbsrv/smb_kproto.h>
29da6c28aaSamw
30da6c28aaSamw /*
31da6c28aaSamw * Close a file by fid. All locks or other resources held by the
32da6c28aaSamw * requesting process on the file should be released by the server.
33da6c28aaSamw * The requesting process can no longer use the fid for further
34da6c28aaSamw * file access requests.
35da6c28aaSamw *
36da6c28aaSamw * If LastWriteTime is non-zero, it should be used to set the file
37da6c28aaSamw * timestamp. Otherwise, file system should set the timestamp.
38da6c28aaSamw * Failure to set the timestamp, even if requested by the client,
39da6c28aaSamw * should not result in an error response from the server.
40da6c28aaSamw */
417b59d02dSjb smb_sdrc_t
smb_pre_close(smb_request_t * sr)42faa1795aSjb smb_pre_close(smb_request_t *sr)
43da6c28aaSamw {
44faa1795aSjb int rc;
45da6c28aaSamw
46faa1795aSjb rc = smbsr_decode_vwv(sr, "wl", &sr->smb_fid, &sr->arg.timestamp);
47faa1795aSjb
48*93bc28dbSGordon Ross DTRACE_SMB_START(op__Close, smb_request_t *, sr);
49faa1795aSjb return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
50faa1795aSjb }
51faa1795aSjb
52faa1795aSjb void
smb_post_close(smb_request_t * sr)53faa1795aSjb smb_post_close(smb_request_t *sr)
54faa1795aSjb {
55*93bc28dbSGordon Ross DTRACE_SMB_DONE(op__Close, smb_request_t *, sr);
56faa1795aSjb }
57faa1795aSjb
58faa1795aSjb smb_sdrc_t
smb_com_close(smb_request_t * sr)59faa1795aSjb smb_com_close(smb_request_t *sr)
60faa1795aSjb {
615fd03bc0SGordon Ross int32_t mtime;
625fd03bc0SGordon Ross
632c2961f8Sjose borrego smbsr_lookup_file(sr);
64da6c28aaSamw if (sr->fid_ofile == NULL) {
65dc20a302Sas smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
66faa1795aSjb return (SDRC_ERROR);
67da6c28aaSamw }
68da6c28aaSamw
695fd03bc0SGordon Ross mtime = smb_time_local_to_gmt(sr, sr->arg.timestamp);
705fd03bc0SGordon Ross smb_ofile_close(sr->fid_ofile, mtime);
71c8ec8eeaSjose borrego
72c8ec8eeaSjose borrego if (smbsr_encode_empty_result(sr) != 0)
73faa1795aSjb return (SDRC_ERROR);
74da6c28aaSamw
75c8ec8eeaSjose borrego return (SDRC_SUCCESS);
76da6c28aaSamw }
77da6c28aaSamw
78da6c28aaSamw /*
79da6c28aaSamw * Close the file represented by fid and then disconnect the
80da6c28aaSamw * associated tree.
81da6c28aaSamw */
827b59d02dSjb smb_sdrc_t
smb_pre_close_and_tree_disconnect(smb_request_t * sr)83faa1795aSjb smb_pre_close_and_tree_disconnect(smb_request_t *sr)
84da6c28aaSamw {
85faa1795aSjb int rc;
86da6c28aaSamw
87faa1795aSjb rc = smbsr_decode_vwv(sr, "wl", &sr->smb_fid, &sr->arg.timestamp);
88faa1795aSjb
89*93bc28dbSGordon Ross DTRACE_SMB_START(op__CloseAndTreeDisconnect, smb_request_t *, sr);
90faa1795aSjb return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
91faa1795aSjb }
92faa1795aSjb
93faa1795aSjb void
smb_post_close_and_tree_disconnect(smb_request_t * sr)94faa1795aSjb smb_post_close_and_tree_disconnect(smb_request_t *sr)
95faa1795aSjb {
96*93bc28dbSGordon Ross DTRACE_SMB_DONE(op__CloseAndTreeDisconnect, smb_request_t *, sr);
97faa1795aSjb }
98faa1795aSjb
99faa1795aSjb smb_sdrc_t
smb_com_close_and_tree_disconnect(smb_request_t * sr)100faa1795aSjb smb_com_close_and_tree_disconnect(smb_request_t *sr)
101faa1795aSjb {
1025fd03bc0SGordon Ross int32_t mtime;
1035fd03bc0SGordon Ross
1042c2961f8Sjose borrego smbsr_lookup_file(sr);
105da6c28aaSamw if (sr->fid_ofile == NULL) {
106dc20a302Sas smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
107faa1795aSjb return (SDRC_ERROR);
108da6c28aaSamw }
109da6c28aaSamw
1105fd03bc0SGordon Ross mtime = smb_time_local_to_gmt(sr, sr->arg.timestamp);
1115fd03bc0SGordon Ross smb_ofile_close(sr->fid_ofile, mtime);
1120897f7fbSGordon Ross
11329bd2886SAlan Wright smb_tree_disconnect(sr->tid_tree, B_TRUE);
1140897f7fbSGordon Ross smb_session_cancel_requests(sr->session, sr->tid_tree, sr);
115da6c28aaSamw
116c8ec8eeaSjose borrego if (smbsr_encode_empty_result(sr) != 0)
117faa1795aSjb return (SDRC_ERROR);
118da6c28aaSamw
119c8ec8eeaSjose borrego return (SDRC_SUCCESS);
120da6c28aaSamw }
121