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
44 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
46 IN PDEVICE_OBJECT DeviceObject
,
51 #pragma alloc_text(INIT, DriverEntry)
52 #pragma alloc_text(PAGE, CdUnload)
53 #pragma alloc_text(PAGE, CdShutdown)
54 #pragma alloc_text(INIT, CdInitializeGlobalData)
59 // Local support routine
63 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
65 IN PDRIVER_OBJECT DriverObject
,
66 IN PUNICODE_STRING RegistryPath
73 This is the initialization routine for the Cdrom file system
74 device driver. This routine creates the device object for the FileSystem
75 device and performs all other driver initialization.
79 DriverObject - Pointer to driver object created by the system.
83 NTSTATUS - The function value is the final status from the initialization
90 UNICODE_STRING UnicodeString
;
91 PDEVICE_OBJECT CdfsFileSystemDeviceObject
;
94 // Create the device object.
97 RtlInitUnicodeString( &UnicodeString
, L
"\\Cdfs" );
99 Status
= IoCreateDevice( DriverObject
,
102 FILE_DEVICE_CD_ROM_FILE_SYSTEM
,
105 &CdfsFileSystemDeviceObject
);
107 if (!NT_SUCCESS( Status
)) {
110 DriverObject
->DriverUnload
= CdUnload
;
112 // Note that because of the way data caching is done, we set neither
113 // the Direct I/O or Buffered I/O bit in DeviceObject->Flags. If
114 // data is not in the cache, or the request is not buffered, we may,
115 // set up for Direct I/O by hand.
119 // Initialize the driver object with this driver's entry points.
121 // NOTE - Each entry in the dispatch table must have an entry in
122 // the Fsp/Fsd dispatch switch statements.
125 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] =
126 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] =
127 DriverObject
->MajorFunction
[IRP_MJ_READ
] =
128 DriverObject
->MajorFunction
[IRP_MJ_QUERY_INFORMATION
] =
129 DriverObject
->MajorFunction
[IRP_MJ_SET_INFORMATION
] =
130 DriverObject
->MajorFunction
[IRP_MJ_QUERY_VOLUME_INFORMATION
]=
131 DriverObject
->MajorFunction
[IRP_MJ_DIRECTORY_CONTROL
] =
132 DriverObject
->MajorFunction
[IRP_MJ_FILE_SYSTEM_CONTROL
] =
133 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] =
134 DriverObject
->MajorFunction
[IRP_MJ_LOCK_CONTROL
] =
135 DriverObject
->MajorFunction
[IRP_MJ_CLEANUP
] =
136 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = (PDRIVER_DISPATCH
) CdFsdDispatch
;
137 DriverObject
->MajorFunction
[IRP_MJ_SHUTDOWN
] = CdShutdown
;
139 DriverObject
->FastIoDispatch
= &CdFastIoDispatch
;
141 Status
= IoRegisterShutdownNotification (CdfsFileSystemDeviceObject
);
142 if (!NT_SUCCESS (Status
)) {
143 IoDeleteDevice (CdfsFileSystemDeviceObject
);
148 // Initialize the global data structures
151 Status
= CdInitializeGlobalData( DriverObject
, CdfsFileSystemDeviceObject
);
152 if (!NT_SUCCESS (Status
)) {
153 IoDeleteDevice (CdfsFileSystemDeviceObject
);
158 // Register the file system as low priority with the I/O system. This will cause
159 // CDFS to receive mount requests after a) other filesystems currently registered
160 // and b) other normal priority filesystems that may be registered later.
163 CdfsFileSystemDeviceObject
->Flags
|= DO_LOW_PRIORITY_FILESYSTEM
;
165 IoRegisterFileSystem( CdfsFileSystemDeviceObject
);
166 ObReferenceObject (CdfsFileSystemDeviceObject
);
169 // And return to our caller
172 return( STATUS_SUCCESS
);
176 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
178 IN PDEVICE_OBJECT DeviceObject
,
185 This routine is the shutdown handler for CDFS.
189 DeviceObject - Supplies the registered device object for CDFS.
199 IoUnregisterFileSystem (DeviceObject
);
200 IoDeleteDevice (CdData
.FileSystemDeviceObject
);
202 CdCompleteRequest( NULL
, Irp
, STATUS_SUCCESS
);
203 return STATUS_SUCCESS
;
208 NTAPI
/* ReactOS Change: GCC Does not support STDCALL by default */
210 IN PDRIVER_OBJECT DriverObject
216 This routine unload routine for CDFS.
220 DriverObject - Supplies the driver object for CDFS.
228 PIRP_CONTEXT IrpContext
;
231 // Free any IRP contexts
234 IrpContext
= (PIRP_CONTEXT
) PopEntryList( &CdData
.IrpContextList
) ;
235 if (IrpContext
== NULL
) {
238 CdFreePool(&IrpContext
);
241 IoFreeWorkItem (CdData
.CloseItem
);
242 ExDeleteResourceLite( &CdData
.DataResource
);
243 ObDereferenceObject (CdData
.FileSystemDeviceObject
);
247 // Local support routine
251 CdInitializeGlobalData (
252 IN PDRIVER_OBJECT DriverObject
,
253 IN PDEVICE_OBJECT FileSystemDeviceObject
260 This routine initializes the global cdfs data structures.
264 DriverObject - Supplies the driver object for CDFS.
266 FileSystemDeviceObject - Supplies the device object for CDFS.
276 // Start by initializing the FastIoDispatch Table.
279 RtlZeroMemory( &CdFastIoDispatch
, sizeof( FAST_IO_DISPATCH
));
281 CdFastIoDispatch
.SizeOfFastIoDispatch
= sizeof(FAST_IO_DISPATCH
);
282 CdFastIoDispatch
.FastIoCheckIfPossible
= CdFastIoCheckIfPossible
; // CheckForFastIo
283 CdFastIoDispatch
.FastIoRead
= FsRtlCopyRead
; // Read
284 CdFastIoDispatch
.FastIoQueryBasicInfo
= CdFastQueryBasicInfo
; // QueryBasicInfo
285 CdFastIoDispatch
.FastIoQueryStandardInfo
= CdFastQueryStdInfo
; // QueryStandardInfo
286 CdFastIoDispatch
.FastIoLock
= CdFastLock
; // Lock
287 CdFastIoDispatch
.FastIoUnlockSingle
= CdFastUnlockSingle
; // UnlockSingle
288 CdFastIoDispatch
.FastIoUnlockAll
= CdFastUnlockAll
; // UnlockAll
289 CdFastIoDispatch
.FastIoUnlockAllByKey
= CdFastUnlockAllByKey
; // UnlockAllByKey
290 CdFastIoDispatch
.AcquireFileForNtCreateSection
= CdAcquireForCreateSection
;
291 CdFastIoDispatch
.ReleaseFileForNtCreateSection
= CdReleaseForCreateSection
;
292 CdFastIoDispatch
.FastIoQueryNetworkOpenInfo
= CdFastQueryNetworkInfo
; // QueryNetworkInfo
294 CdFastIoDispatch
.MdlRead
= FsRtlMdlReadDev
;
295 CdFastIoDispatch
.MdlReadComplete
= FsRtlMdlReadCompleteDev
;
296 CdFastIoDispatch
.PrepareMdlWrite
= FsRtlPrepareMdlWriteDev
;
297 CdFastIoDispatch
.MdlWriteComplete
= FsRtlMdlWriteCompleteDev
;
300 // Initialize the CdData structure.
303 RtlZeroMemory( &CdData
, sizeof( CD_DATA
));
305 CdData
.NodeTypeCode
= CDFS_NTC_DATA_HEADER
;
306 CdData
.NodeByteSize
= sizeof( CD_DATA
);
308 CdData
.DriverObject
= DriverObject
;
309 CdData
.FileSystemDeviceObject
= FileSystemDeviceObject
;
311 InitializeListHead( &CdData
.VcbQueue
);
313 ExInitializeResourceLite( &CdData
.DataResource
);
316 // Initialize the cache manager callback routines
319 CdData
.CacheManagerCallbacks
.AcquireForLazyWrite
= (PVOID
)&CdAcquireForCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
320 CdData
.CacheManagerCallbacks
.ReleaseFromLazyWrite
= (PVOID
)&CdReleaseFromCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
321 CdData
.CacheManagerCallbacks
.AcquireForReadAhead
= (PVOID
)&CdAcquireForCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
322 CdData
.CacheManagerCallbacks
.ReleaseFromReadAhead
= (PVOID
)&CdReleaseFromCache
;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
324 CdData
.CacheManagerVolumeCallbacks
.AcquireForLazyWrite
= &CdNoopAcquire
;
325 CdData
.CacheManagerVolumeCallbacks
.ReleaseFromLazyWrite
= &CdNoopRelease
;
326 CdData
.CacheManagerVolumeCallbacks
.AcquireForReadAhead
= &CdNoopAcquire
;
327 CdData
.CacheManagerVolumeCallbacks
.ReleaseFromReadAhead
= &CdNoopRelease
;
330 // Initialize the lock mutex and the async and delay close queues.
333 ExInitializeFastMutex( &CdData
.CdDataMutex
);
334 InitializeListHead( &CdData
.AsyncCloseQueue
);
335 InitializeListHead( &CdData
.DelayedCloseQueue
);
337 CdData
.CloseItem
= IoAllocateWorkItem (FileSystemDeviceObject
);
338 if (CdData
.CloseItem
== NULL
) {
340 ExDeleteResourceLite( &CdData
.DataResource
);
341 return STATUS_INSUFFICIENT_RESOURCES
;
344 // Do the initialization based on the system size.
347 switch (MmQuerySystemSize()) {
351 CdData
.IrpContextMaxDepth
= 4;
352 CdData
.MaxDelayedCloseCount
= 8;
353 CdData
.MinDelayedCloseCount
= 2;
358 CdData
.IrpContextMaxDepth
= 8;
359 CdData
.MaxDelayedCloseCount
= 24;
360 CdData
.MinDelayedCloseCount
= 6;
365 CdData
.IrpContextMaxDepth
= 32;
366 CdData
.MaxDelayedCloseCount
= 72;
367 CdData
.MinDelayedCloseCount
= 18;
370 return STATUS_SUCCESS
;