btrfs.h 25 KB

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