1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * 4 * Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved. 5 * 6 * on-disk ntfs structs 7 */ 8 9 // clang-format off 10 #ifndef _LINUX_NTFS3_NTFS_H 11 #define _LINUX_NTFS3_NTFS_H 12 13 #include <linux/blkdev.h> 14 #include <linux/build_bug.h> 15 #include <linux/kernel.h> 16 #include <linux/stddef.h> 17 #include <linux/string.h> 18 #include <linux/types.h> 19 20 #include "debug.h" 21 22 /* TODO: Check 4K MFT record and 512 bytes cluster. */ 23 24 /* Check each run for marked clusters. */ 25 #define NTFS3_CHECK_FREE_CLST 26 27 #define NTFS_NAME_LEN 255 28 29 /* 30 * ntfs.sys used 500 maximum links on-disk struct allows up to 0xffff. 31 * xfstest generic/041 creates 3003 hardlinks. 32 */ 33 #define NTFS_LINK_MAX 4000 34 35 /* 36 * Activate to use 64 bit clusters instead of 32 bits in ntfs.sys. 37 * Logical and virtual cluster number if needed, may be 38 * redefined to use 64 bit value. 39 */ 40 //#define CONFIG_NTFS3_64BIT_CLUSTER 41 42 #define NTFS_LZNT_MAX_CLUSTER 4096 43 #define NTFS_LZNT_CUNIT 4 44 #define NTFS_LZNT_CLUSTERS (1u<<NTFS_LZNT_CUNIT) 45 46 struct GUID { 47 __le32 Data1; 48 __le16 Data2; 49 __le16 Data3; 50 u8 Data4[8]; 51 }; 52 53 /* 54 * This struct repeats layout of ATTR_FILE_NAME 55 * at offset 0x40. 56 * It used to store global constants NAME_MFT/NAME_MIRROR... 57 * most constant names are shorter than 10. 58 */ 59 struct cpu_str { 60 u8 len; 61 u8 unused; 62 u16 name[]; 63 }; 64 65 struct le_str { 66 u8 len; 67 u8 unused; 68 __le16 name[]; 69 }; 70 71 static_assert(SECTOR_SHIFT == 9); 72 73 #ifdef CONFIG_NTFS3_64BIT_CLUSTER 74 typedef u64 CLST; 75 static_assert(sizeof(size_t) == 8); 76 #else 77 typedef u32 CLST; 78 #endif 79 80 /* On-disk sparsed cluster is marked as -1. */ 81 #define SPARSE_LCN64 ((u64)-1) 82 #define SPARSE_LCN ((CLST)-1) 83 /* Below is virtual (not on-disk) values. */ 84 #define RESIDENT_LCN ((CLST)-2) 85 #define COMPRESSED_LCN ((CLST)-3) 86 #define EOF_LCN ((CLST)-4) 87 #define DELALLOC_LCN ((CLST)-5) 88 89 enum RECORD_NUM { 90 MFT_REC_MFT = 0, 91 MFT_REC_MIRR = 1, 92 MFT_REC_LOG = 2, 93 MFT_REC_VOL = 3, 94 MFT_REC_ATTR = 4, 95 MFT_REC_ROOT = 5, 96 MFT_REC_BITMAP = 6, 97 MFT_REC_BOOT = 7, 98 MFT_REC_BADCLUST = 8, 99 MFT_REC_SECURE = 9, 100 MFT_REC_UPCASE = 10, 101 MFT_REC_EXTEND = 11, 102 MFT_REC_RESERVED = 12, 103 MFT_REC_FREE = 16, 104 MFT_REC_USER = 24, 105 }; 106 107 enum ATTR_TYPE { 108 ATTR_ZERO = cpu_to_le32(0x00), 109 ATTR_STD = cpu_to_le32(0x10), 110 ATTR_LIST = cpu_to_le32(0x20), 111 ATTR_NAME = cpu_to_le32(0x30), 112 ATTR_ID = cpu_to_le32(0x40), 113 ATTR_SECURE = cpu_to_le32(0x50), 114 ATTR_LABEL = cpu_to_le32(0x60), 115 ATTR_VOL_INFO = cpu_to_le32(0x70), 116 ATTR_DATA = cpu_to_le32(0x80), 117 ATTR_ROOT = cpu_to_le32(0x90), 118 ATTR_ALLOC = cpu_to_le32(0xA0), 119 ATTR_BITMAP = cpu_to_le32(0xB0), 120 ATTR_REPARSE = cpu_to_le32(0xC0), 121 ATTR_EA_INFO = cpu_to_le32(0xD0), 122 ATTR_EA = cpu_to_le32(0xE0), 123 ATTR_PROPERTYSET = cpu_to_le32(0xF0), 124 ATTR_LOGGED_UTILITY_STREAM = cpu_to_le32(0x100), 125 ATTR_END = cpu_to_le32(0xFFFFFFFF) 126 }; 127 128 static_assert(sizeof(enum ATTR_TYPE) == 4); 129 130 enum FILE_ATTRIBUTE { 131 FILE_ATTRIBUTE_READONLY = cpu_to_le32(0x00000001), 132 FILE_ATTRIBUTE_HIDDEN = cpu_to_le32(0x00000002), 133 FILE_ATTRIBUTE_SYSTEM = cpu_to_le32(0x00000004), 134 FILE_ATTRIBUTE_ARCHIVE = cpu_to_le32(0x00000020), 135 FILE_ATTRIBUTE_DEVICE = cpu_to_le32(0x00000040), 136 FILE_ATTRIBUTE_TEMPORARY = cpu_to_le32(0x00000100), 137 FILE_ATTRIBUTE_SPARSE_FILE = cpu_to_le32(0x00000200), 138 FILE_ATTRIBUTE_REPARSE_POINT = cpu_to_le32(0x00000400), 139 FILE_ATTRIBUTE_COMPRESSED = cpu_to_le32(0x00000800), 140 FILE_ATTRIBUTE_OFFLINE = cpu_to_le32(0x00001000), 141 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = cpu_to_le32(0x00002000), 142 FILE_ATTRIBUTE_ENCRYPTED = cpu_to_le32(0x00004000), 143 FILE_ATTRIBUTE_VALID_FLAGS = cpu_to_le32(0x00007fb7), 144 FILE_ATTRIBUTE_DIRECTORY = cpu_to_le32(0x10000000), 145 FILE_ATTRIBUTE_INDEX = cpu_to_le32(0x20000000) 146 }; 147 148 static_assert(sizeof(enum FILE_ATTRIBUTE) == 4); 149 150 extern const struct cpu_str NAME_MFT; 151 extern const struct cpu_str NAME_MIRROR; 152 extern const struct cpu_str NAME_LOGFILE; 153 extern const struct cpu_str NAME_VOLUME; 154 extern const struct cpu_str NAME_ATTRDEF; 155 extern const struct cpu_str NAME_ROOT; 156 extern const struct cpu_str NAME_BITMAP; 157 extern const struct cpu_str NAME_BOOT; 158 extern const struct cpu_str NAME_BADCLUS; 159 extern const struct cpu_str NAME_QUOTA; 160 extern const struct cpu_str NAME_SECURE; 161 extern const struct cpu_str NAME_UPCASE; 162 extern const struct cpu_str NAME_EXTEND; 163 extern const struct cpu_str NAME_OBJID; 164 extern const struct cpu_str NAME_REPARSE; 165 extern const struct cpu_str NAME_USNJRNL; 166 167 extern const __le16 I30_NAME[4]; 168 extern const __le16 SII_NAME[4]; 169 extern const __le16 SDH_NAME[4]; 170 extern const __le16 SO_NAME[2]; 171 extern const __le16 SQ_NAME[2]; 172 extern const __le16 SR_NAME[2]; 173 174 extern const __le16 BAD_NAME[4]; 175 extern const __le16 SDS_NAME[4]; 176 extern const __le16 WOF_NAME[17]; /* WofCompressedData */ 177 178 /* MFT record number structure. */ 179 struct MFT_REF { 180 __le32 low; // The low part of the number. 181 __le16 high; // The high part of the number. 182 __le16 seq; // The sequence number of MFT record. 183 }; 184 185 static_assert(sizeof(__le64) == sizeof(struct MFT_REF)); 186 187 static inline CLST ino_get(const struct MFT_REF *ref) 188 { 189 #ifdef CONFIG_NTFS3_64BIT_CLUSTER 190 return le32_to_cpu(ref->low) | ((u64)le16_to_cpu(ref->high) << 32); 191 #else 192 return le32_to_cpu(ref->low); 193 #endif 194 } 195 196 struct NTFS_BOOT { 197 u8 jump_code[3]; // 0x00: Jump to boot code. 198 u8 system_id[8]; // 0x03: System ID, equals "NTFS " 199 200 // NOTE: This member is not aligned(!) 201 // bytes_per_sector[0] must be 0. 202 // bytes_per_sector[1] must be multiplied by 256. 203 u8 bytes_per_sector[2]; // 0x0B: Bytes per sector. 204 205 u8 sectors_per_clusters;// 0x0D: Sectors per cluster. 206 u8 unused1[7]; 207 u8 media_type; // 0x15: Media type (0xF8 - harddisk) 208 u8 unused2[2]; 209 __le16 sct_per_track; // 0x18: number of sectors per track. 210 __le16 heads; // 0x1A: number of heads per cylinder. 211 __le32 hidden_sectors; // 0x1C: number of 'hidden' sectors. 212 u8 unused3[4]; 213 u8 bios_drive_num; // 0x24: BIOS drive number =0x80. 214 u8 unused4; 215 u8 signature_ex; // 0x26: Extended BOOT signature =0x80. 216 u8 unused5; 217 __le64 sectors_per_volume;// 0x28: Size of volume in sectors. 218 __le64 mft_clst; // 0x30: First cluster of $MFT 219 __le64 mft2_clst; // 0x38: First cluster of $MFTMirr 220 s8 record_size; // 0x40: Size of MFT record in clusters(sectors). 221 u8 unused6[3]; 222 s8 index_size; // 0x44: Size of INDX record in clusters(sectors). 223 u8 unused7[3]; 224 __le64 serial_num; // 0x48: Volume serial number 225 __le32 check_sum; // 0x50: Simple additive checksum of all 226 // of the u32's which precede the 'check_sum'. 227 228 u8 boot_code[0x200 - 0x50 - 2 - 4]; // 0x54: 229 u8 boot_magic[2]; // 0x1FE: Boot signature =0x55 + 0xAA 230 }; 231 232 static_assert(sizeof(struct NTFS_BOOT) == 0x200); 233 234 enum NTFS_SIGNATURE { 235 NTFS_FILE_SIGNATURE = cpu_to_le32(0x454C4946), // 'FILE' 236 NTFS_INDX_SIGNATURE = cpu_to_le32(0x58444E49), // 'INDX' 237 NTFS_CHKD_SIGNATURE = cpu_to_le32(0x444B4843), // 'CHKD' 238 NTFS_RSTR_SIGNATURE = cpu_to_le32(0x52545352), // 'RSTR' 239 NTFS_RCRD_SIGNATURE = cpu_to_le32(0x44524352), // 'RCRD' 240 NTFS_BAAD_SIGNATURE = cpu_to_le32(0x44414142), // 'BAAD' 241 NTFS_HOLE_SIGNATURE = cpu_to_le32(0x454C4F48), // 'HOLE' 242 NTFS_FFFF_SIGNATURE = cpu_to_le32(0xffffffff), 243 }; 244 245 static_assert(sizeof(enum NTFS_SIGNATURE) == 4); 246 247 /* MFT Record header structure. */ 248 struct NTFS_RECORD_HEADER { 249 /* Record magic number, equals 'FILE'/'INDX'/'RSTR'/'RCRD'. */ 250 enum NTFS_SIGNATURE sign; // 0x00: 251 __le16 fix_off; // 0x04: 252 __le16 fix_num; // 0x06: 253 __le64 lsn; // 0x08: Log file sequence number, 254 }; 255 256 static_assert(sizeof(struct NTFS_RECORD_HEADER) == 0x10); 257 258 static inline int is_baad(const struct NTFS_RECORD_HEADER *hdr) 259 { 260 return hdr->sign == NTFS_BAAD_SIGNATURE; 261 } 262 263 /* Possible bits in struct MFT_REC.flags. */ 264 enum RECORD_FLAG { 265 RECORD_FLAG_IN_USE = cpu_to_le16(0x0001), 266 RECORD_FLAG_DIR = cpu_to_le16(0x0002), 267 RECORD_FLAG_SYSTEM = cpu_to_le16(0x0004), 268 RECORD_FLAG_INDEX = cpu_to_le16(0x0008), 269 }; 270 271 /* MFT Record structure. */ 272 struct MFT_REC { 273 struct NTFS_RECORD_HEADER rhdr; // 'FILE' 274 275 __le16 seq; // 0x10: Sequence number for this record. 276 __le16 hard_links; // 0x12: The number of hard links to record. 277 __le16 attr_off; // 0x14: Offset to attributes. 278 __le16 flags; // 0x16: See RECORD_FLAG. 279 __le32 used; // 0x18: The size of used part. 280 __le32 total; // 0x1C: Total record size. 281 282 struct MFT_REF parent_ref; // 0x20: Parent MFT record. 283 __le16 next_attr_id; // 0x28: The next attribute Id. 284 285 __le16 res; // 0x2A: High part of MFT record? 286 __le32 mft_record; // 0x2C: Current MFT record number. 287 __le16 fixups[]; // 0x30: 288 }; 289 290 #define MFTRECORD_FIXUP_OFFSET_1 offsetof(struct MFT_REC, res) 291 #define MFTRECORD_FIXUP_OFFSET_3 offsetof(struct MFT_REC, fixups) 292 /* 293 * define MFTRECORD_FIXUP_OFFSET as MFTRECORD_FIXUP_OFFSET_3 (0x30) 294 * to format new mft records with bigger header (as current ntfs.sys does) 295 * 296 * define MFTRECORD_FIXUP_OFFSET as MFTRECORD_FIXUP_OFFSET_1 (0x2A) 297 * to format new mft records with smaller header (as old ntfs.sys did) 298 * Both variants are valid. 299 */ 300 #define MFTRECORD_FIXUP_OFFSET MFTRECORD_FIXUP_OFFSET_1 301 302 static_assert(MFTRECORD_FIXUP_OFFSET_1 == 0x2A); 303 static_assert(MFTRECORD_FIXUP_OFFSET_3 == 0x30); 304 305 static inline bool is_rec_base(const struct MFT_REC *rec) 306 { 307 const struct MFT_REF *r = &rec->parent_ref; 308 309 return !r->low && !r->high && !r->seq; 310 } 311 312 static inline bool is_mft_rec5(const struct MFT_REC *rec) 313 { 314 return le16_to_cpu(rec->rhdr.fix_off) >= 315 offsetof(struct MFT_REC, fixups); 316 } 317 318 static inline bool is_rec_inuse(const struct MFT_REC *rec) 319 { 320 return rec->flags & RECORD_FLAG_IN_USE; 321 } 322 323 static inline bool clear_rec_inuse(struct MFT_REC *rec) 324 { 325 return rec->flags &= ~RECORD_FLAG_IN_USE; 326 } 327 328 /* Possible values of ATTR_RESIDENT.flags */ 329 #define RESIDENT_FLAG_INDEXED 0x01 330 331 struct ATTR_RESIDENT { 332 __le32 data_size; // 0x10: The size of data. 333 __le16 data_off; // 0x14: Offset to data. 334 u8 flags; // 0x16: Resident flags ( 1 - indexed ). 335 u8 res; // 0x17: 336 }; // sizeof() = 0x18 337 338 struct ATTR_NONRESIDENT { 339 __le64 svcn; // 0x10: Starting VCN of this segment. 340 __le64 evcn; // 0x18: End VCN of this segment. 341 __le16 run_off; // 0x20: Offset to packed runs. 342 // Unit of Compression size for this stream, expressed 343 // as a log of the cluster size. 344 // 345 // 0 means file is not compressed 346 // 1, 2, 3, and 4 are potentially legal values if the 347 // stream is compressed, however the implementation 348 // may only choose to use 4, or possibly 3. 349 // Note that 4 means cluster size time 16. 350 // If convenient the implementation may wish to accept a 351 // reasonable range of legal values here (1-5?), 352 // even if the implementation only generates 353 // a smaller set of values itself. 354 u8 c_unit; // 0x22: 355 u8 res1[5]; // 0x23: 356 __le64 alloc_size; // 0x28: The allocated size of attribute in bytes. 357 // (multiple of cluster size) 358 __le64 data_size; // 0x30: The size of attribute in bytes <= alloc_size. 359 __le64 valid_size; // 0x38: The size of valid part in bytes <= data_size. 360 __le64 total_size; // 0x40: The sum of the allocated clusters for a file. 361 // (present only for the first segment (0 == vcn) 362 // of compressed attribute) 363 364 }; // sizeof()=0x40 or 0x48 (if compressed) 365 366 /* Possible values of ATTRIB.flags: */ 367 #define ATTR_FLAG_COMPRESSED cpu_to_le16(0x0001) 368 #define ATTR_FLAG_COMPRESSED_MASK cpu_to_le16(0x00FF) 369 #define ATTR_FLAG_ENCRYPTED cpu_to_le16(0x4000) 370 #define ATTR_FLAG_SPARSED cpu_to_le16(0x8000) 371 372 struct ATTRIB { 373 enum ATTR_TYPE type; // 0x00: The type of this attribute. 374 __le32 size; // 0x04: The size of this attribute. 375 u8 non_res; // 0x08: Is this attribute non-resident? 376 u8 name_len; // 0x09: This attribute name length. 377 __le16 name_off; // 0x0A: Offset to the attribute name. 378 __le16 flags; // 0x0C: See ATTR_FLAG_XXX. 379 __le16 id; // 0x0E: Unique id (per record). 380 381 union { 382 struct ATTR_RESIDENT res; // 0x10 383 struct ATTR_NONRESIDENT nres; // 0x10 384 }; 385 }; 386 387 /* Define attribute sizes. */ 388 #define SIZEOF_RESIDENT 0x18 389 #define SIZEOF_NONRESIDENT_EX 0x48 390 #define SIZEOF_NONRESIDENT 0x40 391 392 #define SIZEOF_RESIDENT_LE cpu_to_le16(0x18) 393 #define SIZEOF_NONRESIDENT_EX_LE cpu_to_le16(0x48) 394 #define SIZEOF_NONRESIDENT_LE cpu_to_le16(0x40) 395 396 static inline u64 attr_ondisk_size(const struct ATTRIB *attr) 397 { 398 return attr->non_res ? ((attr->flags & 399 (ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED)) ? 400 le64_to_cpu(attr->nres.total_size) : 401 le64_to_cpu(attr->nres.alloc_size)) 402 : ALIGN(le32_to_cpu(attr->res.data_size), 8); 403 } 404 405 static inline u64 attr_size(const struct ATTRIB *attr) 406 { 407 return attr->non_res ? le64_to_cpu(attr->nres.data_size) : 408 le32_to_cpu(attr->res.data_size); 409 } 410 411 static inline bool is_attr_encrypted(const struct ATTRIB *attr) 412 { 413 return attr->flags & ATTR_FLAG_ENCRYPTED; 414 } 415 416 static inline bool is_attr_sparsed(const struct ATTRIB *attr) 417 { 418 return attr->flags & ATTR_FLAG_SPARSED; 419 } 420 421 static inline bool is_attr_compressed(const struct ATTRIB *attr) 422 { 423 return attr->flags & ATTR_FLAG_COMPRESSED; 424 } 425 426 static inline bool is_attr_ext(const struct ATTRIB *attr) 427 { 428 return attr->flags & (ATTR_FLAG_SPARSED | ATTR_FLAG_COMPRESSED); 429 } 430 431 static inline bool is_attr_indexed(const struct ATTRIB *attr) 432 { 433 return !attr->non_res && (attr->res.flags & RESIDENT_FLAG_INDEXED); 434 } 435 436 static inline __le16 const *attr_name(const struct ATTRIB *attr) 437 { 438 return Add2Ptr(attr, le16_to_cpu(attr->name_off)); 439 } 440 441 static inline u64 attr_svcn(const struct ATTRIB *attr) 442 { 443 return attr->non_res ? le64_to_cpu(attr->nres.svcn) : 0; 444 } 445 446 static_assert(sizeof(struct ATTRIB) == 0x48); 447 static_assert(sizeof(((struct ATTRIB *)NULL)->res) == 0x08); 448 static_assert(sizeof(((struct ATTRIB *)NULL)->nres) == 0x38); 449 450 static inline void *resident_data_ex(const struct ATTRIB *attr, u32 datasize) 451 { 452 u32 asize, rsize; 453 u16 off; 454 455 if (attr->non_res) 456 return NULL; 457 458 asize = le32_to_cpu(attr->size); 459 off = le16_to_cpu(attr->res.data_off); 460 461 if (asize < datasize + off) 462 return NULL; 463 464 rsize = le32_to_cpu(attr->res.data_size); 465 if (rsize < datasize) 466 return NULL; 467 468 return Add2Ptr(attr, off); 469 } 470 471 static inline void *resident_data(const struct ATTRIB *attr) 472 { 473 return Add2Ptr(attr, le16_to_cpu(attr->res.data_off)); 474 } 475 476 static inline void *attr_run(const struct ATTRIB *attr) 477 { 478 return Add2Ptr(attr, le16_to_cpu(attr->nres.run_off)); 479 } 480 481 /* Standard information attribute (0x10). */ 482 struct ATTR_STD_INFO { 483 __le64 cr_time; // 0x00: File creation file. 484 __le64 m_time; // 0x08: File modification time. 485 __le64 c_time; // 0x10: Last time any attribute was modified. 486 __le64 a_time; // 0x18: File last access time. 487 enum FILE_ATTRIBUTE fa; // 0x20: Standard DOS attributes & more. 488 __le32 max_ver_num; // 0x24: Maximum Number of Versions. 489 __le32 ver_num; // 0x28: Version Number. 490 __le32 class_id; // 0x2C: Class Id from bidirectional Class Id index. 491 }; 492 493 static_assert(sizeof(struct ATTR_STD_INFO) == 0x30); 494 495 #define SECURITY_ID_INVALID 0x00000000 496 #define SECURITY_ID_FIRST 0x00000100 497 498 struct ATTR_STD_INFO5 { 499 __le64 cr_time; // 0x00: File creation file. 500 __le64 m_time; // 0x08: File modification time. 501 __le64 c_time; // 0x10: Last time any attribute was modified. 502 __le64 a_time; // 0x18: File last access time. 503 enum FILE_ATTRIBUTE fa; // 0x20: Standard DOS attributes & more. 504 __le32 max_ver_num; // 0x24: Maximum Number of Versions. 505 __le32 ver_num; // 0x28: Version Number. 506 __le32 class_id; // 0x2C: Class Id from bidirectional Class Id index. 507 508 __le32 owner_id; // 0x30: Owner Id of the user owning the file. 509 __le32 security_id; // 0x34: The Security Id is a key in the $SII Index and $SDS. 510 __le64 quota_charge; // 0x38: 511 __le64 usn; // 0x40: Last Update Sequence Number of the file. This is a direct 512 // index into the file $UsnJrnl. If zero, the USN Journal is 513 // disabled. 514 }; 515 516 static_assert(sizeof(struct ATTR_STD_INFO5) == 0x48); 517 518 /* Attribute list entry structure (0x20) */ 519 struct ATTR_LIST_ENTRY { 520 enum ATTR_TYPE type; // 0x00: The type of attribute. 521 __le16 size; // 0x04: The size of this record. 522 u8 name_len; // 0x06: The length of attribute name. 523 u8 name_off; // 0x07: The offset to attribute name. 524 __le64 vcn; // 0x08: Starting VCN of this attribute. 525 struct MFT_REF ref; // 0x10: MFT record number with attribute. 526 __le16 id; // 0x18: struct ATTRIB ID. 527 __le16 name[]; // 0x1A: To get real name use name_off. 528 529 }; // sizeof(0x20) 530 531 static inline u32 le_size(u8 name_len) 532 { 533 return ALIGN(offsetof(struct ATTR_LIST_ENTRY, name) + 534 name_len * sizeof(short), 8); 535 } 536 537 /* Returns 0 if 'attr' has the same type and name. */ 538 static inline int le_cmp(const struct ATTR_LIST_ENTRY *le, 539 const struct ATTRIB *attr) 540 { 541 return le->type != attr->type || le->name_len != attr->name_len || 542 (!le->name_len && 543 memcmp(Add2Ptr(le, le->name_off), 544 Add2Ptr(attr, le16_to_cpu(attr->name_off)), 545 le->name_len * sizeof(short))); 546 } 547 548 static inline __le16 const *le_name(const struct ATTR_LIST_ENTRY *le) 549 { 550 return Add2Ptr(le, le->name_off); 551 } 552 553 /* File name types (the field type in struct ATTR_FILE_NAME). */ 554 #define FILE_NAME_POSIX 0 555 #define FILE_NAME_UNICODE 1 556 #define FILE_NAME_DOS 2 557 #define FILE_NAME_UNICODE_AND_DOS (FILE_NAME_DOS | FILE_NAME_UNICODE) 558 559 /* Filename attribute structure (0x30). */ 560 struct NTFS_DUP_INFO { 561 __le64 cr_time; // 0x00: File creation file. 562 __le64 m_time; // 0x08: File modification time. 563 __le64 c_time; // 0x10: Last time any attribute was modified. 564 __le64 a_time; // 0x18: File last access time. 565 __le64 alloc_size; // 0x20: Data attribute allocated size, multiple of cluster size. 566 __le64 data_size; // 0x28: Data attribute size <= Dataalloc_size. 567 enum FILE_ATTRIBUTE fa; // 0x30: Standard DOS attributes & more. 568 __le32 extend_data; // 0x34: Extended data. 569 570 }; // 0x38 571 572 struct ATTR_FILE_NAME { 573 struct MFT_REF home; // 0x00: MFT record for directory. 574 struct NTFS_DUP_INFO dup;// 0x08: 575 u8 name_len; // 0x40: File name length in words. 576 u8 type; // 0x41: File name type. 577 __le16 name[]; // 0x42: File name. 578 }; 579 580 static_assert(sizeof(((struct ATTR_FILE_NAME *)NULL)->dup) == 0x38); 581 static_assert(offsetof(struct ATTR_FILE_NAME, name) == 0x42); 582 #define SIZEOF_ATTRIBUTE_FILENAME 0x44 583 #define SIZEOF_ATTRIBUTE_FILENAME_MAX (0x42 + 255 * 2) 584 585 static inline struct ATTRIB *attr_from_name(struct ATTR_FILE_NAME *fname) 586 { 587 return (struct ATTRIB *)((char *)fname - SIZEOF_RESIDENT); 588 } 589 590 static inline u16 fname_full_size(const struct ATTR_FILE_NAME *fname) 591 { 592 /* Don't return struct_size(fname, name, fname->name_len); */ 593 return offsetof(struct ATTR_FILE_NAME, name) + 594 fname->name_len * sizeof(short); 595 } 596 597 static inline u8 paired_name(u8 type) 598 { 599 if (type == FILE_NAME_UNICODE) 600 return FILE_NAME_DOS; 601 if (type == FILE_NAME_DOS) 602 return FILE_NAME_UNICODE; 603 return FILE_NAME_POSIX; 604 } 605 606 /* Index entry defines ( the field flags in NtfsDirEntry ). */ 607 #define NTFS_IE_HAS_SUBNODES cpu_to_le16(1) 608 #define NTFS_IE_LAST cpu_to_le16(2) 609 610 /* Directory entry structure. */ 611 struct NTFS_DE { 612 union { 613 struct MFT_REF ref; // 0x00: MFT record number with this file. 614 struct { 615 __le16 data_off; // 0x00: 616 __le16 data_size; // 0x02: 617 __le32 res; // 0x04: Must be 0. 618 } view; 619 }; 620 __le16 size; // 0x08: The size of this entry. 621 __le16 key_size; // 0x0A: The size of File name length in bytes + 0x42. 622 __le16 flags; // 0x0C: Entry flags: NTFS_IE_XXX. 623 __le16 res; // 0x0E: 624 625 // Here any indexed attribute can be placed. 626 // One of them is: 627 // struct ATTR_FILE_NAME AttrFileName; 628 // 629 630 // The last 8 bytes of this structure contains 631 // the VBN of subnode. 632 // !!! Note !!! 633 // This field is presented only if (flags & NTFS_IE_HAS_SUBNODES) 634 // __le64 vbn; 635 }; 636 637 static_assert(sizeof(struct NTFS_DE) == 0x10); 638 639 static inline void de_set_vbn_le(struct NTFS_DE *e, __le64 vcn) 640 { 641 __le64 *v = Add2Ptr(e, le16_to_cpu(e->size) - sizeof(__le64)); 642 643 *v = vcn; 644 } 645 646 static inline void de_set_vbn(struct NTFS_DE *e, CLST vcn) 647 { 648 __le64 *v = Add2Ptr(e, le16_to_cpu(e->size) - sizeof(__le64)); 649 650 *v = cpu_to_le64(vcn); 651 } 652 653 static inline __le64 de_get_vbn_le(const struct NTFS_DE *e) 654 { 655 return *(__le64 *)Add2Ptr(e, le16_to_cpu(e->size) - sizeof(__le64)); 656 } 657 658 static inline CLST de_get_vbn(const struct NTFS_DE *e) 659 { 660 __le64 *v = Add2Ptr(e, le16_to_cpu(e->size) - sizeof(__le64)); 661 662 return le64_to_cpu(*v); 663 } 664 665 static inline struct NTFS_DE *de_get_next(const struct NTFS_DE *e) 666 { 667 return Add2Ptr(e, le16_to_cpu(e->size)); 668 } 669 670 static inline struct ATTR_FILE_NAME *de_get_fname(const struct NTFS_DE *e) 671 { 672 return le16_to_cpu(e->key_size) >= SIZEOF_ATTRIBUTE_FILENAME ? 673 Add2Ptr(e, sizeof(struct NTFS_DE)) : 674 NULL; 675 } 676 677 static inline bool de_is_last(const struct NTFS_DE *e) 678 { 679 return e->flags & NTFS_IE_LAST; 680 } 681 682 static inline bool de_has_vcn(const struct NTFS_DE *e) 683 { 684 return e->flags & NTFS_IE_HAS_SUBNODES; 685 } 686 687 static inline bool de_has_vcn_ex(const struct NTFS_DE *e) 688 { 689 return (e->flags & NTFS_IE_HAS_SUBNODES) && 690 (u64)(-1) != *((u64 *)Add2Ptr(e, le16_to_cpu(e->size) - 691 sizeof(__le64))); 692 } 693 694 #define MAX_BYTES_PER_NAME_ENTRY \ 695 ALIGN(sizeof(struct NTFS_DE) + \ 696 offsetof(struct ATTR_FILE_NAME, name) + \ 697 NTFS_NAME_LEN * sizeof(short), 8) 698 699 #define NTFS_INDEX_HDR_HAS_SUBNODES cpu_to_le32(1) 700 701 struct INDEX_HDR { 702 __le32 de_off; // 0x00: The offset from the start of this structure 703 // to the first NTFS_DE. 704 __le32 used; // 0x04: The size of this structure plus all 705 // entries (quad-word aligned). 706 __le32 total; // 0x08: The allocated size of for this structure plus all entries. 707 __le32 flags; // 0x0C: 0x00 = Small directory, 0x01 = Large directory. 708 709 // 710 // de_off + used <= total 711 // 712 }; 713 714 static_assert(sizeof(struct INDEX_HDR) == 0x10); 715 716 static inline struct NTFS_DE *hdr_first_de(const struct INDEX_HDR *hdr) 717 { 718 u32 de_off = le32_to_cpu(hdr->de_off); 719 u32 used = le32_to_cpu(hdr->used); 720 struct NTFS_DE *e; 721 u16 esize; 722 723 if (de_off >= used || size_add(de_off, sizeof(struct NTFS_DE)) > used) 724 return NULL; 725 726 e = Add2Ptr(hdr, de_off); 727 esize = le16_to_cpu(e->size); 728 if (esize < sizeof(struct NTFS_DE) || de_off + esize > used) 729 return NULL; 730 731 return e; 732 } 733 734 static inline struct NTFS_DE *hdr_next_de(const struct INDEX_HDR *hdr, 735 const struct NTFS_DE *e) 736 { 737 size_t off = PtrOffset(hdr, e); 738 u32 used = le32_to_cpu(hdr->used); 739 u16 esize; 740 741 if (off >= used) 742 return NULL; 743 744 esize = le16_to_cpu(e->size); 745 746 if (esize < sizeof(struct NTFS_DE) || 747 off + esize + sizeof(struct NTFS_DE) > used) 748 return NULL; 749 750 return Add2Ptr(e, esize); 751 } 752 753 static inline bool hdr_has_subnode(const struct INDEX_HDR *hdr) 754 { 755 return hdr->flags & NTFS_INDEX_HDR_HAS_SUBNODES; 756 } 757 758 struct INDEX_BUFFER { 759 struct NTFS_RECORD_HEADER rhdr; // 'INDX' 760 __le64 vbn; // 0x10: vcn if index >= cluster or vsn id index < cluster 761 struct INDEX_HDR ihdr; // 0x18: 762 }; 763 764 static_assert(sizeof(struct INDEX_BUFFER) == 0x28); 765 766 static inline bool ib_is_empty(const struct INDEX_BUFFER *ib) 767 { 768 const struct NTFS_DE *first = hdr_first_de(&ib->ihdr); 769 770 return !first || de_is_last(first); 771 } 772 773 static inline bool ib_is_leaf(const struct INDEX_BUFFER *ib) 774 { 775 return !(ib->ihdr.flags & NTFS_INDEX_HDR_HAS_SUBNODES); 776 } 777 778 /* Index root structure ( 0x90 ). */ 779 enum COLLATION_RULE { 780 NTFS_COLLATION_TYPE_BINARY = cpu_to_le32(0), 781 // $I30 782 NTFS_COLLATION_TYPE_FILENAME = cpu_to_le32(0x01), 783 // $SII of $Secure and $Q of Quota 784 NTFS_COLLATION_TYPE_UINT = cpu_to_le32(0x10), 785 // $O of Quota 786 NTFS_COLLATION_TYPE_SID = cpu_to_le32(0x11), 787 // $SDH of $Secure 788 NTFS_COLLATION_TYPE_SECURITY_HASH = cpu_to_le32(0x12), 789 // $O of ObjId and "$R" for Reparse 790 NTFS_COLLATION_TYPE_UINTS = cpu_to_le32(0x13) 791 }; 792 793 static_assert(sizeof(enum COLLATION_RULE) == 4); 794 795 // 796 struct INDEX_ROOT { 797 enum ATTR_TYPE type; // 0x00: The type of attribute to index on. 798 enum COLLATION_RULE rule; // 0x04: The rule. 799 __le32 index_block_size;// 0x08: The size of index record. 800 u8 index_block_clst; // 0x0C: The number of clusters or sectors per index. 801 u8 res[3]; 802 struct INDEX_HDR ihdr; // 0x10: 803 }; 804 805 static_assert(sizeof(struct INDEX_ROOT) == 0x20); 806 static_assert(offsetof(struct INDEX_ROOT, ihdr) == 0x10); 807 808 #define VOLUME_FLAG_DIRTY cpu_to_le16(0x0001) 809 #define VOLUME_FLAG_RESIZE_LOG_FILE cpu_to_le16(0x0002) 810 811 struct VOLUME_INFO { 812 __le64 res1; // 0x00 813 u8 major_ver; // 0x08: NTFS major version number (before .) 814 u8 minor_ver; // 0x09: NTFS minor version number (after .) 815 __le16 flags; // 0x0A: Volume flags, see VOLUME_FLAG_XXX 816 817 }; // sizeof=0xC 818 819 #define SIZEOF_ATTRIBUTE_VOLUME_INFO 0xc 820 821 #define NTFS_LABEL_MAX_LENGTH (0x100 / sizeof(short)) 822 #define NTFS_ATTR_INDEXABLE cpu_to_le32(0x00000002) 823 #define NTFS_ATTR_DUPALLOWED cpu_to_le32(0x00000004) 824 #define NTFS_ATTR_MUST_BE_INDEXED cpu_to_le32(0x00000010) 825 #define NTFS_ATTR_MUST_BE_NAMED cpu_to_le32(0x00000020) 826 #define NTFS_ATTR_MUST_BE_RESIDENT cpu_to_le32(0x00000040) 827 #define NTFS_ATTR_LOG_ALWAYS cpu_to_le32(0x00000080) 828 829 /* $AttrDef file entry. */ 830 struct ATTR_DEF_ENTRY { 831 __le16 name[0x40]; // 0x00: Attr name. 832 enum ATTR_TYPE type; // 0x80: struct ATTRIB type. 833 __le32 res; // 0x84: 834 enum COLLATION_RULE rule; // 0x88: 835 __le32 flags; // 0x8C: NTFS_ATTR_XXX (see above). 836 __le64 min_sz; // 0x90: Minimum attribute data size. 837 __le64 max_sz; // 0x98: Maximum attribute data size. 838 }; 839 840 static_assert(sizeof(struct ATTR_DEF_ENTRY) == 0xa0); 841 842 /* Object ID (0x40) */ 843 struct OBJECT_ID { 844 struct GUID ObjId; // 0x00: Unique Id assigned to file. 845 846 // Birth Volume Id is the Object Id of the Volume on. 847 // which the Object Id was allocated. It never changes. 848 struct GUID BirthVolumeId; //0x10: 849 850 // Birth Object Id is the first Object Id that was 851 // ever assigned to this MFT Record. I.e. If the Object Id 852 // is changed for some reason, this field will reflect the 853 // original value of the Object Id. 854 struct GUID BirthObjectId; // 0x20: 855 856 // Domain Id is currently unused but it is intended to be 857 // used in a network environment where the local machine is 858 // part of a Windows 2000 Domain. This may be used in a Windows 859 // 2000 Advanced Server managed domain. 860 struct GUID DomainId; // 0x30: 861 }; 862 863 static_assert(sizeof(struct OBJECT_ID) == 0x40); 864 865 /* O Directory entry structure ( rule = 0x13 ) */ 866 struct NTFS_DE_O { 867 struct NTFS_DE de; 868 struct GUID ObjId; // 0x10: Unique Id assigned to file. 869 struct MFT_REF ref; // 0x20: MFT record number with this file. 870 871 // Birth Volume Id is the Object Id of the Volume on 872 // which the Object Id was allocated. It never changes. 873 struct GUID BirthVolumeId; // 0x28: 874 875 // Birth Object Id is the first Object Id that was 876 // ever assigned to this MFT Record. I.e. If the Object Id 877 // is changed for some reason, this field will reflect the 878 // original value of the Object Id. 879 // This field is valid if data_size == 0x48. 880 struct GUID BirthObjectId; // 0x38: 881 882 // Domain Id is currently unused but it is intended 883 // to be used in a network environment where the local 884 // machine is part of a Windows 2000 Domain. This may be 885 // used in a Windows 2000 Advanced Server managed domain. 886 struct GUID BirthDomainId; // 0x48: 887 }; 888 889 static_assert(sizeof(struct NTFS_DE_O) == 0x58); 890 891 /* Q Directory entry structure ( rule = 0x11 ) */ 892 struct NTFS_DE_Q { 893 struct NTFS_DE de; 894 __le32 owner_id; // 0x10: Unique Id assigned to file 895 896 /* here is 0x30 bytes of user quota. NOTE: 4 byte aligned! */ 897 __le32 Version; // 0x14: 0x02 898 __le32 Flags; // 0x18: Quota flags, see above 899 __le64 BytesUsed; // 0x1C: 900 __le64 ChangeTime; // 0x24: 901 __le64 WarningLimit; // 0x28: 902 __le64 HardLimit; // 0x34: 903 __le64 ExceededTime; // 0x3C: 904 905 // SID is placed here 906 }__packed; // sizeof() = 0x44 907 908 static_assert(sizeof(struct NTFS_DE_Q) == 0x44); 909 910 #define SecurityDescriptorsBlockSize 0x40000 // 256K 911 #define SecurityDescriptorMaxSize 0x20000 // 128K 912 #define Log2OfSecurityDescriptorsBlockSize 18 913 914 struct SECURITY_KEY { 915 __le32 hash; // Hash value for descriptor 916 __le32 sec_id; // Security Id (guaranteed unique) 917 }; 918 919 /* Security descriptors (the content of $Secure::SDS data stream) */ 920 struct SECURITY_HDR { 921 struct SECURITY_KEY key; // 0x00: Security Key. 922 __le64 off; // 0x08: Offset of this entry in the file. 923 __le32 size; // 0x10: Size of this entry, 8 byte aligned. 924 /* 925 * Security descriptor itself is placed here. 926 * Total size is 16 byte aligned. 927 */ 928 } __packed; 929 930 static_assert(sizeof(struct SECURITY_HDR) == 0x14); 931 932 /* SII Directory entry structure */ 933 struct NTFS_DE_SII { 934 struct NTFS_DE de; 935 __le32 sec_id; // 0x10: Key: sizeof(security_id) = wKeySize 936 struct SECURITY_HDR sec_hdr; // 0x14: 937 } __packed; 938 939 static_assert(offsetof(struct NTFS_DE_SII, sec_hdr) == 0x14); 940 static_assert(sizeof(struct NTFS_DE_SII) == 0x28); 941 942 /* SDH Directory entry structure */ 943 struct NTFS_DE_SDH { 944 struct NTFS_DE de; 945 struct SECURITY_KEY key; // 0x10: Key 946 struct SECURITY_HDR sec_hdr; // 0x18: Data 947 __le16 magic[2]; // 0x2C: 0x00490049 "I I" 948 }; 949 950 #define SIZEOF_SDH_DIRENTRY 0x30 951 952 struct REPARSE_KEY { 953 __le32 ReparseTag; // 0x00: Reparse Tag 954 struct MFT_REF ref; // 0x04: MFT record number with this file 955 }; // sizeof() = 0x0C 956 957 static_assert(offsetof(struct REPARSE_KEY, ref) == 0x04); 958 #define SIZEOF_REPARSE_KEY 0x0C 959 960 /* Reparse Directory entry structure */ 961 struct NTFS_DE_R { 962 struct NTFS_DE de; 963 struct REPARSE_KEY key; // 0x10: Reparse Key. 964 u32 zero; // 0x1c: 965 }; // sizeof() = 0x20 966 967 static_assert(sizeof(struct NTFS_DE_R) == 0x20); 968 969 /* CompressReparseBuffer.WofVersion */ 970 #define WOF_CURRENT_VERSION cpu_to_le32(1) 971 /* CompressReparseBuffer.WofProvider */ 972 #define WOF_PROVIDER_WIM cpu_to_le32(1) 973 /* CompressReparseBuffer.WofProvider */ 974 #define WOF_PROVIDER_SYSTEM cpu_to_le32(2) 975 /* CompressReparseBuffer.ProviderVer */ 976 #define WOF_PROVIDER_CURRENT_VERSION cpu_to_le32(1) 977 978 #define WOF_COMPRESSION_XPRESS4K cpu_to_le32(0) // 4k 979 #define WOF_COMPRESSION_LZX32K cpu_to_le32(1) // 32k 980 #define WOF_COMPRESSION_XPRESS8K cpu_to_le32(2) // 8k 981 #define WOF_COMPRESSION_XPRESS16K cpu_to_le32(3) // 16k 982 983 /* 984 * ATTR_REPARSE (0xC0) 985 * 986 * The reparse struct GUID structure is used by all 3rd party layered drivers to 987 * store data in a reparse point. For non-Microsoft tags, The struct GUID field 988 * cannot be GUID_NULL. 989 * The constraints on reparse tags are defined below. 990 * Microsoft tags can also be used with this format of the reparse point buffer. 991 */ 992 struct REPARSE_POINT { 993 __le32 ReparseTag; // 0x00: 994 __le16 ReparseDataLength;// 0x04: 995 __le16 Reserved; 996 997 struct GUID Guid; // 0x08: 998 999 // 1000 // Here GenericReparseBuffer is placed 1001 // 1002 }; 1003 1004 static_assert(sizeof(struct REPARSE_POINT) == 0x18); 1005 1006 /* 1007 * The value of the following constant needs to satisfy the following 1008 * conditions: 1009 * (1) Be at least as large as the largest of the reserved tags. 1010 * (2) Be strictly smaller than all the tags in use. 1011 */ 1012 #define IO_REPARSE_TAG_RESERVED_RANGE 1 1013 1014 /* 1015 * The reparse tags are a ULONG. The 32 bits are laid out as follows: 1016 * 1017 * 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1018 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 1019 * +-+-+-+-+-----------------------+-------------------------------+ 1020 * |M|R|N|R| Reserved bits | Reparse Tag Value | 1021 * +-+-+-+-+-----------------------+-------------------------------+ 1022 * 1023 * M is the Microsoft bit. When set to 1, it denotes a tag owned by Microsoft. 1024 * All ISVs must use a tag with a 0 in this position. 1025 * Note: If a Microsoft tag is used by non-Microsoft software, the 1026 * behavior is not defined. 1027 * 1028 * R is reserved. Must be zero for non-Microsoft tags. 1029 * 1030 * N is name surrogate. When set to 1, the file represents another named 1031 * entity in the system. 1032 * 1033 * The M and N bits are OR-able. 1034 * The following macros check for the M and N bit values: 1035 */ 1036 1037 /* 1038 * Macro to determine whether a reparse point tag corresponds to a tag 1039 * owned by Microsoft. 1040 */ 1041 #define IsReparseTagMicrosoft(_tag) (((_tag)&IO_REPARSE_TAG_MICROSOFT)) 1042 1043 /* Macro to determine whether a reparse point tag is a name surrogate. */ 1044 #define IsReparseTagNameSurrogate(_tag) (((_tag)&IO_REPARSE_TAG_NAME_SURROGATE)) 1045 1046 /* 1047 * The following constant represents the bits that are valid to use in 1048 * reparse tags. 1049 */ 1050 #define IO_REPARSE_TAG_VALID_VALUES 0xF000FFFF 1051 1052 /* 1053 * Macro to determine whether a reparse tag is a valid tag. 1054 */ 1055 #define IsReparseTagValid(_tag) \ 1056 (!((_tag) & ~IO_REPARSE_TAG_VALID_VALUES) && \ 1057 ((_tag) > IO_REPARSE_TAG_RESERVED_RANGE)) 1058 1059 /* Microsoft tags for reparse points. */ 1060 1061 enum IO_REPARSE_TAG { 1062 IO_REPARSE_TAG_SYMBOLIC_LINK = cpu_to_le32(0), 1063 IO_REPARSE_TAG_NAME_SURROGATE = cpu_to_le32(0x20000000), 1064 IO_REPARSE_TAG_MICROSOFT = cpu_to_le32(0x80000000), 1065 IO_REPARSE_TAG_MOUNT_POINT = cpu_to_le32(0xA0000003), 1066 IO_REPARSE_TAG_SYMLINK = cpu_to_le32(0xA000000C), 1067 IO_REPARSE_TAG_HSM = cpu_to_le32(0xC0000004), 1068 IO_REPARSE_TAG_SIS = cpu_to_le32(0x80000007), 1069 IO_REPARSE_TAG_DEDUP = cpu_to_le32(0x80000013), 1070 IO_REPARSE_TAG_COMPRESS = cpu_to_le32(0x80000017), 1071 1072 /* 1073 * The reparse tag 0x80000008 is reserved for Microsoft internal use. 1074 * May be published in the future. 1075 */ 1076 1077 /* Microsoft reparse tag reserved for DFS */ 1078 IO_REPARSE_TAG_DFS = cpu_to_le32(0x8000000A), 1079 1080 /* Microsoft reparse tag reserved for the file system filter manager. */ 1081 IO_REPARSE_TAG_FILTER_MANAGER = cpu_to_le32(0x8000000B), 1082 1083 /* Non-Microsoft tags for reparse points */ 1084 1085 /* Tag allocated to CONGRUENT, May 2000. Used by IFSTEST. */ 1086 IO_REPARSE_TAG_IFSTEST_CONGRUENT = cpu_to_le32(0x00000009), 1087 1088 /* Tag allocated to ARKIVIO. */ 1089 IO_REPARSE_TAG_ARKIVIO = cpu_to_le32(0x0000000C), 1090 1091 /* Tag allocated to SOLUTIONSOFT. */ 1092 IO_REPARSE_TAG_SOLUTIONSOFT = cpu_to_le32(0x2000000D), 1093 1094 /* Tag allocated to COMMVAULT. */ 1095 IO_REPARSE_TAG_COMMVAULT = cpu_to_le32(0x0000000E), 1096 1097 /* OneDrive?? */ 1098 IO_REPARSE_TAG_CLOUD = cpu_to_le32(0x9000001A), 1099 IO_REPARSE_TAG_CLOUD_1 = cpu_to_le32(0x9000101A), 1100 IO_REPARSE_TAG_CLOUD_2 = cpu_to_le32(0x9000201A), 1101 IO_REPARSE_TAG_CLOUD_3 = cpu_to_le32(0x9000301A), 1102 IO_REPARSE_TAG_CLOUD_4 = cpu_to_le32(0x9000401A), 1103 IO_REPARSE_TAG_CLOUD_5 = cpu_to_le32(0x9000501A), 1104 IO_REPARSE_TAG_CLOUD_6 = cpu_to_le32(0x9000601A), 1105 IO_REPARSE_TAG_CLOUD_7 = cpu_to_le32(0x9000701A), 1106 IO_REPARSE_TAG_CLOUD_8 = cpu_to_le32(0x9000801A), 1107 IO_REPARSE_TAG_CLOUD_9 = cpu_to_le32(0x9000901A), 1108 IO_REPARSE_TAG_CLOUD_A = cpu_to_le32(0x9000A01A), 1109 IO_REPARSE_TAG_CLOUD_B = cpu_to_le32(0x9000B01A), 1110 IO_REPARSE_TAG_CLOUD_C = cpu_to_le32(0x9000C01A), 1111 IO_REPARSE_TAG_CLOUD_D = cpu_to_le32(0x9000D01A), 1112 IO_REPARSE_TAG_CLOUD_E = cpu_to_le32(0x9000E01A), 1113 IO_REPARSE_TAG_CLOUD_F = cpu_to_le32(0x9000F01A), 1114 1115 }; 1116 1117 #define SYMLINK_FLAG_RELATIVE 1 1118 1119 /* Microsoft reparse buffer. (see DDK for details) */ 1120 struct REPARSE_DATA_BUFFER { 1121 __le32 ReparseTag; // 0x00: 1122 __le16 ReparseDataLength; // 0x04: 1123 __le16 Reserved; 1124 1125 union { 1126 /* If ReparseTag == 0xA0000003 (IO_REPARSE_TAG_MOUNT_POINT) */ 1127 struct { 1128 __le16 SubstituteNameOffset; // 0x08 1129 __le16 SubstituteNameLength; // 0x0A 1130 __le16 PrintNameOffset; // 0x0C 1131 __le16 PrintNameLength; // 0x0E 1132 __le16 PathBuffer[]; // 0x10 1133 } MountPointReparseBuffer; 1134 1135 /* 1136 * If ReparseTag == 0xA000000C (IO_REPARSE_TAG_SYMLINK) 1137 * https://msdn.microsoft.com/en-us/library/cc232006.aspx 1138 */ 1139 struct { 1140 __le16 SubstituteNameOffset; // 0x08 1141 __le16 SubstituteNameLength; // 0x0A 1142 __le16 PrintNameOffset; // 0x0C 1143 __le16 PrintNameLength; // 0x0E 1144 // 0-absolute path 1- relative path, SYMLINK_FLAG_RELATIVE 1145 __le32 Flags; // 0x10 1146 __le16 PathBuffer[]; // 0x14 1147 } SymbolicLinkReparseBuffer; 1148 1149 /* If ReparseTag == 0x80000017U */ 1150 struct { 1151 __le32 WofVersion; // 0x08 == 1 1152 /* 1153 * 1 - WIM backing provider ("WIMBoot"), 1154 * 2 - System compressed file provider 1155 */ 1156 __le32 WofProvider; // 0x0C: 1157 __le32 ProviderVer; // 0x10: == 1 WOF_FILE_PROVIDER_CURRENT_VERSION == 1 1158 __le32 CompressionFormat; // 0x14: 0, 1, 2, 3. See WOF_COMPRESSION_XXX 1159 } CompressReparseBuffer; 1160 1161 struct { 1162 u8 DataBuffer[1]; // 0x08: 1163 } GenericReparseBuffer; 1164 }; 1165 }; 1166 1167 /* ATTR_EA_INFO (0xD0) */ 1168 1169 #define FILE_NEED_EA 0x80 // See ntifs.h 1170 /* 1171 * FILE_NEED_EA, indicates that the file to which the EA belongs cannot be 1172 * interpreted without understanding the associated extended attributes. 1173 */ 1174 struct EA_INFO { 1175 __le16 size_pack; // 0x00: Size of buffer to hold in packed form. 1176 __le16 count; // 0x02: Count of EA's with FILE_NEED_EA bit set. 1177 __le32 size; // 0x04: Size of buffer to hold in unpacked form. 1178 }; 1179 1180 static_assert(sizeof(struct EA_INFO) == 8); 1181 1182 /* ATTR_EA (0xE0) */ 1183 struct EA_FULL { 1184 __le32 size; // 0x00: (not in packed) 1185 u8 flags; // 0x04: 1186 u8 name_len; // 0x05: 1187 __le16 elength; // 0x06: 1188 u8 name[]; // 0x08: 1189 }; 1190 1191 static_assert(offsetof(struct EA_FULL, name) == 8); 1192 1193 #define ACL_REVISION 2 1194 #define ACL_REVISION_DS 4 1195 1196 #define SE_SELF_RELATIVE cpu_to_le16(0x8000) 1197 1198 struct SECURITY_DESCRIPTOR_RELATIVE { 1199 u8 Revision; 1200 u8 Sbz1; 1201 __le16 Control; 1202 __le32 Owner; 1203 __le32 Group; 1204 __le32 Sacl; 1205 __le32 Dacl; 1206 }; 1207 static_assert(sizeof(struct SECURITY_DESCRIPTOR_RELATIVE) == 0x14); 1208 1209 struct ACE_HEADER { 1210 u8 AceType; 1211 u8 AceFlags; 1212 __le16 AceSize; 1213 }; 1214 static_assert(sizeof(struct ACE_HEADER) == 4); 1215 1216 struct ACL { 1217 u8 AclRevision; 1218 u8 Sbz1; 1219 __le16 AclSize; 1220 __le16 AceCount; 1221 __le16 Sbz2; 1222 }; 1223 static_assert(sizeof(struct ACL) == 8); 1224 1225 struct SID { 1226 u8 Revision; 1227 u8 SubAuthorityCount; 1228 u8 IdentifierAuthority[6]; 1229 __le32 SubAuthority[]; 1230 }; 1231 static_assert(offsetof(struct SID, SubAuthority) == 8); 1232 1233 #endif /* _LINUX_NTFS3_NTFS_H */ 1234 // clang-format on 1235