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.

266 lines
6.8 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1996, Microsoft Corporation
  4. //
  5. // File: create.c
  6. //
  7. // Contents: Implements the Create code for the Dfs server. The Dfs server
  8. // only allows opening the File System Device object for the
  9. // express purpose of FsControlling to the Dfs server.
  10. //
  11. // Classes:
  12. //
  13. // Functions: DfsFsdCreate
  14. // DfsOpenDevice
  15. //
  16. //-----------------------------------------------------------------------------
  17. #include "dfsprocs.h"
  18. #include "attach.h"
  19. //
  20. // The debug trace level
  21. //
  22. #define Dbg (DEBUG_TRACE_CREATE)
  23. //
  24. // Local procedure prototypes
  25. //
  26. NTSTATUS
  27. DfsOpenDevice (
  28. IN PFILE_OBJECT FileObject,
  29. IN PDEVICE_OBJECT DeviceObject,
  30. IN ULONG CreateOptions);
  31. #ifdef ALLOC_PRAGMA
  32. #pragma alloc_text( PAGE, DfsFsdCreate )
  33. #pragma alloc_text( PAGE, DfsOpenDevice )
  34. #endif // ALLOC_PRAGMA
  35. //+-------------------------------------------------------------------
  36. //
  37. // Function: DfsFsdCreate, public
  38. //
  39. // Synopsis: This routine implements the FSD part of the NtCreateFile
  40. // and NtOpenFile API calls.
  41. //
  42. // Arguments: [DeviceObject] -- Supplies the device object relative to which
  43. // the open is to be processed.
  44. // [Irp] - Supplies the Irp being processed.
  45. //
  46. // Returns: NTSTATUS - The Fsd status for the Irp
  47. //
  48. //--------------------------------------------------------------------
  49. NTSTATUS
  50. DfsFsdCreate (
  51. IN PDEVICE_OBJECT DeviceObject,
  52. IN PIRP Irp
  53. )
  54. {
  55. NTSTATUS status;
  56. PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation(Irp);
  57. PFILE_OBJECT fileObject;
  58. ULONG createOptions;
  59. DebugTrace(+1, Dbg, "DfsFsdCreate: Entered\n", 0);
  60. ASSERT(IoIsOperationSynchronous(Irp) == TRUE);
  61. //
  62. // If someone is coming in via a device object attached to a file system
  63. // device object, pass it through.
  64. //
  65. if (DeviceObject->DeviceType == FILE_DEVICE_DISK_FILE_SYSTEM) {
  66. status = DfsVolumePassThrough(DeviceObject, Irp);
  67. DebugTrace(-1, Dbg, "DfsFsdCreate: FS Device Pass Through Exit %08lx\n", status);
  68. return status;
  69. }
  70. //
  71. // If someone is coming in via a device object attached to a file system
  72. // volume, we need to see if they are opening an exit point via its local
  73. // file system name.
  74. //
  75. if (DeviceObject->DeviceType == FILE_DEVICE_DFS_VOLUME) {
  76. status = DfsOpenFile(DeviceObject, Irp);
  77. DebugTrace(-1, Dbg, "DfsFsdCreate: Local File Open Exit %08lx\n', status);
  78. return status;
  79. }
  80. //
  81. // The only other create we handle is someone trying to open our own
  82. // file system device object.
  83. //
  84. ASSERT(DeviceObject->DeviceType == FILE_DEVICE_DFS_FILE_SYSTEM);
  85. FsRtlEnterFileSystem();
  86. fileObject = irpSp->FileObject;
  87. createOptions = irpSp->Parameters.Create.Options;
  88. if (fileObject->FileName.Length == 0 &&
  89. fileObject->RelatedFileObject == NULL) {
  90. //
  91. // This is the only case we handle
  92. //
  93. status = DfsOpenDevice(
  94. fileObject,
  95. DeviceObject,
  96. createOptions);
  97. } else {
  98. status = STATUS_INVALID_DEVICE_REQUEST;
  99. }
  100. FsRtlExitFileSystem();
  101. //
  102. // And return to our caller
  103. //
  104. DebugTrace(-1, Dbg, "DfsFsdCreate: Exit -> %08lx\n", status );
  105. DfsCompleteRequest( Irp, status );
  106. return status;
  107. }
  108. //+----------------------------------------------------------------------------
  109. //
  110. // Function: DfsOpenFile, local
  111. //
  112. // Synopsis: This routine handles file opens that come in via attached
  113. // volumes. The semantics of this open are:
  114. //
  115. // If the named file is a child of a DfsExitPath, fail it
  116. // with access denied.
  117. //
  118. // If the named file is a DfsExitPath, and CreateOptions specify
  119. // DELETE_ON_CLOSE, fail it with access denied.
  120. //
  121. // In all other cases, allocate an FCB, and pass the open through
  122. // to the underlying FS. If the open succeeds, then insert the
  123. // FCB in our FCB table. If the open fails, destroy the FCB.
  124. //
  125. // Arguments: [DeviceObject] -- The attached device object through which
  126. // the Create Irp came in.
  127. //
  128. // [Irp] -- The Create Irp.
  129. //
  130. // Returns: [STATUS_INSUFFICIENT_RESOURCES] -- Unable to allocate an FCB.
  131. //
  132. // [STATUS_ACCESS_DENIED] -- The file is a child of a Dfs exit
  133. // path or the file is a Dfs exit path and
  134. // DELETE_ON_CLOSE was specified.
  135. //
  136. // Status from the underlying FS.
  137. //
  138. //-----------------------------------------------------------------------------
  139. NTSTATUS
  140. DfsOpenFile(
  141. IN PDEVICE_OBJECT DeviceObject,
  142. IN PIRP Irp)
  143. {
  144. NTSTATUS status;
  145. PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation(Irp);
  146. PFILE_OBJECT fileObject = irpSp->FileObject;
  147. ULONG createOptions = irpSp->Parameters.Create.Options;
  148. DebugTrace(+1, Dbg, "DfsOpenFile - Entered\n", 0);
  149. if (fileObject->RelatedFileObject) {
  150. DebugTrace(0,
  151. }
  152. }
  153. //+-------------------------------------------------------------------
  154. //
  155. // Function: DfsOpenDevice, local
  156. //
  157. // Synopsis: This routine opens the specified device for direct
  158. // access.
  159. //
  160. // Arguments: [FileObject] - Supplies the File object
  161. // [DeviceObject] - Supplies the object denoting the device
  162. // being opened
  163. // [CreateOptions] - Supplies the create options for
  164. // this operation
  165. //
  166. // Returns: [IO_STATUS_BLOCK] - Returns the completion status for
  167. // the operation
  168. //
  169. //--------------------------------------------------------------------
  170. NTSTATUS
  171. DfsOpenDevice (
  172. IN PFILE_OBJECT FileObject,
  173. IN PDEVICE_OBJECT DeviceObject,
  174. IN ULONG CreateOptions
  175. ) {
  176. //
  177. // Check to see which type of device is being opened.
  178. // We don't permit all open modes on the file system
  179. // device object.
  180. //
  181. ULONG CreateDisposition = (CreateOptions >> 24) & 0x000000ff;
  182. //
  183. // Check for proper desired access and rights
  184. //
  185. if (CreateDisposition != FILE_OPEN
  186. && CreateDisposition != FILE_OPEN_IF ) {
  187. DebugTrace(0, Dbg,
  188. "DfsOpenDevice: Invalid CreateDisposition\n", 0);
  189. return( STATUS_ACCESS_DENIED );
  190. }
  191. //
  192. // Check if we were to open a directory
  193. //
  194. if (CreateOptions & FILE_DIRECTORY_FILE) {
  195. DebugTrace(0, Dbg,
  196. "DfsOpenDevice: Cannot open device as a directory\n", 0);
  197. return( STATUS_NOT_A_DIRECTORY );
  198. }
  199. FileObject->FsContext = (PVOID) DFS_OPEN_CONTEXT;
  200. return( STATUS_SUCCESS );
  201. }