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
5.9 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. msinit.c
  5. Abstract:
  6. This module implements the DRIVER_INITIALIZATION routine for the
  7. mailslot file system.
  8. Author:
  9. Manny Weiser (mannyw) 7-Jan-91
  10. Revision History:
  11. Neill Clift (NeillC) 22-Jan-2000
  12. Major rework, Do raise exceptions, fix locking, fix cancel logic, fix validation and error handling.
  13. --*/
  14. #include "mailslot.h"
  15. #include "zwapi.h"
  16. NTSTATUS
  17. DriverEntry(
  18. IN PDRIVER_OBJECT DriverObject,
  19. IN PUNICODE_STRING RegistryPath
  20. );
  21. VOID
  22. MsfsUnload(
  23. IN PDRIVER_OBJECT DriverObject
  24. );
  25. #ifdef ALLOC_PRAGMA
  26. #pragma alloc_text( INIT, DriverEntry )
  27. #pragma alloc_text( PAGE, MsfsUnload )
  28. #endif
  29. PMSFS_DEVICE_OBJECT msfsDeviceObject = NULL;
  30. NTSTATUS
  31. DriverEntry(
  32. IN PDRIVER_OBJECT DriverObject,
  33. IN PUNICODE_STRING RegistryPath
  34. )
  35. /*++
  36. Routine Description:
  37. This is the initialization routine for the mailslot file system
  38. device driver. This routine creates the device object for the mailslot
  39. device and performs all other driver initialization.
  40. Arguments:
  41. DriverObject - Pointer to driver object created by the system.
  42. Return Value:
  43. NTSTATUS - The function value is the final status from the initialization
  44. operation.
  45. --*/
  46. {
  47. NTSTATUS status = STATUS_SUCCESS;
  48. UNICODE_STRING nameString;
  49. PDEVICE_OBJECT deviceObject;
  50. PAGED_CODE();
  51. //
  52. // Initialize MSFS global data.
  53. //
  54. status = MsInitializeData();
  55. if (!NT_SUCCESS (status)) {
  56. return status;
  57. }
  58. //
  59. // Set driver to be completely paged out.
  60. //
  61. MmPageEntireDriver(DriverEntry);
  62. //
  63. // Create the MSFS device object.
  64. //
  65. RtlInitUnicodeString( &nameString, L"\\Device\\Mailslot" );
  66. status = IoCreateDevice( DriverObject,
  67. sizeof(MSFS_DEVICE_OBJECT)-sizeof(DEVICE_OBJECT),
  68. &nameString,
  69. FILE_DEVICE_MAILSLOT,
  70. 0,
  71. FALSE,
  72. &deviceObject );
  73. if (!NT_SUCCESS( status )) {
  74. MsUninitializeData();
  75. return status;
  76. }
  77. DriverObject->DriverUnload = MsfsUnload;
  78. //
  79. // Now because we use the irp stack for storing a data entry we need
  80. // to bump up the stack size in the device object we just created.
  81. //
  82. deviceObject->StackSize += 1;
  83. //
  84. // Note that because of the way data copying is done, we set neither
  85. // the Direct I/O or Buffered I/O bit in DeviceObject->Flags. If
  86. // data is not buffered we may set up for Direct I/O by hand.
  87. //
  88. //
  89. // Initialize the driver object with this driver's entry points.
  90. //
  91. DriverObject->MajorFunction[IRP_MJ_CREATE] =
  92. (PDRIVER_DISPATCH)MsFsdCreate;
  93. DriverObject->MajorFunction[IRP_MJ_CREATE_MAILSLOT] =
  94. (PDRIVER_DISPATCH)MsFsdCreateMailslot;
  95. DriverObject->MajorFunction[IRP_MJ_CLOSE] =
  96. (PDRIVER_DISPATCH)MsFsdClose;
  97. DriverObject->MajorFunction[IRP_MJ_READ] =
  98. (PDRIVER_DISPATCH)MsFsdRead;
  99. DriverObject->MajorFunction[IRP_MJ_WRITE] =
  100. (PDRIVER_DISPATCH)MsFsdWrite;
  101. DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
  102. (PDRIVER_DISPATCH)MsFsdQueryInformation;
  103. DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
  104. (PDRIVER_DISPATCH)MsFsdSetInformation;
  105. DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] =
  106. (PDRIVER_DISPATCH)MsFsdQueryVolumeInformation;
  107. DriverObject->MajorFunction[IRP_MJ_CLEANUP] =
  108. (PDRIVER_DISPATCH)MsFsdCleanup;
  109. DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] =
  110. (PDRIVER_DISPATCH)MsFsdDirectoryControl;
  111. DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
  112. (PDRIVER_DISPATCH)MsFsdFsControl;
  113. DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] =
  114. (PDRIVER_DISPATCH)MsFsdQuerySecurityInfo;
  115. DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] =
  116. (PDRIVER_DISPATCH)MsFsdSetSecurityInfo;
  117. #ifdef _PNP_POWER_
  118. //
  119. // Mailslots should probably have a SetPower handler to ensure
  120. // that the driver is not powered down while a guarateed
  121. // mailslot delivery is in progress. For now, we'll just
  122. // ignore this and let the machine set power.
  123. //
  124. deviceObject->DeviceObjectExtension->PowerControlNeeded = FALSE;
  125. #endif
  126. //
  127. // Initialize stuff
  128. //
  129. msfsDeviceObject = (PMSFS_DEVICE_OBJECT)deviceObject;
  130. //
  131. // Now initialize the Vcb, and create the root dcb
  132. //
  133. MsInitializeVcb( &msfsDeviceObject->Vcb );
  134. //
  135. // Createt the root DCB
  136. //
  137. if (MsCreateRootDcb( &msfsDeviceObject->Vcb ) == NULL) {
  138. MsDereferenceVcb (&msfsDeviceObject->Vcb);
  139. IoDeleteDevice (&msfsDeviceObject->DeviceObject);
  140. MsUninitializeData();
  141. return STATUS_INSUFFICIENT_RESOURCES;
  142. }
  143. //
  144. // Return to the caller.
  145. //
  146. return( status );
  147. }
  148. VOID
  149. MsfsUnload(
  150. IN PDRIVER_OBJECT DriverObject
  151. )
  152. /*++
  153. Routine Description:
  154. This routine cleans up all of the memory associated with
  155. the driver.
  156. Arguments:
  157. DriverObject - Supplies the driver object controlling the device.
  158. Return Value:
  159. None.
  160. --*/
  161. {
  162. UNICODE_STRING us;
  163. //
  164. // Remove the initial reference to the VCB. This should be the last.
  165. //
  166. ASSERT ( msfsDeviceObject->Vcb.Header.ReferenceCount == 1 );
  167. MsDereferenceVcb (&msfsDeviceObject->Vcb);
  168. RtlInitUnicodeString (&us, L"\\??\\MAILSLOT"); // Created by SMSS
  169. IoDeleteSymbolicLink (&us);
  170. //
  171. // Delete the device object
  172. //
  173. IoDeleteDevice (&msfsDeviceObject->DeviceObject);
  174. //
  175. // Release the globals
  176. //
  177. MsUninitializeData();
  178. }