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.

282 lines
11 KiB

  1. #ifndef NODE_INCLUDED
  2. #define NODE_INCLUDED
  3. typedef SRID ITEM;
  4. #define citemMost 300
  5. #define citemMax 301
  6. #define citagSonMax ctagMax
  7. #define cbFOPNoSon ( sizeof(TAG) + 1 + 1 ) // 6
  8. #define cbFOPOneSon ( cbFOPNoSon + 1 + 1 ) // 8
  9. /* most bytes available for page subtree not including FOP son
  10. /**/
  11. #define cbAvailMost ( cbPage - sizeof(PGHDR) - sizeof(PGTRLR) - cbFOPNoSon - 1 )
  12. // 4096 - 28 - 4 - 6 - 1 /* for FOP son count */ = 4057
  13. /* most bytes for node key and data, backlink included.
  14. /**/
  15. #define cbNodeMost ( cbAvailMost - 1 - 1 - sizeof(TAG) - sizeof(SRID) )
  16. // 4057 - 1 /* FOP son */ - 1 - 4 - 4 = 4047
  17. /* bytes for Null key and no data, backlink excluded.
  18. /**/
  19. #define cbNullKeyData ( cbFOPOneSon - cbFOPNoSon + sizeof(TAG) + 1 + 1 )
  20. // 8 - 6 + 4 + 1 + 1 = 8
  21. // cbNullKeyData is for inserted nodes and
  22. // does not have backlink
  23. /* most bytes for long value chunk with 4 byte key.
  24. /**/
  25. #define cbChunkMost ( cbNodeMost - cbNullKeyData - sizeof(LONG) )
  26. // 4047 - 8 /* node null key data */ - 4 /* key */ = 4035
  27. #define cbItemNodeMost ( 1 + 1 + JET_cbKeyMost + 0 + 0 + sizeof(SRID) + (citemMax * sizeof(SRID)) )
  28. // 261 + 300 * 4 = 1461
  29. #define cbHalfItemNodeMost ( 1 + 1 + JET_cbKeyMost + 0 + 0 + sizeof(SRID) + ((((citemMax + 1) / 2) + 1 ) * sizeof(SRID)) )
  30. // 261 + 151 * 4 = 865
  31. #define cbFirstPagePointer ( 1 + sizeof(PGNO) )
  32. // node header bits
  33. #define fNDVersion 0x80
  34. #define fNDDeleted 0x40
  35. #define fNDBackLink 0x20
  36. #define fNDReserved 0x10 // Reserved for future use (formerly fNDFDPPtr)
  37. #define fNDSon 0x08
  38. #define fNDVisibleSon 0x04
  39. #define fNDFirstItem 0x02
  40. #define fNDLastItem 0x01
  41. #define FNDDeleted(b) ( (b) & fNDDeleted )
  42. #define FNDVersion(b) ( (b) & fNDVersion )
  43. #define FNDVerDel(b) ( (b) & (fNDDeleted | fNDVersion) )
  44. #define FNDBackLink(b) ( (b) & fNDBackLink )
  45. #define FNDNullSon(b) ( !( (b) & fNDSon ) )
  46. #define FNDSon(b) ( (b) & fNDSon )
  47. #define FNDReserved(b) ( (b) & fNDReserved )
  48. #define FNDFDPPtr(b) FNDReserved(b)
  49. #define FNDVisibleSons(b) ( (b) & fNDVisibleSon )
  50. #define FNDInvisibleSons(b) ( !( (b) & fNDVisibleSon ) )
  51. #define FNDFirstItem(b) ( (b) & fNDFirstItem )
  52. #define FNDLastItem(b) ( (b) & fNDLastItem )
  53. // node flag toggle macros
  54. #define NDSetDeleted(b) ( (b) |= fNDDeleted )
  55. #define NDResetDeleted(b) ( (b) &= ~fNDDeleted )
  56. #define NDSetVersion(b) ( (b) |= fNDVersion )
  57. #define NDResetVersion(b) ( (b) &= ~fNDVersion )
  58. #define NDSetSon(b) ( (b) |= fNDSon )
  59. #define NDResetSon(b) ( (b) &= ~fNDSon )
  60. #define NDSetKeyLength(pb, cb) ( *(pb) = cb )
  61. #define NDSetVisibleSons(b) ( (b) |= fNDVisibleSon )
  62. #define NDSetInvisibleSons(b) ( (b) &= ~fNDVisibleSon )
  63. #define NDSetBackLink(b) ( (b) |= fNDBackLink )
  64. #define NDResetBackLink(b) ( (b) &= ~fNDBackLink )
  65. #define NDSetFirstItem(b) ( (b) |= fNDFirstItem )
  66. #define NDResetFirstItem(b) ( (b) &= ~fNDFirstItem )
  67. #define NDSetLastItem(b) ( (b) |= fNDLastItem )
  68. #define NDResetLastItem(b) ( (b) &= ~fNDLastItem )
  69. // macros
  70. #define StNDKey(pb) ( (pb) + 1 )
  71. #define PbNDKeyCb(pb) ( (pb) + 1 )
  72. #define PbNDKey(pb) ( (pb) + 2 )
  73. #define CbNDKey(pb) ( *( (pb) + 1 ) )
  74. #define PbNDSonTable(pb) ( (pb) + 1 + 1 + *(pb + 1) )
  75. #define PbNDSon(pb) ( (BYTE *)PbNDSonTable(pb) + 1 )
  76. #define CbNDSonTable(pbSonTable) ( *(BYTE *)(pbSonTable) )
  77. #define CbNDSon(pbNode) \
  78. ( FNDNullSon(*(pbNode)) ? 0 : *PbNDSonTable(pbNode) )
  79. #define PgnoNDOfPbSon(pb) ( *(PGNO UNALIGNED *)PbNDSon(pb) )
  80. #define FNDNonIntrinsicSons(pbNode) ( !FNDNullSon(*pbNode) && ( FNDVisibleSons(*pbNode) || CbNDSon(pbNode) > 1 ) )
  81. #define FNDIntrinsicSons(pbNode) ( !FNDNullSon(*pbNode) && !FNDVisibleSons(*pbNode) && CbNDSon(pbNode) == 1 )
  82. #define PbNDBackLink(pb) \
  83. ( PbNDSonTable(pb) + ( FNDNullSon( *(pb) ) ? 0 : \
  84. ( ( ( *PbNDSonTable(pb) == 1 ) && FNDInvisibleSons( *(pb) ) ) ? \
  85. sizeof(PGNO) + 1 : *PbNDSonTable(pb) + 1 ) ) )
  86. #define PbNDData(pb) \
  87. ( PbNDBackLink(pb) + ( FNDBackLink( *(pb) ) ? sizeof(SRID) : 0 ) )
  88. #define CbNDData( pbNode, cbNode ) ( (cbNode) - (INT)( PbNDData(pbNode) - (pbNode) ) )
  89. #define ItagSonOfPbND(pb,ib) ( PbNDSonTable(pb)[ib] )
  90. #define ItagSonOfPbSonTable(pb,ib) ( pb[ib+1] )
  91. #define ItagSonOfPbSon(pb,ib) ( pb[ib] )
  92. #define NDGet( pfucb, itagT ) PMGet( &(pfucb)->ssib, itagT )
  93. #ifdef DEBUG
  94. #define AssertNDIntrinsicSon( pbNode, cbNode ) \
  95. { \
  96. Assert( ( PbNDData( (pbNode) )) - (pbNode) <= \
  97. (INT)(cbNode) ); \
  98. Assert( ( PgnoNDOfPbSon( pbNode ) & 0xff000000 ) == 0 ); \
  99. }
  100. #define AssertNDGet( pfucb, itagT ) \
  101. { \
  102. AssertPMGet( &(pfucb)->ssib, itagT ); \
  103. }
  104. VOID AssertNDGetKey( FUCB *pfucb, INT itag );
  105. VOID AssertNDGetNode( FUCB *pfucb, INT itag );
  106. #else
  107. #define AssertNDIntrinsicSon( pbNode, cbNode )
  108. #define AssertNDGet( pfucb, itag )
  109. #define AssertNDGetKey( pfucb, itag )
  110. #define AssertNDGetNode( pfucb, itag )
  111. #endif
  112. #define NDIGetBookmarkFromCSR( pfucb, pcsr, psrid ) \
  113. { \
  114. if ( FNDBackLink( *((pfucb)->ssib.line.pb) ) ) \
  115. { \
  116. *(SRID *)(psrid) = *(SRID UNALIGNED *)PbNDBackLink((pfucb)->ssib.line.pb); \
  117. Assert( PgnoOfPn(*(SRID *)psrid) != pgnoNull ); \
  118. } \
  119. else \
  120. { \
  121. *(psrid) = SridOfPgnoItag( (pcsr)->pgno, (pcsr)->itag ); \
  122. } \
  123. }
  124. #define NDIGetBookmark( pfucb, psrid ) NDIGetBookmarkFromCSR( pfucb, \
  125. PcsrCurrent( pfucb ), \
  126. psrid )
  127. #define NDGetBookmark( pfucb, psrid ) NDGetBookmarkFromCSR( pfucb, \
  128. PcsrCurrent( pfucb ), \
  129. psrid )
  130. /* item bits and macros.
  131. /**/
  132. #define fNDItemDelete 0x40000000
  133. #define fNDItemVersion 0x80000000
  134. #define FNDItemVersion( item ) ( (item) & fNDItemVersion )
  135. #define ITEMSetVersion( item ) ( (item) |= fNDItemVersion )
  136. #define ITEMResetVersion( item ) ( (item) &= ~(fNDItemVersion) )
  137. #define FNDItemDelete( item ) ( (item) & fNDItemDelete )
  138. #define ITEMSetDelete( item ) ( (item) |= fNDItemDelete )
  139. #define ITEMResetDelete( item ) ( (item) &= ~(fNDItemDelete) )
  140. #define BmNDOfItem( item ) ((item) & ~( fNDItemVersion | fNDItemDelete ) )
  141. #define CitemND(pb, cb) \
  142. ( ( cb - ( PbNDData(pb) - pb ) ) / sizeof(ITEM) )
  143. #define CitemNDData(pb, cb, pbData) \
  144. ( ( cb - ( (pbData) - pb ) ) / sizeof(ITEM) )
  145. #define FNDSingleItem( pfucb ) \
  146. ( ( (pfucb)->ssib.line.cb - \
  147. ( PbNDData( (pfucb)->ssib.line.pb ) - (pfucb)->ssib.line.pb ) ) \
  148. / sizeof(ITEM) == 1 )
  149. // LSridCmp
  150. // ========================================================================
  151. // LONG LSridCmp( SRID *psrid1, SRID *psrid2 )
  152. //
  153. // Compare the srids.
  154. //
  155. // PARAMETERS psrid1 pointer to a item;
  156. // psrid2 pointer to a item;
  157. //
  158. // RETURNS < 0, then the first srid is less than the second.
  159. // = 0, then the first srid is equal to the the second.
  160. // > 0, then the first srid is greater than the second.
  161. //-
  162. #define LSridCmp( srid1, srid2 ) \
  163. ((LONG) ((SRID) BmNDOfItem( srid1 ) - (SRID) BmNDOfItem( srid2 )))
  164. #ifdef DEBUG
  165. VOID NDCheckTreeInPage( PAGE *ppage, INT itagFather );
  166. #define NDCheckPage( pssib ) NDCheckTreeInPage( (pssib)->pbf->ppage, itagFOP )
  167. #else
  168. #define NDCheckTreeInPage( ppage, itagFather )
  169. #define NDCheckPage( pssib )
  170. #endif
  171. #define NDGetKey( pfucb ) \
  172. { \
  173. AssertNDGet( pfucb, PcsrCurrent(pfucb)->itag ); \
  174. (pfucb)->keyNode.cb = (INT)*((BYTE *)(pfucb)->ssib.line.pb + 1); \
  175. (pfucb)->keyNode.pb = ( (BYTE *)(pfucb)->ssib.line.pb + 2 ); \
  176. }
  177. // node prototypes
  178. ERR ErrNDNewPage( FUCB *pfucb, PGNO pgno, PGNO pgnoFDP, PGTYP pgtyp, BOOL fVisibleSons );
  179. ERR ErrNDSetNodeHeader( FUCB *pfucb, BYTE bHeader );
  180. VOID NDSeekSon( FUCB *pfucb, CSR *pcsr, KEY const *pkey, INT fFlags );
  181. VOID NDMoveFirstSon( FUCB *pfucb, CSR *pcsr );
  182. VOID NDMoveLastSon( FUCB *pfucb, CSR *pcsr );
  183. ERR ErrNDMoveSon( FUCB *pfucb, CSR *pcsr );
  184. VOID NDGetNode( FUCB *pfucb );
  185. VOID NDGetBookmarkFromCSR( FUCB *pfucb, CSR *pcsr, SRID *psrid );
  186. ERR ErrNDInsertNode( FUCB *pfucb, KEY const *pkey, LINE *plineData, INT fHeader, INT fFlags );
  187. ERR ErrNDDeleteNode( FUCB *pfucb );
  188. ERR ErrNDReplaceWithLink( FUCB *pfucb, SRID sridLink );
  189. ERR ErrNDDeleteInvisibleSon(
  190. FUCB *pfucb,
  191. RMPAGE *prmpage,
  192. BOOL fCheckRemoveParentOnly,
  193. BOOL *pfRmParent );
  194. ERR ErrNDFlagDeleteNode( FUCB *pfucb, INT fFlags );
  195. ERR ErrNDReplaceNodeData( FUCB *pfucb, LINE *pline, INT fFlags );
  196. VOID NDResetNodeVersion( FUCB *pfucb );
  197. VOID NDDeferResetNodeVersion( FUCB *pfucb );
  198. VOID NDResetNodeDeleted( FUCB *pfucb );
  199. ERR ErrNDGetItem( FUCB *pfucb );
  200. ERR ErrNDFirstItem( FUCB *pfucb );
  201. ERR ErrNDLastItem( FUCB *pfucb );
  202. ERR ErrNDNextItem( FUCB *pfucb );
  203. ERR ErrNDPrevItem( FUCB *pfucb );
  204. ERR ErrNDSeekItem( FUCB *pfucb, SRID srid );
  205. #define fNDCitemAll (1<<0)
  206. #define fNDCitemFromIsrid (1<<1)
  207. #define fNDCitemToIsrid (1<<2)
  208. INT CitemNDThere( FUCB *pfucb, BYTE fNDCitem, INT isrid );
  209. ERR ErrNDInsertItemList( FUCB *pfucb, KEY *pkey, SRID srid, INT fFlags );
  210. ERR ErrNDInsertItem( FUCB *pfucb, ITEM item, INT fFlags );
  211. ERR ErrNDInsertItems( FUCB *pfucb, ITEM *rgitem, INT citem );
  212. ERR ErrNDFlagInsertItem( FUCB *pfucb );
  213. ERR ErrNDDeleteItem( FUCB *pfucb );
  214. ERR ErrNDFlagDeleteItem( FUCB *pfucb, BOOL fNoMPLRegister );
  215. VOID NDSetItemDelete( FUCB *pfucb );
  216. VOID NDResetItemVersion( FUCB *pfucb );
  217. VOID NDResetItemDelete( FUCB *pfucb );
  218. ERR ErrNDSplitItemListNode( FUCB *pfucb, INT fFlags );
  219. ERR ErrNDDelta( FUCB *pfucb, LONG lDelta, INT fFlags );
  220. ERR ErrNDDeltaNoCheckLog( FUCB *pfucb, LONG lDelta, INT fFlags );
  221. ERR ErrNDLockRecord( FUCB *pfucb );
  222. ERR ErrNDInsertWithBackLink( FUCB *pfucb, BYTE bFlags, KEY const *pkey,
  223. LINE *plineSonTable, SRID sridBackLink, LINE *plineData );
  224. VOID NDGetBackLink( FUCB *pfucb, PGNO *ppgno, INT *pitag );
  225. ERR ErrNDExpungeBackLink( FUCB *pfucb );
  226. ERR ErrNDExpungeLinkCommit( FUCB *pfucb, FUCB *pfucbSrc );
  227. VOID NDGetItagFatherIbSon( INT *pitagFather, INT *pibSon, PAGE *ppage, INT itag );
  228. #define FNDFreePageSpace( pssib, cbT ) \
  229. ( ((INT)(pssib)->pbf->ppage->cbFree) < cbT ? \
  230. fFalse : \
  231. FVERCheckUncommittedFreedSpace( (pssib)->pbf, cbT ) )
  232. INT CbNDFreePageSpace( BF *pbf );
  233. BOOL FNDMaxKeyInPage( FUCB *pfucb );
  234. #endif // NODE_INCLUDED