xref: /OK3568_Linux_fs/kernel/include/uapi/linux/fsmap.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * FS_IOC_GETFSMAP ioctl infrastructure.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2017 Oracle.  All Rights Reserved.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Author: Darrick J. Wong <darrick.wong@oracle.com>
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun #ifndef _LINUX_FSMAP_H
10*4882a593Smuzhiyun #define _LINUX_FSMAP_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/types.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun /*
15*4882a593Smuzhiyun  *	Structure for FS_IOC_GETFSMAP.
16*4882a593Smuzhiyun  *
17*4882a593Smuzhiyun  *	The memory layout for this call are the scalar values defined in
18*4882a593Smuzhiyun  *	struct fsmap_head, followed by two struct fsmap that describe
19*4882a593Smuzhiyun  *	the lower and upper bound of mappings to return, followed by an
20*4882a593Smuzhiyun  *	array of struct fsmap mappings.
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  *	fmh_iflags control the output of the call, whereas fmh_oflags report
23*4882a593Smuzhiyun  *	on the overall record output.  fmh_count should be set to the
24*4882a593Smuzhiyun  *	length of the fmh_recs array, and fmh_entries will be set to the
25*4882a593Smuzhiyun  *	number of entries filled out during each call.  If fmh_count is
26*4882a593Smuzhiyun  *	zero, the number of reverse mappings will be returned in
27*4882a593Smuzhiyun  *	fmh_entries, though no mappings will be returned.  fmh_reserved
28*4882a593Smuzhiyun  *	must be set to zero.
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  *	The two elements in the fmh_keys array are used to constrain the
31*4882a593Smuzhiyun  *	output.  The first element in the array should represent the
32*4882a593Smuzhiyun  *	lowest disk mapping ("low key") that the user wants to learn
33*4882a593Smuzhiyun  *	about.  If this value is all zeroes, the filesystem will return
34*4882a593Smuzhiyun  *	the first entry it knows about.  For a subsequent call, the
35*4882a593Smuzhiyun  *	contents of fsmap_head.fmh_recs[fsmap_head.fmh_count - 1] should be
36*4882a593Smuzhiyun  *	copied into fmh_keys[0] to have the kernel start where it left off.
37*4882a593Smuzhiyun  *
38*4882a593Smuzhiyun  *	The second element in the fmh_keys array should represent the
39*4882a593Smuzhiyun  *	highest disk mapping ("high key") that the user wants to learn
40*4882a593Smuzhiyun  *	about.  If this value is all ones, the filesystem will not stop
41*4882a593Smuzhiyun  *	until it runs out of mapping to return or runs out of space in
42*4882a593Smuzhiyun  *	fmh_recs.
43*4882a593Smuzhiyun  *
44*4882a593Smuzhiyun  *	fmr_device can be either a 32-bit cookie representing a device, or
45*4882a593Smuzhiyun  *	a 32-bit dev_t if the FMH_OF_DEV_T flag is set.  fmr_physical,
46*4882a593Smuzhiyun  *	fmr_offset, and fmr_length are expressed in units of bytes.
47*4882a593Smuzhiyun  *	fmr_owner is either an inode number, or a special value if
48*4882a593Smuzhiyun  *	FMR_OF_SPECIAL_OWNER is set in fmr_flags.
49*4882a593Smuzhiyun  */
50*4882a593Smuzhiyun struct fsmap {
51*4882a593Smuzhiyun 	__u32		fmr_device;	/* device id */
52*4882a593Smuzhiyun 	__u32		fmr_flags;	/* mapping flags */
53*4882a593Smuzhiyun 	__u64		fmr_physical;	/* device offset of segment */
54*4882a593Smuzhiyun 	__u64		fmr_owner;	/* owner id */
55*4882a593Smuzhiyun 	__u64		fmr_offset;	/* file offset of segment */
56*4882a593Smuzhiyun 	__u64		fmr_length;	/* length of segment */
57*4882a593Smuzhiyun 	__u64		fmr_reserved[3];	/* must be zero */
58*4882a593Smuzhiyun };
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun struct fsmap_head {
61*4882a593Smuzhiyun 	__u32		fmh_iflags;	/* control flags */
62*4882a593Smuzhiyun 	__u32		fmh_oflags;	/* output flags */
63*4882a593Smuzhiyun 	__u32		fmh_count;	/* # of entries in array incl. input */
64*4882a593Smuzhiyun 	__u32		fmh_entries;	/* # of entries filled in (output). */
65*4882a593Smuzhiyun 	__u64		fmh_reserved[6];	/* must be zero */
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun 	struct fsmap	fmh_keys[2];	/* low and high keys for the mapping search */
68*4882a593Smuzhiyun 	struct fsmap	fmh_recs[];	/* returned records */
69*4882a593Smuzhiyun };
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun /* Size of an fsmap_head with room for nr records. */
72*4882a593Smuzhiyun static inline size_t
fsmap_sizeof(unsigned int nr)73*4882a593Smuzhiyun fsmap_sizeof(
74*4882a593Smuzhiyun 	unsigned int	nr)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun 	return sizeof(struct fsmap_head) + nr * sizeof(struct fsmap);
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /* Start the next fsmap query at the end of the current query results. */
80*4882a593Smuzhiyun static inline void
fsmap_advance(struct fsmap_head * head)81*4882a593Smuzhiyun fsmap_advance(
82*4882a593Smuzhiyun 	struct fsmap_head	*head)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun 	head->fmh_keys[0] = head->fmh_recs[head->fmh_entries - 1];
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun /*	fmh_iflags values - set by FS_IOC_GETFSMAP caller in the header. */
88*4882a593Smuzhiyun /* no flags defined yet */
89*4882a593Smuzhiyun #define FMH_IF_VALID		0
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun /*	fmh_oflags values - returned in the header segment only. */
92*4882a593Smuzhiyun #define FMH_OF_DEV_T		0x1	/* fmr_device values will be dev_t */
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun /*	fmr_flags values - returned for each non-header segment */
95*4882a593Smuzhiyun #define FMR_OF_PREALLOC		0x1	/* segment = unwritten pre-allocation */
96*4882a593Smuzhiyun #define FMR_OF_ATTR_FORK	0x2	/* segment = attribute fork */
97*4882a593Smuzhiyun #define FMR_OF_EXTENT_MAP	0x4	/* segment = extent map */
98*4882a593Smuzhiyun #define FMR_OF_SHARED		0x8	/* segment = shared with another file */
99*4882a593Smuzhiyun #define FMR_OF_SPECIAL_OWNER	0x10	/* owner is a special value */
100*4882a593Smuzhiyun #define FMR_OF_LAST		0x20	/* segment is the last in the dataset */
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun /* Each FS gets to define its own special owner codes. */
103*4882a593Smuzhiyun #define FMR_OWNER(type, code)	(((__u64)type << 32) | \
104*4882a593Smuzhiyun 				 ((__u64)code & 0xFFFFFFFFULL))
105*4882a593Smuzhiyun #define FMR_OWNER_TYPE(owner)	((__u32)((__u64)owner >> 32))
106*4882a593Smuzhiyun #define FMR_OWNER_CODE(owner)	((__u32)(((__u64)owner & 0xFFFFFFFFULL)))
107*4882a593Smuzhiyun #define FMR_OWN_FREE		FMR_OWNER(0, 1) /* free space */
108*4882a593Smuzhiyun #define FMR_OWN_UNKNOWN		FMR_OWNER(0, 2) /* unknown owner */
109*4882a593Smuzhiyun #define FMR_OWN_METADATA	FMR_OWNER(0, 3) /* metadata */
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun #define FS_IOC_GETFSMAP		_IOWR('X', 59, struct fsmap_head)
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun #endif /* _LINUX_FSMAP_H */
114