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.

192 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. filobsup.c
  5. Abstract:
  6. This module implements the mailslot file object support routines.
  7. Author:
  8. Manny Weiser (mannyw) 10-Jan-1991
  9. Revision History:
  10. --*/
  11. #include "mailslot.h"
  12. //
  13. // The debug trace level
  14. //
  15. #define Dbg (DEBUG_TRACE_FILOBSUP)
  16. #ifdef ALLOC_PRAGMA
  17. #pragma alloc_text( PAGE, MsDecodeFileObject )
  18. #pragma alloc_text( PAGE, MsSetFileObject )
  19. #endif
  20. VOID
  21. MsSetFileObject (
  22. IN PFILE_OBJECT FileObject OPTIONAL,
  23. IN PVOID FsContext,
  24. IN PVOID FsContext2
  25. )
  26. /*++
  27. Routine Description:
  28. This routine sets the file system pointers within the file object.
  29. Arguments:
  30. FileObject - Supplies a pointer to the file object being modified, and
  31. can optionally be null.
  32. FsContext - Supplies a pointer to either a ccb, fcb, vcb, or root_dcb
  33. structure.
  34. FsContext2 - Supplies a pointer to a root_dcb_ccb, or is null.
  35. Return Value:
  36. None.
  37. --*/
  38. {
  39. NODE_TYPE_CODE nodeType;
  40. PAGED_CODE();
  41. DebugTrace(+1, Dbg, "MsSetFileObject, FileObject = %08lx\n", (ULONG)FileObject );
  42. //
  43. // Set the fscontext fields of the file object.
  44. //
  45. FileObject->FsContext = FsContext;
  46. FileObject->FsContext2 = FsContext2;
  47. //
  48. // Set the mailslot flag in the file object if necessary and return.
  49. //
  50. if (FsContext != NULL) {
  51. nodeType = NodeType(FsContext);
  52. if (nodeType == MSFS_NTC_CCB || nodeType == MSFS_NTC_FCB) {
  53. FileObject->Flags |= FO_MAILSLOT;
  54. }
  55. }
  56. DebugTrace(-1, Dbg, "MsSetFileObject -> VOID\n", 0);
  57. return;
  58. }
  59. NODE_TYPE_CODE
  60. MsDecodeFileObject (
  61. IN PFILE_OBJECT FileObject,
  62. OUT PVOID *FsContext,
  63. OUT PVOID *FsContext2
  64. )
  65. /*++
  66. Routine Description:
  67. This procedure takes a pointer to a file object, that has already been
  68. opened by the mailslot file system and figures out what it really
  69. is opened.
  70. Arguments:
  71. FileObject - Supplies the file object pointer being interrogated
  72. FsContext - Receive the file object FsContext pointer
  73. FsContext2 - Receive the file object FsContext2 pointer
  74. Return Value:
  75. NODE_TYPE_CODE - Returns the node type code for a Vcb, RootDcb, Ccb,
  76. or zero.
  77. Vcb - indicates that file object opens the mailslot driver.
  78. RootDcb - indicates that the file object is for the root directory.
  79. Ccb - indicates that the file object is for a mailslot file.
  80. Zero - indicates that the file object was for a mailslot file
  81. but has been closed.
  82. --*/
  83. {
  84. NODE_TYPE_CODE NodeTypeCode = NTC_UNDEFINED;
  85. PAGED_CODE();
  86. DebugTrace(+1, Dbg, "MsDecodeFileObject, FileObject = %08lx\n", (ULONG)FileObject);
  87. //
  88. // Read the fs FsContext fields of the file object, then reference
  89. // the block pointed at by the file object
  90. //
  91. *FsContext = FileObject->FsContext;
  92. *FsContext2 = FileObject->FsContext2;
  93. //
  94. // Acquire the global lock to protect the node reference counts.
  95. //
  96. MsAcquireGlobalLock();
  97. if ( ((PNODE_HEADER)(*FsContext))->NodeState != NodeStateActive ) {
  98. //
  99. // This node is shutting down. Indicate this to the caller.
  100. //
  101. NodeTypeCode = NTC_UNDEFINED;
  102. } else {
  103. //
  104. // The node is active. Supply a referenced pointer to the node.
  105. //
  106. NodeTypeCode = NodeType( *FsContext );
  107. MsReferenceNode( ((PNODE_HEADER)(*FsContext)) );
  108. }
  109. //
  110. // Release the global lock and return to the caller.
  111. //
  112. MsReleaseGlobalLock();
  113. DebugTrace(0,
  114. DEBUG_TRACE_REFCOUNT,
  115. "Referencing block %08lx\n",
  116. (ULONG)*FsContext);
  117. DebugTrace(0,
  118. DEBUG_TRACE_REFCOUNT,
  119. " Reference count = %lx\n",
  120. ((PNODE_HEADER)(*FsContext))->ReferenceCount );
  121. DebugTrace(-1, Dbg, "MsDecodeFileObject -> %08lx\n", NodeTypeCode);
  122. return NodeTypeCode;
  123. }