ReactOS 0.4.16-dev-91-g764881a
lock.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/client/file/lock.c
5 * PURPOSE: Directory functions
6 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
7 * UPDATE HISTORY:
8 * Created 01/11/98
9 */
10
11
12/* INCLUDES ****************************************************************/
13
14#include <k32.h>
15#define NDEBUG
16#include <debug.h>
17
18/* FUNCTIONS ****************************************************************/
19
20/*
21 * @implemented
22 */
23BOOL
26 IN DWORD dwFileOffsetLow,
27 IN DWORD dwFileOffsetHigh,
28 IN DWORD nNumberOfBytesToLockLow,
29 IN DWORD nNumberOfBytesToLockHigh)
30{
33 LARGE_INTEGER BytesToLock, Offset;
34
35 /* Is this a console handle? */
37 {
38 /* Can't "lock" a console! */
40 return FALSE;
41 }
42
43 /* Setup the parameters in NT style and call the native API */
44 BytesToLock.u.LowPart = nNumberOfBytesToLockLow;
45 BytesToLock.u.HighPart = nNumberOfBytesToLockHigh;
46 Offset.u.LowPart = dwFileOffsetLow;
47 Offset.u.HighPart = dwFileOffsetHigh;
49 NULL,
50 NULL,
51 NULL,
53 &Offset,
54 &BytesToLock,
55 0,
56 TRUE,
57 TRUE);
59 {
60 /* Wait for completion if needed */
63 }
64
65 /* Check if we failed */
66 if (!NT_SUCCESS(Status))
67 {
68 /* Convert the error code and fail */
70 return FALSE;
71 }
72
73 /* Success! */
74 return TRUE;
75}
76
77/*
78 * @implemented
79 */
80BOOL
85 IN DWORD nNumberOfBytesToLockLow,
86 IN DWORD nNumberOfBytesToLockHigh,
88{
89 LARGE_INTEGER BytesToLock, Offset;
91
92 /* Is this a console handle? */
94 {
95 /* Can't "lock" a console! */
97 return FALSE;
98 }
99
100 /* This parameter should be zero */
101 if (dwReserved)
102 {
103 /* Fail since it isn't */
105 return FALSE;
106 }
107
108 /* Set the initial status in the IO_STATUS_BLOCK to pending... */
109 lpOverlapped->Internal = STATUS_PENDING;
110
111 /* Convert the parameters to NT format and call the native API */
112 Offset.u.LowPart = lpOverlapped->Offset;
113 Offset.u.HighPart = lpOverlapped->OffsetHigh;
114 BytesToLock.u.LowPart = nNumberOfBytesToLockLow;
115 BytesToLock.u.HighPart = nNumberOfBytesToLockHigh;
117 lpOverlapped->hEvent,
118 NULL,
119 NULL,
121 &Offset,
122 &BytesToLock,
123 0,
126 if ((NT_SUCCESS(Status)) && (Status != STATUS_PENDING))
127 {
128 /* Pending status is *not* allowed in the Ex API */
129 return TRUE;
130 }
131
132 /* Convert the error code and fail */
134 return FALSE;
135}
136
137/*
138 * @implemented
139 */
140BOOL
141WINAPI
143 IN DWORD dwFileOffsetLow,
144 IN DWORD dwFileOffsetHigh,
145 IN DWORD nNumberOfBytesToUnlockLow,
146 IN DWORD nNumberOfBytesToUnlockHigh)
147{
148 OVERLAPPED Overlapped;
151
152 /* Convert parameters to Ex format and call the new API */
153 Overlapped.Offset = dwFileOffsetLow;
154 Overlapped.OffsetHigh = dwFileOffsetHigh;
156 0,
157 nNumberOfBytesToUnlockLow,
158 nNumberOfBytesToUnlockHigh,
159 &Overlapped);
160 if (!(Result) && (GetLastError() == ERROR_IO_PENDING))
161 {
162 /* Ex fails during STATUS_PENDING, handle that here by waiting */
164 if (NT_SUCCESS(Status)) Status = Overlapped.Internal;
165
166 /* Now if the status is successful, return */
167 if (!NT_SUCCESS(Status)) return TRUE;
168
169 /* Otherwise the asynchronous operation had a failure, so fail */
171 return FALSE;
172 }
173
174 /* Success or error case -- Ex took care of the rest, just return */
175 return Result;
176}
177
178/*
179 * @implemented
180 */
181BOOL
182WINAPI
185 IN DWORD nNumberOfBytesToUnLockLow,
186 IN DWORD nNumberOfBytesToUnLockHigh,
188{
189 LARGE_INTEGER BytesToUnLock, StartAddress;
191
192 /* Is this a console handle? */
194 {
195 /* Can't "unlock" a console! */
197 return FALSE;
198 }
199
200 /* This parameter should be zero */
201 if (dwReserved)
202 {
203 /* Fail since it isn't */
205 return FALSE;
206 }
207
208 /* Convert to NT format and call the native function */
209 BytesToUnLock.u.LowPart = nNumberOfBytesToUnLockLow;
210 BytesToUnLock.u.HighPart = nNumberOfBytesToUnLockHigh;
211 StartAddress.u.LowPart = lpOverlapped->Offset;
212 StartAddress.u.HighPart = lpOverlapped->OffsetHigh;
215 &StartAddress,
216 &BytesToUnLock,
217 0);
218 if (!NT_SUCCESS(Status))
219 {
220 /* Convert the error and fail */
222 return FALSE;
223 }
224
225 /* All good */
226 return TRUE;
227}
228
229/* EOF */
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define ERROR_IO_PENDING
Definition: dderror.h:15
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
BOOL WINAPI UnlockFileEx(IN HANDLE hFile, IN DWORD dwReserved, IN DWORD nNumberOfBytesToUnLockLow, IN DWORD nNumberOfBytesToUnLockHigh, IN LPOVERLAPPED lpOverlapped)
Definition: lock.c:183
BOOL WINAPI UnlockFile(IN HANDLE hFile, IN DWORD dwFileOffsetLow, IN DWORD dwFileOffsetHigh, IN DWORD nNumberOfBytesToUnlockLow, IN DWORD nNumberOfBytesToUnlockHigh)
Definition: lock.c:142
BOOL WINAPI LockFileEx(IN HANDLE hFile, IN DWORD dwFlags, IN DWORD dwReserved, IN DWORD nNumberOfBytesToLockLow, IN DWORD nNumberOfBytesToLockHigh, IN LPOVERLAPPED lpOverlapped)
Definition: lock.c:82
BOOL WINAPI LockFile(IN HANDLE hFile, IN DWORD dwFileOffsetLow, IN DWORD dwFileOffsetHigh, IN DWORD nNumberOfBytesToLockLow, IN DWORD nNumberOfBytesToLockHigh)
Definition: lock.c:25
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
NTSTATUS NTAPI NtLockFile(IN HANDLE FileHandle, IN HANDLE EventHandle OPTIONAL, IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER ByteOffset, IN PLARGE_INTEGER Length, IN ULONG Key, IN BOOLEAN FailImmediately, IN BOOLEAN ExclusiveLock)
Definition: iofunc.c:1764
NTSTATUS NTAPI NtUnlockFile(IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER ByteOffset, IN PLARGE_INTEGER Length, IN ULONG Key OPTIONAL)
Definition: iofunc.c:3551
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
_In_ HANDLE hFile
Definition: mswsock.h:90
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED _In_opt_ LPTRANSMIT_FILE_BUFFERS _In_ DWORD dwReserved
Definition: mswsock.h:95
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:93
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
#define STATUS_PENDING
Definition: ntstatus.h:82
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:167
#define IsConsoleHandle(h)
Definition: console.h:14
DWORD OffsetHigh
Definition: winbase.h:816
DWORD Offset
Definition: winbase.h:815
ULONG_PTR Internal
Definition: winbase.h:811
#define IN
Definition: typedefs.h:39
struct _LARGE_INTEGER::@2299 u
#define LOCKFILE_FAIL_IMMEDIATELY
Definition: winbase.h:385
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define LOCKFILE_EXCLUSIVE_LOCK
Definition: winbase.h:386
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define WINAPI
Definition: msvc.h:6
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409