1 .\" Copyright (c) 2017, Oracle. All rights reserved.
3 .\" SPDX-License-Identifier: GPL-2.0-or-later
4 .TH IOCTL_GETFSMAP 2 2021-03-22 "Linux" "Linux Programmer's Manual"
6 ioctl_getfsmap \- retrieve the physical layout of the filesystem
12 .BR "#include <linux/fsmap.h> " "/* Definition of " FS_IOC_GETFSMAP ,
13 .BR " FM?_OF_*" ", and " *FMR_OWN_* " constants */"
14 .B #include <sys/ioctl.h>
16 .BI "int ioctl(int " fd ", FS_IOC_GETFSMAP, struct fsmap_head * " arg );
21 operation retrieves physical extent mappings for a filesystem.
22 This information can be used to discover which files are mapped to a physical
23 block, examine free space, or find known bad blocks, among other things.
25 The sole argument to this operation should be a pointer to a single
26 .IR "struct fsmap_head" ":"
31 __u32 fmr_device; /* Device ID */
32 __u32 fmr_flags; /* Mapping flags */
33 __u64 fmr_physical; /* Device offset of segment */
34 __u64 fmr_owner; /* Owner ID */
35 __u64 fmr_offset; /* File offset of segment */
36 __u64 fmr_length; /* Length of segment */
37 __u64 fmr_reserved[3]; /* Must be zero */
41 __u32 fmh_iflags; /* Control flags */
42 __u32 fmh_oflags; /* Output flags */
43 __u32 fmh_count; /* # of entries in array incl. input */
44 __u32 fmh_entries; /* # of entries filled in (output) */
45 __u64 fmh_reserved[6]; /* Must be zero */
47 struct fsmap fmh_keys[2]; /* Low and high keys for
49 struct fsmap fmh_recs[]; /* Returned records */
56 array elements specify the lowest and highest reverse-mapping
57 key for which the application would like physical mapping
59 A reverse mapping key consists of the tuple (device, block, owner, offset).
60 The owner and offset fields are part of the key because some filesystems
61 support sharing physical blocks between multiple files and
62 therefore may return multiple mappings for a given physical block.
64 Filesystem mappings are copied into the
66 array, which immediately follows the header data.
68 .SS Fields of struct fsmap_head
71 field is a bit mask passed to the kernel to alter the output.
72 No flags are currently defined, so the caller must set this value to zero.
76 field is a bit mask of flags set by the kernel concerning the returned mappings.
83 structure containing the major and minor numbers of the block device.
87 field contains the number of elements in the array being passed to the
91 will be set to the number of records that would have been returned had
92 the array been large enough;
93 no mapping information will be returned.
97 field contains the number of elements in the
99 array that contain useful information.
103 fields must be set to zero.
106 The two key records in
107 .I fsmap_head.fmh_keys
108 specify the lowest and highest extent records in the keyspace that the caller
110 A filesystem that can share blocks between files likely requires the tuple
111 .RI "(" "device" ", " "physical" ", " "owner" ", " "offset" ", " "flags" ")"
112 to uniquely index any filesystem mapping record.
113 Classic non-sharing filesystems might be able to identify any record with only
114 .RI "(" "device" ", " "physical" ", " "flags" ")."
115 For example, if the low key is set to (8:0, 36864, 0, 0, 0), the filesystem will
116 only return records for extents starting at or above 36\ KiB on disk.
117 If the high key is set to (8:0, 1048576, 0, 0, 0), only records below 1\ MiB will
121 in the keys must match the format of the same field in the output records,
123 By convention, the field
124 .I fsmap_head.fmh_keys[0]
125 must contain the low key and
126 .I fsmap_head.fmh_keys[1]
127 must contain the high key for the request.
131 is set in the low key, it will be added to
132 .IR fmr_block " or " fmr_offset
134 The caller can take advantage of this subtlety to set up subsequent calls
136 .I fsmap_head.fmh_recs[fsmap_head.fmh_entries \- 1]
142 provides this functionality.
144 .SS Fields of struct fsmap
147 field uniquely identifies the underlying storage device.
150 flag is set in the header's
152 field, this field contains a
154 from which major and minor numbers can be extracted.
155 If the flag is not set, this field contains a value that must be unique
156 for each unique storage device.
160 field contains the disk address of the extent in bytes.
164 field contains the owner of the extent.
165 This is an inode number unless
166 .B FMR_OF_SPECIAL_OWNER
169 field, in which case the value is determined by the filesystem.
170 See the section below about owner values for more details.
174 field contains the logical address in the mapping record in bytes.
175 This field has no meaning if the
176 .BR FMR_OF_SPECIAL_OWNER " or " FMR_OF_EXTENT_MAP
182 field contains the length of the extent in bytes.
186 field is a bit mask of extent state flags.
191 The extent is allocated but not yet written.
194 This extent contains extended attribute data.
197 This extent contains extent map information for the owner.
200 Parts of this extent may be shared.
202 .B FMR_OF_SPECIAL_OWNER
205 field contains a special value instead of an inode number.
208 This is the last record in the data set.
213 field will be set to zero.
216 Generally, the value of the
218 field for non-metadata extents should be an inode number.
219 However, filesystems are under no obligation to report inode numbers;
220 they may instead report
222 if the inode number cannot easily be retrieved, if the caller lacks
223 sufficient privilege, if the filesystem does not support stable
224 inode numbers, or for any other reason.
225 If a filesystem wishes to condition the reporting of inode numbers based
226 on process capabilities, it is strongly urged that the
228 capability be used for this purpose.
230 The following special owner values are generic to all filesystems:
237 This extent is in use but its owner is not known or not easily retrieved.
240 This extent is filesystem metadata.
243 XFS can return the following special owner values:
249 .B XFS_FMR_OWN_UNKNOWN
250 This extent is in use but its owner is not known or not easily retrieved.
253 Static filesystem metadata which exists at a fixed address.
254 These are the AG superblock, the AGF, the AGFL, and the AGI headers.
257 The filesystem journal.
260 Allocation group metadata, such as the free space btrees and the
261 reverse mapping btrees.
264 The inode and free inode btrees.
266 .B XFS_FMR_OWN_INODES
270 Reference count information.
273 This extent is being used to stage a copy-on-write.
275 .B XFS_FMR_OWN_DEFECTIVE:
276 This extent has been marked defective either by the filesystem or the
280 ext4 can return the following special owner values:
286 .B EXT4_FMR_OWN_UNKNOWN
287 This extent is in use but its owner is not known or not easily retrieved.
290 Static filesystem metadata which exists at a fixed address.
291 This is the superblock and the group descriptors.
294 The filesystem journal.
296 .B EXT4_FMR_OWN_INODES
299 .B EXT4_FMR_OWN_BLKBM
302 .B EXT4_FMR_OWN_INOBM
306 On error, \-1 is returned, and
308 is set to indicate the error.
312 can be one of, but is not limited to, the following:
316 is not open for reading.
319 The filesystem has detected a checksum error in the metadata.
322 The pointer passed in was not mapped to a valid memory address.
325 The array is not long enough, the keys do not point to a valid part of
326 the filesystem, the low key points to a higher point in the filesystem's
327 physical storage address space than the high key, or a nonzero value
328 was passed in one of the fields that must be zero.
331 Insufficient memory to process the request.
334 The filesystem does not support this command.
337 The filesystem metadata is corrupt and needs repair.
341 operation first appeared in Linux 4.12.
343 This API is Linux-specific.
344 Not all filesystems support it.
350 distribution for a sample program.