1 // No copyright claimed in this file - do what you want with it. 2 3 #ifndef BTRFSIOCTL_H_DEFINED 4 #define BTRFSIOCTL_H_DEFINED 5 6 #include "btrfs.h" 7 8 #define FSCTL_BTRFS_GET_FILE_IDS CTL_CODE(FILE_DEVICE_UNKNOWN, 0x829, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 9 #define FSCTL_BTRFS_CREATE_SUBVOL CTL_CODE(FILE_DEVICE_UNKNOWN, 0x82a, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 10 #define FSCTL_BTRFS_CREATE_SNAPSHOT CTL_CODE(FILE_DEVICE_UNKNOWN, 0x82b, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 11 #define FSCTL_BTRFS_GET_INODE_INFO CTL_CODE(FILE_DEVICE_UNKNOWN, 0x82c, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 12 #define FSCTL_BTRFS_SET_INODE_INFO CTL_CODE(FILE_DEVICE_UNKNOWN, 0x82d, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 13 #define FSCTL_BTRFS_GET_DEVICES CTL_CODE(FILE_DEVICE_UNKNOWN, 0x82e, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 14 #define FSCTL_BTRFS_GET_USAGE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x82f, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 15 #define FSCTL_BTRFS_START_BALANCE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x830, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 16 #define FSCTL_BTRFS_QUERY_BALANCE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x831, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 17 #define FSCTL_BTRFS_PAUSE_BALANCE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x832, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 18 #define FSCTL_BTRFS_RESUME_BALANCE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x833, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 19 #define FSCTL_BTRFS_STOP_BALANCE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x834, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 20 #define FSCTL_BTRFS_ADD_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x835, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 21 #define FSCTL_BTRFS_REMOVE_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x836, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 22 #define IOCTL_BTRFS_QUERY_FILESYSTEMS CTL_CODE(FILE_DEVICE_UNKNOWN, 0x837, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 23 #define FSCTL_BTRFS_GET_UUID CTL_CODE(FILE_DEVICE_UNKNOWN, 0x838, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 24 #define FSCTL_BTRFS_START_SCRUB CTL_CODE(FILE_DEVICE_UNKNOWN, 0x839, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 25 #define FSCTL_BTRFS_QUERY_SCRUB CTL_CODE(FILE_DEVICE_UNKNOWN, 0x83a, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 26 #define FSCTL_BTRFS_PAUSE_SCRUB CTL_CODE(FILE_DEVICE_UNKNOWN, 0x83b, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 27 #define FSCTL_BTRFS_RESUME_SCRUB CTL_CODE(FILE_DEVICE_UNKNOWN, 0x83c, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 28 #define FSCTL_BTRFS_STOP_SCRUB CTL_CODE(FILE_DEVICE_UNKNOWN, 0x83d, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 29 #define IOCTL_BTRFS_PROBE_VOLUME CTL_CODE(FILE_DEVICE_UNKNOWN, 0x83e, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 30 #define FSCTL_BTRFS_RESET_STATS CTL_CODE(FILE_DEVICE_UNKNOWN, 0x83f, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 31 #define FSCTL_BTRFS_MKNOD CTL_CODE(FILE_DEVICE_UNKNOWN, 0x840, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 32 #define FSCTL_BTRFS_RECEIVED_SUBVOL CTL_CODE(FILE_DEVICE_UNKNOWN, 0x841, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 33 #define FSCTL_BTRFS_GET_XATTRS CTL_CODE(FILE_DEVICE_UNKNOWN, 0x842, METHOD_BUFFERED, FILE_ANY_ACCESS) 34 #define FSCTL_BTRFS_SET_XATTR CTL_CODE(FILE_DEVICE_UNKNOWN, 0x843, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 35 #define FSCTL_BTRFS_RESERVE_SUBVOL CTL_CODE(FILE_DEVICE_UNKNOWN, 0x844, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 36 #define FSCTL_BTRFS_FIND_SUBVOL CTL_CODE(FILE_DEVICE_UNKNOWN, 0x845, METHOD_BUFFERED, FILE_ANY_ACCESS) 37 #define FSCTL_BTRFS_SEND_SUBVOL CTL_CODE(FILE_DEVICE_UNKNOWN, 0x846, METHOD_BUFFERED, FILE_ANY_ACCESS) 38 #define FSCTL_BTRFS_READ_SEND_BUFFER CTL_CODE(FILE_DEVICE_UNKNOWN, 0x847, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 39 #define FSCTL_BTRFS_RESIZE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x848, METHOD_IN_DIRECT, FILE_ANY_ACCESS) 40 41 typedef struct { 42 UINT64 subvol; 43 UINT64 inode; 44 BOOL top; 45 } btrfs_get_file_ids; 46 47 typedef struct { 48 HANDLE subvol; 49 BOOL readonly; 50 BOOL posix; 51 UINT16 namelen; 52 WCHAR name[1]; 53 } btrfs_create_snapshot; 54 55 typedef struct { 56 void* POINTER_32 subvol; 57 BOOL readonly; 58 BOOL posix; 59 UINT16 namelen; 60 WCHAR name[1]; 61 } btrfs_create_snapshot32; 62 63 #define BTRFS_COMPRESSION_ANY 0 64 #define BTRFS_COMPRESSION_ZLIB 1 65 #define BTRFS_COMPRESSION_LZO 2 66 #define BTRFS_COMPRESSION_ZSTD 3 67 68 typedef struct { 69 UINT64 subvol; 70 UINT64 inode; 71 BOOL top; 72 UINT8 type; 73 UINT32 st_uid; 74 UINT32 st_gid; 75 UINT32 st_mode; 76 UINT64 st_rdev; 77 UINT64 flags; 78 UINT32 inline_length; 79 UINT64 disk_size[3]; 80 UINT8 compression_type; 81 } btrfs_inode_info; 82 83 typedef struct { 84 UINT64 subvol; 85 UINT64 inode; 86 BOOL top; 87 UINT8 type; 88 UINT32 st_uid; 89 UINT32 st_gid; 90 UINT32 st_mode; 91 UINT64 st_rdev; 92 UINT64 flags; 93 UINT32 inline_length; 94 UINT64 disk_size_uncompressed; 95 UINT64 disk_size_zlib; 96 UINT64 disk_size_lzo; 97 UINT8 compression_type; 98 UINT64 disk_size_zstd; 99 UINT64 sparse_size; 100 } btrfs_inode_info2; 101 102 typedef struct { 103 UINT64 flags; 104 BOOL flags_changed; 105 UINT32 st_uid; 106 BOOL uid_changed; 107 UINT32 st_gid; 108 BOOL gid_changed; 109 UINT32 st_mode; 110 BOOL mode_changed; 111 UINT8 compression_type; 112 BOOL compression_type_changed; 113 } btrfs_set_inode_info; 114 115 typedef struct { 116 UINT32 next_entry; 117 UINT64 dev_id; 118 UINT64 size; 119 UINT64 max_size; 120 BOOL readonly; 121 BOOL missing; 122 ULONG device_number; 123 ULONG partition_number; 124 UINT64 stats[5]; 125 USHORT namelen; 126 WCHAR name[1]; 127 } btrfs_device; 128 129 typedef struct { 130 UINT64 dev_id; 131 UINT64 alloc; 132 } btrfs_usage_device; 133 134 typedef struct { 135 UINT32 next_entry; 136 UINT64 type; 137 UINT64 size; 138 UINT64 used; 139 UINT64 num_devices; 140 btrfs_usage_device devices[1]; 141 } btrfs_usage; 142 143 #define BTRFS_BALANCE_OPTS_ENABLED 0x001 144 #define BTRFS_BALANCE_OPTS_PROFILES 0x002 145 #define BTRFS_BALANCE_OPTS_DEVID 0x004 146 #define BTRFS_BALANCE_OPTS_DRANGE 0x008 147 #define BTRFS_BALANCE_OPTS_VRANGE 0x010 148 #define BTRFS_BALANCE_OPTS_LIMIT 0x020 149 #define BTRFS_BALANCE_OPTS_STRIPES 0x040 150 #define BTRFS_BALANCE_OPTS_USAGE 0x080 151 #define BTRFS_BALANCE_OPTS_CONVERT 0x100 152 #define BTRFS_BALANCE_OPTS_SOFT 0x200 153 154 #define BLOCK_FLAG_SINGLE 0x1000000000000 // only used in balance 155 156 typedef struct { 157 UINT64 flags; 158 UINT64 profiles; 159 UINT64 devid; 160 UINT64 drange_start; 161 UINT64 drange_end; 162 UINT64 vrange_start; 163 UINT64 vrange_end; 164 UINT64 limit_start; 165 UINT64 limit_end; 166 UINT16 stripes_start; 167 UINT16 stripes_end; 168 UINT8 usage_start; 169 UINT8 usage_end; 170 UINT64 convert; 171 } btrfs_balance_opts; 172 173 #define BTRFS_BALANCE_STOPPED 0 174 #define BTRFS_BALANCE_RUNNING 1 175 #define BTRFS_BALANCE_PAUSED 2 176 #define BTRFS_BALANCE_REMOVAL 4 177 #define BTRFS_BALANCE_ERROR 8 178 #define BTRFS_BALANCE_SHRINKING 16 179 180 typedef struct { 181 UINT32 status; 182 UINT64 chunks_left; 183 UINT64 total_chunks; 184 NTSTATUS error; 185 btrfs_balance_opts data_opts; 186 btrfs_balance_opts metadata_opts; 187 btrfs_balance_opts system_opts; 188 } btrfs_query_balance; 189 190 typedef struct { 191 btrfs_balance_opts opts[3]; 192 } btrfs_start_balance; 193 194 typedef struct { 195 UINT8 uuid[16]; 196 BOOL missing; 197 USHORT name_length; 198 WCHAR name[1]; 199 } btrfs_filesystem_device; 200 201 typedef struct { 202 UINT32 next_entry; 203 UINT8 uuid[16]; 204 UINT32 num_devices; 205 btrfs_filesystem_device device; 206 } btrfs_filesystem; 207 208 #define BTRFS_SCRUB_STOPPED 0 209 #define BTRFS_SCRUB_RUNNING 1 210 #define BTRFS_SCRUB_PAUSED 2 211 212 typedef struct { 213 UINT32 next_entry; 214 UINT64 address; 215 UINT64 device; 216 BOOL recovered; 217 BOOL is_metadata; 218 BOOL parity; 219 220 union { 221 struct { 222 UINT64 subvol; 223 UINT64 offset; 224 UINT16 filename_length; 225 WCHAR filename[1]; 226 } data; 227 228 struct { 229 UINT64 root; 230 UINT8 level; 231 KEY firstitem; 232 } metadata; 233 }; 234 } btrfs_scrub_error; 235 236 typedef struct { 237 UINT32 status; 238 LARGE_INTEGER start_time; 239 LARGE_INTEGER finish_time; 240 UINT64 chunks_left; 241 UINT64 total_chunks; 242 UINT64 data_scrubbed; 243 UINT64 duration; 244 NTSTATUS error; 245 UINT32 num_errors; 246 btrfs_scrub_error errors; 247 } btrfs_query_scrub; 248 249 typedef struct { 250 UINT64 inode; 251 UINT8 type; 252 UINT64 st_rdev; 253 UINT16 namelen; 254 WCHAR name[1]; 255 } btrfs_mknod; 256 257 typedef struct { 258 UINT64 generation; 259 BTRFS_UUID uuid; 260 } btrfs_received_subvol; 261 262 typedef struct { 263 USHORT namelen; 264 USHORT valuelen; 265 char data[1]; 266 } btrfs_set_xattr; 267 268 typedef struct { 269 BOOL readonly; 270 BOOL posix; 271 USHORT namelen; 272 WCHAR name[1]; 273 } btrfs_create_subvol; 274 275 typedef struct { 276 BTRFS_UUID uuid; 277 UINT64 ctransid; 278 } btrfs_find_subvol; 279 280 typedef struct { 281 HANDLE parent; 282 ULONG num_clones; 283 HANDLE clones[1]; 284 } btrfs_send_subvol; 285 286 typedef struct { 287 void* POINTER_32 parent; 288 ULONG num_clones; 289 void* POINTER_32 clones[1]; 290 } btrfs_send_subvol32; 291 292 typedef struct { 293 UINT64 device; 294 UINT64 size; 295 } btrfs_resize; 296 297 #endif 298