1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) International Business Machines Corp., 2000-2004
11 * JFS B+-tree (dtree and xtree) common definitions
15 * basic btree page - btpage
18 s64 next; right sibling bn
19 s64 prev; left sibling bn
22 u8 rsrvd[7]; type specific
23 s64 self; self address
29 #define BT_TYPE 0x07 /* B+-tree index */
30 #define BT_ROOT 0x01 /* root page */
31 #define BT_LEAF 0x02 /* leaf page */
32 #define BT_INTERNAL 0x04 /* internal page */
33 #define BT_RIGHTMOST 0x10 /* rightmost page */
34 #define BT_LEFTMOST 0x20 /* leftmost page */
35 #define BT_SWAPPED 0x80 /* used by fsck for endian swapping */
37 /* btorder (in inode) */
38 #define BT_RANDOM 0x0000
39 #define BT_SEQUENTIAL 0x0001
40 #define BT_LOOKUP 0x0010
41 #define BT_INSERT 0x0020
42 #define BT_DELETE 0x0040
45 * btree page buffer cache access
47 #define BT_IS_ROOT(MP) (((MP)->xflag & COMMIT_PAGE) == 0)
49 /* get page from buffer page */
50 #define BT_PAGE(IP, MP, TYPE, ROOT)\
51 (BT_IS_ROOT(MP) ? (TYPE *)&JFS_IP(IP)->ROOT : (TYPE *)(MP)->data)
53 /* get the page buffer and the page for specified block address */
54 #define BT_GETPAGE(IP, BN, MP, TYPE, SIZE, P, RC, ROOT)\
58 MP = (struct metapage *)&JFS_IP(IP)->bxflag;\
59 P = (TYPE *)&JFS_IP(IP)->ROOT;\
64 MP = read_metapage((IP), BN, SIZE, 1);\
70 jfs_err("bread failed!");\
76 #define BT_MARK_DIRTY(MP, IP)\
79 mark_inode_dirty(IP);\
81 mark_metapage_dirty(MP);\
84 /* put the page buffer */
85 #define BT_PUTPAGE(MP)\
87 if (! BT_IS_ROOT(MP)) \
88 release_metapage(MP); \
93 * btree traversal stack
95 * record the path traversed during the search;
96 * top frame record the leaf page/entry selected.
98 struct btframe { /* stack frame */
101 s16 lastindex; /* 2: unused */
102 struct metapage *mp; /* 4/8: */
108 struct btframe stack[MAXTREEHEIGHT];
111 #define BT_CLR(btstack)\
112 (btstack)->top = (btstack)->stack
114 #define BT_STACK_FULL(btstack)\
115 ( (btstack)->top == &((btstack)->stack[MAXTREEHEIGHT-1]))
117 #define BT_PUSH(BTSTACK, BN, INDEX)\
119 assert(!BT_STACK_FULL(BTSTACK));\
120 (BTSTACK)->top->bn = BN;\
121 (BTSTACK)->top->index = INDEX;\
125 #define BT_POP(btstack)\
126 ( (btstack)->top == (btstack)->stack ? NULL : --(btstack)->top )
128 #define BT_STACK(btstack)\
129 ( (btstack)->top == (btstack)->stack ? NULL : (btstack)->top )
131 static inline void BT_STACK_DUMP(struct btstack *btstack)
134 printk("btstack dump:\n");
135 for (i = 0; i < MAXTREEHEIGHT; i++)
136 printk(KERN_ERR "bn = %Lx, index = %d\n",
137 (long long)btstack->stack[i].bn,
138 btstack->stack[i].index);
141 /* retrieve search results */
142 #define BT_GETSEARCH(IP, LEAF, BN, MP, TYPE, P, INDEX, ROOT)\
147 P = (TYPE *)MP->data;\
149 P = (TYPE *)&JFS_IP(IP)->ROOT;\
150 INDEX = (LEAF)->index;\
153 /* put the page buffer of search */
154 #define BT_PUTSEARCH(BTSTACK)\
156 if (! BT_IS_ROOT((BTSTACK)->top->mp))\
157 release_metapage((BTSTACK)->top->mp);\
159 #endif /* _H_JFS_BTREE */