btrfs.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * Copyright (C) 2007 Oracle. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public
  7. * License v2 as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public
  15. * License along with this program; if not, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. * Boston, MA 021110-1307, USA.
  18. */
  19. #ifndef _UAPI_LINUX_BTRFS_H
  20. #define _UAPI_LINUX_BTRFS_H
  21. #include <linux/types.h>
  22. #include <linux/ioctl.h>
  23. #define BTRFS_IOCTL_MAGIC 0x94
  24. #define BTRFS_VOL_NAME_MAX 255
  25. #define BTRFS_LABEL_SIZE 256
  26. /* this should be 4k */
  27. #define BTRFS_PATH_NAME_MAX 4087
  28. struct btrfs_ioctl_vol_args {
  29. __s64 fd;
  30. char name[BTRFS_PATH_NAME_MAX + 1];
  31. };
  32. #define BTRFS_DEVICE_PATH_NAME_MAX 1024
  33. #define BTRFS_DEVICE_SPEC_BY_ID (1ULL << 3)
  34. #define BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED \
  35. (BTRFS_SUBVOL_CREATE_ASYNC | \
  36. BTRFS_SUBVOL_RDONLY | \
  37. BTRFS_SUBVOL_QGROUP_INHERIT | \
  38. BTRFS_DEVICE_SPEC_BY_ID)
  39. #define BTRFS_FSID_SIZE 16
  40. #define BTRFS_UUID_SIZE 16
  41. #define BTRFS_UUID_UNPARSED_SIZE 37
  42. /*
  43. * flags definition for qgroup limits
  44. *
  45. * Used by:
  46. * struct btrfs_qgroup_limit.flags
  47. * struct btrfs_qgroup_limit_item.flags
  48. */
  49. #define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0)
  50. #define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1)
  51. #define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2)
  52. #define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3)
  53. #define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4)
  54. #define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5)
  55. struct btrfs_qgroup_limit {
  56. __u64 flags;
  57. __u64 max_rfer;
  58. __u64 max_excl;
  59. __u64 rsv_rfer;
  60. __u64 rsv_excl;
  61. };
  62. /*
  63. * flags definition for qgroup inheritance
  64. *
  65. * Used by:
  66. * struct btrfs_qgroup_inherit.flags
  67. */
  68. #define BTRFS_QGROUP_INHERIT_SET_LIMITS (1ULL << 0)
  69. struct btrfs_qgroup_inherit {
  70. __u64 flags;
  71. __u64 num_qgroups;
  72. __u64 num_ref_copies;
  73. __u64 num_excl_copies;
  74. struct btrfs_qgroup_limit lim;
  75. __u64 qgroups[0];
  76. };
  77. struct btrfs_ioctl_qgroup_limit_args {
  78. __u64 qgroupid;
  79. struct btrfs_qgroup_limit lim;
  80. };
  81. /*
  82. * flags for subvolumes
  83. *
  84. * Used by:
  85. * struct btrfs_ioctl_vol_args_v2.flags
  86. *
  87. * BTRFS_SUBVOL_RDONLY is also provided/consumed by the following ioctls:
  88. * - BTRFS_IOC_SUBVOL_GETFLAGS
  89. * - BTRFS_IOC_SUBVOL_SETFLAGS
  90. */
  91. #define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
  92. #define BTRFS_SUBVOL_RDONLY (1ULL << 1)
  93. #define BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2)
  94. #define BTRFS_SUBVOL_NAME_MAX 4039
  95. struct btrfs_ioctl_vol_args_v2 {
  96. __s64 fd;
  97. __u64 transid;
  98. __u64 flags;
  99. union {
  100. struct {
  101. __u64 size;
  102. struct btrfs_qgroup_inherit __user *qgroup_inherit;
  103. };
  104. __u64 unused[4];
  105. };
  106. union {
  107. char name[BTRFS_SUBVOL_NAME_MAX + 1];
  108. __u64 devid;
  109. };
  110. };
  111. /*
  112. * structure to report errors and progress to userspace, either as a
  113. * result of a finished scrub, a canceled scrub or a progress inquiry
  114. */
  115. struct btrfs_scrub_progress {
  116. __u64 data_extents_scrubbed; /* # of data extents scrubbed */
  117. __u64 tree_extents_scrubbed; /* # of tree extents scrubbed */
  118. __u64 data_bytes_scrubbed; /* # of data bytes scrubbed */
  119. __u64 tree_bytes_scrubbed; /* # of tree bytes scrubbed */
  120. __u64 read_errors; /* # of read errors encountered (EIO) */
  121. __u64 csum_errors; /* # of failed csum checks */
  122. __u64 verify_errors; /* # of occurences, where the metadata
  123. * of a tree block did not match the
  124. * expected values, like generation or
  125. * logical */
  126. __u64 no_csum; /* # of 4k data block for which no csum
  127. * is present, probably the result of
  128. * data written with nodatasum */
  129. __u64 csum_discards; /* # of csum for which no data was found
  130. * in the extent tree. */
  131. __u64 super_errors; /* # of bad super blocks encountered */
  132. __u64 malloc_errors; /* # of internal kmalloc errors. These
  133. * will likely cause an incomplete
  134. * scrub */
  135. __u64 uncorrectable_errors; /* # of errors where either no intact
  136. * copy was found or the writeback
  137. * failed */
  138. __u64 corrected_errors; /* # of errors corrected */
  139. __u64 last_physical; /* last physical address scrubbed. In
  140. * case a scrub was aborted, this can
  141. * be used to restart the scrub */
  142. __u64 unverified_errors; /* # of occurences where a read for a
  143. * full (64k) bio failed, but the re-
  144. * check succeeded for each 4k piece.
  145. * Intermittent error. */
  146. };
  147. #define BTRFS_SCRUB_READONLY 1
  148. struct btrfs_ioctl_scrub_args {
  149. __u64 devid; /* in */
  150. __u64 start; /* in */
  151. __u64 end; /* in */
  152. __u64 flags; /* in */
  153. struct btrfs_scrub_progress progress; /* out */
  154. /* pad to 1k */
  155. __u64 unused[(1024-32-sizeof(struct btrfs_scrub_progress))/8];
  156. };
  157. #define BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
  158. #define BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
  159. struct btrfs_ioctl_dev_replace_start_params {
  160. __u64 srcdevid; /* in, if 0, use srcdev_name instead */
  161. __u64 cont_reading_from_srcdev_mode; /* in, see #define
  162. * above */
  163. __u8 srcdev_name[BTRFS_DEVICE_PATH_NAME_MAX + 1]; /* in */
  164. __u8 tgtdev_name[BTRFS_DEVICE_PATH_NAME_MAX + 1]; /* in */
  165. };
  166. #define BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED 0
  167. #define BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED 1
  168. #define BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED 2
  169. #define BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED 3
  170. #define BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED 4
  171. struct btrfs_ioctl_dev_replace_status_params {
  172. __u64 replace_state; /* out, see #define above */
  173. __u64 progress_1000; /* out, 0 <= x <= 1000 */
  174. __u64 time_started; /* out, seconds since 1-Jan-1970 */
  175. __u64 time_stopped; /* out, seconds since 1-Jan-1970 */
  176. __u64 num_write_errors; /* out */
  177. __u64 num_uncorrectable_read_errors; /* out */
  178. };
  179. #define BTRFS_IOCTL_DEV_REPLACE_CMD_START 0
  180. #define BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS 1
  181. #define BTRFS_IOCTL_DEV_REPLACE_CMD_CANCEL 2
  182. #define BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR 0
  183. #define BTRFS_IOCTL_DEV_REPLACE_RESULT_NOT_STARTED 1
  184. #define BTRFS_IOCTL_DEV_REPLACE_RESULT_ALREADY_STARTED 2
  185. #define BTRFS_IOCTL_DEV_REPLACE_RESULT_SCRUB_INPROGRESS 3
  186. struct btrfs_ioctl_dev_replace_args {
  187. __u64 cmd; /* in */
  188. __u64 result; /* out */
  189. union {
  190. struct btrfs_ioctl_dev_replace_start_params start;
  191. struct btrfs_ioctl_dev_replace_status_params status;
  192. }; /* in/out */
  193. __u64 spare[64];
  194. };
  195. struct btrfs_ioctl_dev_info_args {
  196. __u64 devid; /* in/out */
  197. __u8 uuid[BTRFS_UUID_SIZE]; /* in/out */
  198. __u64 bytes_used; /* out */
  199. __u64 total_bytes; /* out */
  200. __u64 unused[379]; /* pad to 4k */
  201. __u8 path[BTRFS_DEVICE_PATH_NAME_MAX]; /* out */
  202. };
  203. struct btrfs_ioctl_fs_info_args {
  204. __u64 max_id; /* out */
  205. __u64 num_devices; /* out */
  206. __u8 fsid[BTRFS_FSID_SIZE]; /* out */
  207. __u32 nodesize; /* out */
  208. __u32 sectorsize; /* out */
  209. __u32 clone_alignment; /* out */
  210. __u32 reserved32;
  211. __u64 reserved[122]; /* pad to 1k */
  212. };
  213. /*
  214. * feature flags
  215. *
  216. * Used by:
  217. * struct btrfs_ioctl_feature_flags
  218. */
  219. #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE (1ULL << 0)
  220. /*
  221. * Older kernels (< 4.9) on big-endian systems produced broken free space tree
  222. * bitmaps, and btrfs-progs also used to corrupt the free space tree (versions
  223. * < 4.7.3). If this bit is clear, then the free space tree cannot be trusted.
  224. * btrfs-progs can also intentionally clear this bit to ask the kernel to
  225. * rebuild the free space tree, however this might not work on older kernels
  226. * that do not know about this bit. If not sure, clear the cache manually on
  227. * first mount when booting older kernel versions.
  228. */
  229. #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID (1ULL << 1)
  230. #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
  231. #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
  232. #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
  233. #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3)
  234. #define BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD (1ULL << 4)
  235. /*
  236. * older kernels tried to do bigger metadata blocks, but the
  237. * code was pretty buggy. Lets not let them try anymore.
  238. */
  239. #define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5)
  240. #define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
  241. #define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
  242. #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)
  243. #define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9)
  244. struct btrfs_ioctl_feature_flags {
  245. __u64 compat_flags;
  246. __u64 compat_ro_flags;
  247. __u64 incompat_flags;
  248. };
  249. /* balance control ioctl modes */
  250. #define BTRFS_BALANCE_CTL_PAUSE 1
  251. #define BTRFS_BALANCE_CTL_CANCEL 2
  252. /*
  253. * this is packed, because it should be exactly the same as its disk
  254. * byte order counterpart (struct btrfs_disk_balance_args)
  255. */
  256. struct btrfs_balance_args {
  257. __u64 profiles;
  258. union {
  259. __u64 usage;
  260. struct {
  261. __u32 usage_min;
  262. __u32 usage_max;
  263. };
  264. };
  265. __u64 devid;
  266. __u64 pstart;
  267. __u64 pend;
  268. __u64 vstart;
  269. __u64 vend;
  270. __u64 target;
  271. __u64 flags;
  272. /*
  273. * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
  274. * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
  275. * and maximum
  276. */
  277. union {
  278. __u64 limit; /* limit number of processed chunks */
  279. struct {
  280. __u32 limit_min;
  281. __u32 limit_max;
  282. };
  283. };
  284. /*
  285. * Process chunks that cross stripes_min..stripes_max devices,
  286. * BTRFS_BALANCE_ARGS_STRIPES_RANGE
  287. */
  288. __u32 stripes_min;
  289. __u32 stripes_max;
  290. __u64 unused[6];
  291. } __attribute__ ((__packed__));
  292. /* report balance progress to userspace */
  293. struct btrfs_balance_progress {
  294. __u64 expected; /* estimated # of chunks that will be
  295. * relocated to fulfill the request */
  296. __u64 considered; /* # of chunks we have considered so far */
  297. __u64 completed; /* # of chunks relocated so far */
  298. };
  299. /*
  300. * flags definition for balance
  301. *
  302. * Restriper's general type filter
  303. *
  304. * Used by:
  305. * btrfs_ioctl_balance_args.flags
  306. * btrfs_balance_control.flags (internal)
  307. */
  308. #define BTRFS_BALANCE_DATA (1ULL << 0)
  309. #define BTRFS_BALANCE_SYSTEM (1ULL << 1)
  310. #define BTRFS_BALANCE_METADATA (1ULL << 2)
  311. #define BTRFS_BALANCE_TYPE_MASK (BTRFS_BALANCE_DATA | \
  312. BTRFS_BALANCE_SYSTEM | \
  313. BTRFS_BALANCE_METADATA)
  314. #define BTRFS_BALANCE_FORCE (1ULL << 3)
  315. #define BTRFS_BALANCE_RESUME (1ULL << 4)
  316. /*
  317. * flags definitions for per-type balance args
  318. *
  319. * Balance filters
  320. *
  321. * Used by:
  322. * struct btrfs_balance_args
  323. */
  324. #define BTRFS_BALANCE_ARGS_PROFILES (1ULL << 0)
  325. #define BTRFS_BALANCE_ARGS_USAGE (1ULL << 1)
  326. #define BTRFS_BALANCE_ARGS_DEVID (1ULL << 2)
  327. #define BTRFS_BALANCE_ARGS_DRANGE (1ULL << 3)
  328. #define BTRFS_BALANCE_ARGS_VRANGE (1ULL << 4)
  329. #define BTRFS_BALANCE_ARGS_LIMIT (1ULL << 5)
  330. #define BTRFS_BALANCE_ARGS_LIMIT_RANGE (1ULL << 6)
  331. #define BTRFS_BALANCE_ARGS_STRIPES_RANGE (1ULL << 7)
  332. #define BTRFS_BALANCE_ARGS_USAGE_RANGE (1ULL << 10)
  333. #define BTRFS_BALANCE_ARGS_MASK \
  334. (BTRFS_BALANCE_ARGS_PROFILES | \
  335. BTRFS_BALANCE_ARGS_USAGE | \
  336. BTRFS_BALANCE_ARGS_DEVID | \
  337. BTRFS_BALANCE_ARGS_DRANGE | \
  338. BTRFS_BALANCE_ARGS_VRANGE | \
  339. BTRFS_BALANCE_ARGS_LIMIT | \
  340. BTRFS_BALANCE_ARGS_LIMIT_RANGE | \
  341. BTRFS_BALANCE_ARGS_STRIPES_RANGE | \
  342. BTRFS_BALANCE_ARGS_USAGE_RANGE)
  343. /*
  344. * Profile changing flags. When SOFT is set we won't relocate chunk if
  345. * it already has the target profile (even though it may be
  346. * half-filled).
  347. */
  348. #define BTRFS_BALANCE_ARGS_CONVERT (1ULL << 8)
  349. #define BTRFS_BALANCE_ARGS_SOFT (1ULL << 9)
  350. /*
  351. * flags definition for balance state
  352. *
  353. * Used by:
  354. * struct btrfs_ioctl_balance_args.state
  355. */
  356. #define BTRFS_BALANCE_STATE_RUNNING (1ULL << 0)
  357. #define BTRFS_BALANCE_STATE_PAUSE_REQ (1ULL << 1)
  358. #define BTRFS_BALANCE_STATE_CANCEL_REQ (1ULL << 2)
  359. struct btrfs_ioctl_balance_args {
  360. __u64 flags; /* in/out */
  361. __u64 state; /* out */
  362. struct btrfs_balance_args data; /* in/out */
  363. struct btrfs_balance_args meta; /* in/out */
  364. struct btrfs_balance_args sys; /* in/out */
  365. struct btrfs_balance_progress stat; /* out */
  366. __u64 unused[72]; /* pad to 1k */
  367. };
  368. #define BTRFS_INO_LOOKUP_PATH_MAX 4080
  369. struct btrfs_ioctl_ino_lookup_args {
  370. __u64 treeid;
  371. __u64 objectid;
  372. char name[BTRFS_INO_LOOKUP_PATH_MAX];
  373. };
  374. /* Search criteria for the btrfs SEARCH ioctl family. */
  375. struct btrfs_ioctl_search_key {
  376. /*
  377. * The tree we're searching in. 1 is the tree of tree roots, 2 is the
  378. * extent tree, etc...
  379. *
  380. * A special tree_id value of 0 will cause a search in the subvolume
  381. * tree that the inode which is passed to the ioctl is part of.
  382. */
  383. __u64 tree_id; /* in */
  384. /*
  385. * When doing a tree search, we're actually taking a slice from a
  386. * linear search space of 136-bit keys.
  387. *
  388. * A full 136-bit tree key is composed as:
  389. * (objectid << 72) + (type << 64) + offset
  390. *
  391. * The individual min and max values for objectid, type and offset
  392. * define the min_key and max_key values for the search range. All
  393. * metadata items with a key in the interval [min_key, max_key] will be
  394. * returned.
  395. *
  396. * Additionally, we can filter the items returned on transaction id of
  397. * the metadata block they're stored in by specifying a transid range.
  398. * Be aware that this transaction id only denotes when the metadata
  399. * page that currently contains the item got written the last time as
  400. * result of a COW operation. The number does not have any meaning
  401. * related to the transaction in which an individual item that is being
  402. * returned was created or changed.
  403. */
  404. __u64 min_objectid; /* in */
  405. __u64 max_objectid; /* in */
  406. __u64 min_offset; /* in */
  407. __u64 max_offset; /* in */
  408. __u64 min_transid; /* in */
  409. __u64 max_transid; /* in */
  410. __u32 min_type; /* in */
  411. __u32 max_type; /* in */
  412. /*
  413. * input: The maximum amount of results desired.
  414. * output: The actual amount of items returned, restricted by any of:
  415. * - reaching the upper bound of the search range
  416. * - reaching the input nr_items amount of items
  417. * - completely filling the supplied memory buffer
  418. */
  419. __u32 nr_items; /* in/out */
  420. /* align to 64 bits */
  421. __u32 unused;
  422. /* some extra for later */
  423. __u64 unused1;
  424. __u64 unused2;
  425. __u64 unused3;
  426. __u64 unused4;
  427. };
  428. struct btrfs_ioctl_search_header {
  429. __u64 transid;
  430. __u64 objectid;
  431. __u64 offset;
  432. __u32 type;
  433. __u32 len;
  434. };
  435. #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
  436. /*
  437. * the buf is an array of search headers where
  438. * each header is followed by the actual item
  439. * the type field is expanded to 32 bits for alignment
  440. */
  441. struct btrfs_ioctl_search_args {
  442. struct btrfs_ioctl_search_key key;
  443. char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
  444. };
  445. struct btrfs_ioctl_search_args_v2 {
  446. struct btrfs_ioctl_search_key key; /* in/out - search parameters */
  447. __u64 buf_size; /* in - size of buffer
  448. * out - on EOVERFLOW: needed size
  449. * to store item */
  450. __u64 buf[0]; /* out - found items */
  451. };
  452. struct btrfs_ioctl_clone_range_args {
  453. __s64 src_fd;
  454. __u64 src_offset, src_length;
  455. __u64 dest_offset;
  456. };
  457. /*
  458. * flags definition for the defrag range ioctl
  459. *
  460. * Used by:
  461. * struct btrfs_ioctl_defrag_range_args.flags
  462. */
  463. #define BTRFS_DEFRAG_RANGE_COMPRESS 1
  464. #define BTRFS_DEFRAG_RANGE_START_IO 2
  465. struct btrfs_ioctl_defrag_range_args {
  466. /* start of the defrag operation */
  467. __u64 start;
  468. /* number of bytes to defrag, use (u64)-1 to say all */
  469. __u64 len;
  470. /*
  471. * flags for the operation, which can include turning
  472. * on compression for this one defrag
  473. */
  474. __u64 flags;
  475. /*
  476. * any extent bigger than this will be considered
  477. * already defragged. Use 0 to take the kernel default
  478. * Use 1 to say every single extent must be rewritten
  479. */
  480. __u32 extent_thresh;
  481. /*
  482. * which compression method to use if turning on compression
  483. * for this defrag operation. If unspecified, zlib will
  484. * be used
  485. */
  486. __u32 compress_type;
  487. /* spare for later */
  488. __u32 unused[4];
  489. };
  490. #define BTRFS_SAME_DATA_DIFFERS 1
  491. /* For extent-same ioctl */
  492. struct btrfs_ioctl_same_extent_info {
  493. __s64 fd; /* in - destination file */
  494. __u64 logical_offset; /* in - start of extent in destination */
  495. __u64 bytes_deduped; /* out - total # of bytes we were able
  496. * to dedupe from this file */
  497. /* status of this dedupe operation:
  498. * 0 if dedup succeeds
  499. * < 0 for error
  500. * == BTRFS_SAME_DATA_DIFFERS if data differs
  501. */
  502. __s32 status; /* out - see above description */
  503. __u32 reserved;
  504. };
  505. struct btrfs_ioctl_same_args {
  506. __u64 logical_offset; /* in - start of extent in source */
  507. __u64 length; /* in - length of extent */
  508. __u16 dest_count; /* in - total elements in info array */
  509. __u16 reserved1;
  510. __u32 reserved2;
  511. struct btrfs_ioctl_same_extent_info info[0];
  512. };
  513. struct btrfs_ioctl_space_info {
  514. __u64 flags;
  515. __u64 total_bytes;
  516. __u64 used_bytes;
  517. };
  518. struct btrfs_ioctl_space_args {
  519. __u64 space_slots;
  520. __u64 total_spaces;
  521. struct btrfs_ioctl_space_info spaces[0];
  522. };
  523. struct btrfs_data_container {
  524. __u32 bytes_left; /* out -- bytes not needed to deliver output */
  525. __u32 bytes_missing; /* out -- additional bytes needed for result */
  526. __u32 elem_cnt; /* out */
  527. __u32 elem_missed; /* out */
  528. __u64 val[0]; /* out */
  529. };
  530. struct btrfs_ioctl_ino_path_args {
  531. __u64 inum; /* in */
  532. __u64 size; /* in */
  533. __u64 reserved[4];
  534. /* struct btrfs_data_container *fspath; out */
  535. __u64 fspath; /* out */
  536. };
  537. struct btrfs_ioctl_logical_ino_args {
  538. __u64 logical; /* in */
  539. __u64 size; /* in */
  540. __u64 reserved[3]; /* must be 0 for now */
  541. __u64 flags; /* in, v2 only */
  542. /* struct btrfs_data_container *inodes; out */
  543. __u64 inodes;
  544. };
  545. /* Return every ref to the extent, not just those containing logical block.
  546. * Requires logical == extent bytenr. */
  547. #define BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET (1ULL << 0)
  548. enum btrfs_dev_stat_values {
  549. /* disk I/O failure stats */
  550. BTRFS_DEV_STAT_WRITE_ERRS, /* EIO or EREMOTEIO from lower layers */
  551. BTRFS_DEV_STAT_READ_ERRS, /* EIO or EREMOTEIO from lower layers */
  552. BTRFS_DEV_STAT_FLUSH_ERRS, /* EIO or EREMOTEIO from lower layers */
  553. /* stats for indirect indications for I/O failures */
  554. BTRFS_DEV_STAT_CORRUPTION_ERRS, /* checksum error, bytenr error or
  555. * contents is illegal: this is an
  556. * indication that the block was damaged
  557. * during read or write, or written to
  558. * wrong location or read from wrong
  559. * location */
  560. BTRFS_DEV_STAT_GENERATION_ERRS, /* an indication that blocks have not
  561. * been written */
  562. BTRFS_DEV_STAT_VALUES_MAX
  563. };
  564. /* Reset statistics after reading; needs SYS_ADMIN capability */
  565. #define BTRFS_DEV_STATS_RESET (1ULL << 0)
  566. struct btrfs_ioctl_get_dev_stats {
  567. __u64 devid; /* in */
  568. __u64 nr_items; /* in/out */
  569. __u64 flags; /* in/out */
  570. /* out values: */
  571. __u64 values[BTRFS_DEV_STAT_VALUES_MAX];
  572. __u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
  573. };
  574. #define BTRFS_QUOTA_CTL_ENABLE 1
  575. #define BTRFS_QUOTA_CTL_DISABLE 2
  576. #define BTRFS_QUOTA_CTL_RESCAN__NOTUSED 3
  577. struct btrfs_ioctl_quota_ctl_args {
  578. __u64 cmd;
  579. __u64 status;
  580. };
  581. struct btrfs_ioctl_quota_rescan_args {
  582. __u64 flags;
  583. __u64 progress;
  584. __u64 reserved[6];
  585. };
  586. struct btrfs_ioctl_qgroup_assign_args {
  587. __u64 assign;
  588. __u64 src;
  589. __u64 dst;
  590. };
  591. struct btrfs_ioctl_qgroup_create_args {
  592. __u64 create;
  593. __u64 qgroupid;
  594. };
  595. struct btrfs_ioctl_timespec {
  596. __u64 sec;
  597. __u32 nsec;
  598. };
  599. struct btrfs_ioctl_received_subvol_args {
  600. char uuid[BTRFS_UUID_SIZE]; /* in */
  601. __u64 stransid; /* in */
  602. __u64 rtransid; /* out */
  603. struct btrfs_ioctl_timespec stime; /* in */
  604. struct btrfs_ioctl_timespec rtime; /* out */
  605. __u64 flags; /* in */
  606. __u64 reserved[16]; /* in */
  607. };
  608. /*
  609. * Caller doesn't want file data in the send stream, even if the
  610. * search of clone sources doesn't find an extent. UPDATE_EXTENT
  611. * commands will be sent instead of WRITE commands.
  612. */
  613. #define BTRFS_SEND_FLAG_NO_FILE_DATA 0x1
  614. /*
  615. * Do not add the leading stream header. Used when multiple snapshots
  616. * are sent back to back.
  617. */
  618. #define BTRFS_SEND_FLAG_OMIT_STREAM_HEADER 0x2
  619. /*
  620. * Omit the command at the end of the stream that indicated the end
  621. * of the stream. This option is used when multiple snapshots are
  622. * sent back to back.
  623. */
  624. #define BTRFS_SEND_FLAG_OMIT_END_CMD 0x4
  625. #define BTRFS_SEND_FLAG_MASK \
  626. (BTRFS_SEND_FLAG_NO_FILE_DATA | \
  627. BTRFS_SEND_FLAG_OMIT_STREAM_HEADER | \
  628. BTRFS_SEND_FLAG_OMIT_END_CMD)
  629. struct btrfs_ioctl_send_args {
  630. __s64 send_fd; /* in */
  631. __u64 clone_sources_count; /* in */
  632. __u64 __user *clone_sources; /* in */
  633. __u64 parent_root; /* in */
  634. __u64 flags; /* in */
  635. __u64 reserved[4]; /* in */
  636. };
  637. /* Error codes as returned by the kernel */
  638. enum btrfs_err_code {
  639. BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1,
  640. BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
  641. BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
  642. BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
  643. BTRFS_ERROR_DEV_TGT_REPLACE,
  644. BTRFS_ERROR_DEV_MISSING_NOT_FOUND,
  645. BTRFS_ERROR_DEV_ONLY_WRITABLE,
  646. BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS
  647. };
  648. #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
  649. struct btrfs_ioctl_vol_args)
  650. #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
  651. struct btrfs_ioctl_vol_args)
  652. #define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \
  653. struct btrfs_ioctl_vol_args)
  654. #define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \
  655. struct btrfs_ioctl_vol_args)
  656. /* trans start and trans end are dangerous, and only for
  657. * use by applications that know how to avoid the
  658. * resulting deadlocks
  659. */
  660. #define BTRFS_IOC_TRANS_START _IO(BTRFS_IOCTL_MAGIC, 6)
  661. #define BTRFS_IOC_TRANS_END _IO(BTRFS_IOCTL_MAGIC, 7)
  662. #define BTRFS_IOC_SYNC _IO(BTRFS_IOCTL_MAGIC, 8)
  663. #define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)
  664. #define BTRFS_IOC_ADD_DEV _IOW(BTRFS_IOCTL_MAGIC, 10, \
  665. struct btrfs_ioctl_vol_args)
  666. #define BTRFS_IOC_RM_DEV _IOW(BTRFS_IOCTL_MAGIC, 11, \
  667. struct btrfs_ioctl_vol_args)
  668. #define BTRFS_IOC_BALANCE _IOW(BTRFS_IOCTL_MAGIC, 12, \
  669. struct btrfs_ioctl_vol_args)
  670. #define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \
  671. struct btrfs_ioctl_clone_range_args)
  672. #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
  673. struct btrfs_ioctl_vol_args)
  674. #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
  675. struct btrfs_ioctl_vol_args)
  676. #define BTRFS_IOC_DEFRAG_RANGE _IOW(BTRFS_IOCTL_MAGIC, 16, \
  677. struct btrfs_ioctl_defrag_range_args)
  678. #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
  679. struct btrfs_ioctl_search_args)
  680. #define BTRFS_IOC_TREE_SEARCH_V2 _IOWR(BTRFS_IOCTL_MAGIC, 17, \
  681. struct btrfs_ioctl_search_args_v2)
  682. #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
  683. struct btrfs_ioctl_ino_lookup_args)
  684. #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, __u64)
  685. #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
  686. struct btrfs_ioctl_space_args)
  687. #define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64)
  688. #define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)
  689. #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
  690. struct btrfs_ioctl_vol_args_v2)
  691. #define BTRFS_IOC_SUBVOL_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 24, \
  692. struct btrfs_ioctl_vol_args_v2)
  693. #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)
  694. #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
  695. #define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \
  696. struct btrfs_ioctl_scrub_args)
  697. #define BTRFS_IOC_SCRUB_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28)
  698. #define BTRFS_IOC_SCRUB_PROGRESS _IOWR(BTRFS_IOCTL_MAGIC, 29, \
  699. struct btrfs_ioctl_scrub_args)
  700. #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
  701. struct btrfs_ioctl_dev_info_args)
  702. #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
  703. struct btrfs_ioctl_fs_info_args)
  704. #define BTRFS_IOC_BALANCE_V2 _IOWR(BTRFS_IOCTL_MAGIC, 32, \
  705. struct btrfs_ioctl_balance_args)
  706. #define BTRFS_IOC_BALANCE_CTL _IOW(BTRFS_IOCTL_MAGIC, 33, int)
  707. #define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 34, \
  708. struct btrfs_ioctl_balance_args)
  709. #define BTRFS_IOC_INO_PATHS _IOWR(BTRFS_IOCTL_MAGIC, 35, \
  710. struct btrfs_ioctl_ino_path_args)
  711. #define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \
  712. struct btrfs_ioctl_logical_ino_args)
  713. #define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \
  714. struct btrfs_ioctl_received_subvol_args)
  715. #define BTRFS_IOC_SEND _IOW(BTRFS_IOCTL_MAGIC, 38, struct btrfs_ioctl_send_args)
  716. #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
  717. struct btrfs_ioctl_vol_args)
  718. #define BTRFS_IOC_QUOTA_CTL _IOWR(BTRFS_IOCTL_MAGIC, 40, \
  719. struct btrfs_ioctl_quota_ctl_args)
  720. #define BTRFS_IOC_QGROUP_ASSIGN _IOW(BTRFS_IOCTL_MAGIC, 41, \
  721. struct btrfs_ioctl_qgroup_assign_args)
  722. #define BTRFS_IOC_QGROUP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 42, \
  723. struct btrfs_ioctl_qgroup_create_args)
  724. #define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43, \
  725. struct btrfs_ioctl_qgroup_limit_args)
  726. #define BTRFS_IOC_QUOTA_RESCAN _IOW(BTRFS_IOCTL_MAGIC, 44, \
  727. struct btrfs_ioctl_quota_rescan_args)
  728. #define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45, \
  729. struct btrfs_ioctl_quota_rescan_args)
  730. #define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
  731. #define BTRFS_IOC_GET_FSLABEL _IOR(BTRFS_IOCTL_MAGIC, 49, \
  732. char[BTRFS_LABEL_SIZE])
  733. #define BTRFS_IOC_SET_FSLABEL _IOW(BTRFS_IOCTL_MAGIC, 50, \
  734. char[BTRFS_LABEL_SIZE])
  735. #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
  736. struct btrfs_ioctl_get_dev_stats)
  737. #define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53, \
  738. struct btrfs_ioctl_dev_replace_args)
  739. #define BTRFS_IOC_FILE_EXTENT_SAME _IOWR(BTRFS_IOCTL_MAGIC, 54, \
  740. struct btrfs_ioctl_same_args)
  741. #define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
  742. struct btrfs_ioctl_feature_flags)
  743. #define BTRFS_IOC_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 57, \
  744. struct btrfs_ioctl_feature_flags[2])
  745. #define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
  746. struct btrfs_ioctl_feature_flags[3])
  747. #define BTRFS_IOC_RM_DEV_V2 _IOW(BTRFS_IOCTL_MAGIC, 58, \
  748. struct btrfs_ioctl_vol_args_v2)
  749. #define BTRFS_IOC_LOGICAL_INO_V2 _IOWR(BTRFS_IOCTL_MAGIC, 59, \
  750. struct btrfs_ioctl_logical_ino_args)
  751. #endif /* _UAPI_LINUX_BTRFS_H */