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 #include "xfs_rtbitmap.h"
16 #include "xfs_rtgroup.h"
20 * Verify that an AG block number pointer neither points outside the AG
21 * nor points at static metadata.
24 xfs_verify_agno_agbno(
31 eoag = xfs_ag_block_count(mp, agno);
34 if (agbno <= XFS_AGFL_BLOCK(mp))
40 * Verify that an FS block number pointer neither points outside the
41 * filesystem nor points at static AG metadata.
48 xfs_agnumber_t agno = XFS_FSB_TO_AGNO(mp, fsbno);
50 if (agno >= mp->m_sb.sb_agcount)
52 return xfs_verify_agno_agbno(mp, agno, XFS_FSB_TO_AGBNO(mp, fsbno));
56 * Verify that a data device extent is fully contained inside the filesystem,
57 * does not cross an AG boundary, and does not point at static metadata.
65 if (fsbno + len <= fsbno)
68 if (!xfs_verify_fsbno(mp, fsbno))
71 if (!xfs_verify_fsbno(mp, fsbno + len - 1))
74 return XFS_FSB_TO_AGNO(mp, fsbno) ==
75 XFS_FSB_TO_AGNO(mp, fsbno + len - 1);
79 * Verify that an AG inode number pointer neither points outside the AG
80 * nor points at static metadata.
83 xfs_verify_agno_agino(
91 xfs_agino_range(mp, agno, &first, &last);
92 return agino >= first && agino <= last;
96 * Verify that an FS inode number pointer neither points outside the
97 * filesystem nor points at static AG metadata.
101 struct xfs_mount *mp,
104 xfs_agnumber_t agno = XFS_INO_TO_AGNO(mp, ino);
105 xfs_agino_t agino = XFS_INO_TO_AGINO(mp, ino);
107 if (agno >= mp->m_sb.sb_agcount)
109 if (XFS_AGINO_TO_INO(mp, agno, agino) != ino)
111 return xfs_verify_agno_agino(mp, agno, agino);
114 /* Is this an internal inode number? */
117 struct xfs_mount *mp,
120 return ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino ||
121 (xfs_has_quota(mp) &&
122 xfs_is_quota_inode(&mp->m_sb, ino));
126 * Verify that a directory entry's inode number doesn't point at an internal
127 * inode, empty space, or static AG metadata.
131 struct xfs_mount *mp,
134 if (xfs_is_sb_inum(mp, ino))
136 return xfs_verify_ino(mp, ino);
140 * Verify that a realtime block number pointer neither points outside the
141 * allocatable areas of the rtgroup nor off the end of the realtime
146 struct xfs_mount *mp,
149 if (xfs_has_rtgroups(mp)) {
150 xfs_rgnumber_t rgno = xfs_rtb_to_rgno(mp, rtbno);
151 xfs_rtxnum_t rtx = xfs_rtb_to_rtx(mp, rtbno);
153 if (rgno >= mp->m_sb.sb_rgcount)
155 if (rtx >= xfs_rtgroup_extents(mp, rgno))
157 if (xfs_has_rtsb(mp) && rgno == 0 && rtx == 0)
162 return rtbno < mp->m_sb.sb_rblocks;
166 * Verify that an allocated realtime device extent neither points outside
167 * allocatable areas of the rtgroup, across an rtgroup boundary, nor off the
168 * end of the realtime device.
172 struct xfs_mount *mp,
176 if (rtbno + len <= rtbno)
179 if (!xfs_verify_rtbno(mp, rtbno))
182 if (!xfs_verify_rtbno(mp, rtbno + len - 1))
185 if (xfs_has_rtgroups(mp) &&
186 xfs_rtb_to_rgno(mp, rtbno) != xfs_rtb_to_rgno(mp, rtbno + len - 1))
192 /* Calculate the range of valid icount values. */
195 struct xfs_mount *mp,
196 unsigned long long *min,
197 unsigned long long *max)
199 unsigned long long nr_inos = 0;
200 struct xfs_perag *pag = NULL;
202 /* root, rtbitmap, rtsum all live in the first chunk */
203 *min = XFS_INODES_PER_CHUNK;
205 while ((pag = xfs_perag_next(mp, pag)))
206 nr_inos += pag->agino_max - pag->agino_min + 1;
210 /* Sanity-checking of inode counts. */
213 struct xfs_mount *mp,
214 unsigned long long icount)
216 unsigned long long min, max;
218 xfs_icount_range(mp, &min, &max);
219 return icount >= min && icount <= max;
222 /* Sanity-checking of dir/attr block offsets. */
225 struct xfs_mount *mp,
228 xfs_dablk_t max_dablk = -1U;
230 return dabno <= max_dablk;
233 /* Check that a file block offset does not exceed the maximum. */
236 struct xfs_mount *mp,
239 return off <= XFS_MAX_FILEOFF;
242 /* Check that a range of file block offsets do not exceed the maximum. */
245 struct xfs_mount *mp,
249 if (off + len <= off)
252 if (!xfs_verify_fileoff(mp, off))
255 return xfs_verify_fileoff(mp, off + len - 1);