ReactOS 0.4.16-dev-336-gb667d82
NtWriteFile.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for NtWriteFile
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8#include "precomp.h"
9
10static
11BOOL
13{
14#ifdef _WIN64
15 return TRUE;
16#else
19
22 &IsWow64,
23 sizeof(IsWow64),
24 NULL);
25 if (NT_SUCCESS(Status))
26 {
27 return IsWow64 != 0;
28 }
29
30 return FALSE;
31#endif
32}
33
34static
37{
38 return Is64BitSystem() ? 48 : 28;
39}
40
41static
44{
45 BOOL Ret;
47
48 /* FIXME: Would be better to actually open systemroot */
50 ok(Ret != FALSE, "GetDiskFreeSpaceW failed: %lx\n", GetLastError());
51 if (!Ret)
52 {
53 SectorSize = 4096; /* On failure, assume max size */
54 }
55
56 return SectorSize;
57}
58
60{
63 UNICODE_STRING FileName = RTL_CONSTANT_STRING(L"\\SystemRoot\\ntdll-apitest-NtWriteFile-test.bin");
69 FILE_DISPOSITION_INFORMATION DispositionInfo;
70 ULONG TooLargeDataSize = (MAXUSHORT + 1 - SizeOfMdl()) / sizeof(ULONG_PTR) * PAGE_SIZE; // 0x3FF9000 on x86
71 ULONG LargeMdlMaxDataSize = TooLargeDataSize - PAGE_SIZE;
72
73 trace("System is %d bits, Size of MDL: %lu\n", Is64BitSystem() ? 64 : 32, SizeOfMdl());
74 trace("Max MDL data size: 0x%lx bytes\n", LargeMdlMaxDataSize);
75
76 ByteOffset.QuadPart = 0;
77
78 Buffer = NULL;
79 BufferSize = TooLargeDataSize;
81 &Buffer,
82 0,
86 if (!NT_SUCCESS(Status))
87 {
88 skip("Failed to allocate memory, status %lx\n", Status);
89 return;
90 }
91
93 &FileName,
95 NULL,
96 NULL);
100 &IoStatus,
101 NULL,
102 0,
103 0,
107 NULL,
108 0);
110
111 /* non-cached, max size -- succeeds */
113 NULL,
114 NULL,
115 NULL,
116 &IoStatus,
117 Buffer,
118 LargeMdlMaxDataSize - PAGE_SIZE,
119 &ByteOffset,
120 NULL);
122
123 /* non-cached, max size -- succeeds */
125 NULL,
126 NULL,
127 NULL,
128 &IoStatus,
129 Buffer,
130 LargeMdlMaxDataSize,
131 &ByteOffset,
132 NULL);
134
135 /* non-cached, too large -- fails to allocate MDL
136 * Note: this returns STATUS_SUCCESS on Win7 -- higher MDL size limit */
138 NULL,
139 NULL,
140 NULL,
141 &IoStatus,
142 Buffer,
143 LargeMdlMaxDataSize + PAGE_SIZE,
144 &ByteOffset,
145 NULL);
147
148 /* non-cached, unaligned -- fails with invalid parameter */
150 NULL,
151 NULL,
152 NULL,
153 &IoStatus,
154 Buffer,
155 LargeMdlMaxDataSize + 1,
156 &ByteOffset,
157 NULL);
159
160 DispositionInfo.DeleteFile = TRUE;
162 &IoStatus,
163 &DispositionInfo,
164 sizeof(DispositionInfo),
169
173 &IoStatus,
174 NULL,
175 0,
176 0,
179 NULL,
180 0);
182
183 /* cached: succeeds with arbitrary length */
185 NULL,
186 NULL,
187 NULL,
188 &IoStatus,
189 Buffer,
190 LargeMdlMaxDataSize,
191 &ByteOffset,
192 NULL);
194
196 NULL,
197 NULL,
198 NULL,
199 &IoStatus,
200 Buffer,
201 LargeMdlMaxDataSize + 1,
202 &ByteOffset,
203 NULL);
205
207 NULL,
208 NULL,
209 NULL,
210 &IoStatus,
211 Buffer,
212 TooLargeDataSize,
213 &ByteOffset,
214 NULL);
216
217 DispositionInfo.DeleteFile = TRUE;
219 &IoStatus,
220 &DispositionInfo,
221 sizeof(DispositionInfo),
226
228 &Buffer,
229 &BufferSize,
232
233 /* Now, testing aligned/non aligned writes */
234
236 trace("Sector is %ld bytes\n", BufferSize);
237
239 &Buffer,
240 0,
241 &BufferSize,
244 if (!NT_SUCCESS(Status))
245 {
246 skip("Failed to allocate memory, status %lx\n", Status);
247 return;
248 }
249
253 &IoStatus,
254 NULL,
255 0,
256 0,
261 NULL,
262 0);
264
265 /* non-cached, broken length -- fails with invalid parameter */
266 ByteOffset.QuadPart = 0;
268 NULL,
269 NULL,
270 NULL,
271 &IoStatus,
272 Buffer,
273 4,
274 &ByteOffset,
275 NULL);
277
278 /* non-cached, broken offset -- fails with invalid parameter */
279 ByteOffset.QuadPart = 4;
281 NULL,
282 NULL,
283 NULL,
284 &IoStatus,
285 Buffer,
287 &ByteOffset,
288 NULL);
290
291 /* non-cached, good length and offset -- succeeds */
292 ByteOffset.QuadPart = 0;
294 NULL,
295 NULL,
296 NULL,
297 &IoStatus,
298 Buffer,
300 &ByteOffset,
301 NULL);
303
304 DispositionInfo.DeleteFile = TRUE;
306 &IoStatus,
307 &DispositionInfo,
308 sizeof(DispositionInfo),
313
315 &Buffer,
316 &BufferSize,
319}
static ULONG SizeOfSector(VOID)
Definition: NtWriteFile.c:43
static BOOL Is64BitSystem(VOID)
Definition: NtWriteFile.c:12
static ULONG SizeOfMdl(VOID)
Definition: NtWriteFile.c:36
#define ok_hex(expression, result)
Definition: atltest.h:94
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define BufferSize
Definition: mmc.h:75
#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 PAGE_READONLY
Definition: compat.h:138
BOOL WINAPI GetDiskFreeSpaceW(IN LPCWSTR lpRootPathName, OUT LPDWORD lpSectorsPerCluster, OUT LPDWORD lpBytesPerSector, OUT LPDWORD lpNumberOfFreeClusters, OUT LPDWORD lpTotalNumberOfClusters)
Definition: disk.c:173
#define PAGE_SIZE
Definition: env_spec_w32.h:49
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:732
unsigned int BOOL
Definition: ntddk_ex.h:94
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
@ FileDispositionInformation
Definition: from_kernel.h:74
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
#define FILE_WRITE_THROUGH
Definition: from_kernel.h:26
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
Status
Definition: gdiplustypes.h:25
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
@ ProcessWow64Information
Definition: winternl.h:396
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_WRITE_DATA
Definition: nt_native.h:631
NTSYSAPI NTSTATUS NTAPI NtWriteFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID WriteBuffer, IN ULONG WriteBufferLength, IN PLARGE_INTEGER FileOffset OPTIONAL, IN PULONG LockOperationKey OPTIONAL)
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSYSAPI NTSTATUS NTAPI NtSetInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
Definition: iofunc.c:3096
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define DELETE
Definition: nt_native.h:57
#define MEM_RESERVE
Definition: nt_native.h:1314
#define MEM_RELEASE
Definition: nt_native.h:1316
NTSTATUS NTAPI NtCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG CreateDisposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength)
#define MEM_COMMIT
Definition: nt_native.h:1313
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5230
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4492
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define MAXUSHORT
Definition: typedefs.h:83
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
BOOL IsWow64(VOID)
Definition: user_lib.cpp:579
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ ULONG SectorSize
Definition: halfuncs.h:291