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.

128 lines
3.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2000.
  5. //
  6. // File: DYNSTRM.HXX
  7. //
  8. // Contents: Dynamicly growing memory mapped versioned stream
  9. //
  10. // History: 18-May-93 BartoszM Created
  11. // 07-Dec-93 DwightKr Added Shrink() method
  12. // 28-Jul-97 SitaramR Added sequential read/write
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include <pmmstrm.hxx>
  17. //
  18. // The stream header contains the following numbers
  19. //
  20. // Version
  21. // Count of items
  22. // Data size in bytes
  23. //
  24. // followed by items occupying data_size bytes
  25. // and possibly some slack space for growth
  26. //
  27. // |-----|++++++++++++++|---------|
  28. // HDR ^ ^ ^
  29. // +-- data size -+ |
  30. // +----- avail size -------+
  31. //
  32. // The size of the stream is always kept a multiple
  33. // of COMMON_PAGE_SIZE
  34. class PStorage;
  35. class CDynStream
  36. {
  37. enum
  38. {
  39. HEADER_VERSION = 0,
  40. HEADER_DIRTY = 1,
  41. HEADER_COUNT = 2,
  42. HEADER_DATASIZE = 3,
  43. HEADER_SIZE = 4 * sizeof(ULONG)
  44. };
  45. public:
  46. CDynStream(PMmStream* pStream);
  47. CDynStream();
  48. ~CDynStream();
  49. void Init ( PMmStream* pStream ) { _pStream = pStream; }
  50. BOOL CheckVersion ( PStorage& storage, ULONG version, BOOL fIsReadOnly );
  51. BOOL Ok() { return _pStream->Ok(); }
  52. BYTE* Get() { return (BYTE*)_bufStream.Get() + HEADER_SIZE; }
  53. void Grow( PStorage& storage, ULONG newDataSize );
  54. void Shrink( PStorage& storage, ULONG newDataSize );
  55. BOOL isWritable() { return _pStream->isWritable(); }
  56. ULONG Version()
  57. {
  58. Win4Assert( 0 == HEADER_VERSION );
  59. return *(ULONG*)_bufStream.Get();
  60. }
  61. void Flush();
  62. BOOL MarkDirty();
  63. void MarkClean()
  64. {
  65. *((ULONG *) _bufStream.Get() + HEADER_DIRTY) = FALSE;
  66. }
  67. BOOL IsDirty()
  68. {
  69. return *((ULONG *) _bufStream.Get() + HEADER_DIRTY);
  70. }
  71. ULONG Count()
  72. {
  73. return *((ULONG*)_bufStream.Get() + HEADER_COUNT);
  74. }
  75. ULONG DataSize()
  76. {
  77. return *((ULONG*)_bufStream.Get() + HEADER_DATASIZE);
  78. }
  79. void SetVersion( ULONG version)
  80. {
  81. Win4Assert( 0 == HEADER_VERSION );
  82. *((ULONG *) _bufStream.Get()) = version;
  83. }
  84. void SetCount( ULONG count)
  85. {
  86. *((ULONG *) _bufStream.Get() + HEADER_COUNT) = count;
  87. }
  88. void SetDataSize ( ULONG size)
  89. {
  90. *((ULONG *) _bufStream.Get() + HEADER_DATASIZE) = size;
  91. }
  92. ULONG AvailSize() const
  93. {
  94. return _bufStream.Size() - HEADER_SIZE;
  95. }
  96. void InitializeForRead();
  97. void InitializeForWrite( ULONG cbSize );
  98. ULONG Read( void *pBuf, ULONG cbToRead );
  99. void Write( void *pBuf, ULONG cbToWrite );
  100. private:
  101. PMmStream* _pStream;
  102. CMmStreamBuf _bufStream;
  103. BYTE * _pCurPos; // Pointer for reading, writing
  104. BYTE * _pStartPos; // Start pointer for reading, writing
  105. ULONG _ulDataSize; // Size of persistent stream
  106. };