Sample Code
windows driver samples/ cdfs file system driver/ C++/ cdinit.c/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | /*++ Copyright (c) 1989-2000 Microsoft Corporation Module Name: CdInit.c Abstract: This module implements the DRIVER_INITIALIZATION routine for Cdfs --*/ #include "CdProcs.h" // // The Bug check file id for this module // #define BugCheckFileId (CDFS_BUG_CHECK_CDINIT) // Tell prefast the function type. DRIVER_INITIALIZE DriverEntry; NTSTATUS DriverEntry( _In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath ); // tell prefast this is a driver unload function DRIVER_UNLOAD CdUnload; VOID CdUnload( _In_ PDRIVER_OBJECT DriverObject ); NTSTATUS CdInitializeGlobalData ( _In_ PDRIVER_OBJECT DriverObject, _In_ PDEVICE_OBJECT FileSystemDeviceObject ); #ifdef ALLOC_PRAGMA #pragma alloc_text(INIT, DriverEntry) #pragma alloc_text(PAGE, CdUnload) #pragma alloc_text(INIT, CdInitializeGlobalData) #endif
// // Local support routine // NTSTATUS DriverEntry( _In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath ) /*++ Routine Description: This is the initialization routine for the Cdrom file system device driver. This routine creates the device object for the FileSystem device and performs all other driver initialization. Arguments: DriverObject - Pointer to driver object created by the system. Return Value: NTSTATUS - The function value is the final status from the initialization operation. --*/ { NTSTATUS Status; UNICODE_STRING UnicodeString; PDEVICE_OBJECT CdfsFileSystemDeviceObject; FS_FILTER_CALLBACKS FilterCallbacks; UNREFERENCED_PARAMETER( RegistryPath ); // // Create the device object. // RtlInitUnicodeString( &UnicodeString, L "\\Cdfs" ); Status = IoCreateDevice( DriverObject, 0, &UnicodeString, FILE_DEVICE_CD_ROM_FILE_SYSTEM, 0, FALSE, &CdfsFileSystemDeviceObject ); if (!NT_SUCCESS( Status )) { return Status; } #pragma prefast(push) #pragma prefast(disable: 28155, "the dispatch routine has the correct type, prefast is just being paranoid.") #pragma prefast(disable: 28168, "the dispatch routine has the correct type, prefast is just being paranoid.") #pragma prefast(disable: 28169, "the dispatch routine has the correct type, prefast is just being paranoid.") #pragma prefast(disable: 28175, "we're allowed to change these.") DriverObject->DriverUnload = CdUnload; // // Note that because of the way data caching is done, we set neither // the Direct I/O or Buffered I/O bit in DeviceObject->Flags. If // data is not in the cache, or the request is not buffered, we may, // set up for Direct I/O by hand. // // // Initialize the driver object with this driver's entry points. // // NOTE - Each entry in the dispatch table must have an entry in // the Fsp/Fsd dispatch switch statements. // DriverObject->MajorFunction[IRP_MJ_CREATE] = DriverObject->MajorFunction[IRP_MJ_CLOSE] = DriverObject->MajorFunction[IRP_MJ_READ] = DriverObject->MajorFunction[IRP_MJ_WRITE] = DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION]= DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = DriverObject->MajorFunction[IRP_MJ_CLEANUP] = DriverObject->MajorFunction[IRP_MJ_PNP] = DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = (PDRIVER_DISPATCH) CdFsdDispatch; #pragma prefast(pop) #pragma prefast(suppress: 28175, "this is a file system driver, we're allowed to touch FastIoDispatch.") DriverObject->FastIoDispatch = &CdFastIoDispatch; // // Initialize the filter callbacks we use. // RtlZeroMemory( &FilterCallbacks, sizeof (FS_FILTER_CALLBACKS) ); FilterCallbacks.SizeOfFsFilterCallbacks = sizeof (FS_FILTER_CALLBACKS); FilterCallbacks.PreAcquireForSectionSynchronization = CdFilterCallbackAcquireForCreateSection; Status = FsRtlRegisterFileSystemFilterCallbacks( DriverObject, &FilterCallbacks ); if (!NT_SUCCESS( Status )) { IoDeleteDevice( CdfsFileSystemDeviceObject ); return Status; } // // Initialize the global data structures // Status = CdInitializeGlobalData( DriverObject, CdfsFileSystemDeviceObject ); if (!NT_SUCCESS (Status)) { IoDeleteDevice (CdfsFileSystemDeviceObject); return Status; } // // Register the file system as low priority with the I/O system. This will cause // CDFS to receive mount requests after a) other filesystems currently registered // and b) other normal priority filesystems that may be registered later. // CdfsFileSystemDeviceObject->Flags |= DO_LOW_PRIORITY_FILESYSTEM; IoRegisterFileSystem( CdfsFileSystemDeviceObject ); ObReferenceObject (CdfsFileSystemDeviceObject); // // And return to our caller // return ( STATUS_SUCCESS ); } VOID CdUnload( _In_ PDRIVER_OBJECT DriverObject ) /*++ Routine Description: This routine unload routine for CDFS. Arguments: DriverObject - Supplies the driver object for CDFS. Return Value: None. --*/ { PIRP_CONTEXT IrpContext; PAGED_CODE(); UNREFERENCED_PARAMETER( DriverObject ); // // Free any IRP contexts // while (1) { IrpContext = (PIRP_CONTEXT) PopEntryList( &CdData.IrpContextList) ; if (IrpContext == NULL) { break ; } CdFreePool(&IrpContext); } IoFreeWorkItem (CdData.CloseItem); ExDeleteResourceLite( &CdData.DataResource ); ObDereferenceObject (CdData.FileSystemDeviceObject); }
// // Local support routine // NTSTATUS CdInitializeGlobalData ( _In_ PDRIVER_OBJECT DriverObject, _In_ PDEVICE_OBJECT FileSystemDeviceObject ) /*++ Routine Description: This routine initializes the global cdfs data structures. Arguments: DriverObject - Supplies the driver object for CDFS. FileSystemDeviceObject - Supplies the device object for CDFS. Return Value: None. --*/ { // // Start by initializing the FastIoDispatch Table. // RtlZeroMemory( &CdFastIoDispatch, sizeof ( FAST_IO_DISPATCH )); CdFastIoDispatch.SizeOfFastIoDispatch = sizeof (FAST_IO_DISPATCH); #pragma prefast(push) #pragma prefast(disable:28155, "these are all correct") CdFastIoDispatch.FastIoCheckIfPossible = CdFastIoCheckIfPossible; // CheckForFastIo CdFastIoDispatch.FastIoRead = FsRtlCopyRead; // Read CdFastIoDispatch.FastIoQueryBasicInfo = CdFastQueryBasicInfo; // QueryBasicInfo CdFastIoDispatch.FastIoQueryStandardInfo = CdFastQueryStdInfo; // QueryStandardInfo CdFastIoDispatch.FastIoLock = CdFastLock; // Lock CdFastIoDispatch.FastIoUnlockSingle = CdFastUnlockSingle; // UnlockSingle CdFastIoDispatch.FastIoUnlockAll = CdFastUnlockAll; // UnlockAll CdFastIoDispatch.FastIoUnlockAllByKey = CdFastUnlockAllByKey; // UnlockAllByKey // // This callback has been replaced by CdFilterCallbackAcquireForCreateSection. // CdFastIoDispatch.AcquireFileForNtCreateSection = NULL; CdFastIoDispatch.ReleaseFileForNtCreateSection = CdReleaseForCreateSection; CdFastIoDispatch.FastIoQueryNetworkOpenInfo = CdFastQueryNetworkInfo; // QueryNetworkInfo CdFastIoDispatch.MdlRead = FsRtlMdlReadDev; CdFastIoDispatch.MdlReadComplete = FsRtlMdlReadCompleteDev; CdFastIoDispatch.PrepareMdlWrite = FsRtlPrepareMdlWriteDev; CdFastIoDispatch.MdlWriteComplete = FsRtlMdlWriteCompleteDev; #pragma prefast(pop) // // Initialize the CdData structure. // RtlZeroMemory( &CdData, sizeof ( CD_DATA )); CdData.NodeTypeCode = CDFS_NTC_DATA_HEADER; CdData.NodeByteSize = sizeof ( CD_DATA ); CdData.DriverObject = DriverObject; CdData.FileSystemDeviceObject = FileSystemDeviceObject; InitializeListHead( &CdData.VcbQueue ); ExInitializeResourceLite( &CdData.DataResource ); // // Initialize the cache manager callback routines // CdData.CacheManagerCallbacks.AcquireForLazyWrite = &CdAcquireForCache; CdData.CacheManagerCallbacks.ReleaseFromLazyWrite = &CdReleaseFromCache; CdData.CacheManagerCallbacks.AcquireForReadAhead = &CdAcquireForCache; CdData.CacheManagerCallbacks.ReleaseFromReadAhead = &CdReleaseFromCache; CdData.CacheManagerVolumeCallbacks.AcquireForLazyWrite = &CdNoopAcquire; CdData.CacheManagerVolumeCallbacks.ReleaseFromLazyWrite = &CdNoopRelease; CdData.CacheManagerVolumeCallbacks.AcquireForReadAhead = &CdNoopAcquire; CdData.CacheManagerVolumeCallbacks.ReleaseFromReadAhead = &CdNoopRelease; // // Initialize the lock mutex and the async and delay close queues. // ExInitializeFastMutex( &CdData.CdDataMutex ); InitializeListHead( &CdData.AsyncCloseQueue ); InitializeListHead( &CdData.DelayedCloseQueue ); CdData.CloseItem = IoAllocateWorkItem (FileSystemDeviceObject); if (CdData.CloseItem == NULL) { ExDeleteResourceLite( &CdData.DataResource ); return STATUS_INSUFFICIENT_RESOURCES; } // // Do the initialization based on the system size. // switch (MmQuerySystemSize()) { case MmSmallSystem: CdData.IrpContextMaxDepth = 4; CdData.MaxDelayedCloseCount = 8; CdData.MinDelayedCloseCount = 2; break ; case MmMediumSystem: CdData.IrpContextMaxDepth = 8; CdData.MaxDelayedCloseCount = 24; CdData.MinDelayedCloseCount = 6; break ; case MmLargeSystem: CdData.IrpContextMaxDepth = 32; CdData.MaxDelayedCloseCount = 72; CdData.MinDelayedCloseCount = 18; break ; } return STATUS_SUCCESS; } |
Our Services
-
What our customers say about us?
Read our customer testimonials to find out why our clients keep returning for their projects.
View Testimonials