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