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.

264 lines
9.7 KiB

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