Changes.old: Add missing piece to 5.00 changelog
[man-pages.git] / man2 / ioctl_getfsmap.2
blob6892946c51b5885766f16e35102045764c989979
1 .\" Copyright (c) 2017, Oracle.  All rights reserved.
2 .\"
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.
8 .\"
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.
13 .\"
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.
18 .\"
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/>.
22 .\" %%%LICENSE_END
23 .TH IOCTL_GETFSMAP 2 2017-09-15 "Linux" "Linux Programmer's Manual"
24 .SH NAME
25 ioctl_getfsmap \- retrieve the physical layout of the filesystem
26 .SH SYNOPSIS
27 .br
28 .B #include <sys/ioctl.h>
29 .br
30 .B #include <linux/fs.h>
31 .br
32 .B #include <linux/fsmap.h>
33 .PP
34 .BI "int ioctl(int " fd ", FS_IOC_GETFSMAP, struct fsmap_head * " arg );
35 .SH DESCRIPTION
36 This
37 .BR ioctl (2)
38 operation retrieves physical extent mappings for a filesystem.
39 This information can be used to discover which files are mapped to a physical
40 block, examine free space, or find known bad blocks, among other things.
41 .PP
42 The sole argument to this operation should be a pointer to a single
43 .IR "struct fsmap_head" ":"
44 .PP
45 .in +4n
46 .EX
47 struct fsmap {
48     __u32 fmr_device;      /* Device ID */
49     __u32 fmr_flags;       /* Mapping flags */
50     __u64 fmr_physical;    /* Device offset of segment */
51     __u64 fmr_owner;       /* Owner ID */
52     __u64 fmr_offset;      /* File offset of segment */
53     __u64 fmr_length;      /* Length of segment */
54     __u64 fmr_reserved[3]; /* Must be zero */
57 struct fsmap_head {
58     __u32 fmh_iflags;       /* Control flags */
59     __u32 fmh_oflags;       /* Output flags */
60     __u32 fmh_count;        /* # of entries in array incl. input */
61     __u32 fmh_entries;      /* # of entries filled in (output) */
62     __u64 fmh_reserved[6];  /* Must be zero */
64     struct fsmap fmh_keys[2];  /* Low and high keys for
65                                   the mapping search */
66     struct fsmap fmh_recs[];   /* Returned records */
68 .EE
69 .in
70 .PP
71 The two
72 .I fmh_keys
73 array elements specify the lowest and highest reverse-mapping
74 key for which the application would like physical mapping
75 information.
76 A reverse mapping key consists of the tuple (device, block, owner, offset).
77 The owner and offset fields are part of the key because some filesystems
78 support sharing physical blocks between multiple files and
79 therefore may return multiple mappings for a given physical block.
80 .PP
81 Filesystem mappings are copied into the
82 .I fmh_recs
83 array, which immediately follows the header data.
84 .\"
85 .SS Fields of struct fsmap_head
86 .PP
87 The
88 .I fmh_iflags
89 field is a bit mask passed to the kernel to alter the output.
90 No flags are currently defined, so the caller must set this value to zero.
91 .PP
92 The
93 .I fmh_oflags
94 field is a bit mask of flags set by the kernel concerning the returned mappings.
96 .B FMH_OF_DEV_T
97 is set, then the
98 .I fmr_device
99 field represents a
100 .I dev_t
101 structure containing the major and minor numbers of the block device.
104 .I fmh_count
105 field contains the number of elements in the array being passed to the
106 kernel.
107 If this value is 0,
108 .I fmh_entries
109 will be set to the number of records that would have been returned had
110 the array been large enough;
111 no mapping information will be returned.
114 .I fmh_entries
115 field contains the number of elements in the
116 .I fmh_recs
117 array that contain useful information.
120 .I fmh_reserved
121 fields must be set to zero.
123 .SS Keys
125 The two key records in
126 .I fsmap_head.fmh_keys
127 specify the lowest and highest extent records in the keyspace that the caller
128 wants returned.
129 A filesystem that can share blocks between files likely requires the tuple
130 .RI "(" "device" ", " "physical" ", " "owner" ", " "offset" ", " "flags" ")"
131 to uniquely index any filesystem mapping record.
132 Classic non-sharing filesystems might be able to identify any record with only
133 .RI "(" "device" ", " "physical" ", " "flags" ")."
134 For example, if the low key is set to (8:0, 36864, 0, 0, 0), the filesystem will
135 only return records for extents starting at or above 36\ KiB on disk.
136 If the high key is set to (8:0, 1048576, 0, 0, 0), only records below 1\ MiB will
137 be returned.
138 The format of
139 .I fmr_device
140 in the keys must match the format of the same field in the output records,
141 as defined below.
142 By convention, the field
143 .I fsmap_head.fmh_keys[0]
144 must contain the low key and
145 .I fsmap_head.fmh_keys[1]
146 must contain the high key for the request.
148 For convenience, if
149 .I fmr_length
150 is set in the low key, it will be added to
151 .IR fmr_block " or " fmr_offset
152 as appropriate.
153 The caller can take advantage of this subtlety to set up subsequent calls
154 by copying
155 .I fsmap_head.fmh_recs[fsmap_head.fmh_entries \- 1]
156 into the low key.
157 The function
158 .I fsmap_advance
159 (defined in
160 .IR linux/fsmap.h )
161 provides this functionality.
163 .SS Fields of struct fsmap
166 .I fmr_device
167 field uniquely identifies the underlying storage device.
168 If the
169 .B FMH_OF_DEV_T
170 flag is set in the header's
171 .I fmh_oflags
172 field, this field contains a
173 .I dev_t
174 from which major and minor numbers can be extracted.
175 If the flag is not set, this field contains a value that must be unique
176 for each unique storage device.
179 .I fmr_physical
180 field contains the disk address of the extent in bytes.
183 .I fmr_owner
184 field contains the owner of the extent.
185 This is an inode number unless
186 .B FMR_OF_SPECIAL_OWNER
187 is set in the
188 .I fmr_flags
189 field, in which case the value is determined by the filesystem.
190 See the section below about owner values for more details.
193 .I fmr_offset
194 field contains the logical address in the mapping record in bytes.
195 This field has no meaning if the
196 .BR FMR_OF_SPECIAL_OWNER " or " FMR_OF_EXTENT_MAP
197 flags are set in
198 .IR fmr_flags "."
201 .I fmr_length
202 field contains the length of the extent in bytes.
205 .I fmr_flags
206 field is a bit mask of extent state flags.
207 The bits are:
208 .RS 0.4i
210 .B FMR_OF_PREALLOC
211 The extent is allocated but not yet written.
213 .B FMR_OF_ATTR_FORK
214 This extent contains extended attribute data.
216 .B FMR_OF_EXTENT_MAP
217 This extent contains extent map information for the owner.
219 .B FMR_OF_SHARED
220 Parts of this extent may be shared.
222 .B FMR_OF_SPECIAL_OWNER
224 .I fmr_owner
225 field contains a special value instead of an inode number.
227 .B FMR_OF_LAST
228 This is the last record in the data set.
232 .I fmr_reserved
233 field will be set to zero.
235 .SS Owner values
236 Generally, the value of the
237 .I fmr_owner
238 field for non-metadata extents should be an inode number.
239 However, filesystems are under no obligation to report inode numbers;
240 they may instead report
241 .B FMR_OWN_UNKNOWN
242 if the inode number cannot easily be retrieved, if the caller lacks
243 sufficient privilege, if the filesystem does not support stable
244 inode numbers, or for any other reason.
245 If a filesystem wishes to condition the reporting of inode numbers based
246 on process capabilities, it is strongly urged that the
247 .B CAP_SYS_ADMIN
248 capability be used for this purpose.
250 The following special owner values are generic to all filesystems:
251 .RS 0.4i
253 .B FMR_OWN_FREE
254 Free space.
256 .B FMR_OWN_UNKNOWN
257 This extent is in use but its owner is not known or not easily retrieved.
259 .B FMR_OWN_METADATA
260 This extent is filesystem metadata.
263 XFS can return the following special owner values:
264 .RS 0.4i
266 .B XFS_FMR_OWN_FREE
267 Free space.
269 .B XFS_FMR_OWN_UNKNOWN
270 This extent is in use but its owner is not known or not easily retrieved.
272 .B XFS_FMR_OWN_FS
273 Static filesystem metadata which exists at a fixed address.
274 These are the AG superblock, the AGF, the AGFL, and the AGI headers.
276 .B XFS_FMR_OWN_LOG
277 The filesystem journal.
279 .B XFS_FMR_OWN_AG
280 Allocation group metadata, such as the free space btrees and the
281 reverse mapping btrees.
283 .B XFS_FMR_OWN_INOBT
284 The inode and free inode btrees.
286 .B XFS_FMR_OWN_INODES
287 Inode records.
289 .B XFS_FMR_OWN_REFC
290 Reference count information.
292 .B XFS_FMR_OWN_COW
293 This extent is being used to stage a copy-on-write.
295 .B XFS_FMR_OWN_DEFECTIVE:
296 This extent has been marked defective either by the filesystem or the
297 underlying device.
300 ext4 can return the following special owner values:
301 .RS 0.4i
303 .B EXT4_FMR_OWN_FREE
304 Free space.
306 .B EXT4_FMR_OWN_UNKNOWN
307 This extent is in use but its owner is not known or not easily retrieved.
309 .B EXT4_FMR_OWN_FS
310 Static filesystem metadata which exists at a fixed address.
311 This is the superblock and the group descriptors.
313 .B EXT4_FMR_OWN_LOG
314 The filesystem journal.
316 .B EXT4_FMR_OWN_INODES
317 Inode records.
319 .B EXT4_FMR_OWN_BLKBM
320 Block bit map.
322 .B EXT4_FMR_OWN_INOBM
323 Inode bit map.
325 .SH RETURN VALUE
326 On error, \-1 is returned, and
327 .I errno
328 is set to indicate the error.
330 .SH ERRORS
331 The error placed in
332 .I errno
333 can be one of, but is not limited to, the following:
335 .B EBADF
336 .IR fd
337 is not open for reading.
339 .B EBADMSG
340 The filesystem has detected a checksum error in the metadata.
342 .B EFAULT
343 The pointer passed in was not mapped to a valid memory address.
345 .B EINVAL
346 The array is not long enough, the keys do not point to a valid part of
347 the filesystem, the low key points to a higher point in the filesystem's
348 physical storage address space than the high key, or a nonzero value
349 was passed in one of the fields that must be zero.
351 .B ENOMEM
352 Insufficient memory to process the request.
354 .B EOPNOTSUPP
355 The filesystem does not support this command.
357 .B EUCLEAN
358 The filesystem metadata is corrupt and needs repair.
359 .SH VERSIONS
361 .B FS_IOC_GETFSMAP
362 operation first appeared in Linux 4.12.
363 .SH CONFORMING TO
364 This API is Linux-specific.
365 Not all filesystems support it.
366 .SH EXAMPLE
368 .I io/fsmap.c
369 in the
370 .I xfsprogs
371 distribution for a sample program.
372 .SH SEE ALSO
373 .BR ioctl (2)