disable some mediatekl custom warnings
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / xfs / xfs_bmap_btree.h
CommitLineData
1da177e4 1/*
7b718769
NS
2 * Copyright (c) 2000,2002-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
1da177e4 4 *
7b718769
NS
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
1da177e4
LT
7 * published by the Free Software Foundation.
8 *
7b718769
NS
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.
1da177e4 13 *
7b718769
NS
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
1da177e4
LT
17 */
18#ifndef __XFS_BMAP_BTREE_H__
19#define __XFS_BMAP_BTREE_H__
20
ee1a47ab
CH
21#define XFS_BMAP_MAGIC 0x424d4150 /* 'BMAP' */
22#define XFS_BMAP_CRC_MAGIC 0x424d4133 /* 'BMA3' */
1da177e4
LT
23
24struct xfs_btree_cur;
136341b4 25struct xfs_btree_block;
1da177e4
LT
26struct xfs_mount;
27struct xfs_inode;
561f7d17 28struct xfs_trans;
1da177e4
LT
29
30/*
31 * Bmap root header, on-disk form only.
32 */
16259e7d
CH
33typedef struct xfs_bmdr_block {
34 __be16 bb_level; /* 0 is a leaf */
35 __be16 bb_numrecs; /* current # of data records */
1da177e4
LT
36} xfs_bmdr_block_t;
37
38/*
39 * Bmap btree record and extent descriptor.
1da177e4
LT
40 * l0:63 is an extent flag (value 1 indicates non-normal).
41 * l0:9-62 are startoff.
42 * l0:0-8 and l1:21-63 are startblock.
43 * l1:0-20 are blockcount.
44 */
1da177e4 45#define BMBT_EXNTFLAG_BITLEN 1
1da177e4 46#define BMBT_STARTOFF_BITLEN 54
1da177e4 47#define BMBT_STARTBLOCK_BITLEN 52
1da177e4
LT
48#define BMBT_BLOCKCOUNT_BITLEN 21
49
a5f9be58 50typedef struct xfs_bmbt_rec {
cd8b0a97 51 __be64 l0, l1;
a5f9be58 52} xfs_bmbt_rec_t;
1da177e4
LT
53
54typedef __uint64_t xfs_bmbt_rec_base_t; /* use this for casts */
a5f9be58 55typedef xfs_bmbt_rec_t xfs_bmdr_rec_t;
1da177e4 56
a6f64d4a
CH
57typedef struct xfs_bmbt_rec_host {
58 __uint64_t l0, l1;
59} xfs_bmbt_rec_host_t;
60
1da177e4
LT
61/*
62 * Values and macros for delayed-allocation startblock fields.
63 */
64#define STARTBLOCKVALBITS 17
65#define STARTBLOCKMASKBITS (15 + XFS_BIG_BLKNOS * 20)
66#define DSTARTBLOCKMASKBITS (15 + 20)
67#define STARTBLOCKMASK \
68 (((((xfs_fsblock_t)1) << STARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS)
69#define DSTARTBLOCKMASK \
70 (((((xfs_dfsbno_t)1) << DSTARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS)
a844f451 71
a844f451
NS
72static inline int isnullstartblock(xfs_fsblock_t x)
73{
74 return ((x) & STARTBLOCKMASK) == STARTBLOCKMASK;
75}
76
a844f451
NS
77static inline int isnulldstartblock(xfs_dfsbno_t x)
78{
79 return ((x) & DSTARTBLOCKMASK) == DSTARTBLOCKMASK;
80}
81
a844f451
NS
82static inline xfs_fsblock_t nullstartblock(int k)
83{
84 ASSERT(k < (1 << STARTBLOCKVALBITS));
85 return STARTBLOCKMASK | (k);
86}
87
a844f451
NS
88static inline xfs_filblks_t startblockval(xfs_fsblock_t x)
89{
90 return (xfs_filblks_t)((x) & ~STARTBLOCKMASK);
91}
1da177e4
LT
92
93/*
94 * Possible extent formats.
95 */
96typedef enum {
97 XFS_EXTFMT_NOSTATE = 0,
98 XFS_EXTFMT_HASSTATE
99} xfs_exntfmt_t;
100
101/*
102 * Possible extent states.
103 */
104typedef enum {
105 XFS_EXT_NORM, XFS_EXT_UNWRITTEN,
106 XFS_EXT_DMAPI_OFFLINE, XFS_EXT_INVALID
107} xfs_exntst_t;
108
109/*
110 * Extent state and extent format macros.
111 */
a844f451 112#define XFS_EXTFMT_INODE(x) \
62118709 113 (xfs_sb_version_hasextflgbit(&((x)->i_mount->m_sb)) ? \
a844f451 114 XFS_EXTFMT_HASSTATE : XFS_EXTFMT_NOSTATE)
1da177e4
LT
115#define ISUNWRITTEN(x) ((x)->br_state == XFS_EXT_UNWRITTEN)
116
117/*
118 * Incore version of above.
119 */
120typedef struct xfs_bmbt_irec
121{
122 xfs_fileoff_t br_startoff; /* starting file offset */
123 xfs_fsblock_t br_startblock; /* starting block number */
124 xfs_filblks_t br_blockcount; /* number of blocks */
125 xfs_exntst_t br_state; /* extent state */
126} xfs_bmbt_irec_t;
127
128/*
129 * Key structure for non-leaf levels of the tree.
130 */
8801bb99
CH
131typedef struct xfs_bmbt_key {
132 __be64 br_startoff; /* starting file offset */
1da177e4
LT
133} xfs_bmbt_key_t, xfs_bmdr_key_t;
134
397b5208
CH
135/* btree pointer type */
136typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t;
137
7cc95a82
CH
138/*
139 * Btree block header size depends on a superblock flag.
7cc95a82 140 */
ee1a47ab
CH
141#define XFS_BMBT_BLOCK_LEN(mp) \
142 (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
143 XFS_BTREE_LBLOCK_CRC_LEN : XFS_BTREE_LBLOCK_LEN)
1da177e4 144
136341b4
CH
145#define XFS_BMBT_REC_ADDR(mp, block, index) \
146 ((xfs_bmbt_rec_t *) \
147 ((char *)(block) + \
7cc95a82 148 XFS_BMBT_BLOCK_LEN(mp) + \
136341b4
CH
149 ((index) - 1) * sizeof(xfs_bmbt_rec_t)))
150
151#define XFS_BMBT_KEY_ADDR(mp, block, index) \
152 ((xfs_bmbt_key_t *) \
153 ((char *)(block) + \
7cc95a82 154 XFS_BMBT_BLOCK_LEN(mp) + \
136341b4
CH
155 ((index) - 1) * sizeof(xfs_bmbt_key_t)))
156
157#define XFS_BMBT_PTR_ADDR(mp, block, index, maxrecs) \
158 ((xfs_bmbt_ptr_t *) \
159 ((char *)(block) + \
7cc95a82 160 XFS_BMBT_BLOCK_LEN(mp) + \
136341b4
CH
161 (maxrecs) * sizeof(xfs_bmbt_key_t) + \
162 ((index) - 1) * sizeof(xfs_bmbt_ptr_t)))
163
164#define XFS_BMDR_REC_ADDR(block, index) \
165 ((xfs_bmdr_rec_t *) \
166 ((char *)(block) + \
167 sizeof(struct xfs_bmdr_block) + \
168 ((index) - 1) * sizeof(xfs_bmdr_rec_t)))
169
170#define XFS_BMDR_KEY_ADDR(block, index) \
171 ((xfs_bmdr_key_t *) \
172 ((char *)(block) + \
173 sizeof(struct xfs_bmdr_block) + \
174 ((index) - 1) * sizeof(xfs_bmdr_key_t)))
175
176#define XFS_BMDR_PTR_ADDR(block, index, maxrecs) \
177 ((xfs_bmdr_ptr_t *) \
178 ((char *)(block) + \
179 sizeof(struct xfs_bmdr_block) + \
180 (maxrecs) * sizeof(xfs_bmdr_key_t) + \
181 ((index) - 1) * sizeof(xfs_bmdr_ptr_t)))
1da177e4
LT
182
183/*
184 * These are to be used when we know the size of the block and
185 * we don't have a cursor.
186 */
136341b4
CH
187#define XFS_BMAP_BROOT_PTR_ADDR(mp, bb, i, sz) \
188 XFS_BMBT_PTR_ADDR(mp, bb, i, xfs_bmbt_maxrecs(mp, sz, 0))
1da177e4 189
ee1a47ab
CH
190#define XFS_BMAP_BROOT_SPACE_CALC(mp, nrecs) \
191 (int)(XFS_BMBT_BLOCK_LEN(mp) + \
a844f451
NS
192 ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
193
ee1a47ab
CH
194#define XFS_BMAP_BROOT_SPACE(mp, bb) \
195 (XFS_BMAP_BROOT_SPACE_CALC(mp, be16_to_cpu((bb)->bb_numrecs)))
a844f451
NS
196#define XFS_BMDR_SPACE_CALC(nrecs) \
197 (int)(sizeof(xfs_bmdr_block_t) + \
198 ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
1da177e4
LT
199
200/*
201 * Maximum number of bmap btree levels.
202 */
a844f451 203#define XFS_BM_MAXLEVELS(mp,w) ((mp)->m_bm_maxlevels[(w)])
1da177e4 204
1da177e4
LT
205/*
206 * Prototypes for xfs_bmap.c to call.
207 */
ee1a47ab 208extern void xfs_bmdr_to_bmbt(struct xfs_inode *, xfs_bmdr_block_t *, int,
7cc95a82 209 struct xfs_btree_block *, int);
a6f64d4a 210extern void xfs_bmbt_get_all(xfs_bmbt_rec_host_t *r, xfs_bmbt_irec_t *s);
a6f64d4a
CH
211extern xfs_filblks_t xfs_bmbt_get_blockcount(xfs_bmbt_rec_host_t *r);
212extern xfs_fsblock_t xfs_bmbt_get_startblock(xfs_bmbt_rec_host_t *r);
213extern xfs_fileoff_t xfs_bmbt_get_startoff(xfs_bmbt_rec_host_t *r);
214extern xfs_exntst_t xfs_bmbt_get_state(xfs_bmbt_rec_host_t *r);
1da177e4 215
a844f451 216extern xfs_filblks_t xfs_bmbt_disk_get_blockcount(xfs_bmbt_rec_t *r);
a844f451 217extern xfs_fileoff_t xfs_bmbt_disk_get_startoff(xfs_bmbt_rec_t *r);
1da177e4 218
a6f64d4a
CH
219extern void xfs_bmbt_set_all(xfs_bmbt_rec_host_t *r, xfs_bmbt_irec_t *s);
220extern void xfs_bmbt_set_allf(xfs_bmbt_rec_host_t *r, xfs_fileoff_t o,
a844f451 221 xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v);
a6f64d4a
CH
222extern void xfs_bmbt_set_blockcount(xfs_bmbt_rec_host_t *r, xfs_filblks_t v);
223extern void xfs_bmbt_set_startblock(xfs_bmbt_rec_host_t *r, xfs_fsblock_t v);
224extern void xfs_bmbt_set_startoff(xfs_bmbt_rec_host_t *r, xfs_fileoff_t v);
225extern void xfs_bmbt_set_state(xfs_bmbt_rec_host_t *r, xfs_exntst_t v);
1da177e4 226
a844f451
NS
227extern void xfs_bmbt_disk_set_allf(xfs_bmbt_rec_t *r, xfs_fileoff_t o,
228 xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v);
1da177e4 229
7cc95a82 230extern void xfs_bmbt_to_bmdr(struct xfs_mount *, struct xfs_btree_block *, int,
60197e8d
CH
231 xfs_bmdr_block_t *, int);
232
233extern int xfs_bmbt_get_maxrecs(struct xfs_btree_cur *, int level);
234extern int xfs_bmdr_maxrecs(struct xfs_mount *, int blocklen, int leaf);
235extern int xfs_bmbt_maxrecs(struct xfs_mount *, int blocklen, int leaf);
1da177e4 236
561f7d17
CH
237extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *,
238 struct xfs_trans *, struct xfs_inode *, int);
239
1813dd64 240extern const struct xfs_buf_ops xfs_bmbt_buf_ops;
1da177e4
LT
241
242#endif /* __XFS_BMAP_BTREE_H__ */