btrfs.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  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. #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
  220. #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
  221. #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
  222. #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3)
  223. /*
  224. * some patches floated around with a second compression method
  225. * lets save that incompat here for when they do get in
  226. * Note we don't actually support it, we're just reserving the
  227. * number
  228. */
  229. #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZOv2 (1ULL << 4)
  230. /*
  231. * older kernels tried to do bigger metadata blocks, but the
  232. * code was pretty buggy. Lets not let them try anymore.
  233. */
  234. #define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5)
  235. #define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
  236. #define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
  237. #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)
  238. #define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9)
  239. struct btrfs_ioctl_feature_flags {
  240. __u64 compat_flags;
  241. __u64 compat_ro_flags;
  242. __u64 incompat_flags;
  243. };
  244. /* balance control ioctl modes */
  245. #define BTRFS_BALANCE_CTL_PAUSE 1
  246. #define BTRFS_BALANCE_CTL_CANCEL 2
  247. /*
  248. * this is packed, because it should be exactly the same as its disk
  249. * byte order counterpart (struct btrfs_disk_balance_args)
  250. */
  251. struct btrfs_balance_args {
  252. __u64 profiles;
  253. union {
  254. __le64 usage;
  255. struct {
  256. __le32 usage_min;
  257. __le32 usage_max;
  258. };
  259. };
  260. __u64 devid;
  261. __u64 pstart;
  262. __u64 pend;
  263. __u64 vstart;
  264. __u64 vend;
  265. __u64 target;
  266. __u64 flags;
  267. /*
  268. * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
  269. * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
  270. * and maximum
  271. */
  272. union {
  273. __u64 limit; /* limit number of processed chunks */
  274. struct {
  275. __u32 limit_min;
  276. __u32 limit_max;
  277. };
  278. };
  279. /*
  280. * Process chunks that cross stripes_min..stripes_max devices,
  281. * BTRFS_BALANCE_ARGS_STRIPES_RANGE
  282. */
  283. __le32 stripes_min;
  284. __le32 stripes_max;
  285. __u64 unused[6];
  286. } __attribute__ ((__packed__));
  287. /* report balance progress to userspace */
  288. struct btrfs_balance_progress {
  289. __u64 expected; /* estimated # of chunks that will be
  290. * relocated to fulfill the request */
  291. __u64 considered; /* # of chunks we have considered so far */
  292. __u64 completed; /* # of chunks relocated so far */
  293. };
  294. /*
  295. * flags definition for balance
  296. *
  297. * Restriper's general type filter
  298. *
  299. * Used by:
  300. * btrfs_ioctl_balance_args.flags
  301. * btrfs_balance_control.flags (internal)
  302. */
  303. #define BTRFS_BALANCE_DATA (1ULL << 0)
  304. #define BTRFS_BALANCE_SYSTEM (1ULL << 1)
  305. #define BTRFS_BALANCE_METADATA (1ULL << 2)
  306. #define BTRFS_BALANCE_TYPE_MASK (BTRFS_BALANCE_DATA | \
  307. BTRFS_BALANCE_SYSTEM | \
  308. BTRFS_BALANCE_METADATA)
  309. #define BTRFS_BALANCE_FORCE (1ULL << 3)
  310. #define BTRFS_BALANCE_RESUME (1ULL << 4)
  311. /*
  312. * flags definitions for per-type balance args
  313. *
  314. * Balance filters
  315. *
  316. * Used by:
  317. * struct btrfs_balance_args
  318. */
  319. #define BTRFS_BALANCE_ARGS_PROFILES (1ULL << 0)
  320. #define BTRFS_BALANCE_ARGS_USAGE (1ULL << 1)
  321. #define BTRFS_BALANCE_ARGS_DEVID (1ULL << 2)
  322. #define BTRFS_BALANCE_ARGS_DRANGE (1ULL << 3)
  323. #define BTRFS_BALANCE_ARGS_VRANGE (1ULL << 4)
  324. #define BTRFS_BALANCE_ARGS_LIMIT (1ULL << 5)
  325. #define BTRFS_BALANCE_ARGS_LIMIT_RANGE (1ULL << 6)
  326. #define BTRFS_BALANCE_ARGS_STRIPES_RANGE (1ULL << 7)
  327. #define BTRFS_BALANCE_ARGS_USAGE_RANGE (1ULL << 10)
  328. #define BTRFS_BALANCE_ARGS_MASK \
  329. (BTRFS_BALANCE_ARGS_PROFILES | \
  330. BTRFS_BALANCE_ARGS_USAGE | \
  331. BTRFS_BALANCE_ARGS_DEVID | \
  332. BTRFS_BALANCE_ARGS_DRANGE | \
  333. BTRFS_BALANCE_ARGS_VRANGE | \
  334. BTRFS_BALANCE_ARGS_LIMIT | \
  335. BTRFS_BALANCE_ARGS_LIMIT_RANGE | \
  336. BTRFS_BALANCE_ARGS_STRIPES_RANGE | \
  337. BTRFS_BALANCE_ARGS_USAGE_RANGE)
  338. /*
  339. * Profile changing flags. When SOFT is set we won't relocate chunk if
  340. * it already has the target profile (even though it may be
  341. * half-filled).
  342. */
  343. #define BTRFS_BALANCE_ARGS_CONVERT (1ULL << 8)
  344. #define BTRFS_BALANCE_ARGS_SOFT (1ULL << 9)
  345. /*
  346. * flags definition for balance state
  347. *
  348. * Used by:
  349. * struct btrfs_ioctl_balance_args.state
  350. */
  351. #define BTRFS_BALANCE_STATE_RUNNING (1ULL << 0)
  352. #define BTRFS_BALANCE_STATE_PAUSE_REQ (1ULL << 1)
  353. #define BTRFS_BALANCE_STATE_CANCEL_REQ (1ULL << 2)
  354. struct btrfs_ioctl_balance_args {
  355. __u64 flags; /* in/out */
  356. __u64 state; /* out */
  357. struct btrfs_balance_args data; /* in/out */
  358. struct btrfs_balance_args meta; /* in/out */
  359. struct btrfs_balance_args sys; /* in/out */
  360. struct btrfs_balance_progress stat; /* out */
  361. __u64 unused[72]; /* pad to 1k */
  362. };
  363. #define BTRFS_INO_LOOKUP_PATH_MAX 4080
  364. struct btrfs_ioctl_ino_lookup_args {
  365. __u64 treeid;
  366. __u64 objectid;
  367. char name[BTRFS_INO_LOOKUP_PATH_MAX];
  368. };
  369. struct btrfs_ioctl_search_key {
  370. /* which root are we searching. 0 is the tree of tree roots */
  371. __u64 tree_id;
  372. /* keys returned will be >= min and <= max */
  373. __u64 min_objectid;
  374. __u64 max_objectid;
  375. /* keys returned will be >= min and <= max */
  376. __u64 min_offset;
  377. __u64 max_offset;
  378. /* max and min transids to search for */
  379. __u64 min_transid;
  380. __u64 max_transid;
  381. /* keys returned will be >= min and <= max */
  382. __u32 min_type;
  383. __u32 max_type;
  384. /*
  385. * how many items did userland ask for, and how many are we
  386. * returning
  387. */
  388. __u32 nr_items;
  389. /* align to 64 bits */
  390. __u32 unused;
  391. /* some extra for later */
  392. __u64 unused1;
  393. __u64 unused2;
  394. __u64 unused3;
  395. __u64 unused4;
  396. };
  397. struct btrfs_ioctl_search_header {
  398. __u64 transid;
  399. __u64 objectid;
  400. __u64 offset;
  401. __u32 type;
  402. __u32 len;
  403. };
  404. #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
  405. /*
  406. * the buf is an array of search headers where
  407. * each header is followed by the actual item
  408. * the type field is expanded to 32 bits for alignment
  409. */
  410. struct btrfs_ioctl_search_args {
  411. struct btrfs_ioctl_search_key key;
  412. char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
  413. };
  414. struct btrfs_ioctl_search_args_v2 {
  415. struct btrfs_ioctl_search_key key; /* in/out - search parameters */
  416. __u64 buf_size; /* in - size of buffer
  417. * out - on EOVERFLOW: needed size
  418. * to store item */
  419. __u64 buf[0]; /* out - found items */
  420. };
  421. struct btrfs_ioctl_clone_range_args {
  422. __s64 src_fd;
  423. __u64 src_offset, src_length;
  424. __u64 dest_offset;
  425. };
  426. /*
  427. * flags definition for the defrag range ioctl
  428. *
  429. * Used by:
  430. * struct btrfs_ioctl_defrag_range_args.flags
  431. */
  432. #define BTRFS_DEFRAG_RANGE_COMPRESS 1
  433. #define BTRFS_DEFRAG_RANGE_START_IO 2
  434. struct btrfs_ioctl_defrag_range_args {
  435. /* start of the defrag operation */
  436. __u64 start;
  437. /* number of bytes to defrag, use (u64)-1 to say all */
  438. __u64 len;
  439. /*
  440. * flags for the operation, which can include turning
  441. * on compression for this one defrag
  442. */
  443. __u64 flags;
  444. /*
  445. * any extent bigger than this will be considered
  446. * already defragged. Use 0 to take the kernel default
  447. * Use 1 to say every single extent must be rewritten
  448. */
  449. __u32 extent_thresh;
  450. /*
  451. * which compression method to use if turning on compression
  452. * for this defrag operation. If unspecified, zlib will
  453. * be used
  454. */
  455. __u32 compress_type;
  456. /* spare for later */
  457. __u32 unused[4];
  458. };
  459. #define BTRFS_SAME_DATA_DIFFERS 1
  460. /* For extent-same ioctl */
  461. struct btrfs_ioctl_same_extent_info {
  462. __s64 fd; /* in - destination file */
  463. __u64 logical_offset; /* in - start of extent in destination */
  464. __u64 bytes_deduped; /* out - total # of bytes we were able
  465. * to dedupe from this file */
  466. /* status of this dedupe operation:
  467. * 0 if dedup succeeds
  468. * < 0 for error
  469. * == BTRFS_SAME_DATA_DIFFERS if data differs
  470. */
  471. __s32 status; /* out - see above description */
  472. __u32 reserved;
  473. };
  474. struct btrfs_ioctl_same_args {
  475. __u64 logical_offset; /* in - start of extent in source */
  476. __u64 length; /* in - length of extent */
  477. __u16 dest_count; /* in - total elements in info array */
  478. __u16 reserved1;
  479. __u32 reserved2;
  480. struct btrfs_ioctl_same_extent_info info[0];
  481. };
  482. struct btrfs_ioctl_space_info {
  483. __u64 flags;
  484. __u64 total_bytes;
  485. __u64 used_bytes;
  486. };
  487. struct btrfs_ioctl_space_args {
  488. __u64 space_slots;
  489. __u64 total_spaces;
  490. struct btrfs_ioctl_space_info spaces[0];
  491. };
  492. struct btrfs_data_container {
  493. __u32 bytes_left; /* out -- bytes not needed to deliver output */
  494. __u32 bytes_missing; /* out -- additional bytes needed for result */
  495. __u32 elem_cnt; /* out */
  496. __u32 elem_missed; /* out */
  497. __u64 val[0]; /* out */
  498. };
  499. struct btrfs_ioctl_ino_path_args {
  500. __u64 inum; /* in */
  501. __u64 size; /* in */
  502. __u64 reserved[4];
  503. /* struct btrfs_data_container *fspath; out */
  504. __u64 fspath; /* out */
  505. };
  506. struct btrfs_ioctl_logical_ino_args {
  507. __u64 logical; /* in */
  508. __u64 size; /* in */
  509. __u64 reserved[4];
  510. /* struct btrfs_data_container *inodes; out */
  511. __u64 inodes;
  512. };
  513. enum btrfs_dev_stat_values {
  514. /* disk I/O failure stats */
  515. BTRFS_DEV_STAT_WRITE_ERRS, /* EIO or EREMOTEIO from lower layers */
  516. BTRFS_DEV_STAT_READ_ERRS, /* EIO or EREMOTEIO from lower layers */
  517. BTRFS_DEV_STAT_FLUSH_ERRS, /* EIO or EREMOTEIO from lower layers */
  518. /* stats for indirect indications for I/O failures */
  519. BTRFS_DEV_STAT_CORRUPTION_ERRS, /* checksum error, bytenr error or
  520. * contents is illegal: this is an
  521. * indication that the block was damaged
  522. * during read or write, or written to
  523. * wrong location or read from wrong
  524. * location */
  525. BTRFS_DEV_STAT_GENERATION_ERRS, /* an indication that blocks have not
  526. * been written */
  527. BTRFS_DEV_STAT_VALUES_MAX
  528. };
  529. /* Reset statistics after reading; needs SYS_ADMIN capability */
  530. #define BTRFS_DEV_STATS_RESET (1ULL << 0)
  531. struct btrfs_ioctl_get_dev_stats {
  532. __u64 devid; /* in */
  533. __u64 nr_items; /* in/out */
  534. __u64 flags; /* in/out */
  535. /* out values: */
  536. __u64 values[BTRFS_DEV_STAT_VALUES_MAX];
  537. __u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
  538. };
  539. #define BTRFS_QUOTA_CTL_ENABLE 1
  540. #define BTRFS_QUOTA_CTL_DISABLE 2
  541. #define BTRFS_QUOTA_CTL_RESCAN__NOTUSED 3
  542. struct btrfs_ioctl_quota_ctl_args {
  543. __u64 cmd;
  544. __u64 status;
  545. };
  546. struct btrfs_ioctl_quota_rescan_args {
  547. __u64 flags;
  548. __u64 progress;
  549. __u64 reserved[6];
  550. };
  551. struct btrfs_ioctl_qgroup_assign_args {
  552. __u64 assign;
  553. __u64 src;
  554. __u64 dst;
  555. };
  556. struct btrfs_ioctl_qgroup_create_args {
  557. __u64 create;
  558. __u64 qgroupid;
  559. };
  560. struct btrfs_ioctl_timespec {
  561. __u64 sec;
  562. __u32 nsec;
  563. };
  564. struct btrfs_ioctl_received_subvol_args {
  565. char uuid[BTRFS_UUID_SIZE]; /* in */
  566. __u64 stransid; /* in */
  567. __u64 rtransid; /* out */
  568. struct btrfs_ioctl_timespec stime; /* in */
  569. struct btrfs_ioctl_timespec rtime; /* out */
  570. __u64 flags; /* in */
  571. __u64 reserved[16]; /* in */
  572. };
  573. /*
  574. * Caller doesn't want file data in the send stream, even if the
  575. * search of clone sources doesn't find an extent. UPDATE_EXTENT
  576. * commands will be sent instead of WRITE commands.
  577. */
  578. #define BTRFS_SEND_FLAG_NO_FILE_DATA 0x1
  579. /*
  580. * Do not add the leading stream header. Used when multiple snapshots
  581. * are sent back to back.
  582. */
  583. #define BTRFS_SEND_FLAG_OMIT_STREAM_HEADER 0x2
  584. /*
  585. * Omit the command at the end of the stream that indicated the end
  586. * of the stream. This option is used when multiple snapshots are
  587. * sent back to back.
  588. */
  589. #define BTRFS_SEND_FLAG_OMIT_END_CMD 0x4
  590. #define BTRFS_SEND_FLAG_MASK \
  591. (BTRFS_SEND_FLAG_NO_FILE_DATA | \
  592. BTRFS_SEND_FLAG_OMIT_STREAM_HEADER | \
  593. BTRFS_SEND_FLAG_OMIT_END_CMD)
  594. struct btrfs_ioctl_send_args {
  595. __s64 send_fd; /* in */
  596. __u64 clone_sources_count; /* in */
  597. __u64 __user *clone_sources; /* in */
  598. __u64 parent_root; /* in */
  599. __u64 flags; /* in */
  600. __u64 reserved[4]; /* in */
  601. };
  602. /* Error codes as returned by the kernel */
  603. enum btrfs_err_code {
  604. BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1,
  605. BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
  606. BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
  607. BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
  608. BTRFS_ERROR_DEV_TGT_REPLACE,
  609. BTRFS_ERROR_DEV_MISSING_NOT_FOUND,
  610. BTRFS_ERROR_DEV_ONLY_WRITABLE,
  611. BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS
  612. };
  613. /* An error code to error string mapping for the kernel
  614. * error codes
  615. */
  616. static inline char *btrfs_err_str(enum btrfs_err_code err_code)
  617. {
  618. switch (err_code) {
  619. case BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET:
  620. return "unable to go below two devices on raid1";
  621. case BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET:
  622. return "unable to go below four devices on raid10";
  623. case BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET:
  624. return "unable to go below two devices on raid5";
  625. case BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET:
  626. return "unable to go below three devices on raid6";
  627. case BTRFS_ERROR_DEV_TGT_REPLACE:
  628. return "unable to remove the dev_replace target dev";
  629. case BTRFS_ERROR_DEV_MISSING_NOT_FOUND:
  630. return "no missing devices found to remove";
  631. case BTRFS_ERROR_DEV_ONLY_WRITABLE:
  632. return "unable to remove the only writeable device";
  633. case BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS:
  634. return "add/delete/balance/replace/resize operation "\
  635. "in progress";
  636. default:
  637. return NULL;
  638. }
  639. }
  640. #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
  641. struct btrfs_ioctl_vol_args)
  642. #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
  643. struct btrfs_ioctl_vol_args)
  644. #define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \
  645. struct btrfs_ioctl_vol_args)
  646. #define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \
  647. struct btrfs_ioctl_vol_args)
  648. /* trans start and trans end are dangerous, and only for
  649. * use by applications that know how to avoid the
  650. * resulting deadlocks
  651. */
  652. #define BTRFS_IOC_TRANS_START _IO(BTRFS_IOCTL_MAGIC, 6)
  653. #define BTRFS_IOC_TRANS_END _IO(BTRFS_IOCTL_MAGIC, 7)
  654. #define BTRFS_IOC_SYNC _IO(BTRFS_IOCTL_MAGIC, 8)
  655. #define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)
  656. #define BTRFS_IOC_ADD_DEV _IOW(BTRFS_IOCTL_MAGIC, 10, \
  657. struct btrfs_ioctl_vol_args)
  658. #define BTRFS_IOC_RM_DEV _IOW(BTRFS_IOCTL_MAGIC, 11, \
  659. struct btrfs_ioctl_vol_args)
  660. #define BTRFS_IOC_BALANCE _IOW(BTRFS_IOCTL_MAGIC, 12, \
  661. struct btrfs_ioctl_vol_args)
  662. #define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \
  663. struct btrfs_ioctl_clone_range_args)
  664. #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
  665. struct btrfs_ioctl_vol_args)
  666. #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
  667. struct btrfs_ioctl_vol_args)
  668. #define BTRFS_IOC_DEFRAG_RANGE _IOW(BTRFS_IOCTL_MAGIC, 16, \
  669. struct btrfs_ioctl_defrag_range_args)
  670. #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
  671. struct btrfs_ioctl_search_args)
  672. #define BTRFS_IOC_TREE_SEARCH_V2 _IOWR(BTRFS_IOCTL_MAGIC, 17, \
  673. struct btrfs_ioctl_search_args_v2)
  674. #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
  675. struct btrfs_ioctl_ino_lookup_args)
  676. #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, __u64)
  677. #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
  678. struct btrfs_ioctl_space_args)
  679. #define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64)
  680. #define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)
  681. #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
  682. struct btrfs_ioctl_vol_args_v2)
  683. #define BTRFS_IOC_SUBVOL_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 24, \
  684. struct btrfs_ioctl_vol_args_v2)
  685. #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)
  686. #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
  687. #define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \
  688. struct btrfs_ioctl_scrub_args)
  689. #define BTRFS_IOC_SCRUB_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28)
  690. #define BTRFS_IOC_SCRUB_PROGRESS _IOWR(BTRFS_IOCTL_MAGIC, 29, \
  691. struct btrfs_ioctl_scrub_args)
  692. #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
  693. struct btrfs_ioctl_dev_info_args)
  694. #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
  695. struct btrfs_ioctl_fs_info_args)
  696. #define BTRFS_IOC_BALANCE_V2 _IOWR(BTRFS_IOCTL_MAGIC, 32, \
  697. struct btrfs_ioctl_balance_args)
  698. #define BTRFS_IOC_BALANCE_CTL _IOW(BTRFS_IOCTL_MAGIC, 33, int)
  699. #define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 34, \
  700. struct btrfs_ioctl_balance_args)
  701. #define BTRFS_IOC_INO_PATHS _IOWR(BTRFS_IOCTL_MAGIC, 35, \
  702. struct btrfs_ioctl_ino_path_args)
  703. #define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \
  704. struct btrfs_ioctl_ino_path_args)
  705. #define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \
  706. struct btrfs_ioctl_received_subvol_args)
  707. #define BTRFS_IOC_SEND _IOW(BTRFS_IOCTL_MAGIC, 38, struct btrfs_ioctl_send_args)
  708. #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
  709. struct btrfs_ioctl_vol_args)
  710. #define BTRFS_IOC_QUOTA_CTL _IOWR(BTRFS_IOCTL_MAGIC, 40, \
  711. struct btrfs_ioctl_quota_ctl_args)
  712. #define BTRFS_IOC_QGROUP_ASSIGN _IOW(BTRFS_IOCTL_MAGIC, 41, \
  713. struct btrfs_ioctl_qgroup_assign_args)
  714. #define BTRFS_IOC_QGROUP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 42, \
  715. struct btrfs_ioctl_qgroup_create_args)
  716. #define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43, \
  717. struct btrfs_ioctl_qgroup_limit_args)
  718. #define BTRFS_IOC_QUOTA_RESCAN _IOW(BTRFS_IOCTL_MAGIC, 44, \
  719. struct btrfs_ioctl_quota_rescan_args)
  720. #define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45, \
  721. struct btrfs_ioctl_quota_rescan_args)
  722. #define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
  723. #define BTRFS_IOC_GET_FSLABEL _IOR(BTRFS_IOCTL_MAGIC, 49, \
  724. char[BTRFS_LABEL_SIZE])
  725. #define BTRFS_IOC_SET_FSLABEL _IOW(BTRFS_IOCTL_MAGIC, 50, \
  726. char[BTRFS_LABEL_SIZE])
  727. #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
  728. struct btrfs_ioctl_get_dev_stats)
  729. #define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53, \
  730. struct btrfs_ioctl_dev_replace_args)
  731. #define BTRFS_IOC_FILE_EXTENT_SAME _IOWR(BTRFS_IOCTL_MAGIC, 54, \
  732. struct btrfs_ioctl_same_args)
  733. #define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
  734. struct btrfs_ioctl_feature_flags)
  735. #define BTRFS_IOC_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 57, \
  736. struct btrfs_ioctl_feature_flags[2])
  737. #define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
  738. struct btrfs_ioctl_feature_flags[3])
  739. #define BTRFS_IOC_RM_DEV_V2 _IOW(BTRFS_IOCTL_MAGIC, 58, \
  740. struct btrfs_ioctl_vol_args_v2)
  741. #endif /* _UAPI_LINUX_BTRFS_H */