blob: 5615ebba6a3a070c59c6715f34c8704c4774962f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * 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 Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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 Torvalds1da177e2005-04-16 15:20:36 -070017 */
18#ifndef __XFS_ALLOC_BTREE_H__
19#define __XFS_ALLOC_BTREE_H__
20
21/*
22 * Freespace on-disk structures
23 */
24
25struct xfs_buf;
26struct xfs_btree_cur;
27struct xfs_btree_sblock;
28struct xfs_mount;
29
30/*
31 * There are two on-disk btrees, one sorted by blockno and one sorted
32 * by blockcount and blockno. All blocks look the same to make the code
33 * simpler; if we have time later, we'll make the optimizations.
34 */
35#define XFS_ABTB_MAGIC 0x41425442 /* 'ABTB' for bno tree */
36#define XFS_ABTC_MAGIC 0x41425443 /* 'ABTC' for cnt tree */
37
38/*
39 * Data record/key structure
40 */
41typedef struct xfs_alloc_rec
42{
43 xfs_agblock_t ar_startblock; /* starting block number */
44 xfs_extlen_t ar_blockcount; /* count of free blocks */
45} xfs_alloc_rec_t, xfs_alloc_key_t;
46
47typedef xfs_agblock_t xfs_alloc_ptr_t; /* btree pointer type */
48 /* btree block header type */
49typedef struct xfs_btree_sblock xfs_alloc_block_t;
50
Nathan Scotta844f452005-11-02 14:38:42 +110051#define XFS_BUF_TO_ALLOC_BLOCK(bp) ((xfs_alloc_block_t *)XFS_BUF_PTR(bp))
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/*
54 * Real block structures have a size equal to the disk block size.
55 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#define XFS_ALLOC_BLOCK_SIZE(lev,cur) (1 << (cur)->bc_blocklog)
Nathan Scotta844f452005-11-02 14:38:42 +110057#define XFS_ALLOC_BLOCK_MAXRECS(lev,cur) ((cur)->bc_mp->m_alloc_mxr[lev != 0])
58#define XFS_ALLOC_BLOCK_MINRECS(lev,cur) ((cur)->bc_mp->m_alloc_mnr[lev != 0])
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60/*
61 * Minimum and maximum blocksize and sectorsize.
62 * The blocksize upper limit is pretty much arbitrary.
63 * The sectorsize upper limit is due to sizeof(sb_sectsize).
64 */
65#define XFS_MIN_BLOCKSIZE_LOG 9 /* i.e. 512 bytes */
66#define XFS_MAX_BLOCKSIZE_LOG 16 /* i.e. 65536 bytes */
67#define XFS_MIN_BLOCKSIZE (1 << XFS_MIN_BLOCKSIZE_LOG)
68#define XFS_MAX_BLOCKSIZE (1 << XFS_MAX_BLOCKSIZE_LOG)
69#define XFS_MIN_SECTORSIZE_LOG 9 /* i.e. 512 bytes */
70#define XFS_MAX_SECTORSIZE_LOG 15 /* i.e. 32768 bytes */
71#define XFS_MIN_SECTORSIZE (1 << XFS_MIN_SECTORSIZE_LOG)
72#define XFS_MAX_SECTORSIZE (1 << XFS_MAX_SECTORSIZE_LOG)
73
74/*
75 * Block numbers in the AG:
76 * SB is sector 0, AGF is sector 1, AGI is sector 2, AGFL is sector 3.
77 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define XFS_BNO_BLOCK(mp) ((xfs_agblock_t)(XFS_AGFL_BLOCK(mp) + 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#define XFS_CNT_BLOCK(mp) ((xfs_agblock_t)(XFS_BNO_BLOCK(mp) + 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81/*
82 * Record, key, and pointer address macros for btree blocks.
83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#define XFS_ALLOC_REC_ADDR(bb,i,cur) \
Nathan Scotta844f452005-11-02 14:38:42 +110085 XFS_BTREE_REC_ADDR(XFS_ALLOC_BLOCK_SIZE(0,cur), xfs_alloc, \
86 bb, i, XFS_ALLOC_BLOCK_MAXRECS(0, cur))
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define XFS_ALLOC_KEY_ADDR(bb,i,cur) \
Nathan Scotta844f452005-11-02 14:38:42 +110089 XFS_BTREE_KEY_ADDR(XFS_ALLOC_BLOCK_SIZE(1,cur), xfs_alloc, \
90 bb, i, XFS_ALLOC_BLOCK_MAXRECS(1, cur))
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#define XFS_ALLOC_PTR_ADDR(bb,i,cur) \
Nathan Scotta844f452005-11-02 14:38:42 +110093 XFS_BTREE_PTR_ADDR(XFS_ALLOC_BLOCK_SIZE(1,cur), xfs_alloc, \
94 bb, i, XFS_ALLOC_BLOCK_MAXRECS(1, cur))
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96/*
97 * Decrement cursor by one record at the level.
98 * For nonzero levels the leaf-ward information is untouched.
99 */
Nathan Scotta844f452005-11-02 14:38:42 +1100100extern int xfs_alloc_decrement(struct xfs_btree_cur *cur, int level, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102/*
103 * Delete the record pointed to by cur.
104 * The cursor refers to the place where the record was (could be inserted)
105 * when the operation returns.
106 */
Nathan Scotta844f452005-11-02 14:38:42 +1100107extern int xfs_alloc_delete(struct xfs_btree_cur *cur, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109/*
110 * Get the data from the pointed-to record.
111 */
Nathan Scotta844f452005-11-02 14:38:42 +1100112extern int xfs_alloc_get_rec(struct xfs_btree_cur *cur, xfs_agblock_t *bno,
113 xfs_extlen_t *len, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115/*
116 * Increment cursor by one record at the level.
117 * For nonzero levels the leaf-ward information is untouched.
118 */
Nathan Scotta844f452005-11-02 14:38:42 +1100119extern int xfs_alloc_increment(struct xfs_btree_cur *cur, int level, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121/*
122 * Insert the current record at the point referenced by cur.
123 * The cursor may be inconsistent on return if splits have been done.
124 */
Nathan Scotta844f452005-11-02 14:38:42 +1100125extern int xfs_alloc_insert(struct xfs_btree_cur *cur, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127/*
128 * Lookup the record equal to [bno, len] in the btree given by cur.
129 */
Nathan Scotta844f452005-11-02 14:38:42 +1100130extern int xfs_alloc_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno,
131 xfs_extlen_t len, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/*
134 * Lookup the first record greater than or equal to [bno, len]
135 * in the btree given by cur.
136 */
Nathan Scotta844f452005-11-02 14:38:42 +1100137extern int xfs_alloc_lookup_ge(struct xfs_btree_cur *cur, xfs_agblock_t bno,
138 xfs_extlen_t len, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140/*
141 * Lookup the first record less than or equal to [bno, len]
142 * in the btree given by cur.
143 */
Nathan Scotta844f452005-11-02 14:38:42 +1100144extern int xfs_alloc_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno,
145 xfs_extlen_t len, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147/*
148 * Update the record referred to by cur, to the value given by [bno, len].
149 * This either works (return 0) or gets an EFSCORRUPTED error.
150 */
Nathan Scotta844f452005-11-02 14:38:42 +1100151extern int xfs_alloc_update(struct xfs_btree_cur *cur, xfs_agblock_t bno,
152 xfs_extlen_t len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154#endif /* __XFS_ALLOC_BTREE_H__ */