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