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. If FMH_OF_DEV_T is set, then the fmr_device field represents a dev_t structure 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 is 0, then fmh_entries will 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 the fmh_recs array 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 the FMH_OF_DEV_T flag is set in the header's fmh_oflags field, this field contains a dev_t from 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 unless FMR_OF_SPECIAL_OWNER is set in the fmr_flags field, 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 the FMR_OF_SPECIAL_OWNER or FMR_OF_EXTENT_MAP flags are set in fmr_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 โ€” The fmr_owner field 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 โ€” fd is 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms