| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. | 
|  | 3 | * All Rights Reserved. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * | 
| Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. | 
|  | 8 | * | 
| Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * | 
| Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ | 
|  | 18 | #ifndef __XFS_DIR2_LEAF_H__ | 
|  | 19 | #define	__XFS_DIR2_LEAF_H__ | 
|  | 20 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
|  | 28 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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)	\ | 
| Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 35 | xfs_dir2_byte_to_db(mp, XFS_DIR2_LEAF_OFFSET) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 |  | 
|  | 37 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
|  | 44 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | * Leaf block header. | 
|  | 46 | */ | 
|  | 47 | typedef struct xfs_dir2_leaf_hdr { | 
|  | 48 | xfs_da_blkinfo_t	info;		/* header for da routines */ | 
| Nathan Scott | a818e5d | 2006-03-17 17:28:07 +1100 | [diff] [blame] | 49 | __be16			count;		/* count of entries */ | 
|  | 50 | __be16			stale;		/* count of stale entries */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } xfs_dir2_leaf_hdr_t; | 
|  | 52 |  | 
|  | 53 | /* | 
|  | 54 | * Leaf block entry. | 
|  | 55 | */ | 
|  | 56 | typedef struct xfs_dir2_leaf_entry { | 
| Nathan Scott | 3c1f9c1 | 2006-03-17 17:28:18 +1100 | [diff] [blame] | 57 | __be32			hashval;	/* hash value of name */ | 
|  | 58 | __be32			address;	/* address of data entry */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } xfs_dir2_leaf_entry_t; | 
|  | 60 |  | 
|  | 61 | /* | 
|  | 62 | * Leaf block tail. | 
|  | 63 | */ | 
|  | 64 | typedef struct xfs_dir2_leaf_tail { | 
| Nathan Scott | afbcb3f | 2006-03-17 17:27:28 +1100 | [diff] [blame] | 65 | __be32			bestcount; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | /* | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 82 | * DB blocks here are logical directory block numbers, not filesystem blocks. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | */ | 
|  | 84 |  | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 85 | static inline int xfs_dir2_max_leaf_ents(struct xfs_mount *mp) | 
|  | 86 | { | 
|  | 87 | return (int)(((mp)->m_dirblksize - (uint)sizeof(xfs_dir2_leaf_hdr_t)) / | 
|  | 88 | (uint)sizeof(xfs_dir2_leaf_entry_t)); | 
|  | 89 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 |  | 
|  | 91 | /* | 
|  | 92 | * Get address of the bestcount field in the single-leaf block. | 
|  | 93 | */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 94 | static inline xfs_dir2_leaf_tail_t * | 
|  | 95 | xfs_dir2_leaf_tail_p(struct xfs_mount *mp, xfs_dir2_leaf_t *lp) | 
|  | 96 | { | 
|  | 97 | return (xfs_dir2_leaf_tail_t *) | 
|  | 98 | ((char *)(lp) + (mp)->m_dirblksize - | 
|  | 99 | (uint)sizeof(xfs_dir2_leaf_tail_t)); | 
|  | 100 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 |  | 
|  | 102 | /* | 
|  | 103 | * Get address of the bests array in the single-leaf block. | 
|  | 104 | */ | 
| Nathan Scott | 68b3a10 | 2006-03-17 17:27:19 +1100 | [diff] [blame] | 105 | static inline __be16 * | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 106 | xfs_dir2_leaf_bests_p(xfs_dir2_leaf_tail_t *ltp) | 
|  | 107 | { | 
| Nathan Scott | afbcb3f | 2006-03-17 17:27:28 +1100 | [diff] [blame] | 108 | return (__be16 *)ltp - be32_to_cpu(ltp->bestcount); | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 109 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 |  | 
|  | 111 | /* | 
|  | 112 | * Convert dataptr to byte in file space | 
|  | 113 | */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 114 | static inline xfs_dir2_off_t | 
|  | 115 | xfs_dir2_dataptr_to_byte(struct xfs_mount *mp, xfs_dir2_dataptr_t dp) | 
|  | 116 | { | 
|  | 117 | return (xfs_dir2_off_t)(dp) << XFS_DIR2_DATA_ALIGN_LOG; | 
|  | 118 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 |  | 
|  | 120 | /* | 
|  | 121 | * Convert byte in file space to dataptr.  It had better be aligned. | 
|  | 122 | */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 123 | static inline xfs_dir2_dataptr_t | 
|  | 124 | xfs_dir2_byte_to_dataptr(struct xfs_mount *mp, xfs_dir2_off_t by) | 
|  | 125 | { | 
|  | 126 | return (xfs_dir2_dataptr_t)((by) >> XFS_DIR2_DATA_ALIGN_LOG); | 
|  | 127 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 |  | 
|  | 129 | /* | 
|  | 130 | * Convert byte in space to (DB) block | 
|  | 131 | */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 132 | static inline xfs_dir2_db_t | 
|  | 133 | xfs_dir2_byte_to_db(struct xfs_mount *mp, xfs_dir2_off_t by) | 
|  | 134 | { | 
|  | 135 | return (xfs_dir2_db_t)((by) >> \ | 
|  | 136 | ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)); | 
|  | 137 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 |  | 
|  | 139 | /* | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 140 | * Convert dataptr to a block number | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 142 | static inline xfs_dir2_db_t | 
|  | 143 | xfs_dir2_dataptr_to_db(struct xfs_mount *mp, xfs_dir2_dataptr_t dp) | 
|  | 144 | { | 
| Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 145 | return xfs_dir2_byte_to_db(mp, xfs_dir2_dataptr_to_byte(mp, dp)); | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 146 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 |  | 
|  | 148 | /* | 
|  | 149 | * Convert byte in space to offset in a block | 
|  | 150 | */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 151 | static inline xfs_dir2_data_aoff_t | 
|  | 152 | xfs_dir2_byte_to_off(struct xfs_mount *mp, xfs_dir2_off_t by) | 
|  | 153 | { | 
|  | 154 | return (xfs_dir2_data_aoff_t)((by) & \ | 
|  | 155 | ((1 << ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)) - 1)); | 
|  | 156 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 |  | 
|  | 158 | /* | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 159 | * Convert dataptr to a byte offset in a block | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 161 | static inline xfs_dir2_data_aoff_t | 
|  | 162 | xfs_dir2_dataptr_to_off(struct xfs_mount *mp, xfs_dir2_dataptr_t dp) | 
|  | 163 | { | 
| Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 164 | return xfs_dir2_byte_to_off(mp, xfs_dir2_dataptr_to_byte(mp, dp)); | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 165 | } | 
|  | 166 |  | 
|  | 167 | /* | 
|  | 168 | * Convert block and offset to byte in space | 
|  | 169 | */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 170 | static inline xfs_dir2_off_t | 
|  | 171 | xfs_dir2_db_off_to_byte(struct xfs_mount *mp, xfs_dir2_db_t db, | 
|  | 172 | xfs_dir2_data_aoff_t o) | 
|  | 173 | { | 
|  | 174 | return ((xfs_dir2_off_t)(db) << \ | 
|  | 175 | ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)) + (o); | 
|  | 176 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 |  | 
|  | 178 | /* | 
|  | 179 | * Convert block (DB) to block (dablk) | 
|  | 180 | */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 181 | static inline xfs_dablk_t | 
|  | 182 | xfs_dir2_db_to_da(struct xfs_mount *mp, xfs_dir2_db_t db) | 
|  | 183 | { | 
|  | 184 | return (xfs_dablk_t)((db) << (mp)->m_sb.sb_dirblklog); | 
|  | 185 | } | 
|  | 186 |  | 
|  | 187 | /* | 
|  | 188 | * Convert byte in space to (DA) block | 
|  | 189 | */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 190 | static inline xfs_dablk_t | 
|  | 191 | xfs_dir2_byte_to_da(struct xfs_mount *mp, xfs_dir2_off_t by) | 
|  | 192 | { | 
| Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 193 | return xfs_dir2_db_to_da(mp, xfs_dir2_byte_to_db(mp, by)); | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 194 | } | 
|  | 195 |  | 
|  | 196 | /* | 
|  | 197 | * Convert block and offset to dataptr | 
|  | 198 | */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 199 | static inline xfs_dir2_dataptr_t | 
|  | 200 | xfs_dir2_db_off_to_dataptr(struct xfs_mount *mp, xfs_dir2_db_t db, | 
|  | 201 | xfs_dir2_data_aoff_t o) | 
|  | 202 | { | 
| Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 203 | return xfs_dir2_byte_to_dataptr(mp, xfs_dir2_db_off_to_byte(mp, db, o)); | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 204 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 |  | 
|  | 206 | /* | 
|  | 207 | * Convert block (dablk) to block (DB) | 
|  | 208 | */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 209 | static inline xfs_dir2_db_t | 
|  | 210 | xfs_dir2_da_to_db(struct xfs_mount *mp, xfs_dablk_t da) | 
|  | 211 | { | 
|  | 212 | return (xfs_dir2_db_t)((da) >> (mp)->m_sb.sb_dirblklog); | 
|  | 213 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 |  | 
|  | 215 | /* | 
|  | 216 | * Convert block (dablk) to byte offset in space | 
|  | 217 | */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 218 | static inline xfs_dir2_off_t | 
|  | 219 | xfs_dir2_da_to_byte(struct xfs_mount *mp, xfs_dablk_t da) | 
|  | 220 | { | 
| Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 221 | return xfs_dir2_db_off_to_byte(mp, xfs_dir2_da_to_db(mp, da), 0); | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 222 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 |  | 
|  | 224 | /* | 
|  | 225 | * Function declarations. | 
|  | 226 | */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 227 | extern int xfs_dir2_block_to_leaf(struct xfs_da_args *args, | 
|  | 228 | struct xfs_dabuf *dbp); | 
|  | 229 | extern int xfs_dir2_leaf_addname(struct xfs_da_args *args); | 
|  | 230 | extern void xfs_dir2_leaf_compact(struct xfs_da_args *args, | 
|  | 231 | struct xfs_dabuf *bp); | 
|  | 232 | extern void xfs_dir2_leaf_compact_x1(struct xfs_dabuf *bp, int *indexp, | 
|  | 233 | int *lowstalep, int *highstalep, | 
|  | 234 | int *lowlogp, int *highlogp); | 
| Christoph Hellwig | 051e7cd | 2007-08-28 13:58:24 +1000 | [diff] [blame] | 235 | extern int xfs_dir2_leaf_getdents(struct xfs_inode *dp, void *dirent, | 
|  | 236 | size_t bufsize, xfs_off_t *offset, | 
|  | 237 | filldir_t filldir); | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 238 | extern int xfs_dir2_leaf_init(struct xfs_da_args *args, xfs_dir2_db_t bno, | 
|  | 239 | struct xfs_dabuf **bpp, int magic); | 
|  | 240 | extern void xfs_dir2_leaf_log_ents(struct xfs_trans *tp, struct xfs_dabuf *bp, | 
|  | 241 | int first, int last); | 
|  | 242 | extern void xfs_dir2_leaf_log_header(struct xfs_trans *tp, | 
|  | 243 | struct xfs_dabuf *bp); | 
|  | 244 | extern int xfs_dir2_leaf_lookup(struct xfs_da_args *args); | 
|  | 245 | extern int xfs_dir2_leaf_removename(struct xfs_da_args *args); | 
|  | 246 | extern int xfs_dir2_leaf_replace(struct xfs_da_args *args); | 
|  | 247 | extern int xfs_dir2_leaf_search_hash(struct xfs_da_args *args, | 
|  | 248 | struct xfs_dabuf *lbp); | 
|  | 249 | extern int xfs_dir2_leaf_trim_data(struct xfs_da_args *args, | 
|  | 250 | struct xfs_dabuf *lbp, xfs_dir2_db_t db); | 
|  | 251 | extern int xfs_dir2_node_to_leaf(struct xfs_da_state *state); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 |  | 
|  | 253 | #endif	/* __XFS_DIR2_LEAF_H__ */ |