btrfs.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  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_SUBVOL_NAME_MAX 4039
  34. #define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
  35. #define BTRFS_SUBVOL_RDONLY (1ULL << 1)
  36. #define BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2)
  37. #define BTRFS_DEVICE_SPEC_BY_ID (1ULL << 3)
  38. #define BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED \
  39. (BTRFS_SUBVOL_CREATE_ASYNC | \
  40. BTRFS_SUBVOL_RDONLY | \
  41. BTRFS_SUBVOL_QGROUP_INHERIT | \
  42. BTRFS_DEVICE_SPEC_BY_ID)
  43. #define BTRFS_FSID_SIZE 16
  44. #define BTRFS_UUID_SIZE 16
  45. #define BTRFS_UUID_UNPARSED_SIZE 37
  46. /*
  47. * flags definition for qgroup limits
  48. *
  49. * Used by:
  50. * struct btrfs_qgroup_limit.flags
  51. * struct btrfs_qgroup_limit_item.flags
  52. */
  53. #define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0)
  54. #define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1)
  55. #define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2)
  56. #define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3)
  57. #define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4)
  58. #define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5)
  59. struct btrfs_qgroup_limit {
  60. __u64 flags;
  61. __u64 max_rfer;
  62. __u64 max_excl;
  63. __u64 rsv_rfer;
  64. __u64 rsv_excl;
  65. };
  66. /*
  67. * flags definition for qgroup inheritance
  68. *
  69. * Used by:
  70. * struct btrfs_qgroup_inherit.flags
  71. */
  72. #define BTRFS_QGROUP_INHERIT_SET_LIMITS (1ULL << 0)
  73. struct btrfs_qgroup_inherit {
  74. __u64 flags;
  75. __u64 num_qgroups;
  76. __u64 num_ref_copies;
  77. __u64 num_excl_copies;
  78. struct btrfs_qgroup_limit lim;
  79. __u64 qgroups[0];
  80. };
  81. struct btrfs_ioctl_qgroup_limit_args {
  82. __u64 qgroupid;
  83. struct btrfs_qgroup_limit lim;
  84. };
  85. /*
  86. * flags for subvolumes
  87. *
  88. * Used by:
  89. * struct btrfs_ioctl_vol_args_v2.flags
  90. *
  91. * BTRFS_SUBVOL_RDONLY is also provided/consumed by the following ioctls:
  92. * - BTRFS_IOC_SUBVOL_GETFLAGS
  93. * - BTRFS_IOC_SUBVOL_SETFLAGS
  94. */
  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. #define BTRFS_INO_LOOKUP_USER_PATH_MAX (4080 - BTRFS_VOL_NAME_MAX - 1)
  375. struct btrfs_ioctl_ino_lookup_user_args {
  376. /* in, inode number containing the subvolume of 'subvolid' */
  377. __u64 dirid;
  378. /* in */
  379. __u64 treeid;
  380. /* out, name of the subvolume of 'treeid' */
  381. char name[BTRFS_VOL_NAME_MAX + 1];
  382. /*
  383. * out, constructed path from the directory with which the ioctl is
  384. * called to dirid
  385. */
  386. char path[BTRFS_INO_LOOKUP_USER_PATH_MAX];
  387. };
  388. /* Search criteria for the btrfs SEARCH ioctl family. */
  389. struct btrfs_ioctl_search_key {
  390. /*
  391. * The tree we're searching in. 1 is the tree of tree roots, 2 is the
  392. * extent tree, etc...
  393. *
  394. * A special tree_id value of 0 will cause a search in the subvolume
  395. * tree that the inode which is passed to the ioctl is part of.
  396. */
  397. __u64 tree_id; /* in */
  398. /*
  399. * When doing a tree search, we're actually taking a slice from a
  400. * linear search space of 136-bit keys.
  401. *
  402. * A full 136-bit tree key is composed as:
  403. * (objectid << 72) + (type << 64) + offset
  404. *
  405. * The individual min and max values for objectid, type and offset
  406. * define the min_key and max_key values for the search range. All
  407. * metadata items with a key in the interval [min_key, max_key] will be
  408. * returned.
  409. *
  410. * Additionally, we can filter the items returned on transaction id of
  411. * the metadata block they're stored in by specifying a transid range.
  412. * Be aware that this transaction id only denotes when the metadata
  413. * page that currently contains the item got written the last time as
  414. * result of a COW operation. The number does not have any meaning
  415. * related to the transaction in which an individual item that is being
  416. * returned was created or changed.
  417. */
  418. __u64 min_objectid; /* in */
  419. __u64 max_objectid; /* in */
  420. __u64 min_offset; /* in */
  421. __u64 max_offset; /* in */
  422. __u64 min_transid; /* in */
  423. __u64 max_transid; /* in */
  424. __u32 min_type; /* in */
  425. __u32 max_type; /* in */
  426. /*
  427. * input: The maximum amount of results desired.
  428. * output: The actual amount of items returned, restricted by any of:
  429. * - reaching the upper bound of the search range
  430. * - reaching the input nr_items amount of items
  431. * - completely filling the supplied memory buffer
  432. */
  433. __u32 nr_items; /* in/out */
  434. /* align to 64 bits */
  435. __u32 unused;
  436. /* some extra for later */
  437. __u64 unused1;
  438. __u64 unused2;
  439. __u64 unused3;
  440. __u64 unused4;
  441. };
  442. struct btrfs_ioctl_search_header {
  443. __u64 transid;
  444. __u64 objectid;
  445. __u64 offset;
  446. __u32 type;
  447. __u32 len;
  448. };
  449. #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
  450. /*
  451. * the buf is an array of search headers where
  452. * each header is followed by the actual item
  453. * the type field is expanded to 32 bits for alignment
  454. */
  455. struct btrfs_ioctl_search_args {
  456. struct btrfs_ioctl_search_key key;
  457. char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
  458. };
  459. struct btrfs_ioctl_search_args_v2 {
  460. struct btrfs_ioctl_search_key key; /* in/out - search parameters */
  461. __u64 buf_size; /* in - size of buffer
  462. * out - on EOVERFLOW: needed size
  463. * to store item */
  464. __u64 buf[0]; /* out - found items */
  465. };
  466. struct btrfs_ioctl_clone_range_args {
  467. __s64 src_fd;
  468. __u64 src_offset, src_length;
  469. __u64 dest_offset;
  470. };
  471. /*
  472. * flags definition for the defrag range ioctl
  473. *
  474. * Used by:
  475. * struct btrfs_ioctl_defrag_range_args.flags
  476. */
  477. #define BTRFS_DEFRAG_RANGE_COMPRESS 1
  478. #define BTRFS_DEFRAG_RANGE_START_IO 2
  479. struct btrfs_ioctl_defrag_range_args {
  480. /* start of the defrag operation */
  481. __u64 start;
  482. /* number of bytes to defrag, use (u64)-1 to say all */
  483. __u64 len;
  484. /*
  485. * flags for the operation, which can include turning
  486. * on compression for this one defrag
  487. */
  488. __u64 flags;
  489. /*
  490. * any extent bigger than this will be considered
  491. * already defragged. Use 0 to take the kernel default
  492. * Use 1 to say every single extent must be rewritten
  493. */
  494. __u32 extent_thresh;
  495. /*
  496. * which compression method to use if turning on compression
  497. * for this defrag operation. If unspecified, zlib will
  498. * be used
  499. */
  500. __u32 compress_type;
  501. /* spare for later */
  502. __u32 unused[4];
  503. };
  504. #define BTRFS_SAME_DATA_DIFFERS 1
  505. /* For extent-same ioctl */
  506. struct btrfs_ioctl_same_extent_info {
  507. __s64 fd; /* in - destination file */
  508. __u64 logical_offset; /* in - start of extent in destination */
  509. __u64 bytes_deduped; /* out - total # of bytes we were able
  510. * to dedupe from this file */
  511. /* status of this dedupe operation:
  512. * 0 if dedup succeeds
  513. * < 0 for error
  514. * == BTRFS_SAME_DATA_DIFFERS if data differs
  515. */
  516. __s32 status; /* out - see above description */
  517. __u32 reserved;
  518. };
  519. struct btrfs_ioctl_same_args {
  520. __u64 logical_offset; /* in - start of extent in source */
  521. __u64 length; /* in - length of extent */
  522. __u16 dest_count; /* in - total elements in info array */
  523. __u16 reserved1;
  524. __u32 reserved2;
  525. struct btrfs_ioctl_same_extent_info info[0];
  526. };
  527. struct btrfs_ioctl_space_info {
  528. __u64 flags;
  529. __u64 total_bytes;
  530. __u64 used_bytes;
  531. };
  532. struct btrfs_ioctl_space_args {
  533. __u64 space_slots;
  534. __u64 total_spaces;
  535. struct btrfs_ioctl_space_info spaces[0];
  536. };
  537. struct btrfs_data_container {
  538. __u32 bytes_left; /* out -- bytes not needed to deliver output */
  539. __u32 bytes_missing; /* out -- additional bytes needed for result */
  540. __u32 elem_cnt; /* out */
  541. __u32 elem_missed; /* out */
  542. __u64 val[0]; /* out */
  543. };
  544. struct btrfs_ioctl_ino_path_args {
  545. __u64 inum; /* in */
  546. __u64 size; /* in */
  547. __u64 reserved[4];
  548. /* struct btrfs_data_container *fspath; out */
  549. __u64 fspath; /* out */
  550. };
  551. struct btrfs_ioctl_logical_ino_args {
  552. __u64 logical; /* in */
  553. __u64 size; /* in */
  554. __u64 reserved[3]; /* must be 0 for now */
  555. __u64 flags; /* in, v2 only */
  556. /* struct btrfs_data_container *inodes; out */
  557. __u64 inodes;
  558. };
  559. /* Return every ref to the extent, not just those containing logical block.
  560. * Requires logical == extent bytenr. */
  561. #define BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET (1ULL << 0)
  562. enum btrfs_dev_stat_values {
  563. /* disk I/O failure stats */
  564. BTRFS_DEV_STAT_WRITE_ERRS, /* EIO or EREMOTEIO from lower layers */
  565. BTRFS_DEV_STAT_READ_ERRS, /* EIO or EREMOTEIO from lower layers */
  566. BTRFS_DEV_STAT_FLUSH_ERRS, /* EIO or EREMOTEIO from lower layers */
  567. /* stats for indirect indications for I/O failures */
  568. BTRFS_DEV_STAT_CORRUPTION_ERRS, /* checksum error, bytenr error or
  569. * contents is illegal: this is an
  570. * indication that the block was damaged
  571. * during read or write, or written to
  572. * wrong location or read from wrong
  573. * location */
  574. BTRFS_DEV_STAT_GENERATION_ERRS, /* an indication that blocks have not
  575. * been written */
  576. BTRFS_DEV_STAT_VALUES_MAX
  577. };
  578. /* Reset statistics after reading; needs SYS_ADMIN capability */
  579. #define BTRFS_DEV_STATS_RESET (1ULL << 0)
  580. struct btrfs_ioctl_get_dev_stats {
  581. __u64 devid; /* in */
  582. __u64 nr_items; /* in/out */
  583. __u64 flags; /* in/out */
  584. /* out values: */
  585. __u64 values[BTRFS_DEV_STAT_VALUES_MAX];
  586. __u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
  587. };
  588. #define BTRFS_QUOTA_CTL_ENABLE 1
  589. #define BTRFS_QUOTA_CTL_DISABLE 2
  590. #define BTRFS_QUOTA_CTL_RESCAN__NOTUSED 3
  591. struct btrfs_ioctl_quota_ctl_args {
  592. __u64 cmd;
  593. __u64 status;
  594. };
  595. struct btrfs_ioctl_quota_rescan_args {
  596. __u64 flags;
  597. __u64 progress;
  598. __u64 reserved[6];
  599. };
  600. struct btrfs_ioctl_qgroup_assign_args {
  601. __u64 assign;
  602. __u64 src;
  603. __u64 dst;
  604. };
  605. struct btrfs_ioctl_qgroup_create_args {
  606. __u64 create;
  607. __u64 qgroupid;
  608. };
  609. struct btrfs_ioctl_timespec {
  610. __u64 sec;
  611. __u32 nsec;
  612. };
  613. struct btrfs_ioctl_received_subvol_args {
  614. char uuid[BTRFS_UUID_SIZE]; /* in */
  615. __u64 stransid; /* in */
  616. __u64 rtransid; /* out */
  617. struct btrfs_ioctl_timespec stime; /* in */
  618. struct btrfs_ioctl_timespec rtime; /* out */
  619. __u64 flags; /* in */
  620. __u64 reserved[16]; /* in */
  621. };
  622. /*
  623. * Caller doesn't want file data in the send stream, even if the
  624. * search of clone sources doesn't find an extent. UPDATE_EXTENT
  625. * commands will be sent instead of WRITE commands.
  626. */
  627. #define BTRFS_SEND_FLAG_NO_FILE_DATA 0x1
  628. /*
  629. * Do not add the leading stream header. Used when multiple snapshots
  630. * are sent back to back.
  631. */
  632. #define BTRFS_SEND_FLAG_OMIT_STREAM_HEADER 0x2
  633. /*
  634. * Omit the command at the end of the stream that indicated the end
  635. * of the stream. This option is used when multiple snapshots are
  636. * sent back to back.
  637. */
  638. #define BTRFS_SEND_FLAG_OMIT_END_CMD 0x4
  639. #define BTRFS_SEND_FLAG_MASK \
  640. (BTRFS_SEND_FLAG_NO_FILE_DATA | \
  641. BTRFS_SEND_FLAG_OMIT_STREAM_HEADER | \
  642. BTRFS_SEND_FLAG_OMIT_END_CMD)
  643. struct btrfs_ioctl_send_args {
  644. __s64 send_fd; /* in */
  645. __u64 clone_sources_count; /* in */
  646. __u64 __user *clone_sources; /* in */
  647. __u64 parent_root; /* in */
  648. __u64 flags; /* in */
  649. __u64 reserved[4]; /* in */
  650. };
  651. /*
  652. * Information about a fs tree root.
  653. *
  654. * All items are filled by the ioctl
  655. */
  656. struct btrfs_ioctl_get_subvol_info_args {
  657. /* Id of this subvolume */
  658. __u64 treeid;
  659. /* Name of this subvolume, used to get the real name at mount point */
  660. char name[BTRFS_VOL_NAME_MAX + 1];
  661. /*
  662. * Id of the subvolume which contains this subvolume.
  663. * Zero for top-level subvolume or a deleted subvolume.
  664. */
  665. __u64 parent_id;
  666. /*
  667. * Inode number of the directory which contains this subvolume.
  668. * Zero for top-level subvolume or a deleted subvolume
  669. */
  670. __u64 dirid;
  671. /* Latest transaction id of this subvolume */
  672. __u64 generation;
  673. /* Flags of this subvolume */
  674. __u64 flags;
  675. /* UUID of this subvolume */
  676. __u8 uuid[BTRFS_UUID_SIZE];
  677. /*
  678. * UUID of the subvolume of which this subvolume is a snapshot.
  679. * All zero for a non-snapshot subvolume.
  680. */
  681. __u8 parent_uuid[BTRFS_UUID_SIZE];
  682. /*
  683. * UUID of the subvolume from which this subvolume was received.
  684. * All zero for non-received subvolume.
  685. */
  686. __u8 received_uuid[BTRFS_UUID_SIZE];
  687. /* Transaction id indicating when change/create/send/receive happened */
  688. __u64 ctransid;
  689. __u64 otransid;
  690. __u64 stransid;
  691. __u64 rtransid;
  692. /* Time corresponding to c/o/s/rtransid */
  693. struct btrfs_ioctl_timespec ctime;
  694. struct btrfs_ioctl_timespec otime;
  695. struct btrfs_ioctl_timespec stime;
  696. struct btrfs_ioctl_timespec rtime;
  697. /* Must be zero */
  698. __u64 reserved[8];
  699. };
  700. #define BTRFS_MAX_ROOTREF_BUFFER_NUM 255
  701. struct btrfs_ioctl_get_subvol_rootref_args {
  702. /* in/out, minimum id of rootref's treeid to be searched */
  703. __u64 min_treeid;
  704. /* out */
  705. struct {
  706. __u64 treeid;
  707. __u64 dirid;
  708. } rootref[BTRFS_MAX_ROOTREF_BUFFER_NUM];
  709. /* out, number of found items */
  710. __u8 num_items;
  711. __u8 align[7];
  712. };
  713. /* Error codes as returned by the kernel */
  714. enum btrfs_err_code {
  715. BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1,
  716. BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
  717. BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
  718. BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
  719. BTRFS_ERROR_DEV_TGT_REPLACE,
  720. BTRFS_ERROR_DEV_MISSING_NOT_FOUND,
  721. BTRFS_ERROR_DEV_ONLY_WRITABLE,
  722. BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS
  723. };
  724. #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
  725. struct btrfs_ioctl_vol_args)
  726. #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
  727. struct btrfs_ioctl_vol_args)
  728. #define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \
  729. struct btrfs_ioctl_vol_args)
  730. #define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \
  731. struct btrfs_ioctl_vol_args)
  732. /* trans start and trans end are dangerous, and only for
  733. * use by applications that know how to avoid the
  734. * resulting deadlocks
  735. */
  736. #define BTRFS_IOC_TRANS_START _IO(BTRFS_IOCTL_MAGIC, 6)
  737. #define BTRFS_IOC_TRANS_END _IO(BTRFS_IOCTL_MAGIC, 7)
  738. #define BTRFS_IOC_SYNC _IO(BTRFS_IOCTL_MAGIC, 8)
  739. #define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)
  740. #define BTRFS_IOC_ADD_DEV _IOW(BTRFS_IOCTL_MAGIC, 10, \
  741. struct btrfs_ioctl_vol_args)
  742. #define BTRFS_IOC_RM_DEV _IOW(BTRFS_IOCTL_MAGIC, 11, \
  743. struct btrfs_ioctl_vol_args)
  744. #define BTRFS_IOC_BALANCE _IOW(BTRFS_IOCTL_MAGIC, 12, \
  745. struct btrfs_ioctl_vol_args)
  746. #define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \
  747. struct btrfs_ioctl_clone_range_args)
  748. #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
  749. struct btrfs_ioctl_vol_args)
  750. #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
  751. struct btrfs_ioctl_vol_args)
  752. #define BTRFS_IOC_DEFRAG_RANGE _IOW(BTRFS_IOCTL_MAGIC, 16, \
  753. struct btrfs_ioctl_defrag_range_args)
  754. #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
  755. struct btrfs_ioctl_search_args)
  756. #define BTRFS_IOC_TREE_SEARCH_V2 _IOWR(BTRFS_IOCTL_MAGIC, 17, \
  757. struct btrfs_ioctl_search_args_v2)
  758. #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
  759. struct btrfs_ioctl_ino_lookup_args)
  760. #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, __u64)
  761. #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
  762. struct btrfs_ioctl_space_args)
  763. #define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64)
  764. #define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)
  765. #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
  766. struct btrfs_ioctl_vol_args_v2)
  767. #define BTRFS_IOC_SUBVOL_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 24, \
  768. struct btrfs_ioctl_vol_args_v2)
  769. #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)
  770. #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
  771. #define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \
  772. struct btrfs_ioctl_scrub_args)
  773. #define BTRFS_IOC_SCRUB_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28)
  774. #define BTRFS_IOC_SCRUB_PROGRESS _IOWR(BTRFS_IOCTL_MAGIC, 29, \
  775. struct btrfs_ioctl_scrub_args)
  776. #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
  777. struct btrfs_ioctl_dev_info_args)
  778. #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
  779. struct btrfs_ioctl_fs_info_args)
  780. #define BTRFS_IOC_BALANCE_V2 _IOWR(BTRFS_IOCTL_MAGIC, 32, \
  781. struct btrfs_ioctl_balance_args)
  782. #define BTRFS_IOC_BALANCE_CTL _IOW(BTRFS_IOCTL_MAGIC, 33, int)
  783. #define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 34, \
  784. struct btrfs_ioctl_balance_args)
  785. #define BTRFS_IOC_INO_PATHS _IOWR(BTRFS_IOCTL_MAGIC, 35, \
  786. struct btrfs_ioctl_ino_path_args)
  787. #define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \
  788. struct btrfs_ioctl_logical_ino_args)
  789. #define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \
  790. struct btrfs_ioctl_received_subvol_args)
  791. #define BTRFS_IOC_SEND _IOW(BTRFS_IOCTL_MAGIC, 38, struct btrfs_ioctl_send_args)
  792. #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
  793. struct btrfs_ioctl_vol_args)
  794. #define BTRFS_IOC_QUOTA_CTL _IOWR(BTRFS_IOCTL_MAGIC, 40, \
  795. struct btrfs_ioctl_quota_ctl_args)
  796. #define BTRFS_IOC_QGROUP_ASSIGN _IOW(BTRFS_IOCTL_MAGIC, 41, \
  797. struct btrfs_ioctl_qgroup_assign_args)
  798. #define BTRFS_IOC_QGROUP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 42, \
  799. struct btrfs_ioctl_qgroup_create_args)
  800. #define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43, \
  801. struct btrfs_ioctl_qgroup_limit_args)
  802. #define BTRFS_IOC_QUOTA_RESCAN _IOW(BTRFS_IOCTL_MAGIC, 44, \
  803. struct btrfs_ioctl_quota_rescan_args)
  804. #define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45, \
  805. struct btrfs_ioctl_quota_rescan_args)
  806. #define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
  807. #define BTRFS_IOC_GET_FSLABEL _IOR(BTRFS_IOCTL_MAGIC, 49, \
  808. char[BTRFS_LABEL_SIZE])
  809. #define BTRFS_IOC_SET_FSLABEL _IOW(BTRFS_IOCTL_MAGIC, 50, \
  810. char[BTRFS_LABEL_SIZE])
  811. #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
  812. struct btrfs_ioctl_get_dev_stats)
  813. #define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53, \
  814. struct btrfs_ioctl_dev_replace_args)
  815. #define BTRFS_IOC_FILE_EXTENT_SAME _IOWR(BTRFS_IOCTL_MAGIC, 54, \
  816. struct btrfs_ioctl_same_args)
  817. #define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
  818. struct btrfs_ioctl_feature_flags)
  819. #define BTRFS_IOC_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 57, \
  820. struct btrfs_ioctl_feature_flags[2])
  821. #define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
  822. struct btrfs_ioctl_feature_flags[3])
  823. #define BTRFS_IOC_RM_DEV_V2 _IOW(BTRFS_IOCTL_MAGIC, 58, \
  824. struct btrfs_ioctl_vol_args_v2)
  825. #define BTRFS_IOC_LOGICAL_INO_V2 _IOWR(BTRFS_IOCTL_MAGIC, 59, \
  826. struct btrfs_ioctl_logical_ino_args)
  827. #define BTRFS_IOC_GET_SUBVOL_INFO _IOR(BTRFS_IOCTL_MAGIC, 60, \
  828. struct btrfs_ioctl_get_subvol_info_args)
  829. #define BTRFS_IOC_GET_SUBVOL_ROOTREF _IOWR(BTRFS_IOCTL_MAGIC, 61, \
  830. struct btrfs_ioctl_get_subvol_rootref_args)
  831. #define BTRFS_IOC_INO_LOOKUP_USER _IOWR(BTRFS_IOCTL_MAGIC, 62, \
  832. struct btrfs_ioctl_ino_lookup_user_args)
  833. #endif /* _UAPI_LINUX_BTRFS_H */