3 Copyright (c) 1989-2000 Microsoft Corporation
11 This module implements the DRIVER_INITIALIZATION routine for Cdfs
19 // The Bug check file id for this module
22 #define BugCheckFileId (CDFS_BUG_CHECK_CDINIT)
24 // Tell prefast the function type.
25 DRIVER_INITIALIZE DriverEntry
;
28 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
30 _In_ PDRIVER_OBJECT DriverObject
,
31 _In_ PUNICODE_STRING RegistryPath
35 // tell prefast this is a driver unload function
36 DRIVER_UNLOAD CdUnload
;
39 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
41 _In_ PDRIVER_OBJECT DriverObject
45 CdInitializeGlobalData (
46 _In_ PDRIVER_OBJECT DriverObject
,
47 _In_ PDEVICE_OBJECT FileSystemDeviceObject
50 IN PDEVICE_OBJECT HddFileSystemDeviceObject
55 #pragma alloc_text(INIT, DriverEntry)
56 #pragma alloc_text(PAGE, CdUnload)
57 #pragma alloc_text(INIT, CdInitializeGlobalData)
62 // Local support routine
66 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
68 _In_ PDRIVER_OBJECT DriverObject
,
69 _In_ PUNICODE_STRING RegistryPath
76 This is the initialization routine for the Cdrom file system
77 device driver. This routine creates the device object for the FileSystem
78 device and performs all other driver initialization.
82 DriverObject - Pointer to driver object created by the system.
86 NTSTATUS - The function value is the final status from the initialization
93 UNICODE_STRING UnicodeString
;
94 PDEVICE_OBJECT CdfsFileSystemDeviceObject
;
95 FS_FILTER_CALLBACKS FilterCallbacks
;
97 PDEVICE_OBJECT HddFileSystemDeviceObject
;
100 UNREFERENCED_PARAMETER( RegistryPath
);
103 // Create the device object.
106 RtlInitUnicodeString( &UnicodeString
, L
"\\Cdfs" );
108 Status
= IoCreateDevice( DriverObject
,
111 FILE_DEVICE_CD_ROM_FILE_SYSTEM
,
114 &CdfsFileSystemDeviceObject
);
116 if (!NT_SUCCESS( Status
)) {
122 // Create the HDD device object.
125 RtlInitUnicodeString( &UnicodeString
, L
"\\CdfsHdd" );
127 Status
= IoCreateDevice( DriverObject
,
130 FILE_DEVICE_DISK_FILE_SYSTEM
,
133 &HddFileSystemDeviceObject
);
135 if (!NT_SUCCESS( Status
)) {
136 IoDeleteDevice (CdfsFileSystemDeviceObject
);
142 #pragma prefast(push)
143 #pragma prefast(disable: 28155, "the dispatch routine has the correct type, prefast is just being paranoid.")
144 #pragma prefast(disable: 28168, "the dispatch routine has the correct type, prefast is just being paranoid.")
145 #pragma prefast(disable: 28169, "the dispatch routine has the correct type, prefast is just being paranoid.")
146 #pragma prefast(disable: 28175, "we're allowed to change these.")
149 DriverObject
->DriverUnload
= CdUnload
;
152 // Note that because of the way data caching is done, we set neither
153 // the Direct I/O or Buffered I/O bit in DeviceObject->Flags. If
154 // data is not in the cache, or the request is not buffered, we may,
155 // set up for Direct I/O by hand.
159 // Initialize the driver object with this driver's entry points.
161 // NOTE - Each entry in the dispatch table must have an entry in
162 // the Fsp/Fsd dispatch switch statements.
165 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] =
166 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] =
167 DriverObject
->MajorFunction
[IRP_MJ_READ
] =
168 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] =
169 DriverObject
->MajorFunction
[IRP_MJ_QUERY_INFORMATION
] =
170 DriverObject
->MajorFunction
[IRP_MJ_SET_INFORMATION
] =
171 DriverObject
->MajorFunction
[IRP_MJ_QUERY_VOLUME_INFORMATION
]=
172 DriverObject
->MajorFunction
[IRP_MJ_DIRECTORY_CONTROL
] =
173 DriverObject
->MajorFunction
[IRP_MJ_FILE_SYSTEM_CONTROL
] =
174 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] =
175 DriverObject
->MajorFunction
[IRP_MJ_LOCK_CONTROL
] =
176 DriverObject
->MajorFunction
[IRP_MJ_CLEANUP
] =
177 DriverObject
->MajorFunction
[IRP_MJ_PNP
] =
178 DriverObject
->MajorFunction
[IRP_MJ_SHUTDOWN
] = (PDRIVER_DISPATCH
) CdFsdDispatch
;
182 #pragma prefast(suppress: 28175, "this is a file system driver, we're allowed to touch FastIoDispatch.")
184 DriverObject
->FastIoDispatch
= &CdFastIoDispatch
;
187 // Initialize the filter callbacks we use.
190 RtlZeroMemory( &FilterCallbacks
,
191 sizeof(FS_FILTER_CALLBACKS
) );
193 FilterCallbacks
.SizeOfFsFilterCallbacks
= sizeof(FS_FILTER_CALLBACKS
);
194 FilterCallbacks
.PreAcquireForSectionSynchronization
= CdFilterCallbackAcquireForCreateSection
;
196 Status
= FsRtlRegisterFileSystemFilterCallbacks( DriverObject
,
199 if (!NT_SUCCESS( Status
)) {
201 IoDeleteDevice( CdfsFileSystemDeviceObject
);
203 IoDeleteDevice (HddFileSystemDeviceObject
);
209 // Initialize the global data structures
213 Status
= CdInitializeGlobalData( DriverObject
, CdfsFileSystemDeviceObject
);
215 Status
= CdInitializeGlobalData( DriverObject
, CdfsFileSystemDeviceObject
, HddFileSystemDeviceObject
);
217 if (!NT_SUCCESS (Status
)) {
218 IoDeleteDevice (CdfsFileSystemDeviceObject
);
220 IoDeleteDevice (HddFileSystemDeviceObject
);
226 // Register the file system as low priority with the I/O system. This will cause
227 // CDFS to receive mount requests after a) other filesystems currently registered
228 // and b) other normal priority filesystems that may be registered later.
231 CdfsFileSystemDeviceObject
->Flags
|= DO_LOW_PRIORITY_FILESYSTEM
;
233 HddFileSystemDeviceObject
->Flags
|= DO_LOW_PRIORITY_FILESYSTEM
;
236 IoRegisterFileSystem( CdfsFileSystemDeviceObject
);
237 ObReferenceObject (CdfsFileSystemDeviceObject
);
239 IoRegisterFileSystem( HddFileSystemDeviceObject
);
240 ObReferenceObject (HddFileSystemDeviceObject
);
243 #ifdef CDFS_TELEMETRY_DATA
245 // Initialize Telemetry
248 CdInitializeTelemetry();
253 // And return to our caller
256 return( STATUS_SUCCESS
);
261 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
263 _In_ PDRIVER_OBJECT DriverObject
269 This routine unload routine for CDFS.
273 DriverObject - Supplies the driver object for CDFS.
281 PIRP_CONTEXT IrpContext
;
285 UNREFERENCED_PARAMETER( DriverObject
);
288 // Free any IRP contexts
291 IrpContext
= (PIRP_CONTEXT
) PopEntryList( &CdData
.IrpContextList
) ;
292 if (IrpContext
== NULL
) {
295 CdFreePool(&IrpContext
);
298 IoFreeWorkItem (CdData
.CloseItem
);
299 ExDeleteResourceLite( &CdData
.DataResource
);
300 ObDereferenceObject (CdData
.FileSystemDeviceObject
);
302 ObDereferenceObject (CdData
.HddFileSystemDeviceObject
);
307 // Local support routine
311 CdInitializeGlobalData (
312 _In_ PDRIVER_OBJECT DriverObject
,
313 _In_ PDEVICE_OBJECT FileSystemDeviceObject
316 IN PDEVICE_OBJECT HddFileSystemDeviceObject
324 This routine initializes the global cdfs data structures.
328 DriverObject - Supplies the driver object for CDFS.
330 FileSystemDeviceObject - Supplies the device object for CDFS.
340 // Start by initializing the FastIoDispatch Table.
343 RtlZeroMemory( &CdFastIoDispatch
, sizeof( FAST_IO_DISPATCH
));
345 CdFastIoDispatch
.SizeOfFastIoDispatch
= sizeof(FAST_IO_DISPATCH
);
348 #pragma prefast(push)
349 #pragma prefast(disable:28155, "these are all correct")
352 CdFastIoDispatch
.FastIoCheckIfPossible
= CdFastIoCheckIfPossible
; // CheckForFastIo
353 CdFastIoDispatch
.FastIoRead
= FsRtlCopyRead
; // Read
354 CdFastIoDispatch
.FastIoQueryBasicInfo
= CdFastQueryBasicInfo
; // QueryBasicInfo
355 CdFastIoDispatch
.FastIoQueryStandardInfo
= CdFastQueryStdInfo
; // QueryStandardInfo
356 CdFastIoDispatch
.FastIoLock
= CdFastLock
; // Lock
357 CdFastIoDispatch
.FastIoUnlockSingle
= CdFastUnlockSingle
; // UnlockSingle
358 CdFastIoDispatch
.FastIoUnlockAll
= CdFastUnlockAll
; // UnlockAll
359 CdFastIoDispatch
.FastIoUnlockAllByKey
= CdFastUnlockAllByKey
; // UnlockAllByKey
361 // This callback has been replaced by CdFilterCallbackAcquireForCreateSection.
364 CdFastIoDispatch
.AcquireFileForNtCreateSection
= NULL
;
365 CdFastIoDispatch
.ReleaseFileForNtCreateSection
= CdReleaseForCreateSection
;
366 CdFastIoDispatch
.FastIoQueryNetworkOpenInfo
= CdFastQueryNetworkInfo
; // QueryNetworkInfo
368 CdFastIoDispatch
.MdlRead
= FsRtlMdlReadDev
;
369 CdFastIoDispatch
.MdlReadComplete
= FsRtlMdlReadCompleteDev
;
370 CdFastIoDispatch
.PrepareMdlWrite
= FsRtlPrepareMdlWriteDev
;
371 CdFastIoDispatch
.MdlWriteComplete
= FsRtlMdlWriteCompleteDev
;
378 // Initialize the CdData structure.
381 RtlZeroMemory( &CdData
, sizeof( CD_DATA
));
383 CdData
.NodeTypeCode
= CDFS_NTC_DATA_HEADER
;
384 CdData
.NodeByteSize
= sizeof( CD_DATA
);
386 CdData
.DriverObject
= DriverObject
;
387 CdData
.FileSystemDeviceObject
= FileSystemDeviceObject
;
389 CdData
.HddFileSystemDeviceObject
= HddFileSystemDeviceObject
;
392 InitializeListHead( &CdData
.VcbQueue
);
394 ExInitializeResourceLite( &CdData
.DataResource
);
397 // Initialize the cache manager callback routines
400 CdData
.CacheManagerCallbacks
.AcquireForLazyWrite
= (PVOID
)&CdAcquireForCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
401 CdData
.CacheManagerCallbacks
.ReleaseFromLazyWrite
= (PVOID
)&CdReleaseFromCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
402 CdData
.CacheManagerCallbacks
.AcquireForReadAhead
= (PVOID
)&CdAcquireForCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
403 CdData
.CacheManagerCallbacks
.ReleaseFromReadAhead
= (PVOID
)&CdReleaseFromCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
405 CdData
.CacheManagerVolumeCallbacks
.AcquireForLazyWrite
= &CdNoopAcquire
;
406 CdData
.CacheManagerVolumeCallbacks
.ReleaseFromLazyWrite
= &CdNoopRelease
;
407 CdData
.CacheManagerVolumeCallbacks
.AcquireForReadAhead
= &CdNoopAcquire
;
408 CdData
.CacheManagerVolumeCallbacks
.ReleaseFromReadAhead
= &CdNoopRelease
;
411 // Initialize the lock mutex and the async and delay close queues.
414 ExInitializeFastMutex( &CdData
.CdDataMutex
);
415 InitializeListHead( &CdData
.AsyncCloseQueue
);
416 InitializeListHead( &CdData
.DelayedCloseQueue
);
418 CdData
.CloseItem
= IoAllocateWorkItem (FileSystemDeviceObject
);
419 if (CdData
.CloseItem
== NULL
) {
421 ExDeleteResourceLite( &CdData
.DataResource
);
422 return STATUS_INSUFFICIENT_RESOURCES
;
425 // Do the initialization based on the system size.
428 switch (MmQuerySystemSize()) {
432 CdData
.IrpContextMaxDepth
= 4;
433 CdData
.MaxDelayedCloseCount
= 8;
434 CdData
.MinDelayedCloseCount
= 2;
439 CdData
.IrpContextMaxDepth
= 8;
440 CdData
.MaxDelayedCloseCount
= 24;
441 CdData
.MinDelayedCloseCount
= 6;
446 CdData
.IrpContextMaxDepth
= 32;
447 CdData
.MaxDelayedCloseCount
= 72;
448 CdData
.MinDelayedCloseCount
= 18;
451 return STATUS_SUCCESS
;