summaryrefslogtreecommitdiffstats
path: root/upstream/debian-bookworm/man2/ioctl_getfsmap.2
blob: 3f63f0841e931a058752dbbb679cf0f11711da1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
.\" Copyright (c) 2017, Oracle.  All rights reserved.
.\"
.\" SPDX-License-Identifier: GPL-2.0-or-later
.TH ioctl_getfsmap 2 2022-10-30 "Linux man-pages 6.03"
.SH NAME
ioctl_getfsmap \- retrieve the physical layout of the filesystem
.SH LIBRARY
Standard C library
.RI ( libc ", " \-lc )
.SH SYNOPSIS
.nf
.BR "#include <linux/fsmap.h>  " "/* Definition of " FS_IOC_GETFSMAP ,
.BR "                             FM?_OF_*" ", and " *FMR_OWN_* " constants */"
.B #include <sys/ioctl.h>
.PP
.BI "int ioctl(int " fd ", FS_IOC_GETFSMAP, struct fsmap_head * " arg );
.fi
.SH DESCRIPTION
This
.BR ioctl (2)
operation retrieves physical extent mappings for a filesystem.
This information can be used to discover which files are mapped to a physical
block, examine free space, or find known bad blocks, among other things.
.PP
The sole argument to this operation should be a pointer to a single
.IR "struct fsmap_head" ":"
.PP
.in +4n
.EX
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 incl. 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 */
};
.EE
.in
.PP
The two
.I fmh_keys
array elements specify the lowest and highest reverse-mapping
key for which the application would like physical mapping
information.
A reverse mapping key consists of 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 and
therefore may return multiple mappings for a given physical block.
.PP
Filesystem mappings are copied into the
.I fmh_recs
array, which immediately follows the header data.
.\"
.SS Fields of struct fsmap_head
The
.I fmh_iflags
field is a bit mask passed to the kernel to alter the output.
No flags are currently defined, so the caller must set this value to zero.
.PP
The
.I fmh_oflags
field is a bit mask of flags set by the kernel concerning the returned mappings.
If
.B FMH_OF_DEV_T
is set, then the
.I fmr_device
field represents a
.I dev_t
structure containing the major and minor numbers of the block device.
.PP
The
.I fmh_count
field contains the number of elements in the array being passed to the
kernel.
If this value is 0,
.I fmh_entries
will be set to the number of records that would have been returned had
the array been large enough;
no mapping information will be returned.
.PP
The
.I fmh_entries
field contains the number of elements in the
.I fmh_recs
array that contain useful information.
.PP
The
.I fmh_reserved
fields must be set to zero.
.\"
.SS Keys
The two key records in
.I 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 requires the tuple
.RI "(" "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
.RI "(" "device" ", " "physical" ", " "flags" ")."
For example, 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
.I fmr_device
in the keys must match the format of the same field in the output records,
as defined below.
By convention, the field
.I fsmap_head.fmh_keys[0]
must contain the low key and
.I fsmap_head.fmh_keys[1]
must contain the high key for the request.
.PP
For convenience, if
.I fmr_length
is set in the low key, it will be added to
.IR fmr_block " or " fmr_offset
as appropriate.
The caller can take advantage of this subtlety to set up subsequent calls
by copying
.I fsmap_head.fmh_recs[fsmap_head.fmh_entries \- 1]
into the low key.
The function
.I fsmap_advance
(defined in
.IR linux/fsmap.h )
provides this functionality.
.\"
.SS Fields of struct fsmap
The
.I fmr_device
field uniquely identifies the underlying storage device.
If the
.B FMH_OF_DEV_T
flag is set in the header's
.I fmh_oflags
field, this field contains a
.I 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.
.PP
The
.I fmr_physical
field contains the disk address of the extent in bytes.
.PP
The
.I fmr_owner
field contains the owner of the extent.
This is an inode number unless
.B FMR_OF_SPECIAL_OWNER
is set in the
.I fmr_flags
field, in which case the value is determined by the filesystem.
See the section below about owner values for more details.
.PP
The
.I fmr_offset
field contains the logical address in the mapping record in bytes.
This field has no meaning if the
.BR FMR_OF_SPECIAL_OWNER " or " FMR_OF_EXTENT_MAP
flags are set in
.IR fmr_flags "."
.PP
The
.I fmr_length
field contains the length of the extent in bytes.
.PP
The
.I fmr_flags
field is a bit mask of extent state flags.
The bits are:
.RS 0.4i
.TP
.B FMR_OF_PREALLOC
The extent is allocated but not yet written.
.TP
.B FMR_OF_ATTR_FORK
This extent contains extended attribute data.
.TP
.B FMR_OF_EXTENT_MAP
This extent contains extent map information for the owner.
.TP
.B FMR_OF_SHARED
Parts of this extent may be shared.
.TP
.B FMR_OF_SPECIAL_OWNER
The
.I fmr_owner
field contains a special value instead of an inode number.
.TP
.B FMR_OF_LAST
This is the last record in the data set.
.RE
.PP
The
.I fmr_reserved
field will be set to zero.
.\"
.SS Owner values
Generally, the value of the
.I 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
.B FMR_OWN_UNKNOWN
if the inode number cannot easily be retrieved, if the caller lacks
sufficient privilege, if the filesystem does not support stable
inode numbers, or for any other reason.
If a filesystem wishes to condition the reporting of inode numbers based
on process capabilities, it is strongly urged that the
.B CAP_SYS_ADMIN
capability be used for this purpose.
.TP
The following special owner values are generic to all filesystems:
.RS 0.4i
.TP
.B FMR_OWN_FREE
Free space.
.TP
.B FMR_OWN_UNKNOWN
This extent is in use but its owner is not known or not easily retrieved.
.TP
.B FMR_OWN_METADATA
This extent is filesystem metadata.
.RE
.PP
XFS can return the following special owner values:
.RS 0.4i
.TP
.B XFS_FMR_OWN_FREE
Free space.
.TP
.B XFS_FMR_OWN_UNKNOWN
This extent is in use but its owner is not known or not easily retrieved.
.TP
.B 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.
.TP
.B XFS_FMR_OWN_LOG
The filesystem journal.
.TP
.B XFS_FMR_OWN_AG
Allocation group metadata, such as the free space btrees and the
reverse mapping btrees.
.TP
.B XFS_FMR_OWN_INOBT
The inode and free inode btrees.
.TP
.B XFS_FMR_OWN_INODES
Inode records.
.TP
.B XFS_FMR_OWN_REFC
Reference count information.
.TP
.B XFS_FMR_OWN_COW
This extent is being used to stage a copy-on-write.
.TP
.B XFS_FMR_OWN_DEFECTIVE:
This extent has been marked defective either by the filesystem or the
underlying device.
.RE
.PP
ext4 can return the following special owner values:
.RS 0.4i
.TP
.B EXT4_FMR_OWN_FREE
Free space.
.TP
.B EXT4_FMR_OWN_UNKNOWN
This extent is in use but its owner is not known or not easily retrieved.
.TP
.B EXT4_FMR_OWN_FS
Static filesystem metadata which exists at a fixed address.
This is the superblock and the group descriptors.
.TP
.B EXT4_FMR_OWN_LOG
The filesystem journal.
.TP
.B EXT4_FMR_OWN_INODES
Inode records.
.TP
.B EXT4_FMR_OWN_BLKBM
Block bit map.
.TP
.B EXT4_FMR_OWN_INOBM
Inode bit map.
.RE
.SH RETURN VALUE
On error, \-1 is returned, and
.I errno
is set to indicate the error.
.SH ERRORS
The error placed in
.I errno
can be one of, but is not limited to, the following:
.TP
.B EBADF
.I fd
is not open for reading.
.TP
.B EBADMSG
The filesystem has detected a checksum error in the metadata.
.TP
.B EFAULT
The pointer passed in was not mapped to a valid memory address.
.TP
.B 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.
.TP
.B ENOMEM
Insufficient memory to process the request.
.TP
.B EOPNOTSUPP
The filesystem does not support this command.
.TP
.B EUCLEAN
The filesystem metadata is corrupt and needs repair.
.SH VERSIONS
The
.B FS_IOC_GETFSMAP
operation first appeared in Linux 4.12.
.SH STANDARDS
This API is Linux-specific.
Not all filesystems support it.
.SH EXAMPLES
See
.I io/fsmap.c
in the
.I xfsprogs
distribution for a sample program.
.SH SEE ALSO
.BR ioctl (2)