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.

397 lines
11 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. rstrcore.h
  5. Abstract:
  6. Common header file for SRRSTR component.
  7. Revision History:
  8. Seong Kook Khang (SKKhang) 06/20/00
  9. created
  10. ******************************************************************************/
  11. #ifndef _RSTRCORE_H__INCLUDED_
  12. #define _RSTRCORE_H__INCLUDED_
  13. #pragma once
  14. #include "srshutil.h"
  15. /////////////////////////////////////////////////////////////////////////////
  16. //
  17. // Constant Definitions
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #define MAX_STATUS 256
  21. #define MAX_STR 1024
  22. #define DSUSAGE_SLIDER_FREQ 10 // Granularity of DS Usage Slider Bar
  23. #define SRREG_VAL_LOCKFILELIST L"LockFileList"
  24. #define SRREG_VAL_LOADFILELIST L"LoadFileList"
  25. /////////////////////////////////////////////////////////////////////////////
  26. //
  27. // Helper Macros
  28. //
  29. /////////////////////////////////////////////////////////////////////////////
  30. #define VALIDATE_READFILE(hf, buf, size, read, label) \
  31. if ( !::ReadFile( hf, buf, size, &read, NULL ) ) \
  32. { \
  33. LPCWSTR cszErr = ::GetSysErrStr(); \
  34. DebugTrace(0, "::ReadFile failed - %ls", cszErr); \
  35. goto label; \
  36. } \
  37. #define VALIDATE_READSIZE(size, read, label) \
  38. if ( read != size ) \
  39. { \
  40. DebugTrace(TRACE_ID, "Unexpected EOF (size=%d, read=%d)...", size, read); \
  41. goto label; \
  42. } \
  43. #define READFILE_AND_VALIDATE(hf, buf, size, read, label) \
  44. VALIDATE_READFILE(hf, buf, size, read, label) \
  45. VALIDATE_READSIZE(size, read, label) \
  46. #define VALIDATE_WRITEFILE(hf, buf, size, written, label) \
  47. if ( !::WriteFile( hf, buf, size, &written, NULL ) ) \
  48. { \
  49. LPCWSTR cszErr = ::GetSysErrStr(); \
  50. DebugTrace(TRACE_ID, "::WriteFile failed - %ls", cszErr); \
  51. goto label; \
  52. } \
  53. #define VALIDATE_WRITTENSIZE(size, written, label) \
  54. if ( written != size ) \
  55. { \
  56. DebugTrace(TRACE_ID, "Incomplete Write (size=%d, written=%d)...", size, written); \
  57. goto label; \
  58. } \
  59. #define WRITEFILE_AND_VALIDATE(hf, buf, size, read, label) \
  60. VALIDATE_WRITEFILE(hf, buf, size, read, label) \
  61. VALIDATE_WRITTENSIZE(size, read, label) \
  62. /////////////////////////////////////////////////////////////////////////////
  63. //
  64. // Global Variables / Helper Functions
  65. //
  66. /////////////////////////////////////////////////////////////////////////////
  67. // from main.cpp
  68. //
  69. extern HINSTANCE g_hInst;
  70. // from api.cpp
  71. //
  72. extern void EnsureTrace();
  73. extern void ReleaseTrace();
  74. // from password.cpp
  75. //
  76. DWORD RegisterNotificationDLL (HKEY hKeyLM, BOOL fRegister);
  77. /////////////////////////////////////////////////////////////////////////////
  78. //
  79. // Drive Table Management
  80. //
  81. /////////////////////////////////////////////////////////////////////////////
  82. class CRstrDriveInfo
  83. {
  84. public:
  85. CRstrDriveInfo();
  86. ~CRstrDriveInfo();
  87. public:
  88. DWORD GetFlags();
  89. BOOL IsExcluded();
  90. BOOL IsFrozen();
  91. BOOL IsOffline();
  92. BOOL IsSystem();
  93. BOOL RefreshStatus();
  94. LPCWSTR GetID();
  95. LPCWSTR GetMount();
  96. LPCWSTR GetLabel();
  97. void SetMountAndLabel( LPCWSTR cszMount, LPCWSTR cszLabel );
  98. HICON GetIcon( BOOL fSmall );
  99. BOOL SaveToLog( HANDLE hfLog );
  100. UINT GetDSUsage();
  101. BOOL GetUsageText( LPWSTR szUsage );
  102. BOOL GetCfgExcluded( BOOL *pfExcluded );
  103. void SetCfgExcluded( BOOL fExcluded );
  104. BOOL GetCfgDSUsage( UINT *puPos );
  105. void SetCfgDSUsage( UINT uPos );
  106. BOOL ApplyConfig( HWND hWnd );
  107. BOOL Release();
  108. BOOL InitUsage (LPCWSTR cszID, INT64 llDSUsage);
  109. // operations
  110. public:
  111. BOOL Init( LPCWSTR cszID, CDataStore *pDS, BOOL fOffline );
  112. BOOL Init( LPCWSTR cszID, DWORD dwFlags, INT64 llDSUsage, LPCWSTR cszMount,
  113. LPCWSTR cszLabel );
  114. BOOL LoadFromLog( HANDLE hfLog );
  115. void UpdateStatus( DWORD dwFlags, BOOL fOffline );
  116. // attributes
  117. protected:
  118. DWORD m_dwFlags;
  119. CSRStr m_strID; // Unique Volume GUID
  120. CSRStr m_strMount; // Mount Point (drive letter or root directory path)
  121. CSRStr m_strLabel; // Volume Label
  122. HICON m_hIcon[2]; // Large Icon for this drive
  123. INT64 m_llDSMin; // Minimum size of DS
  124. INT64 m_llDSMax; // Maximum size of DS
  125. UINT m_uDSUsage; // Current DS Usage by Service
  126. BOOL m_fCfgExcluded; // Configured value of "Exclude"
  127. UINT m_uCfgDSUsage; // Configured value of "DS Usage"
  128. ULARGE_INTEGER m_ulTotalBytes;
  129. };
  130. typedef CSRDynPtrArray<CRstrDriveInfo*, 8> CRDIArray;
  131. BOOL CreateAndLoadDriveInfoInstance( HANDLE hfLog, CRstrDriveInfo **ppRDI );
  132. BOOL CreateDriveList( int nRP, CRDIArray &aryDrv, BOOL fRemoveDrives );
  133. BOOL UpdateDriveList( CRDIArray &aryDrv );
  134. /////////////////////////////////////////////////////////////////////////////
  135. //
  136. // CRestoreOperationManager class
  137. //
  138. /////////////////////////////////////////////////////////////////////////////
  139. // forward declaration
  140. class CRestoreMapEntry;
  141. class CRestoreLogFile;
  142. class CRestoreProgressWindow;
  143. typedef CSRDynPtrArray<CRestoreMapEntry*, 64> CRMEArray;
  144. class CRestoreOperationManager
  145. {
  146. public:
  147. CRestoreOperationManager();
  148. protected:
  149. ~CRestoreOperationManager();
  150. // operations - methods
  151. public:
  152. BOOL Run( BOOL fFull );
  153. BOOL FindDependentMapEntry( LPCWSTR cszSrc, BOOL fCheckSrc, CRestoreMapEntry **ppEnt );
  154. BOOL GetNextMapEntry( CRestoreMapEntry **ppEnt );
  155. BOOL Release();
  156. // operations
  157. public:
  158. BOOL Init();
  159. // operations - worker thread
  160. protected:
  161. static DWORD WINAPI ExtThreadProc( LPVOID lpParam );
  162. DWORD ROThreadProc();
  163. DWORD T2Initialize();
  164. DWORD T2EnumerateDrives();
  165. DWORD T2CreateMap();
  166. DWORD T2DoRestore( BOOL fUndo );
  167. DWORD T2HandleSnapshot( CSnapshot & cSS, WCHAR * szSSPath );
  168. DWORD T2CleanUp();
  169. DWORD T2Fifo( int nDrv, DWORD dwRPNum );
  170. DWORD T2UndoForFail();
  171. // attributes
  172. protected:
  173. BOOL m_fFullRestore; // internal debug purpose only
  174. WCHAR m_szMapFile[MAX_PATH];
  175. CRestoreLogFile *m_pLogFile;
  176. CRestoreProgressWindow *m_pProgress;
  177. DWORD m_dwRPNum;
  178. DWORD m_dwRPNew;
  179. CRDIArray m_aryDrv;
  180. CRMEArray *m_paryEnt;
  181. DWORD m_dwTotalEntry;
  182. BOOL m_fRebuildCatalogDb;
  183. // Restore Context
  184. int m_nDrv; // Current drive being restored
  185. int m_nEnt; // Current map entry being restored
  186. };
  187. BOOL CreateRestoreOperationManager( CRestoreOperationManager **ppROMgr );
  188. /////////////////////////////////////////////////////////////////////////////
  189. //
  190. // CRestoreMapEntry class
  191. //
  192. /////////////////////////////////////////////////////////////////////////////
  193. class CRestoreMapEntry
  194. {
  195. public:
  196. CRestoreMapEntry( INT64 llSeq, DWORD dwOpr, LPCWSTR cszSrc );
  197. // operations - methods
  198. public:
  199. INT64 GetSeqNum()
  200. { return( m_llSeq ); }
  201. DWORD GetOpCode()
  202. { return( m_dwOpr ); }
  203. DWORD GetAttr()
  204. { return( m_dwAttr ); }
  205. DWORD GetResult()
  206. { return( m_dwRes ); }
  207. DWORD GetError()
  208. { return( m_dwErr ); }
  209. LPCWSTR GetPath1()
  210. { return( m_strSrc ); }
  211. virtual LPCWSTR GetPath2()
  212. { return( NULL ); }
  213. LPCWSTR GetAltPath()
  214. { return( m_strAlt ); }
  215. void SetResults( DWORD dwRes, DWORD dwErr )
  216. { m_dwRes = dwRes; m_dwErr = dwErr; }
  217. void UpdateSrc( LPCWSTR cszPath )
  218. { m_strSrc = cszPath; }
  219. virtual void ProcessLocked() {}
  220. virtual void Restore( CRestoreOperationManager *pROMgr ) {}
  221. void ProcessLockedAlt();
  222. BOOL Release();
  223. // operations
  224. protected:
  225. BOOL ClearAccess( LPCWSTR cszPath );
  226. BOOL MoveFileDelay( LPCWSTR cszSrc, LPCWSTR cszDst );
  227. void ProcessDependency( CRestoreOperationManager *pROMgr, DWORD dwFlags );
  228. // attributes
  229. protected:
  230. INT64 m_llSeq;
  231. DWORD m_dwOpr;
  232. DWORD m_dwAttr;
  233. CSRStr m_strSrc;
  234. CSRStr m_strDst;
  235. CSRStr m_strTmp;
  236. CSRStr m_strAlt; // Alternative file name for renaming locked file/dir.
  237. DWORD m_dwRes;
  238. DWORD m_dwErr;
  239. CSRStr m_strShortFileName;
  240. };
  241. BOOL CreateRestoreMapEntryFromChgLog( CChangeLogEntry* pCLE, LPCWSTR cszDrv, LPCWSTR cszDSPath, CRMEArray &aryEnt );
  242. /////////////////////////////////////////////////////////////////////////////
  243. //
  244. // CRestoreLogFile class
  245. //
  246. /////////////////////////////////////////////////////////////////////////////
  247. class CRestoreLogFile
  248. {
  249. public:
  250. CRestoreLogFile();
  251. protected:
  252. ~CRestoreLogFile();
  253. public:
  254. BOOL Open();
  255. BOOL Close();
  256. BOOL ReadHeader( SRstrLogHdrV3 *pRPInfo , CRDIArray &aryDrv );
  257. BOOL AppendHeader( SRstrLogHdrV3Ex *pExtInfo );
  258. BOOL WriteEntry( DWORD dwID, CRestoreMapEntry *pEnt, LPCWSTR cszMount );
  259. BOOL WriteCollisionEntry( LPCWSTR cszSrc, LPCWSTR cszDst, LPCWSTR cszMount
  260. );
  261. BOOL WriteMarker( DWORD dwMarker, DWORD dwErr );
  262. BOOL IsValid();
  263. BOOL Release();
  264. // operations
  265. public:
  266. BOOL Init();
  267. // attributes
  268. protected:
  269. WCHAR m_szLogFile[MAX_PATH];
  270. HANDLE m_hfLog;
  271. };
  272. BOOL CreateRestoreLogFile( SRstrLogHdrV3 *pRPInfo, CRDIArray &aryDrv );
  273. BOOL OpenRestoreLogFile( CRestoreLogFile **ppLogFile );
  274. /////////////////////////////////////////////////////////////////////////////
  275. //
  276. // CRestoreProgressWindow class
  277. //
  278. /////////////////////////////////////////////////////////////////////////////
  279. class CRestoreProgressWindow
  280. {
  281. public:
  282. CRestoreProgressWindow();
  283. protected:
  284. ~CRestoreProgressWindow();
  285. // operations - methods
  286. public:
  287. BOOL Create();
  288. BOOL Close();
  289. BOOL Run();
  290. BOOL SetStage( DWORD dwStage, DWORD dwBase );
  291. BOOL Increment();
  292. BOOL Release();
  293. // operations
  294. public:
  295. BOOL Init();
  296. BOOL LoadAndSetBrandBitmap( HWND hwndCtrl );
  297. // operations - dialog procedure
  298. protected:
  299. static INT_PTR CALLBACK ExtDlgProc( HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam );
  300. int RPWDlgProc( HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam );
  301. // attributes
  302. protected:
  303. HWND m_hWnd;
  304. HBITMAP m_hbmBrand;
  305. int m_nResId;
  306. HFONT m_hFntTitle;
  307. int m_cxBar; // Client width of progress bar.
  308. int m_cxBarReal; // Width of progress bar portion corresponds to "restore" stage.
  309. DWORD m_dwStage; // Current stage.
  310. DWORD m_dwBase; // Maximum position value, valid only for RPS_RESTORE.
  311. DWORD m_dwPosLog; // Logical position, e.g. number of change log entries.
  312. DWORD m_dwPosReal; // Physical position of progress bar.
  313. };
  314. // Restore Progress Stage
  315. enum
  316. {
  317. RPS_PREPARE = 0,
  318. RPS_RESTORE,
  319. RPS_SNAPSHOT
  320. };
  321. BOOL CreateRestoreProgressWindow( CRestoreProgressWindow **ppDlg );
  322. #endif //_RSTRCORE_H__INCLUDED_