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.

198 lines
5.3 KiB

  1. /*++
  2. Copyright (C) 2000-2001 Microsoft Corporation
  3. --*/
  4. #ifndef __WMI_A51_LONG_STAGE__H_
  5. #define __WMI_A51_LONG_STAGE__H_
  6. #include <queue>
  7. #include <map>
  8. #include <list>
  9. #include <sync.h>
  10. #include "a51tools.h"
  11. #include "stagemgr.h"
  12. #define A51_MAX_FILES 5
  13. class CFileCache;
  14. class CLongFileStagingFile;
  15. struct CFileLocation
  16. {
  17. int m_nFileId;
  18. TFileOffset m_lStartOffset;
  19. CFileLocation() : m_nFileId(0), m_lStartOffset(0)
  20. {}
  21. CFileLocation(int nFileId, TFileOffset lStartOffset)
  22. : m_nFileId(nFileId), m_lStartOffset(lStartOffset)
  23. {}
  24. };
  25. class CLongFileInstruction : public CStageInstruction
  26. {
  27. protected:
  28. CFileLocation m_Location;
  29. public:
  30. CLongFileInstruction(CLongFileStagingFile* pFile);
  31. CLongFileInstruction(CLongFileStagingFile* pFile, int nFileId,
  32. TFileOffset lStartOffset);
  33. virtual ~CLongFileInstruction(){}
  34. virtual bool IsWrite() = 0;
  35. virtual void Dump();
  36. protected:
  37. BYTE* WriteLocation(BYTE* pBuffer);
  38. DWORD ComputeSpaceForLocation();
  39. long RecoverLocation(HANDLE hFile);
  40. friend class CLongFileStagingFile;
  41. };
  42. class CWriteFileInstruction : public CLongFileInstruction
  43. {
  44. protected:
  45. DWORD m_dwLen;
  46. __int64 m_lZOrder;
  47. static __int64 mstatic_lNextZOrder;
  48. bool m_bReuse;
  49. public:
  50. CWriteFileInstruction(CLongFileStagingFile* pFile)
  51. : CLongFileInstruction(pFile), m_dwLen(0),
  52. m_lZOrder(mstatic_lNextZOrder++), m_bReuse(false)
  53. {
  54. }
  55. CWriteFileInstruction(CLongFileStagingFile* pFile, int nFileId,
  56. TFileOffset lStartOffset, DWORD dwLen)
  57. : CLongFileInstruction(pFile, nFileId, lStartOffset),
  58. m_dwLen(dwLen), m_lZOrder(mstatic_lNextZOrder++), m_bReuse(false)
  59. {
  60. }
  61. virtual ~CWriteFileInstruction(){}
  62. bool IsWrite() {return true;}
  63. virtual void Dump();
  64. virtual long Execute();
  65. virtual long RecoverData(HANDLE hFile);
  66. void MakeTopmost();
  67. void SetReuseFlag() { m_bReuse = true; }
  68. public:
  69. long Write(TFileOffset lOffset, BYTE* pBuffer);
  70. DWORD ComputeNeededSpace();
  71. void GetEnd(CFileLocation* pLocation);
  72. long GetData(HANDLE hFile, long lExtraOffset, DWORD dwLen, BYTE* pBuffer);
  73. TFileOffset ComputeOriginalOffset();
  74. friend class CLongFileStagingFile;
  75. };
  76. class CSetEndOfFileInstruction : public CLongFileInstruction
  77. {
  78. public:
  79. CSetEndOfFileInstruction(CLongFileStagingFile* pFile)
  80. : CLongFileInstruction(pFile)
  81. {}
  82. CSetEndOfFileInstruction(CLongFileStagingFile* pFile, int nFileId,
  83. TFileOffset lLength)
  84. : CLongFileInstruction(pFile, nFileId, lLength)
  85. {}
  86. virtual ~CSetEndOfFileInstruction(){}
  87. bool IsWrite() {return false;}
  88. virtual long Execute();
  89. virtual long RecoverData(HANDLE hFile);
  90. public:
  91. long Write(TFileOffset lOffset);
  92. DWORD ComputeNeededSpace();
  93. friend class CLongFileStagingFile;
  94. };
  95. class CLongFileStagingFile : public CExecutableStageManager
  96. {
  97. class CCompareLocations
  98. {
  99. public:
  100. bool operator()(const CFileLocation& loc1,
  101. const CFileLocation& loc2) const
  102. {
  103. if(loc1.m_nFileId != loc2.m_nFileId)
  104. return (loc1.m_nFileId < loc2.m_nFileId);
  105. else
  106. return loc1.m_lStartOffset < loc2.m_lStartOffset;
  107. }
  108. };
  109. protected:
  110. typedef std::multimap<CFileLocation, CWriteFileInstruction*,
  111. CCompareLocations,
  112. CPrivateTempAllocator<CWriteFileInstruction*> > TMap;
  113. typedef TMap::iterator TIterator;
  114. typedef TMap::value_type TValue;
  115. TMap m_mapStarts;
  116. TMap m_mapEnds;
  117. struct FileInfo
  118. {
  119. HANDLE m_h;
  120. bool m_bSupportsOverwrites;
  121. } m_aFiles[A51_MAX_FILES];
  122. public:
  123. CLongFileStagingFile(long lMaxFileSize = 0,
  124. long lAbortTransactionFileSize = 0);
  125. virtual ~CLongFileStagingFile();
  126. public:
  127. long Create(LPCWSTR wszStagingFileName);
  128. long Initialize();
  129. long Uninitialize(DWORD dwShutDownFlags);
  130. long RegisterFile(int nFileId, HANDLE hFile, bool bSupportsOverwrites);
  131. long ReadFile(int nFileId, DWORD dwStartOffset, BYTE* pBuffer, DWORD dwLen,
  132. DWORD* pdwRead);
  133. long WriteFile(int nFileId, DWORD dwStartOffset, BYTE* pBuffer, DWORD dwLen,
  134. DWORD* pdwRead);
  135. long SetFileLength(int nFileId, DWORD dwLen);
  136. long GetFileLength(int nFileId, DWORD* pdwLength);
  137. long CloseAllFiles();
  138. void Dump(FILE* f);
  139. void FlushDataFiles();
  140. protected:
  141. virtual long AddInstructionToMap(CStageInstruction* pInst,
  142. CStageInstruction** ppUndoInst);
  143. virtual long RemoveInstructionFromMap(CStageInstruction* pInst);
  144. virtual long ConstructInstructionFromType(int nType,
  145. CStageInstruction** ppInst);
  146. virtual bool IsStillCurrent(CStageInstruction* pInst);
  147. bool DoesSupportOverwrites(int nFileId);
  148. virtual long WriteEmpty();
  149. bool InjectFailure();
  150. protected: // for instructions
  151. long WriteToActualFile(int nFileId, TFileOffset lFileOffset, BYTE* pBuffer,
  152. DWORD dwLen);
  153. long SetEndOfActualFile(int nFileId, TFileOffset lFileLength);
  154. friend class CWriteFileInstruction;
  155. friend class CSetEndOfFileInstruction;
  156. };
  157. #endif