1 vfs: add common GETFSMAP ioctl definitions
3 From: "Darrick J. Wong" <darrick.wong@oracle.com>
5 Add the GETFSMAP headers to the VFS kernel headers
7 Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
8 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 include/uapi/linux/fsmap.h | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11 1 file changed, 112 insertions(+)
13 diff --git a/include/uapi/linux/fsmap.h b/include/uapi/linux/fsmap.h
15 index 000000000000..7e8e5f0bd6d2
17 +++ b/include/uapi/linux/fsmap.h
20 + * FS_IOC_GETFSMAP ioctl infrastructure.
22 + * Copyright (C) 2017 Oracle. All Rights Reserved.
24 + * Author: Darrick J. Wong <darrick.wong@oracle.com>
26 +#ifndef _LINUX_FSMAP_H
27 +#define _LINUX_FSMAP_H
29 +#include <linux/types.h>
32 + * Structure for FS_IOC_GETFSMAP.
34 + * The memory layout for this call are the scalar values defined in
35 + * struct fsmap_head, followed by two struct fsmap that describe
36 + * the lower and upper bound of mappings to return, followed by an
37 + * array of struct fsmap mappings.
39 + * fmh_iflags control the output of the call, whereas fmh_oflags report
40 + * on the overall record output. fmh_count should be set to the
41 + * length of the fmh_recs array, and fmh_entries will be set to the
42 + * number of entries filled out during each call. If fmh_count is
43 + * zero, the number of reverse mappings will be returned in
44 + * fmh_entries, though no mappings will be returned. fmh_reserved
45 + * must be set to zero.
47 + * The two elements in the fmh_keys array are used to constrain the
48 + * output. The first element in the array should represent the
49 + * lowest disk mapping ("low key") that the user wants to learn
50 + * about. If this value is all zeroes, the filesystem will return
51 + * the first entry it knows about. For a subsequent call, the
52 + * contents of fsmap_head.fmh_recs[fsmap_head.fmh_count - 1] should be
53 + * copied into fmh_keys[0] to have the kernel start where it left off.
55 + * The second element in the fmh_keys array should represent the
56 + * highest disk mapping ("high key") that the user wants to learn
57 + * about. If this value is all ones, the filesystem will not stop
58 + * until it runs out of mapping to return or runs out of space in
61 + * fmr_device can be either a 32-bit cookie representing a device, or
62 + * a 32-bit dev_t if the FMH_OF_DEV_T flag is set. fmr_physical,
63 + * fmr_offset, and fmr_length are expressed in units of bytes.
64 + * fmr_owner is either an inode number, or a special value if
65 + * FMR_OF_SPECIAL_OWNER is set in fmr_flags.
68 + __u32 fmr_device; /* device id */
69 + __u32 fmr_flags; /* mapping flags */
70 + __u64 fmr_physical; /* device offset of segment */
71 + __u64 fmr_owner; /* owner id */
72 + __u64 fmr_offset; /* file offset of segment */
73 + __u64 fmr_length; /* length of segment */
74 + __u64 fmr_reserved[3]; /* must be zero */
78 + __u32 fmh_iflags; /* control flags */
79 + __u32 fmh_oflags; /* output flags */
80 + __u32 fmh_count; /* # of entries in array incl. input */
81 + __u32 fmh_entries; /* # of entries filled in (output). */
82 + __u64 fmh_reserved[6]; /* must be zero */
84 + struct fsmap fmh_keys[2]; /* low and high keys for the mapping search */
85 + struct fsmap fmh_recs[]; /* returned records */
88 +/* Size of an fsmap_head with room for nr records. */
93 + return sizeof(struct fsmap_head) + nr * sizeof(struct fsmap);
96 +/* Start the next fsmap query at the end of the current query results. */
99 + struct fsmap_head *head)
101 + head->fmh_keys[0] = head->fmh_recs[head->fmh_entries - 1];
104 +/* fmh_iflags values - set by FS_IOC_GETFSMAP caller in the header. */
105 +/* no flags defined yet */
106 +#define FMH_IF_VALID 0
108 +/* fmh_oflags values - returned in the header segment only. */
109 +#define FMH_OF_DEV_T 0x1 /* fmr_device values will be dev_t */
111 +/* fmr_flags values - returned for each non-header segment */
112 +#define FMR_OF_PREALLOC 0x1 /* segment = unwritten pre-allocation */
113 +#define FMR_OF_ATTR_FORK 0x2 /* segment = attribute fork */
114 +#define FMR_OF_EXTENT_MAP 0x4 /* segment = extent map */
115 +#define FMR_OF_SHARED 0x8 /* segment = shared with another file */
116 +#define FMR_OF_SPECIAL_OWNER 0x10 /* owner is a special value */
117 +#define FMR_OF_LAST 0x20 /* segment is the last in the FS */
119 +/* Each FS gets to define its own special owner codes. */
120 +#define FMR_OWNER(type, code) (((__u64)type << 32) | \
121 + ((__u64)code & 0xFFFFFFFFULL))
122 +#define FMR_OWNER_TYPE(owner) ((__u32)((__u64)owner >> 32))
123 +#define FMR_OWNER_CODE(owner) ((__u32)(((__u64)owner & 0xFFFFFFFFULL)))
124 +#define FMR_OWN_FREE FMR_OWNER(0, 1) /* free space */
125 +#define FMR_OWN_UNKNOWN FMR_OWNER(0, 2) /* unknown owner */
126 +#define FMR_OWN_METADATA FMR_OWNER(0, 3) /* metadata */
128 +#define FS_IOC_GETFSMAP _IOWR('X', 59, struct fsmap_head)
130 +#endif /* _LINUX_FSMAP_H */