15331Samw /*
25331Samw * CDDL HEADER START
35331Samw *
45331Samw * The contents of this file are subject to the terms of the
55331Samw * Common Development and Distribution License (the "License").
65331Samw * You may not use this file except in compliance with the License.
75331Samw *
85331Samw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95331Samw * or http://www.opensolaris.org/os/licensing.
105331Samw * See the License for the specific language governing permissions
115331Samw * and limitations under the License.
125331Samw *
135331Samw * When distributing Covered Code, include this CDDL HEADER in each
145331Samw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155331Samw * If applicable, add the following below this CDDL HEADER, with the
165331Samw * fields enclosed by brackets "[]" replaced with your own identifying
175331Samw * information: Portions Copyright [yyyy] [name of copyright owner]
185331Samw *
195331Samw * CDDL HEADER END
205331Samw */
215331Samw /*
228934SJose.Borrego@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
235331Samw * Use is subject to license terms.
245331Samw */
255331Samw
26*10966SJordan.Brown@Sun.COM #include <smbsrv/smb_kproto.h>
275331Samw
285331Samw /*
295331Samw * Close a file by fid. All locks or other resources held by the
305331Samw * requesting process on the file should be released by the server.
315331Samw * The requesting process can no longer use the fid for further
325331Samw * file access requests.
335331Samw *
345331Samw * If LastWriteTime is non-zero, it should be used to set the file
355331Samw * timestamp. Otherwise, file system should set the timestamp.
365331Samw * Failure to set the timestamp, even if requested by the client,
375331Samw * should not result in an error response from the server.
385331Samw */
396030Sjb150015 smb_sdrc_t
smb_pre_close(smb_request_t * sr)406139Sjb150015 smb_pre_close(smb_request_t *sr)
415331Samw {
426139Sjb150015 int rc;
436139Sjb150015
446139Sjb150015 rc = smbsr_decode_vwv(sr, "wl", &sr->smb_fid, &sr->arg.timestamp);
456139Sjb150015
466139Sjb150015 DTRACE_SMB_1(op__Close__start, smb_request_t *, sr);
476139Sjb150015 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
486139Sjb150015 }
495331Samw
506139Sjb150015 void
smb_post_close(smb_request_t * sr)516139Sjb150015 smb_post_close(smb_request_t *sr)
526139Sjb150015 {
536139Sjb150015 DTRACE_SMB_1(op__Close__done, smb_request_t *, sr);
546139Sjb150015 }
556139Sjb150015
566139Sjb150015 smb_sdrc_t
smb_com_close(smb_request_t * sr)576139Sjb150015 smb_com_close(smb_request_t *sr)
586139Sjb150015 {
598934SJose.Borrego@Sun.COM smbsr_lookup_file(sr);
605331Samw if (sr->fid_ofile == NULL) {
615772Sas200622 smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
626139Sjb150015 return (SDRC_ERROR);
635331Samw }
645331Samw
657348SJose.Borrego@Sun.COM smb_ofile_close(sr->fid_ofile, sr->arg.timestamp);
667348SJose.Borrego@Sun.COM
677348SJose.Borrego@Sun.COM if (smbsr_encode_empty_result(sr) != 0)
686139Sjb150015 return (SDRC_ERROR);
695331Samw
707348SJose.Borrego@Sun.COM return (SDRC_SUCCESS);
715331Samw }
725331Samw
735331Samw /*
745331Samw * Close the file represented by fid and then disconnect the
755331Samw * associated tree.
765331Samw */
776030Sjb150015 smb_sdrc_t
smb_pre_close_and_tree_disconnect(smb_request_t * sr)786139Sjb150015 smb_pre_close_and_tree_disconnect(smb_request_t *sr)
795331Samw {
806139Sjb150015 int rc;
816139Sjb150015
826139Sjb150015 rc = smbsr_decode_vwv(sr, "wl", &sr->smb_fid, &sr->arg.timestamp);
836139Sjb150015
846139Sjb150015 DTRACE_SMB_1(op__CloseAndTreeDisconnect__start, smb_request_t *, sr);
856139Sjb150015 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
866139Sjb150015 }
875331Samw
886139Sjb150015 void
smb_post_close_and_tree_disconnect(smb_request_t * sr)896139Sjb150015 smb_post_close_and_tree_disconnect(smb_request_t *sr)
906139Sjb150015 {
916139Sjb150015 DTRACE_SMB_1(op__CloseAndTreeDisconnect__done, smb_request_t *, sr);
926139Sjb150015 }
936139Sjb150015
946139Sjb150015 smb_sdrc_t
smb_com_close_and_tree_disconnect(smb_request_t * sr)956139Sjb150015 smb_com_close_and_tree_disconnect(smb_request_t *sr)
966139Sjb150015 {
978934SJose.Borrego@Sun.COM smbsr_lookup_file(sr);
985331Samw if (sr->fid_ofile == NULL) {
995772Sas200622 smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
1006139Sjb150015 return (SDRC_ERROR);
1015331Samw }
1025331Samw
1037348SJose.Borrego@Sun.COM smb_ofile_close(sr->fid_ofile, sr->arg.timestamp);
1047348SJose.Borrego@Sun.COM smb_session_cancel_requests(sr->session, sr->tid_tree, sr);
1059832Samw@Sun.COM smb_tree_disconnect(sr->tid_tree, B_TRUE);
1065331Samw
1077348SJose.Borrego@Sun.COM if (smbsr_encode_empty_result(sr) != 0)
1086139Sjb150015 return (SDRC_ERROR);
1095331Samw
1107348SJose.Borrego@Sun.COM return (SDRC_SUCCESS);
1115331Samw }
112