Leaked source code of windows server 2003
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.

377 lines
11 KiB

  1. /*++
  2. Copyright (c) 1996-2000 Microsoft Corporation
  3. Module Name:
  4. UdfInit.c
  5. Abstract:
  6. This module implements the DRIVER_INITIALIZATION routine for Udfs
  7. // @@BEGIN_DDKSPLIT
  8. Author:
  9. Dan Lovinger [DanLo] 24-May-1996
  10. Tom Jolly [tomjolly] 21-Jan-2000
  11. Revision History:
  12. // @@END_DDKSPLIT
  13. --*/
  14. #include "UdfProcs.h"
  15. //
  16. // The Bug check file id for this module
  17. //
  18. #define BugCheckFileId (UDFS_BUG_CHECK_UDFINIT)
  19. //
  20. // The local debug trace level
  21. //
  22. #define Dbg (UDFS_DEBUG_LEVEL_UDFINIT)
  23. NTSTATUS
  24. DriverEntry(
  25. IN PDRIVER_OBJECT DriverObject,
  26. IN PUNICODE_STRING RegistryPath
  27. );
  28. VOID
  29. UdfInitializeGlobalData (
  30. IN PDRIVER_OBJECT DriverObject,
  31. IN PDEVICE_OBJECT *FileSystemDeviceObjects
  32. );
  33. #ifdef ALLOC_PRAGMA
  34. #pragma alloc_text(INIT, DriverEntry)
  35. #pragma alloc_text(INIT, UdfInitializeGlobalData)
  36. #endif
  37. //
  38. // Local support routine
  39. //
  40. NTSTATUS
  41. DriverEntry(
  42. IN PDRIVER_OBJECT DriverObject,
  43. IN PUNICODE_STRING RegistryPath
  44. )
  45. /*++
  46. Routine Description:
  47. This is the initialization routine for the UDF file system
  48. device driver. This routine creates the device object for the FileSystem
  49. device and performs all other driver initialization.
  50. Arguments:
  51. DriverObject - Pointer to driver object created by the system.
  52. Return Value:
  53. NTSTATUS - The function value is the final status from the initialization
  54. operation.
  55. --*/
  56. {
  57. NTSTATUS Status;
  58. UNICODE_STRING UnicodeString;
  59. PDEVICE_OBJECT UdfsFileSystemDeviceObjects[NUMBER_OF_FS_OBJECTS];
  60. PDEVICE_OBJECT UdfsDiskFileSystemDeviceObject;
  61. //
  62. // Create the device objects for both device "types". Since
  63. // UDF is a legitimate filesystem for media underlying device
  64. // drivers claiming both DVD/CDROMs and disks, we must register
  65. // this filesystem twice.
  66. //
  67. ASSERT( NUMBER_OF_FS_OBJECTS >= 2 );
  68. RtlZeroMemory( UdfsFileSystemDeviceObjects, sizeof(PDEVICE_OBJECT) * NUMBER_OF_FS_OBJECTS );
  69. RtlInitUnicodeString( &UnicodeString, L"\\UdfsCdRom" );
  70. Status = IoCreateDevice( DriverObject,
  71. 0,
  72. &UnicodeString,
  73. FILE_DEVICE_CD_ROM_FILE_SYSTEM,
  74. 0,
  75. FALSE,
  76. &UdfsFileSystemDeviceObjects[0] );
  77. if (!NT_SUCCESS( Status )) {
  78. return Status;
  79. }
  80. RtlInitUnicodeString( &UnicodeString, L"\\UdfsDisk" );
  81. Status = IoCreateDevice( DriverObject,
  82. 0,
  83. &UnicodeString,
  84. FILE_DEVICE_DISK_FILE_SYSTEM,
  85. 0,
  86. FALSE,
  87. &UdfsFileSystemDeviceObjects[1] );
  88. if (!NT_SUCCESS( Status )) {
  89. ObDereferenceObject( UdfsFileSystemDeviceObjects[0] );
  90. return Status;
  91. }
  92. try {
  93. Status = STATUS_SUCCESS;
  94. //
  95. // Initialize the global data structures
  96. //
  97. UdfInitializeGlobalData( DriverObject, UdfsFileSystemDeviceObjects );
  98. //
  99. // Note that because of the way data caching is done, we set neither
  100. // the Direct I/O or Buffered I/O bit in DeviceObject->Flags. If
  101. // data is not in the cache, or the request is not buffered, we may,
  102. // set up for Direct I/O by hand.
  103. //
  104. //
  105. // Initialize the driver object with this driver's entry points.
  106. //
  107. // NOTE - Each entry in the dispatch table must have an entry in
  108. // the Fsp/Fsd dispatch switch statements.
  109. //
  110. DriverObject->MajorFunction[IRP_MJ_CREATE] =
  111. DriverObject->MajorFunction[IRP_MJ_CLOSE] =
  112. DriverObject->MajorFunction[IRP_MJ_READ] =
  113. DriverObject->MajorFunction[IRP_MJ_WRITE] =
  114. DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
  115. DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
  116. DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION]=
  117. DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] =
  118. DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
  119. DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
  120. DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] =
  121. DriverObject->MajorFunction[IRP_MJ_CLEANUP] =
  122. DriverObject->MajorFunction[IRP_MJ_PNP] = (PDRIVER_DISPATCH) UdfFsdDispatch;
  123. DriverObject->FastIoDispatch = &UdfFastIoDispatch;
  124. //
  125. // Register the file system with the I/O system
  126. //
  127. IoRegisterFileSystem( UdfsFileSystemDeviceObjects[0] );
  128. IoRegisterFileSystem( UdfsFileSystemDeviceObjects[1] );
  129. }
  130. except (FsRtlIsNtstatusExpected(GetExceptionCode()) ?
  131. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
  132. ObDereferenceObject( UdfsFileSystemDeviceObjects[0] );
  133. ObDereferenceObject( UdfsFileSystemDeviceObjects[1] );
  134. Status = GetExceptionCode();
  135. }
  136. //
  137. // And return to our caller
  138. //
  139. return Status;
  140. }
  141. //
  142. // Local support routine
  143. //
  144. #define NPagedInit(L,S,T) { ExInitializeNPagedLookasideList( (L), NULL, NULL, POOL_RAISE_IF_ALLOCATION_FAILURE, S, T, 0); }
  145. #define PagedInit(L,S,T) { ExInitializePagedLookasideList( (L), NULL, NULL, POOL_RAISE_IF_ALLOCATION_FAILURE, S, T, 0); }
  146. VOID
  147. UdfInitializeGlobalData (
  148. IN PDRIVER_OBJECT DriverObject,
  149. IN PDEVICE_OBJECT *UdfsFileSystemDeviceObjects
  150. )
  151. /*++
  152. Routine Description:
  153. This routine initializes the global Udfs data structures.
  154. Arguments:
  155. DriverObject - Supplies the driver object for UDFS.
  156. FileSystemDeviceObjects - Supplies a vector of device objects for UDFS.
  157. Return Value:
  158. None.
  159. --*/
  160. {
  161. TIMESTAMP UdfTime;
  162. //
  163. // Initialize the CRC table. Per UDF 1.01, we use the seed 10041 octal (4129 dec).
  164. // We do this first because it can raise (allocates memory)
  165. //
  166. UdfInitializeCrc16( 4129 );
  167. //
  168. // Start by initializing the FastIoDispatch Table.
  169. //
  170. RtlZeroMemory( &UdfFastIoDispatch, sizeof( FAST_IO_DISPATCH ));
  171. UdfFastIoDispatch.SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH);
  172. UdfFastIoDispatch.AcquireFileForNtCreateSection = UdfAcquireForCreateSection;
  173. UdfFastIoDispatch.ReleaseFileForNtCreateSection = UdfReleaseForCreateSection;
  174. UdfFastIoDispatch.FastIoCheckIfPossible = UdfFastIoCheckIfPossible; // CheckForFastIo
  175. UdfFastIoDispatch.FastIoRead = FsRtlCopyRead; // Read
  176. UdfFastIoDispatch.FastIoQueryBasicInfo = NULL; // QueryBasicInfo
  177. UdfFastIoDispatch.FastIoQueryStandardInfo = NULL; // QueryStandardInfo
  178. UdfFastIoDispatch.FastIoLock = NULL; // Lock
  179. UdfFastIoDispatch.FastIoUnlockSingle = NULL; // UnlockSingle
  180. UdfFastIoDispatch.FastIoUnlockAll = NULL; // UnlockAll
  181. UdfFastIoDispatch.FastIoUnlockAllByKey = NULL; // UnlockAllByKey
  182. UdfFastIoDispatch.FastIoQueryNetworkOpenInfo = NULL; // QueryNetworkInfo
  183. UdfFastIoDispatch.MdlRead = FsRtlMdlReadDev;
  184. UdfFastIoDispatch.MdlReadComplete = FsRtlMdlReadCompleteDev;
  185. UdfFastIoDispatch.PrepareMdlWrite = FsRtlPrepareMdlWriteDev;
  186. UdfFastIoDispatch.MdlWriteComplete = FsRtlMdlWriteCompleteDev;
  187. //
  188. // Initialize the UdfData structure.
  189. //
  190. RtlZeroMemory( &UdfData, sizeof( UDF_DATA ));
  191. UdfData.NodeTypeCode = UDFS_NTC_DATA_HEADER;
  192. UdfData.NodeByteSize = sizeof( UDF_DATA );
  193. UdfData.DriverObject = DriverObject;
  194. RtlCopyMemory( &UdfData.FileSystemDeviceObjects,
  195. UdfsFileSystemDeviceObjects,
  196. sizeof(PDEVICE_OBJECT) * NUMBER_OF_FS_OBJECTS );
  197. InitializeListHead( &UdfData.VcbQueue );
  198. ExInitializeResourceLite( &UdfData.DataResource );
  199. #ifdef UDF_CAPTURE_BACKTRACES
  200. //
  201. // Initialize debugging stack backtrace support.
  202. //
  203. UdfData.A.BufferPage = FsRtlAllocatePoolWithTag( UdfPagedPool,
  204. PAGE_SIZE,
  205. TAG_CDROM_TOC);
  206. UdfData.B.BufferPage = FsRtlAllocatePoolWithTag( UdfPagedPool,
  207. PAGE_SIZE,
  208. TAG_CDROM_TOC);
  209. ExInitializeFastMutex( &UdfData.ExceptionInfoMutex);
  210. #endif
  211. //
  212. // Initialize the cache manager callback routines
  213. //
  214. UdfData.CacheManagerCallbacks.AcquireForLazyWrite = &UdfAcquireForCache;
  215. UdfData.CacheManagerCallbacks.ReleaseFromLazyWrite = &UdfReleaseFromCache;
  216. UdfData.CacheManagerCallbacks.AcquireForReadAhead = &UdfAcquireForCache;
  217. UdfData.CacheManagerCallbacks.ReleaseFromReadAhead = &UdfReleaseFromCache;
  218. UdfData.CacheManagerVolumeCallbacks.AcquireForLazyWrite = &UdfNoopAcquire;
  219. UdfData.CacheManagerVolumeCallbacks.ReleaseFromLazyWrite = &UdfNoopRelease;
  220. UdfData.CacheManagerVolumeCallbacks.AcquireForReadAhead = &UdfNoopAcquire;
  221. UdfData.CacheManagerVolumeCallbacks.ReleaseFromReadAhead = &UdfNoopRelease;
  222. //
  223. // Initialize the lock mutex and the async and delay close queues.
  224. //
  225. ExInitializeFastMutex( &UdfData.UdfDataMutex );
  226. InitializeListHead( &UdfData.AsyncCloseQueue );
  227. InitializeListHead( &UdfData.DelayedCloseQueue );
  228. ExInitializeWorkItem( &UdfData.CloseItem,
  229. (PWORKER_THREAD_ROUTINE) UdfFspClose,
  230. NULL );
  231. //
  232. // Do the initialization based on the system size.
  233. //
  234. switch (MmQuerySystemSize()) {
  235. case MmSmallSystem:
  236. UdfData.MaxDelayedCloseCount = 10;
  237. UdfData.MinDelayedCloseCount = 2;
  238. break;
  239. case MmLargeSystem:
  240. UdfData.MaxDelayedCloseCount = 72;
  241. UdfData.MinDelayedCloseCount = 18;
  242. break;
  243. default:
  244. case MmMediumSystem:
  245. UdfData.MaxDelayedCloseCount = 32;
  246. UdfData.MinDelayedCloseCount = 8;
  247. break;
  248. }
  249. NPagedInit( &UdfIrpContextLookasideList, sizeof( IRP_CONTEXT ), TAG_IRP_CONTEXT);
  250. NPagedInit( &UdfFcbNonPagedLookasideList, sizeof( FCB_NONPAGED ), TAG_FCB_NONPAGED);
  251. PagedInit( &UdfCcbLookasideList, sizeof( CCB ), TAG_CCB );
  252. PagedInit( &UdfFcbIndexLookasideList, SIZEOF_FCB_INDEX, TAG_FCB_INDEX );
  253. PagedInit( &UdfFcbDataLookasideList, SIZEOF_FCB_DATA, TAG_FCB_DATA );
  254. PagedInit( &UdfLcbLookasideList, SIZEOF_LOOKASIDE_LCB, TAG_LCB);
  255. //
  256. // Initialize our default time which we use when enumerating FIDs whose
  257. // associated FEs are toast.
  258. //
  259. RtlZeroMemory( &UdfTime, sizeof( TIMESTAMP));
  260. UdfTime.Day = 25;
  261. UdfTime.Month = 7;
  262. UdfTime.Year = 1974;
  263. UdfConvertUdfTimeToNtTime( NULL,
  264. &UdfTime,
  265. &UdfCorruptFileTime);
  266. }