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.

96 lines
2.8 KiB

  1. #ifndef __A51_HEAP__H_
  2. #define __A51_HEAP__H_
  3. #include <lock.h>
  4. #include <absfile.h>
  5. typedef DWORD TOffset;
  6. #define ROSWELL_INVALID_OFFSET -1
  7. struct CRecordInfo
  8. {
  9. DWORD m_dwIndex;
  10. TOffset m_nOffset;
  11. CRecordInfo(DWORD dwIndex, TOffset nOffset)
  12. : m_dwIndex(dwIndex), m_nOffset(nOffset)
  13. {}
  14. };
  15. class CFileHeap
  16. {
  17. public:
  18. CFileHeap()
  19. : m_bInit(FALSE),
  20. // m_hTimerQueue(NULL), m_hTrimRequest(NULL),
  21. m_pMainFile(NULL), m_pFreeFile(NULL)
  22. {}
  23. virtual ~CFileHeap();
  24. long Initialize(CAbstractFileSource* pSource,
  25. LPCWSTR wszFileNameBase);
  26. long Uninitialize();
  27. long Allocate(DWORD dwLength, TOffset* pnOffset);
  28. long FreeAllocation(TOffset nOffset, DWORD dwLength);
  29. long ReadBytes(TOffset nOffset, BYTE* pBuffer, DWORD dwLength);
  30. long WriteBytes(TOffset nOffset, BYTE* pBuffer, DWORD dwLength);
  31. long InvalidateCache();
  32. public:
  33. DWORD GetFileLength();
  34. long FindNextFree(TOffset nCurrentOffset, TOffset* pnNextFreeOffset,
  35. DWORD* pdwNextFreeLength);
  36. protected:
  37. BOOL m_bInit;
  38. CCritSec m_cs;
  39. CAbstractFile* m_pMainFile;
  40. CAbstractFile* m_pFreeFile;
  41. public:
  42. typedef std::multimap<DWORD, CRecordInfo> TFreeMap;
  43. typedef TFreeMap::iterator TFreeIterator;
  44. typedef TFreeMap::value_type TFreeValue;
  45. typedef std::map<TOffset, DWORD> TFreeOffsetMap;
  46. typedef TFreeOffsetMap::iterator TFreeOffsetIterator;
  47. typedef TFreeOffsetMap::value_type TFreeOffsetValue;
  48. // for the dump utility
  49. TFreeOffsetMap& GetFreeOffsetMap() {return m_mapFreeOffset;}
  50. protected:
  51. TFreeMap m_mapFree;
  52. TFreeOffsetMap m_mapFreeOffset;
  53. // HANDLE m_hTimerQueue;
  54. // HANDLE m_hTrimRequest;
  55. protected:
  56. DWORD GetFreeListRecordSize();
  57. TFreeOffsetIterator GetOffsetIteratorFromFree(TFreeIterator itFree);
  58. TFreeIterator GetFreeIteratorFromOffset(TFreeOffsetIterator itOffset);
  59. long InsertFreeBlock(TOffset nOffset, DWORD dwLength);
  60. long EraseFreeBlockByFreeIt(TFreeIterator itFree);
  61. long EraseFreeBlockByOffsetIt(TFreeOffsetIterator itFreeOffset);
  62. long EraseFreeBlock(TFreeIterator itFree, TFreeOffsetIterator itOffset);
  63. long ReplaceFreeBlockByFreeIt(TFreeIterator itFree, TOffset nOffset,
  64. DWORD dwSize);
  65. long ReplaceFreeBlockByOffsetIt(TFreeOffsetIterator itFreeOffset,
  66. TOffset nOffset, DWORD dwSize);
  67. long ReplaceFreeBlock(TFreeIterator itFree, TFreeOffsetIterator itOffset,
  68. TOffset nOffset, DWORD dwSize);
  69. long WriteAllocationRecordToDisk(const CRecordInfo& Info, DWORD dwSize);
  70. long WriteToFreeFile(TOffset nOffset, BYTE* pBuffer, DWORD dwLength);
  71. long ReadFromFreeFile(TOffset nOffset, BYTE* pBuffer, DWORD dwLength);
  72. long ReadFreeList();
  73. };
  74. #endif