Leaked source code of windows server 2003
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.

235 lines
6.7 KiB

  1. /******************************************************************************
  2. *
  3. * Copyright (c) 2000 Microsoft Corporation
  4. *
  5. * Module Name:
  6. * datastormgr.h
  7. *
  8. * Abstract:
  9. * CDataStoreMgr class definition
  10. *
  11. * Revision History:
  12. * Brijesh Krishnaswami (brijeshk) 03/28/2000
  13. * created
  14. *
  15. *****************************************************************************/
  16. #ifndef _DATASTORMGR_H_
  17. #define _DATASTORMGR_H_
  18. #include "datastor.h"
  19. class CDataStoreMgr;
  20. class CDriveTable;
  21. class CRestorePoint;
  22. //
  23. // DriveTable structure with pointers to CDataStore objects
  24. //
  25. // pointer to CDataStore method for looping through all drives
  26. //
  27. typedef DWORD (CDataStore::* PDATASTOREMETHOD) (LONG_PTR lParam);
  28. //+-------------------------------------------------------------------------
  29. //
  30. // Class: CDriveTable
  31. //
  32. // Synopsis: maintains table of drives and CDataStore objects
  33. //
  34. // History: 13-Apr-2000 HenryLee Created
  35. //
  36. //--------------------------------------------------------------------------
  37. struct SDriveTableEnumContext
  38. {
  39. const CDriveTable * _pdt;
  40. int _iIndex;
  41. void Reset ()
  42. {
  43. _pdt = NULL;
  44. _iIndex = 0;
  45. }
  46. };
  47. #define RP_NORMAL 0
  48. #define RP_ADVANCED 1
  49. class CDriveTable : public CSRAlloc
  50. {
  51. public:
  52. friend CDataStoreMgr;
  53. CDriveTable();
  54. ~CDriveTable();
  55. CDataStore * FindDriveInTable (WCHAR *pwszDrive) const;
  56. CDataStore * FindGuidInTable (WCHAR *pwszGuid) const;
  57. CDataStore * FindSystemDrive () const;
  58. DWORD AddDriveToTable(WCHAR *pwszDrive, WCHAR *pwszGuid);
  59. DWORD RemoveDrivesFromTable ();
  60. DWORD FindMountPoint (WCHAR *pwszGuid, WCHAR *pwszPath) const;
  61. DWORD SaveDriveTable (CRestorePoint *prp);
  62. DWORD SaveDriveTable (WCHAR *pwszPath);
  63. DWORD LoadDriveTable (WCHAR *pwszPath);
  64. DWORD IsAdvancedRp (CRestorePoint *prp, PDWORD pdwFlags);
  65. BOOL AnyMountedDrives();
  66. DWORD ForAllDrives (PDATASTOREMETHOD pMethod, LONG_PTR lParam);
  67. DWORD ForOneOrAllDrives (WCHAR *pwszDrive,
  68. PDATASTOREMETHOD pMethod,
  69. LONG_PTR lParam);
  70. CDataStore * FindFirstDrive (SDriveTableEnumContext & dtec) const;
  71. CDataStore * FindNextDrive (SDriveTableEnumContext & dtec) const;
  72. DWORD Merge (CDriveTable &dt); // merge one table into another
  73. DWORD EnumAllVolumes (); // fill in the drive table
  74. inline void SetDirty ()
  75. {
  76. _fDirty = TRUE;
  77. }
  78. BOOL GetDirty()
  79. {
  80. return _fDirty;
  81. }
  82. private:
  83. DWORD CreateNewEntry (CDataStore *pds);
  84. static const enum { DRIVE_TABLE_SIZE = 26 };
  85. CDataStore * _rgDriveTable[DRIVE_TABLE_SIZE];
  86. CDriveTable * _pdtNext;
  87. int _nLastDrive;
  88. BOOL _fDirty;
  89. BOOL _fLockInit;
  90. CLock _lock;
  91. };
  92. //+-------------------------------------------------------------------------
  93. //
  94. // Class: CDataStoreMgr
  95. //
  96. // Synopsis: there will be one global instance of this class
  97. // this is the starting point for all of the datastore tasks
  98. // all the datastore objects will be accessible from here
  99. //
  100. // History: 13-Apr-2000 BrijeshK Created
  101. //
  102. //--------------------------------------------------------------------------
  103. class CDataStoreMgr : public CSRAlloc
  104. {
  105. public:
  106. CDataStoreMgr();
  107. ~CDataStoreMgr();
  108. CDriveTable * GetDriveTable ()
  109. {
  110. return &_dt;
  111. }
  112. // pass NULL for action on all datastores
  113. DWORD Initialize (BOOL fFirstRun);
  114. DWORD Fifo(WCHAR *pwszDrive,
  115. DWORD dwTargetRPNum,
  116. int nTargetPercent,
  117. BOOL fIncludeCurrentRp,
  118. BOOL fFifoAtLeastOneRp);
  119. DWORD FifoOldRps(INT64 llTimeInSeconds);
  120. DWORD FreezeDrive(WCHAR *pwszDrive);
  121. DWORD ThawDrives(BOOL fCheckOnly);
  122. DWORD MonitorDrive(WCHAR *pwszDrive, BOOL fSet);
  123. DWORD TriggerFreezeOrFifo();
  124. DWORD FindFrozenDrive();
  125. BOOL IsDriveFrozen(LPWSTR pszDrive);
  126. void SignalStop ()
  127. {
  128. _fStop = TRUE;
  129. _dt.SaveDriveTable ((CRestorePoint*) NULL);
  130. }
  131. DWORD UpdateDataStoreUsage(WCHAR *pwszDrive, INT64 llDelta);
  132. DWORD CreateDataStore (WCHAR *pwszDrive)
  133. {
  134. return _dt.ForOneOrAllDrives (pwszDrive,
  135. &CDataStore::CreateDataStore,
  136. NULL);
  137. }
  138. DWORD DestroyDataStore (WCHAR *pwszDrive)
  139. {
  140. return _dt.ForOneOrAllDrives (pwszDrive,
  141. &CDataStore::DestroyDataStore,
  142. TRUE);
  143. }
  144. DWORD SetDriveParticipation (WCHAR *pwszDrive, BOOL fParticipate)
  145. {
  146. return _dt.ForOneOrAllDrives (pwszDrive,
  147. &CDataStore::SetParticipate,
  148. fParticipate);
  149. }
  150. DWORD UpdateDriveParticipation (WCHAR *pwszDrive, LPWSTR pwszDir)
  151. {
  152. return _dt.ForOneOrAllDrives (pwszDrive,
  153. &CDataStore::UpdateParticipate,
  154. (LONG_PTR) pwszDir);
  155. }
  156. DWORD UpdateDiskFree (WCHAR *pwszDrive)
  157. {
  158. return _dt.ForOneOrAllDrives (pwszDrive,
  159. &CDataStore::UpdateDiskFree,
  160. NULL);
  161. }
  162. DWORD SetDriveError (WCHAR *pwszDrive)
  163. {
  164. return _dt.ForOneOrAllDrives (pwszDrive,
  165. &CDataStore::SetError,
  166. NULL);
  167. }
  168. DWORD Compress (LPWSTR pszDrive, LONG lDuration);
  169. // Used to get the participation, monitor, freeze, and other flags
  170. DWORD GetFlags (WCHAR *pwszDrive, DWORD *pdwFlags);
  171. DWORD GetUsagePercent(WCHAR *pwszDrive, int * pnPercent);
  172. DWORD CountChangeLogs (CRestorePoint *prp)
  173. {
  174. return _dt.ForAllDrives (&CDataStore::CountChangeLogs, (LONG_PTR) prp);
  175. }
  176. DWORD SwitchRestorePoint (CRestorePoint *prp);
  177. BOOL * GetStopFlag () // used for Delnode_Recurse
  178. {
  179. return &_fStop;
  180. }
  181. DWORD DeleteMachineGuidFile ();
  182. private:
  183. CDriveTable _dt;
  184. BOOL _fStop;
  185. DWORD WriteFifoLog(LPWSTR pwszDrive, LPWSTR pwszRPDir);
  186. DWORD WriteMachineGuid ();
  187. };
  188. extern CDataStoreMgr * g_pDataStoreMgr; // the global instance
  189. #endif