]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/xfs_ag.h
cmd/xfs/bmap/Makefile 1.8 Renamed to cmd/xfsprogs/bmap/Makefile
[thirdparty/xfsprogs-dev.git] / include / xfs_ag.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_AG_H__
33 #define __XFS_AG_H__
34
35 /*
36 * Allocation group header
37 * This is divided into three structures, placed in sequential 512-byte
38 * buffers after a copy of the superblock (also in a 512-byte buffer).
39 */
40
41 struct xfs_buf;
42 struct xfs_mount;
43
44 #define XFS_AGF_MAGIC 0x58414746 /* 'XAGF' */
45 #define XFS_AGI_MAGIC 0x58414749 /* 'XAGI' */
46 #define XFS_AGF_VERSION 1
47 #define XFS_AGI_VERSION 1
48 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGF_GOOD_VERSION)
49 int xfs_agf_good_version(unsigned v);
50 #define XFS_AGF_GOOD_VERSION(v) xfs_agf_good_version(v)
51 #else
52 #define XFS_AGF_GOOD_VERSION(v) ((v) == XFS_AGF_VERSION)
53 #endif
54 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGI_GOOD_VERSION)
55 int xfs_agi_good_version(unsigned v);
56 #define XFS_AGI_GOOD_VERSION(v) xfs_agi_good_version(v)
57 #else
58 #define XFS_AGI_GOOD_VERSION(v) ((v) == XFS_AGI_VERSION)
59 #endif
60
61 /*
62 * Btree number 0 is bno, 1 is cnt. This value gives the size of the
63 * arrays below.
64 */
65 #define XFS_BTNUM_AGF ((int)XFS_BTNUM_CNTi + 1)
66
67 /*
68 * The second word of agf_levels in the first a.g. overlaps the EFS
69 * superblock's magic number. Since the magic numbers valid for EFS
70 * are > 64k, our value cannot be confused for an EFS superblock's.
71 */
72
73 typedef struct xfs_agf
74 {
75 /*
76 * Common allocation group header information
77 */
78 __uint32_t agf_magicnum; /* magic number == XFS_AGF_MAGIC */
79 __uint32_t agf_versionnum; /* header version == XFS_AGF_VERSION */
80 xfs_agnumber_t agf_seqno; /* sequence # starting from 0 */
81 xfs_agblock_t agf_length; /* size in blocks of a.g. */
82 /*
83 * Freespace information
84 */
85 xfs_agblock_t agf_roots[XFS_BTNUM_AGF]; /* root blocks */
86 __uint32_t agf_spare0; /* spare field */
87 __uint32_t agf_levels[XFS_BTNUM_AGF]; /* btree levels */
88 __uint32_t agf_spare1; /* spare field */
89 __uint32_t agf_flfirst; /* first freelist block's index */
90 __uint32_t agf_fllast; /* last freelist block's index */
91 __uint32_t agf_flcount; /* count of blocks in freelist */
92 xfs_extlen_t agf_freeblks; /* total free blocks */
93 xfs_extlen_t agf_longest; /* longest free space */
94 } xfs_agf_t;
95
96 #define XFS_AGF_MAGICNUM 0x00000001
97 #define XFS_AGF_VERSIONNUM 0x00000002
98 #define XFS_AGF_SEQNO 0x00000004
99 #define XFS_AGF_LENGTH 0x00000008
100 #define XFS_AGF_ROOTS 0x00000010
101 #define XFS_AGF_LEVELS 0x00000020
102 #define XFS_AGF_FLFIRST 0x00000040
103 #define XFS_AGF_FLLAST 0x00000080
104 #define XFS_AGF_FLCOUNT 0x00000100
105 #define XFS_AGF_FREEBLKS 0x00000200
106 #define XFS_AGF_LONGEST 0x00000400
107 #define XFS_AGF_NUM_BITS 11
108 #define XFS_AGF_ALL_BITS ((1 << XFS_AGF_NUM_BITS) - 1)
109
110 /* disk block (xfs_daddr_t) in the AG */
111 #define XFS_AGF_DADDR ((xfs_daddr_t)1)
112 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGF_BLOCK)
113 xfs_agblock_t xfs_agf_block(struct xfs_mount *mp);
114 #define XFS_AGF_BLOCK(mp) xfs_agf_block(mp)
115 #else
116 #define XFS_AGF_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGF_DADDR)
117 #endif
118
119 /*
120 * Size of the unlinked inode hash table in the agi.
121 */
122 #define XFS_AGI_UNLINKED_BUCKETS 64
123
124 typedef struct xfs_agi
125 {
126 /*
127 * Common allocation group header information
128 */
129 __uint32_t agi_magicnum; /* magic number == XFS_AGI_MAGIC */
130 __uint32_t agi_versionnum; /* header version == XFS_AGI_VERSION */
131 xfs_agnumber_t agi_seqno; /* sequence # starting from 0 */
132 xfs_agblock_t agi_length; /* size in blocks of a.g. */
133 /*
134 * Inode information
135 * Inodes are mapped by interpreting the inode number, so no
136 * mapping data is needed here.
137 */
138 xfs_agino_t agi_count; /* count of allocated inodes */
139 xfs_agblock_t agi_root; /* root of inode btree */
140 __uint32_t agi_level; /* levels in inode btree */
141 xfs_agino_t agi_freecount; /* number of free inodes */
142 xfs_agino_t agi_newino; /* new inode just allocated */
143 xfs_agino_t agi_dirino; /* last directory inode chunk */
144 /*
145 * Hash table of inodes which have been unlinked but are
146 * still being referenced.
147 */
148 xfs_agino_t agi_unlinked[XFS_AGI_UNLINKED_BUCKETS];
149 } xfs_agi_t;
150
151 #define XFS_AGI_MAGICNUM 0x00000001
152 #define XFS_AGI_VERSIONNUM 0x00000002
153 #define XFS_AGI_SEQNO 0x00000004
154 #define XFS_AGI_LENGTH 0x00000008
155 #define XFS_AGI_COUNT 0x00000010
156 #define XFS_AGI_ROOT 0x00000020
157 #define XFS_AGI_LEVEL 0x00000040
158 #define XFS_AGI_FREECOUNT 0x00000080
159 #define XFS_AGI_NEWINO 0x00000100
160 #define XFS_AGI_DIRINO 0x00000200
161 #define XFS_AGI_UNLINKED 0x00000400
162 #define XFS_AGI_NUM_BITS 11
163 #define XFS_AGI_ALL_BITS ((1 << XFS_AGI_NUM_BITS) - 1)
164
165 /* disk block (xfs_daddr_t) in the AG */
166 #define XFS_AGI_DADDR ((xfs_daddr_t)2)
167 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGI_BLOCK)
168 xfs_agblock_t xfs_agi_block(struct xfs_mount *mp);
169 #define XFS_AGI_BLOCK(mp) xfs_agi_block(mp)
170 #else
171 #define XFS_AGI_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGI_DADDR)
172 #endif
173
174 /*
175 * The third a.g. block contains the a.g. freelist, an array
176 * of block pointers to blocks owned by the allocation btree code.
177 */
178 #define XFS_AGFL_DADDR ((xfs_daddr_t)3)
179 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGFL_BLOCK)
180 xfs_agblock_t xfs_agfl_block(struct xfs_mount *mp);
181 #define XFS_AGFL_BLOCK(mp) xfs_agfl_block(mp)
182 #else
183 #define XFS_AGFL_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGFL_DADDR)
184 #endif
185 #define XFS_AGFL_SIZE (BBSIZE / sizeof(xfs_agblock_t))
186 typedef struct xfs_agfl
187 {
188 xfs_agblock_t agfl_bno[XFS_AGFL_SIZE];
189 } xfs_agfl_t;
190
191 /*
192 * Per-ag incore structure, copies of information in agf and agi,
193 * to improve the performance of allocation group selection.
194 */
195 typedef struct xfs_perag
196 {
197 char pagf_init; /* this agf's entry is initialized */
198 char pagi_init; /* this agi's entry is initialized */
199 __uint8_t pagf_levels[XFS_BTNUM_AGF];
200 /* # of levels in bno & cnt btree */
201 __uint32_t pagf_flcount; /* count of blocks in freelist */
202 xfs_extlen_t pagf_freeblks; /* total free blocks */
203 xfs_extlen_t pagf_longest; /* longest free space */
204 xfs_agino_t pagi_freecount; /* number of free inodes */
205 } xfs_perag_t;
206
207 #define XFS_AG_MIN_BYTES (1LL << 24) /* 16 MB */
208 #define XFS_AG_BEST_BYTES (1LL << 30) /* 1 GB */
209 #define XFS_AG_MAX_BYTES (1LL << 32) /* 4 GB */
210
211 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AG_MIN_BLOCKS)
212 xfs_extlen_t xfs_ag_min_blocks(int bl);
213 #define XFS_AG_MIN_BLOCKS(bl) xfs_ag_min_blocks(bl)
214 #else
215 #define XFS_AG_MIN_BLOCKS(bl) ((xfs_extlen_t)(XFS_AG_MIN_BYTES >> bl))
216 #endif
217 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AG_BEST_BLOCKS)
218 xfs_extlen_t xfs_ag_best_blocks(int bl);
219 #define XFS_AG_BEST_BLOCKS(bl) xfs_ag_best_blocks(bl)
220 #else
221 #define XFS_AG_BEST_BLOCKS(bl) ((xfs_extlen_t)(XFS_AG_BEST_BYTES >> bl))
222 #endif
223 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AG_MAX_BLOCKS)
224 xfs_extlen_t xfs_ag_max_blocks(int bl);
225 #define XFS_AG_MAX_BLOCKS(bl) xfs_ag_max_blocks(bl)
226 #else
227 #define XFS_AG_MAX_BLOCKS(bl) ((xfs_extlen_t)(XFS_AG_MAX_BYTES >> bl))
228 #endif
229
230 #define XFS_MAX_AGNUMBER ((xfs_agnumber_t)(NULLAGNUMBER - 1))
231
232 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AG_MAXLEVELS)
233 int xfs_ag_maxlevels(struct xfs_mount *mp);
234 #define XFS_AG_MAXLEVELS(mp) xfs_ag_maxlevels(mp)
235 #else
236 #define XFS_AG_MAXLEVELS(mp) ((mp)->m_ag_maxlevels)
237 #endif
238 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_MIN_FREELIST)
239 int xfs_min_freelist(xfs_agf_t *a, struct xfs_mount *mp);
240 #define XFS_MIN_FREELIST(a,mp) xfs_min_freelist(a,mp)
241 #else
242 #define XFS_MIN_FREELIST(a,mp) \
243 XFS_MIN_FREELIST_RAW( \
244 INT_GET((a)->agf_levels[XFS_BTNUM_BNOi], ARCH_CONVERT), \
245 INT_GET((a)->agf_levels[XFS_BTNUM_CNTi], ARCH_CONVERT), mp)
246 #endif
247 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_MIN_FREELIST_PAG)
248 int xfs_min_freelist_pag(xfs_perag_t *pag, struct xfs_mount *mp);
249 #define XFS_MIN_FREELIST_PAG(pag,mp) xfs_min_freelist_pag(pag,mp)
250 #else
251 #define XFS_MIN_FREELIST_PAG(pag,mp) \
252 XFS_MIN_FREELIST_RAW((pag)->pagf_levels[XFS_BTNUM_BNOi], \
253 (pag)->pagf_levels[XFS_BTNUM_CNTi], mp)
254 #endif
255 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_MIN_FREELIST_RAW)
256 int xfs_min_freelist_raw(int bl, int cl, struct xfs_mount *mp);
257 #define XFS_MIN_FREELIST_RAW(bl,cl,mp) xfs_min_freelist_raw(bl,cl,mp)
258 #else
259 #define XFS_MIN_FREELIST_RAW(bl,cl,mp) \
260 (MIN(bl + 1, XFS_AG_MAXLEVELS(mp)) + \
261 MIN(cl + 1, XFS_AG_MAXLEVELS(mp)))
262 #endif
263
264 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGB_TO_FSB)
265 xfs_fsblock_t xfs_agb_to_fsb(struct xfs_mount *mp, xfs_agnumber_t agno,
266 xfs_agblock_t agbno);
267 #define XFS_AGB_TO_FSB(mp,agno,agbno) xfs_agb_to_fsb(mp,agno,agbno)
268 #else
269 #define XFS_AGB_TO_FSB(mp,agno,agbno) \
270 (((xfs_fsblock_t)(agno) << (mp)->m_sb.sb_agblklog) | (agbno))
271 #endif
272 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FSB_TO_AGNO)
273 xfs_agnumber_t xfs_fsb_to_agno(struct xfs_mount *mp, xfs_fsblock_t fsbno);
274 #define XFS_FSB_TO_AGNO(mp,fsbno) xfs_fsb_to_agno(mp,fsbno)
275 #else
276 #define XFS_FSB_TO_AGNO(mp,fsbno) \
277 ((xfs_agnumber_t)((fsbno) >> (mp)->m_sb.sb_agblklog))
278 #endif
279 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FSB_TO_AGBNO)
280 xfs_agblock_t xfs_fsb_to_agbno(struct xfs_mount *mp, xfs_fsblock_t fsbno);
281 #define XFS_FSB_TO_AGBNO(mp,fsbno) xfs_fsb_to_agbno(mp,fsbno)
282 #else
283 #define XFS_FSB_TO_AGBNO(mp,fsbno) \
284 ((xfs_agblock_t)((fsbno) & XFS_MASK32LO((mp)->m_sb.sb_agblklog)))
285 #endif
286
287 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGB_TO_DADDR)
288 xfs_daddr_t xfs_agb_to_daddr(struct xfs_mount *mp, xfs_agnumber_t agno,
289 xfs_agblock_t agbno);
290 #define XFS_AGB_TO_DADDR(mp,agno,agbno) xfs_agb_to_daddr(mp,agno,agbno)
291 #else
292 #define XFS_AGB_TO_DADDR(mp,agno,agbno) \
293 ((xfs_daddr_t)(XFS_FSB_TO_BB(mp, \
294 (xfs_fsblock_t)(agno) * (mp)->m_sb.sb_agblocks + (agbno))))
295 #endif
296 /*
297 * XFS_DADDR_TO_AGNO and XFS_DADDR_TO_AGBNO moved to xfs_mount.h
298 * to avoid header file ordering change
299 */
300
301 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AG_DADDR)
302 xfs_daddr_t xfs_ag_daddr(struct xfs_mount *mp, xfs_agnumber_t agno, xfs_daddr_t d);
303 #define XFS_AG_DADDR(mp,agno,d) xfs_ag_daddr(mp,agno,d)
304 #else
305 #define XFS_AG_DADDR(mp,agno,d) (XFS_AGB_TO_DADDR(mp, agno, 0) + (d))
306 #endif
307
308 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_AGF)
309 xfs_agf_t *xfs_buf_to_agf(struct xfs_buf *bp);
310 #define XFS_BUF_TO_AGF(bp) xfs_buf_to_agf(bp)
311 #else
312 #define XFS_BUF_TO_AGF(bp) ((xfs_agf_t *)XFS_BUF_PTR(bp))
313 #endif
314 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_AGI)
315 xfs_agi_t *xfs_buf_to_agi(struct xfs_buf *bp);
316 #define XFS_BUF_TO_AGI(bp) xfs_buf_to_agi(bp)
317 #else
318 #define XFS_BUF_TO_AGI(bp) ((xfs_agi_t *)XFS_BUF_PTR(bp))
319 #endif
320 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_AGFL)
321 xfs_agfl_t *xfs_buf_to_agfl(struct xfs_buf *bp);
322 #define XFS_BUF_TO_AGFL(bp) xfs_buf_to_agfl(bp)
323 #else
324 #define XFS_BUF_TO_AGFL(bp) ((xfs_agfl_t *)XFS_BUF_PTR(bp))
325 #endif
326
327 /*
328 * For checking for bad ranges of xfs_daddr_t's, covering multiple
329 * allocation groups or a single xfs_daddr_t that's a superblock copy.
330 */
331 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AG_CHECK_DADDR)
332 void xfs_ag_check_daddr(struct xfs_mount *mp, xfs_daddr_t d, xfs_extlen_t len);
333 #define XFS_AG_CHECK_DADDR(mp,d,len) xfs_ag_check_daddr(mp,d,len)
334 #else
335 #define XFS_AG_CHECK_DADDR(mp,d,len) \
336 ((len) == 1 ? \
337 ASSERT((d) == XFS_SB_DADDR || \
338 XFS_DADDR_TO_AGBNO(mp, d) != XFS_SB_DADDR) : \
339 ASSERT(XFS_DADDR_TO_AGNO(mp, d) == \
340 XFS_DADDR_TO_AGNO(mp, (d) + (len) - 1)))
341 #endif
342
343 #endif /* __XFS_AG_H__ */