Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

369 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 1989-2000 Microsoft Corporation
  3. Module Name:
  4. CdInit.c
  5. Abstract:
  6. This module implements the DRIVER_INITIALIZATION routine for Cdfs
  7. // @@BEGIN_DDKSPLIT
  8. Author:
  9. Brian Andrew [BrianAn] 01-July-1995
  10. Revision History:
  11. // @@END_DDKSPLIT
  12. --*/
  13. #include "CdProcs.h"
  14. //
  15. // The Bug check file id for this module
  16. //
  17. #define BugCheckFileId (CDFS_BUG_CHECK_CDINIT)
  18. NTSTATUS
  19. DriverEntry(
  20. IN PDRIVER_OBJECT DriverObject,
  21. IN PUNICODE_STRING RegistryPath
  22. );
  23. VOID
  24. CdUnload(
  25. IN PDRIVER_OBJECT DriverObject
  26. );
  27. NTSTATUS
  28. CdInitializeGlobalData (
  29. IN PDRIVER_OBJECT DriverObject,
  30. IN PDEVICE_OBJECT FileSystemDeviceObject
  31. );
  32. NTSTATUS
  33. CdShutdown (
  34. IN PDEVICE_OBJECT DeviceObject,
  35. IN PIRP Irp
  36. );
  37. #ifdef ALLOC_PRAGMA
  38. #pragma alloc_text(INIT, DriverEntry)
  39. #pragma alloc_text(PAGE, CdUnload)
  40. #pragma alloc_text(PAGE, CdShutdown)
  41. #pragma alloc_text(INIT, CdInitializeGlobalData)
  42. #endif
  43. //
  44. // Local support routine
  45. //
  46. NTSTATUS
  47. DriverEntry(
  48. IN PDRIVER_OBJECT DriverObject,
  49. IN PUNICODE_STRING RegistryPath
  50. )
  51. /*++
  52. Routine Description:
  53. This is the initialization routine for the Cdrom file system
  54. device driver. This routine creates the device object for the FileSystem
  55. device and performs all other driver initialization.
  56. Arguments:
  57. DriverObject - Pointer to driver object created by the system.
  58. Return Value:
  59. NTSTATUS - The function value is the final status from the initialization
  60. operation.
  61. --*/
  62. {
  63. NTSTATUS Status;
  64. UNICODE_STRING UnicodeString;
  65. PDEVICE_OBJECT CdfsFileSystemDeviceObject;
  66. //
  67. // Create the device object.
  68. //
  69. RtlInitUnicodeString( &UnicodeString, L"\\Cdfs" );
  70. Status = IoCreateDevice( DriverObject,
  71. 0,
  72. &UnicodeString,
  73. FILE_DEVICE_CD_ROM_FILE_SYSTEM,
  74. 0,
  75. FALSE,
  76. &CdfsFileSystemDeviceObject );
  77. if (!NT_SUCCESS( Status )) {
  78. return Status;
  79. }
  80. DriverObject->DriverUnload = CdUnload;
  81. //
  82. // Note that because of the way data caching is done, we set neither
  83. // the Direct I/O or Buffered I/O bit in DeviceObject->Flags. If
  84. // data is not in the cache, or the request is not buffered, we may,
  85. // set up for Direct I/O by hand.
  86. //
  87. //
  88. // Initialize the driver object with this driver's entry points.
  89. //
  90. // NOTE - Each entry in the dispatch table must have an entry in
  91. // the Fsp/Fsd dispatch switch statements.
  92. //
  93. DriverObject->MajorFunction[IRP_MJ_CREATE] =
  94. DriverObject->MajorFunction[IRP_MJ_CLOSE] =
  95. DriverObject->MajorFunction[IRP_MJ_READ] =
  96. DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
  97. DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
  98. DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION]=
  99. DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] =
  100. DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
  101. DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
  102. DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] =
  103. DriverObject->MajorFunction[IRP_MJ_CLEANUP] =
  104. DriverObject->MajorFunction[IRP_MJ_PNP] = (PDRIVER_DISPATCH) CdFsdDispatch;
  105. DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = CdShutdown;
  106. DriverObject->FastIoDispatch = &CdFastIoDispatch;
  107. Status = IoRegisterShutdownNotification (CdfsFileSystemDeviceObject);
  108. if (!NT_SUCCESS (Status)) {
  109. IoDeleteDevice (CdfsFileSystemDeviceObject);
  110. return Status;
  111. }
  112. //
  113. // Initialize the global data structures
  114. //
  115. Status = CdInitializeGlobalData( DriverObject, CdfsFileSystemDeviceObject );
  116. if (!NT_SUCCESS (Status)) {
  117. IoDeleteDevice (CdfsFileSystemDeviceObject);
  118. return Status;
  119. }
  120. //
  121. // Register the file system as low priority with the I/O system. This will cause
  122. // CDFS to receive mount requests after a) other filesystems currently registered
  123. // and b) other normal priority filesystems that may be registered later.
  124. //
  125. CdfsFileSystemDeviceObject->Flags |= DO_LOW_PRIORITY_FILESYSTEM;
  126. IoRegisterFileSystem( CdfsFileSystemDeviceObject );
  127. ObReferenceObject (CdfsFileSystemDeviceObject);
  128. //
  129. // And return to our caller
  130. //
  131. return( STATUS_SUCCESS );
  132. }
  133. NTSTATUS
  134. CdShutdown (
  135. IN PDEVICE_OBJECT DeviceObject,
  136. IN PIRP Irp
  137. )
  138. /*++
  139. Routine Description:
  140. This routine is the shutdown handler for CDFS.
  141. Arguments:
  142. DeviceObject - Supplies the registered device object for CDFS.
  143. Irp - Shutdown IRP
  144. Return Value:
  145. None.
  146. --*/
  147. {
  148. IoUnregisterFileSystem (DeviceObject);
  149. IoDeleteDevice (CdData.FileSystemDeviceObject);
  150. CdCompleteRequest( NULL, Irp, STATUS_SUCCESS );
  151. return STATUS_SUCCESS;
  152. }
  153. VOID
  154. CdUnload(
  155. IN PDRIVER_OBJECT DriverObject
  156. )
  157. /*++
  158. Routine Description:
  159. This routine unload routine for CDFS.
  160. Arguments:
  161. DriverObject - Supplies the driver object for CDFS.
  162. Return Value:
  163. None.
  164. --*/
  165. {
  166. PIRP_CONTEXT IrpContext;
  167. //
  168. // Free any IRP contexts
  169. //
  170. while (1) {
  171. IrpContext = (PIRP_CONTEXT) PopEntryList( &CdData.IrpContextList) ;
  172. if (IrpContext == NULL) {
  173. break;
  174. }
  175. ExFreePool (IrpContext);
  176. }
  177. IoFreeWorkItem (CdData.CloseItem);
  178. ExDeleteResourceLite( &CdData.DataResource );
  179. ObDereferenceObject (CdData.FileSystemDeviceObject);
  180. }
  181. //
  182. // Local support routine
  183. //
  184. NTSTATUS
  185. CdInitializeGlobalData (
  186. IN PDRIVER_OBJECT DriverObject,
  187. IN PDEVICE_OBJECT FileSystemDeviceObject
  188. )
  189. /*++
  190. Routine Description:
  191. This routine initializes the global cdfs data structures.
  192. Arguments:
  193. DriverObject - Supplies the driver object for CDFS.
  194. FileSystemDeviceObject - Supplies the device object for CDFS.
  195. Return Value:
  196. None.
  197. --*/
  198. {
  199. //
  200. // Start by initializing the FastIoDispatch Table.
  201. //
  202. RtlZeroMemory( &CdFastIoDispatch, sizeof( FAST_IO_DISPATCH ));
  203. CdFastIoDispatch.SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH);
  204. CdFastIoDispatch.FastIoCheckIfPossible = CdFastIoCheckIfPossible; // CheckForFastIo
  205. CdFastIoDispatch.FastIoRead = FsRtlCopyRead; // Read
  206. CdFastIoDispatch.FastIoQueryBasicInfo = CdFastQueryBasicInfo; // QueryBasicInfo
  207. CdFastIoDispatch.FastIoQueryStandardInfo = CdFastQueryStdInfo; // QueryStandardInfo
  208. CdFastIoDispatch.FastIoLock = CdFastLock; // Lock
  209. CdFastIoDispatch.FastIoUnlockSingle = CdFastUnlockSingle; // UnlockSingle
  210. CdFastIoDispatch.FastIoUnlockAll = CdFastUnlockAll; // UnlockAll
  211. CdFastIoDispatch.FastIoUnlockAllByKey = CdFastUnlockAllByKey; // UnlockAllByKey
  212. CdFastIoDispatch.AcquireFileForNtCreateSection = CdAcquireForCreateSection;
  213. CdFastIoDispatch.ReleaseFileForNtCreateSection = CdReleaseForCreateSection;
  214. CdFastIoDispatch.FastIoQueryNetworkOpenInfo = CdFastQueryNetworkInfo; // QueryNetworkInfo
  215. //
  216. // Initialize the CdData structure.
  217. //
  218. RtlZeroMemory( &CdData, sizeof( CD_DATA ));
  219. CdData.NodeTypeCode = CDFS_NTC_DATA_HEADER;
  220. CdData.NodeByteSize = sizeof( CD_DATA );
  221. CdData.DriverObject = DriverObject;
  222. CdData.FileSystemDeviceObject = FileSystemDeviceObject;
  223. InitializeListHead( &CdData.VcbQueue );
  224. ExInitializeResourceLite( &CdData.DataResource );
  225. //
  226. // Initialize the cache manager callback routines
  227. //
  228. CdData.CacheManagerCallbacks.AcquireForLazyWrite = &CdAcquireForCache;
  229. CdData.CacheManagerCallbacks.ReleaseFromLazyWrite = &CdReleaseFromCache;
  230. CdData.CacheManagerCallbacks.AcquireForReadAhead = &CdAcquireForCache;
  231. CdData.CacheManagerCallbacks.ReleaseFromReadAhead = &CdReleaseFromCache;
  232. CdData.CacheManagerVolumeCallbacks.AcquireForLazyWrite = &CdNoopAcquire;
  233. CdData.CacheManagerVolumeCallbacks.ReleaseFromLazyWrite = &CdNoopRelease;
  234. CdData.CacheManagerVolumeCallbacks.AcquireForReadAhead = &CdNoopAcquire;
  235. CdData.CacheManagerVolumeCallbacks.ReleaseFromReadAhead = &CdNoopRelease;
  236. //
  237. // Initialize the lock mutex and the async and delay close queues.
  238. //
  239. ExInitializeFastMutex( &CdData.CdDataMutex );
  240. InitializeListHead( &CdData.AsyncCloseQueue );
  241. InitializeListHead( &CdData.DelayedCloseQueue );
  242. CdData.CloseItem = IoAllocateWorkItem (FileSystemDeviceObject);
  243. if (CdData.CloseItem == NULL) {
  244. ExDeleteResourceLite( &CdData.DataResource );
  245. return STATUS_INSUFFICIENT_RESOURCES;
  246. }
  247. //
  248. // Do the initialization based on the system size.
  249. //
  250. switch (MmQuerySystemSize()) {
  251. case MmSmallSystem:
  252. CdData.IrpContextMaxDepth = 4;
  253. CdData.MaxDelayedCloseCount = 8;
  254. CdData.MinDelayedCloseCount = 2;
  255. break;
  256. case MmMediumSystem:
  257. CdData.IrpContextMaxDepth = 8;
  258. CdData.MaxDelayedCloseCount = 24;
  259. CdData.MinDelayedCloseCount = 6;
  260. break;
  261. case MmLargeSystem:
  262. CdData.IrpContextMaxDepth = 32;
  263. CdData.MaxDelayedCloseCount = 72;
  264. CdData.MinDelayedCloseCount = 18;
  265. break;
  266. }
  267. return STATUS_SUCCESS;
  268. }