fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / fs / xfs / xfs_ialloc_btree.h
1 /*
2  * Copyright (c) 2000,2005 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
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
7  * published by the Free Software Foundation.
8  *
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.
13  *
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
17  */
18 #ifndef __XFS_IALLOC_BTREE_H__
19 #define __XFS_IALLOC_BTREE_H__
20
21 /*
22  * Inode map on-disk structures
23  */
24
25 struct xfs_buf;
26 struct xfs_btree_cur;
27 struct xfs_btree_sblock;
28 struct xfs_mount;
29
30 /*
31  * There is a btree for the inode map per allocation group.
32  */
33 #define XFS_IBT_MAGIC   0x49414254      /* 'IABT' */
34
35 typedef __uint64_t      xfs_inofree_t;
36 #define XFS_INODES_PER_CHUNK    (NBBY * sizeof(xfs_inofree_t))
37 #define XFS_INODES_PER_CHUNK_LOG        (XFS_NBBYLOG + 3)
38 #define XFS_INOBT_ALL_FREE      ((xfs_inofree_t)-1)
39
40 #define XFS_INOBT_MASKN(i,n)            xfs_inobt_maskn(i,n)
41 static inline xfs_inofree_t xfs_inobt_maskn(int i, int n)
42 {
43         return (((n) >= XFS_INODES_PER_CHUNK ? \
44                 (xfs_inofree_t)0 : ((xfs_inofree_t)1 << (n))) - 1) << (i);
45 }
46
47 /*
48  * Data record structure
49  */
50 typedef struct xfs_inobt_rec {
51         __be32          ir_startino;    /* starting inode number */
52         __be32          ir_freecount;   /* count of free inodes (set bits) */
53         __be64          ir_free;        /* free inode mask */
54 } xfs_inobt_rec_t;
55
56 typedef struct xfs_inobt_rec_incore {
57         xfs_agino_t     ir_startino;    /* starting inode number */
58         __int32_t       ir_freecount;   /* count of free inodes (set bits) */
59         xfs_inofree_t   ir_free;        /* free inode mask */
60 } xfs_inobt_rec_incore_t;
61
62
63 /*
64  * Key structure
65  */
66 typedef struct xfs_inobt_key {
67         __be32          ir_startino;    /* starting inode number */
68 } xfs_inobt_key_t;
69
70 /* btree pointer type */
71 typedef __be32 xfs_inobt_ptr_t;
72
73 /* btree block header type */
74 typedef struct xfs_btree_sblock xfs_inobt_block_t;
75
76 #define XFS_BUF_TO_INOBT_BLOCK(bp)      ((xfs_inobt_block_t *)XFS_BUF_PTR(bp))
77
78 /*
79  * Bit manipulations for ir_free.
80  */
81 #define XFS_INOBT_MASK(i)               ((xfs_inofree_t)1 << (i))
82 #define XFS_INOBT_IS_FREE(rp,i)         \
83                 (((rp)->ir_free & XFS_INOBT_MASK(i)) != 0)
84 #define XFS_INOBT_IS_FREE_DISK(rp,i)    \
85                 ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0)
86 #define XFS_INOBT_SET_FREE(rp,i)        ((rp)->ir_free |= XFS_INOBT_MASK(i))
87 #define XFS_INOBT_CLR_FREE(rp,i)        ((rp)->ir_free &= ~XFS_INOBT_MASK(i))
88
89 /*
90  * Real block structures have a size equal to the disk block size.
91  */
92 #define XFS_INOBT_BLOCK_SIZE(lev,cur)   (1 << (cur)->bc_blocklog)
93 #define XFS_INOBT_BLOCK_MAXRECS(lev,cur) ((cur)->bc_mp->m_inobt_mxr[lev != 0])
94 #define XFS_INOBT_BLOCK_MINRECS(lev,cur) ((cur)->bc_mp->m_inobt_mnr[lev != 0])
95 #define XFS_INOBT_IS_LAST_REC(cur)      \
96         ((cur)->bc_ptrs[0] == be16_to_cpu(XFS_BUF_TO_INOBT_BLOCK((cur)->bc_bufs[0])->bb_numrecs))
97
98 /*
99  * Maximum number of inode btree levels.
100  */
101 #define XFS_IN_MAXLEVELS(mp)            ((mp)->m_in_maxlevels)
102
103 /*
104  * block numbers in the AG.
105  */
106 #define XFS_IBT_BLOCK(mp)               ((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1))
107 #define XFS_PREALLOC_BLOCKS(mp)         ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))
108
109 /*
110  * Record, key, and pointer address macros for btree blocks.
111  */
112 #define XFS_INOBT_REC_ADDR(bb,i,cur) \
113         (XFS_BTREE_REC_ADDR(XFS_INOBT_BLOCK_SIZE(0,cur), xfs_inobt, bb, \
114                                 i, XFS_INOBT_BLOCK_MAXRECS(0, cur)))
115 #define XFS_INOBT_KEY_ADDR(bb,i,cur) \
116         (XFS_BTREE_KEY_ADDR(XFS_INOBT_BLOCK_SIZE(1,cur), xfs_inobt, bb, \
117                                 i, XFS_INOBT_BLOCK_MAXRECS(1, cur)))
118
119 #define XFS_INOBT_PTR_ADDR(bb,i,cur) \
120         (XFS_BTREE_PTR_ADDR(XFS_INOBT_BLOCK_SIZE(1,cur), xfs_inobt, bb, \
121                                 i, XFS_INOBT_BLOCK_MAXRECS(1, cur)))
122
123 /*
124  * Decrement cursor by one record at the level.
125  * For nonzero levels the leaf-ward information is untouched.
126  */
127 extern int xfs_inobt_decrement(struct xfs_btree_cur *cur, int level, int *stat);
128
129 /*
130  * Delete the record pointed to by cur.
131  * The cursor refers to the place where the record was (could be inserted)
132  * when the operation returns.
133  */
134 extern int xfs_inobt_delete(struct xfs_btree_cur *cur, int *stat);
135
136 /*
137  * Get the data from the pointed-to record.
138  */
139 extern int xfs_inobt_get_rec(struct xfs_btree_cur *cur, xfs_agino_t *ino,
140                              __int32_t *fcnt, xfs_inofree_t *free, int *stat);
141
142 /*
143  * Increment cursor by one record at the level.
144  * For nonzero levels the leaf-ward information is untouched.
145  */
146 extern int xfs_inobt_increment(struct xfs_btree_cur *cur, int level, int *stat);
147
148 /*
149  * Insert the current record at the point referenced by cur.
150  * The cursor may be inconsistent on return if splits have been done.
151  */
152 extern int xfs_inobt_insert(struct xfs_btree_cur *cur, int *stat);
153
154 /*
155  * Lookup the record equal to ino in the btree given by cur.
156  */
157 extern int xfs_inobt_lookup_eq(struct xfs_btree_cur *cur, xfs_agino_t ino,
158                                 __int32_t fcnt, xfs_inofree_t free, int *stat);
159
160 /*
161  * Lookup the first record greater than or equal to ino
162  * in the btree given by cur.
163  */
164 extern int xfs_inobt_lookup_ge(struct xfs_btree_cur *cur, xfs_agino_t ino,
165                                 __int32_t fcnt, xfs_inofree_t free, int *stat);
166
167 /*
168  * Lookup the first record less than or equal to ino
169  * in the btree given by cur.
170  */
171 extern int xfs_inobt_lookup_le(struct xfs_btree_cur *cur, xfs_agino_t ino,
172                                 __int32_t fcnt, xfs_inofree_t free, int *stat);
173
174 /*
175  * Update the record referred to by cur, to the value given
176  * by [ino, fcnt, free].
177  * This either works (return 0) or gets an EFSCORRUPTED error.
178  */
179 extern int xfs_inobt_update(struct xfs_btree_cur *cur, xfs_agino_t ino,
180                                 __int32_t fcnt, xfs_inofree_t free);
181
182 #endif  /* __XFS_IALLOC_BTREE_H__ */