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.

253 lines
7.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998 - 1999.
  5. //
  6. // File: CatCnfg.hxx
  7. //
  8. // Contents: Support for adding catalogs during setup.
  9. //
  10. // Classes: CDriveInformation
  11. // CCatalogConfig
  12. // CCatReg
  13. //
  14. // History: 13-May-1998 KyleP Added copyright
  15. //
  16. //--------------------------------------------------------------------------
  17. #pragma hdrstop
  18. //#include <smart.hxx>
  19. #define MAX_DRIVES 27
  20. #define CHARS_PER_DRIVE 4
  21. const ULONGLONG ONE_MB = (1024*1024);
  22. // Amount to add to min. page file size if max is not specified
  23. const ULONG MAXOVERMINFACTOR = 50;
  24. // Minimum catalog size (most is propstore backup)
  25. const ULONGLONG MIN_CATALOG_SPACE = 9 * ONE_MB;
  26. // Minimum space to reserve for over-the-net upgrade
  27. const ULONGLONG MIN_UPGRADE_SPACE = 300 * ONE_MB;
  28. // Estimated size of the catalog as a proportion of used space on the disk
  29. const double CATALOG_SIZE_RATIO_NTFS = 0.10;
  30. const double CATALOG_SIZE_RATIO_FAT = 0.20;
  31. //
  32. // forward declarations
  33. //
  34. class CError;
  35. //
  36. // externals
  37. //
  38. extern const WCHAR wcsRegCatalogsSubKey[];
  39. //+-------------------------------------------------------------------------
  40. //
  41. // Class: CDriveInformation
  42. //
  43. // Purpose: Collects and provides information about a drive.
  44. //
  45. //--------------------------------------------------------------------------
  46. class CDriveInformation
  47. {
  48. public:
  49. void SetDriveName(WCHAR const * wszDriveName) {
  50. Win4Assert( wcslen(wszDriveName) == CHARS_PER_DRIVE - 1 );
  51. memcpy( _wszDriveName, wszDriveName, CHARS_PER_DRIVE*sizeof (WCHAR) );
  52. }
  53. BOOL SetDriveInfo();
  54. BOOL Exists(WCHAR * pwszPath);
  55. WCHAR const * GetDriveName() const { return _wszDriveName; }
  56. WCHAR GetDriveLetter() const { return _wszDriveName[0]; }
  57. //
  58. // These disk space numbers are kept:
  59. // _cbTotalSpace - Total space on disk
  60. // _cbFreeSpace - Actual free bytes on disk
  61. // _cbReservedSpace - Space currently reserved for system files
  62. //
  63. // In addition, the currently available and currently used space can be
  64. // computed.
  65. ULONGLONG GetActualFreeSpace() const { return _cbFreeSpace; }
  66. ULONGLONG GetTotalSpace() const { return _cbTotalSpace; }
  67. ULONGLONG GetReservedSpace() const { return _cbReservedSpace; }
  68. ULONGLONG GetAvailableSpace() const
  69. {
  70. return _cbReservedSpace > _cbFreeSpace ?
  71. 0 :
  72. _cbFreeSpace - _cbReservedSpace;
  73. }
  74. ULONGLONG GetUsedSpace() const
  75. {
  76. return (GetAvailableSpace()) > _cbTotalSpace ?
  77. 0 :
  78. _cbTotalSpace - (GetAvailableSpace());
  79. }
  80. BOOL IsNtfs() const
  81. { return (_dwFileSystemFlags & FS_PERSISTENT_ACLS) != 0; }
  82. BOOL SupportsCompression() const
  83. { return (_dwFileSystemFlags & FS_FILE_COMPRESSION) != 0; }
  84. BOOL IsSystemDrive() const
  85. { return GetDriveLetter() == g_awcSystemDir[0]; }
  86. BOOL IsBootDrive() const { return _fIsBootDrive; }
  87. BOOL HasPageFile() const { return _fHasPageFile; }
  88. BOOL IsSmallBootPartition() const
  89. {
  90. return IsBootDrive() &&
  91. ! IsNtfs() &&
  92. GetTotalSpace() <= 20 * ONE_MB;
  93. }
  94. void ReservePagingData(ULONGLONG maxPageSize, ULONGLONG cbCurrentSize)
  95. {
  96. // consider the page file as free space, but reserve it.
  97. _fHasPageFile = TRUE;
  98. _cbPagingSpace = maxPageSize;
  99. _cbFreeSpace += cbCurrentSize;
  100. AddReservedSpace( maxPageSize );
  101. }
  102. void AddReservedSpace(ULONGLONG cbReservation)
  103. { _cbReservedSpace += cbReservation; }
  104. private:
  105. ULONGLONG _cbFreeSpace;
  106. ULONGLONG _cbTotalSpace;
  107. ULONGLONG _cbReservedSpace;
  108. ULONGLONG _cbPagingSpace;
  109. DWORD _dwFileSystemFlags;
  110. BOOL _fIsNtfs;
  111. BOOL _fIsBootDrive;
  112. BOOL _fHasPageFile;
  113. WCHAR _wszDriveName[CHARS_PER_DRIVE];
  114. };
  115. //+-------------------------------------------------------------------------
  116. //
  117. // Class: CCatalogConfig
  118. //
  119. // Purpose: Automatic configuration of a catalog and included scopes.
  120. //
  121. //--------------------------------------------------------------------------
  122. class CCatalogConfig
  123. {
  124. public:
  125. CCatalogConfig(CError &Err);
  126. BOOL InitDriveList();
  127. BOOL AddIncludedDir( WCHAR const * pwszScopeName )
  128. {
  129. return AddStringToArray( _cIncludedScopes, _xaIncludedScopes, pwszScopeName );
  130. }
  131. BOOL AddExcludedDirOrPattern( WCHAR const * pwszScopeName )
  132. {
  133. return AddStringToArray( _cExcludedScopes, _xaExcludedScopes, pwszScopeName );
  134. }
  135. BOOL SaveState();
  136. BOOL ConfigureDefaultCatalog( WCHAR const * pwszPrimaryScope = 0 );
  137. WCHAR const * GetCatalogDrive() const { return _pwszCatalogDrive; }
  138. CDriveInformation * GetDriveInfo(WCHAR const * pwszDriveName);
  139. CDriveInformation * GetDriveInfo(unsigned i)
  140. { return ( i < _cDrive) ? &_DriveList[i] : 0; }
  141. WCHAR const * GetIncludedScope(unsigned i) const
  142. { return ( i < _cIncludedScopes) ? _xaIncludedScopes[i] : 0; }
  143. WCHAR const * GetExcludedScope(unsigned i) const
  144. { return ( i < _cExcludedScopes) ? _xaExcludedScopes[i] : 0; }
  145. void SetName( const WCHAR *pwc )
  146. {
  147. _xName.Init( wcslen( pwc ) + 1 );
  148. RtlCopyMemory( _xName.Get(), pwc, _xName.SizeOf() );
  149. }
  150. const WCHAR * GetName() { return _xName.Get(); }
  151. void SetLocation( const WCHAR *pwc )
  152. {
  153. _xLocation.Init( wcslen( pwc ) + 1 );
  154. RtlCopyMemory( _xLocation.Get(), pwc, _xLocation.SizeOf() );
  155. }
  156. const WCHAR * GetLocation() { return _xLocation.Get(); }
  157. private:
  158. BOOL ReservePageFileData();
  159. static BOOL AddStringToArray( ULONG & c,
  160. XArray<WCHAR const *> & xa,
  161. WCHAR const * pwsz );
  162. CError & _Err;
  163. ULONG _cDrive;
  164. CDriveInformation _DriveList[MAX_DRIVES]; // per-drive info
  165. WCHAR const * _pwszCatalogDrive; // name of catalog drive
  166. ULONG _cIncludedScopes;
  167. XArray<WCHAR const *> _xaIncludedScopes; // scopes included in catalog
  168. ULONG _cExcludedScopes;
  169. XArray<WCHAR const *> _xaExcludedScopes; // scopes excluded from catalog
  170. XArray<WCHAR> _xName; // catalog name
  171. XArray<WCHAR> _xLocation; // catalog location
  172. };
  173. //+-------------------------------------------------------------------------
  174. //
  175. // Class: CCatReg
  176. //
  177. // Purpose: Supports IS catalog registry configuration
  178. //
  179. //--------------------------------------------------------------------------
  180. class CCatReg
  181. {
  182. public:
  183. CCatReg(CError & Err) : _Err(Err)
  184. {
  185. RtlZeroMemory( _wszCatRegSubKey, sizeof _wszCatRegSubKey );
  186. RtlZeroMemory( _wszCatScopeRegSubKey, sizeof _wszCatScopeRegSubKey );
  187. }
  188. BOOL Init( WCHAR const * pwszCatName, WCHAR const * pwszLocation );
  189. BOOL AddScope( WCHAR const * pwszScopeName,
  190. WCHAR const * pwszScopeAttribute );
  191. BOOL TrackW3Svc( DWORD dwInstance = 1 );
  192. private:
  193. CError & _Err;
  194. WCHAR _wszCatRegSubKey[MAX_PATH];
  195. WCHAR _wszCatScopeRegSubKey[MAX_PATH];
  196. };