ioctl.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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 __IOCTL_
  19. #define __IOCTL_
  20. #include <linux/ioctl.h>
  21. #define BTRFS_IOCTL_MAGIC 0x94
  22. #define BTRFS_VOL_NAME_MAX 255
  23. /* this should be 4k */
  24. #define BTRFS_PATH_NAME_MAX 4087
  25. struct btrfs_ioctl_vol_args {
  26. __s64 fd;
  27. char name[BTRFS_PATH_NAME_MAX + 1];
  28. };
  29. #define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
  30. #define BTRFS_SUBVOL_RDONLY (1ULL << 1)
  31. #define BTRFS_FSID_SIZE 16
  32. #define BTRFS_UUID_SIZE 16
  33. #define BTRFS_QGROUP_INHERIT_SET_LIMITS (1ULL << 0)
  34. struct btrfs_qgroup_limit {
  35. __u64 flags;
  36. __u64 max_rfer;
  37. __u64 max_excl;
  38. __u64 rsv_rfer;
  39. __u64 rsv_excl;
  40. };
  41. struct btrfs_qgroup_inherit {
  42. __u64 flags;
  43. __u64 num_qgroups;
  44. __u64 num_ref_copies;
  45. __u64 num_excl_copies;
  46. struct btrfs_qgroup_limit lim;
  47. __u64 qgroups[0];
  48. };
  49. struct btrfs_ioctl_qgroup_limit_args {
  50. __u64 qgroupid;
  51. struct btrfs_qgroup_limit lim;
  52. };
  53. #define BTRFS_SUBVOL_NAME_MAX 4039
  54. struct btrfs_ioctl_vol_args_v2 {
  55. __s64 fd;
  56. __u64 transid;
  57. __u64 flags;
  58. __u64 unused[4];
  59. char name[BTRFS_SUBVOL_NAME_MAX + 1];
  60. };
  61. /*
  62. * structure to report errors and progress to userspace, either as a
  63. * result of a finished scrub, a canceled scrub or a progress inquiry
  64. */
  65. struct btrfs_scrub_progress {
  66. __u64 data_extents_scrubbed; /* # of data extents scrubbed */
  67. __u64 tree_extents_scrubbed; /* # of tree extents scrubbed */
  68. __u64 data_bytes_scrubbed; /* # of data bytes scrubbed */
  69. __u64 tree_bytes_scrubbed; /* # of tree bytes scrubbed */
  70. __u64 read_errors; /* # of read errors encountered (EIO) */
  71. __u64 csum_errors; /* # of failed csum checks */
  72. __u64 verify_errors; /* # of occurences, where the metadata
  73. * of a tree block did not match the
  74. * expected values, like generation or
  75. * logical */
  76. __u64 no_csum; /* # of 4k data block for which no csum
  77. * is present, probably the result of
  78. * data written with nodatasum */
  79. __u64 csum_discards; /* # of csum for which no data was found
  80. * in the extent tree. */
  81. __u64 super_errors; /* # of bad super blocks encountered */
  82. __u64 malloc_errors; /* # of internal kmalloc errors. These
  83. * will likely cause an incomplete
  84. * scrub */
  85. __u64 uncorrectable_errors; /* # of errors where either no intact
  86. * copy was found or the writeback
  87. * failed */
  88. __u64 corrected_errors; /* # of errors corrected */
  89. __u64 last_physical; /* last physical address scrubbed. In
  90. * case a scrub was aborted, this can
  91. * be used to restart the scrub */
  92. __u64 unverified_errors; /* # of occurences where a read for a
  93. * full (64k) bio failed, but the re-
  94. * check succeeded for each 4k piece.
  95. * Intermittent error. */
  96. };
  97. #define BTRFS_SCRUB_READONLY 1
  98. struct btrfs_ioctl_scrub_args {
  99. __u64 devid; /* in */
  100. __u64 start; /* in */
  101. __u64 end; /* in */
  102. __u64 flags; /* in */
  103. struct btrfs_scrub_progress progress; /* out */
  104. /* pad to 1k */
  105. __u64 unused[(1024-32-sizeof(struct btrfs_scrub_progress))/8];
  106. };
  107. #define BTRFS_DEVICE_PATH_NAME_MAX 1024
  108. struct btrfs_ioctl_dev_info_args {
  109. __u64 devid; /* in/out */
  110. __u8 uuid[BTRFS_UUID_SIZE]; /* in/out */
  111. __u64 bytes_used; /* out */
  112. __u64 total_bytes; /* out */
  113. __u64 unused[379]; /* pad to 4k */
  114. __u8 path[BTRFS_DEVICE_PATH_NAME_MAX]; /* out */
  115. };
  116. struct btrfs_ioctl_fs_info_args {
  117. __u64 max_id; /* out */
  118. __u64 num_devices; /* out */
  119. __u8 fsid[BTRFS_FSID_SIZE]; /* out */
  120. __u64 reserved[124]; /* pad to 1k */
  121. };
  122. /* balance control ioctl modes */
  123. #define BTRFS_BALANCE_CTL_PAUSE 1
  124. #define BTRFS_BALANCE_CTL_CANCEL 2
  125. /*
  126. * this is packed, because it should be exactly the same as its disk
  127. * byte order counterpart (struct btrfs_disk_balance_args)
  128. */
  129. struct btrfs_balance_args {
  130. __u64 profiles;
  131. __u64 usage;
  132. __u64 devid;
  133. __u64 pstart;
  134. __u64 pend;
  135. __u64 vstart;
  136. __u64 vend;
  137. __u64 target;
  138. __u64 flags;
  139. __u64 unused[8];
  140. } __attribute__ ((__packed__));
  141. /* report balance progress to userspace */
  142. struct btrfs_balance_progress {
  143. __u64 expected; /* estimated # of chunks that will be
  144. * relocated to fulfill the request */
  145. __u64 considered; /* # of chunks we have considered so far */
  146. __u64 completed; /* # of chunks relocated so far */
  147. };
  148. #define BTRFS_BALANCE_STATE_RUNNING (1ULL << 0)
  149. #define BTRFS_BALANCE_STATE_PAUSE_REQ (1ULL << 1)
  150. #define BTRFS_BALANCE_STATE_CANCEL_REQ (1ULL << 2)
  151. struct btrfs_ioctl_balance_args {
  152. __u64 flags; /* in/out */
  153. __u64 state; /* out */
  154. struct btrfs_balance_args data; /* in/out */
  155. struct btrfs_balance_args meta; /* in/out */
  156. struct btrfs_balance_args sys; /* in/out */
  157. struct btrfs_balance_progress stat; /* out */
  158. __u64 unused[72]; /* pad to 1k */
  159. };
  160. #define BTRFS_INO_LOOKUP_PATH_MAX 4080
  161. struct btrfs_ioctl_ino_lookup_args {
  162. __u64 treeid;
  163. __u64 objectid;
  164. char name[BTRFS_INO_LOOKUP_PATH_MAX];
  165. };
  166. struct btrfs_ioctl_search_key {
  167. /* which root are we searching. 0 is the tree of tree roots */
  168. __u64 tree_id;
  169. /* keys returned will be >= min and <= max */
  170. __u64 min_objectid;
  171. __u64 max_objectid;
  172. /* keys returned will be >= min and <= max */
  173. __u64 min_offset;
  174. __u64 max_offset;
  175. /* max and min transids to search for */
  176. __u64 min_transid;
  177. __u64 max_transid;
  178. /* keys returned will be >= min and <= max */
  179. __u32 min_type;
  180. __u32 max_type;
  181. /*
  182. * how many items did userland ask for, and how many are we
  183. * returning
  184. */
  185. __u32 nr_items;
  186. /* align to 64 bits */
  187. __u32 unused;
  188. /* some extra for later */
  189. __u64 unused1;
  190. __u64 unused2;
  191. __u64 unused3;
  192. __u64 unused4;
  193. };
  194. struct btrfs_ioctl_search_header {
  195. __u64 transid;
  196. __u64 objectid;
  197. __u64 offset;
  198. __u32 type;
  199. __u32 len;
  200. };
  201. #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
  202. /*
  203. * the buf is an array of search headers where
  204. * each header is followed by the actual item
  205. * the type field is expanded to 32 bits for alignment
  206. */
  207. struct btrfs_ioctl_search_args {
  208. struct btrfs_ioctl_search_key key;
  209. char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
  210. };
  211. struct btrfs_ioctl_clone_range_args {
  212. __s64 src_fd;
  213. __u64 src_offset, src_length;
  214. __u64 dest_offset;
  215. };
  216. /* flags for the defrag range ioctl */
  217. #define BTRFS_DEFRAG_RANGE_COMPRESS 1
  218. #define BTRFS_DEFRAG_RANGE_START_IO 2
  219. struct btrfs_ioctl_space_info {
  220. __u64 flags;
  221. __u64 total_bytes;
  222. __u64 used_bytes;
  223. };
  224. struct btrfs_ioctl_space_args {
  225. __u64 space_slots;
  226. __u64 total_spaces;
  227. struct btrfs_ioctl_space_info spaces[0];
  228. };
  229. struct btrfs_data_container {
  230. __u32 bytes_left; /* out -- bytes not needed to deliver output */
  231. __u32 bytes_missing; /* out -- additional bytes needed for result */
  232. __u32 elem_cnt; /* out */
  233. __u32 elem_missed; /* out */
  234. __u64 val[0]; /* out */
  235. };
  236. struct btrfs_ioctl_ino_path_args {
  237. __u64 inum; /* in */
  238. __u64 size; /* in */
  239. __u64 reserved[4];
  240. /* struct btrfs_data_container *fspath; out */
  241. __u64 fspath; /* out */
  242. };
  243. struct btrfs_ioctl_logical_ino_args {
  244. __u64 logical; /* in */
  245. __u64 size; /* in */
  246. __u64 reserved[4];
  247. /* struct btrfs_data_container *inodes; out */
  248. __u64 inodes;
  249. };
  250. enum btrfs_dev_stat_values {
  251. /* disk I/O failure stats */
  252. BTRFS_DEV_STAT_WRITE_ERRS, /* EIO or EREMOTEIO from lower layers */
  253. BTRFS_DEV_STAT_READ_ERRS, /* EIO or EREMOTEIO from lower layers */
  254. BTRFS_DEV_STAT_FLUSH_ERRS, /* EIO or EREMOTEIO from lower layers */
  255. /* stats for indirect indications for I/O failures */
  256. BTRFS_DEV_STAT_CORRUPTION_ERRS, /* checksum error, bytenr error or
  257. * contents is illegal: this is an
  258. * indication that the block was damaged
  259. * during read or write, or written to
  260. * wrong location or read from wrong
  261. * location */
  262. BTRFS_DEV_STAT_GENERATION_ERRS, /* an indication that blocks have not
  263. * been written */
  264. BTRFS_DEV_STAT_VALUES_MAX
  265. };
  266. struct btrfs_ioctl_get_dev_stats {
  267. __u64 devid; /* in */
  268. __u64 nr_items; /* in/out */
  269. /* out values: */
  270. __u64 values[BTRFS_DEV_STAT_VALUES_MAX];
  271. __u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
  272. };
  273. #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
  274. struct btrfs_ioctl_vol_args)
  275. #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
  276. struct btrfs_ioctl_vol_args)
  277. #define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \
  278. struct btrfs_ioctl_vol_args)
  279. #define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \
  280. struct btrfs_ioctl_vol_args)
  281. /* trans start and trans end are dangerous, and only for
  282. * use by applications that know how to avoid the
  283. * resulting deadlocks
  284. */
  285. #define BTRFS_IOC_TRANS_START _IO(BTRFS_IOCTL_MAGIC, 6)
  286. #define BTRFS_IOC_TRANS_END _IO(BTRFS_IOCTL_MAGIC, 7)
  287. #define BTRFS_IOC_SYNC _IO(BTRFS_IOCTL_MAGIC, 8)
  288. #define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)
  289. #define BTRFS_IOC_ADD_DEV _IOW(BTRFS_IOCTL_MAGIC, 10, \
  290. struct btrfs_ioctl_vol_args)
  291. #define BTRFS_IOC_RM_DEV _IOW(BTRFS_IOCTL_MAGIC, 11, \
  292. struct btrfs_ioctl_vol_args)
  293. #define BTRFS_IOC_BALANCE _IOW(BTRFS_IOCTL_MAGIC, 12, \
  294. struct btrfs_ioctl_vol_args)
  295. #define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \
  296. struct btrfs_ioctl_clone_range_args)
  297. #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
  298. struct btrfs_ioctl_vol_args)
  299. #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
  300. struct btrfs_ioctl_vol_args)
  301. #define BTRFS_IOC_DEFRAG_RANGE _IOW(BTRFS_IOCTL_MAGIC, 16, \
  302. struct btrfs_ioctl_defrag_range_args)
  303. #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
  304. struct btrfs_ioctl_search_args)
  305. #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
  306. struct btrfs_ioctl_ino_lookup_args)
  307. #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64)
  308. #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
  309. struct btrfs_ioctl_space_args)
  310. #define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64)
  311. #define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)
  312. #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
  313. struct btrfs_ioctl_vol_args_v2)
  314. #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)
  315. #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
  316. #define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \
  317. struct btrfs_ioctl_scrub_args)
  318. #define BTRFS_IOC_SCRUB_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28)
  319. #define BTRFS_IOC_SCRUB_PROGRESS _IOWR(BTRFS_IOCTL_MAGIC, 29, \
  320. struct btrfs_ioctl_scrub_args)
  321. #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
  322. struct btrfs_ioctl_dev_info_args)
  323. #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
  324. struct btrfs_ioctl_fs_info_args)
  325. #define BTRFS_IOC_BALANCE_V2 _IOWR(BTRFS_IOCTL_MAGIC, 32, \
  326. struct btrfs_ioctl_balance_args)
  327. #define BTRFS_IOC_BALANCE_CTL _IOW(BTRFS_IOCTL_MAGIC, 33, int)
  328. #define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 34, \
  329. struct btrfs_ioctl_balance_args)
  330. #define BTRFS_IOC_INO_PATHS _IOWR(BTRFS_IOCTL_MAGIC, 35, \
  331. struct btrfs_ioctl_ino_path_args)
  332. #define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \
  333. struct btrfs_ioctl_ino_path_args)
  334. #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
  335. struct btrfs_ioctl_get_dev_stats)
  336. #define BTRFS_IOC_GET_AND_RESET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 53, \
  337. struct btrfs_ioctl_get_dev_stats)
  338. #endif