| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 1995, 2026, Oracle and/or its affiliates. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify it under |
| 6 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/** @file include/fut0lst.ic |
| 29 |
File-based list utilities |
| 30 |
|
| 31 |
Created 11/28/1995 Heikki Tuuri |
| 32 |
***********************************************************************/ |
| 33 |
|
| 34 |
#include "buf0buf.h" |
| 35 |
#include "fut0fut.h" |
| 36 |
#include "mtr0log.h" |
| 37 |
|
| 38 |
/* We define the field offsets of a node for the list */ |
| 39 |
/** 6-byte address of the previous list element; the page part of address is |
| 40 |
FIL_NULL, if no previous element */ |
| 41 |
constexpr uint32_t FLST_PREV = 0; |
| 42 |
/* 6-byte address of the next list element; the page part of address is |
| 43 |
FIL_NULL, if no next element */ |
| 44 |
constexpr uint32_t FLST_NEXT = FIL_ADDR_SIZE; |
| 45 |
|
| 46 |
/* We define the field offsets of a base node for the list */ |
| 47 |
/** 32-bit list length field */ |
| 48 |
constexpr uint32_t FLST_LEN = 0; |
| 49 |
/** 6-byte address of the first element of the list; undefined if empty list */ |
| 50 |
constexpr uint32_t FLST_FIRST = 4; |
| 51 |
/** 6-byte address of the last element of the list; undefined if empty list */ |
| 52 |
constexpr uint32_t FLST_LAST = 4 + FIL_ADDR_SIZE; |
| 53 |
|
| 54 |
/** Writes a file address. */ |
| 55 |
static inline void flst_write_addr( |
| 56 |
fil_faddr_t *faddr, /*!< in: pointer to file faddress */ |
| 57 |
fil_addr_t addr, /*!< in: file address */ |
| 58 |
mtr_t *mtr) /*!< in: mini-transaction handle */ |
| 59 |
{ |
| 60 |
ut_ad(faddr && mtr); |
| 61 |
ut_ad(mtr_memo_contains_page_flagged( |
| 62 |
mtr, faddr, MTR_MEMO_PAGE_X_FIX | MTR_MEMO_PAGE_SX_FIX)); |
| 63 |
ut_a(addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA); |
| 64 |
ut_a(ut_align_offset(faddr, UNIV_PAGE_SIZE) >= FIL_PAGE_DATA); |
| 65 |
|
| 66 |
mlog_write_ulint(faddr + FIL_ADDR_PAGE, addr.page, MLOG_4BYTES, mtr); |
| 67 |
mlog_write_ulint(faddr + FIL_ADDR_BYTE, addr.boffset, MLOG_2BYTES, mtr); |
| 68 |
} |
| 69 |
|
| 70 |
/** Reads a file address. |
| 71 |
@return file address */ |
| 72 |
static inline fil_addr_t flst_read_addr( |
| 73 |
const fil_faddr_t *faddr, /*!< in: pointer to file faddress */ |
| 74 |
mtr_t *mtr) /*!< in: mini-transaction handle */ |
| 75 |
{ |
| 76 |
fil_addr_t addr; |
| 77 |
|
| 78 |
ut_ad(faddr && mtr); |
| 79 |
|
| 80 |
addr.page = mtr_read_ulint(faddr + FIL_ADDR_PAGE, MLOG_4BYTES, mtr); |
| 81 |
addr.boffset = mtr_read_ulint(faddr + FIL_ADDR_BYTE, MLOG_2BYTES, mtr); |
| 82 |
ut_a(addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA); |
| 83 |
ut_a(ut_align_offset(faddr, UNIV_PAGE_SIZE) >= FIL_PAGE_DATA); |
| 84 |
return (addr); |
| 85 |
} |
| 86 |
|
| 87 |
/** Initializes a list base node. */ |
| 88 |
static inline void flst_init( |
| 89 |
flst_base_node_t *base, /*!< in: pointer to base node */ |
| 90 |
mtr_t *mtr) /*!< in: mini-transaction handle */ |
| 91 |
{ |
| 92 |
ut_ad(mtr_memo_contains_page_flagged( |
| 93 |
mtr, base, MTR_MEMO_PAGE_X_FIX | MTR_MEMO_PAGE_SX_FIX)); |
| 94 |
|
| 95 |
mlog_write_ulint(base + FLST_LEN, 0, MLOG_4BYTES, mtr); |
| 96 |
flst_write_addr(base + FLST_FIRST, fil_addr_null, mtr); |
| 97 |
flst_write_addr(base + FLST_LAST, fil_addr_null, mtr); |
| 98 |
} |
| 99 |
|
| 100 |
/** Get the length of a list. |
| 101 |
@param[in] base base node |
| 102 |
@return length */ |
| 103 |
static inline ulint flst_get_len(const flst_base_node_t *base) { |
| 104 |
return (mach_read_from_4(base + FLST_LEN)); |
| 105 |
} |
| 106 |
|
| 107 |
/** Gets list first node address. |
| 108 |
@return file address */ |
| 109 |
static inline fil_addr_t flst_get_first( |
| 110 |
const flst_base_node_t *base, /*!< in: pointer to base node */ |
| 111 |
mtr_t *mtr) /*!< in: mini-transaction handle */ |
| 112 |
{ |
| 113 |
return (flst_read_addr(base + FLST_FIRST, mtr)); |
| 114 |
} |
| 115 |
|
| 116 |
/** Gets list last node address. |
| 117 |
@return file address */ |
| 118 |
static inline fil_addr_t flst_get_last( |
| 119 |
const flst_base_node_t *base, /*!< in: pointer to base node */ |
| 120 |
mtr_t *mtr) /*!< in: mini-transaction handle */ |
| 121 |
{ |
| 122 |
return (flst_read_addr(base + FLST_LAST, mtr)); |
| 123 |
} |
| 124 |
|
| 125 |
/** Gets list next node address. |
| 126 |
@return file address */ |
| 127 |
static inline fil_addr_t flst_get_next_addr( |
| 128 |
const flst_node_t *node, /*!< in: pointer to node */ |
| 129 |
mtr_t *mtr) /*!< in: mini-transaction handle */ |
| 130 |
{ |
| 131 |
return (flst_read_addr(node + FLST_NEXT, mtr)); |
| 132 |
} |
| 133 |
|
| 134 |
/** Gets list prev node address. |
| 135 |
@return file address */ |
| 136 |
static inline fil_addr_t flst_get_prev_addr( |
| 137 |
const flst_node_t *node, /*!< in: pointer to node */ |
| 138 |
mtr_t *mtr) /*!< in: mini-transaction handle */ |
| 139 |
{ |
| 140 |
return (flst_read_addr(node + FLST_PREV, mtr)); |
| 141 |
} |