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