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. 24*5fd03bc0SGordon Ross * 25*5fd03bc0SGordon Ross * Copyright 2013 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 */ 417b59d02dSjb150015 smb_sdrc_t 42faa1795aSjb150015 smb_pre_close(smb_request_t *sr) 43da6c28aaSamw { 44faa1795aSjb150015 int rc; 45da6c28aaSamw 46faa1795aSjb150015 rc = smbsr_decode_vwv(sr, "wl", &sr->smb_fid, &sr->arg.timestamp); 47faa1795aSjb150015 48faa1795aSjb150015 DTRACE_SMB_1(op__Close__start, smb_request_t *, sr); 49faa1795aSjb150015 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR); 50faa1795aSjb150015 } 51faa1795aSjb150015 52faa1795aSjb150015 void 53faa1795aSjb150015 smb_post_close(smb_request_t *sr) 54faa1795aSjb150015 { 55faa1795aSjb150015 DTRACE_SMB_1(op__Close__done, smb_request_t *, sr); 56faa1795aSjb150015 } 57faa1795aSjb150015 58faa1795aSjb150015 smb_sdrc_t 59faa1795aSjb150015 smb_com_close(smb_request_t *sr) 60faa1795aSjb150015 { 61*5fd03bc0SGordon Ross int32_t mtime; 62*5fd03bc0SGordon Ross 632c2961f8Sjose borrego smbsr_lookup_file(sr); 64da6c28aaSamw if (sr->fid_ofile == NULL) { 65dc20a302Sas200622 smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid); 66faa1795aSjb150015 return (SDRC_ERROR); 67da6c28aaSamw } 68da6c28aaSamw 69*5fd03bc0SGordon Ross mtime = smb_time_local_to_gmt(sr, sr->arg.timestamp); 70*5fd03bc0SGordon Ross smb_ofile_close(sr->fid_ofile, mtime); 71da6c28aaSamw 72c8ec8eeaSjose borrego if (smbsr_encode_empty_result(sr) != 0) 73c8ec8eeaSjose borrego return (SDRC_ERROR); 74c8ec8eeaSjose borrego 75c8ec8eeaSjose borrego return (SDRC_SUCCESS); 76da6c28aaSamw } 77da6c28aaSamw 78da6c28aaSamw /* 79da6c28aaSamw * Close the file represented by fid and then disconnect the 80da6c28aaSamw * associated tree. 81da6c28aaSamw */ 827b59d02dSjb150015 smb_sdrc_t 83faa1795aSjb150015 smb_pre_close_and_tree_disconnect(smb_request_t *sr) 84da6c28aaSamw { 85faa1795aSjb150015 int rc; 86da6c28aaSamw 87faa1795aSjb150015 rc = smbsr_decode_vwv(sr, "wl", &sr->smb_fid, &sr->arg.timestamp); 88faa1795aSjb150015 89faa1795aSjb150015 DTRACE_SMB_1(op__CloseAndTreeDisconnect__start, smb_request_t *, sr); 90faa1795aSjb150015 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR); 91faa1795aSjb150015 } 92faa1795aSjb150015 93faa1795aSjb150015 void 94faa1795aSjb150015 smb_post_close_and_tree_disconnect(smb_request_t *sr) 95faa1795aSjb150015 { 96faa1795aSjb150015 DTRACE_SMB_1(op__CloseAndTreeDisconnect__done, smb_request_t *, sr); 97faa1795aSjb150015 } 98faa1795aSjb150015 99faa1795aSjb150015 smb_sdrc_t 100faa1795aSjb150015 smb_com_close_and_tree_disconnect(smb_request_t *sr) 101faa1795aSjb150015 { 102*5fd03bc0SGordon Ross int32_t mtime; 103*5fd03bc0SGordon Ross 1042c2961f8Sjose borrego smbsr_lookup_file(sr); 105da6c28aaSamw if (sr->fid_ofile == NULL) { 106dc20a302Sas200622 smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid); 107faa1795aSjb150015 return (SDRC_ERROR); 108da6c28aaSamw } 109da6c28aaSamw 110*5fd03bc0SGordon Ross mtime = smb_time_local_to_gmt(sr, sr->arg.timestamp); 111*5fd03bc0SGordon Ross smb_ofile_close(sr->fid_ofile, mtime); 112c8ec8eeaSjose borrego smb_session_cancel_requests(sr->session, sr->tid_tree, sr); 11329bd2886SAlan Wright smb_tree_disconnect(sr->tid_tree, B_TRUE); 114da6c28aaSamw 115c8ec8eeaSjose borrego if (smbsr_encode_empty_result(sr) != 0) 116faa1795aSjb150015 return (SDRC_ERROR); 117da6c28aaSamw 118c8ec8eeaSjose borrego return (SDRC_SUCCESS); 119da6c28aaSamw } 120