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. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2000.
  5. //
  6. // File: PRCSTOB.CXX
  7. //
  8. // Contents: Recoverable Storage Object
  9. //
  10. // Classes: PRcovStorageObj
  11. //
  12. // History: 04-Feb-1994 SrikantS Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include <prcstob.hxx>
  18. #include <eventlog.hxx>
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Member: PRcovStorageObj::VerifyConsistency
  22. //
  23. // Synopsis: This method checks the consistency of the recoverable storage
  24. // object by comparing the length of the primary stream with that
  25. // stored in the header.
  26. //
  27. // Normally an inconsistency should never be there but this is for
  28. // those situations when something happened causing the inconsistency.
  29. //
  30. // Effects: If there is an inconsistency, the streams will be emptied out.
  31. //
  32. // Arguments: (none)
  33. //
  34. // History: 3-22-94 srikants Created
  35. //
  36. // Notes:
  37. //
  38. //----------------------------------------------------------------------------
  39. void PRcovStorageObj::VerifyConsistency()
  40. {
  41. Win4Assert( !IsOpen( CRcovStorageHdr::idxOne ) );
  42. Win4Assert( !IsOpen( CRcovStorageHdr::idxTwo ) );
  43. //
  44. // Verify the validity of signatures in the header.
  45. //
  46. if ( !_hdr.IsValid(_storage.GetStorageVersion()) )
  47. {
  48. PStorage & storage = GetStorage();
  49. Win4Assert( !"Corrupt recoverable object" );
  50. storage.ReportCorruptComponent( L"RcovStorageObj1" );
  51. THROW( CException( CI_CORRUPT_DATABASE ) );
  52. }
  53. CRcovStorageHdr::DataCopyNum iPrim, iBack;
  54. iPrim = _hdr.GetPrimary();
  55. iBack = _hdr.GetBackup();
  56. //
  57. // First open the primary stream in a read-only mode and check
  58. // consistency.
  59. //
  60. Open( iPrim, FALSE );
  61. PMmStream & mmStrmPrim = GetMmStream( iPrim );
  62. LONGLONG llcbPrimary = _hdr.GetCbToSkip(iPrim) +
  63. _hdr.GetUserDataSize(iPrim);
  64. LONGLONG cbPrimaryStream = mmStrmPrim.Size();
  65. BOOL fIsConsistent = llcbPrimary <= cbPrimaryStream;
  66. Close( iPrim );
  67. if ( !fIsConsistent )
  68. {
  69. ciDebugOut(( DEB_ERROR,
  70. "PRcovStorageObj - this=0x%X Primary is not consistent\n",
  71. this ));
  72. PStorage & storage = GetStorage();
  73. // Don't assert as this can happen when you kill cisvc while
  74. // creating a catalog. Current tests do this.
  75. //Win4Assert( !"Corrupt recoverable object" );
  76. ciDebugOut(( DEB_ERROR,
  77. "llcbPrimary %#I64d, primary size %#I64d\n",
  78. llcbPrimary,
  79. cbPrimaryStream ));
  80. storage.ReportCorruptComponent( L"RcovStorageObj2" );
  81. THROW( CException( CI_CORRUPT_DATABASE ) );
  82. }
  83. //
  84. // If the recoverable object is clean, the backup is excpected to be
  85. // consistent also.
  86. //
  87. if ( _hdr.IsBackupClean() )
  88. {
  89. //
  90. // Check the consistency of the backup stream also.
  91. //
  92. Open( iBack, FALSE );
  93. PMmStream & mmStrmBack = GetMmStream( iBack );
  94. LONGLONG llcbBackup = _hdr.GetCbToSkip(iBack) +
  95. _hdr.GetUserDataSize(iBack);
  96. LONGLONG cbBackupStream = mmStrmBack.Size();
  97. fIsConsistent = llcbBackup <= cbBackupStream;
  98. Close( iBack );
  99. if ( !fIsConsistent )
  100. {
  101. ciDebugOut(( DEB_ERROR,
  102. "PRcovStorageObj - this=0x%X Backup is not consistent\n",
  103. this ));
  104. PStorage & storage = GetStorage();
  105. Win4Assert( !"Corrupt recoverable object" );
  106. ciDebugOut(( DEB_ERROR,
  107. "llcbBackup %#I64d, backup size %#I64d\n",
  108. llcbBackup,
  109. cbBackupStream ));
  110. storage.ReportCorruptComponent( L"RcovStorageObj3" );
  111. THROW( CException( CI_CORRUPT_DATABASE ) );
  112. }
  113. if ( llcbBackup != llcbPrimary )
  114. {
  115. ciDebugOut(( DEB_ERROR,
  116. "PRcovStorageObj - this=0x%X Lengths not equal\n",
  117. this ));
  118. }
  119. }
  120. } //VerifyConsistency