ReactOS 0.4.16-dev-197-g92996da
lock.c File Reference
#include <k32.h>
#include <debug.h>
Include dependency graph for lock.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOL WINAPI LockFile (IN HANDLE hFile, IN DWORD dwFileOffsetLow, IN DWORD dwFileOffsetHigh, IN DWORD nNumberOfBytesToLockLow, IN DWORD nNumberOfBytesToLockHigh)
 
BOOL WINAPI LockFileEx (IN HANDLE hFile, IN DWORD dwFlags, IN DWORD dwReserved, IN DWORD nNumberOfBytesToLockLow, IN DWORD nNumberOfBytesToLockHigh, IN LPOVERLAPPED lpOverlapped)
 
BOOL WINAPI UnlockFile (IN HANDLE hFile, IN DWORD dwFileOffsetLow, IN DWORD dwFileOffsetHigh, IN DWORD nNumberOfBytesToUnlockLow, IN DWORD nNumberOfBytesToUnlockHigh)
 
BOOL WINAPI UnlockFileEx (IN HANDLE hFile, IN DWORD dwReserved, IN DWORD nNumberOfBytesToUnLockLow, IN DWORD nNumberOfBytesToUnLockHigh, IN LPOVERLAPPED lpOverlapped)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file lock.c.

Function Documentation

◆ LockFile()

BOOL WINAPI LockFile ( IN HANDLE  hFile,
IN DWORD  dwFileOffsetLow,
IN DWORD  dwFileOffsetHigh,
IN DWORD  nNumberOfBytesToLockLow,
IN DWORD  nNumberOfBytesToLockHigh 
)

Definition at line 25 of file lock.c.

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}
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#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
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
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
_In_ HANDLE hFile
Definition: mswsock.h:90
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:167
#define IsConsoleHandle(h)
Definition: console.h:14
struct _LARGE_INTEGER::@2299 u

Referenced by _locking(), BestFit_Write(), DosLockFile(), and test_LockFile().

◆ LockFileEx()

BOOL WINAPI LockFileEx ( IN HANDLE  hFile,
IN DWORD  dwFlags,
IN DWORD  dwReserved,
IN DWORD  nNumberOfBytesToLockLow,
IN DWORD  nNumberOfBytesToLockHigh,
IN LPOVERLAPPED  lpOverlapped 
)

Definition at line 82 of file lock.c.

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}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
_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
#define LOCKFILE_FAIL_IMMEDIATELY
Definition: winbase.h:410
#define LOCKFILE_EXCLUSIVE_LOCK
Definition: winbase.h:411
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

Referenced by FileLockBytesImpl_LockRegion(), test_LockFile(), and test_locking().

◆ UnlockFile()

BOOL WINAPI UnlockFile ( IN HANDLE  hFile,
IN DWORD  dwFileOffsetLow,
IN DWORD  dwFileOffsetHigh,
IN DWORD  nNumberOfBytesToUnlockLow,
IN DWORD  nNumberOfBytesToUnlockHigh 
)

Definition at line 142 of file lock.c.

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}
unsigned char BOOLEAN
#define ERROR_IO_PENDING
Definition: dderror.h:15
BOOL WINAPI UnlockFileEx(IN HANDLE hFile, IN DWORD dwReserved, IN DWORD nNumberOfBytesToUnLockLow, IN DWORD nNumberOfBytesToUnLockHigh, IN LPOVERLAPPED lpOverlapped)
Definition: lock.c:183
DWORD OffsetHigh
Definition: winbase.h:840
DWORD Offset
Definition: winbase.h:839
ULONG_PTR Internal
Definition: winbase.h:835
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_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

Referenced by _locking(), BestFit_Write(), DosUnlockFile(), and test_LockFile().

◆ UnlockFileEx()

BOOL WINAPI UnlockFileEx ( IN HANDLE  hFile,
IN DWORD  dwReserved,
IN DWORD  nNumberOfBytesToUnLockLow,
IN DWORD  nNumberOfBytesToUnLockHigh,
IN LPOVERLAPPED  lpOverlapped 
)

Definition at line 183 of file lock.c.

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}
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

Referenced by FileLockBytesImpl_UnlockRegion(), test_LockFile(), test_locking(), and UnlockFile().