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.

218 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. NpInit.c
  5. Abstract:
  6. This module implements the DRIVER_INITIALIZATION routine for the Named
  7. Pipe file system.
  8. Author:
  9. Gary Kimura [GaryKi] 21-Aug-1990
  10. Revision History:
  11. Neill Clift [NeillC] 22-Jan-2000
  12. Major rework, Don't raise exceptions, fix lots of error handling, Sort out cancel logic etc, fix validation.
  13. --*/
  14. #include "NpProcs.h"
  15. //#include <zwapi.h>
  16. VOID
  17. NpfsUnload(
  18. IN PDRIVER_OBJECT DriverObject
  19. );
  20. NTSTATUS
  21. DriverEntry(
  22. IN PDRIVER_OBJECT DriverObject,
  23. IN PUNICODE_STRING RegistryPath
  24. );
  25. PNPFS_DEVICE_OBJECT NpfsDeviceObject = NULL;
  26. #ifdef ALLOC_PRAGMA
  27. #pragma alloc_text(INIT,DriverEntry)
  28. #pragma alloc_text(PAGE,NpfsUnload)
  29. #endif
  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 Named Pipe file system
  38. device driver. This routine creates the device object for the named pipe
  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;
  48. UNICODE_STRING NameString;
  49. PDEVICE_OBJECT DeviceObject;
  50. PAGED_CODE();
  51. //
  52. // Create the alias lists.
  53. //
  54. Status = NpInitializeAliases( );
  55. if (!NT_SUCCESS( Status )) {
  56. return Status;
  57. }
  58. //
  59. // Create the device object.
  60. //
  61. RtlInitUnicodeString( &NameString, L"\\Device\\NamedPipe" );
  62. Status = IoCreateDevice( DriverObject,
  63. sizeof(NPFS_DEVICE_OBJECT)-sizeof(DEVICE_OBJECT),
  64. &NameString,
  65. FILE_DEVICE_NAMED_PIPE,
  66. 0,
  67. FALSE,
  68. &DeviceObject );
  69. if (!NT_SUCCESS( Status )) {
  70. NpUninitializeAliases( );
  71. return Status;
  72. }
  73. //
  74. // Set up the unload routine
  75. //
  76. DriverObject->DriverUnload = NpfsUnload;
  77. //
  78. // Note that because of the way data copying is done, we set neither
  79. // the Direct I/O or Buffered I/O bit in DeviceObject->Flags. If
  80. // data is not buffered we may set up for Direct I/O by hand. We do,
  81. // however, set the long term request flag so that IRPs that get
  82. // allocated for functions such as Listen requests come out of non-paged
  83. // pool always.
  84. //
  85. DeviceObject->Flags |= DO_LONG_TERM_REQUESTS;
  86. //
  87. // Initialize the driver object with this driver's entry points.
  88. //
  89. DriverObject->MajorFunction[IRP_MJ_CREATE] = (PDRIVER_DISPATCH)NpFsdCreate;
  90. DriverObject->MajorFunction[IRP_MJ_CREATE_NAMED_PIPE] = (PDRIVER_DISPATCH)NpFsdCreateNamedPipe;
  91. DriverObject->MajorFunction[IRP_MJ_CLOSE] = (PDRIVER_DISPATCH)NpFsdClose;
  92. DriverObject->MajorFunction[IRP_MJ_READ] = (PDRIVER_DISPATCH)NpFsdRead;
  93. DriverObject->MajorFunction[IRP_MJ_WRITE] = (PDRIVER_DISPATCH)NpFsdWrite;
  94. DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = (PDRIVER_DISPATCH)NpFsdQueryInformation;
  95. DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = (PDRIVER_DISPATCH)NpFsdSetInformation;
  96. DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = (PDRIVER_DISPATCH)NpFsdQueryVolumeInformation;
  97. DriverObject->MajorFunction[IRP_MJ_CLEANUP] = (PDRIVER_DISPATCH)NpFsdCleanup;
  98. DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = (PDRIVER_DISPATCH)NpFsdFlushBuffers;
  99. DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = (PDRIVER_DISPATCH)NpFsdDirectoryControl;
  100. DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = (PDRIVER_DISPATCH)NpFsdFileSystemControl;
  101. DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] = (PDRIVER_DISPATCH)NpFsdQuerySecurityInfo;
  102. DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] = (PDRIVER_DISPATCH)NpFsdSetSecurityInfo;
  103. #ifdef _PNP_POWER_
  104. //
  105. // Npfs doesn't need to handle SetPower requests. Local named pipes
  106. // won't lose any state. Remote pipes will be lost, by a network driver
  107. // will fail PowerQuery if there are open network connections.
  108. //
  109. DeviceObject->DeviceObjectExtension->PowerControlNeeded = FALSE;
  110. #endif
  111. DriverObject->FastIoDispatch = &NpFastIoDispatch;
  112. //
  113. // Now initialize the Vcb, and create the root dcb
  114. //
  115. NpfsDeviceObject = (PNPFS_DEVICE_OBJECT)DeviceObject;
  116. NpVcb = &NpfsDeviceObject->Vcb;
  117. NpInitializeVcb ();
  118. Status = NpCreateRootDcb ();
  119. if (!NT_SUCCESS (Status)) {
  120. LIST_ENTRY DeferredList;
  121. InitializeListHead (&DeferredList);
  122. NpDeleteVcb (&DeferredList);
  123. IoDeleteDevice (DeviceObject);
  124. NpUninitializeAliases ();
  125. NpCompleteDeferredIrps (&DeferredList);
  126. }
  127. //
  128. // And return to our caller
  129. //
  130. return Status;
  131. }
  132. VOID
  133. NpfsUnload(
  134. IN PDRIVER_OBJECT DriverObject
  135. )
  136. /*++
  137. Routine Description:
  138. This routine cleans up all of the memory associated with
  139. the driver.
  140. Arguments:
  141. DriverObject - Supplies the driver object controlling the device.
  142. Return Value:
  143. None.
  144. --*/
  145. {
  146. UNICODE_STRING us;
  147. LIST_ENTRY DeferredList;
  148. InitializeListHead (&DeferredList);
  149. NpDeleteVcb (&DeferredList);
  150. NpCompleteDeferredIrps (&DeferredList);
  151. RtlInitUnicodeString (&us, L"\\??\\PIPE"); // Created by SMSS
  152. IoDeleteSymbolicLink (&us);
  153. IoDeleteDevice (&NpfsDeviceObject->DeviceObject);
  154. NpUninitializeAliases ();
  155. }