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.

222 lines
6.6 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1992, Microsoft Corporation.
  4. //
  5. // File: ATTACH.C
  6. //
  7. // Contents: This module contains routines for managing attached file
  8. // systems.
  9. //
  10. // Functions:
  11. //
  12. // History: 15 May 1992 PeterCo Created.
  13. //
  14. //-----------------------------------------------------------------------------
  15. #include "dfsprocs.h"
  16. #include "mupwml.h"
  17. #define Dbg (DEBUG_TRACE_ATTACH)
  18. #ifdef ALLOC_PRAGMA
  19. //
  20. // The following are not pageable since they can be called at DPC level
  21. //
  22. // DfsVolumePassThrough
  23. // DfsFilePassThrough
  24. //
  25. #endif // ALLOC_PRAGMA
  26. //+-------------------------------------------------------------------
  27. //
  28. // Function: DfsVolumePassThrough, public
  29. //
  30. // Synopsis: This is the main FSD routine that passes a request
  31. // on to an attached-to device, or to a redirected
  32. // file.
  33. //
  34. // Arguments: [DeviceObject] -- Supplies a pointer to the Dfs device
  35. // object this request was aimed at.
  36. // [Irp] -- Supplies a pointer to the I/O request packet.
  37. //
  38. // Returns: [STATUS_INVALID_DEVICE_REQUEST] -- If the DeviceObject
  39. // argument is of unknown type, or the type of file
  40. // is invalid for the request being performed.
  41. //
  42. // NT Status from calling the underlying file system that
  43. // opened the file.
  44. //
  45. //--------------------------------------------------------------------
  46. NTSTATUS
  47. DfsVolumePassThrough(
  48. IN PDEVICE_OBJECT DeviceObject,
  49. IN PIRP Irp
  50. )
  51. {
  52. NTSTATUS Status = STATUS_SUCCESS;
  53. PIO_STACK_LOCATION IrpSp;
  54. PIO_STACK_LOCATION NextIrpSp;
  55. PFILE_OBJECT FileObject;
  56. DfsDbgTrace(+1, Dbg, "DfsVolumePassThrough: Entered\n", 0);
  57. IrpSp = IoGetCurrentIrpStackLocation(Irp);
  58. FileObject = IrpSp->FileObject;
  59. MUP_TRACE_HIGH(TRACE_IRP, DfsVolumePassThrough_Entry,
  60. LOGPTR(DeviceObject)
  61. LOGPTR(Irp)
  62. LOGPTR(FileObject));
  63. DfsDbgTrace(0, Dbg, "DeviceObject = %x\n", DeviceObject);
  64. DfsDbgTrace(0, Dbg, "Irp = %x\n", Irp );
  65. DfsDbgTrace(0, Dbg, " MajorFunction = %x\n", IrpSp->MajorFunction );
  66. DfsDbgTrace(0, Dbg, " MinorFunction = %x\n", IrpSp->MinorFunction );
  67. if (DeviceObject->DeviceType == FILE_DEVICE_DFS && IrpSp->FileObject != NULL) {
  68. TYPE_OF_OPEN TypeOfOpen;
  69. PDFS_VCB Vcb;
  70. PDFS_FCB Fcb;
  71. TypeOfOpen = DfsDecodeFileObject( IrpSp->FileObject, &Vcb, &Fcb);
  72. DfsDbgTrace(0, Dbg, "Fcb = %08lx\n", Fcb);
  73. if (TypeOfOpen == RedirectedFileOpen) {
  74. //
  75. // Copy the stack from one to the next...
  76. //
  77. NextIrpSp = IoGetNextIrpStackLocation(Irp);
  78. (*NextIrpSp) = (*IrpSp);
  79. IoSetCompletionRoutine(Irp, NULL, NULL, FALSE, FALSE, FALSE);
  80. //
  81. // ...and call the next device
  82. //
  83. Status = IoCallDriver( Fcb->TargetDevice, Irp );
  84. MUP_TRACE_ERROR_HIGH(Status, ALL_ERROR, DfsVolumePassThrough_Error_IoCallDriver,
  85. LOGSTATUS(Status)
  86. LOGPTR(Irp)
  87. LOGPTR(FileObject)
  88. LOGPTR(DeviceObject));
  89. } else {
  90. DfsDbgTrace(0, Dbg, "DfsVolumePassThrough: TypeOfOpen = %s\n",
  91. ((TypeOfOpen == UnopenedFileObject) ? "UnopenedFileObject":
  92. (TypeOfOpen == LogicalRootDeviceOpen) ?
  93. "LogicalRootDeviceOpen" : "???"));
  94. DfsDbgTrace(0, Dbg, "Irp = %x\n", Irp);
  95. DfsDbgTrace(0, Dbg, " MajorFunction = %x\n", IrpSp->MajorFunction);
  96. DfsDbgTrace(0, Dbg, " MinorFunction = %x\n", IrpSp->MinorFunction);
  97. Status = STATUS_INVALID_DEVICE_REQUEST;
  98. MUP_TRACE_HIGH(ERROR, DfsVolumePassThrough_Error1,
  99. LOGSTATUS(Status)
  100. LOGPTR(Irp)
  101. LOGPTR(FileObject)
  102. LOGPTR(DeviceObject));
  103. Irp->IoStatus.Status = Status;
  104. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  105. }
  106. } else {
  107. DfsDbgTrace(0, Dbg, "DfsVolumePassThrough: Unexpected Dev = %x\n",
  108. DeviceObject);
  109. Status = STATUS_INVALID_DEVICE_REQUEST;
  110. MUP_TRACE_HIGH(ERROR, DfsVolumePassThrough_Error2,
  111. LOGSTATUS(Status)
  112. LOGPTR(Irp)
  113. LOGPTR(FileObject)
  114. LOGPTR(DeviceObject));
  115. Irp->IoStatus.Status = Status;
  116. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  117. }
  118. DfsDbgTrace(-1, Dbg, "DfsVolumePassThrough: Exit -> %08lx\n", ULongToPtr(Status));
  119. MUP_TRACE_HIGH(TRACE_IRP, DfsVolumePassThrough_Exit,
  120. LOGSTATUS(Status)
  121. LOGPTR(Irp)
  122. LOGPTR(FileObject)
  123. LOGPTR(DeviceObject));
  124. return Status;
  125. }
  126. //+-------------------------------------------------------------------
  127. //
  128. // Function: DfsFilePassThrough, public
  129. //
  130. // Synopsis: Like DfsVolumePassThrough, but used when the file object
  131. // has already been looked up, and the FCB for the file is
  132. // already known. This is needed especially in close processing
  133. // to avoid a race between DfsLookupFcb (for a reused file object)
  134. // and DfsDetachFcb.
  135. //
  136. // Arguments: [pFcb] -- A pointer to an FCB for the file.
  137. // [Irp] -- A pointer to the I/O request packet.
  138. //
  139. // Returns: NTSTATUS - the return value from IoCallDriver.
  140. //
  141. //--------------------------------------------------------------------
  142. NTSTATUS
  143. DfsFilePassThrough(
  144. IN PDFS_FCB pFcb,
  145. IN PIRP Irp
  146. )
  147. {
  148. NTSTATUS Status = STATUS_SUCCESS;
  149. PIO_STACK_LOCATION IrpSp;
  150. PIO_STACK_LOCATION NextIrpSp;
  151. DfsDbgTrace(+1, Dbg, "DfsFilePassThrough: Entered\n", 0);
  152. IrpSp = IoGetCurrentIrpStackLocation(Irp);
  153. //
  154. // Copy the stack from one to the next...
  155. //
  156. NextIrpSp = IoGetNextIrpStackLocation(Irp);
  157. (*NextIrpSp) = (*IrpSp);
  158. IoSetCompletionRoutine(Irp, NULL, NULL, FALSE, FALSE, FALSE);
  159. //
  160. // ...and call the next device
  161. //
  162. Status = IoCallDriver( pFcb->TargetDevice, Irp );
  163. MUP_TRACE_ERROR_HIGH(Status, ALL_ERROR, DfsFilePassThrough_Error_IoCallDriver,
  164. LOGSTATUS(Status)
  165. LOGPTR(Irp));
  166. DfsDbgTrace(-1, Dbg, "DfsFilePassThrough: Exit -> %08lx\n", ULongToPtr(Status));
  167. return Status;
  168. }