ReactOS 0.4.15-dev-7711-g5627da4
cdinit.c
Go to the documentation of this file.
1/*++
2
3Copyright (c) 1989-2000 Microsoft Corporation
4
5Module Name:
6
7 CdInit.c
8
9Abstract:
10
11 This module implements the DRIVER_INITIALIZATION routine for Cdfs
12
13
14--*/
15
16#include "cdprocs.h"
17
18//
19// The Bug check file id for this module
20//
21
22#define BugCheckFileId (CDFS_BUG_CHECK_CDINIT)
23
24// Tell prefast the function type.
25DRIVER_INITIALIZE DriverEntry;
26
28NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
32 );
33
34
35// tell prefast this is a driver unload function
36DRIVER_UNLOAD CdUnload;
37
38VOID
39NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
42 );
43
47 _In_ PDEVICE_OBJECT FileSystemDeviceObject
48#ifdef __REACTOS__
49 ,
50 IN PDEVICE_OBJECT HddFileSystemDeviceObject
51#endif
52 );
53
54#ifdef ALLOC_PRAGMA
55#pragma alloc_text(INIT, DriverEntry)
56#pragma alloc_text(PAGE, CdUnload)
57#pragma alloc_text(INIT, CdInitializeGlobalData)
58#endif
59
60
61//
62// Local support routine
63//
64
66NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
70 )
71
72/*++
73
74Routine Description:
75
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.
79
80Arguments:
81
82 DriverObject - Pointer to driver object created by the system.
83
84Return Value:
85
86 NTSTATUS - The function value is the final status from the initialization
87 operation.
88
89--*/
90
91{
94 PDEVICE_OBJECT CdfsFileSystemDeviceObject;
95 FS_FILTER_CALLBACKS FilterCallbacks;
96#ifdef __REACTOS__
97 PDEVICE_OBJECT HddFileSystemDeviceObject;
98#endif
99
101
102 //
103 // Create the device object.
104 //
105
107
109 0,
112 0,
113 FALSE,
114 &CdfsFileSystemDeviceObject );
115
116 if (!NT_SUCCESS( Status )) {
117 return Status;
118 }
119
120#ifdef __REACTOS__
121 //
122 // Create the HDD device object.
123 //
124
125 RtlInitUnicodeString( &UnicodeString, L"\\CdfsHdd" );
126
128 0,
131 0,
132 FALSE,
133 &HddFileSystemDeviceObject );
134
135 if (!NT_SUCCESS( Status )) {
136 IoDeleteDevice (CdfsFileSystemDeviceObject);
137 return Status;
138 }
139#endif
140
141#ifdef _MSC_VER
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.")
147#endif
148
149 DriverObject->DriverUnload = CdUnload;
150
151 //
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.
156 //
157
158 //
159 // Initialize the driver object with this driver's entry points.
160 //
161 // NOTE - Each entry in the dispatch table must have an entry in
162 // the Fsp/Fsd dispatch switch statements.
163 //
164
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] =
172 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_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;
179#ifdef _MSC_VER
180#pragma prefast(pop)
181
182#pragma prefast(suppress: 28175, "this is a file system driver, we're allowed to touch FastIoDispatch.")
183#endif
184 DriverObject->FastIoDispatch = &CdFastIoDispatch;
185
186 //
187 // Initialize the filter callbacks we use.
188 //
189
190 RtlZeroMemory( &FilterCallbacks,
191 sizeof(FS_FILTER_CALLBACKS) );
192
193 FilterCallbacks.SizeOfFsFilterCallbacks = sizeof(FS_FILTER_CALLBACKS);
194 FilterCallbacks.PreAcquireForSectionSynchronization = CdFilterCallbackAcquireForCreateSection;
195
197 &FilterCallbacks );
198
199 if (!NT_SUCCESS( Status )) {
200
201 IoDeleteDevice( CdfsFileSystemDeviceObject );
202#ifdef __REACTOS__
203 IoDeleteDevice (HddFileSystemDeviceObject);
204#endif
205 return Status;
206 }
207
208 //
209 // Initialize the global data structures
210 //
211
212#ifndef __REACTOS__
213 Status = CdInitializeGlobalData( DriverObject, CdfsFileSystemDeviceObject );
214#else
215 Status = CdInitializeGlobalData( DriverObject, CdfsFileSystemDeviceObject, HddFileSystemDeviceObject );
216#endif
217 if (!NT_SUCCESS (Status)) {
218 IoDeleteDevice (CdfsFileSystemDeviceObject);
219#ifdef __REACTOS__
220 IoDeleteDevice (HddFileSystemDeviceObject);
221#endif
222 return Status;
223 }
224
225 //
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.
229 //
230
231 CdfsFileSystemDeviceObject->Flags |= DO_LOW_PRIORITY_FILESYSTEM;
232#ifdef __REACTOS__
233 HddFileSystemDeviceObject->Flags |= DO_LOW_PRIORITY_FILESYSTEM;
234#endif
235
236 IoRegisterFileSystem( CdfsFileSystemDeviceObject );
237 ObReferenceObject (CdfsFileSystemDeviceObject);
238#ifdef __REACTOS__
239 IoRegisterFileSystem( HddFileSystemDeviceObject );
240 ObReferenceObject (HddFileSystemDeviceObject);
241#endif
242
243#ifdef CDFS_TELEMETRY_DATA
244 //
245 // Initialize Telemetry
246 //
247
248 CdInitializeTelemetry();
249
250#endif
251
252 //
253 // And return to our caller
254 //
255
256 return( STATUS_SUCCESS );
257}
258
259
260VOID
261NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
264 )
265/*++
266
267Routine Description:
268
269 This routine unload routine for CDFS.
270
271Arguments:
272
273 DriverObject - Supplies the driver object for CDFS.
274
275Return Value:
276
277 None.
278
279--*/
280{
281 PIRP_CONTEXT IrpContext;
282
283 PAGED_CODE();
284
286
287 //
288 // Free any IRP contexts
289 //
290 while (1) {
292 if (IrpContext == NULL) {
293 break;
294 }
295 CdFreePool(&IrpContext);
296 }
297
301#ifdef __REACTOS__
302 ObDereferenceObject (CdData.HddFileSystemDeviceObject);
303#endif
304}
305
306//
307// Local support routine
308//
309
313 _In_ PDEVICE_OBJECT FileSystemDeviceObject
314#ifdef __REACTOS__
315 ,
316 IN PDEVICE_OBJECT HddFileSystemDeviceObject
317#endif
318 )
319
320/*++
321
322Routine Description:
323
324 This routine initializes the global cdfs data structures.
325
326Arguments:
327
328 DriverObject - Supplies the driver object for CDFS.
329
330 FileSystemDeviceObject - Supplies the device object for CDFS.
331
332Return Value:
333
334 None.
335
336--*/
337
338{
339 //
340 // Start by initializing the FastIoDispatch Table.
341 //
342
344
346
347#ifdef _MSC_VER
348#pragma prefast(push)
349#pragma prefast(disable:28155, "these are all correct")
350#endif
351
360 //
361 // This callback has been replaced by CdFilterCallbackAcquireForCreateSection.
362 //
363
365 CdFastIoDispatch.ReleaseFileForNtCreateSection = CdReleaseForCreateSection;
367
372
373#ifdef _MSC_VER
374#pragma prefast(pop)
375#endif
376
377 //
378 // Initialize the CdData structure.
379 //
380
381 RtlZeroMemory( &CdData, sizeof( CD_DATA ));
382
383 CdData.NodeTypeCode = CDFS_NTC_DATA_HEADER;
384 CdData.NodeByteSize = sizeof( CD_DATA );
385
387 CdData.FileSystemDeviceObject = FileSystemDeviceObject;
388#ifdef __REACTOS__
389 CdData.HddFileSystemDeviceObject = HddFileSystemDeviceObject;
390#endif
391
393
395
396 //
397 // Initialize the cache manager callback routines
398 //
399
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" */
404
409
410 //
411 // Initialize the lock mutex and the async and delay close queues.
412 //
413
417
418 CdData.CloseItem = IoAllocateWorkItem (FileSystemDeviceObject);
419 if (CdData.CloseItem == NULL) {
420
423 }
424 //
425 // Do the initialization based on the system size.
426 //
427
428 switch (MmQuerySystemSize()) {
429
430 case MmSmallSystem:
431
435 break;
436
437 case MmMediumSystem:
438
442 break;
443
444 case MmLargeSystem:
445
449 break;
450 }
451 return STATUS_SUCCESS;
452}
453
#define PAGED_CODE()
LONG NTSTATUS
Definition: precomp.h:26
CD_DATA CdData
Definition: cddata.c:42
FAST_IO_DISPATCH CdFastIoDispatch
Definition: cddata.c:43
DRIVER_INITIALIZE DriverEntry
Definition: cdinit.c:25
DRIVER_UNLOAD CdUnload
Definition: cdinit.c:36
NTSTATUS CdInitializeGlobalData(_In_ PDRIVER_OBJECT DriverObject, _In_ PDEVICE_OBJECT FileSystemDeviceObject)
Definition: cdinit.c:311
FAST_IO_QUERY_NETWORK_OPEN_INFO CdFastQueryNetworkInfo
Definition: cdprocs.h:1963
VOID NTAPI CdNoopRelease(_In_ PVOID Fcb)
Definition: resrcsup.c:254
FAST_IO_QUERY_STANDARD_INFO CdFastQueryStdInfo
Definition: cdprocs.h:1888
FAST_IO_CHECK_IF_POSSIBLE CdFastIoCheckIfPossible
Definition: cdprocs.h:1951
FAST_IO_UNLOCK_SINGLE CdFastUnlockSingle
Definition: cdprocs.h:1916
FAST_IO_QUERY_BASIC_INFO CdFastQueryBasicInfo
Definition: cdprocs.h:1876
FAST_IO_UNLOCK_ALL CdFastUnlockAll
Definition: cdprocs.h:1926
#define CdFreePool(x)
Definition: cdprocs.h:2190
FAST_IO_UNLOCK_ALL_BY_KEY CdFastUnlockAllByKey
Definition: cdprocs.h:1937
FAST_IO_LOCK CdFastLock
Definition: cdprocs.h:1903
BOOLEAN NTAPI CdNoopAcquire(_In_ PVOID Fcb, _In_ BOOLEAN Wait)
Definition: resrcsup.c:218
_Acquires_shared_lock_ Fcb BOOLEAN NTAPI CdAcquireForCache(_Inout_ PFCB Fcb, _In_ BOOLEAN Wait)
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
struct _CD_DATA CD_DATA
IRP_CONTEXT * PIRP_CONTEXT
Definition: cdstruc.h:1211
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define CDFS_NTC_DATA_HEADER
Definition: nodetype.h:27
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define ExDeleteResourceLite(res)
Definition: env_spec_w32.h:647
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
Status
Definition: gdiplustypes.h:25
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
MM_SYSTEMSIZE NTAPI MmQuerySystemSize(VOID)
Definition: mmsup.c:257
#define _In_
Definition: ms_sal.h:308
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
BOOLEAN NTAPI FsRtlMdlWriteCompleteDev(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN PMDL MdlChain, IN PDEVICE_OBJECT DeviceObject)
Definition: fastio.c:1198
BOOLEAN NTAPI FsRtlMdlReadCompleteDev(IN PFILE_OBJECT FileObject, IN PMDL MemoryDescriptorList, IN PDEVICE_OBJECT DeviceObject)
Definition: fastio.c:1011
BOOLEAN NTAPI FsRtlCopyRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, IN ULONG LockKey, OUT PVOID Buffer, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
Definition: fastio.c:64
BOOLEAN NTAPI FsRtlPrepareMdlWriteDev(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG LockKey, OUT PMDL *MdlChain, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
Definition: fastio.c:1272
NTSTATUS NTAPI FsRtlRegisterFileSystemFilterCallbacks(PDRIVER_OBJECT FilterDriverObject, PFS_FILTER_CALLBACKS Callbacks)
Definition: fastio.c:2008
BOOLEAN NTAPI FsRtlMdlReadDev(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG LockKey, OUT PMDL *MdlChain, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
Definition: fastio.c:1025
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:987
#define L(x)
Definition: ntvdm.h:50
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:114
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM
Definition: winioctl.h:109
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define STATUS_SUCCESS
Definition: shellext.h:65
PACQUIRE_FOR_LAZY_WRITE AcquireForLazyWrite
Definition: cctypes.h:39
PRELEASE_FROM_LAZY_WRITE ReleaseFromLazyWrite
Definition: cctypes.h:40
PACQUIRE_FOR_READ_AHEAD AcquireForReadAhead
Definition: cctypes.h:41
PRELEASE_FROM_READ_AHEAD ReleaseFromReadAhead
Definition: cctypes.h:42
CACHE_MANAGER_CALLBACKS CacheManagerCallbacks
Definition: cdstruc.h:409
ULONG MinDelayedCloseCount
Definition: cdstruc.h:389
NODE_BYTE_SIZE NodeByteSize
Definition: cdstruc.h:322
LIST_ENTRY VcbQueue
Definition: cdstruc.h:334
ERESOURCE DataResource
Definition: cdstruc.h:402
LIST_ENTRY AsyncCloseQueue
Definition: cdstruc.h:376
CACHE_MANAGER_CALLBACKS CacheManagerVolumeCallbacks
Definition: cdstruc.h:410
ULONG MaxDelayedCloseCount
Definition: cdstruc.h:388
PIO_WORKITEM CloseItem
Definition: cdstruc.h:416
ULONG IrpContextMaxDepth
Definition: cdstruc.h:343
SINGLE_LIST_ENTRY IrpContextList
Definition: cdstruc.h:344
PDRIVER_OBJECT DriverObject
Definition: cdstruc.h:328
PDEVICE_OBJECT FileSystemDeviceObject
Definition: cdstruc.h:350
LIST_ENTRY DelayedCloseQueue
Definition: cdstruc.h:386
FAST_MUTEX CdDataMutex
Definition: cdstruc.h:396
PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo
Definition: iotypes.h:1738
PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey
Definition: iotypes.h:1742
PFAST_IO_MDL_READ_COMPLETE MdlReadComplete
Definition: iotypes.h:1750
PFAST_IO_MDL_READ MdlRead
Definition: iotypes.h:1749
PFAST_IO_UNLOCK_ALL FastIoUnlockAll
Definition: iotypes.h:1741
PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo
Definition: iotypes.h:1747
PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete
Definition: iotypes.h:1752
ULONG SizeOfFastIoDispatch
Definition: iotypes.h:1733
PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection
Definition: iotypes.h:1744
PFAST_IO_READ FastIoRead
Definition: iotypes.h:1735
PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo
Definition: iotypes.h:1737
PFAST_IO_LOCK FastIoLock
Definition: iotypes.h:1739
PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle
Definition: iotypes.h:1740
PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection
Definition: iotypes.h:1745
PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite
Definition: iotypes.h:1751
PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible
Definition: iotypes.h:1734
ULONG SizeOfFsFilterCallbacks
Definition: iotypes.h:7426
PFS_FILTER_CALLBACK PreAcquireForSectionSynchronization
Definition: iotypes.h:7428
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define IRP_MJ_FILE_SYSTEM_CONTROL
#define DO_LOW_PRIORITY_FILESYSTEM
DRIVER_DISPATCH * PDRIVER_DISPATCH
Definition: iotypes.h:2262
struct _FS_FILTER_CALLBACKS FS_FILTER_CALLBACKS
struct _FAST_IO_DISPATCH FAST_IO_DISPATCH
#define IRP_MJ_SHUTDOWN
#define IRP_MJ_CLEANUP
@ MmLargeSystem
Definition: mmtypes.h:147
@ MmMediumSystem
Definition: mmtypes.h:146
@ MmSmallSystem
Definition: mmtypes.h:145
#define ObDereferenceObject
Definition: obfuncs.h:203
#define ObReferenceObject
Definition: obfuncs.h:204
FORCEINLINE PSINGLE_LIST_ENTRY PopEntryList(_Inout_ PSINGLE_LIST_ENTRY ListHead)
Definition: rtlfuncs.h:240