[PATCH 06/27] xfs_db: don't abort when bmapping on a non-extents/bmbt fork

Darrick J. Wong
2025-02-06T22:51:18Z

We're going to introduce new fork formats, so let's fix the problem that
xfs_db's bmap command aborts when the fork format isn't one of the
existing ones.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
db/bmap.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/db/bmap.c b/db/bmap.c
index 1c5694c3f7d281..e8dd98d686cb98 100644
--- a/db/bmap.c
+++ b/db/bmap.c
@@ -65,16 +65,18 @@ bmap(
fmt = (enum xfs_dinode_fmt)XFS_DFORK_FORMAT(dip, whichfork);
typ = whichfork == XFS_DATA_FORK ? TYP_BMAPBTD : TYP_BMAPBTA;
ASSERT(typtab[typ].typnm == typ);
- ASSERT(fmt == XFS_DINODE_FMT_LOCAL || fmt == XFS_DINODE_FMT_EXTENTS ||
- fmt == XFS_DINODE_FMT_BTREE);
- if (fmt == XFS_DINODE_FMT_EXTENTS) {
+ switch (fmt) {
+ case XFS_DINODE_FMT_LOCAL:
+ break;
+ case XFS_DINODE_FMT_EXTENTS:
nextents = xfs_dfork_nextents(dip, whichfork);
xp = (xfs_bmbt_rec_t *)XFS_DFORK_PTR(dip, whichfork);
for (ep = xp; ep < &xp[nextents] && n < nex; ep++) {
if (!bmap_one_extent(ep, &curoffset, eoffset, &n, bep))
break;
}
- } else if (fmt == XFS_DINODE_FMT_BTREE) {
+ break;
+ case XFS_DINODE_FMT_BTREE:
push_cur();
rblock = (xfs_bmdr_block_t *)XFS_DFORK_PTR(dip, whichfork);
fsize = XFS_DFORK_SIZE(dip, mp, whichfork);
@@ -114,6 +116,13 @@ bmap(
block = (struct xfs_btree_block *)iocur_top->data;
}
pop_cur();
+ break;
+ default:
+ dbprintf(
+ _("%s fork format %u does not support indexable blocks\n"),
+ whichfork == XFS_DATA_FORK ? "data" : "attr",
+ fmt);
+ break;
}
pop_cur();
*nexp = n;