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. 24da6c28aaSamw */ 25da6c28aaSamw /* 26da6c28aaSamw * SMB: lock_byte_range 27da6c28aaSamw * 28da6c28aaSamw * The lock record message is sent to lock the given byte range. More than 29da6c28aaSamw * one non-overlapping byte range may be locked in a given file. Locks 30da6c28aaSamw * prevent attempts to lock, read or write the locked portion of the file 31da6c28aaSamw * by other clients or Pids. Overlapping locks are not allowed. Offsets 32da6c28aaSamw * beyond the current end of file may be locked. Such locks will not cause 33da6c28aaSamw * allocation of file space. 34da6c28aaSamw * 35da6c28aaSamw * Since Offset is a 32 bit quantity, this request is inappropriate for 36da6c28aaSamw * general locking within a very large file. 37da6c28aaSamw * 38da6c28aaSamw * Client Request Description 39da6c28aaSamw * ================================== ================================= 40da6c28aaSamw * 41da6c28aaSamw * UCHAR WordCount; Count of parameter words = 5 42da6c28aaSamw * USHORT Fid; File handle 43da6c28aaSamw * ULONG Count; Count of bytes to lock 44da6c28aaSamw * ULONG Offset; Offset from start of file 45da6c28aaSamw * USHORT ByteCount; Count of data bytes = 0 46da6c28aaSamw * 47da6c28aaSamw * Locks may only be unlocked by the Pid that performed the lock. 48da6c28aaSamw * 49da6c28aaSamw * Server Response Description 50da6c28aaSamw * ================================== ================================= 51da6c28aaSamw * 52da6c28aaSamw * UCHAR WordCount; Count of parameter words = 0 53da6c28aaSamw * USHORT ByteCount; Count of data bytes = 0 54da6c28aaSamw * 55da6c28aaSamw * This client request does not wait for the lock to be granted. If the 56da6c28aaSamw * lock can not be immediately granted (within 200-300 ms), the server 57da6c28aaSamw * should return failure to the client 58da6c28aaSamw */ 59da6c28aaSamw 60*bbf6f00cSJordan Brown #include <smbsrv/smb_kproto.h> 61da6c28aaSamw 62faa1795aSjb smb_sdrc_t 63faa1795aSjb smb_pre_lock_byte_range(smb_request_t *sr) 64faa1795aSjb { 65faa1795aSjb DTRACE_SMB_1(op__LockByteRange__start, smb_request_t *, sr); 66faa1795aSjb return (SDRC_SUCCESS); 67faa1795aSjb } 68faa1795aSjb 69faa1795aSjb void 70faa1795aSjb smb_post_lock_byte_range(smb_request_t *sr) 71faa1795aSjb { 72faa1795aSjb DTRACE_SMB_1(op__LockByteRange__done, smb_request_t *, sr); 73faa1795aSjb } 74faa1795aSjb 757b59d02dSjb smb_sdrc_t 76da6c28aaSamw smb_com_lock_byte_range(struct smb_request *sr) 77da6c28aaSamw { 78da6c28aaSamw uint32_t count; 79da6c28aaSamw uint32_t off; 80da6c28aaSamw DWORD result; 817b59d02dSjb int rc; 82da6c28aaSamw 837b59d02dSjb if (smbsr_decode_vwv(sr, "wll", &sr->smb_fid, &count, &off) != 0) 84faa1795aSjb return (SDRC_ERROR); 85da6c28aaSamw 862c2961f8Sjose borrego smbsr_lookup_file(sr); 87da6c28aaSamw if (sr->fid_ofile == NULL) { 88dc20a302Sas smbsr_error(sr, NT_STATUS_INVALID_HANDLE, 89da6c28aaSamw ERRDOS, ERRbadfid); 90faa1795aSjb return (SDRC_ERROR); 91da6c28aaSamw } 92da6c28aaSamw 93da6c28aaSamw /* 94da6c28aaSamw * The last parameter is lock type. This is dependent on 95da6c28aaSamw * lock flag (3rd parameter). Since the lock flag is 96da6c28aaSamw * set to be exclusive, lock type is passed as 97da6c28aaSamw * normal lock (write lock). 98da6c28aaSamw */ 996537f381Sas result = smb_lock_range(sr, (u_offset_t)off, (uint64_t)count, 0, 1006537f381Sas SMB_LOCK_TYPE_READWRITE); 101da6c28aaSamw if (result != NT_STATUS_SUCCESS) { 102dc20a302Sas smb_lock_range_error(sr, result); 103faa1795aSjb return (SDRC_ERROR); 104da6c28aaSamw } 105da6c28aaSamw 1067b59d02dSjb rc = smbsr_encode_empty_result(sr); 107faa1795aSjb return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR); 108da6c28aaSamw } 109