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.

185 lines
5.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1992.
  5. //
  6. // File: PropIter.cxx
  7. //
  8. // Contents: Iterator for property store.
  9. //
  10. // Classes: CPropertyStoreWids
  11. //
  12. // History: 27-Dec-19 KyleP Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include <prpstmgr.hxx>
  18. #include <propobj.hxx>
  19. #include <propiter.hxx>
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Member: CPropertyStoreWids::CPropertyStoreWids, public
  23. //
  24. // Synopsis: Constructor
  25. //
  26. // Arguments: [propstore] -- Property store manager.
  27. //
  28. // History: 04-Jan-96 KyleP Created.
  29. // 22-Oct-97 KrishnaN Modified to take the propstore mgr
  30. // and iterate through its primary store.
  31. //
  32. //----------------------------------------------------------------------------
  33. CPropertyStoreWids::CPropertyStoreWids( CPropStoreManager & propstoremgr )
  34. : _propstore( propstoremgr.GetPrimaryStore() ),
  35. _Borrowed( propstoremgr.GetPrimaryStore()._xPhysStore.GetReference(),
  36. propstoremgr.GetPrimaryStore()._PropStoreInfo.RecordsPerPage(),
  37. propstoremgr.GetPrimaryStore()._PropStoreInfo.RecordSize() )
  38. {
  39. Init(propstoremgr.GetPrimaryStore());
  40. }
  41. //+---------------------------------------------------------------------------
  42. //
  43. // Member: CPropertyStoreWids::CPropertyStoreWids, public
  44. //
  45. // Synopsis: Constructor
  46. //
  47. // Arguments: [propstore] -- Property store.
  48. //
  49. // History: 04-Jan-96 KyleP Created.
  50. // 22-Oct-97 KrishnaN Modified to take the propstore mgr
  51. // and iterate through its primary store.
  52. //
  53. //----------------------------------------------------------------------------
  54. CPropertyStoreWids::CPropertyStoreWids( CPropertyStore & propstore )
  55. : _propstore( propstore ),
  56. _Borrowed( propstore._xPhysStore.GetReference(),
  57. propstore._PropStoreInfo.RecordsPerPage(),
  58. propstore._PropStoreInfo.RecordSize() )
  59. {
  60. Init(propstore);
  61. }
  62. //+---------------------------------------------------------------------------
  63. //
  64. // Member: CPropertyStoreWids::Init, private
  65. //
  66. // Synopsis: Constructor helper.
  67. //
  68. // Arguments: [propstore] -- Property store.
  69. //
  70. // History: 20-Nov-97 KrishnaN Created.
  71. //
  72. //----------------------------------------------------------------------------
  73. void CPropertyStoreWids::Init(CPropertyStore& propstore)
  74. {
  75. if ( _propstore.MaxWorkId() > 0 )
  76. {
  77. _Borrowed.Set( 1 );
  78. _wid = 1;
  79. _cRecPerPage = _propstore.RecordsPerPage();
  80. if ( !_Borrowed.Get()->IsTopLevel() )
  81. _wid = NextWorkId();
  82. }
  83. else
  84. _wid = widInvalid;
  85. }
  86. //+---------------------------------------------------------------------------
  87. //
  88. // Member: CPropertyStoreWids::~CPropertyStoreWids, public
  89. //
  90. // Synopsis: Destructor
  91. //
  92. // History: 04-Jan-96 KyleP Created.
  93. //
  94. //----------------------------------------------------------------------------
  95. CPropertyStoreWids::~CPropertyStoreWids()
  96. {
  97. }
  98. //+---------------------------------------------------------------------------
  99. //
  100. // Member: CPropertyStoreWids::NextWorkId, public
  101. //
  102. // Synopsis: Advances iterator to next in-use workid.
  103. //
  104. // Returns: Next workid, or widInvalid if at end.
  105. //
  106. // History: 04-Jan-96 KyleP Created.
  107. //
  108. //----------------------------------------------------------------------------
  109. WORKID CPropertyStoreWids::NextWorkId()
  110. {
  111. CReadAccess lock( _propstore.GetReadWriteAccess() );
  112. return LokNextWorkId();
  113. }
  114. //+---------------------------------------------------------------------------
  115. //
  116. // Member: CPropertyStoreWids::LokNextWorkId, public
  117. //
  118. // Synopsis: Advances iterator to next in-use workid, assumes at least
  119. // a read lock is already grabbed.
  120. //
  121. // Returns: Next workid, or widInvalid if at end.
  122. //
  123. // History: 23-Feb-96 dlee created from NextWorkId
  124. //
  125. //----------------------------------------------------------------------------
  126. WORKID CPropertyStoreWids::LokNextWorkId()
  127. {
  128. Win4Assert( _wid != widInvalid );
  129. while ( TRUE )
  130. {
  131. COnDiskPropertyRecord const * pRec = _Borrowed.Get();
  132. if ( pRec->IsValidType() && pRec->IsValidLength(_wid, _cRecPerPage) )
  133. {
  134. _wid = _wid + _Borrowed.Get()->CountRecords();
  135. }
  136. else
  137. {
  138. ciDebugOut(( DEB_ERROR, "Wid (0x%X) pRec (0x%X) has bad length (%d)\n",
  139. _wid, pRec, pRec->CountRecords() ));
  140. Win4Assert( !"Corruption in PropertyStore" );
  141. // Try to find the next valid top level record.
  142. _wid++;
  143. }
  144. if ( _wid > _propstore.MaxWorkId() )
  145. {
  146. _Borrowed.Release();
  147. _wid = widInvalid;
  148. break;
  149. }
  150. //
  151. // Make sure we acquire new buffer before releasing old. Keeps us from
  152. // unmapping page.
  153. //
  154. CBorrowed temp( _Borrowed );
  155. _Borrowed.Set( _wid );
  156. if ( _Borrowed.Get()->IsTopLevel() )
  157. break;
  158. }
  159. return _wid;
  160. }