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.

247 lines
6.3 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. UNREFERENCED_PARAMETER (RegistryPath);
  57. //
  58. // First create a device object for the Disk file system queue
  59. //
  60. RtlInitUnicodeString( &NameString, L"\\Device\\RawDisk" );
  61. Status = IoCreateDevice( DriverObject,
  62. 0L,
  63. &NameString,
  64. FILE_DEVICE_DISK_FILE_SYSTEM,
  65. 0,
  66. FALSE,
  67. &RawDeviceDiskObject );
  68. if (!NT_SUCCESS( Status )) {
  69. return Status;
  70. }
  71. DriverObject->DriverUnload = RawUnload;
  72. //
  73. // Now create one for the CD ROM file system queue
  74. //
  75. RtlInitUnicodeString( &NameString, L"\\Device\\RawCdRom" );
  76. Status = IoCreateDevice( DriverObject,
  77. 0L,
  78. &NameString,
  79. FILE_DEVICE_CD_ROM_FILE_SYSTEM,
  80. 0,
  81. FALSE,
  82. &RawDeviceCdRomObject );
  83. if (!NT_SUCCESS( Status )) {
  84. IoDeleteDevice (RawDeviceDiskObject);
  85. return Status;
  86. }
  87. //
  88. // And now create one for the Tape file system queue
  89. //
  90. RtlInitUnicodeString( &NameString, L"\\Device\\RawTape" );
  91. Status = IoCreateDevice( DriverObject,
  92. 0L,
  93. &NameString,
  94. FILE_DEVICE_TAPE_FILE_SYSTEM,
  95. 0,
  96. FALSE,
  97. &RawDeviceTapeObject );
  98. if (!NT_SUCCESS( Status )) {
  99. IoDeleteDevice (RawDeviceCdRomObject);
  100. IoDeleteDevice (RawDeviceDiskObject);
  101. return Status;
  102. }
  103. //
  104. // Register a shutdown handler to enable us to unregister the file system objects
  105. //
  106. Status = IoRegisterShutdownNotification (RawDeviceTapeObject);
  107. if (!NT_SUCCESS( Status )) {
  108. IoDeleteDevice (RawDeviceTapeObject);
  109. IoDeleteDevice (RawDeviceCdRomObject);
  110. IoDeleteDevice (RawDeviceDiskObject);
  111. return Status;
  112. }
  113. //
  114. // Raw does direct IO
  115. //
  116. RawDeviceDiskObject->Flags |= DO_DIRECT_IO;
  117. RawDeviceCdRomObject->Flags |= DO_DIRECT_IO;
  118. RawDeviceTapeObject->Flags |= DO_DIRECT_IO;
  119. //
  120. // Initialize the driver object with this driver's entry points. Note
  121. // that only a limited capability is supported by the raw file system.
  122. //
  123. DriverObject->MajorFunction[IRP_MJ_CREATE] =
  124. DriverObject->MajorFunction[IRP_MJ_CLEANUP] =
  125. DriverObject->MajorFunction[IRP_MJ_CLOSE] =
  126. DriverObject->MajorFunction[IRP_MJ_READ] =
  127. DriverObject->MajorFunction[IRP_MJ_WRITE] =
  128. DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
  129. DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
  130. DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] =
  131. DriverObject->MajorFunction[IRP_MJ_CLEANUP] =
  132. DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
  133. DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
  134. DriverObject->MajorFunction[IRP_MJ_PNP] =
  135. (PDRIVER_DISPATCH)RawDispatch;
  136. DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = RawShutdown;
  137. //
  138. // Finally, register this file system in the system.
  139. //
  140. IoRegisterFileSystem( RawDeviceDiskObject );
  141. IoRegisterFileSystem( RawDeviceCdRomObject );
  142. IoRegisterFileSystem( RawDeviceTapeObject );
  143. ObReferenceObject (RawDeviceDiskObject);
  144. ObReferenceObject (RawDeviceCdRomObject);
  145. ObReferenceObject (RawDeviceTapeObject);
  146. //
  147. // And return to our caller
  148. //
  149. return( STATUS_SUCCESS );
  150. }
  151. NTSTATUS
  152. RawShutdown (
  153. IN PDEVICE_OBJECT DeviceObject,
  154. IN PIRP Irp
  155. )
  156. {
  157. UNREFERENCED_PARAMETER (DeviceObject);
  158. //
  159. // Unregister the file system objects so we can unload
  160. //
  161. IoUnregisterFileSystem (RawDeviceDiskObject);
  162. IoUnregisterFileSystem (RawDeviceCdRomObject);
  163. IoUnregisterFileSystem (RawDeviceTapeObject);
  164. IoDeleteDevice (RawDeviceTapeObject);
  165. IoDeleteDevice (RawDeviceCdRomObject);
  166. IoDeleteDevice (RawDeviceDiskObject);
  167. RawCompleteRequest( Irp, STATUS_SUCCESS );
  168. return STATUS_SUCCESS;
  169. }
  170. VOID
  171. RawUnload(
  172. IN PDRIVER_OBJECT DriverObject
  173. )
  174. /*++
  175. Routine Description:
  176. This is the unload routine for the Raw file system
  177. Arguments:
  178. DriverObject - Pointer to driver object created by the system.
  179. Return Value:
  180. None
  181. --*/
  182. {
  183. UNREFERENCED_PARAMETER (DriverObject);
  184. ObDereferenceObject (RawDeviceTapeObject);
  185. ObDereferenceObject (RawDeviceCdRomObject);
  186. ObDereferenceObject (RawDeviceDiskObject);
  187. }