xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb_unlock_byte_range.c (revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0)
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: unlock_byte_range
30  *
31  * This message is sent to unlock the given byte range.  Offset, Count, and
32  * Pid must be identical to that specified in a prior successful lock.  If
33  *
34  * an unlock references an address range that is not locked, no error is
35  * generated.
36  *
37  * Since Offset is a 32 bit quantity, this request is inappropriate for
38  * general locking within a very large file.
39  *
40  * Client Request                     Description
41  * ================================== =================================
42  *
43  * UCHAR WordCount;                   Count of parameter words = 5
44  * USHORT Fid;                        File handle
45  * ULONG Count;                       Count of bytes to unlock
46  * ULONG Offset;                      Offset from start of file
47  * USHORT ByteCount;                  Count of data bytes = 0
48  *
49  * Server Response                    Description
50  * ================================== =================================
51  *
52  * UCHAR WordCount;                   Count of parameter words = 0
53  * USHORT ByteCount;                  Count of data bytes = 0
54  */
55 
56 #include <smbsrv/smb_incl.h>
57 
58 int
59 smb_com_unlock_byte_range(struct smb_request *sr)
60 {
61 	uint32_t	Length;
62 	uint32_t	Offset;
63 	DWORD		result;
64 
65 	if (smbsr_decode_vwv(sr, "wll", &sr->smb_fid, &Length, &Offset) != 0) {
66 		smbsr_decode_error(sr);
67 		/* NOTREACHED */
68 	}
69 
70 	sr->fid_ofile = smb_ofile_lookup_by_fid(sr->tid_tree, sr->smb_fid);
71 	if (sr->fid_ofile == NULL) {
72 		smbsr_raise_cifs_error(sr, NT_STATUS_INVALID_HANDLE,
73 		    ERRDOS, ERRbadfid);
74 		/* NOTREACHED */
75 	}
76 
77 	result = smb_unlock_range(sr, sr->fid_ofile->f_node,
78 	    (off_t)Offset, (uint64_t)Length);
79 	if (result != NT_STATUS_SUCCESS) {
80 		smb_unlock_range_raise_error(sr, result);
81 		/* NOT REACHED */
82 	}
83 
84 	smbsr_encode_empty_result(sr);
85 
86 	return (SDRC_NORMAL_REPLY);
87 }
88