Leaked source code of windows server 2003
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.

213 lines
5.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1992, Microsoft Corporation.
  4. //
  5. // File: FILOBSUP.C
  6. //
  7. // Contents: This module implements the Dfs File object support routines.
  8. //
  9. // Functions: DfsSetFileObject - associate internal data structs to file obj
  10. // DfsDecodeFileObject - get internal structures from file obj
  11. //
  12. // History: 12 Nov 1991 AlanW Created from CDFS souce.
  13. // 02 Mar 1993 AlanW Added association of DFS_FCBs with
  14. // file objects (without actually
  15. // modifying fscontext fields).
  16. //
  17. //--------------------------------------------------------------------------
  18. #include "dfsprocs.h"
  19. #include "fcbsup.h"
  20. //
  21. // The debug trace level
  22. //
  23. #define Dbg (DEBUG_TRACE_FILOBSUP)
  24. #ifdef ALLOC_PRAGMA
  25. #pragma alloc_text ( PAGE, DfsSetFileObject )
  26. #pragma alloc_text ( PAGE, DfsDecodeFileObject )
  27. #endif // ALLOC_PRAGMA
  28. //+-------------------------------------------------------------------
  29. //
  30. // Function: DfsSetFileObject, public
  31. //
  32. // Synopsis: This routine sets the file system pointers within the
  33. // file object
  34. //
  35. // Arguments: [FileObject] -- the file object being modified.
  36. // [TypeOfOpen] -- Supplies the type of open denoted by
  37. // the file object. This is only used by this
  38. // procedure for sanity checking.
  39. // [VcbOrFcb] -- Supplies a pointer to either a DFS_VCB or DFS_FCB.
  40. //
  41. // Returns: None.
  42. //
  43. //--------------------------------------------------------------------
  44. VOID
  45. DfsSetFileObject (
  46. IN PFILE_OBJECT FileObject,
  47. IN TYPE_OF_OPEN TypeOfOpen,
  48. IN PVOID VcbOrFcb
  49. ) {
  50. DfsDbgTrace(+1, Dbg, "DfsSetFileObject, FileObject = %08lx\n", FileObject);
  51. ASSERT( TypeOfOpen == RedirectedFileOpen
  52. && NodeType( VcbOrFcb ) == DSFS_NTC_FCB
  53. && ((PDFS_FCB) VcbOrFcb)->FileObject == FileObject
  54. ||
  55. (TypeOfOpen == UserVolumeOpen
  56. || TypeOfOpen == LogicalRootDeviceOpen)
  57. && NodeType( VcbOrFcb ) == DSFS_NTC_VCB
  58. ||
  59. TypeOfOpen == FilesystemDeviceOpen
  60. && NodeType( VcbOrFcb ) == IO_TYPE_DEVICE
  61. ||
  62. TypeOfOpen == UnopenedFileObject );
  63. //
  64. // Now set the fscontext fields of the file object
  65. //
  66. if ( ARGUMENT_PRESENT( FileObject )) {
  67. ASSERT( DfsLookupFcb(FileObject) == NULL );
  68. if (TypeOfOpen == RedirectedFileOpen) {
  69. DfsAttachFcb(FileObject, (PDFS_FCB) VcbOrFcb);
  70. } else {
  71. FileObject->FsContext = VcbOrFcb;
  72. FileObject->FsContext2 = NULL;
  73. }
  74. }
  75. //
  76. // And return to our caller
  77. //
  78. DfsDbgTrace(-1, Dbg, "DfsSetFileObject -> VOID\n", 0);
  79. return;
  80. }
  81. //+-------------------------------------------------------------------
  82. //
  83. // Function: DfsDecodeFileObject, public
  84. //
  85. // Synopsis: This procedure takes a pointer to a file object, that
  86. // has already been opened by the Dsfs file system and
  87. // figures out what really is opened.
  88. //
  89. // Arguments: [FileObject] -- Supplies the file object pointer being
  90. // interrogated
  91. // [ppVcb] -- Receives a pointer to the Vcb for the file object.
  92. // [ppFcb] -- Receives a pointer to the Fcb for the
  93. // file object, if one exists.
  94. //
  95. // Returns: [TYPE_OF_OPEN] - returns the type of file denoted by the
  96. // input file object.
  97. //
  98. // FilesystemDeviceOpen -
  99. //
  100. // LogicalRootDeviceOpen -
  101. //
  102. // RedirectedFileOpen - The FO represents a user's opened file or
  103. // directory which must be passed through to some other
  104. // FSD. Fcb, Vcb are set. Fcb points to an Fcb.
  105. //
  106. //--------------------------------------------------------------------
  107. TYPE_OF_OPEN
  108. DfsDecodeFileObject (
  109. IN PFILE_OBJECT FileObject,
  110. OUT PDFS_VCB *ppVcb,
  111. OUT PDFS_FCB *ppFcb
  112. ) {
  113. TYPE_OF_OPEN TypeOfOpen;
  114. PVOID FsContext = FileObject->FsContext;
  115. PDFS_FCB pFcb;
  116. DfsDbgTrace(+1, Dbg, "DfsDecodeFileObject, FileObject = %08lx\n",
  117. FileObject);
  118. //
  119. // Zero out the out pointer parameters.
  120. //
  121. *ppFcb = NULL;
  122. *ppVcb = NULL;
  123. //
  124. // Attempt to look up the associated DFS_FCB in the lookaside table.
  125. // If it's there, the open type must be RedirectedFileOpen.
  126. //
  127. pFcb = DfsLookupFcb(FileObject);
  128. if (pFcb != NULL) {
  129. *ppFcb = pFcb;
  130. *ppVcb = pFcb->Vcb;
  131. ASSERT(pFcb->TargetDevice != NULL);
  132. TypeOfOpen = RedirectedFileOpen;
  133. DfsDbgTrace(0, Dbg, "DfsDecodeFileObject, Fcb = %08x\n", pFcb);
  134. DfsDbgTrace(-1, Dbg, "DfsDecodeFileObject -> %x\n", TypeOfOpen);
  135. return TypeOfOpen;
  136. }
  137. //
  138. // Special case the situation where FsContext is null
  139. //
  140. if ( FsContext == NULL ) {
  141. TypeOfOpen = UnopenedFileObject;
  142. } else {
  143. //
  144. // Now we can case on the node type code of the fscontext pointer
  145. // and set the appropriate out pointers
  146. //
  147. switch ( NodeType( FsContext )) {
  148. case IO_TYPE_DEVICE:
  149. TypeOfOpen = FilesystemDeviceOpen;
  150. break;
  151. case DSFS_NTC_VCB:
  152. *ppVcb = (PDFS_VCB) FsContext;
  153. TypeOfOpen = LogicalRootDeviceOpen;
  154. break;
  155. default:
  156. TypeOfOpen = UnknownOpen;
  157. }
  158. }
  159. //
  160. // and return to our caller
  161. //
  162. DfsDbgTrace(-1, Dbg, "DfsDecodeFileObject -> %x\n", TypeOfOpen);
  163. return TypeOfOpen;
  164. }