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