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.

133 lines
3.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1998.
  5. //
  6. // File: CIDIR.HXX
  7. //
  8. // Contents: Persistent directory
  9. //
  10. // Classes: CiDirectory
  11. //
  12. // History: 3-Apr-91 BartoszM Created stub.
  13. // 3-May-96 dlee Don't read it in -- map on-disk data
  14. //
  15. //----------------------------------------------------------------------------
  16. #pragma once
  17. #include <pdir.hxx>
  18. #include <pstore.hxx>
  19. class CiStorage;
  20. class CiDirectoryIter;
  21. class PMmStream;
  22. //+---------------------------------------------------------------------------
  23. //
  24. // Class: CiDirectory
  25. //
  26. // Purpose: Persistent Directory
  27. //
  28. // History: 13-Jun-91 BartoszM Created
  29. //
  30. //----------------------------------------------------------------------------
  31. class CiDirectory : public PDirectory
  32. {
  33. public:
  34. CiDirectory( CiStorage & storage,
  35. WORKID objectId,
  36. PStorage::EOpenMode mode );
  37. void Add( BitOffset& posKey, const CKeyBuf& key );
  38. void Close();
  39. void Seek( const CKey& key, CKeyBuf *pKeyInit, BitOffset& off );
  40. void Seek( const CKeyBuf& key, CKeyBuf *pKeyInit, BitOffset& off );
  41. void SeekNext( const CKeyBuf &key, CKeyBuf *pKeyInit, BitOffset& off );
  42. unsigned CountLeaf() const { return _cKeys; }
  43. void LokBuildDir(const CKeyBuf & maxKey );
  44. void LokFlushDir(const CKeyBuf & maxKey );
  45. void DeleteKeysAfter( const CKeyBuf & key );
  46. void MakeBackupCopy( PStorage & dstStorage,
  47. PSaveProgressTracker & progressTracker );
  48. #if (CIDBG == 1)
  49. CKeyBuf const & GetLastKey()
  50. {
  51. return _keyLast;
  52. }
  53. BitOffset const & GetBitOffsetLastAdded()
  54. {
  55. return _bitOffLastAdded;
  56. }
  57. void SetBitOffsetLastAdded( ULONG page, ULONG offset )
  58. {
  59. _bitOffLastAdded.SetPage( page );
  60. _bitOffLastAdded.SetOff( offset );
  61. }
  62. #endif // CIDBG == 1
  63. // for debugging
  64. unsigned Level1Count() { return _cKeys; }
  65. unsigned Level2Count() { return _cLevel2Keys; }
  66. CDirectoryKey & GetLevel1Key( unsigned i ) { return *_aKeys[i]; }
  67. CDirectoryKey & GetLevel2Key( unsigned i ) { return *_aLevel2Keys[i]; }
  68. private:
  69. // This must be a power of 2. Avg CDirectoryKey size on index1 is
  70. // 36.3 bytes, which means 112.8 keys per 4096k page. A fanout of
  71. // 64 means about 1.5 page hits per seek, and a Level2 total size
  72. // of about 39k.
  73. enum { eDirectoryFanOut = 64 };
  74. void LokClose();
  75. ULONG DoSeekForKeyBuf( const CKeyBuf & key,
  76. CDirectoryKey ** aKeys,
  77. ULONG low,
  78. ULONG cKeys );
  79. void GrowIfNeeded( unsigned cbToGrow );
  80. void LokWriteKey( const CKeyBuf & key,
  81. BitOffset & bitOffset );
  82. void ReadIn( BOOL fWrite = FALSE );
  83. void ReMapIfNeeded( void );
  84. WORKID _objectId;
  85. unsigned _cKeys;
  86. unsigned _cLevel2Keys;
  87. XArray<CDirectoryKey *> _aKeys;
  88. XArray<CDirectoryKey *> _aLevel2Keys;
  89. CiStorage & _storage;
  90. BOOL _fReadOnly;
  91. ULONG * _pcKeys; // array of 2 ulong counts
  92. BYTE * _pbCurrent; // current end of the file
  93. XPtr<PMmStream> _stream;
  94. CMmStreamBuf _streamBuf;
  95. #if (CIDBG == 1)
  96. CKeyBuf _keyLast; // Last key retrieved from directory
  97. BitOffset _bitOffLastAdded; // Bit offset of the last key added
  98. #endif // CIDBG == 1
  99. };