2
0

block.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*-------------------------------------------------------------------------
  2. *
  3. * block.h
  4. * POSTGRES disk block definitions.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/storage/block.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef BLOCK_H
  15. #define BLOCK_H
  16. /*
  17. * BlockNumber:
  18. *
  19. * each data file (heap or index) is divided into postgres disk blocks
  20. * (which may be thought of as the unit of i/o -- a postgres buffer
  21. * contains exactly one disk block). the blocks are numbered
  22. * sequentially, 0 to 0xFFFFFFFE.
  23. *
  24. * InvalidBlockNumber is the same thing as P_NEW in bufmgr.h.
  25. *
  26. * the access methods, the buffer manager and the storage manager are
  27. * more or less the only pieces of code that should be accessing disk
  28. * blocks directly.
  29. */
  30. typedef uint32 BlockNumber;
  31. #define InvalidBlockNumber ((BlockNumber) 0xFFFFFFFF)
  32. #define MaxBlockNumber ((BlockNumber) 0xFFFFFFFE)
  33. /*
  34. * BlockId:
  35. *
  36. * this is a storage type for BlockNumber. in other words, this type
  37. * is used for on-disk structures (e.g., in HeapTupleData) whereas
  38. * BlockNumber is the type on which calculations are performed (e.g.,
  39. * in access method code).
  40. *
  41. * there doesn't appear to be any reason to have separate types except
  42. * for the fact that BlockIds can be SHORTALIGN'd (and therefore any
  43. * structures that contains them, such as ItemPointerData, can also be
  44. * SHORTALIGN'd). this is an important consideration for reducing the
  45. * space requirements of the line pointer (ItemIdData) array on each
  46. * page and the header of each heap or index tuple, so it doesn't seem
  47. * wise to change this without good reason.
  48. */
  49. typedef struct BlockIdData
  50. {
  51. uint16 bi_hi;
  52. uint16 bi_lo;
  53. } BlockIdData;
  54. typedef BlockIdData *BlockId; /* block identifier */
  55. /* ----------------
  56. * support macros
  57. * ----------------
  58. */
  59. /*
  60. * BlockNumberIsValid
  61. * True iff blockNumber is valid.
  62. */
  63. #define BlockNumberIsValid(blockNumber) \
  64. ((BlockNumber) (blockNumber) != InvalidBlockNumber)
  65. /*
  66. * BlockIdIsValid
  67. * True iff the block identifier is valid.
  68. */
  69. #define BlockIdIsValid(blockId) \
  70. PointerIsValid(blockId)
  71. /*
  72. * BlockIdSet
  73. * Sets a block identifier to the specified value.
  74. */
  75. #define BlockIdSet(blockId, blockNumber) \
  76. ( \
  77. (blockId)->bi_hi = (blockNumber) >> 16, \
  78. (blockId)->bi_lo = (blockNumber) & 0xffff \
  79. )
  80. /*
  81. * BlockIdCopy
  82. * Copy a block identifier.
  83. */
  84. #define BlockIdCopy(toBlockId, fromBlockId) \
  85. ( \
  86. (toBlockId)->bi_hi = (fromBlockId)->bi_hi, \
  87. (toBlockId)->bi_lo = (fromBlockId)->bi_lo \
  88. )
  89. /*
  90. * BlockIdEquals
  91. * Check for block number equality.
  92. */
  93. #define BlockIdEquals(blockId1, blockId2) \
  94. ((blockId1)->bi_hi == (blockId2)->bi_hi && \
  95. (blockId1)->bi_lo == (blockId2)->bi_lo)
  96. /*
  97. * BlockIdGetBlockNumber
  98. * Retrieve the block number from a block identifier.
  99. */
  100. #define BlockIdGetBlockNumber(blockId) \
  101. ((((BlockNumber) (blockId)->bi_hi) << 16) | ((BlockNumber) (blockId)->bi_lo))
  102. #endif /* BLOCK_H */