Windows NT 4.0 source code leak
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.

134 lines
4.1 KiB

4 years ago
  1. /*****************************************************************************
  2. * *
  3. * BTPRIV.H *
  4. * *
  5. * Copyright (C) Microsoft Corporation 1989 - 1994 *
  6. * All Rights reserved. *
  7. * *
  8. *****************************************************************************/
  9. #ifndef HC_H
  10. #include "hc.h"
  11. #endif
  12. // cache flags
  13. const BYTE CACHE_DIRTY = 1; // means block has been modified in memory
  14. const BYTE CACHE_VALID = 4; // means block is in memory
  15. /***************************************************************************\
  16. *
  17. * Macros
  18. *
  19. \***************************************************************************/
  20. // Get the real size of a cache block
  21. #define CbCacheBlock(qbthr) \
  22. (sizeof(CACHE_BLOCK) - sizeof(DISK_BLOCK) + (qbthr)->bth.cbBlock)
  23. // convert a BK into a file offset
  24. #define LifFromBk(bk, qbthr) \
  25. ((int) (bk) * (int) (qbthr)->bth.cbBlock + (int) sizeof(BTH))
  26. // get a pointer to the cache block cached for the given level
  27. #define QCacheBlock(qbthr, wLevel) \
  28. ((PCACHE) ((qbthr) ->pCache + (wLevel) * CbCacheBlock(qbthr)))
  29. // get and set prev and next BK (defined for leaf blocks only)
  30. #define BkPrev(pcache) *(BK *) ((pcache)->db.rgbBlock)
  31. #define BkNext(pcache) *(((BK *) ((pcache)->db.rgbBlock)) + 1)
  32. #define SetBkPrev(pcache, bk) (BkPrev(pcache) = (BK) bk)
  33. #define SetBkNext(pcache, bk) (BkNext(pcache) = (BK) bk)
  34. // For btree map functions: returns byte number of x-th btree map record
  35. #define LcbFromBk(x) (sizeof(BK) + x * sizeof(MAPREC))
  36. /***************************************************************************\
  37. *
  38. * Types
  39. *
  40. \***************************************************************************/
  41. // In-memory struct referring to a btree.
  42. /*
  43. Btree leaf or internal node. Keys and records live in rgbBlock[].
  44. See btree.doc for details.
  45. */
  46. // REVIEW: change to 32-bit integer for alignment?
  47. typedef struct {
  48. INT16 cbSlack; // unused bytes in block
  49. INT16 cKeys; // count of keys in block
  50. BYTE rgbBlock[1]; // the block (real size cbBlock - 4)
  51. } DISK_BLOCK;
  52. // Btree node as it exists in the in-memory cache.
  53. // REVIEW: bFlags has been changed to 32-bit values for alignment
  54. typedef struct {
  55. DWORD bk; // IDs which block is cached
  56. DWORD bFlags; // dirty, cache valid
  57. DISK_BLOCK db;
  58. } CACHE_BLOCK, *PCACHE;
  59. // One record of a btree map.
  60. typedef struct { // One record of a btree map {
  61. LONG cPreviousKeys; // total # of keys in previous blocks
  62. BK bk; // The block number
  63. } MAPREC, *QMAPREC;
  64. /*
  65. Auxiliary index of btree leaves.
  66. Used for indexing a given % of the way into a btree.
  67. */
  68. typedef struct {
  69. INT16 cTotalBk;
  70. MAPREC table[1]; // sorted by MAPREC's cPreviousKeys field
  71. } MAPBT, *QMAPBT; // and is in-order list of leaf nodes
  72. /***************************************************************************\
  73. *
  74. * Function Prototypes
  75. *
  76. \***************************************************************************/
  77. int STDCALL CbSizeKey(KEY, QBTHR, BOOL);
  78. int STDCALL CbSizeRec(void*, QBTHR);
  79. BOOL STDCALL FReadBlock(PCACHE, QBTHR);
  80. PCACHE STDCALL QFromBk(DWORD, int, QBTHR);
  81. RC_TYPE STDCALL RcWriteBlock(PCACHE, QBTHR);
  82. int STDCALL WCmpKey(KEY, KEY, KT);
  83. RC_TYPE STDCALL RcFlushCache(QBTHR);
  84. // KT specific routines
  85. RC_TYPE STDCALL RcScanLeaf(BK bk, KEY key, int wLevel, QBTHR qbthr, void* qRec, QBTPOS qbtpos);
  86. BK STDCALL BkScanInternal(BK bk, KEY key, int wLevel, QBTHR qbthr, int* piKey);
  87. BK STDCALL BkScanSzInternal(BK, KEY, int, QBTHR, int*);
  88. RC_TYPE STDCALL RcScanSzLeaf(BK, KEY, int, QBTHR, void*, QBTPOS);
  89. BK STDCALL BkScanLInternal(BK, KEY, int, QBTHR, int*);
  90. RC_TYPE STDCALL RcScanLLeaf(BK, KEY, int, QBTHR, void*, QBTPOS);
  91. BK STDCALL BkScanSziInternal(BK, KEY, int, QBTHR, int*);
  92. RC_TYPE STDCALL RcScanSziLeaf(BK, KEY, int, QBTHR, void*, QBTPOS);
  93. BK STDCALL BkScanSziScandInternal(BK, KEY, int, QBTHR, int*);
  94. RC_TYPE STDCALL RcScanSziScandLeaf(BK, KEY, int, QBTHR, void*, QBTPOS);
  95. BK STDCALL BkScanSzNLSInternal(BK bk, KEY key, int wLevel, QBTHR qbthr, int* piKey);
  96. RC_TYPE STDCALL RcScanSzNLSLeaf(BK, KEY, int, QBTHR, void*, QBTPOS);
  97. DWORD STDCALL BkAlloc(QBTHR qbthr);