1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
4 * Copyright (C) 2017 Oracle.
9 #include "xfs_format.h"
10 #include "xfs_shared.h"
11 #include "xfs_trans_resv.h"
13 #include "xfs_mount.h"
15 /* Find the size of the AG, in blocks. */
21 ASSERT(agno < mp->m_sb.sb_agcount);
23 if (agno < mp->m_sb.sb_agcount - 1)
24 return mp->m_sb.sb_agblocks;
25 return mp->m_sb.sb_dblocks - (agno * mp->m_sb.sb_agblocks);
29 * Verify that an AG block number pointer neither points outside the AG
30 * nor points at static metadata.
40 eoag = xfs_ag_block_count(mp, agno);
43 if (agbno <= XFS_AGFL_BLOCK(mp))
49 * Verify that an FS block number pointer neither points outside the
50 * filesystem nor points at static AG metadata.
57 xfs_agnumber_t agno = XFS_FSB_TO_AGNO(mp, fsbno);
59 if (agno >= mp->m_sb.sb_agcount)
61 return xfs_verify_agbno(mp, agno, XFS_FSB_TO_AGBNO(mp, fsbno));
64 /* Calculate the first and last possible inode number in an AG. */
75 eoag = xfs_ag_block_count(mp, agno);
78 * Calculate the first inode, which will be in the first
79 * cluster-aligned block after the AGFL.
81 bno = round_up(XFS_AGFL_BLOCK(mp) + 1, M_IGEO(mp)->cluster_align);
82 *first = XFS_AGB_TO_AGINO(mp, bno);
85 * Calculate the last inode, which will be at the end of the
86 * last (aligned) cluster that can be allocated in the AG.
88 bno = round_down(eoag, M_IGEO(mp)->cluster_align);
89 *last = XFS_AGB_TO_AGINO(mp, bno) - 1;
93 * Verify that an AG inode number pointer neither points outside the AG
94 * nor points at static metadata.
105 xfs_agino_range(mp, agno, &first, &last);
106 return agino >= first && agino <= last;
110 * Verify that an AG inode number pointer neither points outside the AG
111 * nor points at static metadata, or is NULLAGINO.
114 xfs_verify_agino_or_null(
115 struct xfs_mount *mp,
119 return agino == NULLAGINO || xfs_verify_agino(mp, agno, agino);
123 * Verify that an FS inode number pointer neither points outside the
124 * filesystem nor points at static AG metadata.
128 struct xfs_mount *mp,
131 xfs_agnumber_t agno = XFS_INO_TO_AGNO(mp, ino);
132 xfs_agino_t agino = XFS_INO_TO_AGINO(mp, ino);
134 if (agno >= mp->m_sb.sb_agcount)
136 if (XFS_AGINO_TO_INO(mp, agno, agino) != ino)
138 return xfs_verify_agino(mp, agno, agino);
141 /* Is this an internal inode number? */
144 struct xfs_mount *mp,
147 return ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino ||
148 (xfs_sb_version_hasquota(&mp->m_sb) &&
149 xfs_is_quota_inode(&mp->m_sb, ino));
153 * Verify that a directory entry's inode number doesn't point at an internal
154 * inode, empty space, or static AG metadata.
158 struct xfs_mount *mp,
161 if (xfs_internal_inum(mp, ino))
163 return xfs_verify_ino(mp, ino);
167 * Verify that an realtime block number pointer doesn't point off the
168 * end of the realtime device.
172 struct xfs_mount *mp,
175 return rtbno < mp->m_sb.sb_rblocks;
178 /* Calculate the range of valid icount values. */
181 struct xfs_mount *mp,
182 unsigned long long *min,
183 unsigned long long *max)
185 unsigned long long nr_inos = 0;
188 /* root, rtbitmap, rtsum all live in the first chunk */
189 *min = XFS_INODES_PER_CHUNK;
191 for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) {
192 xfs_agino_t first, last;
194 xfs_agino_range(mp, agno, &first, &last);
195 nr_inos += last - first + 1;
200 /* Sanity-checking of inode counts. */
203 struct xfs_mount *mp,
204 unsigned long long icount)
206 unsigned long long min, max;
208 xfs_icount_range(mp, &min, &max);
209 return icount >= min && icount <= max;
212 /* Sanity-checking of dir/attr block offsets. */
215 struct xfs_mount *mp,
218 xfs_dablk_t max_dablk = -1U;
220 return dabno <= max_dablk;