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.

150 lines
4.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 2000.
  5. //
  6. // File: PRCSTOB.HXX
  7. //
  8. // Contents: Recoverable Storage Object.
  9. //
  10. // Classes: PRcovStorageObj
  11. // SRcovStorageObj
  12. //
  13. // History: 25-Jan-94 SrikantS Created.
  14. //
  15. //----------------------------------------------------------------------------
  16. #pragma once
  17. #include <rcstrmhd.hxx>
  18. #include <pmmstrm.hxx>
  19. #include <pstore.hxx>
  20. #if DBG==1
  21. #define AssertValidIndex(n) \
  22. Win4Assert( CRcovStorageHdr::idxOne == n || \
  23. CRcovStorageHdr::idxTwo == n )
  24. #else
  25. #define AssertValidIndex(n)
  26. #endif // DBG==1
  27. #define CI_INITIAL_VERSION 0xFFFFFFFF
  28. //+---------------------------------------------------------------------------
  29. //
  30. // Class: PRcovStorageObj
  31. //
  32. // Purpose: Declares a recoverable storage object. A recoverable storage
  33. // object consists of three streams :
  34. // 1. A header stream which must be written atomically.
  35. // 2. Two copies of the recoverable stream. At any instant
  36. // atleast one of the copies is clean. The other copy may be
  37. // clean or not depending upon whether any operation was in
  38. // progress at the last time this object was accessed and
  39. // updated unsuccessfully.
  40. //
  41. // This class provides the framework for CiRcovStorageObj
  42. //
  43. // History: 1-25-94 srikants Created
  44. // 3-03-98 kitmanh Added IsReadOnly pure virtual function
  45. //
  46. // Notes:
  47. //
  48. //----------------------------------------------------------------------------
  49. class PRcovStorageObj
  50. {
  51. public:
  52. enum StreamType { stPrimary, stBackup };
  53. enum ExclusionType { etShared, etExclusive };
  54. virtual void AcquireAccess( ExclusionType et ) = 0;
  55. virtual void ReleaseAccess() = 0;
  56. virtual void ReadHeader() = 0;
  57. virtual void WriteHeader() = 0;
  58. virtual void Open( CRcovStorageHdr::DataCopyNum n, BOOL fWrite ) = 0;
  59. virtual void Close( CRcovStorageHdr::DataCopyNum n ) = 0 ;
  60. virtual PMmStream & GetMmStream( CRcovStorageHdr::DataCopyNum n ) = 0;
  61. virtual BOOL IsOpen( CRcovStorageHdr::DataCopyNum n ) = 0;
  62. virtual CMmStreamBuf & GetMmStreamBuf( CRcovStorageHdr::DataCopyNum n ) = 0;
  63. virtual BOOL IsMapped( CRcovStorageHdr::DataCopyNum n ) = 0;
  64. CRcovStorageHdr & GetHeader() { return _hdr; }
  65. void InitHeader(ULONG ulVer)
  66. {
  67. _hdr.Init(ulVer);
  68. WriteHeader();
  69. }
  70. PStorage & GetStorage() { return _storage; }
  71. void VerifyConsistency();
  72. ULONG GetVersion() const { return _hdr.GetVersion(); }
  73. virtual ~PRcovStorageObj() {}
  74. virtual IsReadOnly() = 0;
  75. protected:
  76. void SetVersion( ULONG version ) { _hdr.SetVersion(version); }
  77. PRcovStorageObj( PStorage & storage );
  78. PStorage & _storage;
  79. CRcovStorageHdr _hdr; // Header part of the recoverable storage
  80. // object.
  81. };
  82. inline
  83. PRcovStorageObj::PRcovStorageObj( PStorage & storage )
  84. : _storage(storage),
  85. _hdr( storage.GetStorageVersion() )
  86. {
  87. }
  88. class SRcovStorageObj
  89. {
  90. public:
  91. SRcovStorageObj( PRcovStorageObj * pRcovStorageObj )
  92. : _pRcovStorageObj( pRcovStorageObj )
  93. {
  94. }
  95. PRcovStorageObj * Acquire()
  96. {
  97. PRcovStorageObj * temp = _pRcovStorageObj;
  98. _pRcovStorageObj = NULL;
  99. return temp;
  100. }
  101. ~SRcovStorageObj()
  102. {
  103. delete _pRcovStorageObj;
  104. }
  105. PRcovStorageObj * operator->() { return _pRcovStorageObj; }
  106. PRcovStorageObj & operator&() { return *_pRcovStorageObj; }
  107. PRcovStorageObj & operator*() { return *_pRcovStorageObj; }
  108. PRcovStorageObj & Get() { return *_pRcovStorageObj; }
  109. private:
  110. PRcovStorageObj * _pRcovStorageObj;
  111. };