| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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_BTREE_H__ | 
|  | 33 | #define	__XFS_BTREE_H__ | 
|  | 34 |  | 
|  | 35 | struct xfs_buf; | 
|  | 36 | struct xfs_bmap_free; | 
|  | 37 | struct xfs_inode; | 
|  | 38 | struct xfs_mount; | 
|  | 39 | struct xfs_trans; | 
|  | 40 |  | 
|  | 41 | /* | 
|  | 42 | * This nonsense is to make -wlint happy. | 
|  | 43 | */ | 
|  | 44 | #define	XFS_LOOKUP_EQ	((xfs_lookup_t)XFS_LOOKUP_EQi) | 
|  | 45 | #define	XFS_LOOKUP_LE	((xfs_lookup_t)XFS_LOOKUP_LEi) | 
|  | 46 | #define	XFS_LOOKUP_GE	((xfs_lookup_t)XFS_LOOKUP_GEi) | 
|  | 47 |  | 
|  | 48 | #define	XFS_BTNUM_BNO	((xfs_btnum_t)XFS_BTNUM_BNOi) | 
|  | 49 | #define	XFS_BTNUM_CNT	((xfs_btnum_t)XFS_BTNUM_CNTi) | 
|  | 50 | #define	XFS_BTNUM_BMAP	((xfs_btnum_t)XFS_BTNUM_BMAPi) | 
|  | 51 | #define	XFS_BTNUM_INO	((xfs_btnum_t)XFS_BTNUM_INOi) | 
|  | 52 |  | 
|  | 53 | /* | 
|  | 54 | * Short form header: space allocation btrees. | 
|  | 55 | */ | 
|  | 56 | typedef struct xfs_btree_sblock | 
|  | 57 | { | 
|  | 58 | __uint32_t	bb_magic;	/* magic number for block type */ | 
|  | 59 | __uint16_t	bb_level;	/* 0 is a leaf */ | 
|  | 60 | __uint16_t	bb_numrecs;	/* current # of data records */ | 
|  | 61 | xfs_agblock_t	bb_leftsib;	/* left sibling block or NULLAGBLOCK */ | 
|  | 62 | xfs_agblock_t	bb_rightsib;	/* right sibling block or NULLAGBLOCK */ | 
|  | 63 | } xfs_btree_sblock_t; | 
|  | 64 |  | 
|  | 65 | /* | 
|  | 66 | * Long form header: bmap btrees. | 
|  | 67 | */ | 
|  | 68 | typedef struct xfs_btree_lblock | 
|  | 69 | { | 
|  | 70 | __uint32_t	bb_magic;	/* magic number for block type */ | 
|  | 71 | __uint16_t	bb_level;	/* 0 is a leaf */ | 
|  | 72 | __uint16_t	bb_numrecs;	/* current # of data records */ | 
|  | 73 | xfs_dfsbno_t	bb_leftsib;	/* left sibling block or NULLDFSBNO */ | 
|  | 74 | xfs_dfsbno_t	bb_rightsib;	/* right sibling block or NULLDFSBNO */ | 
|  | 75 | } xfs_btree_lblock_t; | 
|  | 76 |  | 
|  | 77 | /* | 
|  | 78 | * Combined header and structure, used by common code. | 
|  | 79 | */ | 
|  | 80 | typedef struct xfs_btree_hdr | 
|  | 81 | { | 
|  | 82 | __uint32_t	bb_magic;	/* magic number for block type */ | 
|  | 83 | __uint16_t	bb_level;	/* 0 is a leaf */ | 
|  | 84 | __uint16_t	bb_numrecs;	/* current # of data records */ | 
|  | 85 | } xfs_btree_hdr_t; | 
|  | 86 |  | 
|  | 87 | typedef struct xfs_btree_block | 
|  | 88 | { | 
|  | 89 | xfs_btree_hdr_t	bb_h;		/* header */ | 
|  | 90 | union		{ | 
|  | 91 | struct	{ | 
|  | 92 | xfs_agblock_t	bb_leftsib; | 
|  | 93 | xfs_agblock_t	bb_rightsib; | 
|  | 94 | }	s;		/* short form pointers */ | 
|  | 95 | struct	{ | 
|  | 96 | xfs_dfsbno_t	bb_leftsib; | 
|  | 97 | xfs_dfsbno_t	bb_rightsib; | 
|  | 98 | }	l;		/* long form pointers */ | 
|  | 99 | }		bb_u;		/* rest */ | 
|  | 100 | } xfs_btree_block_t; | 
|  | 101 |  | 
|  | 102 | /* | 
|  | 103 | * For logging record fields. | 
|  | 104 | */ | 
|  | 105 | #define	XFS_BB_MAGIC		0x01 | 
|  | 106 | #define	XFS_BB_LEVEL		0x02 | 
|  | 107 | #define	XFS_BB_NUMRECS		0x04 | 
|  | 108 | #define	XFS_BB_LEFTSIB		0x08 | 
|  | 109 | #define	XFS_BB_RIGHTSIB		0x10 | 
|  | 110 | #define	XFS_BB_NUM_BITS		5 | 
|  | 111 | #define	XFS_BB_ALL_BITS		((1 << XFS_BB_NUM_BITS) - 1) | 
|  | 112 |  | 
|  | 113 | /* | 
|  | 114 | * Boolean to select which form of xfs_btree_block_t.bb_u to use. | 
|  | 115 | */ | 
|  | 116 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BTREE_LONG_PTRS) | 
|  | 117 | int xfs_btree_long_ptrs(xfs_btnum_t btnum); | 
|  | 118 | #define	XFS_BTREE_LONG_PTRS(btnum)	((btnum) == XFS_BTNUM_BMAP) | 
|  | 119 | #else | 
|  | 120 | #define	XFS_BTREE_LONG_PTRS(btnum)	((btnum) == XFS_BTNUM_BMAP) | 
|  | 121 | #endif | 
|  | 122 |  | 
|  | 123 | /* | 
|  | 124 | * Magic numbers for btree blocks. | 
|  | 125 | */ | 
|  | 126 | extern const __uint32_t	xfs_magics[]; | 
|  | 127 |  | 
|  | 128 | /* | 
|  | 129 | * Maximum and minimum records in a btree block. | 
|  | 130 | * Given block size, type prefix, and leaf flag (0 or 1). | 
|  | 131 | * The divisor below is equivalent to lf ? (e1) : (e2) but that produces | 
|  | 132 | * compiler warnings. | 
|  | 133 | */ | 
|  | 134 | #define	XFS_BTREE_BLOCK_MAXRECS(bsz,t,lf)	\ | 
|  | 135 | ((int)(((bsz) - (uint)sizeof(t ## _block_t)) / \ | 
|  | 136 | (((lf) * (uint)sizeof(t ## _rec_t)) + \ | 
|  | 137 | ((1 - (lf)) * \ | 
|  | 138 | ((uint)sizeof(t ## _key_t) + (uint)sizeof(t ## _ptr_t)))))) | 
|  | 139 | #define	XFS_BTREE_BLOCK_MINRECS(bsz,t,lf)	\ | 
|  | 140 | (XFS_BTREE_BLOCK_MAXRECS(bsz,t,lf) / 2) | 
|  | 141 |  | 
|  | 142 | /* | 
|  | 143 | * Record, key, and pointer address calculation macros. | 
|  | 144 | * Given block size, type prefix, block pointer, and index of requested entry | 
|  | 145 | * (first entry numbered 1). | 
|  | 146 | */ | 
|  | 147 | #define	XFS_BTREE_REC_ADDR(bsz,t,bb,i,mxr)	\ | 
|  | 148 | ((t ## _rec_t *)((char *)(bb) + sizeof(t ## _block_t) + \ | 
|  | 149 | ((i) - 1) * sizeof(t ## _rec_t))) | 
|  | 150 | #define	XFS_BTREE_KEY_ADDR(bsz,t,bb,i,mxr)	\ | 
|  | 151 | ((t ## _key_t *)((char *)(bb) + sizeof(t ## _block_t) + \ | 
|  | 152 | ((i) - 1) * sizeof(t ## _key_t))) | 
|  | 153 | #define	XFS_BTREE_PTR_ADDR(bsz,t,bb,i,mxr)	\ | 
|  | 154 | ((t ## _ptr_t *)((char *)(bb) + sizeof(t ## _block_t) + \ | 
|  | 155 | (mxr) * sizeof(t ## _key_t) + ((i) - 1) * sizeof(t ## _ptr_t))) | 
|  | 156 |  | 
|  | 157 | #define	XFS_BTREE_MAXLEVELS	8	/* max of all btrees */ | 
|  | 158 |  | 
|  | 159 | /* | 
|  | 160 | * Btree cursor structure. | 
|  | 161 | * This collects all information needed by the btree code in one place. | 
|  | 162 | */ | 
|  | 163 | typedef struct xfs_btree_cur | 
|  | 164 | { | 
|  | 165 | struct xfs_trans	*bc_tp;	/* transaction we're in, if any */ | 
|  | 166 | struct xfs_mount	*bc_mp;	/* file system mount struct */ | 
|  | 167 | union { | 
|  | 168 | xfs_alloc_rec_t		a; | 
|  | 169 | xfs_bmbt_irec_t		b; | 
|  | 170 | xfs_inobt_rec_t		i; | 
|  | 171 | }		bc_rec;		/* current insert/search record value */ | 
|  | 172 | struct xfs_buf	*bc_bufs[XFS_BTREE_MAXLEVELS];	/* buf ptr per level */ | 
|  | 173 | int		bc_ptrs[XFS_BTREE_MAXLEVELS];	/* key/record # */ | 
|  | 174 | __uint8_t	bc_ra[XFS_BTREE_MAXLEVELS];	/* readahead bits */ | 
|  | 175 | #define	XFS_BTCUR_LEFTRA	1	/* left sibling has been read-ahead */ | 
|  | 176 | #define	XFS_BTCUR_RIGHTRA	2	/* right sibling has been read-ahead */ | 
|  | 177 | __uint8_t	bc_nlevels;	/* number of levels in the tree */ | 
|  | 178 | __uint8_t	bc_blocklog;	/* log2(blocksize) of btree blocks */ | 
|  | 179 | xfs_btnum_t	bc_btnum;	/* identifies which btree type */ | 
|  | 180 | union { | 
|  | 181 | struct {			/* needed for BNO, CNT */ | 
|  | 182 | struct xfs_buf	*agbp;	/* agf buffer pointer */ | 
|  | 183 | xfs_agnumber_t	agno;	/* ag number */ | 
|  | 184 | } a; | 
|  | 185 | struct {			/* needed for BMAP */ | 
|  | 186 | struct xfs_inode *ip;	/* pointer to our inode */ | 
|  | 187 | struct xfs_bmap_free *flist;	/* list to free after */ | 
|  | 188 | xfs_fsblock_t	firstblock;	/* 1st blk allocated */ | 
|  | 189 | int		allocated;	/* count of alloced */ | 
|  | 190 | short		forksize;	/* fork's inode space */ | 
|  | 191 | char		whichfork;	/* data or attr fork */ | 
|  | 192 | char		flags;		/* flags */ | 
|  | 193 | #define	XFS_BTCUR_BPRV_WASDEL	1			/* was delayed */ | 
|  | 194 | } b; | 
|  | 195 | struct {			/* needed for INO */ | 
|  | 196 | struct xfs_buf	*agbp;	/* agi buffer pointer */ | 
|  | 197 | xfs_agnumber_t	agno;	/* ag number */ | 
|  | 198 | } i; | 
|  | 199 | }		bc_private;	/* per-btree type data */ | 
|  | 200 | } xfs_btree_cur_t; | 
|  | 201 |  | 
|  | 202 | #define	XFS_BTREE_NOERROR	0 | 
|  | 203 | #define	XFS_BTREE_ERROR		1 | 
|  | 204 |  | 
|  | 205 | /* | 
|  | 206 | * Convert from buffer to btree block header. | 
|  | 207 | */ | 
|  | 208 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_BLOCK) | 
|  | 209 | xfs_btree_block_t *xfs_buf_to_block(struct xfs_buf *bp); | 
|  | 210 | #define	XFS_BUF_TO_BLOCK(bp)	xfs_buf_to_block(bp) | 
|  | 211 | #else | 
|  | 212 | #define	XFS_BUF_TO_BLOCK(bp)	((xfs_btree_block_t *)(XFS_BUF_PTR(bp))) | 
|  | 213 | #endif | 
|  | 214 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_LBLOCK) | 
|  | 215 | xfs_btree_lblock_t *xfs_buf_to_lblock(struct xfs_buf *bp); | 
|  | 216 | #define	XFS_BUF_TO_LBLOCK(bp)	xfs_buf_to_lblock(bp) | 
|  | 217 | #else | 
|  | 218 | #define	XFS_BUF_TO_LBLOCK(bp)	((xfs_btree_lblock_t *)(XFS_BUF_PTR(bp))) | 
|  | 219 | #endif | 
|  | 220 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_SBLOCK) | 
|  | 221 | xfs_btree_sblock_t *xfs_buf_to_sblock(struct xfs_buf *bp); | 
|  | 222 | #define	XFS_BUF_TO_SBLOCK(bp)	xfs_buf_to_sblock(bp) | 
|  | 223 | #else | 
|  | 224 | #define	XFS_BUF_TO_SBLOCK(bp)	((xfs_btree_sblock_t *)(XFS_BUF_PTR(bp))) | 
|  | 225 | #endif | 
|  | 226 |  | 
|  | 227 | #ifdef __KERNEL__ | 
|  | 228 |  | 
|  | 229 | #ifdef DEBUG | 
|  | 230 | /* | 
|  | 231 | * Debug routine: check that block header is ok. | 
|  | 232 | */ | 
|  | 233 | void | 
|  | 234 | xfs_btree_check_block( | 
|  | 235 | xfs_btree_cur_t		*cur,	/* btree cursor */ | 
|  | 236 | xfs_btree_block_t	*block,	/* generic btree block pointer */ | 
|  | 237 | int			level,	/* level of the btree block */ | 
|  | 238 | struct xfs_buf		*bp);	/* buffer containing block, if any */ | 
|  | 239 |  | 
|  | 240 | /* | 
|  | 241 | * Debug routine: check that keys are in the right order. | 
|  | 242 | */ | 
|  | 243 | void | 
|  | 244 | xfs_btree_check_key( | 
|  | 245 | xfs_btnum_t		btnum,	/* btree identifier */ | 
|  | 246 | void			*ak1,	/* pointer to left (lower) key */ | 
|  | 247 | void			*ak2);	/* pointer to right (higher) key */ | 
|  | 248 |  | 
|  | 249 | /* | 
|  | 250 | * Debug routine: check that records are in the right order. | 
|  | 251 | */ | 
|  | 252 | void | 
|  | 253 | xfs_btree_check_rec( | 
|  | 254 | xfs_btnum_t		btnum,	/* btree identifier */ | 
|  | 255 | void			*ar1,	/* pointer to left (lower) record */ | 
|  | 256 | void			*ar2);	/* pointer to right (higher) record */ | 
|  | 257 | #else | 
|  | 258 | #define	xfs_btree_check_block(a,b,c,d) | 
|  | 259 | #define	xfs_btree_check_key(a,b,c) | 
|  | 260 | #define	xfs_btree_check_rec(a,b,c) | 
|  | 261 | #endif	/* DEBUG */ | 
|  | 262 |  | 
|  | 263 | /* | 
|  | 264 | * Checking routine: check that long form block header is ok. | 
|  | 265 | */ | 
|  | 266 | int					/* error (0 or EFSCORRUPTED) */ | 
|  | 267 | xfs_btree_check_lblock( | 
|  | 268 | xfs_btree_cur_t		*cur,	/* btree cursor */ | 
|  | 269 | xfs_btree_lblock_t	*block,	/* btree long form block pointer */ | 
|  | 270 | int			level,	/* level of the btree block */ | 
|  | 271 | struct xfs_buf		*bp);	/* buffer containing block, if any */ | 
|  | 272 |  | 
|  | 273 | /* | 
|  | 274 | * Checking routine: check that (long) pointer is ok. | 
|  | 275 | */ | 
|  | 276 | int					/* error (0 or EFSCORRUPTED) */ | 
|  | 277 | xfs_btree_check_lptr( | 
|  | 278 | xfs_btree_cur_t		*cur,	/* btree cursor */ | 
|  | 279 | xfs_dfsbno_t		ptr,	/* btree block disk address */ | 
|  | 280 | int			level);	/* btree block level */ | 
|  | 281 |  | 
|  | 282 | /* | 
|  | 283 | * Checking routine: check that short form block header is ok. | 
|  | 284 | */ | 
|  | 285 | int					/* error (0 or EFSCORRUPTED) */ | 
|  | 286 | xfs_btree_check_sblock( | 
|  | 287 | xfs_btree_cur_t		*cur,	/* btree cursor */ | 
|  | 288 | xfs_btree_sblock_t	*block,	/* btree short form block pointer */ | 
|  | 289 | int			level,	/* level of the btree block */ | 
|  | 290 | struct xfs_buf		*bp);	/* buffer containing block */ | 
|  | 291 |  | 
|  | 292 | /* | 
|  | 293 | * Checking routine: check that (short) pointer is ok. | 
|  | 294 | */ | 
|  | 295 | int					/* error (0 or EFSCORRUPTED) */ | 
|  | 296 | xfs_btree_check_sptr( | 
|  | 297 | xfs_btree_cur_t		*cur,	/* btree cursor */ | 
|  | 298 | xfs_agblock_t		ptr,	/* btree block disk address */ | 
|  | 299 | int			level);	/* btree block level */ | 
|  | 300 |  | 
|  | 301 | /* | 
|  | 302 | * Delete the btree cursor. | 
|  | 303 | */ | 
|  | 304 | void | 
|  | 305 | xfs_btree_del_cursor( | 
|  | 306 | xfs_btree_cur_t		*cur,	/* btree cursor */ | 
|  | 307 | int			error);	/* del because of error */ | 
|  | 308 |  | 
|  | 309 | /* | 
|  | 310 | * Duplicate the btree cursor. | 
|  | 311 | * Allocate a new one, copy the record, re-get the buffers. | 
|  | 312 | */ | 
|  | 313 | int					/* error */ | 
|  | 314 | xfs_btree_dup_cursor( | 
|  | 315 | xfs_btree_cur_t		*cur,	/* input cursor */ | 
|  | 316 | xfs_btree_cur_t		**ncur);/* output cursor */ | 
|  | 317 |  | 
|  | 318 | /* | 
|  | 319 | * Change the cursor to point to the first record in the current block | 
|  | 320 | * at the given level.  Other levels are unaffected. | 
|  | 321 | */ | 
|  | 322 | int					/* success=1, failure=0 */ | 
|  | 323 | xfs_btree_firstrec( | 
|  | 324 | xfs_btree_cur_t		*cur,	/* btree cursor */ | 
|  | 325 | int			level);	/* level to change */ | 
|  | 326 |  | 
|  | 327 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | * Get a buffer for the block, return it with no data read. | 
|  | 329 | * Long-form addressing. | 
|  | 330 | */ | 
|  | 331 | struct xfs_buf *				/* buffer for fsbno */ | 
|  | 332 | xfs_btree_get_bufl( | 
|  | 333 | struct xfs_mount	*mp,	/* file system mount point */ | 
|  | 334 | struct xfs_trans	*tp,	/* transaction pointer */ | 
|  | 335 | xfs_fsblock_t		fsbno,	/* file system block number */ | 
|  | 336 | uint			lock);	/* lock flags for get_buf */ | 
|  | 337 |  | 
|  | 338 | /* | 
|  | 339 | * Get a buffer for the block, return it with no data read. | 
|  | 340 | * Short-form addressing. | 
|  | 341 | */ | 
|  | 342 | struct xfs_buf *				/* buffer for agno/agbno */ | 
|  | 343 | xfs_btree_get_bufs( | 
|  | 344 | struct xfs_mount	*mp,	/* file system mount point */ | 
|  | 345 | struct xfs_trans	*tp,	/* transaction pointer */ | 
|  | 346 | xfs_agnumber_t		agno,	/* allocation group number */ | 
|  | 347 | xfs_agblock_t		agbno,	/* allocation group block number */ | 
|  | 348 | uint			lock);	/* lock flags for get_buf */ | 
|  | 349 |  | 
|  | 350 | /* | 
|  | 351 | * Allocate a new btree cursor. | 
|  | 352 | * The cursor is either for allocation (A) or bmap (B). | 
|  | 353 | */ | 
|  | 354 | xfs_btree_cur_t *			/* new btree cursor */ | 
|  | 355 | xfs_btree_init_cursor( | 
|  | 356 | struct xfs_mount	*mp,	/* file system mount point */ | 
|  | 357 | struct xfs_trans	*tp,	/* transaction pointer */ | 
|  | 358 | struct xfs_buf		*agbp,	/* (A only) buffer for agf structure */ | 
|  | 359 | xfs_agnumber_t		agno,	/* (A only) allocation group number */ | 
|  | 360 | xfs_btnum_t		btnum,	/* btree identifier */ | 
|  | 361 | struct xfs_inode	*ip,	/* (B only) inode owning the btree */ | 
|  | 362 | int			whichfork); /* (B only) data/attr fork */ | 
|  | 363 |  | 
|  | 364 | /* | 
|  | 365 | * Check for the cursor referring to the last block at the given level. | 
|  | 366 | */ | 
|  | 367 | int					/* 1=is last block, 0=not last block */ | 
|  | 368 | xfs_btree_islastblock( | 
|  | 369 | xfs_btree_cur_t		*cur,	/* btree cursor */ | 
|  | 370 | int			level);	/* level to check */ | 
|  | 371 |  | 
|  | 372 | /* | 
|  | 373 | * Change the cursor to point to the last record in the current block | 
|  | 374 | * at the given level.  Other levels are unaffected. | 
|  | 375 | */ | 
|  | 376 | int					/* success=1, failure=0 */ | 
|  | 377 | xfs_btree_lastrec( | 
|  | 378 | xfs_btree_cur_t		*cur,	/* btree cursor */ | 
|  | 379 | int			level);	/* level to change */ | 
|  | 380 |  | 
|  | 381 | /* | 
|  | 382 | * Compute first and last byte offsets for the fields given. | 
|  | 383 | * Interprets the offsets table, which contains struct field offsets. | 
|  | 384 | */ | 
|  | 385 | void | 
|  | 386 | xfs_btree_offsets( | 
|  | 387 | __int64_t		fields,	/* bitmask of fields */ | 
|  | 388 | const short		*offsets,/* table of field offsets */ | 
|  | 389 | int			nbits,	/* number of bits to inspect */ | 
|  | 390 | int			*first,	/* output: first byte offset */ | 
|  | 391 | int			*last);	/* output: last byte offset */ | 
|  | 392 |  | 
|  | 393 | /* | 
|  | 394 | * Get a buffer for the block, return it read in. | 
|  | 395 | * Long-form addressing. | 
|  | 396 | */ | 
|  | 397 | int					/* error */ | 
|  | 398 | xfs_btree_read_bufl( | 
|  | 399 | struct xfs_mount	*mp,	/* file system mount point */ | 
|  | 400 | struct xfs_trans	*tp,	/* transaction pointer */ | 
|  | 401 | xfs_fsblock_t		fsbno,	/* file system block number */ | 
|  | 402 | uint			lock,	/* lock flags for read_buf */ | 
|  | 403 | struct xfs_buf		**bpp,	/* buffer for fsbno */ | 
|  | 404 | int			refval);/* ref count value for buffer */ | 
|  | 405 |  | 
|  | 406 | /* | 
|  | 407 | * Get a buffer for the block, return it read in. | 
|  | 408 | * Short-form addressing. | 
|  | 409 | */ | 
|  | 410 | int					/* error */ | 
|  | 411 | xfs_btree_read_bufs( | 
|  | 412 | struct xfs_mount	*mp,	/* file system mount point */ | 
|  | 413 | struct xfs_trans	*tp,	/* transaction pointer */ | 
|  | 414 | xfs_agnumber_t		agno,	/* allocation group number */ | 
|  | 415 | xfs_agblock_t		agbno,	/* allocation group block number */ | 
|  | 416 | uint			lock,	/* lock flags for read_buf */ | 
|  | 417 | struct xfs_buf		**bpp,	/* buffer for agno/agbno */ | 
|  | 418 | int			refval);/* ref count value for buffer */ | 
|  | 419 |  | 
|  | 420 | /* | 
|  | 421 | * Read-ahead the block, don't wait for it, don't return a buffer. | 
|  | 422 | * Long-form addressing. | 
|  | 423 | */ | 
|  | 424 | void					/* error */ | 
|  | 425 | xfs_btree_reada_bufl( | 
|  | 426 | struct xfs_mount	*mp,	/* file system mount point */ | 
|  | 427 | xfs_fsblock_t		fsbno,	/* file system block number */ | 
|  | 428 | xfs_extlen_t		count);	/* count of filesystem blocks */ | 
|  | 429 |  | 
|  | 430 | /* | 
|  | 431 | * Read-ahead the block, don't wait for it, don't return a buffer. | 
|  | 432 | * Short-form addressing. | 
|  | 433 | */ | 
|  | 434 | void					/* error */ | 
|  | 435 | xfs_btree_reada_bufs( | 
|  | 436 | struct xfs_mount	*mp,	/* file system mount point */ | 
|  | 437 | xfs_agnumber_t		agno,	/* allocation group number */ | 
|  | 438 | xfs_agblock_t		agbno,	/* allocation group block number */ | 
|  | 439 | xfs_extlen_t		count);	/* count of filesystem blocks */ | 
|  | 440 |  | 
|  | 441 | /* | 
|  | 442 | * Read-ahead btree blocks, at the given level. | 
|  | 443 | * Bits in lr are set from XFS_BTCUR_{LEFT,RIGHT}RA. | 
|  | 444 | */ | 
|  | 445 | int					/* readahead block count */ | 
|  | 446 | xfs_btree_readahead_core( | 
|  | 447 | xfs_btree_cur_t		*cur,	/* btree cursor */ | 
|  | 448 | int			lev,	/* level in btree */ | 
|  | 449 | int			lr);	/* left/right bits */ | 
|  | 450 |  | 
|  | 451 | static inline int			/* readahead block count */ | 
|  | 452 | xfs_btree_readahead( | 
|  | 453 | xfs_btree_cur_t		*cur,	/* btree cursor */ | 
|  | 454 | int			lev,	/* level in btree */ | 
|  | 455 | int			lr)	/* left/right bits */ | 
|  | 456 | { | 
|  | 457 | if ((cur->bc_ra[lev] | lr) == cur->bc_ra[lev]) | 
|  | 458 | return 0; | 
|  | 459 |  | 
|  | 460 | return xfs_btree_readahead_core(cur, lev, lr); | 
|  | 461 | } | 
|  | 462 |  | 
|  | 463 |  | 
|  | 464 | /* | 
|  | 465 | * Set the buffer for level "lev" in the cursor to bp, releasing | 
|  | 466 | * any previous buffer. | 
|  | 467 | */ | 
|  | 468 | void | 
|  | 469 | xfs_btree_setbuf( | 
|  | 470 | xfs_btree_cur_t		*cur,	/* btree cursor */ | 
|  | 471 | int			lev,	/* level in btree */ | 
|  | 472 | struct xfs_buf		*bp);	/* new buffer to set */ | 
|  | 473 |  | 
|  | 474 | #endif	/* __KERNEL__ */ | 
|  | 475 |  | 
|  | 476 |  | 
|  | 477 | /* | 
|  | 478 | * Min and max functions for extlen, agblock, fileoff, and filblks types. | 
|  | 479 | */ | 
|  | 480 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_EXTLEN_MIN) | 
|  | 481 | xfs_extlen_t xfs_extlen_min(xfs_extlen_t a, xfs_extlen_t b); | 
|  | 482 | #define	XFS_EXTLEN_MIN(a,b)	xfs_extlen_min(a,b) | 
|  | 483 | #else | 
|  | 484 | #define	XFS_EXTLEN_MIN(a,b)	\ | 
|  | 485 | ((xfs_extlen_t)(a) < (xfs_extlen_t)(b) ? \ | 
|  | 486 | (xfs_extlen_t)(a) : (xfs_extlen_t)(b)) | 
|  | 487 | #endif | 
|  | 488 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_EXTLEN_MAX) | 
|  | 489 | xfs_extlen_t xfs_extlen_max(xfs_extlen_t a, xfs_extlen_t b); | 
|  | 490 | #define	XFS_EXTLEN_MAX(a,b)	xfs_extlen_max(a,b) | 
|  | 491 | #else | 
|  | 492 | #define	XFS_EXTLEN_MAX(a,b)	\ | 
|  | 493 | ((xfs_extlen_t)(a) > (xfs_extlen_t)(b) ? \ | 
|  | 494 | (xfs_extlen_t)(a) : (xfs_extlen_t)(b)) | 
|  | 495 | #endif | 
|  | 496 |  | 
|  | 497 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGBLOCK_MIN) | 
|  | 498 | xfs_agblock_t xfs_agblock_min(xfs_agblock_t a, xfs_agblock_t b); | 
|  | 499 | #define	XFS_AGBLOCK_MIN(a,b)	xfs_agblock_min(a,b) | 
|  | 500 | #else | 
|  | 501 | #define	XFS_AGBLOCK_MIN(a,b)	\ | 
|  | 502 | ((xfs_agblock_t)(a) < (xfs_agblock_t)(b) ? \ | 
|  | 503 | (xfs_agblock_t)(a) : (xfs_agblock_t)(b)) | 
|  | 504 | #endif | 
|  | 505 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGBLOCK_MAX) | 
|  | 506 | xfs_agblock_t xfs_agblock_max(xfs_agblock_t a, xfs_agblock_t b); | 
|  | 507 | #define	XFS_AGBLOCK_MAX(a,b)	xfs_agblock_max(a,b) | 
|  | 508 | #else | 
|  | 509 | #define	XFS_AGBLOCK_MAX(a,b)	\ | 
|  | 510 | ((xfs_agblock_t)(a) > (xfs_agblock_t)(b) ? \ | 
|  | 511 | (xfs_agblock_t)(a) : (xfs_agblock_t)(b)) | 
|  | 512 | #endif | 
|  | 513 |  | 
|  | 514 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILEOFF_MIN) | 
|  | 515 | xfs_fileoff_t xfs_fileoff_min(xfs_fileoff_t a, xfs_fileoff_t b); | 
|  | 516 | #define	XFS_FILEOFF_MIN(a,b)	xfs_fileoff_min(a,b) | 
|  | 517 | #else | 
|  | 518 | #define	XFS_FILEOFF_MIN(a,b)	\ | 
|  | 519 | ((xfs_fileoff_t)(a) < (xfs_fileoff_t)(b) ? \ | 
|  | 520 | (xfs_fileoff_t)(a) : (xfs_fileoff_t)(b)) | 
|  | 521 | #endif | 
|  | 522 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILEOFF_MAX) | 
|  | 523 | xfs_fileoff_t xfs_fileoff_max(xfs_fileoff_t a, xfs_fileoff_t b); | 
|  | 524 | #define	XFS_FILEOFF_MAX(a,b)	xfs_fileoff_max(a,b) | 
|  | 525 | #else | 
|  | 526 | #define	XFS_FILEOFF_MAX(a,b)	\ | 
|  | 527 | ((xfs_fileoff_t)(a) > (xfs_fileoff_t)(b) ? \ | 
|  | 528 | (xfs_fileoff_t)(a) : (xfs_fileoff_t)(b)) | 
|  | 529 | #endif | 
|  | 530 |  | 
|  | 531 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILBLKS_MIN) | 
|  | 532 | xfs_filblks_t xfs_filblks_min(xfs_filblks_t a, xfs_filblks_t b); | 
|  | 533 | #define	XFS_FILBLKS_MIN(a,b)	xfs_filblks_min(a,b) | 
|  | 534 | #else | 
|  | 535 | #define	XFS_FILBLKS_MIN(a,b)	\ | 
|  | 536 | ((xfs_filblks_t)(a) < (xfs_filblks_t)(b) ? \ | 
|  | 537 | (xfs_filblks_t)(a) : (xfs_filblks_t)(b)) | 
|  | 538 | #endif | 
|  | 539 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILBLKS_MAX) | 
|  | 540 | xfs_filblks_t xfs_filblks_max(xfs_filblks_t a, xfs_filblks_t b); | 
|  | 541 | #define	XFS_FILBLKS_MAX(a,b)	xfs_filblks_max(a,b) | 
|  | 542 | #else | 
|  | 543 | #define	XFS_FILBLKS_MAX(a,b)	\ | 
|  | 544 | ((xfs_filblks_t)(a) > (xfs_filblks_t)(b) ? \ | 
|  | 545 | (xfs_filblks_t)(a) : (xfs_filblks_t)(b)) | 
|  | 546 | #endif | 
|  | 547 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FSB_SANITY_CHECK) | 
|  | 548 | int xfs_fsb_sanity_check(struct xfs_mount *mp, xfs_fsblock_t fsb); | 
|  | 549 | #define	XFS_FSB_SANITY_CHECK(mp,fsb)	xfs_fsb_sanity_check(mp,fsb) | 
|  | 550 | #else | 
|  | 551 | #define	XFS_FSB_SANITY_CHECK(mp,fsb)	\ | 
|  | 552 | (XFS_FSB_TO_AGNO(mp, fsb) < mp->m_sb.sb_agcount && \ | 
|  | 553 | XFS_FSB_TO_AGBNO(mp, fsb) < mp->m_sb.sb_agblocks) | 
|  | 554 | #endif | 
|  | 555 |  | 
|  | 556 | /* | 
|  | 557 | * Macros to set EFSCORRUPTED & return/branch. | 
|  | 558 | */ | 
|  | 559 | #define	XFS_WANT_CORRUPTED_GOTO(x,l)	\ | 
|  | 560 | { \ | 
|  | 561 | int fs_is_ok = (x); \ | 
|  | 562 | ASSERT(fs_is_ok); \ | 
|  | 563 | if (unlikely(!fs_is_ok)) { \ | 
|  | 564 | XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_GOTO", \ | 
|  | 565 | XFS_ERRLEVEL_LOW, NULL); \ | 
|  | 566 | error = XFS_ERROR(EFSCORRUPTED); \ | 
|  | 567 | goto l; \ | 
|  | 568 | } \ | 
|  | 569 | } | 
|  | 570 |  | 
|  | 571 | #define	XFS_WANT_CORRUPTED_RETURN(x)	\ | 
|  | 572 | { \ | 
|  | 573 | int fs_is_ok = (x); \ | 
|  | 574 | ASSERT(fs_is_ok); \ | 
|  | 575 | if (unlikely(!fs_is_ok)) { \ | 
|  | 576 | XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_RETURN", \ | 
|  | 577 | XFS_ERRLEVEL_LOW, NULL); \ | 
|  | 578 | return XFS_ERROR(EFSCORRUPTED); \ | 
|  | 579 | } \ | 
|  | 580 | } | 
|  | 581 |  | 
|  | 582 | #endif	/* __XFS_BTREE_H__ */ |