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