ReactOS  0.4.13-dev-479-gec9c8fd
cdinit.c File Reference
#include "cdprocs.h"
Include dependency graph for cdinit.c:

Go to the source code of this file.

Macros

#define BugCheckFileId   (CDFS_BUG_CHECK_CDINIT)
 

Functions

NTSTATUS NTAPI DriverEntry (_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
 
VOID NTAPI CdUnload (_In_ PDRIVER_OBJECT DriverObject)
 
NTSTATUS CdInitializeGlobalData (_In_ PDRIVER_OBJECT DriverObject, _In_ PDEVICE_OBJECT FileSystemDeviceObject)
 

Variables

DRIVER_INITIALIZE DriverEntry
 
DRIVER_UNLOAD CdUnload
 

Macro Definition Documentation

◆ BugCheckFileId

#define BugCheckFileId   (CDFS_BUG_CHECK_CDINIT)

Definition at line 22 of file cdinit.c.

Function Documentation

◆ CdInitializeGlobalData()

NTSTATUS CdInitializeGlobalData ( _In_ PDRIVER_OBJECT  DriverObject,
_In_ PDEVICE_OBJECT  FileSystemDeviceObject 
)

Definition at line 311 of file cdinit.c.

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 }
PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle
Definition: iotypes.h:1696
ULONG MaxDelayedCloseCount
Definition: cdstruc.h:394
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LIST_ENTRY AsyncCloseQueue
Definition: cdstruc.h:382
PDEVICE_OBJECT FileSystemDeviceObject
Definition: cdstruc.h:356
BOOLEAN NTAPI FsRtlMdlReadCompleteDev(IN PFILE_OBJECT FileObject, IN PMDL MemoryDescriptorList, IN PDEVICE_OBJECT DeviceObject)
Definition: fastio.c:1011
FAST_IO_QUERY_BASIC_INFO CdFastQueryBasicInfo
Definition: cdprocs.h:1886
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
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
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
PIO_WORKITEM CloseItem
Definition: cdstruc.h:422
PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo
Definition: iotypes.h:1693
struct _FAST_IO_DISPATCH FAST_IO_DISPATCH
ERESOURCE DataResource
Definition: cdstruc.h:408
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
PDRIVER_OBJECT DriverObject
Definition: cdstruc.h:334
void * PVOID
Definition: retypes.h:9
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
CD_DATA CdData
Definition: cddata.c:42
FAST_IO_UNLOCK_SINGLE CdFastUnlockSingle
Definition: cdprocs.h:1926
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
PFAST_IO_LOCK FastIoLock
Definition: iotypes.h:1695
PRELEASE_FROM_READ_AHEAD ReleaseFromReadAhead
Definition: cctypes.h:42
FAST_IO_UNLOCK_ALL CdFastUnlockAll
Definition: cdprocs.h:1936
_Acquires_shared_lock_ Fcb BOOLEAN NTAPI CdAcquireForCache(_Inout_ PFCB Fcb, _In_ BOOLEAN Wait)
PFAST_IO_READ FastIoRead
Definition: iotypes.h:1691
FAST_IO_UNLOCK_ALL_BY_KEY CdFastUnlockAllByKey
Definition: cdprocs.h:1947
FAST_IO_DISPATCH CdFastIoDispatch
Definition: cddata.c:43
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
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
PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete
Definition: iotypes.h:1708
ULONG IrpContextMaxDepth
Definition: cdstruc.h:349
PRELEASE_FROM_LAZY_WRITE ReleaseFromLazyWrite
Definition: cctypes.h:40
PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible
Definition: iotypes.h:1690
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
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
ULONG SizeOfFastIoDispatch
Definition: iotypes.h:1689

Referenced by DriverEntry().

◆ CdUnload()

VOID NTAPI CdUnload ( _In_ PDRIVER_OBJECT  DriverObject)

Definition at line 262 of file cdinit.c.

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 }
PDEVICE_OBJECT FileSystemDeviceObject
Definition: cdstruc.h:356
IRP_CONTEXT * PIRP_CONTEXT
Definition: cdstruc.h:1217
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
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
ERESOURCE DataResource
Definition: cdstruc.h:408
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
SINGLE_LIST_ENTRY IrpContextList
Definition: cdstruc.h:350
FORCEINLINE PSINGLE_LIST_ENTRY PopEntryList(_Inout_ PSINGLE_LIST_ENTRY ListHead)
Definition: rtlfuncs.h:240
CD_DATA CdData
Definition: cddata.c:42
#define CdFreePool(x)
Definition: cdprocs.h:2200

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( _In_ PDRIVER_OBJECT  DriverObject,
_In_ PUNICODE_STRING  RegistryPath 
)

Definition at line 67 of file cdinit.c.

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 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
ULONG SizeOfFsFilterCallbacks
Definition: iotypes.h:7069
*BytesInUnicodeString PWCH UnicodeString
Definition: rtlfuncs.h:1980
#define IRP_MJ_SHUTDOWN
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
PFS_FILTER_CALLBACK PreAcquireForSectionSynchronization
Definition: iotypes.h:7071
NTSTATUS CdInitializeGlobalData(_In_ PDRIVER_OBJECT DriverObject, _In_ PDEVICE_OBJECT FileSystemDeviceObject)
Definition: cdinit.c:311
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MJ_FILE_SYSTEM_CONTROL
NTSTATUS NTAPI FsRtlRegisterFileSystemFilterCallbacks(PDRIVER_OBJECT FilterDriverObject, PFS_FILTER_CALLBACKS Callbacks)
Definition: fastio.c:1947
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2179
#define DO_LOW_PRIORITY_FILESYSTEM
struct _FS_FILTER_CALLBACKS FS_FILTER_CALLBACKS
Status
Definition: gdiplustypes.h:24
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1250
DRIVER_DISPATCH * PDRIVER_DISPATCH
Definition: iotypes.h:2153
FAST_IO_DISPATCH CdFastIoDispatch
Definition: cddata.c:43
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
#define IRP_MJ_READ
Definition: rdpdr.c:46
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:992
struct _FAST_IO_DISPATCH * FastIoDispatch
Definition: iotypes.h:2176
#define IRP_MJ_CLEANUP
#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
#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
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
return STATUS_SUCCESS
Definition: btrfs.c:2777
DRIVER_UNLOAD CdUnload
Definition: cdinit.c:36
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

Variable Documentation

◆ CdUnload

VOID NTAPI CdUnload

Definition at line 36 of file cdinit.c.

Referenced by DriverEntry().

◆ DriverEntry

DRIVER_INITIALIZE DriverEntry

Definition at line 25 of file cdinit.c.