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.

276 lines
6.1 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. FilObSup.c
  5. Abstract:
  6. This module implements the Named Pipe File object support routines.
  7. Author:
  8. Gary Kimura [GaryKi] 30-Aug-1990
  9. Revision History:
  10. --*/
  11. #include "NpProcs.h"
  12. //
  13. // The Bug check file id for this module
  14. //
  15. #define BugCheckFileId (NPFS_BUG_CHECK_FILOBSUP)
  16. //
  17. // The debug trace level
  18. //
  19. #define Dbg (DEBUG_TRACE_FILOBSUP)
  20. #ifdef ALLOC_PRAGMA
  21. #pragma alloc_text(PAGE, NpDecodeFileObject)
  22. #pragma alloc_text(PAGE, NpSetFileObject)
  23. #endif
  24. VOID
  25. NpSetFileObject (
  26. IN PFILE_OBJECT FileObject OPTIONAL,
  27. IN PVOID FsContext,
  28. IN PVOID FsContext2,
  29. IN NAMED_PIPE_END NamedPipeEnd
  30. )
  31. /*++
  32. Routine Description:
  33. This routine sets the file system pointers within the file object
  34. and handles the indicator for storing the named pipe end.
  35. Arguments:
  36. FileObject - Supplies a pointer to the file object being modified, and
  37. can optionally be null.
  38. FsContext - Supplies a pointer to either a ccb, vcb, or root_dcb
  39. structure.
  40. FsContext2 - Supplies a pointer to either a nonpaged ccb, root_dcb_ccb,
  41. or is null
  42. NamedPipeEnd - Supplies the indication if this is either the server end
  43. or client end file object. This is only applicable if the
  44. fscontext points to a ccb.
  45. Return Value:
  46. None.
  47. --*/
  48. {
  49. BOOLEAN GotCcb;
  50. PAGED_CODE();
  51. DebugTrace(+1, Dbg, "NpSetFileObject, FileObject = %08lx\n", FileObject );
  52. //
  53. // If no file object was given, do nothing.
  54. //
  55. if (ARGUMENT_PRESENT( FileObject )) {
  56. //
  57. // Check if we need to add in the named pipe end to the
  58. // fscontext pointer. We only need to 'OR' in a 1 if this is
  59. // the server end and fscontext points to a ccb. Also remember
  60. // now if this is a pointer is a ccb, so that we can later set
  61. // the fo_named_pipe flag
  62. //
  63. if ((FsContext != NULL) &&
  64. (*(PNODE_TYPE_CODE)FsContext == NPFS_NTC_CCB)) {
  65. GotCcb = TRUE;
  66. if (NamedPipeEnd == FILE_PIPE_SERVER_END) {
  67. FsContext = (PVOID)((ULONG_PTR)FsContext | 0x00000001);
  68. }
  69. } else {
  70. GotCcb = FALSE;
  71. }
  72. //
  73. // Now set the fscontext fields of the file object, and conditionally
  74. // set the named pipe flag in the file object if necessary.
  75. //
  76. FileObject->FsContext = FsContext;
  77. FileObject->FsContext2 = FsContext2;
  78. //
  79. // Set the private cache map to 1 and that what we will get our
  80. // fast I/O routines called
  81. //
  82. FileObject->PrivateCacheMap = (PVOID)1;
  83. if (GotCcb) {
  84. FileObject->Flags |= FO_NAMED_PIPE;
  85. }
  86. }
  87. //
  88. // And return to our caller
  89. //
  90. DebugTrace(-1, Dbg, "NpSetFileObject -> VOID\n", 0);
  91. return;
  92. }
  93. NODE_TYPE_CODE
  94. NpDecodeFileObject (
  95. IN PFILE_OBJECT FileObject,
  96. OUT PFCB *Fcb OPTIONAL,
  97. OUT PCCB *Ccb,
  98. OUT PNAMED_PIPE_END NamedPipeEnd OPTIONAL
  99. )
  100. /*++
  101. Routine Description:
  102. This procedure takes a pointer to a file object, that has already been
  103. opened by the named pipe file system and figures out what it really
  104. is opened.
  105. Arguments:
  106. FileObject - Supplies the file object pointer being interrogated
  107. Fcb - Receives a pointer to the Fcb for the file object, if we can
  108. find it.
  109. Ccb - Receives a pointer to the Ccb for the file object, if we can
  110. find it
  111. NamedPipeEnd - Receives a value indicating if this is a server
  112. or client end file object.
  113. Return Value:
  114. NODE_TYPE_CODE - Returns the node type code for a Vcb, RootDcb, Ccb,
  115. or zero.
  116. Vcb - indicates that file object opens the named pipe driver.
  117. Fcb and Ccb are NOT returned.
  118. RootDcb - indicates that the file object is for the root directory.
  119. Fcb (RootDcb), and Ccb (RootDcbCcb) are set.
  120. Ccb - indicates that the file object is for a named pipe instance.
  121. Ccb is set, while Fcb is optionally set.
  122. Zero - indicates that the file object was for a named pipe instance
  123. but became disconnected. Fcb, Ccb, and NamedPipeEnd are NOT
  124. returned.
  125. --*/
  126. {
  127. NODE_TYPE_CODE NodeTypeCode;
  128. PVOID FsContext;
  129. PAGED_CODE();
  130. DebugTrace(+1, Dbg, "NpDecodeFileObject, FileObject = %08lx\n", FileObject);
  131. //
  132. // Reference the fs context fields of the file object.
  133. //
  134. FsContext = FileObject->FsContext;
  135. //
  136. // If the fscontext field is null then we been disconnected.
  137. //
  138. if ((FsContext == NULL) || ((ULONG_PTR)FsContext == 1)) {
  139. NodeTypeCode = NTC_UNDEFINED;
  140. } else {
  141. //
  142. // We're actually pointing to something so first extract the
  143. // named pipe end information and then we can reference through
  144. // the fscontext pointer after we clean it up.
  145. //
  146. if (ARGUMENT_PRESENT(NamedPipeEnd)) {
  147. if (FlagOn((ULONG_PTR)FsContext, 0x00000001)) {
  148. *NamedPipeEnd = FILE_PIPE_SERVER_END;
  149. } else {
  150. *NamedPipeEnd = FILE_PIPE_CLIENT_END;
  151. }
  152. }
  153. FsContext = (PVOID)((ULONG_PTR)FsContext & ~0x00000001);
  154. //
  155. // Now we can case on the node type code of the fscontext pointer
  156. // and set the appropriate out pointers
  157. //
  158. NodeTypeCode = *(PNODE_TYPE_CODE)FsContext;
  159. switch (NodeTypeCode) {
  160. case NPFS_NTC_VCB:
  161. break;
  162. case NPFS_NTC_ROOT_DCB:
  163. *Ccb = FileObject->FsContext2;
  164. if (ARGUMENT_PRESENT(Fcb)) {
  165. *Fcb = FsContext;
  166. }
  167. break;
  168. case NPFS_NTC_CCB:
  169. *Ccb = FsContext;
  170. if (ARGUMENT_PRESENT(Fcb)) {
  171. *Fcb = ((PCCB)FsContext)->Fcb;
  172. }
  173. break;
  174. default:
  175. NpBugCheck( NodeTypeCode, 0, 0 );
  176. }
  177. }
  178. //
  179. // and return to our caller
  180. //
  181. DebugTrace(-1, Dbg, "NpDecodeFileObject -> %08lx\n", NodeTypeCode);
  182. return NodeTypeCode;
  183. }