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.

150 lines
4.4 KiB

20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
  1. /**********************************************************************
  2. File-based list utilities
  3. (c) 1995 Innobase Oy
  4. Created 11/28/1995 Heikki Tuuri
  5. ***********************************************************************/
  6. #include "fut0fut.h"
  7. #include "mtr0log.h"
  8. #include "buf0buf.h"
  9. /* We define the field offsets of a node for the list */
  10. #define FLST_PREV 0 /* 6-byte address of the previous list element;
  11. the page part of address is FIL_NULL, if no
  12. previous element */
  13. #define FLST_NEXT FIL_ADDR_SIZE /* 6-byte address of the next
  14. list element; the page part of address
  15. is FIL_NULL, if no next element */
  16. /* We define the field offsets of a base node for the list */
  17. #define FLST_LEN 0 /* 32-bit list length field */
  18. #define FLST_FIRST 4 /* 6-byte address of the first element
  19. of the list; undefined if empty list */
  20. #define FLST_LAST (4 + FIL_ADDR_SIZE) /* 6-byte address of the
  21. last element of the list; undefined
  22. if empty list */
  23. /************************************************************************
  24. Writes a file address. */
  25. UNIV_INLINE
  26. void
  27. flst_write_addr(
  28. /*============*/
  29. fil_faddr_t* faddr, /* in: pointer to file faddress */
  30. fil_addr_t addr, /* in: file address */
  31. mtr_t* mtr) /* in: mini-transaction handle */
  32. {
  33. ut_ad(faddr && mtr);
  34. ut_ad(mtr_memo_contains_page(mtr, faddr, MTR_MEMO_PAGE_X_FIX));
  35. ut_a(addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA);
  36. ut_a(ut_align_offset(faddr, UNIV_PAGE_SIZE) >= FIL_PAGE_DATA);
  37. mlog_write_ulint(faddr + FIL_ADDR_PAGE, addr.page, MLOG_4BYTES, mtr);
  38. mlog_write_ulint(faddr + FIL_ADDR_BYTE, addr.boffset,
  39. MLOG_2BYTES, mtr);
  40. }
  41. /************************************************************************
  42. Reads a file address. */
  43. UNIV_INLINE
  44. fil_addr_t
  45. flst_read_addr(
  46. /*===========*/
  47. /* out: file address */
  48. const fil_faddr_t* faddr, /* in: pointer to file faddress */
  49. mtr_t* mtr) /* in: mini-transaction handle */
  50. {
  51. fil_addr_t addr;
  52. ut_ad(faddr && mtr);
  53. addr.page = mtr_read_ulint(faddr + FIL_ADDR_PAGE, MLOG_4BYTES, mtr);
  54. addr.boffset = mtr_read_ulint(faddr + FIL_ADDR_BYTE, MLOG_2BYTES,
  55. mtr);
  56. ut_a(addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA);
  57. ut_a(ut_align_offset(faddr, UNIV_PAGE_SIZE) >= FIL_PAGE_DATA);
  58. return(addr);
  59. }
  60. /************************************************************************
  61. Initializes a list base node. */
  62. UNIV_INLINE
  63. void
  64. flst_init(
  65. /*======*/
  66. flst_base_node_t* base, /* in: pointer to base node */
  67. mtr_t* mtr) /* in: mini-transaction handle */
  68. {
  69. ut_ad(mtr_memo_contains_page(mtr, base, MTR_MEMO_PAGE_X_FIX));
  70. mlog_write_ulint(base + FLST_LEN, 0, MLOG_4BYTES, mtr);
  71. flst_write_addr(base + FLST_FIRST, fil_addr_null, mtr);
  72. flst_write_addr(base + FLST_LAST, fil_addr_null, mtr);
  73. }
  74. /************************************************************************
  75. Gets list length. */
  76. UNIV_INLINE
  77. ulint
  78. flst_get_len(
  79. /*=========*/
  80. /* out: length */
  81. const flst_base_node_t* base, /* in: pointer to base node */
  82. mtr_t* mtr) /* in: mini-transaction handle */
  83. {
  84. return(mtr_read_ulint(base + FLST_LEN, MLOG_4BYTES, mtr));
  85. }
  86. /************************************************************************
  87. Gets list first node address. */
  88. UNIV_INLINE
  89. fil_addr_t
  90. flst_get_first(
  91. /*===========*/
  92. /* out: file address */
  93. const flst_base_node_t* base, /* in: pointer to base node */
  94. mtr_t* mtr) /* in: mini-transaction handle */
  95. {
  96. return(flst_read_addr(base + FLST_FIRST, mtr));
  97. }
  98. /************************************************************************
  99. Gets list last node address. */
  100. UNIV_INLINE
  101. fil_addr_t
  102. flst_get_last(
  103. /*==========*/
  104. /* out: file address */
  105. const flst_base_node_t* base, /* in: pointer to base node */
  106. mtr_t* mtr) /* in: mini-transaction handle */
  107. {
  108. return(flst_read_addr(base + FLST_LAST, mtr));
  109. }
  110. /************************************************************************
  111. Gets list next node address. */
  112. UNIV_INLINE
  113. fil_addr_t
  114. flst_get_next_addr(
  115. /*===============*/
  116. /* out: file address */
  117. const flst_node_t* node, /* in: pointer to node */
  118. mtr_t* mtr) /* in: mini-transaction handle */
  119. {
  120. return(flst_read_addr(node + FLST_NEXT, mtr));
  121. }
  122. /************************************************************************
  123. Gets list prev node address. */
  124. UNIV_INLINE
  125. fil_addr_t
  126. flst_get_prev_addr(
  127. /*===============*/
  128. /* out: file address */
  129. const flst_node_t* node, /* in: pointer to node */
  130. mtr_t* mtr) /* in: mini-transaction handle */
  131. {
  132. return(flst_read_addr(node + FLST_PREV, mtr));
  133. }