ReactOS  0.4.13-dev-563-g0561610
cdinit.c
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) 1989-2000 Microsoft Corporation
4 
5 Module Name:
6 
7  CdInit.c
8 
9 Abstract:
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.
25 DRIVER_INITIALIZE DriverEntry;
26 
28 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
32  );
33 
34 
35 // tell prefast this is a driver unload function
36 DRIVER_UNLOAD CdUnload;
37 
38 VOID
39 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
40 CdUnload(
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 
66 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
70  )
71 
72 /*++
73 
74 Routine 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 
80 Arguments:
81 
82  DriverObject - Pointer to driver object created by the system.
83 
84 Return 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 
106  RtlInitUnicodeString( &UnicodeString, L"\\Cdfs" );
107 
109  0,
110  &UnicodeString,
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,
129  &UnicodeString,
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 
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 
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
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 
260 VOID
261 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
264  )
265 /*++
266 
267 Routine Description:
268 
269  This routine unload routine for CDFS.
270 
271 Arguments:
272 
273  DriverObject - Supplies the driver object for CDFS.
274 
275 Return 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) {
291  IrpContext = (PIRP_CONTEXT) PopEntryList( &CdData.IrpContextList) ;
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 
310 NTSTATUS
313  _In_ PDEVICE_OBJECT FileSystemDeviceObject
314 #ifdef __REACTOS__
315  ,
316  IN PDEVICE_OBJECT HddFileSystemDeviceObject
317 #endif
318  )
319 
320 /*++
321 
322 Routine Description:
323 
324  This routine initializes the global cdfs data structures.
325 
326 Arguments:
327 
328  DriverObject - Supplies the driver object for CDFS.
329 
330  FileSystemDeviceObject - Supplies the device object for CDFS.
331 
332 Return 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 IN
Definition: typedefs.h:38
PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle
Definition: iotypes.h:1696
ULONG MaxDelayedCloseCount
Definition: cdstruc.h:394
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ULONG SizeOfFsFilterCallbacks
Definition: iotypes.h:7069
*BytesInUnicodeString PWCH UnicodeString
Definition: rtlfuncs.h:1980
LIST_ENTRY AsyncCloseQueue
Definition: cdstruc.h:382
PDEVICE_OBJECT FileSystemDeviceObject
Definition: cdstruc.h:356
IRP_CONTEXT * PIRP_CONTEXT
Definition: cdstruc.h:1217
BOOLEAN NTAPI FsRtlMdlReadCompleteDev(IN PFILE_OBJECT FileObject, IN PMDL MemoryDescriptorList, IN PDEVICE_OBJECT DeviceObject)
Definition: fastio.c:1011
#define IRP_MJ_SHUTDOWN
FAST_IO_QUERY_BASIC_INFO CdFastQueryBasicInfo
Definition: cdprocs.h:1886
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
BOOLEAN NTAPI FsRtlMdlWriteCompleteDev(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN PMDL MdlChain, IN PDEVICE_OBJECT DeviceObject)
Definition: fastio.c:1198
CACHE_MANAGER_CALLBACKS CacheManagerCallbacks
Definition: cdstruc.h:415
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
FAST_IO_CHECK_IF_POSSIBLE CdFastIoCheckIfPossible
Definition: cdprocs.h:1961
BOOLEAN NTAPI CdNoopAcquire(_In_ PVOID Fcb, _In_ BOOLEAN Wait)
Definition: resrcsup.c:218
FAST_IO_QUERY_STANDARD_INFO CdFastQueryStdInfo
Definition: cdprocs.h:1898
FAST_IO_QUERY_NETWORK_OPEN_INFO CdFastQueryNetworkInfo
Definition: cdprocs.h:1973
PFAST_IO_MDL_READ MdlRead
Definition: iotypes.h:1705
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite
Definition: iotypes.h:1707
PFAST_IO_UNLOCK_ALL FastIoUnlockAll
Definition: iotypes.h:1697
PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection
Definition: iotypes.h:1701
FAST_MUTEX CdDataMutex
Definition: cdstruc.h:402
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo
Definition: iotypes.h:1703
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
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
PFAST_IO_MDL_READ_COMPLETE MdlReadComplete
Definition: iotypes.h:1706
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
#define PAGED_CODE()
Definition: video.h:57
PIO_WORKITEM CloseItem
Definition: cdstruc.h:422
PFS_FILTER_CALLBACK PreAcquireForSectionSynchronization
Definition: iotypes.h:7071
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo
Definition: iotypes.h:1693
struct _FAST_IO_DISPATCH FAST_IO_DISPATCH
ERESOURCE DataResource
Definition: cdstruc.h:408
NTSTATUS CdInitializeGlobalData(_In_ PDRIVER_OBJECT DriverObject, _In_ PDEVICE_OBJECT FileSystemDeviceObject)
Definition: cdinit.c:311
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
PDRIVER_OBJECT DriverObject
Definition: cdstruc.h:334
SINGLE_LIST_ENTRY IrpContextList
Definition: cdstruc.h:350
void * PVOID
Definition: retypes.h:9
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
FORCEINLINE PSINGLE_LIST_ENTRY PopEntryList(_Inout_ PSINGLE_LIST_ENTRY ListHead)
Definition: rtlfuncs.h:240
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
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
DRIVER_INITIALIZE DriverEntry
Definition: cdinit.c:25
CD_DATA CdData
Definition: cddata.c:42
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
FAST_IO_UNLOCK_SINGLE CdFastUnlockSingle
Definition: cdprocs.h:1926
#define IRP_MJ_FILE_SYSTEM_CONTROL
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
MM_SYSTEMSIZE NTAPI MmQuerySystemSize(VOID)
Definition: mmsup.c:257
PACQUIRE_FOR_LAZY_WRITE AcquireForLazyWrite
Definition: cctypes.h:39
PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey
Definition: iotypes.h:1698
#define CDFS_NTC_DATA_HEADER
Definition: nodetype.h:27
PACQUIRE_FOR_READ_AHEAD AcquireForReadAhead
Definition: cctypes.h:41
struct _CD_DATA CD_DATA
NTSTATUS NTAPI FsRtlRegisterFileSystemFilterCallbacks(PDRIVER_OBJECT FilterDriverObject, PFS_FILTER_CALLBACKS Callbacks)
Definition: fastio.c:1947
PFAST_IO_LOCK FastIoLock
Definition: iotypes.h:1695
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2179
PRELEASE_FROM_READ_AHEAD ReleaseFromReadAhead
Definition: cctypes.h:42
#define DO_LOW_PRIORITY_FILESYSTEM
struct _FS_FILTER_CALLBACKS FS_FILTER_CALLBACKS
FAST_IO_UNLOCK_ALL CdFastUnlockAll
Definition: cdprocs.h:1936
_Acquires_shared_lock_ Fcb BOOLEAN NTAPI CdAcquireForCache(_Inout_ PFCB Fcb, _In_ BOOLEAN Wait)
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
PFAST_IO_READ FastIoRead
Definition: iotypes.h:1691
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1250
DRIVER_DISPATCH * PDRIVER_DISPATCH
Definition: iotypes.h:2153
FAST_IO_UNLOCK_ALL_BY_KEY CdFastUnlockAllByKey
Definition: cdprocs.h:1947
FAST_IO_DISPATCH CdFastIoDispatch
Definition: cddata.c:43
#define CdFreePool(x)
Definition: cdprocs.h:2200
CACHE_MANAGER_CALLBACKS CacheManagerVolumeCallbacks
Definition: cdstruc.h:416
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
LIST_ENTRY DelayedCloseQueue
Definition: cdstruc.h:392
PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo
Definition: iotypes.h:1694
LIST_ENTRY VcbQueue
Definition: cdstruc.h:340
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
#define IRP_MJ_READ
Definition: rdpdr.c:46
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
VOID NTAPI CdNoopRelease(_In_ PVOID Fcb)
Definition: resrcsup.c:254
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:992
struct _FAST_IO_DISPATCH * FastIoDispatch
Definition: iotypes.h:2176
PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete
Definition: iotypes.h:1708
#define IRP_MJ_CLEANUP
ULONG IrpContextMaxDepth
Definition: cdstruc.h:349
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM
Definition: winioctl.h:108
#define ObReferenceObject
Definition: obfuncs.h:204
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2180
PRELEASE_FROM_LAZY_WRITE ReleaseFromLazyWrite
Definition: cctypes.h:40
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
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
PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible
Definition: iotypes.h:1690
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection
Definition: iotypes.h:1700
return STATUS_SUCCESS
Definition: btrfs.c:2777
NODE_BYTE_SIZE NodeByteSize
Definition: cdstruc.h:328
ULONG MinDelayedCloseCount
Definition: cdstruc.h:395
FAST_IO_LOCK CdFastLock
Definition: cdprocs.h:1913
DRIVER_UNLOAD CdUnload
Definition: cdinit.c:36
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
ULONG SizeOfFastIoDispatch
Definition: iotypes.h:1689