xref: /titanic_51/usr/src/uts/common/fs/smbsrv/smb_close.c (revision 14f1dfe8cc1a1f86b7a23d406ca317c05ce87cd6)
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_incl.h>
27 
28 
29 /*
30  * Close a file by fid.  All locks or other resources held by the
31  * requesting process on the file should be released by the server.
32  * The requesting process can no longer use the fid for further
33  * file access requests.
34  *
35  * If LastWriteTime is non-zero, it should be used to set the file
36  * timestamp.  Otherwise, file system should set the timestamp.
37  * Failure to set the timestamp, even if requested by the client,
38  * should not result in an error response from the server.
39  */
40 smb_sdrc_t
41 smb_pre_close(smb_request_t *sr)
42 {
43 	int rc;
44 
45 	rc = smbsr_decode_vwv(sr, "wl", &sr->smb_fid, &sr->arg.timestamp);
46 
47 	DTRACE_SMB_1(op__Close__start, smb_request_t *, sr);
48 	return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
49 }
50 
51 void
52 smb_post_close(smb_request_t *sr)
53 {
54 	DTRACE_SMB_1(op__Close__done, smb_request_t *, sr);
55 }
56 
57 smb_sdrc_t
58 smb_com_close(smb_request_t *sr)
59 {
60 	smbsr_lookup_file(sr);
61 	if (sr->fid_ofile == NULL) {
62 		smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
63 		return (SDRC_ERROR);
64 	}
65 
66 	smb_ofile_close(sr->fid_ofile, sr->arg.timestamp);
67 
68 	if (smbsr_encode_empty_result(sr) != 0)
69 		return (SDRC_ERROR);
70 
71 	return (SDRC_SUCCESS);
72 }
73 
74 /*
75  * Close the file represented by fid and then disconnect the
76  * associated tree.
77  */
78 smb_sdrc_t
79 smb_pre_close_and_tree_disconnect(smb_request_t *sr)
80 {
81 	int rc;
82 
83 	rc = smbsr_decode_vwv(sr, "wl", &sr->smb_fid, &sr->arg.timestamp);
84 
85 	DTRACE_SMB_1(op__CloseAndTreeDisconnect__start, smb_request_t *, sr);
86 	return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
87 }
88 
89 void
90 smb_post_close_and_tree_disconnect(smb_request_t *sr)
91 {
92 	DTRACE_SMB_1(op__CloseAndTreeDisconnect__done, smb_request_t *, sr);
93 }
94 
95 smb_sdrc_t
96 smb_com_close_and_tree_disconnect(smb_request_t *sr)
97 {
98 	smbsr_lookup_file(sr);
99 	if (sr->fid_ofile == NULL) {
100 		smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
101 		return (SDRC_ERROR);
102 	}
103 
104 	smb_ofile_close(sr->fid_ofile, sr->arg.timestamp);
105 	smb_session_cancel_requests(sr->session, sr->tid_tree, sr);
106 	smb_tree_disconnect(sr->tid_tree);
107 
108 	if (smbsr_encode_empty_result(sr) != 0)
109 		return (SDRC_ERROR);
110 
111 	return (SDRC_SUCCESS);
112 }
113