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.

229 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. FTMan
  5. File Name:
  6. PhPart.cpp
  7. Abstract:
  8. Implementation of the CPhysicalPartitionData class. The class that stores all information related
  9. to a physical partition
  10. Author:
  11. Cristian Teodorescu October 23, 1998
  12. Notes:
  13. Revision History:
  14. --*/
  15. #include "stdafx.h"
  16. #include "Global.h"
  17. #include "MainFrm.h"
  18. #include "PhPart.h"
  19. #include "Resource.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. ///////////////////////////////////////////////////////////////////////////////////////////////////
  26. // CPhysicalPartitionData
  27. // Constructor
  28. CPhysicalPartitionData::CPhysicalPartitionData(
  29. DWORD dwDiskNumber,
  30. DWORD dwSignature,
  31. const PPARTITION_INFORMATION pPartInfo,
  32. PARTITION_TYPE wPartitionType,
  33. CItemData* pParentData /* = NULL */,
  34. BOOL bIsRootVolume /* = FALSE */ )
  35. : CItemData( IT_PhysicalPartition, pParentData, bIsRootVolume ), m_dwDiskNumber(dwDiskNumber),
  36. m_dwSignature(dwSignature), m_wPartitionType( wPartitionType )
  37. {
  38. ASSERT( pPartInfo );
  39. memcpy(&m_PartInfo, pPartInfo, sizeof(PARTITION_INFORMATION) );
  40. }
  41. ////////////////////////////////////////////////////////////////////////////////////////////////////
  42. // Public methods
  43. BOOL CPhysicalPartitionData::ReadItemInfo( CString& strErrors )
  44. {
  45. MY_TRY
  46. m_bValid = TRUE;
  47. strErrors = _T("");
  48. m_ulNumMembers = 0;
  49. // Read the drive letter, volume name and mount paths ( if any )
  50. if( !ReadDriveLetterAndVolumeName() )
  51. {
  52. //AddError( strErrors, IDS_ERR_READ_DRIVE_LETTER_AND_VOLUME_NAME, FALSE );
  53. m_bValid = FALSE;
  54. }
  55. // The mount paths will be retrieved later together with all other siblings mount paths ( for performance reason )
  56. m_arrMountPaths.RemoveAll();
  57. // Retrieve all disks used by this volume
  58. if( !RetrieveDisksSet() )
  59. {
  60. AddError( strErrors, IDS_ERR_RETRIEVE_DISKS_SET, FALSE );
  61. m_bValid = FALSE;
  62. }
  63. m_bIoOK = TRUE;
  64. m_iImage = ComputeImageIndex();
  65. return m_bValid;
  66. MY_CATCH_AND_THROW
  67. }
  68. BOOL CPhysicalPartitionData::ReadMembers( CObArray& arrMembersData, CString& strErrors )
  69. {
  70. MY_TRY
  71. arrMembersData.RemoveAll();
  72. strErrors = _T("");
  73. m_ulNumMembers = 0;
  74. return TRUE;
  75. MY_CATCH_AND_THROW
  76. }
  77. int CPhysicalPartitionData::ComputeImageIndex() const
  78. {
  79. if( m_bValid && m_bIoOK )
  80. return II_PhysicalPartition;
  81. else
  82. return II_PhysicalPartition_Error;
  83. }
  84. BOOL CPhysicalPartitionData::operator==(CItemData& rData) const
  85. {
  86. if( rData.GetItemType() != IT_PhysicalPartition )
  87. return FALSE;
  88. CPhysicalPartitionData* pPhPartData = (CPhysicalPartitionData*)(&rData);
  89. return( ( m_dwDiskNumber == pPhPartData->m_dwDiskNumber ) &&
  90. ( m_PartInfo.StartingOffset.QuadPart == pPhPartData->m_PartInfo.StartingOffset.QuadPart ) &&
  91. ( m_PartInfo.PartitionLength.QuadPart == pPhPartData->m_PartInfo.PartitionLength.QuadPart ) );
  92. }
  93. void CPhysicalPartitionData::GetDisplayName( CString& strDisplay ) const
  94. {
  95. MY_TRY
  96. strDisplay = _T("");
  97. for( int i = 0; i < m_arrMountPaths.GetSize(); i++ )
  98. {
  99. if( i != 0 )
  100. strDisplay += _T("; ");
  101. strDisplay += m_arrMountPaths[i];
  102. }
  103. if( strDisplay.IsEmpty() )
  104. {
  105. if( m_cDriveLetter )
  106. strDisplay.Format(_T("%c:"), m_cDriveLetter );
  107. /*
  108. else
  109. strDisplay.Format( IDS_STR_PHYSICAL_PARTITION_NAME,
  110. m_dwDiskNumber, m_PartInfo.PartitionNumber );
  111. */
  112. }
  113. CString str;
  114. str.Format( IDS_STR_PHYSICAL_PARTITION_NAME,
  115. m_dwDiskNumber, m_PartInfo.PartitionNumber );
  116. if( !strDisplay.IsEmpty() )
  117. strDisplay += (" ");
  118. strDisplay += str;
  119. MY_CATCH_AND_THROW
  120. }
  121. void CPhysicalPartitionData::GetDisplayType( CString& strDisplay ) const
  122. {
  123. MY_TRY
  124. switch( m_wPartitionType )
  125. {
  126. case PT_Primary:
  127. strDisplay.LoadString( IDS_TYPE_PRIMARY_PARTITION);
  128. break;
  129. case PT_InExtendedPartition:
  130. strDisplay.LoadString( IDS_TYPE_PARTITION_IN_EXTENDED_PARTITION);
  131. break;
  132. default:
  133. ASSERT(FALSE);
  134. }
  135. MY_CATCH_AND_THROW
  136. }
  137. BOOL CPhysicalPartitionData::GetSize( LONGLONG& llSize ) const
  138. {
  139. llSize = m_PartInfo.PartitionLength.QuadPart;
  140. return TRUE;
  141. }
  142. BOOL CPhysicalPartitionData::GetDiskNumber( ULONG& ulDiskNumber ) const
  143. {
  144. ulDiskNumber = m_dwDiskNumber;
  145. return TRUE;
  146. }
  147. BOOL CPhysicalPartitionData::GetOffset( LONGLONG& llOffset) const
  148. {
  149. llOffset = m_PartInfo.StartingOffset.QuadPart;
  150. return TRUE;
  151. }
  152. BOOL CPhysicalPartitionData::IsFTPartition() const
  153. {
  154. // FT partitions have the most significant bit of PartitionType equal with 1
  155. return ( ( m_PartInfo.PartitionType & 0x80 ) != 0 );
  156. }
  157. ////////////////////////////////////////////////////////////////////////////////////////////////////
  158. // Protected methods
  159. BOOL CPhysicalPartitionData::RetrieveNTName( CString& strNTName ) const
  160. {
  161. MY_TRY
  162. strNTName.Format(_T("\\Device\\Harddisk%lu\\Partition%lu"), m_dwDiskNumber, m_PartInfo.PartitionNumber );
  163. return TRUE;
  164. MY_CATCH_AND_THROW
  165. }
  166. BOOL CPhysicalPartitionData::RetrieveDisksSet()
  167. {
  168. MY_TRY
  169. m_setDisks.RemoveAll();
  170. m_setDisks.Add( m_dwDiskNumber );
  171. return TRUE;
  172. MY_CATCH_AND_THROW
  173. }