]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
7b718769 NS |
2 | * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
1da177e4 | 4 | * |
7b718769 NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
1da177e4 LT |
7 | * published by the Free Software Foundation. |
8 | * | |
7b718769 NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
1da177e4 | 13 | * |
7b718769 NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
1da177e4 LT |
17 | */ |
18 | #ifndef __XFS_DIR2_LEAF_H__ | |
19 | #define __XFS_DIR2_LEAF_H__ | |
20 | ||
1da177e4 LT |
21 | struct uio; |
22 | struct xfs_dabuf; | |
23 | struct xfs_da_args; | |
24 | struct xfs_inode; | |
25 | struct xfs_mount; | |
26 | struct xfs_trans; | |
27 | ||
1da177e4 LT |
28 | /* |
29 | * Offset of the leaf/node space. First block in this space | |
30 | * is the btree root. | |
31 | */ | |
32 | #define XFS_DIR2_LEAF_SPACE 1 | |
33 | #define XFS_DIR2_LEAF_OFFSET (XFS_DIR2_LEAF_SPACE * XFS_DIR2_SPACE_SIZE) | |
34 | #define XFS_DIR2_LEAF_FIRSTDB(mp) \ | |
35 | XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_LEAF_OFFSET) | |
36 | ||
1da177e4 LT |
37 | /* |
38 | * Offset in data space of a data entry. | |
39 | */ | |
40 | typedef __uint32_t xfs_dir2_dataptr_t; | |
41 | #define XFS_DIR2_MAX_DATAPTR ((xfs_dir2_dataptr_t)0xffffffff) | |
42 | #define XFS_DIR2_NULL_DATAPTR ((xfs_dir2_dataptr_t)0) | |
43 | ||
1da177e4 LT |
44 | /* |
45 | * Leaf block header. | |
46 | */ | |
47 | typedef struct xfs_dir2_leaf_hdr { | |
48 | xfs_da_blkinfo_t info; /* header for da routines */ | |
49 | __uint16_t count; /* count of entries */ | |
50 | __uint16_t stale; /* count of stale entries */ | |
51 | } xfs_dir2_leaf_hdr_t; | |
52 | ||
53 | /* | |
54 | * Leaf block entry. | |
55 | */ | |
56 | typedef struct xfs_dir2_leaf_entry { | |
57 | xfs_dahash_t hashval; /* hash value of name */ | |
58 | xfs_dir2_dataptr_t address; /* address of data entry */ | |
59 | } xfs_dir2_leaf_entry_t; | |
60 | ||
61 | /* | |
62 | * Leaf block tail. | |
63 | */ | |
64 | typedef struct xfs_dir2_leaf_tail { | |
65 | __uint32_t bestcount; | |
66 | } xfs_dir2_leaf_tail_t; | |
67 | ||
68 | /* | |
69 | * Leaf block. | |
70 | * bests and tail are at the end of the block for single-leaf only | |
71 | * (magic = XFS_DIR2_LEAF1_MAGIC not XFS_DIR2_LEAFN_MAGIC). | |
72 | */ | |
73 | typedef struct xfs_dir2_leaf { | |
74 | xfs_dir2_leaf_hdr_t hdr; /* leaf header */ | |
75 | xfs_dir2_leaf_entry_t ents[1]; /* entries */ | |
76 | /* ... */ | |
77 | xfs_dir2_data_off_t bests[1]; /* best free counts */ | |
78 | xfs_dir2_leaf_tail_t tail; /* leaf tail */ | |
79 | } xfs_dir2_leaf_t; | |
80 | ||
81 | /* | |
a844f451 | 82 | * DB blocks here are logical directory block numbers, not filesystem blocks. |
1da177e4 LT |
83 | */ |
84 | ||
a844f451 NS |
85 | #define XFS_DIR2_MAX_LEAF_ENTS(mp) xfs_dir2_max_leaf_ents(mp) |
86 | static inline int xfs_dir2_max_leaf_ents(struct xfs_mount *mp) | |
87 | { | |
88 | return (int)(((mp)->m_dirblksize - (uint)sizeof(xfs_dir2_leaf_hdr_t)) / | |
89 | (uint)sizeof(xfs_dir2_leaf_entry_t)); | |
90 | } | |
1da177e4 LT |
91 | |
92 | /* | |
93 | * Get address of the bestcount field in the single-leaf block. | |
94 | */ | |
a844f451 NS |
95 | #define XFS_DIR2_LEAF_TAIL_P(mp,lp) xfs_dir2_leaf_tail_p(mp, lp) |
96 | static inline xfs_dir2_leaf_tail_t * | |
97 | xfs_dir2_leaf_tail_p(struct xfs_mount *mp, xfs_dir2_leaf_t *lp) | |
98 | { | |
99 | return (xfs_dir2_leaf_tail_t *) | |
100 | ((char *)(lp) + (mp)->m_dirblksize - | |
101 | (uint)sizeof(xfs_dir2_leaf_tail_t)); | |
102 | } | |
1da177e4 LT |
103 | |
104 | /* | |
105 | * Get address of the bests array in the single-leaf block. | |
106 | */ | |
1da177e4 | 107 | #define XFS_DIR2_LEAF_BESTS_P(ltp) xfs_dir2_leaf_bests_p(ltp) |
a844f451 NS |
108 | static inline xfs_dir2_data_off_t * |
109 | xfs_dir2_leaf_bests_p(xfs_dir2_leaf_tail_t *ltp) | |
110 | { | |
111 | return (xfs_dir2_data_off_t *) | |
112 | (ltp) - INT_GET((ltp)->bestcount, ARCH_CONVERT); | |
113 | } | |
1da177e4 LT |
114 | |
115 | /* | |
116 | * Convert dataptr to byte in file space | |
117 | */ | |
1da177e4 | 118 | #define XFS_DIR2_DATAPTR_TO_BYTE(mp,dp) xfs_dir2_dataptr_to_byte(mp, dp) |
a844f451 NS |
119 | static inline xfs_dir2_off_t |
120 | xfs_dir2_dataptr_to_byte(struct xfs_mount *mp, xfs_dir2_dataptr_t dp) | |
121 | { | |
122 | return (xfs_dir2_off_t)(dp) << XFS_DIR2_DATA_ALIGN_LOG; | |
123 | } | |
1da177e4 LT |
124 | |
125 | /* | |
126 | * Convert byte in file space to dataptr. It had better be aligned. | |
127 | */ | |
1da177e4 | 128 | #define XFS_DIR2_BYTE_TO_DATAPTR(mp,by) xfs_dir2_byte_to_dataptr(mp,by) |
a844f451 NS |
129 | static inline xfs_dir2_dataptr_t |
130 | xfs_dir2_byte_to_dataptr(struct xfs_mount *mp, xfs_dir2_off_t by) | |
131 | { | |
132 | return (xfs_dir2_dataptr_t)((by) >> XFS_DIR2_DATA_ALIGN_LOG); | |
133 | } | |
134 | ||
135 | /* | |
136 | * Convert byte in space to (DB) block | |
137 | */ | |
138 | #define XFS_DIR2_BYTE_TO_DB(mp,by) xfs_dir2_byte_to_db(mp, by) | |
139 | static inline xfs_dir2_db_t | |
140 | xfs_dir2_byte_to_db(struct xfs_mount *mp, xfs_dir2_off_t by) | |
141 | { | |
142 | return (xfs_dir2_db_t)((by) >> \ | |
143 | ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)); | |
144 | } | |
1da177e4 LT |
145 | |
146 | /* | |
147 | * Convert dataptr to a block number | |
148 | */ | |
1da177e4 | 149 | #define XFS_DIR2_DATAPTR_TO_DB(mp,dp) xfs_dir2_dataptr_to_db(mp, dp) |
a844f451 NS |
150 | static inline xfs_dir2_db_t |
151 | xfs_dir2_dataptr_to_db(struct xfs_mount *mp, xfs_dir2_dataptr_t dp) | |
152 | { | |
153 | return XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_DATAPTR_TO_BYTE(mp, dp)); | |
154 | } | |
155 | ||
156 | /* | |
157 | * Convert byte in space to offset in a block | |
158 | */ | |
159 | #define XFS_DIR2_BYTE_TO_OFF(mp,by) xfs_dir2_byte_to_off(mp, by) | |
160 | static inline xfs_dir2_data_aoff_t | |
161 | xfs_dir2_byte_to_off(struct xfs_mount *mp, xfs_dir2_off_t by) | |
162 | { | |
163 | return (xfs_dir2_data_aoff_t)((by) & \ | |
164 | ((1 << ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)) - 1)); | |
165 | } | |
1da177e4 LT |
166 | |
167 | /* | |
168 | * Convert dataptr to a byte offset in a block | |
169 | */ | |
1da177e4 | 170 | #define XFS_DIR2_DATAPTR_TO_OFF(mp,dp) xfs_dir2_dataptr_to_off(mp, dp) |
a844f451 NS |
171 | static inline xfs_dir2_data_aoff_t |
172 | xfs_dir2_dataptr_to_off(struct xfs_mount *mp, xfs_dir2_dataptr_t dp) | |
173 | { | |
174 | return XFS_DIR2_BYTE_TO_OFF(mp, XFS_DIR2_DATAPTR_TO_BYTE(mp, dp)); | |
175 | } | |
1da177e4 LT |
176 | |
177 | /* | |
178 | * Convert block and offset to byte in space | |
179 | */ | |
1da177e4 LT |
180 | #define XFS_DIR2_DB_OFF_TO_BYTE(mp,db,o) \ |
181 | xfs_dir2_db_off_to_byte(mp, db, o) | |
a844f451 NS |
182 | static inline xfs_dir2_off_t |
183 | xfs_dir2_db_off_to_byte(struct xfs_mount *mp, xfs_dir2_db_t db, | |
184 | xfs_dir2_data_aoff_t o) | |
185 | { | |
186 | return ((xfs_dir2_off_t)(db) << \ | |
187 | ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)) + (o); | |
188 | } | |
1da177e4 LT |
189 | |
190 | /* | |
a844f451 | 191 | * Convert block (DB) to block (dablk) |
1da177e4 | 192 | */ |
a844f451 NS |
193 | #define XFS_DIR2_DB_TO_DA(mp,db) xfs_dir2_db_to_da(mp, db) |
194 | static inline xfs_dablk_t | |
195 | xfs_dir2_db_to_da(struct xfs_mount *mp, xfs_dir2_db_t db) | |
196 | { | |
197 | return (xfs_dablk_t)((db) << (mp)->m_sb.sb_dirblklog); | |
198 | } | |
1da177e4 LT |
199 | |
200 | /* | |
201 | * Convert byte in space to (DA) block | |
202 | */ | |
1da177e4 | 203 | #define XFS_DIR2_BYTE_TO_DA(mp,by) xfs_dir2_byte_to_da(mp, by) |
a844f451 NS |
204 | static inline xfs_dablk_t |
205 | xfs_dir2_byte_to_da(struct xfs_mount *mp, xfs_dir2_off_t by) | |
206 | { | |
207 | return XFS_DIR2_DB_TO_DA(mp, XFS_DIR2_BYTE_TO_DB(mp, by)); | |
208 | } | |
1da177e4 LT |
209 | |
210 | /* | |
211 | * Convert block and offset to dataptr | |
212 | */ | |
1da177e4 LT |
213 | #define XFS_DIR2_DB_OFF_TO_DATAPTR(mp,db,o) \ |
214 | xfs_dir2_db_off_to_dataptr(mp, db, o) | |
a844f451 NS |
215 | static inline xfs_dir2_dataptr_t |
216 | xfs_dir2_db_off_to_dataptr(struct xfs_mount *mp, xfs_dir2_db_t db, | |
217 | xfs_dir2_data_aoff_t o) | |
218 | { | |
219 | return XFS_DIR2_BYTE_TO_DATAPTR(mp, XFS_DIR2_DB_OFF_TO_BYTE(mp, db, o)); | |
220 | } | |
1da177e4 LT |
221 | |
222 | /* | |
223 | * Convert block (dablk) to block (DB) | |
224 | */ | |
1da177e4 | 225 | #define XFS_DIR2_DA_TO_DB(mp,da) xfs_dir2_da_to_db(mp, da) |
a844f451 NS |
226 | static inline xfs_dir2_db_t |
227 | xfs_dir2_da_to_db(struct xfs_mount *mp, xfs_dablk_t da) | |
228 | { | |
229 | return (xfs_dir2_db_t)((da) >> (mp)->m_sb.sb_dirblklog); | |
230 | } | |
1da177e4 LT |
231 | |
232 | /* | |
233 | * Convert block (dablk) to byte offset in space | |
234 | */ | |
1da177e4 | 235 | #define XFS_DIR2_DA_TO_BYTE(mp,da) xfs_dir2_da_to_byte(mp, da) |
a844f451 NS |
236 | static inline xfs_dir2_off_t |
237 | xfs_dir2_da_to_byte(struct xfs_mount *mp, xfs_dablk_t da) | |
238 | { | |
239 | return XFS_DIR2_DB_OFF_TO_BYTE(mp, XFS_DIR2_DA_TO_DB(mp, da), 0); | |
240 | } | |
1da177e4 LT |
241 | |
242 | /* | |
243 | * Function declarations. | |
244 | */ | |
a844f451 NS |
245 | extern int xfs_dir2_block_to_leaf(struct xfs_da_args *args, |
246 | struct xfs_dabuf *dbp); | |
247 | extern int xfs_dir2_leaf_addname(struct xfs_da_args *args); | |
248 | extern void xfs_dir2_leaf_compact(struct xfs_da_args *args, | |
249 | struct xfs_dabuf *bp); | |
250 | extern void xfs_dir2_leaf_compact_x1(struct xfs_dabuf *bp, int *indexp, | |
251 | int *lowstalep, int *highstalep, | |
252 | int *lowlogp, int *highlogp); | |
253 | extern int xfs_dir2_leaf_getdents(struct xfs_trans *tp, struct xfs_inode *dp, | |
254 | struct uio *uio, int *eofp, | |
255 | struct xfs_dirent *dbp, xfs_dir2_put_t put); | |
256 | extern int xfs_dir2_leaf_init(struct xfs_da_args *args, xfs_dir2_db_t bno, | |
257 | struct xfs_dabuf **bpp, int magic); | |
258 | extern void xfs_dir2_leaf_log_ents(struct xfs_trans *tp, struct xfs_dabuf *bp, | |
259 | int first, int last); | |
260 | extern void xfs_dir2_leaf_log_header(struct xfs_trans *tp, | |
261 | struct xfs_dabuf *bp); | |
262 | extern int xfs_dir2_leaf_lookup(struct xfs_da_args *args); | |
263 | extern int xfs_dir2_leaf_removename(struct xfs_da_args *args); | |
264 | extern int xfs_dir2_leaf_replace(struct xfs_da_args *args); | |
265 | extern int xfs_dir2_leaf_search_hash(struct xfs_da_args *args, | |
266 | struct xfs_dabuf *lbp); | |
267 | extern int xfs_dir2_leaf_trim_data(struct xfs_da_args *args, | |
268 | struct xfs_dabuf *lbp, xfs_dir2_db_t db); | |
269 | extern int xfs_dir2_node_to_leaf(struct xfs_da_state *state); | |
1da177e4 LT |
270 | |
271 | #endif /* __XFS_DIR2_LEAF_H__ */ |