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.

241 lines
6.0 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. RawInit.c
  5. Abstract:
  6. This module implements the DRIVER_INITIALIZATION routine for Raw
  7. Author:
  8. David Goebel [DavidGoe] 18-Mar-91
  9. Environment:
  10. Kernel mode
  11. Revision History:
  12. --*/
  13. #include "RawProcs.h"
  14. #include <zwapi.h>
  15. NTSTATUS
  16. RawInitialize(
  17. IN PDRIVER_OBJECT DriverObject,
  18. IN PUNICODE_STRING RegistryPath
  19. );
  20. VOID
  21. RawUnload(
  22. IN PDRIVER_OBJECT DriverObject
  23. );
  24. NTSTATUS
  25. RawShutdown (
  26. IN PDEVICE_OBJECT DeviceObject,
  27. IN PIRP Irp
  28. );
  29. #ifdef ALLOC_PRAGMA
  30. #pragma alloc_text(INIT, RawInitialize)
  31. #pragma alloc_text(PAGE, RawUnload)
  32. #pragma alloc_text(PAGE, RawShutdown)
  33. #endif
  34. PDEVICE_OBJECT RawDeviceCdRomObject;
  35. PDEVICE_OBJECT RawDeviceTapeObject;
  36. PDEVICE_OBJECT RawDeviceDiskObject;
  37. NTSTATUS
  38. RawInitialize(
  39. IN PDRIVER_OBJECT DriverObject,
  40. IN PUNICODE_STRING RegistryPath
  41. )
  42. /*++
  43. Routine Description:
  44. This is the initialization routine for the Raw file system
  45. device driver. This routine creates the device object for the FileSystem
  46. device and performs all other driver initialization.
  47. Arguments:
  48. DriverObject - Pointer to driver object created by the system.
  49. Return Value:
  50. NTSTATUS - The function value is the final status from the initialization
  51. operation.
  52. --*/
  53. {
  54. NTSTATUS Status;
  55. UNICODE_STRING NameString;
  56. //
  57. // First create a device object for the Disk file system queue
  58. //
  59. RtlInitUnicodeString( &NameString, L"\\Device\\RawDisk" );
  60. Status = IoCreateDevice( DriverObject,
  61. 0L,
  62. &NameString,
  63. FILE_DEVICE_DISK_FILE_SYSTEM,
  64. 0,
  65. FALSE,
  66. &RawDeviceDiskObject );
  67. if (!NT_SUCCESS( Status )) {
  68. return Status;
  69. }
  70. DriverObject->DriverUnload = RawUnload;
  71. //
  72. // Now create one for the CD ROM file system queue
  73. //
  74. RtlInitUnicodeString( &NameString, L"\\Device\\RawCdRom" );
  75. Status = IoCreateDevice( DriverObject,
  76. 0L,
  77. &NameString,
  78. FILE_DEVICE_CD_ROM_FILE_SYSTEM,
  79. 0,
  80. FALSE,
  81. &RawDeviceCdRomObject );
  82. if (!NT_SUCCESS( Status )) {
  83. IoDeleteDevice (RawDeviceDiskObject);
  84. return Status;
  85. }
  86. //
  87. // And now create one for the Tape file system queue
  88. //
  89. RtlInitUnicodeString( &NameString, L"\\Device\\RawTape" );
  90. Status = IoCreateDevice( DriverObject,
  91. 0L,
  92. &NameString,
  93. FILE_DEVICE_TAPE_FILE_SYSTEM,
  94. 0,
  95. FALSE,
  96. &RawDeviceTapeObject );
  97. if (!NT_SUCCESS( Status )) {
  98. IoDeleteDevice (RawDeviceCdRomObject);
  99. IoDeleteDevice (RawDeviceDiskObject);
  100. return Status;
  101. }
  102. //
  103. // Register a shutdown handler to enable us to unregister the file system objects
  104. //
  105. Status = IoRegisterShutdownNotification (RawDeviceTapeObject);
  106. if (!NT_SUCCESS( Status )) {
  107. IoDeleteDevice (RawDeviceTapeObject);
  108. IoDeleteDevice (RawDeviceCdRomObject);
  109. IoDeleteDevice (RawDeviceDiskObject);
  110. return Status;
  111. }
  112. //
  113. // Raw does direct IO
  114. //
  115. RawDeviceDiskObject->Flags |= DO_DIRECT_IO;
  116. RawDeviceCdRomObject->Flags |= DO_DIRECT_IO;
  117. RawDeviceTapeObject->Flags |= DO_DIRECT_IO;
  118. //
  119. // Initialize the driver object with this driver's entry points. Note
  120. // that only a limited capability is supported by the raw file system.
  121. //
  122. DriverObject->MajorFunction[IRP_MJ_CREATE] =
  123. DriverObject->MajorFunction[IRP_MJ_CLEANUP] =
  124. DriverObject->MajorFunction[IRP_MJ_CLOSE] =
  125. DriverObject->MajorFunction[IRP_MJ_READ] =
  126. DriverObject->MajorFunction[IRP_MJ_WRITE] =
  127. DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
  128. DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
  129. DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] =
  130. DriverObject->MajorFunction[IRP_MJ_CLEANUP] =
  131. DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
  132. DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
  133. DriverObject->MajorFunction[IRP_MJ_PNP] =
  134. (PDRIVER_DISPATCH)RawDispatch;
  135. DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = RawShutdown;
  136. //
  137. // Finally, register this file system in the system.
  138. //
  139. IoRegisterFileSystem( RawDeviceDiskObject );
  140. IoRegisterFileSystem( RawDeviceCdRomObject );
  141. IoRegisterFileSystem( RawDeviceTapeObject );
  142. ObReferenceObject (RawDeviceDiskObject);
  143. ObReferenceObject (RawDeviceCdRomObject);
  144. ObReferenceObject (RawDeviceTapeObject);
  145. //
  146. // And return to our caller
  147. //
  148. return( STATUS_SUCCESS );
  149. }
  150. NTSTATUS
  151. RawShutdown (
  152. IN PDEVICE_OBJECT DeviceObject,
  153. IN PIRP Irp
  154. )
  155. {
  156. //
  157. // Unregister the file system objects so we can unload
  158. //
  159. IoUnregisterFileSystem (RawDeviceDiskObject);
  160. IoUnregisterFileSystem (RawDeviceCdRomObject);
  161. IoUnregisterFileSystem (RawDeviceTapeObject);
  162. IoDeleteDevice (RawDeviceTapeObject);
  163. IoDeleteDevice (RawDeviceCdRomObject);
  164. IoDeleteDevice (RawDeviceDiskObject);
  165. RawCompleteRequest( Irp, STATUS_SUCCESS );
  166. return STATUS_SUCCESS;
  167. }
  168. VOID
  169. RawUnload(
  170. IN PDRIVER_OBJECT DriverObject
  171. )
  172. /*++
  173. Routine Description:
  174. This is the unload routine for the Raw file system
  175. Arguments:
  176. DriverObject - Pointer to driver object created by the system.
  177. Return Value:
  178. None
  179. --*/
  180. {
  181. ObDereferenceObject (RawDeviceTapeObject);
  182. ObDereferenceObject (RawDeviceCdRomObject);
  183. ObDereferenceObject (RawDeviceDiskObject);
  184. }