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