1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2021, Oracle and/or its affiliates.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8 
9 This program is also distributed 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 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 GNU General Public License, version 2.0, for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
24 
25 *****************************************************************************/
26 
27 /******************************************************************//**
28 @file include/fut0lst.h
29 File-based list utilities
30 
31 Created 11/28/1995 Heikki Tuuri
32 ***********************************************************************/
33 
34 #ifndef fut0lst_h
35 #define fut0lst_h
36 
37 #ifndef UNIV_INNOCHECKSUM
38 
39 #include "univ.i"
40 
41 #include "fil0fil.h"
42 #include "mtr0mtr.h"
43 
44 
45 /* The C 'types' of base node and list node: these should be used to
46 write self-documenting code. Of course, the sizeof macro cannot be
47 applied to these types! */
48 
49 typedef	byte	flst_base_node_t;
50 typedef	byte	flst_node_t;
51 
52 /* The physical size of a list base node in bytes */
53 #define	FLST_BASE_NODE_SIZE	(4 + 2 * FIL_ADDR_SIZE)
54 #endif /* !UNIV_INNOCHECKSUM */
55 
56 /* The physical size of a list node in bytes */
57 #define	FLST_NODE_SIZE		(2 * FIL_ADDR_SIZE)
58 
59 #if !defined UNIV_HOTBACKUP && !defined UNIV_INNOCHECKSUM
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 Adds a node as the last node in a list. */
70 void
71 flst_add_last(
72 /*==========*/
73 	flst_base_node_t*	base,	/*!< in: pointer to base node of list */
74 	flst_node_t*		node,	/*!< in: node to add */
75 	mtr_t*			mtr);	/*!< in: mini-transaction handle */
76 /********************************************************************//**
77 Adds a node as the first node in a list. */
78 void
79 flst_add_first(
80 /*===========*/
81 	flst_base_node_t*	base,	/*!< in: pointer to base node of list */
82 	flst_node_t*		node,	/*!< in: node to add */
83 	mtr_t*			mtr);	/*!< in: mini-transaction handle */
84 /********************************************************************//**
85 Inserts a node after another in a list. */
86 void
87 flst_insert_after(
88 /*==============*/
89 	flst_base_node_t*	base,	/*!< in: pointer to base node of list */
90 	flst_node_t*		node1,	/*!< in: node to insert after */
91 	flst_node_t*		node2,	/*!< in: node to add */
92 	mtr_t*			mtr);	/*!< in: mini-transaction handle */
93 /********************************************************************//**
94 Inserts a node before another in a list. */
95 void
96 flst_insert_before(
97 /*===============*/
98 	flst_base_node_t*	base,	/*!< in: pointer to base node of list */
99 	flst_node_t*		node2,	/*!< in: node to insert */
100 	flst_node_t*		node3,	/*!< in: node to insert before */
101 	mtr_t*			mtr);	/*!< in: mini-transaction handle */
102 /********************************************************************//**
103 Removes a node. */
104 void
105 flst_remove(
106 /*========*/
107 	flst_base_node_t*	base,	/*!< in: pointer to base node of list */
108 	flst_node_t*		node2,	/*!< in: node to remove */
109 	mtr_t*			mtr);	/*!< in: mini-transaction handle */
110 
111 /** Get the length of a list.
112 @param[in]	base	base node
113 @return length */
114 UNIV_INLINE
115 ulint
116 flst_get_len(
117 	const flst_base_node_t*	base);
118 /********************************************************************//**
119 Gets list first node address.
120 @return file address */
121 UNIV_INLINE
122 fil_addr_t
123 flst_get_first(
124 /*===========*/
125 	const flst_base_node_t*	base,	/*!< in: pointer to base node */
126 	mtr_t*			mtr);	/*!< in: mini-transaction handle */
127 /********************************************************************//**
128 Gets list last node address.
129 @return file address */
130 UNIV_INLINE
131 fil_addr_t
132 flst_get_last(
133 /*==========*/
134 	const flst_base_node_t*	base,	/*!< in: pointer to base node */
135 	mtr_t*			mtr);	/*!< in: mini-transaction handle */
136 /********************************************************************//**
137 Gets list next node address.
138 @return file address */
139 UNIV_INLINE
140 fil_addr_t
141 flst_get_next_addr(
142 /*===============*/
143 	const flst_node_t*	node,	/*!< in: pointer to node */
144 	mtr_t*			mtr);	/*!< in: mini-transaction handle */
145 /********************************************************************//**
146 Gets list prev node address.
147 @return file address */
148 UNIV_INLINE
149 fil_addr_t
150 flst_get_prev_addr(
151 /*===============*/
152 	const flst_node_t*	node,	/*!< in: pointer to node */
153 	mtr_t*			mtr);	/*!< in: mini-transaction handle */
154 /********************************************************************//**
155 Writes a file address. */
156 UNIV_INLINE
157 void
158 flst_write_addr(
159 /*============*/
160 	fil_faddr_t*	faddr,	/*!< in: pointer to file faddress */
161 	fil_addr_t	addr,	/*!< in: file address */
162 	mtr_t*		mtr);	/*!< in: mini-transaction handle */
163 /********************************************************************//**
164 Reads a file address.
165 @return file address */
166 UNIV_INLINE
167 fil_addr_t
168 flst_read_addr(
169 /*===========*/
170 	const fil_faddr_t*	faddr,	/*!< in: pointer to file faddress */
171 	mtr_t*			mtr);	/*!< in: mini-transaction handle */
172 /********************************************************************//**
173 Validates a file-based list.
174 @return TRUE if ok */
175 ibool
176 flst_validate(
177 /*==========*/
178 	const flst_base_node_t*	base,	/*!< in: pointer to base node of list */
179 	mtr_t*			mtr1);	/*!< in: mtr */
180 /********************************************************************//**
181 Prints info of a file-based list. */
182 void
183 flst_print(
184 /*=======*/
185 	const flst_base_node_t*	base,	/*!< in: pointer to base node of list */
186 	mtr_t*			mtr);	/*!< in: mtr */
187 
188 
189 #ifndef UNIV_NONINL
190 #include "fut0lst.ic"
191 #endif
192 
193 #endif /* !UNIV_HOTBACKUP && !UNIV_INNOCHECKSUM*/
194 
195 #endif
196