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)
25 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
27 IN PDRIVER_OBJECT DriverObject
,
28 IN PUNICODE_STRING RegistryPath
32 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
34 IN PDRIVER_OBJECT DriverObject
38 CdInitializeGlobalData (
39 IN PDRIVER_OBJECT DriverObject
,
40 IN PDEVICE_OBJECT FileSystemDeviceObject
43 IN PDEVICE_OBJECT HddFileSystemDeviceObject
48 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
50 IN PDEVICE_OBJECT DeviceObject
,
55 #pragma alloc_text(INIT, DriverEntry)
56 #pragma alloc_text(PAGE, CdUnload)
57 #pragma alloc_text(PAGE, CdShutdown)
58 #pragma alloc_text(INIT, CdInitializeGlobalData)
63 // Local support routine
67 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
69 IN PDRIVER_OBJECT DriverObject
,
70 IN PUNICODE_STRING RegistryPath
77 This is the initialization routine for the Cdrom file system
78 device driver. This routine creates the device object for the FileSystem
79 device and performs all other driver initialization.
83 DriverObject - Pointer to driver object created by the system.
87 NTSTATUS - The function value is the final status from the initialization
94 UNICODE_STRING UnicodeString
;
95 PDEVICE_OBJECT CdfsFileSystemDeviceObject
;
97 PDEVICE_OBJECT HddFileSystemDeviceObject
;
101 // Create the device object.
104 RtlInitUnicodeString( &UnicodeString
, L
"\\Cdfs" );
106 Status
= IoCreateDevice( DriverObject
,
109 FILE_DEVICE_CD_ROM_FILE_SYSTEM
,
112 &CdfsFileSystemDeviceObject
);
114 if (!NT_SUCCESS( Status
)) {
120 // Create the HDD device object.
123 RtlInitUnicodeString( &UnicodeString
, L
"\\CdfsHdd" );
125 Status
= IoCreateDevice( DriverObject
,
128 FILE_DEVICE_DISK_FILE_SYSTEM
,
131 &HddFileSystemDeviceObject
);
133 if (!NT_SUCCESS( Status
)) {
134 IoDeleteDevice (CdfsFileSystemDeviceObject
);
138 DriverObject
->DriverUnload
= CdUnload
;
140 // Note that because of the way data caching is done, we set neither
141 // the Direct I/O or Buffered I/O bit in DeviceObject->Flags. If
142 // data is not in the cache, or the request is not buffered, we may,
143 // set up for Direct I/O by hand.
147 // Initialize the driver object with this driver's entry points.
149 // NOTE - Each entry in the dispatch table must have an entry in
150 // the Fsp/Fsd dispatch switch statements.
153 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] =
154 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] =
155 DriverObject
->MajorFunction
[IRP_MJ_READ
] =
156 DriverObject
->MajorFunction
[IRP_MJ_QUERY_INFORMATION
] =
157 DriverObject
->MajorFunction
[IRP_MJ_SET_INFORMATION
] =
158 DriverObject
->MajorFunction
[IRP_MJ_QUERY_VOLUME_INFORMATION
]=
159 DriverObject
->MajorFunction
[IRP_MJ_DIRECTORY_CONTROL
] =
160 DriverObject
->MajorFunction
[IRP_MJ_FILE_SYSTEM_CONTROL
] =
161 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] =
162 DriverObject
->MajorFunction
[IRP_MJ_LOCK_CONTROL
] =
163 DriverObject
->MajorFunction
[IRP_MJ_CLEANUP
] =
164 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = (PDRIVER_DISPATCH
) CdFsdDispatch
;
165 DriverObject
->MajorFunction
[IRP_MJ_SHUTDOWN
] = CdShutdown
;
167 DriverObject
->FastIoDispatch
= &CdFastIoDispatch
;
169 Status
= IoRegisterShutdownNotification (CdfsFileSystemDeviceObject
);
170 if (!NT_SUCCESS (Status
)) {
171 IoDeleteDevice (CdfsFileSystemDeviceObject
);
173 IoDeleteDevice (HddFileSystemDeviceObject
);
179 // Initialize the global data structures
183 Status
= CdInitializeGlobalData( DriverObject
, CdfsFileSystemDeviceObject
);
185 Status
= CdInitializeGlobalData( DriverObject
, CdfsFileSystemDeviceObject
, HddFileSystemDeviceObject
);
187 if (!NT_SUCCESS (Status
)) {
188 IoDeleteDevice (CdfsFileSystemDeviceObject
);
190 IoDeleteDevice (HddFileSystemDeviceObject
);
196 // Register the file system as low priority with the I/O system. This will cause
197 // CDFS to receive mount requests after a) other filesystems currently registered
198 // and b) other normal priority filesystems that may be registered later.
201 CdfsFileSystemDeviceObject
->Flags
|= DO_LOW_PRIORITY_FILESYSTEM
;
203 HddFileSystemDeviceObject
->Flags
|= DO_LOW_PRIORITY_FILESYSTEM
;
206 IoRegisterFileSystem( CdfsFileSystemDeviceObject
);
207 ObReferenceObject (CdfsFileSystemDeviceObject
);
209 IoRegisterFileSystem( HddFileSystemDeviceObject
);
210 ObReferenceObject (HddFileSystemDeviceObject
);
214 // And return to our caller
217 return( STATUS_SUCCESS
);
221 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
223 IN PDEVICE_OBJECT DeviceObject
,
230 This routine is the shutdown handler for CDFS.
234 DeviceObject - Supplies the registered device object for CDFS.
245 ASSERT(DeviceObject
== CdData
.FileSystemDeviceObject
||
246 DeviceObject
== CdData
.HddFileSystemDeviceObject
);
249 IoUnregisterFileSystem (DeviceObject
);
251 IoDeleteDevice (CdData
.FileSystemDeviceObject
);
253 IoDeleteDevice (DeviceObject
);
256 CdCompleteRequest( NULL
, Irp
, STATUS_SUCCESS
);
257 return STATUS_SUCCESS
;
262 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
264 IN PDRIVER_OBJECT DriverObject
270 This routine unload routine for CDFS.
274 DriverObject - Supplies the driver object for CDFS.
282 PIRP_CONTEXT IrpContext
;
285 // Free any IRP contexts
288 IrpContext
= (PIRP_CONTEXT
) PopEntryList( &CdData
.IrpContextList
) ;
289 if (IrpContext
== NULL
) {
292 CdFreePool(&IrpContext
);
295 IoFreeWorkItem (CdData
.CloseItem
);
296 ExDeleteResourceLite( &CdData
.DataResource
);
297 ObDereferenceObject (CdData
.FileSystemDeviceObject
);
299 ObDereferenceObject (CdData
.HddFileSystemDeviceObject
);
304 // Local support routine
308 CdInitializeGlobalData (
309 IN PDRIVER_OBJECT DriverObject
,
310 IN PDEVICE_OBJECT FileSystemDeviceObject
313 IN PDEVICE_OBJECT HddFileSystemDeviceObject
321 This routine initializes the global cdfs data structures.
325 DriverObject - Supplies the driver object for CDFS.
327 FileSystemDeviceObject - Supplies the device object for CDFS.
337 // Start by initializing the FastIoDispatch Table.
340 RtlZeroMemory( &CdFastIoDispatch
, sizeof( FAST_IO_DISPATCH
));
342 CdFastIoDispatch
.SizeOfFastIoDispatch
= sizeof(FAST_IO_DISPATCH
);
343 CdFastIoDispatch
.FastIoCheckIfPossible
= CdFastIoCheckIfPossible
; // CheckForFastIo
344 CdFastIoDispatch
.FastIoRead
= FsRtlCopyRead
; // Read
345 CdFastIoDispatch
.FastIoQueryBasicInfo
= CdFastQueryBasicInfo
; // QueryBasicInfo
346 CdFastIoDispatch
.FastIoQueryStandardInfo
= CdFastQueryStdInfo
; // QueryStandardInfo
347 CdFastIoDispatch
.FastIoLock
= CdFastLock
; // Lock
348 CdFastIoDispatch
.FastIoUnlockSingle
= CdFastUnlockSingle
; // UnlockSingle
349 CdFastIoDispatch
.FastIoUnlockAll
= CdFastUnlockAll
; // UnlockAll
350 CdFastIoDispatch
.FastIoUnlockAllByKey
= CdFastUnlockAllByKey
; // UnlockAllByKey
351 CdFastIoDispatch
.AcquireFileForNtCreateSection
= CdAcquireForCreateSection
;
352 CdFastIoDispatch
.ReleaseFileForNtCreateSection
= CdReleaseForCreateSection
;
353 CdFastIoDispatch
.FastIoQueryNetworkOpenInfo
= CdFastQueryNetworkInfo
; // QueryNetworkInfo
355 CdFastIoDispatch
.MdlRead
= FsRtlMdlReadDev
;
356 CdFastIoDispatch
.MdlReadComplete
= FsRtlMdlReadCompleteDev
;
357 CdFastIoDispatch
.PrepareMdlWrite
= FsRtlPrepareMdlWriteDev
;
358 CdFastIoDispatch
.MdlWriteComplete
= FsRtlMdlWriteCompleteDev
;
361 // Initialize the CdData structure.
364 RtlZeroMemory( &CdData
, sizeof( CD_DATA
));
366 CdData
.NodeTypeCode
= CDFS_NTC_DATA_HEADER
;
367 CdData
.NodeByteSize
= sizeof( CD_DATA
);
369 CdData
.DriverObject
= DriverObject
;
370 CdData
.FileSystemDeviceObject
= FileSystemDeviceObject
;
372 CdData
.HddFileSystemDeviceObject
= HddFileSystemDeviceObject
;
375 InitializeListHead( &CdData
.VcbQueue
);
377 ExInitializeResourceLite( &CdData
.DataResource
);
380 // Initialize the cache manager callback routines
383 CdData
.CacheManagerCallbacks
.AcquireForLazyWrite
= (PVOID
)&CdAcquireForCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
384 CdData
.CacheManagerCallbacks
.ReleaseFromLazyWrite
= (PVOID
)&CdReleaseFromCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
385 CdData
.CacheManagerCallbacks
.AcquireForReadAhead
= (PVOID
)&CdAcquireForCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
386 CdData
.CacheManagerCallbacks
.ReleaseFromReadAhead
= (PVOID
)&CdReleaseFromCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
388 CdData
.CacheManagerVolumeCallbacks
.AcquireForLazyWrite
= &CdNoopAcquire
;
389 CdData
.CacheManagerVolumeCallbacks
.ReleaseFromLazyWrite
= &CdNoopRelease
;
390 CdData
.CacheManagerVolumeCallbacks
.AcquireForReadAhead
= &CdNoopAcquire
;
391 CdData
.CacheManagerVolumeCallbacks
.ReleaseFromReadAhead
= &CdNoopRelease
;
394 // Initialize the lock mutex and the async and delay close queues.
397 ExInitializeFastMutex( &CdData
.CdDataMutex
);
398 InitializeListHead( &CdData
.AsyncCloseQueue
);
399 InitializeListHead( &CdData
.DelayedCloseQueue
);
401 CdData
.CloseItem
= IoAllocateWorkItem (FileSystemDeviceObject
);
402 if (CdData
.CloseItem
== NULL
) {
404 ExDeleteResourceLite( &CdData
.DataResource
);
405 return STATUS_INSUFFICIENT_RESOURCES
;
408 // Do the initialization based on the system size.
411 switch (MmQuerySystemSize()) {
415 CdData
.IrpContextMaxDepth
= 4;
416 CdData
.MaxDelayedCloseCount
= 8;
417 CdData
.MinDelayedCloseCount
= 2;
422 CdData
.IrpContextMaxDepth
= 8;
423 CdData
.MaxDelayedCloseCount
= 24;
424 CdData
.MinDelayedCloseCount
= 6;
429 CdData
.IrpContextMaxDepth
= 32;
430 CdData
.MaxDelayedCloseCount
= 72;
431 CdData
.MinDelayedCloseCount
= 18;
434 return STATUS_SUCCESS
;