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.

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