• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * ioctl.h - f2fs ioctl header
3  *
4  * Authors: Jaegeuk Kim <jaegeuk@kernel.org>
5  */
6 
7 #include <sys/types.h>
8 #include <sys/ioctl.h>
9 
10 #ifdef HAVE_LINUX_TYPES_H
11 #include <linux/types.h>
12 #endif
13 #ifdef HAVE_LINUX_FIEMAP_H
14 #include <linux/fiemap.h>
15 #endif
16 #ifdef HAVE_LINUX_FS_H
17 #include <linux/fs.h>
18 #endif
19 
20 #include <sys/types.h>
21 
22 #ifdef UNUSED
23 #elif defined(__GNUC__)
24 # define UNUSED(x) UNUSED_ ## x __attribute__((unused))
25 #elif defined(__LCLINT__)
26 # define UNUSED(x) x
27 #elif defined(__cplusplus)
28 # define UNUSED(x)
29 #else
30 # define UNUSED(x) x
31 #endif
32 
33 typedef u_int64_t	u64;
34 typedef u_int32_t	u32;
35 typedef u_int16_t	u16;
36 typedef u_int8_t	u8;
37 
38 #ifndef HAVE_LINUX_TYPES_H
39 typedef u8	__u8;
40 typedef u16	__u16;
41 typedef u32	__u32;
42 typedef u16	__le16;
43 typedef u32	__le32;
44 typedef u16	__be16;
45 typedef u32	__be32;
46 #endif
47 
48 #define F2FS_BLKSIZE	4096
49 #define NEW_ADDR	0xFFFFFFFF
50 
51 #ifndef FS_IOC_GETFLAGS
52 #define FS_IOC_GETFLAGS			_IOR('f', 1, long)
53 #endif
54 #ifndef FS_IOC_SETFLAGS
55 #define FS_IOC_SETFLAGS			_IOW('f', 2, long)
56 #endif
57 
58 #define F2FS_IOCTL_MAGIC		0xf5
59 #define F2FS_IOC_GETFLAGS		FS_IOC_GETFLAGS
60 #define F2FS_IOC_SETFLAGS		FS_IOC_SETFLAGS
61 
62 #define F2FS_IOC_START_ATOMIC_WRITE	_IO(F2FS_IOCTL_MAGIC, 1)
63 #define F2FS_IOC_COMMIT_ATOMIC_WRITE	_IO(F2FS_IOCTL_MAGIC, 2)
64 #define F2FS_IOC_START_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 3)
65 #define F2FS_IOC_RELEASE_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 4)
66 #define F2FS_IOC_ABORT_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 5)
67 #define F2FS_IOC_GARBAGE_COLLECT	_IOW(F2FS_IOCTL_MAGIC, 6, __u32)
68 #define F2FS_IOC_WRITE_CHECKPOINT	_IO(F2FS_IOCTL_MAGIC, 7)
69 #define F2FS_IOC_DEFRAGMENT		_IOWR(F2FS_IOCTL_MAGIC, 8,	\
70 						struct f2fs_defragment)
71 #define F2FS_IOC_MOVE_RANGE		_IOWR(F2FS_IOCTL_MAGIC, 9,	\
72 						struct f2fs_move_range)
73 #define F2FS_IOC_FLUSH_DEVICE		_IOW(F2FS_IOCTL_MAGIC, 10,	\
74 						struct f2fs_flush_device)
75 #define F2FS_IOC_GARBAGE_COLLECT_RANGE	_IOW(F2FS_IOCTL_MAGIC, 11,	\
76 						struct f2fs_gc_range)
77 #define F2FS_IOC_GET_FEATURES		_IOR(F2FS_IOCTL_MAGIC, 12, __u32)
78 #define F2FS_IOC_SET_PIN_FILE		_IOW(F2FS_IOCTL_MAGIC, 13, __u32)
79 #define F2FS_IOC_GET_PIN_FILE		_IOR(F2FS_IOCTL_MAGIC, 14, __u32)
80 #define F2FS_IOC_PRECACHE_EXTENTS	_IO(F2FS_IOCTL_MAGIC, 15)
81 #define F2FS_IOC_RESIZE_FS		_IOW(F2FS_IOCTL_MAGIC, 16, __u64)
82 #define F2FS_IOC_GET_COMPRESS_BLOCKS	_IOR(F2FS_IOCTL_MAGIC, 17, __u64)
83 #define F2FS_IOC_RELEASE_COMPRESS_BLOCKS				\
84 					_IOR(F2FS_IOCTL_MAGIC, 18, __u64)
85 #define F2FS_IOC_RESERVE_COMPRESS_BLOCKS				\
86 					_IOR(F2FS_IOCTL_MAGIC, 19, __u64)
87 #define F2FS_IOC_GET_COMPRESS_OPTION    _IOR(F2FS_IOCTL_MAGIC, 21,      \
88 						struct f2fs_comp_option)
89 #define F2FS_IOC_SET_COMPRESS_OPTION    _IOW(F2FS_IOCTL_MAGIC, 22,      \
90 						struct f2fs_comp_option)
91 #define F2FS_IOC_DECOMPRESS_FILE        _IO(F2FS_IOCTL_MAGIC, 23)
92 #define F2FS_IOC_COMPRESS_FILE          _IO(F2FS_IOCTL_MAGIC, 24)
93 
94 #ifndef FSCRYPT_POLICY_V1
95 #define FSCRYPT_POLICY_V1		0
96 #define FSCRYPT_KEY_DESCRIPTOR_SIZE	8
97 struct fscrypt_policy_v1 {
98 	__u8 version;
99 	__u8 contents_encryption_mode;
100 	__u8 filenames_encryption_mode;
101 	__u8 flags;
102 	__u8 master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE];
103 };
104 #endif
105 #ifndef FS_IOC_GET_ENCRYPTION_POLICY
106 #define FS_IOC_GET_ENCRYPTION_POLICY		_IOW('f', 21, struct fscrypt_policy_v1)
107 #endif
108 
109 #ifndef FSCRYPT_POLICY_V2
110 #define FSCRYPT_POLICY_V2		2
111 #define FSCRYPT_KEY_IDENTIFIER_SIZE	16
112 struct fscrypt_policy_v2 {
113 	__u8 version;
114 	__u8 contents_encryption_mode;
115 	__u8 filenames_encryption_mode;
116 	__u8 flags;
117 	__u8 __reserved[4];
118 	__u8 master_key_identifier[FSCRYPT_KEY_IDENTIFIER_SIZE];
119 };
120 /* Struct passed to FS_IOC_GET_ENCRYPTION_POLICY_EX */
121 struct fscrypt_get_policy_ex_arg {
122 	__u64 policy_size; /* input/output */
123 	union {
124 		__u8 version;
125 		struct fscrypt_policy_v1 v1;
126 		struct fscrypt_policy_v2 v2;
127 	} policy; /* output */
128 };
129 #endif
130 #ifndef FS_IOC_GET_ENCRYPTION_POLICY_EX
131 #define FS_IOC_GET_ENCRYPTION_POLICY_EX		_IOWR('f', 22, __u8[9]) /* size + version */
132 #endif
133 
134 #define F2FS_IOC_SET_ENCRYPTION_POLICY	FS_IOC_SET_ENCRYPTION_POLICY
135 #define F2FS_IOC_GET_ENCRYPTION_POLICY	FS_IOC_GET_ENCRYPTION_POLICY
136 #define F2FS_IOC_GET_ENCRYPTION_PWSALT	FS_IOC_GET_ENCRYPTION_PWSALT
137 
138 #define FS_IOC_ENABLE_VERITY		_IO('f', 133)
139 
140 /*
141  * Inode flags
142  */
143 #define F2FS_NOCOW_FL			0x00800000 /* Do not cow file */
144 
145 /*
146  * should be same as XFS_IOC_GOINGDOWN.
147  * Flags for going down operation used by FS_IOC_GOINGDOWN
148  */
149 #define F2FS_IOC_SHUTDOWN	_IOR('X', 125, __u32)	/* Shutdown */
150 #define F2FS_GOING_DOWN_FULLSYNC	0x0	/* going down with full sync */
151 #define F2FS_GOING_DOWN_METASYNC	0x1	/* going down with metadata */
152 #define F2FS_GOING_DOWN_NOSYNC		0x2	/* going down */
153 #define F2FS_GOING_DOWN_METAFLUSH	0x3	/* going down with meta flush */
154 #define F2FS_GOING_DOWN_NEED_FSCK	0x4	/* going down to trigger fsck */
155 #define F2FS_GOING_DOWN_MAX		0x5
156 
157 #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
158 /*
159  * ioctl commands in 32 bit emulation
160  */
161 #define F2FS_IOC32_GETFLAGS		FS_IOC32_GETFLAGS
162 #define F2FS_IOC32_SETFLAGS		FS_IOC32_SETFLAGS
163 #define F2FS_IOC32_GETVERSION		FS_IOC32_GETVERSION
164 #endif
165 
166 #define F2FS_IOC_FSGETXATTR		FS_IOC_FSGETXATTR
167 #define F2FS_IOC_FSSETXATTR		FS_IOC_FSSETXATTR
168 
169 #ifndef FS_ENCRYPT_FL
170 #define FS_ENCRYPT_FL			0x00000800 /* Encrypted file */
171 #endif
172 #ifndef FS_VERITY_FL
173 #define FS_VERITY_FL			0x00100000 /* Verity protected inode */
174 #endif
175 #ifndef FS_INLINE_DATA_FL
176 #define FS_INLINE_DATA_FL		0x10000000 /* Inline data for regular/symlink files */
177 #endif
178 #ifndef FS_NOCOW_FL
179 #define FS_NOCOW_FL			0x00800000 /* Do not cow file */
180 #endif
181 #ifndef FS_NOCOMP_FL
182 #define FS_NOCOMP_FL			0x00000400 /* Don't compress */
183 #endif
184 #ifndef FS_COMPR_FL
185 #define FS_COMPR_FL			0x00000004 /* Compress file */
186 #endif
187 #ifndef FS_CASEFOLD_FL
188 #define FS_CASEFOLD_FL			0x40000000 /* Folder is case insensitive */
189 #endif
190 
191 struct f2fs_gc_range {
192 	u32 sync;
193 	u64 start;
194 	u64 len;
195 };
196 
197 struct f2fs_defragment {
198 	u64 start;
199 	u64 len;
200 };
201 
202 struct f2fs_move_range {
203 	u32 dst_fd;		/* destination fd */
204 	u64 pos_in;		/* start position in src_fd */
205 	u64 pos_out;		/* start position in dst_fd */
206 	u64 len;		/* size to move */
207 };
208 
209 struct f2fs_flush_device {
210 	u32 dev_num;		/* device number to flush */
211 	u32 segments;		/* # of segments to flush */
212 };
213 
214 struct f2fs_comp_option {
215 	u8 algorithm;
216 	u8 log_cluster_size;
217 };
218