2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
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).
45 #define XFS_AGF_MAGIC 0x58414746 /* 'XAGF' */
46 #define XFS_AGI_MAGIC 0x58414749 /* 'XAGI' */
47 #define XFS_AGF_VERSION 1
48 #define XFS_AGI_VERSION 1
50 #define XFS_AGF_GOOD_VERSION(v) ((v) == XFS_AGF_VERSION)
51 #define XFS_AGI_GOOD_VERSION(v) ((v) == XFS_AGI_VERSION)
54 * Btree number 0 is bno, 1 is cnt. This value gives the size of the
57 #define XFS_BTNUM_AGF ((int)XFS_BTNUM_CNTi + 1)
60 * The second word of agf_levels in the first a.g. overlaps the EFS
61 * superblock's magic number. Since the magic numbers valid for EFS
62 * are > 64k, our value cannot be confused for an EFS superblock's.
65 typedef struct xfs_agf
68 * Common allocation group header information
70 __uint32_t agf_magicnum
; /* magic number == XFS_AGF_MAGIC */
71 __uint32_t agf_versionnum
; /* header version == XFS_AGF_VERSION */
72 xfs_agnumber_t agf_seqno
; /* sequence # starting from 0 */
73 xfs_agblock_t agf_length
; /* size in blocks of a.g. */
75 * Freespace information
77 xfs_agblock_t agf_roots
[XFS_BTNUM_AGF
]; /* root blocks */
78 __uint32_t agf_spare0
; /* spare field */
79 __uint32_t agf_levels
[XFS_BTNUM_AGF
]; /* btree levels */
80 __uint32_t agf_spare1
; /* spare field */
81 __uint32_t agf_flfirst
; /* first freelist block's index */
82 __uint32_t agf_fllast
; /* last freelist block's index */
83 __uint32_t agf_flcount
; /* count of blocks in freelist */
84 xfs_extlen_t agf_freeblks
; /* total free blocks */
85 xfs_extlen_t agf_longest
; /* longest free space */
88 #define XFS_AGF_MAGICNUM 0x00000001
89 #define XFS_AGF_VERSIONNUM 0x00000002
90 #define XFS_AGF_SEQNO 0x00000004
91 #define XFS_AGF_LENGTH 0x00000008
92 #define XFS_AGF_ROOTS 0x00000010
93 #define XFS_AGF_LEVELS 0x00000020
94 #define XFS_AGF_FLFIRST 0x00000040
95 #define XFS_AGF_FLLAST 0x00000080
96 #define XFS_AGF_FLCOUNT 0x00000100
97 #define XFS_AGF_FREEBLKS 0x00000200
98 #define XFS_AGF_LONGEST 0x00000400
99 #define XFS_AGF_NUM_BITS 11
100 #define XFS_AGF_ALL_BITS ((1 << XFS_AGF_NUM_BITS) - 1)
102 /* disk block (xfs_daddr_t) in the AG */
103 #define XFS_AGF_DADDR(mp) ((xfs_daddr_t)(1 << (mp)->m_sectbb_log))
104 #define XFS_AGF_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGF_DADDR(mp))
105 #define XFS_BUF_TO_AGF(bp) ((xfs_agf_t *)XFS_BUF_PTR(bp))
109 * Size of the unlinked inode hash table in the agi.
111 #define XFS_AGI_UNLINKED_BUCKETS 64
113 typedef struct xfs_agi
116 * Common allocation group header information
118 __uint32_t agi_magicnum
; /* magic number == XFS_AGI_MAGIC */
119 __uint32_t agi_versionnum
; /* header version == XFS_AGI_VERSION */
120 xfs_agnumber_t agi_seqno
; /* sequence # starting from 0 */
121 xfs_agblock_t agi_length
; /* size in blocks of a.g. */
124 * Inodes are mapped by interpreting the inode number, so no
125 * mapping data is needed here.
127 xfs_agino_t agi_count
; /* count of allocated inodes */
128 xfs_agblock_t agi_root
; /* root of inode btree */
129 __uint32_t agi_level
; /* levels in inode btree */
130 xfs_agino_t agi_freecount
; /* number of free inodes */
131 xfs_agino_t agi_newino
; /* new inode just allocated */
132 xfs_agino_t agi_dirino
; /* last directory inode chunk */
134 * Hash table of inodes which have been unlinked but are
135 * still being referenced.
137 xfs_agino_t agi_unlinked
[XFS_AGI_UNLINKED_BUCKETS
];
140 #define XFS_AGI_MAGICNUM 0x00000001
141 #define XFS_AGI_VERSIONNUM 0x00000002
142 #define XFS_AGI_SEQNO 0x00000004
143 #define XFS_AGI_LENGTH 0x00000008
144 #define XFS_AGI_COUNT 0x00000010
145 #define XFS_AGI_ROOT 0x00000020
146 #define XFS_AGI_LEVEL 0x00000040
147 #define XFS_AGI_FREECOUNT 0x00000080
148 #define XFS_AGI_NEWINO 0x00000100
149 #define XFS_AGI_DIRINO 0x00000200
150 #define XFS_AGI_UNLINKED 0x00000400
151 #define XFS_AGI_NUM_BITS 11
152 #define XFS_AGI_ALL_BITS ((1 << XFS_AGI_NUM_BITS) - 1)
154 /* disk block (xfs_daddr_t) in the AG */
155 #define XFS_AGI_DADDR(mp) ((xfs_daddr_t)(2 << (mp)->m_sectbb_log))
156 #define XFS_AGI_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGI_DADDR(mp))
157 #define XFS_BUF_TO_AGI(bp) ((xfs_agi_t *)XFS_BUF_PTR(bp))
160 * The third a.g. block contains the a.g. freelist, an array
161 * of block pointers to blocks owned by the allocation btree code.
163 #define XFS_AGFL_DADDR(mp) ((xfs_daddr_t)(3 << (mp)->m_sectbb_log))
164 #define XFS_AGFL_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGFL_DADDR(mp))
165 #define XFS_AGFL_SIZE(mp) ((mp)->m_sb.sb_sectsize / sizeof(xfs_agblock_t))
166 #define XFS_BUF_TO_AGFL(bp) ((xfs_agfl_t *)XFS_BUF_PTR(bp))
168 typedef struct xfs_agfl
{
169 xfs_agblock_t agfl_bno
[1]; /* actually XFS_AGFL_SIZE(mp) */
173 * Busy block/extent entry. Used in perag to mark blocks that have been freed
174 * but whose transactions aren't committed to disk yet.
176 typedef struct xfs_perag_busy
{
177 xfs_agblock_t busy_start
;
178 xfs_extlen_t busy_length
;
179 struct xfs_trans
*busy_tp
; /* transaction that did the free */
183 * Per-ag incore structure, copies of information in agf and agi,
184 * to improve the performance of allocation group selection.
186 * pick sizes which fit in allocation buckets well
188 #if (BITS_PER_LONG == 32)
189 #define XFS_PAGB_NUM_SLOTS 84
190 #elif (BITS_PER_LONG == 64)
191 #define XFS_PAGB_NUM_SLOTS 128
194 typedef struct xfs_perag
196 char pagf_init
; /* this agf's entry is initialized */
197 char pagi_init
; /* this agi's entry is initialized */
198 char pagf_metadata
; /* the agf is prefered to be metadata */
199 char pagi_inodeok
; /* The agi is ok for inodes */
200 __uint8_t pagf_levels
[XFS_BTNUM_AGF
];
201 /* # of levels in bno & cnt btree */
202 __uint32_t pagf_flcount
; /* count of blocks in freelist */
203 xfs_extlen_t pagf_freeblks
; /* total free blocks */
204 xfs_extlen_t pagf_longest
; /* longest free space */
205 xfs_agino_t pagi_freecount
; /* number of free inodes */
207 lock_t pagb_lock
; /* lock for pagb_list */
209 int pagb_count
; /* pagb slots in use */
210 xfs_perag_busy_t
*pagb_list
; /* unstable blocks */
213 #define XFS_AG_MAXLEVELS(mp) ((mp)->m_ag_maxlevels)
214 #define XFS_MIN_FREELIST_RAW(bl,cl,mp) \
215 (MIN(bl + 1, XFS_AG_MAXLEVELS(mp)) + MIN(cl + 1, XFS_AG_MAXLEVELS(mp)))
216 #define XFS_MIN_FREELIST(a,mp) \
217 (XFS_MIN_FREELIST_RAW( \
218 INT_GET((a)->agf_levels[XFS_BTNUM_BNOi], ARCH_CONVERT), \
219 INT_GET((a)->agf_levels[XFS_BTNUM_CNTi], ARCH_CONVERT), mp))
220 #define XFS_MIN_FREELIST_PAG(pag,mp) \
221 (XFS_MIN_FREELIST_RAW( \
222 (uint_t)(pag)->pagf_levels[XFS_BTNUM_BNOi], \
223 (uint_t)(pag)->pagf_levels[XFS_BTNUM_CNTi], mp))
225 #define XFS_AGB_TO_FSB(mp,agno,agbno) \
226 (((xfs_fsblock_t)(agno) << (mp)->m_sb.sb_agblklog) | (agbno))
227 #define XFS_FSB_TO_AGNO(mp,fsbno) \
228 ((xfs_agnumber_t)((fsbno) >> (mp)->m_sb.sb_agblklog))
229 #define XFS_FSB_TO_AGBNO(mp,fsbno) \
230 ((xfs_agblock_t)((fsbno) & XFS_MASK32LO((mp)->m_sb.sb_agblklog)))
231 #define XFS_AGB_TO_DADDR(mp,agno,agbno) \
232 ((xfs_daddr_t)XFS_FSB_TO_BB(mp, \
233 (xfs_fsblock_t)(agno) * (mp)->m_sb.sb_agblocks + (agbno)))
234 #define XFS_AG_DADDR(mp,agno,d) (XFS_AGB_TO_DADDR(mp, agno, 0) + (d))
237 * For checking for bad ranges of xfs_daddr_t's, covering multiple
238 * allocation groups or a single xfs_daddr_t that's a superblock copy.
240 #define XFS_AG_CHECK_DADDR(mp,d,len) \
242 ASSERT((d) == XFS_SB_DADDR || \
243 XFS_DADDR_TO_AGBNO(mp, d) != XFS_SB_DADDR) : \
244 ASSERT(XFS_DADDR_TO_AGNO(mp, d) == \
245 XFS_DADDR_TO_AGNO(mp, (d) + (len) - 1)))
247 #endif /* __XFS_AG_H__ */