1 .\" Copyright (c) 2017, Oracle. All rights reserved.
3 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 .\" GNU General Public License for more details.
19 .\" You should have received a copy of the GNU General Public
20 .\" License along with this manual; if not, see
21 .\" <http://www.gnu.org/licenses/>.
23 .TH IOCTL_GETFSMAP 2 2021-03-22 "Linux" "Linux Programmer's Manual"
25 ioctl_getfsmap \- retrieve the physical layout of the filesystem
28 .BR "#include <linux/fsmap.h> " "/* Definition of " FS_IOC_GETFSMAP ,
29 .BR " FM?_OF_*" ", and " *FMR_OWN_* " constants */"
30 .B #include <sys/ioctl.h>
32 .BI "int ioctl(int " fd ", FS_IOC_GETFSMAP, struct fsmap_head * " arg );
37 operation retrieves physical extent mappings for a filesystem.
38 This information can be used to discover which files are mapped to a physical
39 block, examine free space, or find known bad blocks, among other things.
41 The sole argument to this operation should be a pointer to a single
42 .IR "struct fsmap_head" ":"
47 __u32 fmr_device; /* Device ID */
48 __u32 fmr_flags; /* Mapping flags */
49 __u64 fmr_physical; /* Device offset of segment */
50 __u64 fmr_owner; /* Owner ID */
51 __u64 fmr_offset; /* File offset of segment */
52 __u64 fmr_length; /* Length of segment */
53 __u64 fmr_reserved[3]; /* Must be zero */
57 __u32 fmh_iflags; /* Control flags */
58 __u32 fmh_oflags; /* Output flags */
59 __u32 fmh_count; /* # of entries in array incl. input */
60 __u32 fmh_entries; /* # of entries filled in (output) */
61 __u64 fmh_reserved[6]; /* Must be zero */
63 struct fsmap fmh_keys[2]; /* Low and high keys for
65 struct fsmap fmh_recs[]; /* Returned records */
72 array elements specify the lowest and highest reverse-mapping
73 key for which the application would like physical mapping
75 A reverse mapping key consists of the tuple (device, block, owner, offset).
76 The owner and offset fields are part of the key because some filesystems
77 support sharing physical blocks between multiple files and
78 therefore may return multiple mappings for a given physical block.
80 Filesystem mappings are copied into the
82 array, which immediately follows the header data.
84 .SS Fields of struct fsmap_head
87 field is a bit mask passed to the kernel to alter the output.
88 No flags are currently defined, so the caller must set this value to zero.
92 field is a bit mask of flags set by the kernel concerning the returned mappings.
99 structure containing the major and minor numbers of the block device.
103 field contains the number of elements in the array being passed to the
107 will be set to the number of records that would have been returned had
108 the array been large enough;
109 no mapping information will be returned.
113 field contains the number of elements in the
115 array that contain useful information.
119 fields must be set to zero.
122 The two key records in
123 .I fsmap_head.fmh_keys
124 specify the lowest and highest extent records in the keyspace that the caller
126 A filesystem that can share blocks between files likely requires the tuple
127 .RI "(" "device" ", " "physical" ", " "owner" ", " "offset" ", " "flags" ")"
128 to uniquely index any filesystem mapping record.
129 Classic non-sharing filesystems might be able to identify any record with only
130 .RI "(" "device" ", " "physical" ", " "flags" ")."
131 For example, if the low key is set to (8:0, 36864, 0, 0, 0), the filesystem will
132 only return records for extents starting at or above 36\ KiB on disk.
133 If the high key is set to (8:0, 1048576, 0, 0, 0), only records below 1\ MiB will
137 in the keys must match the format of the same field in the output records,
139 By convention, the field
140 .I fsmap_head.fmh_keys[0]
141 must contain the low key and
142 .I fsmap_head.fmh_keys[1]
143 must contain the high key for the request.
147 is set in the low key, it will be added to
148 .IR fmr_block " or " fmr_offset
150 The caller can take advantage of this subtlety to set up subsequent calls
152 .I fsmap_head.fmh_recs[fsmap_head.fmh_entries \- 1]
158 provides this functionality.
160 .SS Fields of struct fsmap
163 field uniquely identifies the underlying storage device.
166 flag is set in the header's
168 field, this field contains a
170 from which major and minor numbers can be extracted.
171 If the flag is not set, this field contains a value that must be unique
172 for each unique storage device.
176 field contains the disk address of the extent in bytes.
180 field contains the owner of the extent.
181 This is an inode number unless
182 .B FMR_OF_SPECIAL_OWNER
185 field, in which case the value is determined by the filesystem.
186 See the section below about owner values for more details.
190 field contains the logical address in the mapping record in bytes.
191 This field has no meaning if the
192 .BR FMR_OF_SPECIAL_OWNER " or " FMR_OF_EXTENT_MAP
198 field contains the length of the extent in bytes.
202 field is a bit mask of extent state flags.
207 The extent is allocated but not yet written.
210 This extent contains extended attribute data.
213 This extent contains extent map information for the owner.
216 Parts of this extent may be shared.
218 .B FMR_OF_SPECIAL_OWNER
221 field contains a special value instead of an inode number.
224 This is the last record in the data set.
229 field will be set to zero.
232 Generally, the value of the
234 field for non-metadata extents should be an inode number.
235 However, filesystems are under no obligation to report inode numbers;
236 they may instead report
238 if the inode number cannot easily be retrieved, if the caller lacks
239 sufficient privilege, if the filesystem does not support stable
240 inode numbers, or for any other reason.
241 If a filesystem wishes to condition the reporting of inode numbers based
242 on process capabilities, it is strongly urged that the
244 capability be used for this purpose.
246 The following special owner values are generic to all filesystems:
253 This extent is in use but its owner is not known or not easily retrieved.
256 This extent is filesystem metadata.
259 XFS can return the following special owner values:
265 .B XFS_FMR_OWN_UNKNOWN
266 This extent is in use but its owner is not known or not easily retrieved.
269 Static filesystem metadata which exists at a fixed address.
270 These are the AG superblock, the AGF, the AGFL, and the AGI headers.
273 The filesystem journal.
276 Allocation group metadata, such as the free space btrees and the
277 reverse mapping btrees.
280 The inode and free inode btrees.
282 .B XFS_FMR_OWN_INODES
286 Reference count information.
289 This extent is being used to stage a copy-on-write.
291 .B XFS_FMR_OWN_DEFECTIVE:
292 This extent has been marked defective either by the filesystem or the
296 ext4 can return the following special owner values:
302 .B EXT4_FMR_OWN_UNKNOWN
303 This extent is in use but its owner is not known or not easily retrieved.
306 Static filesystem metadata which exists at a fixed address.
307 This is the superblock and the group descriptors.
310 The filesystem journal.
312 .B EXT4_FMR_OWN_INODES
315 .B EXT4_FMR_OWN_BLKBM
318 .B EXT4_FMR_OWN_INOBM
322 On error, \-1 is returned, and
324 is set to indicate the error.
328 can be one of, but is not limited to, the following:
332 is not open for reading.
335 The filesystem has detected a checksum error in the metadata.
338 The pointer passed in was not mapped to a valid memory address.
341 The array is not long enough, the keys do not point to a valid part of
342 the filesystem, the low key points to a higher point in the filesystem's
343 physical storage address space than the high key, or a nonzero value
344 was passed in one of the fields that must be zero.
347 Insufficient memory to process the request.
350 The filesystem does not support this command.
353 The filesystem metadata is corrupt and needs repair.
357 operation first appeared in Linux 4.12.
359 This API is Linux-specific.
360 Not all filesystems support it.
366 distribution for a sample program.