1 /* 2 * PROJECT: ReactOS kernel-mode tests 3 * LICENSE: GPLv2+ - See COPYING in the top level directory 4 * PURPOSE: Kernel-Mode Test Suite CcCopyWrite test user-mode part 5 * PROGRAMMER: Pierre Schweitzer <pierre@reactos.org> 6 */ 7 8 #include <kmt_test.h> 9 10 START_TEST(CcCopyWrite) 11 { 12 HANDLE Handle; 13 NTSTATUS Status; 14 LARGE_INTEGER ByteOffset; 15 IO_STATUS_BLOCK IoStatusBlock; 16 OBJECT_ATTRIBUTES ObjectAttributes; 17 PVOID Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, 4097); 18 UNICODE_STRING BigFile = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyWrite\\BigFile"); 19 UNICODE_STRING SmallFile = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyWrite\\SmallFile"); 20 UNICODE_STRING VerySmallFile = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyWrite\\VerySmallFile"); 21 UNICODE_STRING NormalFile = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyWrite\\NormalFile"); 22 23 KmtLoadDriver(L"CcCopyWrite", FALSE); 24 KmtOpenDriver(); 25 26 InitializeObjectAttributes(&ObjectAttributes, &VerySmallFile, OBJ_CASE_INSENSITIVE, NULL, NULL); 27 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT); 28 ok_eq_hex(Status, STATUS_SUCCESS); 29 30 ByteOffset.QuadPart = 0; 31 Status = NtWriteFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 62, &ByteOffset, NULL); 32 ok_eq_hex(Status, STATUS_SUCCESS); 33 34 Status = NtFlushBuffersFile(Handle, &IoStatusBlock); 35 ok_eq_hex(Status, STATUS_SUCCESS); 36 37 NtClose(Handle); 38 39 InitializeObjectAttributes(&ObjectAttributes, &SmallFile, OBJ_CASE_INSENSITIVE, NULL, NULL); 40 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT); 41 ok_eq_hex(Status, STATUS_SUCCESS); 42 43 ByteOffset.QuadPart = 0; 44 Status = NtWriteFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 512, &ByteOffset, NULL); 45 ok_eq_hex(Status, STATUS_SUCCESS); 46 47 Status = NtFlushBuffersFile(Handle, &IoStatusBlock); 48 ok_eq_hex(Status, STATUS_SUCCESS); 49 50 NtClose(Handle); 51 52 InitializeObjectAttributes(&ObjectAttributes, &NormalFile, OBJ_CASE_INSENSITIVE, NULL, NULL); 53 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT); 54 ok_eq_hex(Status, STATUS_SUCCESS); 55 56 ByteOffset.QuadPart = 0; 57 Status = NtWriteFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 1004, &ByteOffset, NULL); 58 ok_eq_hex(Status, STATUS_SUCCESS); 59 60 Status = NtFlushBuffersFile(Handle, &IoStatusBlock); 61 ok_eq_hex(Status, STATUS_SUCCESS); 62 63 NtClose(Handle); 64 65 InitializeObjectAttributes(&ObjectAttributes, &BigFile, OBJ_CASE_INSENSITIVE, NULL, NULL); 66 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT); 67 ok_eq_hex(Status, STATUS_SUCCESS); 68 69 ByteOffset.QuadPart = 0; 70 Status = NtWriteFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 4097, &ByteOffset, NULL); 71 ok_eq_hex(Status, STATUS_SUCCESS); 72 73 Status = NtFlushBuffersFile(Handle, &IoStatusBlock); 74 ok_eq_hex(Status, STATUS_SUCCESS); 75 76 NtClose(Handle); 77 78 InitializeObjectAttributes(&ObjectAttributes, &BigFile, OBJ_CASE_INSENSITIVE, NULL, NULL); 79 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT); 80 ok_eq_hex(Status, STATUS_SUCCESS); 81 82 ByteOffset.QuadPart = 4097; 83 Status = NtWriteFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 4097, &ByteOffset, NULL); 84 ok_eq_hex(Status, STATUS_SUCCESS); 85 86 Status = NtFlushBuffersFile(Handle, &IoStatusBlock); 87 ok_eq_hex(Status, STATUS_SUCCESS); 88 89 NtClose(Handle); 90 91 RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); 92 KmtCloseDriver(); 93 KmtUnloadDriver(); 94 } 95