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.

182 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. filobsup.c
  5. Abstract:
  6. This module implements the mup file object support routines.
  7. Author:
  8. Manny Weiser (mannyw) 20-Dec-1991
  9. Revision History:
  10. --*/
  11. #include "mup.h"
  12. //
  13. // The debug trace level
  14. //
  15. #define Dbg (DEBUG_TRACE_FILOBSUP)
  16. #ifdef ALLOC_PRAGMA
  17. #pragma alloc_text( PAGE, MupDecodeFileObject )
  18. #pragma alloc_text( PAGE, MupSetFileObject )
  19. #endif
  20. VOID
  21. MupSetFileObject (
  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. This routine MUST be called with the Global Lock held.
  30. Arguments:
  31. FileObject - Supplies a pointer to the file object being modified, and
  32. can optionally be null.
  33. FsContext - Supplies a pointer to the vcb.
  34. structure.
  35. FsContext2 - NULL
  36. Return Value:
  37. None.
  38. --*/
  39. {
  40. PAGED_CODE();
  41. DebugTrace(+1, Dbg, "MupSetFileObject, 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. DebugTrace(-1, Dbg, "MupSetFileObject -> VOID\n", 0);
  48. return;
  49. }
  50. BLOCK_TYPE
  51. MupDecodeFileObject (
  52. IN PFILE_OBJECT FileObject,
  53. OUT PVOID *FsContext,
  54. OUT PVOID *FsContext2
  55. )
  56. /*++
  57. Routine Description:
  58. This procedure takes a pointer to a file object, that has already been
  59. opened by the MUP and figures out what it really is opened.
  60. Arguments:
  61. FileObject - Supplies the file object pointer being interrogated
  62. FsContext - Receive the file object FsContext pointer
  63. FsContext2 - Receive the file object FsContext2 pointer
  64. Return Value:
  65. BlockType - Returns the node type code for a Vcb or Fcb.
  66. Vcb - indicates that file object opens the mup driver.
  67. Ccb - indicates that the file object is for a broadcast mailslot file.
  68. Zero - indicates that the file object has been closed.
  69. --*/
  70. {
  71. BLOCK_TYPE blockType;
  72. PBLOCK_HEADER pBlockHead;
  73. PAGED_CODE();
  74. DebugTrace(+1, Dbg, "MupDecodeFileObject, FileObject = %08lx\n", (ULONG)FileObject);
  75. //
  76. // Acquire the global lock to protect the block reference counts.
  77. //
  78. MupAcquireGlobalLock();
  79. //
  80. // Read the fs FsContext fields of the file object, then reference
  81. // the block pointed at by the file object
  82. //
  83. *FsContext = FileObject->FsContext;
  84. *FsContext2 = FileObject->FsContext2;
  85. ASSERT( (*FsContext) != NULL );
  86. if ((*FsContext) == NULL) {
  87. blockType = BlockTypeUndefined;
  88. }
  89. else {
  90. pBlockHead = (PBLOCK_HEADER)(*FsContext);
  91. if ( ((pBlockHead->BlockType != BlockTypeVcb) &&
  92. (pBlockHead->BlockType != BlockTypeFcb)) ||
  93. ((pBlockHead->BlockState != BlockStateActive) &&
  94. (pBlockHead->BlockState != BlockStateClosing)) ) {
  95. *FsContext = NULL;
  96. blockType = BlockTypeUndefined;
  97. } else {
  98. //
  99. // The node is active. Supply a referenced pointer to the node.
  100. //
  101. blockType = BlockType( pBlockHead );
  102. MupReferenceBlock( pBlockHead );
  103. }
  104. }
  105. //
  106. // Release the global lock and return to the caller.
  107. //
  108. MupReleaseGlobalLock();
  109. DebugTrace(0,
  110. DEBUG_TRACE_REFCOUNT,
  111. "Referencing block %08lx\n",
  112. (ULONG)*FsContext);
  113. DebugTrace(0,
  114. DEBUG_TRACE_REFCOUNT,
  115. " Reference count = %lx\n",
  116. ((PBLOCK_HEADER)(*FsContext))->ReferenceCount );
  117. DebugTrace(-1, Dbg, "MupDecodeFileObject -> %08lx\n", blockType);
  118. return blockType;
  119. }