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.

219 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. bitfrs.cxx
  5. Abstract:
  6. This module contains the member function definitions for
  7. the NTFS_BITMAP_FILE class.
  8. Author:
  9. Bill McJohn (billmc) 18-June-91
  10. Environment:
  11. ULIB, User Mode
  12. --*/
  13. #include <pch.cxx>
  14. #define _NTAPI_ULIB_
  15. #define _UNTFS_MEMBER_
  16. #include "ulib.hxx"
  17. #include "error.hxx"
  18. #include "untfs.hxx"
  19. #include "ntfsbit.hxx"
  20. #include "drive.hxx"
  21. #include "attrib.hxx"
  22. #include "bitfrs.hxx"
  23. DEFINE_EXPORTED_CONSTRUCTOR( NTFS_BITMAP_FILE, NTFS_FILE_RECORD_SEGMENT, UNTFS_EXPORT );
  24. UNTFS_EXPORT
  25. NTFS_BITMAP_FILE::~NTFS_BITMAP_FILE(
  26. )
  27. {
  28. Destroy();
  29. }
  30. VOID
  31. NTFS_BITMAP_FILE::Construct(
  32. )
  33. /*++
  34. Routine Description:
  35. Worker function for the construtor.
  36. Arguments:
  37. None.
  38. Return Value:
  39. None.
  40. --*/
  41. {
  42. }
  43. VOID
  44. NTFS_BITMAP_FILE::Destroy(
  45. )
  46. /*++
  47. Routine Description:
  48. Clean up an NTFS_BITMAP_FILE object in preparation for
  49. destruction or reinitialization.
  50. Arguments:
  51. None.
  52. Return Value:
  53. None.
  54. --*/
  55. {
  56. }
  57. UNTFS_EXPORT
  58. BOOLEAN
  59. NTFS_BITMAP_FILE::Initialize(
  60. IN OUT PNTFS_MASTER_FILE_TABLE Mft
  61. )
  62. /*++
  63. Routine Description:
  64. This method initializes a Bitmap File object.
  65. The only special knowledge that it adds to the File Record Segment
  66. initialization is the location within the Master File Table of the
  67. Bitmap File.
  68. Arguments:
  69. Mft -- Supplies the volume MasterFile Table.
  70. Return Value:
  71. TRUE upon successful completion
  72. Notes:
  73. This class is reinitializable.
  74. --*/
  75. {
  76. Destroy();
  77. return( NTFS_FILE_RECORD_SEGMENT::Initialize( BIT_MAP_FILE_NUMBER,
  78. Mft ) );
  79. }
  80. BOOLEAN
  81. NTFS_BITMAP_FILE::Create(
  82. IN PCSTANDARD_INFORMATION StandardInformation,
  83. IN OUT PNTFS_BITMAP VolumeBitmap
  84. )
  85. /*++
  86. Routine Description:
  87. This method formats a Bitmap-File File Record
  88. Segment in memory (without writing it to disk).
  89. It creates a DATA attribute to hold the volume bitmap, and
  90. allocates space on disk for the bitmap. Note that it does
  91. not write the bitmap.
  92. Arguments:
  93. StandardInformation -- supplies the standard information for the
  94. file record segment.
  95. VolumeBitmap -- supplies the volume bitmap
  96. Return Value:
  97. TRUE upon successful completion.
  98. --*/
  99. {
  100. NTFS_ATTRIBUTE DataAttribute;
  101. NTFS_EXTENT_LIST Extents;
  102. LCN BitmapLcn;
  103. BIG_INT NumberOfClusters;
  104. ULONG Size;
  105. ULONG ClusterSize;
  106. ULONG ClustersToHoldBitmap;
  107. // Set this object up as a File Record Segment.
  108. if( !NTFS_FILE_RECORD_SEGMENT::Create( StandardInformation ) ) {
  109. return FALSE;
  110. }
  111. // Determine the number of clusters necessary to hold the bitmap.
  112. NumberOfClusters = VolumeBitmap->QuerySize();
  113. if( NumberOfClusters.GetHighPart() != 0 ) {
  114. DebugAbort( "Bitmap is too big.\n" );
  115. return FALSE;
  116. }
  117. Size = NumberOfClusters.GetLowPart()/8;
  118. ClusterSize = GetDrive()->QuerySectorSize() * QueryClusterFactor();
  119. if( NumberOfClusters.GetLowPart() % (ULONG)8 ) {
  120. Size += 1;
  121. }
  122. Size = QuadAlign(Size);
  123. ClustersToHoldBitmap = Size/ClusterSize;
  124. if( Size % ClusterSize ) {
  125. ClustersToHoldBitmap++;
  126. }
  127. // Create a zero-length non-resident attribute, and
  128. // then resize it to the correct size to hold the bitmap.
  129. //
  130. if( !Extents.Initialize( 0, 0 ) ||
  131. !Extents.Resize( ClustersToHoldBitmap, VolumeBitmap ) ||
  132. !DataAttribute.Initialize( GetDrive(),
  133. QueryClusterFactor(),
  134. &Extents,
  135. Size,
  136. Size,
  137. $DATA ) ||
  138. !DataAttribute.InsertIntoFile( this, VolumeBitmap ) ) {
  139. return FALSE;
  140. }
  141. return TRUE;
  142. }