[XFS] Remove xfs_macros.c, xfs_macros.h, rework headers a whole lot.
[deliverable/linux.git] / fs / xfs / xfs_alloc_btree.h
CommitLineData
1da177e4
LT
1/*
2 * Copyright (c) 2000 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_ALLOC_BTREE_H__
33#define __XFS_ALLOC_BTREE_H__
34
35/*
36 * Freespace on-disk structures
37 */
38
39struct xfs_buf;
40struct xfs_btree_cur;
41struct xfs_btree_sblock;
42struct xfs_mount;
43
44/*
45 * There are two on-disk btrees, one sorted by blockno and one sorted
46 * by blockcount and blockno. All blocks look the same to make the code
47 * simpler; if we have time later, we'll make the optimizations.
48 */
49#define XFS_ABTB_MAGIC 0x41425442 /* 'ABTB' for bno tree */
50#define XFS_ABTC_MAGIC 0x41425443 /* 'ABTC' for cnt tree */
51
52/*
53 * Data record/key structure
54 */
55typedef struct xfs_alloc_rec
56{
57 xfs_agblock_t ar_startblock; /* starting block number */
58 xfs_extlen_t ar_blockcount; /* count of free blocks */
59} xfs_alloc_rec_t, xfs_alloc_key_t;
60
61typedef xfs_agblock_t xfs_alloc_ptr_t; /* btree pointer type */
62 /* btree block header type */
63typedef struct xfs_btree_sblock xfs_alloc_block_t;
64
a844f451 65#define XFS_BUF_TO_ALLOC_BLOCK(bp) ((xfs_alloc_block_t *)XFS_BUF_PTR(bp))
1da177e4
LT
66
67/*
68 * Real block structures have a size equal to the disk block size.
69 */
1da177e4 70#define XFS_ALLOC_BLOCK_SIZE(lev,cur) (1 << (cur)->bc_blocklog)
a844f451
NS
71#define XFS_ALLOC_BLOCK_MAXRECS(lev,cur) ((cur)->bc_mp->m_alloc_mxr[lev != 0])
72#define XFS_ALLOC_BLOCK_MINRECS(lev,cur) ((cur)->bc_mp->m_alloc_mnr[lev != 0])
1da177e4
LT
73
74/*
75 * Minimum and maximum blocksize and sectorsize.
76 * The blocksize upper limit is pretty much arbitrary.
77 * The sectorsize upper limit is due to sizeof(sb_sectsize).
78 */
79#define XFS_MIN_BLOCKSIZE_LOG 9 /* i.e. 512 bytes */
80#define XFS_MAX_BLOCKSIZE_LOG 16 /* i.e. 65536 bytes */
81#define XFS_MIN_BLOCKSIZE (1 << XFS_MIN_BLOCKSIZE_LOG)
82#define XFS_MAX_BLOCKSIZE (1 << XFS_MAX_BLOCKSIZE_LOG)
83#define XFS_MIN_SECTORSIZE_LOG 9 /* i.e. 512 bytes */
84#define XFS_MAX_SECTORSIZE_LOG 15 /* i.e. 32768 bytes */
85#define XFS_MIN_SECTORSIZE (1 << XFS_MIN_SECTORSIZE_LOG)
86#define XFS_MAX_SECTORSIZE (1 << XFS_MAX_SECTORSIZE_LOG)
87
88/*
89 * Block numbers in the AG:
90 * SB is sector 0, AGF is sector 1, AGI is sector 2, AGFL is sector 3.
91 */
1da177e4 92#define XFS_BNO_BLOCK(mp) ((xfs_agblock_t)(XFS_AGFL_BLOCK(mp) + 1))
1da177e4 93#define XFS_CNT_BLOCK(mp) ((xfs_agblock_t)(XFS_BNO_BLOCK(mp) + 1))
1da177e4
LT
94
95/*
96 * Record, key, and pointer address macros for btree blocks.
97 */
1da177e4 98#define XFS_ALLOC_REC_ADDR(bb,i,cur) \
a844f451
NS
99 XFS_BTREE_REC_ADDR(XFS_ALLOC_BLOCK_SIZE(0,cur), xfs_alloc, \
100 bb, i, XFS_ALLOC_BLOCK_MAXRECS(0, cur))
1da177e4 101
1da177e4 102#define XFS_ALLOC_KEY_ADDR(bb,i,cur) \
a844f451
NS
103 XFS_BTREE_KEY_ADDR(XFS_ALLOC_BLOCK_SIZE(1,cur), xfs_alloc, \
104 bb, i, XFS_ALLOC_BLOCK_MAXRECS(1, cur))
1da177e4 105
1da177e4 106#define XFS_ALLOC_PTR_ADDR(bb,i,cur) \
a844f451
NS
107 XFS_BTREE_PTR_ADDR(XFS_ALLOC_BLOCK_SIZE(1,cur), xfs_alloc, \
108 bb, i, XFS_ALLOC_BLOCK_MAXRECS(1, cur))
1da177e4
LT
109
110/*
111 * Decrement cursor by one record at the level.
112 * For nonzero levels the leaf-ward information is untouched.
113 */
a844f451 114extern int xfs_alloc_decrement(struct xfs_btree_cur *cur, int level, int *stat);
1da177e4
LT
115
116/*
117 * Delete the record pointed to by cur.
118 * The cursor refers to the place where the record was (could be inserted)
119 * when the operation returns.
120 */
a844f451 121extern int xfs_alloc_delete(struct xfs_btree_cur *cur, int *stat);
1da177e4
LT
122
123/*
124 * Get the data from the pointed-to record.
125 */
a844f451
NS
126extern int xfs_alloc_get_rec(struct xfs_btree_cur *cur, xfs_agblock_t *bno,
127 xfs_extlen_t *len, int *stat);
1da177e4
LT
128
129/*
130 * Increment cursor by one record at the level.
131 * For nonzero levels the leaf-ward information is untouched.
132 */
a844f451 133extern int xfs_alloc_increment(struct xfs_btree_cur *cur, int level, int *stat);
1da177e4
LT
134
135/*
136 * Insert the current record at the point referenced by cur.
137 * The cursor may be inconsistent on return if splits have been done.
138 */
a844f451 139extern int xfs_alloc_insert(struct xfs_btree_cur *cur, int *stat);
1da177e4
LT
140
141/*
142 * Lookup the record equal to [bno, len] in the btree given by cur.
143 */
a844f451
NS
144extern int xfs_alloc_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno,
145 xfs_extlen_t len, int *stat);
1da177e4
LT
146
147/*
148 * Lookup the first record greater than or equal to [bno, len]
149 * in the btree given by cur.
150 */
a844f451
NS
151extern int xfs_alloc_lookup_ge(struct xfs_btree_cur *cur, xfs_agblock_t bno,
152 xfs_extlen_t len, int *stat);
1da177e4
LT
153
154/*
155 * Lookup the first record less than or equal to [bno, len]
156 * in the btree given by cur.
157 */
a844f451
NS
158extern int xfs_alloc_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno,
159 xfs_extlen_t len, int *stat);
1da177e4
LT
160
161/*
162 * Update the record referred to by cur, to the value given by [bno, len].
163 * This either works (return 0) or gets an EFSCORRUPTED error.
164 */
a844f451
NS
165extern int xfs_alloc_update(struct xfs_btree_cur *cur, xfs_agblock_t bno,
166 xfs_extlen_t len);
1da177e4
LT
167
168#endif /* __XFS_ALLOC_BTREE_H__ */
This page took 0.121231 seconds and 5 git commands to generate.