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 /*
265331Samw * SMB: lock_byte_range
275331Samw *
285331Samw * The lock record message is sent to lock the given byte range. More than
295331Samw * one non-overlapping byte range may be locked in a given file. Locks
305331Samw * prevent attempts to lock, read or write the locked portion of the file
315331Samw * by other clients or Pids. Overlapping locks are not allowed. Offsets
325331Samw * beyond the current end of file may be locked. Such locks will not cause
335331Samw * allocation of file space.
345331Samw *
355331Samw * Since Offset is a 32 bit quantity, this request is inappropriate for
365331Samw * general locking within a very large file.
375331Samw *
385331Samw * Client Request Description
395331Samw * ================================== =================================
405331Samw *
415331Samw * UCHAR WordCount; Count of parameter words = 5
425331Samw * USHORT Fid; File handle
435331Samw * ULONG Count; Count of bytes to lock
445331Samw * ULONG Offset; Offset from start of file
455331Samw * USHORT ByteCount; Count of data bytes = 0
465331Samw *
475331Samw * Locks may only be unlocked by the Pid that performed the lock.
485331Samw *
495331Samw * Server Response Description
505331Samw * ================================== =================================
515331Samw *
525331Samw * UCHAR WordCount; Count of parameter words = 0
535331Samw * USHORT ByteCount; Count of data bytes = 0
545331Samw *
555331Samw * This client request does not wait for the lock to be granted. If the
565331Samw * lock can not be immediately granted (within 200-300 ms), the server
575331Samw * should return failure to the client
585331Samw */
595331Samw
60*10966SJordan.Brown@Sun.COM #include <smbsrv/smb_kproto.h>
615331Samw
626030Sjb150015 smb_sdrc_t
smb_pre_lock_byte_range(smb_request_t * sr)636139Sjb150015 smb_pre_lock_byte_range(smb_request_t *sr)
646139Sjb150015 {
656139Sjb150015 DTRACE_SMB_1(op__LockByteRange__start, smb_request_t *, sr);
666139Sjb150015 return (SDRC_SUCCESS);
676139Sjb150015 }
686139Sjb150015
696139Sjb150015 void
smb_post_lock_byte_range(smb_request_t * sr)706139Sjb150015 smb_post_lock_byte_range(smb_request_t *sr)
716139Sjb150015 {
726139Sjb150015 DTRACE_SMB_1(op__LockByteRange__done, smb_request_t *, sr);
736139Sjb150015 }
746139Sjb150015
756139Sjb150015 smb_sdrc_t
smb_com_lock_byte_range(struct smb_request * sr)765331Samw smb_com_lock_byte_range(struct smb_request *sr)
775331Samw {
785331Samw uint32_t count;
795331Samw uint32_t off;
805331Samw DWORD result;
816030Sjb150015 int rc;
825331Samw
836030Sjb150015 if (smbsr_decode_vwv(sr, "wll", &sr->smb_fid, &count, &off) != 0)
846139Sjb150015 return (SDRC_ERROR);
855331Samw
868934SJose.Borrego@Sun.COM smbsr_lookup_file(sr);
875331Samw if (sr->fid_ofile == NULL) {
885772Sas200622 smbsr_error(sr, NT_STATUS_INVALID_HANDLE,
895331Samw ERRDOS, ERRbadfid);
906139Sjb150015 return (SDRC_ERROR);
915331Samw }
925331Samw
935331Samw /*
945331Samw * The last parameter is lock type. This is dependent on
955331Samw * lock flag (3rd parameter). Since the lock flag is
965331Samw * set to be exclusive, lock type is passed as
975331Samw * normal lock (write lock).
985331Samw */
996432Sas200622 result = smb_lock_range(sr, (u_offset_t)off, (uint64_t)count, 0,
1006432Sas200622 SMB_LOCK_TYPE_READWRITE);
1015331Samw if (result != NT_STATUS_SUCCESS) {
1025772Sas200622 smb_lock_range_error(sr, result);
1036139Sjb150015 return (SDRC_ERROR);
1045331Samw }
1055331Samw
1066030Sjb150015 rc = smbsr_encode_empty_result(sr);
1076139Sjb150015 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
1085331Samw }
109