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.

245 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1989-2000 Microsoft Corporation
  3. Module Name:
  4. FilObSup.c
  5. Abstract:
  6. This module implements the Udfs File object support routines.
  7. // @@BEGIN_DDKSPLIT
  8. Author:
  9. Dan Lovinger [DanLo] 23-Sep-1996
  10. Revision History:
  11. // @@END_DDKSPLIT
  12. --*/
  13. #include "UdfProcs.h"
  14. //
  15. // The Bug check file id for this module
  16. //
  17. #define BugCheckFileId (UDFS_BUG_CHECK_FILOBSUP)
  18. //
  19. // The local debug trace level
  20. //
  21. #define Dbg (UDFS_DEBUG_LEVEL_FILOBSUP)
  22. //
  23. // Local constants.
  24. //
  25. #define TYPE_OF_OPEN_MASK (0x00000007)
  26. #ifdef ALLOC_PRAGMA
  27. #pragma alloc_text(PAGE, UdfDecodeFileObject)
  28. #pragma alloc_text(PAGE, UdfFastDecodeFileObject)
  29. #pragma alloc_text(PAGE, UdfSetFileObject)
  30. #endif
  31. VOID
  32. UdfSetFileObject (
  33. IN PIRP_CONTEXT IrpContext,
  34. IN PFILE_OBJECT FileObject,
  35. IN TYPE_OF_OPEN TypeOfOpen,
  36. IN PFCB Fcb OPTIONAL,
  37. IN PCCB Ccb OPTIONAL
  38. )
  39. /*++
  40. Routine Description:
  41. This routine will initialize the FileObject context fields based on the
  42. input type and data structures.
  43. Arguments:
  44. FileObject - Supplies the file object pointer being initialized.
  45. TypeOfOpen - Sets the type of open.
  46. Fcb - Fcb for this file object. Ignored for UnopenedFileObject.
  47. Ccb - Ccb for the handle corresponding to this file object. Will not
  48. be present for stream file objects.
  49. Return Value:
  50. None.
  51. --*/
  52. {
  53. PAGED_CODE();
  54. //
  55. // We only have values 0 to 7 available so make sure we didn't
  56. // inadvertantly add a new type.
  57. //
  58. ASSERTMSG( "FileObject types exceed available bits\n", BeyondValidType <= 8 );
  59. //
  60. // Setting a file object to type UnopenedFileObject means just
  61. // clearing all of the context fields. All the other input
  62. //
  63. if (TypeOfOpen == UnopenedFileObject) {
  64. FileObject->FsContext =
  65. FileObject->FsContext2 = NULL;
  66. return;
  67. }
  68. //
  69. // Check that the 3 low-order bits of the Ccb are clear.
  70. //
  71. ASSERTMSG( "Ccb is not quad-aligned\n", !FlagOn( ((ULONG_PTR) Ccb), TYPE_OF_OPEN_MASK ));
  72. //
  73. // We will or the type of open into the low order bits of FsContext2
  74. // along with the Ccb value.
  75. // The Fcb is stored into the FsContext field.
  76. //
  77. FileObject->FsContext = Fcb;
  78. FileObject->FsContext2 = Ccb;
  79. SetFlag( ((ULONG_PTR) FileObject->FsContext2), TypeOfOpen );
  80. //
  81. // Set the Vpb field in the file object.
  82. //
  83. FileObject->Vpb = Fcb->Vcb->Vpb;
  84. return;
  85. }
  86. TYPE_OF_OPEN
  87. UdfDecodeFileObject (
  88. IN PFILE_OBJECT FileObject,
  89. OUT PFCB *Fcb,
  90. OUT PCCB *Ccb
  91. )
  92. /*++
  93. Routine Description:
  94. This routine takes a file object and extracts the Fcb and Ccb (possibly NULL)
  95. and returns the type of open.
  96. Arguments:
  97. FileObject - Supplies the file object pointer being initialized.
  98. Fcb - Address to store the Fcb contained in the file object.
  99. Ccb - Address to store the Ccb contained in the file object.
  100. Return Value:
  101. TYPE_OF_OPEN - Indicates the type of file object.
  102. --*/
  103. {
  104. TYPE_OF_OPEN TypeOfOpen;
  105. PAGED_CODE();
  106. //
  107. // If this is an unopened file object then return NULL for the
  108. // Fcb/Ccb. Don't trust any other values in the file object.
  109. //
  110. TypeOfOpen = (TYPE_OF_OPEN) FlagOn( (ULONG_PTR) FileObject->FsContext2,
  111. TYPE_OF_OPEN_MASK );
  112. if (TypeOfOpen == UnopenedFileObject) {
  113. *Fcb = NULL;
  114. *Ccb = NULL;
  115. } else {
  116. //
  117. // The Fcb is pointed to by the FsContext field. The Ccb is in
  118. // FsContext2 (after clearing the low three bits). The low three
  119. // bits are the file object type.
  120. //
  121. *Fcb = FileObject->FsContext;
  122. *Ccb = FileObject->FsContext2;
  123. ClearFlag( (ULONG_PTR) *Ccb, TYPE_OF_OPEN_MASK );
  124. }
  125. //
  126. // Now return the type of open.
  127. //
  128. return TypeOfOpen;
  129. }
  130. TYPE_OF_OPEN
  131. UdfFastDecodeFileObject (
  132. IN PFILE_OBJECT FileObject,
  133. OUT PFCB *Fcb
  134. )
  135. /*++
  136. Routine Description:
  137. This procedure takes a pointer to a file object, that has already been
  138. opened by Udfs and does a quick decode operation. It will only return
  139. a non null value if the file object is a user file open
  140. Arguments:
  141. FileObject - Supplies the file object pointer being interrogated
  142. Fcb - Address to store Fcb if this is a user file object. NULL
  143. otherwise.
  144. Return Value:
  145. TYPE_OF_OPEN - type of open of this file object.
  146. --*/
  147. {
  148. PAGED_CODE();
  149. ASSERT_FILE_OBJECT( FileObject );
  150. //
  151. // The Fcb is in the FsContext field. The type of open is in the low
  152. // bits of the Ccb.
  153. //
  154. *Fcb = FileObject->FsContext;
  155. return (TYPE_OF_OPEN) FlagOn( (ULONG_PTR) FileObject->FsContext2, TYPE_OF_OPEN_MASK );
  156. }