]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/xfs_types.c
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
4 * Copyright (C) 2017 Oracle.
7 #include "libxfs_priv.h"
9 #include "xfs_format.h"
10 #include "xfs_log_format.h"
11 #include "xfs_shared.h"
12 #include "xfs_trans_resv.h"
15 #include "xfs_mount.h"
16 #include "xfs_defer.h"
17 #include "xfs_inode.h"
18 #include "xfs_btree.h"
20 #include "xfs_alloc_btree.h"
21 #include "xfs_alloc.h"
22 #include "xfs_ialloc.h"
24 /* Find the size of the AG, in blocks. */
30 ASSERT(agno
< mp
->m_sb
.sb_agcount
);
32 if (agno
< mp
->m_sb
.sb_agcount
- 1)
33 return mp
->m_sb
.sb_agblocks
;
34 return mp
->m_sb
.sb_dblocks
- (agno
* mp
->m_sb
.sb_agblocks
);
38 * Verify that an AG block number pointer neither points outside the AG
39 * nor points at static metadata.
49 eoag
= xfs_ag_block_count(mp
, agno
);
52 if (agbno
<= XFS_AGFL_BLOCK(mp
))
58 * Verify that an FS block number pointer neither points outside the
59 * filesystem nor points at static AG metadata.
66 xfs_agnumber_t agno
= XFS_FSB_TO_AGNO(mp
, fsbno
);
68 if (agno
>= mp
->m_sb
.sb_agcount
)
70 return xfs_verify_agbno(mp
, agno
, XFS_FSB_TO_AGBNO(mp
, fsbno
));
73 /* Calculate the first and last possible inode number in an AG. */
84 eoag
= xfs_ag_block_count(mp
, agno
);
87 * Calculate the first inode, which will be in the first
88 * cluster-aligned block after the AGFL.
90 bno
= round_up(XFS_AGFL_BLOCK(mp
) + 1,
91 xfs_ialloc_cluster_alignment(mp
));
92 *first
= XFS_OFFBNO_TO_AGINO(mp
, bno
, 0);
95 * Calculate the last inode, which will be at the end of the
96 * last (aligned) cluster that can be allocated in the AG.
98 bno
= round_down(eoag
, xfs_ialloc_cluster_alignment(mp
));
99 *last
= XFS_OFFBNO_TO_AGINO(mp
, bno
, 0) - 1;
103 * Verify that an AG inode number pointer neither points outside the AG
104 * nor points at static metadata.
108 struct xfs_mount
*mp
,
115 xfs_agino_range(mp
, agno
, &first
, &last
);
116 return agino
>= first
&& agino
<= last
;
120 * Verify that an FS inode number pointer neither points outside the
121 * filesystem nor points at static AG metadata.
125 struct xfs_mount
*mp
,
128 xfs_agnumber_t agno
= XFS_INO_TO_AGNO(mp
, ino
);
129 xfs_agino_t agino
= XFS_INO_TO_AGINO(mp
, ino
);
131 if (agno
>= mp
->m_sb
.sb_agcount
)
133 if (XFS_AGINO_TO_INO(mp
, agno
, agino
) != ino
)
135 return xfs_verify_agino(mp
, agno
, agino
);
138 /* Is this an internal inode number? */
141 struct xfs_mount
*mp
,
144 return ino
== mp
->m_sb
.sb_rbmino
|| ino
== mp
->m_sb
.sb_rsumino
||
145 (xfs_sb_version_hasquota(&mp
->m_sb
) &&
146 xfs_is_quota_inode(&mp
->m_sb
, ino
));
150 * Verify that a directory entry's inode number doesn't point at an internal
151 * inode, empty space, or static AG metadata.
155 struct xfs_mount
*mp
,
158 if (xfs_internal_inum(mp
, ino
))
160 return xfs_verify_ino(mp
, ino
);
164 * Verify that an realtime block number pointer doesn't point off the
165 * end of the realtime device.
169 struct xfs_mount
*mp
,
172 return rtbno
< mp
->m_sb
.sb_rblocks
;
175 /* Calculate the range of valid icount values. */
178 struct xfs_mount
*mp
,
179 unsigned long long *min
,
180 unsigned long long *max
)
182 unsigned long long nr_inos
= 0;
185 /* root, rtbitmap, rtsum all live in the first chunk */
186 *min
= XFS_INODES_PER_CHUNK
;
188 for (agno
= 0; agno
< mp
->m_sb
.sb_agcount
; agno
++) {
189 xfs_agino_t first
, last
;
191 xfs_agino_range(mp
, agno
, &first
, &last
);
192 nr_inos
+= last
- first
+ 1;
197 /* Sanity-checking of inode counts. */
200 struct xfs_mount
*mp
,
201 unsigned long long icount
)
203 unsigned long long min
, max
;
205 xfs_icount_range(mp
, &min
, &max
);
206 return icount
>= min
&& icount
<= max
;