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.
244 IoUnregisterFileSystem (DeviceObject
);
245 IoDeleteDevice (CdData
.FileSystemDeviceObject
);
247 IoDeleteDevice (CdData
.HddFileSystemDeviceObject
);
250 CdCompleteRequest( NULL
, Irp
, STATUS_SUCCESS
);
251 return STATUS_SUCCESS
;
256 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
258 IN PDRIVER_OBJECT DriverObject
264 This routine unload routine for CDFS.
268 DriverObject - Supplies the driver object for CDFS.
276 PIRP_CONTEXT IrpContext
;
279 // Free any IRP contexts
282 IrpContext
= (PIRP_CONTEXT
) PopEntryList( &CdData
.IrpContextList
) ;
283 if (IrpContext
== NULL
) {
286 CdFreePool(&IrpContext
);
289 IoFreeWorkItem (CdData
.CloseItem
);
290 ExDeleteResourceLite( &CdData
.DataResource
);
291 ObDereferenceObject (CdData
.FileSystemDeviceObject
);
293 ObDereferenceObject (CdData
.HddFileSystemDeviceObject
);
298 // Local support routine
302 CdInitializeGlobalData (
303 IN PDRIVER_OBJECT DriverObject
,
304 IN PDEVICE_OBJECT FileSystemDeviceObject
307 IN PDEVICE_OBJECT HddFileSystemDeviceObject
315 This routine initializes the global cdfs data structures.
319 DriverObject - Supplies the driver object for CDFS.
321 FileSystemDeviceObject - Supplies the device object for CDFS.
331 // Start by initializing the FastIoDispatch Table.
334 RtlZeroMemory( &CdFastIoDispatch
, sizeof( FAST_IO_DISPATCH
));
336 CdFastIoDispatch
.SizeOfFastIoDispatch
= sizeof(FAST_IO_DISPATCH
);
337 CdFastIoDispatch
.FastIoCheckIfPossible
= CdFastIoCheckIfPossible
; // CheckForFastIo
338 CdFastIoDispatch
.FastIoRead
= FsRtlCopyRead
; // Read
339 CdFastIoDispatch
.FastIoQueryBasicInfo
= CdFastQueryBasicInfo
; // QueryBasicInfo
340 CdFastIoDispatch
.FastIoQueryStandardInfo
= CdFastQueryStdInfo
; // QueryStandardInfo
341 CdFastIoDispatch
.FastIoLock
= CdFastLock
; // Lock
342 CdFastIoDispatch
.FastIoUnlockSingle
= CdFastUnlockSingle
; // UnlockSingle
343 CdFastIoDispatch
.FastIoUnlockAll
= CdFastUnlockAll
; // UnlockAll
344 CdFastIoDispatch
.FastIoUnlockAllByKey
= CdFastUnlockAllByKey
; // UnlockAllByKey
345 CdFastIoDispatch
.AcquireFileForNtCreateSection
= CdAcquireForCreateSection
;
346 CdFastIoDispatch
.ReleaseFileForNtCreateSection
= CdReleaseForCreateSection
;
347 CdFastIoDispatch
.FastIoQueryNetworkOpenInfo
= CdFastQueryNetworkInfo
; // QueryNetworkInfo
349 CdFastIoDispatch
.MdlRead
= FsRtlMdlReadDev
;
350 CdFastIoDispatch
.MdlReadComplete
= FsRtlMdlReadCompleteDev
;
351 CdFastIoDispatch
.PrepareMdlWrite
= FsRtlPrepareMdlWriteDev
;
352 CdFastIoDispatch
.MdlWriteComplete
= FsRtlMdlWriteCompleteDev
;
355 // Initialize the CdData structure.
358 RtlZeroMemory( &CdData
, sizeof( CD_DATA
));
360 CdData
.NodeTypeCode
= CDFS_NTC_DATA_HEADER
;
361 CdData
.NodeByteSize
= sizeof( CD_DATA
);
363 CdData
.DriverObject
= DriverObject
;
364 CdData
.FileSystemDeviceObject
= FileSystemDeviceObject
;
366 CdData
.HddFileSystemDeviceObject
= HddFileSystemDeviceObject
;
369 InitializeListHead( &CdData
.VcbQueue
);
371 ExInitializeResourceLite( &CdData
.DataResource
);
374 // Initialize the cache manager callback routines
377 CdData
.CacheManagerCallbacks
.AcquireForLazyWrite
= (PVOID
)&CdAcquireForCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
378 CdData
.CacheManagerCallbacks
.ReleaseFromLazyWrite
= (PVOID
)&CdReleaseFromCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
379 CdData
.CacheManagerCallbacks
.AcquireForReadAhead
= (PVOID
)&CdAcquireForCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
380 CdData
.CacheManagerCallbacks
.ReleaseFromReadAhead
= (PVOID
)&CdReleaseFromCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
382 CdData
.CacheManagerVolumeCallbacks
.AcquireForLazyWrite
= &CdNoopAcquire
;
383 CdData
.CacheManagerVolumeCallbacks
.ReleaseFromLazyWrite
= &CdNoopRelease
;
384 CdData
.CacheManagerVolumeCallbacks
.AcquireForReadAhead
= &CdNoopAcquire
;
385 CdData
.CacheManagerVolumeCallbacks
.ReleaseFromReadAhead
= &CdNoopRelease
;
388 // Initialize the lock mutex and the async and delay close queues.
391 ExInitializeFastMutex( &CdData
.CdDataMutex
);
392 InitializeListHead( &CdData
.AsyncCloseQueue
);
393 InitializeListHead( &CdData
.DelayedCloseQueue
);
395 CdData
.CloseItem
= IoAllocateWorkItem (FileSystemDeviceObject
);
396 if (CdData
.CloseItem
== NULL
) {
398 ExDeleteResourceLite( &CdData
.DataResource
);
399 return STATUS_INSUFFICIENT_RESOURCES
;
402 // Do the initialization based on the system size.
405 switch (MmQuerySystemSize()) {
409 CdData
.IrpContextMaxDepth
= 4;
410 CdData
.MaxDelayedCloseCount
= 8;
411 CdData
.MinDelayedCloseCount
= 2;
416 CdData
.IrpContextMaxDepth
= 8;
417 CdData
.MaxDelayedCloseCount
= 24;
418 CdData
.MinDelayedCloseCount
= 6;
423 CdData
.IrpContextMaxDepth
= 32;
424 CdData
.MaxDelayedCloseCount
= 72;
425 CdData
.MinDelayedCloseCount
= 18;
428 return STATUS_SUCCESS
;