xref: /titanic_41/usr/src/uts/common/fs/smbsrv/smb_close.c (revision 80e2ca8596e3435bc3b76f3c597833ea0a87f85e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <smbsrv/smb_kproto.h>
27 
28 /*
29  * Close a file by fid.  All locks or other resources held by the
30  * requesting process on the file should be released by the server.
31  * The requesting process can no longer use the fid for further
32  * file access requests.
33  *
34  * If LastWriteTime is non-zero, it should be used to set the file
35  * timestamp.  Otherwise, file system should set the timestamp.
36  * Failure to set the timestamp, even if requested by the client,
37  * should not result in an error response from the server.
38  */
39 smb_sdrc_t
40 smb_pre_close(smb_request_t *sr)
41 {
42 	int rc;
43 
44 	rc = smbsr_decode_vwv(sr, "wl", &sr->smb_fid, &sr->arg.timestamp);
45 
46 	DTRACE_SMB_1(op__Close__start, smb_request_t *, sr);
47 	return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
48 }
49 
50 void
51 smb_post_close(smb_request_t *sr)
52 {
53 	DTRACE_SMB_1(op__Close__done, smb_request_t *, sr);
54 }
55 
56 smb_sdrc_t
57 smb_com_close(smb_request_t *sr)
58 {
59 	smbsr_lookup_file(sr);
60 	if (sr->fid_ofile == NULL) {
61 		smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
62 		return (SDRC_ERROR);
63 	}
64 
65 	smb_ofile_close(sr->fid_ofile, sr->arg.timestamp);
66 
67 	if (smbsr_encode_empty_result(sr) != 0)
68 		return (SDRC_ERROR);
69 
70 	return (SDRC_SUCCESS);
71 }
72 
73 /*
74  * Close the file represented by fid and then disconnect the
75  * associated tree.
76  */
77 smb_sdrc_t
78 smb_pre_close_and_tree_disconnect(smb_request_t *sr)
79 {
80 	int rc;
81 
82 	rc = smbsr_decode_vwv(sr, "wl", &sr->smb_fid, &sr->arg.timestamp);
83 
84 	DTRACE_SMB_1(op__CloseAndTreeDisconnect__start, smb_request_t *, sr);
85 	return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
86 }
87 
88 void
89 smb_post_close_and_tree_disconnect(smb_request_t *sr)
90 {
91 	DTRACE_SMB_1(op__CloseAndTreeDisconnect__done, smb_request_t *, sr);
92 }
93 
94 smb_sdrc_t
95 smb_com_close_and_tree_disconnect(smb_request_t *sr)
96 {
97 	smbsr_lookup_file(sr);
98 	if (sr->fid_ofile == NULL) {
99 		smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
100 		return (SDRC_ERROR);
101 	}
102 
103 	smb_ofile_close(sr->fid_ofile, sr->arg.timestamp);
104 	smb_session_cancel_requests(sr->session, sr->tid_tree, sr);
105 	smb_tree_disconnect(sr->tid_tree, B_TRUE);
106 
107 	if (smbsr_encode_empty_result(sr) != 0)
108 		return (SDRC_ERROR);
109 
110 	return (SDRC_SUCCESS);
111 }
112