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.

149 lines
4.3 KiB

  1. // FreeList.h -- Definition of CFreeList class and IFreeList interface.
  2. #ifndef __FREELIST_H__
  3. #define __FREELIST_H__
  4. /*
  5. This file defines the interface to the free-space manager for the Tome file. It's
  6. done as a subclass of IPersistStreamInit so that different free list implementations
  7. can be bound to particular Tome files automatically.
  8. Its public methods allow you to:
  9. 1. Add a segment of LockBytes address space to the free space
  10. 2. Allocate address space from available free space
  11. 3. Attempt an allocation beginning at a particular address
  12. 4. Allocate address space at the end of the LockBytes container.
  13. */
  14. #undef GetFreeSpace // kill the obsolete Win16 macro before we
  15. // encounter the IFreeList definition...
  16. class CFreeList : public CITUnknown
  17. {
  18. public:
  19. ~CFreeList();
  20. static HRESULT CreateFreeList(IITFileSystem *pITFS, CULINT cbPreallocated, IITFreeList **ppITFreeList);
  21. static HRESULT CreateAndSizeFreeList(IITFileSystem *pITFS, CULINT cbPreallocated, UINT cSlots, IITFreeList **ppITFreeList);
  22. static HRESULT LoadFreeList(IITFileSystem *pITFS, IITFreeList **ppITFreeList);
  23. static HRESULT AttachFreeList(IITFileSystem *pITFS, IITFreeList **ppITFreeList);
  24. private:
  25. CFreeList(IUnknown *punkOuter);
  26. class CImpIFreeList : public IITFreeList
  27. {
  28. public:
  29. CImpIFreeList(CFreeList *pBackObj, IUnknown *punkOuter);
  30. ~CImpIFreeList(void);
  31. HRESULT ReadIn (LPSTREAM pStm, PVOID pv, ULONG cb);
  32. HRESULT WriteOut(LPSTREAM pStm, PVOID pv, ULONG cb);
  33. // IPersist Method:
  34. HRESULT STDMETHODCALLTYPE GetClassID(
  35. /* [out] */ CLSID __RPC_FAR *pClassID);
  36. // IPersistStreamInit Methods:
  37. HRESULT STDMETHODCALLTYPE IsDirty( void);
  38. HRESULT STDMETHODCALLTYPE Load(
  39. /* [in] */ LPSTREAM pStm);
  40. HRESULT STDMETHODCALLTYPE Save(
  41. /* [in] */ LPSTREAM pStm,
  42. /* [in] */ BOOL fClearDirty);
  43. HRESULT STDMETHODCALLTYPE GetSizeMax(
  44. /* [out] */ ULARGE_INTEGER __RPC_FAR *pCbSize);
  45. HRESULT STDMETHODCALLTYPE InitNew( void);
  46. // IFreeList Methods:
  47. HRESULT STDMETHODCALLTYPE InitNew(IITFileSystem *pITFS, CULINT cbPreallocated);
  48. HRESULT STDMETHODCALLTYPE InitNew(IITFileSystem *pITFS, CULINT cbPreallocated, UINT cEntriesMax);
  49. HRESULT STDMETHODCALLTYPE InitLoad(IITFileSystem *pITFS);
  50. HRESULT STDMETHODCALLTYPE LazyInitNew(IITFileSystem *pITFS);
  51. HRESULT STDMETHODCALLTYPE RecordFreeList();
  52. HRESULT STDMETHODCALLTYPE PutFreeSpace(CULINT ullBase, CULINT ullCB);
  53. HRESULT STDMETHODCALLTYPE GetFreeSpace(CULINT *pullBase, CULINT *pullcb);
  54. HRESULT STDMETHODCALLTYPE GetFreeSpaceAt(CULINT ullBase, CULINT *pullcb);
  55. HRESULT STDMETHODCALLTYPE GetEndingFreeSpace
  56. (CULINT *pullBase, CULINT *pullcb);
  57. HRESULT STDMETHODCALLTYPE GetStatistics
  58. (CULINT *pcbLost, CULINT *pcbSpace);
  59. HRESULT STDMETHODCALLTYPE SetFreeListEmpty();
  60. HRESULT STDMETHODCALLTYPE SetSpaceSize(ULARGE_INTEGER uliCbSpace);
  61. private:
  62. UINT HighestEntryLEQ(CULINT &ullBase);
  63. HRESULT STDMETHODCALLTYPE ConnectToStream();
  64. typedef struct _freeitem
  65. {
  66. CULINT ullOffset; // Start of free block
  67. CULINT ullCB; // Size of free block in bytes
  68. } FREEITEM, *PFREEITEM;
  69. enum { DEFAULT_ENTRIES_MAX = 510 };
  70. CITCriticalSection m_cs;
  71. BOOL m_fInitialed;
  72. BOOL m_fIsDirty;
  73. UINT m_cBlocks; // Number of blocks in list
  74. UINT m_cBlocksMax; // Max number of blocks in list
  75. CULINT m_cbLost; // Number of bytes totally lost forever
  76. CULINT m_cbSpace;
  77. BOOL m_fDirty;
  78. IITFileSystem *m_pITFS;
  79. DEBUGDEF(CULINT m_cbPreallocated)
  80. PFREEITEM m_paFreeItems;
  81. };
  82. friend CImpIFreeList;
  83. CImpIFreeList m_ImpIFreeList;
  84. };
  85. typedef CFreeList *PCFreelist;
  86. extern GUID aIID_CFreeList[4];
  87. extern UINT cInterfaces_CFreeList;
  88. inline CFreeList::CFreeList(IUnknown * punkOuter)
  89. : m_ImpIFreeList(this, punkOuter),
  90. CITUnknown(aIID_CFreeList, cInterfaces_CFreeList, (IUnknown *)&m_ImpIFreeList)
  91. {
  92. }
  93. inline CFreeList::~CFreeList
  94. ()
  95. {
  96. }
  97. #endif // __FREELIST_H__