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 41 typedef struct { 42 uint64_t subvol; 43 uint64_t inode; 44 BOOL top; 45 } btrfs_get_file_ids; 46 47 typedef struct { 48 HANDLE subvol; 49 BOOL readonly; 50 BOOL posix; 51 uint16_t 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_t 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_t subvol; 70 uint64_t inode; 71 BOOL top; 72 uint8_t type; 73 uint32_t st_uid; 74 uint32_t st_gid; 75 uint32_t st_mode; 76 uint64_t st_rdev; 77 uint64_t flags; 78 uint32_t inline_length; 79 uint64_t disk_size_uncompressed; 80 uint64_t disk_size_zlib; 81 uint64_t disk_size_lzo; 82 uint8_t compression_type; 83 uint64_t disk_size_zstd; 84 uint64_t sparse_size; 85 uint32_t num_extents; 86 } btrfs_inode_info; 87 88 typedef struct { 89 uint64_t flags; 90 BOOL flags_changed; 91 uint32_t st_uid; 92 BOOL uid_changed; 93 uint32_t st_gid; 94 BOOL gid_changed; 95 uint32_t st_mode; 96 BOOL mode_changed; 97 uint8_t compression_type; 98 BOOL compression_type_changed; 99 } btrfs_set_inode_info; 100 101 typedef struct { 102 uint32_t next_entry; 103 uint64_t dev_id; 104 uint64_t size; 105 uint64_t max_size; 106 BOOL readonly; 107 BOOL missing; 108 ULONG device_number; 109 ULONG partition_number; 110 uint64_t stats[5]; 111 USHORT namelen; 112 WCHAR name[1]; 113 } btrfs_device; 114 115 typedef struct { 116 uint64_t dev_id; 117 uint64_t alloc; 118 } btrfs_usage_device; 119 120 typedef struct { 121 uint32_t next_entry; 122 uint64_t type; 123 uint64_t size; 124 uint64_t used; 125 uint64_t num_devices; 126 btrfs_usage_device devices[1]; 127 } btrfs_usage; 128 129 #define BTRFS_BALANCE_OPTS_ENABLED 0x001 130 #define BTRFS_BALANCE_OPTS_PROFILES 0x002 131 #define BTRFS_BALANCE_OPTS_DEVID 0x004 132 #define BTRFS_BALANCE_OPTS_DRANGE 0x008 133 #define BTRFS_BALANCE_OPTS_VRANGE 0x010 134 #define BTRFS_BALANCE_OPTS_LIMIT 0x020 135 #define BTRFS_BALANCE_OPTS_STRIPES 0x040 136 #define BTRFS_BALANCE_OPTS_USAGE 0x080 137 #define BTRFS_BALANCE_OPTS_CONVERT 0x100 138 #define BTRFS_BALANCE_OPTS_SOFT 0x200 139 140 #define BLOCK_FLAG_SINGLE 0x1000000000000 // only used in balance 141 142 typedef struct { 143 uint64_t flags; 144 uint64_t profiles; 145 uint64_t devid; 146 uint64_t drange_start; 147 uint64_t drange_end; 148 uint64_t vrange_start; 149 uint64_t vrange_end; 150 uint64_t limit_start; 151 uint64_t limit_end; 152 uint16_t stripes_start; 153 uint16_t stripes_end; 154 uint8_t usage_start; 155 uint8_t usage_end; 156 uint64_t convert; 157 } btrfs_balance_opts; 158 159 #define BTRFS_BALANCE_STOPPED 0 160 #define BTRFS_BALANCE_RUNNING 1 161 #define BTRFS_BALANCE_PAUSED 2 162 #define BTRFS_BALANCE_REMOVAL 4 163 #define BTRFS_BALANCE_ERROR 8 164 #define BTRFS_BALANCE_SHRINKING 16 165 166 typedef struct { 167 uint32_t status; 168 uint64_t chunks_left; 169 uint64_t total_chunks; 170 NTSTATUS error; 171 btrfs_balance_opts data_opts; 172 btrfs_balance_opts metadata_opts; 173 btrfs_balance_opts system_opts; 174 } btrfs_query_balance; 175 176 typedef struct { 177 btrfs_balance_opts opts[3]; 178 } btrfs_start_balance; 179 180 typedef struct { 181 uint8_t uuid[16]; 182 BOOL missing; 183 USHORT name_length; 184 WCHAR name[1]; 185 } btrfs_filesystem_device; 186 187 typedef struct { 188 uint32_t next_entry; 189 uint8_t uuid[16]; 190 uint32_t num_devices; 191 btrfs_filesystem_device device; 192 } btrfs_filesystem; 193 194 #define BTRFS_SCRUB_STOPPED 0 195 #define BTRFS_SCRUB_RUNNING 1 196 #define BTRFS_SCRUB_PAUSED 2 197 198 typedef struct { 199 uint32_t next_entry; 200 uint64_t address; 201 uint64_t device; 202 BOOL recovered; 203 BOOL is_metadata; 204 BOOL parity; 205 206 union { 207 struct { 208 uint64_t subvol; 209 uint64_t offset; 210 uint16_t filename_length; 211 WCHAR filename[1]; 212 } data; 213 214 struct { 215 uint64_t root; 216 uint8_t level; 217 KEY firstitem; 218 } metadata; 219 }; 220 } btrfs_scrub_error; 221 222 typedef struct { 223 uint32_t status; 224 LARGE_INTEGER start_time; 225 LARGE_INTEGER finish_time; 226 uint64_t chunks_left; 227 uint64_t total_chunks; 228 uint64_t data_scrubbed; 229 uint64_t duration; 230 NTSTATUS error; 231 uint32_t num_errors; 232 btrfs_scrub_error errors; 233 } btrfs_query_scrub; 234 235 typedef struct { 236 uint64_t inode; 237 uint8_t type; 238 uint64_t st_rdev; 239 uint16_t namelen; 240 WCHAR name[1]; 241 } btrfs_mknod; 242 243 typedef struct { 244 uint64_t generation; 245 BTRFS_UUID uuid; 246 } btrfs_received_subvol; 247 248 typedef struct { 249 USHORT namelen; 250 USHORT valuelen; 251 char data[1]; 252 } btrfs_set_xattr; 253 254 typedef struct { 255 BOOL readonly; 256 BOOL posix; 257 USHORT namelen; 258 WCHAR name[1]; 259 } btrfs_create_subvol; 260 261 typedef struct { 262 BTRFS_UUID uuid; 263 uint64_t ctransid; 264 } btrfs_find_subvol; 265 266 typedef struct { 267 HANDLE parent; 268 ULONG num_clones; 269 HANDLE clones[1]; 270 } btrfs_send_subvol; 271 272 typedef struct { 273 void* POINTER_32 parent; 274 ULONG num_clones; 275 void* POINTER_32 clones[1]; 276 } btrfs_send_subvol32; 277 278 typedef struct { 279 uint64_t device; 280 uint64_t size; 281 } btrfs_resize; 282