ioctl_fsmap(2)
โจ ioctl_fsmap(2) โ NAME โจ
okay bestie, welcome to ioctl_fsmap(2), also known as FS_IOC_GETFSMAP โ it's the syscall-adjacent girly that spills the tea on your filesystem's physical layout ๐
Not me reading the manual with you. Let's go. ๐ซถ
๐ LIBRARY
Standard C library (libc, -lc). The classic. The icon. No cap.
๐ง SYNOPSIS
#include <linux/fsmap.h> /* Definition of FS_IOC_GETFSMAP,
FM?_OF_*, and *FMR_OWN_* constants */
#include <sys/ioctl.h>
int ioctl(int fd, FS_IOC_GETFSMAP, struct fsmap_head * arg);
Two headers, one ioctl call, infinite possibilities. slay. โจ
๐ธ DESCRIPTION
So this ioctl(2) operation literally retrieves physical extent mappings for a filesystem. It's giving ~full transparency~. You can use this info to:
- discover which files are mapped to a physical block ๐บ๏ธ
- examine free space ๐
- find known bad blocks ๐ญ
- and honestly, a bunch of other things too
The sole argument to this operation has to be a pointer to a single struct fsmap_head, okay? Just one. Main character energy. ๐
struct fsmap {
__u32 fmr_device; /* Device ID */
__u32 fmr_flags; /* Mapping flags */
__u64 fmr_physical; /* Device offset of segment */
__u64 fmr_owner; /* Owner ID */
__u64 fmr_offset; /* File offset of segment */
__u64 fmr_length; /* Length of segment */
__u64 fmr_reserved[3]; /* Must be zero */
};
struct fsmap_head {
__u32 fmh_iflags; /* Control flags */
__u32 fmh_oflags; /* Output flags */
__u32 fmh_count; /* # of entries in array including input */
__u32 fmh_entries; /* # of entries filled in (output) */
__u64 fmh_reserved[6]; /* Must be zero */
struct fsmap fmh_keys[2]; /* Low and high keys for
the mapping search */
struct fsmap fmh_recs[]; /* Returned records */
};
The two fmh_keys array elements specify the lowest and highest reverse-mapping key the app wants physical mapping info for. A reverse mapping key is the tuple (device, block, owner, offset). The owner and offset fields are part of the key because some filesystems support sharing physical blocks between multiple files, so they might return multiple mappings for one physical block. yes, sharing is caring but also complicated. ๐
Filesystem mappings get copied into the fmh_recs array, which sits immediately after the header data. no gap, no sneaky padding, they're besties. ๐ซ
๐ Fields of struct fsmap_head
fmh_iflagsโ a bit mask you pass to the kernel to alter the output. No flags are currently defined, so the caller must set this value to zero. Don't get cute with it. ๐fmh_oflagsโ a bit mask of flags set by the kernel about the returned mappings. IfFMH_OF_DEV_Tis set, then thefmr_devicefield represents adev_tstructure containing the major and minor numbers of the block device. cute of it. ๐fmh_countโ the number of elements in the array you're passing to the kernel. If this value is0, thenfmh_entrieswill be set to the number of records that would have been returned had the array been big enough, and no mapping information will be returned. it's giving "just tell me how much room I need, I'll come back". ๐fmh_entriesโ the number of elements in thefmh_recsarray that actually contain useful info. the rest? filler. background characters. ๐fmh_reservedโ these fields must be set to zero. periodt.
๐ฆ Keys
The two key records in fsmap_head.fmh_keys specify the lowest and highest extent records in the keyspace that the caller wants returned.
A filesystem that can share blocks between files likely needs the tuple (device, physical, owner, offset, flags) to uniquely index any filesystem mapping record. Classic non-sharing filesystems might be able to identify any record with only (device, physical, flags). so like, depends on the vibes of your FS. โจ
Example time, because examples eat:
- if the low key is set to
(8:0, 36864, 0, 0, 0), the filesystem will only return records for extents starting at or above 36 KiB on disk - if the high key is set to
(8:0, 1048576, 0, 0, 0), only records below 1 MiB will be returned
The format of fmr_device in the keys must match the format of the same field in the output records, as defined below. By convention, the field fsmap_head.fmh_keys[0] must contain the low key and fsmap_head.fmh_keys[1] must contain the high key for the operation. low first, high second, no switching. ๐ค
For convenience, if fmr_length is set in the low key, it will be added to fmr_block or fmr_offset as appropriate. The caller can take advantage of this subtlety to set up subsequent calls by copying fsmap_head.fmh_recs[fsmap_head.fmh_entries - 1] into the low key. And the function fsmap_advance (defined in linux/fsmap.h) provides this functionality, so you don't have to do it yourself like a peasant. ๐
๐ Fields of struct fsmap
fmr_deviceโ uniquely identifies the underlying storage device. If theFMH_OF_DEV_Tflag is set in the header'sfmh_oflagsfield, this field contains adev_tfrom which major and minor numbers can be extracted. If the flag is not set, this field contains a value that must be unique for each unique storage device.fmr_physicalโ contains the disk address of the extent, in bytes. ๐fmr_ownerโ contains the owner of the extent. This is an inode number unlessFMR_OF_SPECIAL_OWNERis set in thefmr_flagsfield, in which case the value is determined by the filesystem. See the section below about owner values for more details ๐fmr_offsetโ contains the logical address in the mapping record, in bytes. This field has no meaning if theFMR_OF_SPECIAL_OWNERorFMR_OF_EXTENT_MAPflags are set infmr_flags.fmr_lengthโ contains the length of the extent, in bytes. ๐fmr_flagsโ a bit mask of extent state flags. The bits are:FMR_OF_PREALLOCโ The extent is allocated but not yet written. procrastination, but make it storage. ๐FMR_OF_ATTR_FORKโ This extent contains extended attribute data.FMR_OF_EXTENT_MAPโ This extent contains extent map information for the owner.FMR_OF_SHAREDโ Parts of this extent may be shared. ๐คFMR_OF_SPECIAL_OWNERโ Thefmr_ownerfield contains a special value instead of an inode number.FMR_OF_LASTโ This is the last record in the data set. the final girl. ๐
fmr_reservedโ will be set to zero. best behavior only.
๐ Owner values
Generally, the value of the fmr_owner field for non-metadata extents should be an inode number. However, filesystems are under no obligation to report inode numbers. they may instead report FMR_OWN_UNKNOWN if:
- the inode number cannot easily be retrieved
- the caller lacks sufficient privilege
- the filesystem does not support stable inode numbers
- or for any other reason (the ultimate "because I said so")
If a filesystem wishes to condition the reporting of inode numbers based on process capabilities, it is strongly urged that the CAP_SYS_ADMIN capability be used for this purpose.
The following special owner values are generic to all filesystems:
FMR_OWN_FREEโ Free space. ๐FMR_OWN_UNKNOWNโ This extent is in use but its owner is not known or not easily retrieved. mystery vibes. ๐ต๏ธFMR_OWN_METADATAโ This extent is filesystem metadata.
XFS can return the following special owner values:
XFS_FMR_OWN_FREEโ Free space.XFS_FMR_OWN_UNKNOWNโ This extent is in use but its owner is not known or not easily retrieved.XFS_FMR_OWN_FSโ Static filesystem metadata which exists at a fixed address. These are the AG superblock, the AGF, the AGFL, and the AGI headers.XFS_FMR_OWN_LOGโ The filesystem journal. ๐XFS_FMR_OWN_AGโ Allocation group metadata, such as the free space btrees and the reverse mapping btrees.XFS_FMR_OWN_INOBTโ The inode and free inode btrees. ๐ณ๐ณXFS_FMR_OWN_INODESโ Inode records.XFS_FMR_OWN_REFCโ Reference count information.XFS_FMR_OWN_COWโ This extent is being used to stage a copy-on-write. ๐XFS_FMR_OWN_DEFECTIVE:โ This extent has been marked defective either by the filesystem or the underlying device. ๐ญ not the defective one
ext4 can return the following special owner values:
EXT4_FMR_OWN_FREEโ Free space.EXT4_FMR_OWN_UNKNOWNโ This extent is in use but its owner is not known or not easily retrieved.EXT4_FMR_OWN_FSโ Static filesystem metadata which exists at a fixed address. This is the superblock and the group descriptors.EXT4_FMR_OWN_LOGโ The filesystem journal.EXT4_FMR_OWN_INODESโ Inode records.EXT4_FMR_OWN_BLKBMโ Block bit map.EXT4_FMR_OWN_INOBMโ Inode bit map.
๐ RETURN VALUE
On error, -1 is returned, and errno is set to indicate the error. that's it, that's the whole section. humble but honest. ๐
๐ฅ ERRORS
The error placed in errno can be one of, but is not limited to, the following:
EBADFโfdis not open for reading.EBADMSGโ The filesystem has detected a checksum error in the metadata. ๐งฎEFAULTโ The pointer passed in was not mapped to a valid memory address.EINVALโ The array is not long enough, the keys do not point to a valid part of the filesystem, the low key points to a higher point in the filesystem's physical storage address space than the high key, or a nonzero value was passed in one of the fields that must be zero. (so many reasons, it's giving overachiever ๐ )ENOMEMโ Insufficient memory to process the operation.EOPNOTSUPPโ The filesystem does not support this operation. rude of it, honestly. ๐คEUCLEANโ The filesystem metadata is corrupt and needs repair. ๐
these are not exhaustive, bestie โ "is not limited to" means more chaos may await. ๐
โญ STANDARDS
Linux. ๐ง
Not all filesystems support it. (iykyk)
๐ฐ๏ธ HISTORY
Linux 4.12. a classic, an elder, a legend. ๐
๐ EXAMPLES
See io/fsmap.c in the xfsprogs distribution for a sample program. go peek, it's cute. ๐
๐ฆ SEE ALSO
and that's the whole page, bestie!! ๐ this was ioctl_fsmap(2) from Linux man-pages 6.20, dated 2026-02-08 โ now go forth and map your extents, you absolute icon ๐ซถโจ๐๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: GPL-2.0-or-later
- Copyright 2017, Oracle
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms