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"
18 * Verify that an AG block number pointer neither points outside the AG
19 * nor points at static metadata.
22 xfs_verify_agno_agbno(
29 eoag = xfs_ag_block_count(mp, agno);
32 if (agbno <= XFS_AGFL_BLOCK(mp))
38 * Verify that an FS block number pointer neither points outside the
39 * filesystem nor points at static AG metadata.
46 xfs_agnumber_t agno = XFS_FSB_TO_AGNO(mp, fsbno);
48 if (agno >= mp->m_sb.sb_agcount)
50 return xfs_verify_agno_agbno(mp, agno, XFS_FSB_TO_AGBNO(mp, fsbno));
54 * Verify that a data device extent is fully contained inside the filesystem,
55 * does not cross an AG boundary, and does not point at static metadata.
63 if (fsbno + len <= fsbno)
66 if (!xfs_verify_fsbno(mp, fsbno))
69 if (!xfs_verify_fsbno(mp, fsbno + len - 1))
72 return XFS_FSB_TO_AGNO(mp, fsbno) ==
73 XFS_FSB_TO_AGNO(mp, fsbno + len - 1);
77 * Verify that an AG inode number pointer neither points outside the AG
78 * nor points at static metadata.
81 xfs_verify_agno_agino(
89 xfs_agino_range(mp, agno, &first, &last);
90 return agino >= first && agino <= last;
94 * Verify that an FS inode number pointer neither points outside the
95 * filesystem nor points at static AG metadata.
102 xfs_agnumber_t agno = XFS_INO_TO_AGNO(mp, ino);
103 xfs_agino_t agino = XFS_INO_TO_AGINO(mp, ino);
105 if (agno >= mp->m_sb.sb_agcount)
107 if (XFS_AGINO_TO_INO(mp, agno, agino) != ino)
109 return xfs_verify_agno_agino(mp, agno, agino);
112 /* Is this an internal inode number? */
115 struct xfs_mount *mp,
118 return ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino ||
119 (xfs_has_quota(mp) &&
120 xfs_is_quota_inode(&mp->m_sb, ino));
124 * Verify that a directory entry's inode number doesn't point at an internal
125 * inode, empty space, or static AG metadata.
129 struct xfs_mount *mp,
132 if (xfs_internal_inum(mp, ino))
134 return xfs_verify_ino(mp, ino);
138 * Verify that an realtime block number pointer doesn't point off the
139 * end of the realtime device.
143 struct xfs_mount *mp,
146 return rtbno < mp->m_sb.sb_rblocks;
149 /* Verify that a realtime device extent is fully contained inside the volume. */
152 struct xfs_mount *mp,
156 if (rtbno + len <= rtbno)
159 if (!xfs_verify_rtbno(mp, rtbno))
162 return xfs_verify_rtbno(mp, rtbno + len - 1);
165 /* Calculate the range of valid icount values. */
168 struct xfs_mount *mp,
169 unsigned long long *min,
170 unsigned long long *max)
172 unsigned long long nr_inos = 0;
173 struct xfs_perag *pag;
176 /* root, rtbitmap, rtsum all live in the first chunk */
177 *min = XFS_INODES_PER_CHUNK;
179 for_each_perag(mp, agno, pag)
180 nr_inos += pag->agino_max - pag->agino_min + 1;
184 /* Sanity-checking of inode counts. */
187 struct xfs_mount *mp,
188 unsigned long long icount)
190 unsigned long long min, max;
192 xfs_icount_range(mp, &min, &max);
193 return icount >= min && icount <= max;
196 /* Sanity-checking of dir/attr block offsets. */
199 struct xfs_mount *mp,
202 xfs_dablk_t max_dablk = -1U;
204 return dabno <= max_dablk;
207 /* Check that a file block offset does not exceed the maximum. */
210 struct xfs_mount *mp,
213 return off <= XFS_MAX_FILEOFF;
216 /* Check that a range of file block offsets do not exceed the maximum. */
219 struct xfs_mount *mp,
223 if (off + len <= off)
226 if (!xfs_verify_fileoff(mp, off))
229 return xfs_verify_fileoff(mp, off + len - 1);