IOCTL-XFS-GETBMAPX(2)
π ioctl_xfs_getbmapx β like, the System Calls Manual page for querying extent info π
okay so bestie, welcome to ioctl_xfs_getbmapx, straight out of the System Calls Manual. it's a little query tool that asks an open file "hey, where do your blocks actually live?" and XFS answers. no cap. let's get into it π¦
β¨ NAME β¨
ioctl_xfs_getbmapx β query extent information for an open file
πΈ SYNOPSIS πΈ
#include <xfs/xfs_fs.h>
int ioctl(int fd, XFS_IOC_GETBMAP, struct getbmap *arg);
int ioctl(int fd, XFS_IOC_GETBMAPA, struct getbmap *arg);
int ioctl(int fd, XFS_IOC_GETBMAPX, struct getbmapx *arg);
π DESCRIPTION π
So basically, this gets you the block map for a segment of a file living in an XFS file system. The mapping info gets handed back to you through an array of structs that look like this, periodt:
struct getbmap {
__s64 bmv_offset;
__s64 bmv_block;
__s64 bmv_length;
__s32 bmv_count;
__s32 bmv_entries;
};
And the XFS_IOC_GETBMAPX ioctl is just the glow-up version β it uses a bigger, more main-character struct:
struct getbmapx {
__s64 bmv_offset;
__s64 bmv_block;
__s64 bmv_length;
__s32 bmv_count;
__s32 bmv_entries;
__s32 bmv_iflags;
__s32 bmv_oflags;
__s32 bmv_unused1;
__s32 bmv_unused2;
};
π Important vibe check: all sizes and offsets in the structure are in units of 512 bytes. don't forget it iykyk.
The first struct in the array is the header, and the rest of the structs in the array get filled with block map info when the call returns. The header is the one steering those iterative calls, so fill it out like this:
bmv_offsetβ the file offset of the area of interest in the file.bmv_lengthβ the length of the area of interest in the file. set it to-1and the interesting area is just the rest of the file, easy peasy πbmv_countβ the number of elements in the array, including this header. minimum value is2. that's the floor, bestie.bmv_entriesβ the number of entries actually filled in by the call. you don't need to fill this out before the call. it can be zero if no extents were found in the requested range, or if iterated calls have reached the end of the requested range.bmv_iflagsβ for theXFS_IOC_GETBMAPXfunction, this is a bitmask holding a combo of these flags:BMV_IF_ATTRFORKβ return information about the extended attribute fork.BMV_IF_PREALLOCβ return information about unwritten pre-allocated segments.BMV_IF_DELALLOCβ return information about delayed allocation reservation segments.BMV_IF_NO_HOLESβ do not return information about holes.
The other bmv_* fields in the header are just... ignored. literally nobody's looking at them π
When a call returns successfully, the offset and length values in the header get updated so you can reuse the command to grab more info β it's giving efficient, it's giving recycling β»οΈ. The remaining elements of the array get filled out by the call like so:
bmv_offsetβ file offset of segment.bmv_blockβ physical starting block of segment. if this is-1, then the segment is a hole. (a hole!! π)bmv_lengthβ length of segment.bmv_oflagsβ theXFS_IOC_GETBMAPXfunction fills this field with a combination of these flags:BMV_OF_PREALLOCβ the segment is an unwritten pre-allocation.BMV_OF_DELALLOCβ the segment is a delayed allocation reservation.BMV_OF_LASTβ this segment is the last in the file. the finale. the last one in the group chat π«ΆBMV_OF_SHAREDβ this segment shares blocks with other files.
The other bmv_* fields are unused in the array of output records. just vibing there. unused.
Oh and also π: the XFS_IOC_GETBMAPA command is identical to XFS_IOC_GETBMAP except that information about the attribute fork of the file is returned. that's the whole difference, slay.
β RETURN VALUE β
On error, -1 is returned, and errno is set to indicate the error. classic.
π¨ ERRORS π¨
Error codes can be one of, but are not limited to, the following:
EFAULTβ the kernel was not able to copy into the userspace buffer. rude of it.EFSBADCRCβ metadata checksum validation failed while performing the query.EFSCORRUPTEDβ metadata corruption was encountered while performing the query.EINVALβ one of the arguments was not valid.EIOβ an I/O error was encountered while performing the query.ENOMEMβ there was insufficient memory to perform the query.
lowkey if you seeEFSBADCRCorEFSCORRUPTED, something is genuinely not okay with your metadata. not a vibe. π
π CONFORMING TO π
This API is specific to XFS filesystem on the Linux kernel. exclusive. it's giving XFS-only, no gatekeeping but also no other filesystems π
π₯ SEE ALSO π₯
okay that's the whole page bestie, you ate that π«Ά this was XFS, dated 2019-06-17 β go forth and map those blocks, mwah πβ¨
π¦ where this page comes from
- alpine 3.22: xfsprogs-doc 6.14.0-r0 Β· LGPL-2.1-or-later
- alpine 3.23: xfsprogs-doc 6.17.0-r0 Β· LGPL-2.1-or-later
- alpine 3.24: xfsprogs-doc 7.0.1-r0 Β· LGPL-2.1-or-later
- arch rolling: xfsprogs 7.2.0-1
- arch rolling: xfsprogs 7.2.1-1 Β· GPL-2.0-only AND LGPL-2.1-only
- centos-stream 10: xfsprogs-devel 6.16.0-1.el10 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- centos-stream 9: xfsprogs-devel 6.4.0-9.el9 Β· GPL+ and LGPLv2+
- centos-stream 9: xfsprogs-devel 6.4.0-9.el9 Β· GPL+ and LGPLv2+
- debian bookworm: xfslibs-dev 6.1.0-1 Β· GPL-2.0-only
- debian trixie: xfslibs-dev 6.13.0-2+deb13u1 Β· GPL-2.0-only
- fedora 43: xfsprogs-devel 6.15.0-3.fc43 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 43: xfsprogs-devel 6.15.0-3.fc43 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs-devel 6.18.0-2.fc44 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs-devel 6.18.0-2.fc44 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs-devel 7.1.1-1.fc44 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs-devel 7.1.1-1.fc44 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- nixos 26.05: xfsprogs 6.19.0
- nixpkgs unstable: xfsprogs 7.2.1
- opensuse-leap 16.0: xfsprogs 6.19.0-160000.3.1 Β· GPL-2.0-or-later
- opensuse-leap 16.0: xfsprogs 6.19.0-160000.3.1 Β· GPL-2.0-or-later
- opensuse-leap 16.0: xfsprogs 6.19.0-160000.3.1 Β· GPL-2.0-or-later
- opensuse-leap 16.0: xfsprogs 6.19.0-160000.3.1 Β· GPL-2.0-or-later
- ubuntu jammy: xfslibs-dev 5.13.0-1ubuntu2 Β· GPL-2.0-only
- ubuntu jammy: xfslibs-dev 5.13.0-1ubuntu2.1 Β· GPL-2.0-only
- ubuntu noble: xfslibs-dev 6.6.0-1ubuntu2 Β· GPL-2.0-only
- ubuntu noble: xfslibs-dev 6.6.0-1ubuntu2.1 Β· GPL-2.0-only
- ubuntu questing: xfslibs-dev 6.13.0-2ubuntu2
- ubuntu resolute: xfslibs-dev 6.18.0-3 Β· GPL-2.0-only
- ubuntu stonking: xfslibs-dev 6.19.0-1 Β· GPL-2.0-only
- π the page's license: GPL-2.0+
- Copyright (c) 2019, Oracle. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms