1 /* 2 * PROJECT: ReactOS kernel-mode tests - Filter Manager 3 * LICENSE: GPLv2+ - See COPYING in the top level directory 4 * PURPOSE: Tests for checking filters load correctly 5 * PROGRAMMER: Ged Murphy <gedmurphy@reactos.org> 6 */ 7 8 #include <kmt_test.h> 9 #include <fltkernel.h> 10 11 //#define NDEBUG 12 #include <debug.h> 13 14 /* prototypes */ 15 NTSTATUS 16 FLTAPI 17 TestClientConnect( 18 _In_ PFLT_PORT ClientPort, 19 _In_opt_ PVOID ServerPortCookie, 20 _In_reads_bytes_opt_(SizeOfContext) PVOID ConnectionContext, 21 _In_ ULONG SizeOfContext, 22 _Outptr_result_maybenull_ PVOID *ConnectionPortCookie 23 ); 24 25 VOID 26 FLTAPI 27 TestClientDisconnect( 28 _In_opt_ PVOID ConnectionCookie 29 ); 30 31 NTSTATUS 32 FLTAPI 33 TestMessageHandler( 34 _In_opt_ PVOID ConnectionCookie, 35 _In_reads_bytes_opt_(InputBufferLength) PVOID InputBuffer, 36 _In_ ULONG InputBufferLength, 37 _Out_writes_bytes_to_opt_(OutputBufferLength, *ReturnOutputBufferLength) PVOID OutputBuffer, 38 _In_ ULONG OutputBufferLength, 39 _Out_ PULONG ReturnOutputBufferLength 40 ); 41 42 43 /* Globals */ 44 static PDRIVER_OBJECT TestDriverObject; 45 46 47 48 /** 49 * @name TestEntry 50 * 51 * Test entry point. 52 * This is called by DriverEntry as early as possible, but with ResultBuffer 53 * initialized, so that test macros work correctly 54 * 55 * @param DriverObject 56 * Driver Object. 57 * This is guaranteed not to have been touched by DriverEntry before 58 * the call to TestEntry 59 * @param RegistryPath 60 * Driver Registry Path 61 * This is guaranteed not to have been touched by DriverEntry before 62 * the call to TestEntry 63 * @param DeviceName 64 * Pointer to receive a test-specific name for the device to create 65 * @param Flags 66 * Pointer to a flags variable instructing DriverEntry how to proceed. 67 * See the KMT_TESTENTRY_FLAGS enumeration for possible values 68 * Initialized to zero on entry 69 * 70 * @return Status. 71 * DriverEntry will fail if this is a failure status 72 */ 73 NTSTATUS 74 TestEntry( 75 IN PDRIVER_OBJECT DriverObject, 76 IN PCUNICODE_STRING RegistryPath, 77 OUT PCWSTR *DeviceName, 78 IN OUT INT *Flags) 79 { 80 NTSTATUS Status = STATUS_SUCCESS; 81 82 PAGED_CODE(); 83 84 UNREFERENCED_PARAMETER(RegistryPath); 85 UNREFERENCED_PARAMETER(Flags); 86 87 DPRINT("Entry!\n"); 88 89 ok_irql(PASSIVE_LEVEL); 90 TestDriverObject = DriverObject; 91 92 *DeviceName = L"FltMgrLoad"; 93 94 trace("Hi, this is the filter manager load test driver\n"); 95 96 KmtFilterRegisterComms(TestClientConnect, TestClientDisconnect, TestMessageHandler, 1); 97 98 return Status; 99 } 100 101 /** 102 * @name TestUnload 103 * 104 * Test unload routine. 105 * This is called by the driver's Unload routine as early as possible, with 106 * ResultBuffer and the test device object still valid, so that test macros 107 * work correctly 108 * 109 * @param DriverObject 110 * Driver Object. 111 * This is guaranteed not to have been touched by Unload before the call 112 * to TestEntry 113 * 114 * @return Status 115 */ 116 VOID 117 TestFilterUnload( 118 IN ULONG Flags) 119 { 120 PAGED_CODE(); 121 122 DPRINT("Unload!\n"); 123 124 ok_irql(PASSIVE_LEVEL); 125 126 trace("Unloading filter manager load test driver\n"); 127 } 128 129 130 /** 131 * @name TestInstanceSetup 132 * 133 * Test volume attach routine. 134 * This is called by the driver's InstanceSetupCallback routine in response to 135 * a new volume attaching. 136 * 137 * @param FltObjects 138 * Filter Object Pointers 139 * Pointer to an FLT_RELATED_OBJECTS structure that contains opaque pointers 140 * for the objects related to the current operation 141 * @param Flags 142 * Bitmask of flags that indicate why the instance is being attached 143 * @param VolumeDeviceType 144 * Device type of the file system volume 145 * @param VolumeFilesystemType 146 * File system type of the volume 147 * @param VolumeName 148 * Unicode string containing the name of the volume. 149 * The string is only valid within the context of this function 150 * @param SectorSize 151 * Adjusts the sector size to a minimum of 0x200, which is more reliable 152 * @param ReportedSectorSize 153 * Sector size of the volume as reported by the filter manager 154 * 155 * @return Status. 156 * Return STATUS_SUCCESS to attach or STATUS_FLT_DO_NOT_ATTACH to ignore 157 */ 158 NTSTATUS 159 TestInstanceSetup( 160 _In_ PCFLT_RELATED_OBJECTS FltObjects, 161 _In_ FLT_INSTANCE_SETUP_FLAGS Flags, 162 _In_ DEVICE_TYPE VolumeDeviceType, 163 _In_ FLT_FILESYSTEM_TYPE VolumeFilesystemType, 164 _In_ PUNICODE_STRING VolumeName, 165 _In_ ULONG SectorSize, 166 _In_ ULONG ReportedSectorSize 167 ) 168 { 169 trace("Received an attach request for VolumeType 0x%X, FileSystemType %d\n", 170 VolumeDeviceType, 171 VolumeFilesystemType); 172 173 /* We're not interested in attaching to any volumes in this test */ 174 return STATUS_FLT_DO_NOT_ATTACH; 175 } 176 177 /** 178 * @name TestQueryTeardown 179 * 180 * Test volume attach routine. 181 * This is called by the driver's InstanceSetupCallback routine in response to 182 * a new volume attaching. 183 * 184 * @param FltObjects 185 * Filter Object Pointers 186 * Pointer to an FLT_RELATED_OBJECTS structure that contains opaque pointers 187 * for the objects related to the current operation 188 * @param Flags 189 * Flag that indicates why the minifilter driver instance is being torn down 190 * 191 */ 192 VOID 193 TestQueryTeardown( 194 _In_ PCFLT_RELATED_OBJECTS FltObjects, 195 _In_ FLT_INSTANCE_QUERY_TEARDOWN_FLAGS Flags) 196 { 197 trace("Received a teardown request, Flags %lu\n", Flags); 198 199 UNREFERENCED_PARAMETER(FltObjects); 200 UNREFERENCED_PARAMETER(Flags); 201 } 202 203 NTSTATUS 204 FLTAPI 205 TestClientConnect( 206 _In_ PFLT_PORT ClientPort, 207 _In_opt_ PVOID ServerPortCookie, 208 _In_reads_bytes_opt_(SizeOfContext) PVOID ConnectionContext, 209 _In_ ULONG SizeOfContext, 210 _Outptr_result_maybenull_ PVOID *ConnectionPortCookie) 211 { 212 return 0; 213 } 214 215 VOID 216 FLTAPI 217 TestClientDisconnect( 218 _In_opt_ PVOID ConnectionCookie) 219 { 220 221 } 222 223 NTSTATUS 224 FLTAPI 225 TestMessageHandler( 226 _In_opt_ PVOID ConnectionCookie, 227 _In_reads_bytes_opt_(InputBufferLength) PVOID InputBuffer, 228 _In_ ULONG InputBufferLength, 229 _Out_writes_bytes_to_opt_(OutputBufferLength, *ReturnOutputBufferLength) PVOID OutputBuffer, 230 _In_ ULONG OutputBufferLength, 231 _Out_ PULONG ReturnOutputBufferLength) 232 { 233 return 0; 234 } 235