18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * layout.h - All NTFS associated on-disk structures. Part of the Linux-NTFS 48c2ecf20Sopenharmony_ci * project. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (c) 2001-2005 Anton Altaparmakov 78c2ecf20Sopenharmony_ci * Copyright (c) 2002 Richard Russon 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef _LINUX_NTFS_LAYOUT_H 118c2ecf20Sopenharmony_ci#define _LINUX_NTFS_LAYOUT_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/types.h> 148c2ecf20Sopenharmony_ci#include <linux/bitops.h> 158c2ecf20Sopenharmony_ci#include <linux/list.h> 168c2ecf20Sopenharmony_ci#include <asm/byteorder.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#include "types.h" 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci/* The NTFS oem_id "NTFS " */ 218c2ecf20Sopenharmony_ci#define magicNTFS cpu_to_le64(0x202020205346544eULL) 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci/* 248c2ecf20Sopenharmony_ci * Location of bootsector on partition: 258c2ecf20Sopenharmony_ci * The standard NTFS_BOOT_SECTOR is on sector 0 of the partition. 268c2ecf20Sopenharmony_ci * On NT4 and above there is one backup copy of the boot sector to 278c2ecf20Sopenharmony_ci * be found on the last sector of the partition (not normally accessible 288c2ecf20Sopenharmony_ci * from within Windows as the bootsector contained number of sectors 298c2ecf20Sopenharmony_ci * value is one less than the actual value!). 308c2ecf20Sopenharmony_ci * On versions of NT 3.51 and earlier, the backup copy was located at 318c2ecf20Sopenharmony_ci * number of sectors/2 (integer divide), i.e. in the middle of the volume. 328c2ecf20Sopenharmony_ci */ 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci/* 358c2ecf20Sopenharmony_ci * BIOS parameter block (bpb) structure. 368c2ecf20Sopenharmony_ci */ 378c2ecf20Sopenharmony_citypedef struct { 388c2ecf20Sopenharmony_ci le16 bytes_per_sector; /* Size of a sector in bytes. */ 398c2ecf20Sopenharmony_ci u8 sectors_per_cluster; /* Size of a cluster in sectors. */ 408c2ecf20Sopenharmony_ci le16 reserved_sectors; /* zero */ 418c2ecf20Sopenharmony_ci u8 fats; /* zero */ 428c2ecf20Sopenharmony_ci le16 root_entries; /* zero */ 438c2ecf20Sopenharmony_ci le16 sectors; /* zero */ 448c2ecf20Sopenharmony_ci u8 media_type; /* 0xf8 = hard disk */ 458c2ecf20Sopenharmony_ci le16 sectors_per_fat; /* zero */ 468c2ecf20Sopenharmony_ci le16 sectors_per_track; /* irrelevant */ 478c2ecf20Sopenharmony_ci le16 heads; /* irrelevant */ 488c2ecf20Sopenharmony_ci le32 hidden_sectors; /* zero */ 498c2ecf20Sopenharmony_ci le32 large_sectors; /* zero */ 508c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) BIOS_PARAMETER_BLOCK; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* 538c2ecf20Sopenharmony_ci * NTFS boot sector structure. 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_citypedef struct { 568c2ecf20Sopenharmony_ci u8 jump[3]; /* Irrelevant (jump to boot up code).*/ 578c2ecf20Sopenharmony_ci le64 oem_id; /* Magic "NTFS ". */ 588c2ecf20Sopenharmony_ci BIOS_PARAMETER_BLOCK bpb; /* See BIOS_PARAMETER_BLOCK. */ 598c2ecf20Sopenharmony_ci u8 unused[4]; /* zero, NTFS diskedit.exe states that 608c2ecf20Sopenharmony_ci this is actually: 618c2ecf20Sopenharmony_ci __u8 physical_drive; // 0x80 628c2ecf20Sopenharmony_ci __u8 current_head; // zero 638c2ecf20Sopenharmony_ci __u8 extended_boot_signature; 648c2ecf20Sopenharmony_ci // 0x80 658c2ecf20Sopenharmony_ci __u8 unused; // zero 668c2ecf20Sopenharmony_ci */ 678c2ecf20Sopenharmony_ci/*0x28*/sle64 number_of_sectors; /* Number of sectors in volume. Gives 688c2ecf20Sopenharmony_ci maximum volume size of 2^63 sectors. 698c2ecf20Sopenharmony_ci Assuming standard sector size of 512 708c2ecf20Sopenharmony_ci bytes, the maximum byte size is 718c2ecf20Sopenharmony_ci approx. 4.7x10^21 bytes. (-; */ 728c2ecf20Sopenharmony_ci sle64 mft_lcn; /* Cluster location of mft data. */ 738c2ecf20Sopenharmony_ci sle64 mftmirr_lcn; /* Cluster location of copy of mft. */ 748c2ecf20Sopenharmony_ci s8 clusters_per_mft_record; /* Mft record size in clusters. */ 758c2ecf20Sopenharmony_ci u8 reserved0[3]; /* zero */ 768c2ecf20Sopenharmony_ci s8 clusters_per_index_record; /* Index block size in clusters. */ 778c2ecf20Sopenharmony_ci u8 reserved1[3]; /* zero */ 788c2ecf20Sopenharmony_ci le64 volume_serial_number; /* Irrelevant (serial number). */ 798c2ecf20Sopenharmony_ci le32 checksum; /* Boot sector checksum. */ 808c2ecf20Sopenharmony_ci/*0x54*/u8 bootstrap[426]; /* Irrelevant (boot up code). */ 818c2ecf20Sopenharmony_ci le16 end_of_sector_marker; /* End of bootsector magic. Always is 828c2ecf20Sopenharmony_ci 0xaa55 in little endian. */ 838c2ecf20Sopenharmony_ci/* sizeof() = 512 (0x200) bytes */ 848c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) NTFS_BOOT_SECTOR; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/* 878c2ecf20Sopenharmony_ci * Magic identifiers present at the beginning of all ntfs record containing 888c2ecf20Sopenharmony_ci * records (like mft records for example). 898c2ecf20Sopenharmony_ci */ 908c2ecf20Sopenharmony_cienum { 918c2ecf20Sopenharmony_ci /* Found in $MFT/$DATA. */ 928c2ecf20Sopenharmony_ci magic_FILE = cpu_to_le32(0x454c4946), /* Mft entry. */ 938c2ecf20Sopenharmony_ci magic_INDX = cpu_to_le32(0x58444e49), /* Index buffer. */ 948c2ecf20Sopenharmony_ci magic_HOLE = cpu_to_le32(0x454c4f48), /* ? (NTFS 3.0+?) */ 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci /* Found in $LogFile/$DATA. */ 978c2ecf20Sopenharmony_ci magic_RSTR = cpu_to_le32(0x52545352), /* Restart page. */ 988c2ecf20Sopenharmony_ci magic_RCRD = cpu_to_le32(0x44524352), /* Log record page. */ 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci /* Found in $LogFile/$DATA. (May be found in $MFT/$DATA, also?) */ 1018c2ecf20Sopenharmony_ci magic_CHKD = cpu_to_le32(0x444b4843), /* Modified by chkdsk. */ 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci /* Found in all ntfs record containing records. */ 1048c2ecf20Sopenharmony_ci magic_BAAD = cpu_to_le32(0x44414142), /* Failed multi sector 1058c2ecf20Sopenharmony_ci transfer was detected. */ 1068c2ecf20Sopenharmony_ci /* 1078c2ecf20Sopenharmony_ci * Found in $LogFile/$DATA when a page is full of 0xff bytes and is 1088c2ecf20Sopenharmony_ci * thus not initialized. Page must be initialized before using it. 1098c2ecf20Sopenharmony_ci */ 1108c2ecf20Sopenharmony_ci magic_empty = cpu_to_le32(0xffffffff) /* Record is empty. */ 1118c2ecf20Sopenharmony_ci}; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_citypedef le32 NTFS_RECORD_TYPE; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/* 1168c2ecf20Sopenharmony_ci * Generic magic comparison macros. Finally found a use for the ## preprocessor 1178c2ecf20Sopenharmony_ci * operator! (-8 1188c2ecf20Sopenharmony_ci */ 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_cistatic inline bool __ntfs_is_magic(le32 x, NTFS_RECORD_TYPE r) 1218c2ecf20Sopenharmony_ci{ 1228c2ecf20Sopenharmony_ci return (x == r); 1238c2ecf20Sopenharmony_ci} 1248c2ecf20Sopenharmony_ci#define ntfs_is_magic(x, m) __ntfs_is_magic(x, magic_##m) 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_cistatic inline bool __ntfs_is_magicp(le32 *p, NTFS_RECORD_TYPE r) 1278c2ecf20Sopenharmony_ci{ 1288c2ecf20Sopenharmony_ci return (*p == r); 1298c2ecf20Sopenharmony_ci} 1308c2ecf20Sopenharmony_ci#define ntfs_is_magicp(p, m) __ntfs_is_magicp(p, magic_##m) 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci/* 1338c2ecf20Sopenharmony_ci * Specialised magic comparison macros for the NTFS_RECORD_TYPEs defined above. 1348c2ecf20Sopenharmony_ci */ 1358c2ecf20Sopenharmony_ci#define ntfs_is_file_record(x) ( ntfs_is_magic (x, FILE) ) 1368c2ecf20Sopenharmony_ci#define ntfs_is_file_recordp(p) ( ntfs_is_magicp(p, FILE) ) 1378c2ecf20Sopenharmony_ci#define ntfs_is_mft_record(x) ( ntfs_is_file_record (x) ) 1388c2ecf20Sopenharmony_ci#define ntfs_is_mft_recordp(p) ( ntfs_is_file_recordp(p) ) 1398c2ecf20Sopenharmony_ci#define ntfs_is_indx_record(x) ( ntfs_is_magic (x, INDX) ) 1408c2ecf20Sopenharmony_ci#define ntfs_is_indx_recordp(p) ( ntfs_is_magicp(p, INDX) ) 1418c2ecf20Sopenharmony_ci#define ntfs_is_hole_record(x) ( ntfs_is_magic (x, HOLE) ) 1428c2ecf20Sopenharmony_ci#define ntfs_is_hole_recordp(p) ( ntfs_is_magicp(p, HOLE) ) 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci#define ntfs_is_rstr_record(x) ( ntfs_is_magic (x, RSTR) ) 1458c2ecf20Sopenharmony_ci#define ntfs_is_rstr_recordp(p) ( ntfs_is_magicp(p, RSTR) ) 1468c2ecf20Sopenharmony_ci#define ntfs_is_rcrd_record(x) ( ntfs_is_magic (x, RCRD) ) 1478c2ecf20Sopenharmony_ci#define ntfs_is_rcrd_recordp(p) ( ntfs_is_magicp(p, RCRD) ) 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci#define ntfs_is_chkd_record(x) ( ntfs_is_magic (x, CHKD) ) 1508c2ecf20Sopenharmony_ci#define ntfs_is_chkd_recordp(p) ( ntfs_is_magicp(p, CHKD) ) 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci#define ntfs_is_baad_record(x) ( ntfs_is_magic (x, BAAD) ) 1538c2ecf20Sopenharmony_ci#define ntfs_is_baad_recordp(p) ( ntfs_is_magicp(p, BAAD) ) 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci#define ntfs_is_empty_record(x) ( ntfs_is_magic (x, empty) ) 1568c2ecf20Sopenharmony_ci#define ntfs_is_empty_recordp(p) ( ntfs_is_magicp(p, empty) ) 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci/* 1598c2ecf20Sopenharmony_ci * The Update Sequence Array (usa) is an array of the le16 values which belong 1608c2ecf20Sopenharmony_ci * to the end of each sector protected by the update sequence record in which 1618c2ecf20Sopenharmony_ci * this array is contained. Note that the first entry is the Update Sequence 1628c2ecf20Sopenharmony_ci * Number (usn), a cyclic counter of how many times the protected record has 1638c2ecf20Sopenharmony_ci * been written to disk. The values 0 and -1 (ie. 0xffff) are not used. All 1648c2ecf20Sopenharmony_ci * last le16's of each sector have to be equal to the usn (during reading) or 1658c2ecf20Sopenharmony_ci * are set to it (during writing). If they are not, an incomplete multi sector 1668c2ecf20Sopenharmony_ci * transfer has occurred when the data was written. 1678c2ecf20Sopenharmony_ci * The maximum size for the update sequence array is fixed to: 1688c2ecf20Sopenharmony_ci * maximum size = usa_ofs + (usa_count * 2) = 510 bytes 1698c2ecf20Sopenharmony_ci * The 510 bytes comes from the fact that the last le16 in the array has to 1708c2ecf20Sopenharmony_ci * (obviously) finish before the last le16 of the first 512-byte sector. 1718c2ecf20Sopenharmony_ci * This formula can be used as a consistency check in that usa_ofs + 1728c2ecf20Sopenharmony_ci * (usa_count * 2) has to be less than or equal to 510. 1738c2ecf20Sopenharmony_ci */ 1748c2ecf20Sopenharmony_citypedef struct { 1758c2ecf20Sopenharmony_ci NTFS_RECORD_TYPE magic; /* A four-byte magic identifying the record 1768c2ecf20Sopenharmony_ci type and/or status. */ 1778c2ecf20Sopenharmony_ci le16 usa_ofs; /* Offset to the Update Sequence Array (usa) 1788c2ecf20Sopenharmony_ci from the start of the ntfs record. */ 1798c2ecf20Sopenharmony_ci le16 usa_count; /* Number of le16 sized entries in the usa 1808c2ecf20Sopenharmony_ci including the Update Sequence Number (usn), 1818c2ecf20Sopenharmony_ci thus the number of fixups is the usa_count 1828c2ecf20Sopenharmony_ci minus 1. */ 1838c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) NTFS_RECORD; 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci/* 1868c2ecf20Sopenharmony_ci * System files mft record numbers. All these files are always marked as used 1878c2ecf20Sopenharmony_ci * in the bitmap attribute of the mft; presumably in order to avoid accidental 1888c2ecf20Sopenharmony_ci * allocation for random other mft records. Also, the sequence number for each 1898c2ecf20Sopenharmony_ci * of the system files is always equal to their mft record number and it is 1908c2ecf20Sopenharmony_ci * never modified. 1918c2ecf20Sopenharmony_ci */ 1928c2ecf20Sopenharmony_citypedef enum { 1938c2ecf20Sopenharmony_ci FILE_MFT = 0, /* Master file table (mft). Data attribute 1948c2ecf20Sopenharmony_ci contains the entries and bitmap attribute 1958c2ecf20Sopenharmony_ci records which ones are in use (bit==1). */ 1968c2ecf20Sopenharmony_ci FILE_MFTMirr = 1, /* Mft mirror: copy of first four mft records 1978c2ecf20Sopenharmony_ci in data attribute. If cluster size > 4kiB, 1988c2ecf20Sopenharmony_ci copy of first N mft records, with 1998c2ecf20Sopenharmony_ci N = cluster_size / mft_record_size. */ 2008c2ecf20Sopenharmony_ci FILE_LogFile = 2, /* Journalling log in data attribute. */ 2018c2ecf20Sopenharmony_ci FILE_Volume = 3, /* Volume name attribute and volume information 2028c2ecf20Sopenharmony_ci attribute (flags and ntfs version). Windows 2038c2ecf20Sopenharmony_ci refers to this file as volume DASD (Direct 2048c2ecf20Sopenharmony_ci Access Storage Device). */ 2058c2ecf20Sopenharmony_ci FILE_AttrDef = 4, /* Array of attribute definitions in data 2068c2ecf20Sopenharmony_ci attribute. */ 2078c2ecf20Sopenharmony_ci FILE_root = 5, /* Root directory. */ 2088c2ecf20Sopenharmony_ci FILE_Bitmap = 6, /* Allocation bitmap of all clusters (lcns) in 2098c2ecf20Sopenharmony_ci data attribute. */ 2108c2ecf20Sopenharmony_ci FILE_Boot = 7, /* Boot sector (always at cluster 0) in data 2118c2ecf20Sopenharmony_ci attribute. */ 2128c2ecf20Sopenharmony_ci FILE_BadClus = 8, /* Contains all bad clusters in the non-resident 2138c2ecf20Sopenharmony_ci data attribute. */ 2148c2ecf20Sopenharmony_ci FILE_Secure = 9, /* Shared security descriptors in data attribute 2158c2ecf20Sopenharmony_ci and two indexes into the descriptors. 2168c2ecf20Sopenharmony_ci Appeared in Windows 2000. Before that, this 2178c2ecf20Sopenharmony_ci file was named $Quota but was unused. */ 2188c2ecf20Sopenharmony_ci FILE_UpCase = 10, /* Uppercase equivalents of all 65536 Unicode 2198c2ecf20Sopenharmony_ci characters in data attribute. */ 2208c2ecf20Sopenharmony_ci FILE_Extend = 11, /* Directory containing other system files (eg. 2218c2ecf20Sopenharmony_ci $ObjId, $Quota, $Reparse and $UsnJrnl). This 2228c2ecf20Sopenharmony_ci is new to NTFS3.0. */ 2238c2ecf20Sopenharmony_ci FILE_reserved12 = 12, /* Reserved for future use (records 12-15). */ 2248c2ecf20Sopenharmony_ci FILE_reserved13 = 13, 2258c2ecf20Sopenharmony_ci FILE_reserved14 = 14, 2268c2ecf20Sopenharmony_ci FILE_reserved15 = 15, 2278c2ecf20Sopenharmony_ci FILE_first_user = 16, /* First user file, used as test limit for 2288c2ecf20Sopenharmony_ci whether to allow opening a file or not. */ 2298c2ecf20Sopenharmony_ci} NTFS_SYSTEM_FILES; 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci/* 2328c2ecf20Sopenharmony_ci * These are the so far known MFT_RECORD_* flags (16-bit) which contain 2338c2ecf20Sopenharmony_ci * information about the mft record in which they are present. 2348c2ecf20Sopenharmony_ci */ 2358c2ecf20Sopenharmony_cienum { 2368c2ecf20Sopenharmony_ci MFT_RECORD_IN_USE = cpu_to_le16(0x0001), 2378c2ecf20Sopenharmony_ci MFT_RECORD_IS_DIRECTORY = cpu_to_le16(0x0002), 2388c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_citypedef le16 MFT_RECORD_FLAGS; 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci/* 2438c2ecf20Sopenharmony_ci * mft references (aka file references or file record segment references) are 2448c2ecf20Sopenharmony_ci * used whenever a structure needs to refer to a record in the mft. 2458c2ecf20Sopenharmony_ci * 2468c2ecf20Sopenharmony_ci * A reference consists of a 48-bit index into the mft and a 16-bit sequence 2478c2ecf20Sopenharmony_ci * number used to detect stale references. 2488c2ecf20Sopenharmony_ci * 2498c2ecf20Sopenharmony_ci * For error reporting purposes we treat the 48-bit index as a signed quantity. 2508c2ecf20Sopenharmony_ci * 2518c2ecf20Sopenharmony_ci * The sequence number is a circular counter (skipping 0) describing how many 2528c2ecf20Sopenharmony_ci * times the referenced mft record has been (re)used. This has to match the 2538c2ecf20Sopenharmony_ci * sequence number of the mft record being referenced, otherwise the reference 2548c2ecf20Sopenharmony_ci * is considered stale and removed (FIXME: only ntfsck or the driver itself?). 2558c2ecf20Sopenharmony_ci * 2568c2ecf20Sopenharmony_ci * If the sequence number is zero it is assumed that no sequence number 2578c2ecf20Sopenharmony_ci * consistency checking should be performed. 2588c2ecf20Sopenharmony_ci * 2598c2ecf20Sopenharmony_ci * FIXME: Since inodes are 32-bit as of now, the driver needs to always check 2608c2ecf20Sopenharmony_ci * for high_part being 0 and if not either BUG(), cause a panic() or handle 2618c2ecf20Sopenharmony_ci * the situation in some other way. This shouldn't be a problem as a volume has 2628c2ecf20Sopenharmony_ci * to become HUGE in order to need more than 32-bits worth of mft records. 2638c2ecf20Sopenharmony_ci * Assuming the standard mft record size of 1kb only the records (never mind 2648c2ecf20Sopenharmony_ci * the non-resident attributes, etc.) would require 4Tb of space on their own 2658c2ecf20Sopenharmony_ci * for the first 32 bits worth of records. This is only if some strange person 2668c2ecf20Sopenharmony_ci * doesn't decide to foul play and make the mft sparse which would be a really 2678c2ecf20Sopenharmony_ci * horrible thing to do as it would trash our current driver implementation. )-: 2688c2ecf20Sopenharmony_ci * Do I hear screams "we want 64-bit inodes!" ?!? (-; 2698c2ecf20Sopenharmony_ci * 2708c2ecf20Sopenharmony_ci * FIXME: The mft zone is defined as the first 12% of the volume. This space is 2718c2ecf20Sopenharmony_ci * reserved so that the mft can grow contiguously and hence doesn't become 2728c2ecf20Sopenharmony_ci * fragmented. Volume free space includes the empty part of the mft zone and 2738c2ecf20Sopenharmony_ci * when the volume's free 88% are used up, the mft zone is shrunk by a factor 2748c2ecf20Sopenharmony_ci * of 2, thus making more space available for more files/data. This process is 2758c2ecf20Sopenharmony_ci * repeated every time there is no more free space except for the mft zone until 2768c2ecf20Sopenharmony_ci * there really is no more free space. 2778c2ecf20Sopenharmony_ci */ 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci/* 2808c2ecf20Sopenharmony_ci * Typedef the MFT_REF as a 64-bit value for easier handling. 2818c2ecf20Sopenharmony_ci * Also define two unpacking macros to get to the reference (MREF) and 2828c2ecf20Sopenharmony_ci * sequence number (MSEQNO) respectively. 2838c2ecf20Sopenharmony_ci * The _LE versions are to be applied on little endian MFT_REFs. 2848c2ecf20Sopenharmony_ci * Note: The _LE versions will return a CPU endian formatted value! 2858c2ecf20Sopenharmony_ci */ 2868c2ecf20Sopenharmony_ci#define MFT_REF_MASK_CPU 0x0000ffffffffffffULL 2878c2ecf20Sopenharmony_ci#define MFT_REF_MASK_LE cpu_to_le64(MFT_REF_MASK_CPU) 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_citypedef u64 MFT_REF; 2908c2ecf20Sopenharmony_citypedef le64 leMFT_REF; 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci#define MK_MREF(m, s) ((MFT_REF)(((MFT_REF)(s) << 48) | \ 2938c2ecf20Sopenharmony_ci ((MFT_REF)(m) & MFT_REF_MASK_CPU))) 2948c2ecf20Sopenharmony_ci#define MK_LE_MREF(m, s) cpu_to_le64(MK_MREF(m, s)) 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci#define MREF(x) ((unsigned long)((x) & MFT_REF_MASK_CPU)) 2978c2ecf20Sopenharmony_ci#define MSEQNO(x) ((u16)(((x) >> 48) & 0xffff)) 2988c2ecf20Sopenharmony_ci#define MREF_LE(x) ((unsigned long)(le64_to_cpu(x) & MFT_REF_MASK_CPU)) 2998c2ecf20Sopenharmony_ci#define MSEQNO_LE(x) ((u16)((le64_to_cpu(x) >> 48) & 0xffff)) 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci#define IS_ERR_MREF(x) (((x) & 0x0000800000000000ULL) ? true : false) 3028c2ecf20Sopenharmony_ci#define ERR_MREF(x) ((u64)((s64)(x))) 3038c2ecf20Sopenharmony_ci#define MREF_ERR(x) ((int)((s64)(x))) 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci/* 3068c2ecf20Sopenharmony_ci * The mft record header present at the beginning of every record in the mft. 3078c2ecf20Sopenharmony_ci * This is followed by a sequence of variable length attribute records which 3088c2ecf20Sopenharmony_ci * is terminated by an attribute of type AT_END which is a truncated attribute 3098c2ecf20Sopenharmony_ci * in that it only consists of the attribute type code AT_END and none of the 3108c2ecf20Sopenharmony_ci * other members of the attribute structure are present. 3118c2ecf20Sopenharmony_ci */ 3128c2ecf20Sopenharmony_citypedef struct { 3138c2ecf20Sopenharmony_ci/*Ofs*/ 3148c2ecf20Sopenharmony_ci/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ 3158c2ecf20Sopenharmony_ci NTFS_RECORD_TYPE magic; /* Usually the magic is "FILE". */ 3168c2ecf20Sopenharmony_ci le16 usa_ofs; /* See NTFS_RECORD definition above. */ 3178c2ecf20Sopenharmony_ci le16 usa_count; /* See NTFS_RECORD definition above. */ 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci/* 8*/ le64 lsn; /* $LogFile sequence number for this record. 3208c2ecf20Sopenharmony_ci Changed every time the record is modified. */ 3218c2ecf20Sopenharmony_ci/* 16*/ le16 sequence_number; /* Number of times this mft record has been 3228c2ecf20Sopenharmony_ci reused. (See description for MFT_REF 3238c2ecf20Sopenharmony_ci above.) NOTE: The increment (skipping zero) 3248c2ecf20Sopenharmony_ci is done when the file is deleted. NOTE: If 3258c2ecf20Sopenharmony_ci this is zero it is left zero. */ 3268c2ecf20Sopenharmony_ci/* 18*/ le16 link_count; /* Number of hard links, i.e. the number of 3278c2ecf20Sopenharmony_ci directory entries referencing this record. 3288c2ecf20Sopenharmony_ci NOTE: Only used in mft base records. 3298c2ecf20Sopenharmony_ci NOTE: When deleting a directory entry we 3308c2ecf20Sopenharmony_ci check the link_count and if it is 1 we 3318c2ecf20Sopenharmony_ci delete the file. Otherwise we delete the 3328c2ecf20Sopenharmony_ci FILE_NAME_ATTR being referenced by the 3338c2ecf20Sopenharmony_ci directory entry from the mft record and 3348c2ecf20Sopenharmony_ci decrement the link_count. 3358c2ecf20Sopenharmony_ci FIXME: Careful with Win32 + DOS names! */ 3368c2ecf20Sopenharmony_ci/* 20*/ le16 attrs_offset; /* Byte offset to the first attribute in this 3378c2ecf20Sopenharmony_ci mft record from the start of the mft record. 3388c2ecf20Sopenharmony_ci NOTE: Must be aligned to 8-byte boundary. */ 3398c2ecf20Sopenharmony_ci/* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file 3408c2ecf20Sopenharmony_ci is deleted, the MFT_RECORD_IN_USE flag is 3418c2ecf20Sopenharmony_ci set to zero. */ 3428c2ecf20Sopenharmony_ci/* 24*/ le32 bytes_in_use; /* Number of bytes used in this mft record. 3438c2ecf20Sopenharmony_ci NOTE: Must be aligned to 8-byte boundary. */ 3448c2ecf20Sopenharmony_ci/* 28*/ le32 bytes_allocated; /* Number of bytes allocated for this mft 3458c2ecf20Sopenharmony_ci record. This should be equal to the mft 3468c2ecf20Sopenharmony_ci record size. */ 3478c2ecf20Sopenharmony_ci/* 32*/ leMFT_REF base_mft_record;/* This is zero for base mft records. 3488c2ecf20Sopenharmony_ci When it is not zero it is a mft reference 3498c2ecf20Sopenharmony_ci pointing to the base mft record to which 3508c2ecf20Sopenharmony_ci this record belongs (this is then used to 3518c2ecf20Sopenharmony_ci locate the attribute list attribute present 3528c2ecf20Sopenharmony_ci in the base record which describes this 3538c2ecf20Sopenharmony_ci extension record and hence might need 3548c2ecf20Sopenharmony_ci modification when the extension record 3558c2ecf20Sopenharmony_ci itself is modified, also locating the 3568c2ecf20Sopenharmony_ci attribute list also means finding the other 3578c2ecf20Sopenharmony_ci potential extents, belonging to the non-base 3588c2ecf20Sopenharmony_ci mft record). */ 3598c2ecf20Sopenharmony_ci/* 40*/ le16 next_attr_instance;/* The instance number that will be assigned to 3608c2ecf20Sopenharmony_ci the next attribute added to this mft record. 3618c2ecf20Sopenharmony_ci NOTE: Incremented each time after it is used. 3628c2ecf20Sopenharmony_ci NOTE: Every time the mft record is reused 3638c2ecf20Sopenharmony_ci this number is set to zero. NOTE: The first 3648c2ecf20Sopenharmony_ci instance number is always 0. */ 3658c2ecf20Sopenharmony_ci/* The below fields are specific to NTFS 3.1+ (Windows XP and above): */ 3668c2ecf20Sopenharmony_ci/* 42*/ le16 reserved; /* Reserved/alignment. */ 3678c2ecf20Sopenharmony_ci/* 44*/ le32 mft_record_number; /* Number of this mft record. */ 3688c2ecf20Sopenharmony_ci/* sizeof() = 48 bytes */ 3698c2ecf20Sopenharmony_ci/* 3708c2ecf20Sopenharmony_ci * When (re)using the mft record, we place the update sequence array at this 3718c2ecf20Sopenharmony_ci * offset, i.e. before we start with the attributes. This also makes sense, 3728c2ecf20Sopenharmony_ci * otherwise we could run into problems with the update sequence array 3738c2ecf20Sopenharmony_ci * containing in itself the last two bytes of a sector which would mean that 3748c2ecf20Sopenharmony_ci * multi sector transfer protection wouldn't work. As you can't protect data 3758c2ecf20Sopenharmony_ci * by overwriting it since you then can't get it back... 3768c2ecf20Sopenharmony_ci * When reading we obviously use the data from the ntfs record header. 3778c2ecf20Sopenharmony_ci */ 3788c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) MFT_RECORD; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci/* This is the version without the NTFS 3.1+ specific fields. */ 3818c2ecf20Sopenharmony_citypedef struct { 3828c2ecf20Sopenharmony_ci/*Ofs*/ 3838c2ecf20Sopenharmony_ci/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ 3848c2ecf20Sopenharmony_ci NTFS_RECORD_TYPE magic; /* Usually the magic is "FILE". */ 3858c2ecf20Sopenharmony_ci le16 usa_ofs; /* See NTFS_RECORD definition above. */ 3868c2ecf20Sopenharmony_ci le16 usa_count; /* See NTFS_RECORD definition above. */ 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci/* 8*/ le64 lsn; /* $LogFile sequence number for this record. 3898c2ecf20Sopenharmony_ci Changed every time the record is modified. */ 3908c2ecf20Sopenharmony_ci/* 16*/ le16 sequence_number; /* Number of times this mft record has been 3918c2ecf20Sopenharmony_ci reused. (See description for MFT_REF 3928c2ecf20Sopenharmony_ci above.) NOTE: The increment (skipping zero) 3938c2ecf20Sopenharmony_ci is done when the file is deleted. NOTE: If 3948c2ecf20Sopenharmony_ci this is zero it is left zero. */ 3958c2ecf20Sopenharmony_ci/* 18*/ le16 link_count; /* Number of hard links, i.e. the number of 3968c2ecf20Sopenharmony_ci directory entries referencing this record. 3978c2ecf20Sopenharmony_ci NOTE: Only used in mft base records. 3988c2ecf20Sopenharmony_ci NOTE: When deleting a directory entry we 3998c2ecf20Sopenharmony_ci check the link_count and if it is 1 we 4008c2ecf20Sopenharmony_ci delete the file. Otherwise we delete the 4018c2ecf20Sopenharmony_ci FILE_NAME_ATTR being referenced by the 4028c2ecf20Sopenharmony_ci directory entry from the mft record and 4038c2ecf20Sopenharmony_ci decrement the link_count. 4048c2ecf20Sopenharmony_ci FIXME: Careful with Win32 + DOS names! */ 4058c2ecf20Sopenharmony_ci/* 20*/ le16 attrs_offset; /* Byte offset to the first attribute in this 4068c2ecf20Sopenharmony_ci mft record from the start of the mft record. 4078c2ecf20Sopenharmony_ci NOTE: Must be aligned to 8-byte boundary. */ 4088c2ecf20Sopenharmony_ci/* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file 4098c2ecf20Sopenharmony_ci is deleted, the MFT_RECORD_IN_USE flag is 4108c2ecf20Sopenharmony_ci set to zero. */ 4118c2ecf20Sopenharmony_ci/* 24*/ le32 bytes_in_use; /* Number of bytes used in this mft record. 4128c2ecf20Sopenharmony_ci NOTE: Must be aligned to 8-byte boundary. */ 4138c2ecf20Sopenharmony_ci/* 28*/ le32 bytes_allocated; /* Number of bytes allocated for this mft 4148c2ecf20Sopenharmony_ci record. This should be equal to the mft 4158c2ecf20Sopenharmony_ci record size. */ 4168c2ecf20Sopenharmony_ci/* 32*/ leMFT_REF base_mft_record;/* This is zero for base mft records. 4178c2ecf20Sopenharmony_ci When it is not zero it is a mft reference 4188c2ecf20Sopenharmony_ci pointing to the base mft record to which 4198c2ecf20Sopenharmony_ci this record belongs (this is then used to 4208c2ecf20Sopenharmony_ci locate the attribute list attribute present 4218c2ecf20Sopenharmony_ci in the base record which describes this 4228c2ecf20Sopenharmony_ci extension record and hence might need 4238c2ecf20Sopenharmony_ci modification when the extension record 4248c2ecf20Sopenharmony_ci itself is modified, also locating the 4258c2ecf20Sopenharmony_ci attribute list also means finding the other 4268c2ecf20Sopenharmony_ci potential extents, belonging to the non-base 4278c2ecf20Sopenharmony_ci mft record). */ 4288c2ecf20Sopenharmony_ci/* 40*/ le16 next_attr_instance;/* The instance number that will be assigned to 4298c2ecf20Sopenharmony_ci the next attribute added to this mft record. 4308c2ecf20Sopenharmony_ci NOTE: Incremented each time after it is used. 4318c2ecf20Sopenharmony_ci NOTE: Every time the mft record is reused 4328c2ecf20Sopenharmony_ci this number is set to zero. NOTE: The first 4338c2ecf20Sopenharmony_ci instance number is always 0. */ 4348c2ecf20Sopenharmony_ci/* sizeof() = 42 bytes */ 4358c2ecf20Sopenharmony_ci/* 4368c2ecf20Sopenharmony_ci * When (re)using the mft record, we place the update sequence array at this 4378c2ecf20Sopenharmony_ci * offset, i.e. before we start with the attributes. This also makes sense, 4388c2ecf20Sopenharmony_ci * otherwise we could run into problems with the update sequence array 4398c2ecf20Sopenharmony_ci * containing in itself the last two bytes of a sector which would mean that 4408c2ecf20Sopenharmony_ci * multi sector transfer protection wouldn't work. As you can't protect data 4418c2ecf20Sopenharmony_ci * by overwriting it since you then can't get it back... 4428c2ecf20Sopenharmony_ci * When reading we obviously use the data from the ntfs record header. 4438c2ecf20Sopenharmony_ci */ 4448c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) MFT_RECORD_OLD; 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci/* 4478c2ecf20Sopenharmony_ci * System defined attributes (32-bit). Each attribute type has a corresponding 4488c2ecf20Sopenharmony_ci * attribute name (Unicode string of maximum 64 character length) as described 4498c2ecf20Sopenharmony_ci * by the attribute definitions present in the data attribute of the $AttrDef 4508c2ecf20Sopenharmony_ci * system file. On NTFS 3.0 volumes the names are just as the types are named 4518c2ecf20Sopenharmony_ci * in the below defines exchanging AT_ for the dollar sign ($). If that is not 4528c2ecf20Sopenharmony_ci * a revealing choice of symbol I do not know what is... (-; 4538c2ecf20Sopenharmony_ci */ 4548c2ecf20Sopenharmony_cienum { 4558c2ecf20Sopenharmony_ci AT_UNUSED = cpu_to_le32( 0), 4568c2ecf20Sopenharmony_ci AT_STANDARD_INFORMATION = cpu_to_le32( 0x10), 4578c2ecf20Sopenharmony_ci AT_ATTRIBUTE_LIST = cpu_to_le32( 0x20), 4588c2ecf20Sopenharmony_ci AT_FILE_NAME = cpu_to_le32( 0x30), 4598c2ecf20Sopenharmony_ci AT_OBJECT_ID = cpu_to_le32( 0x40), 4608c2ecf20Sopenharmony_ci AT_SECURITY_DESCRIPTOR = cpu_to_le32( 0x50), 4618c2ecf20Sopenharmony_ci AT_VOLUME_NAME = cpu_to_le32( 0x60), 4628c2ecf20Sopenharmony_ci AT_VOLUME_INFORMATION = cpu_to_le32( 0x70), 4638c2ecf20Sopenharmony_ci AT_DATA = cpu_to_le32( 0x80), 4648c2ecf20Sopenharmony_ci AT_INDEX_ROOT = cpu_to_le32( 0x90), 4658c2ecf20Sopenharmony_ci AT_INDEX_ALLOCATION = cpu_to_le32( 0xa0), 4668c2ecf20Sopenharmony_ci AT_BITMAP = cpu_to_le32( 0xb0), 4678c2ecf20Sopenharmony_ci AT_REPARSE_POINT = cpu_to_le32( 0xc0), 4688c2ecf20Sopenharmony_ci AT_EA_INFORMATION = cpu_to_le32( 0xd0), 4698c2ecf20Sopenharmony_ci AT_EA = cpu_to_le32( 0xe0), 4708c2ecf20Sopenharmony_ci AT_PROPERTY_SET = cpu_to_le32( 0xf0), 4718c2ecf20Sopenharmony_ci AT_LOGGED_UTILITY_STREAM = cpu_to_le32( 0x100), 4728c2ecf20Sopenharmony_ci AT_FIRST_USER_DEFINED_ATTRIBUTE = cpu_to_le32( 0x1000), 4738c2ecf20Sopenharmony_ci AT_END = cpu_to_le32(0xffffffff) 4748c2ecf20Sopenharmony_ci}; 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_citypedef le32 ATTR_TYPE; 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci/* 4798c2ecf20Sopenharmony_ci * The collation rules for sorting views/indexes/etc (32-bit). 4808c2ecf20Sopenharmony_ci * 4818c2ecf20Sopenharmony_ci * COLLATION_BINARY - Collate by binary compare where the first byte is most 4828c2ecf20Sopenharmony_ci * significant. 4838c2ecf20Sopenharmony_ci * COLLATION_UNICODE_STRING - Collate Unicode strings by comparing their binary 4848c2ecf20Sopenharmony_ci * Unicode values, except that when a character can be uppercased, the 4858c2ecf20Sopenharmony_ci * upper case value collates before the lower case one. 4868c2ecf20Sopenharmony_ci * COLLATION_FILE_NAME - Collate file names as Unicode strings. The collation 4878c2ecf20Sopenharmony_ci * is done very much like COLLATION_UNICODE_STRING. In fact I have no idea 4888c2ecf20Sopenharmony_ci * what the difference is. Perhaps the difference is that file names 4898c2ecf20Sopenharmony_ci * would treat some special characters in an odd way (see 4908c2ecf20Sopenharmony_ci * unistr.c::ntfs_collate_names() and unistr.c::legal_ansi_char_array[] 4918c2ecf20Sopenharmony_ci * for what I mean but COLLATION_UNICODE_STRING would not give any special 4928c2ecf20Sopenharmony_ci * treatment to any characters at all, but this is speculation. 4938c2ecf20Sopenharmony_ci * COLLATION_NTOFS_ULONG - Sorting is done according to ascending le32 key 4948c2ecf20Sopenharmony_ci * values. E.g. used for $SII index in FILE_Secure, which sorts by 4958c2ecf20Sopenharmony_ci * security_id (le32). 4968c2ecf20Sopenharmony_ci * COLLATION_NTOFS_SID - Sorting is done according to ascending SID values. 4978c2ecf20Sopenharmony_ci * E.g. used for $O index in FILE_Extend/$Quota. 4988c2ecf20Sopenharmony_ci * COLLATION_NTOFS_SECURITY_HASH - Sorting is done first by ascending hash 4998c2ecf20Sopenharmony_ci * values and second by ascending security_id values. E.g. used for $SDH 5008c2ecf20Sopenharmony_ci * index in FILE_Secure. 5018c2ecf20Sopenharmony_ci * COLLATION_NTOFS_ULONGS - Sorting is done according to a sequence of ascending 5028c2ecf20Sopenharmony_ci * le32 key values. E.g. used for $O index in FILE_Extend/$ObjId, which 5038c2ecf20Sopenharmony_ci * sorts by object_id (16-byte), by splitting up the object_id in four 5048c2ecf20Sopenharmony_ci * le32 values and using them as individual keys. E.g. take the following 5058c2ecf20Sopenharmony_ci * two security_ids, stored as follows on disk: 5068c2ecf20Sopenharmony_ci * 1st: a1 61 65 b7 65 7b d4 11 9e 3d 00 e0 81 10 42 59 5078c2ecf20Sopenharmony_ci * 2nd: 38 14 37 d2 d2 f3 d4 11 a5 21 c8 6b 79 b1 97 45 5088c2ecf20Sopenharmony_ci * To compare them, they are split into four le32 values each, like so: 5098c2ecf20Sopenharmony_ci * 1st: 0xb76561a1 0x11d47b65 0xe0003d9e 0x59421081 5108c2ecf20Sopenharmony_ci * 2nd: 0xd2371438 0x11d4f3d2 0x6bc821a5 0x4597b179 5118c2ecf20Sopenharmony_ci * Now, it is apparent why the 2nd object_id collates after the 1st: the 5128c2ecf20Sopenharmony_ci * first le32 value of the 1st object_id is less than the first le32 of 5138c2ecf20Sopenharmony_ci * the 2nd object_id. If the first le32 values of both object_ids were 5148c2ecf20Sopenharmony_ci * equal then the second le32 values would be compared, etc. 5158c2ecf20Sopenharmony_ci */ 5168c2ecf20Sopenharmony_cienum { 5178c2ecf20Sopenharmony_ci COLLATION_BINARY = cpu_to_le32(0x00), 5188c2ecf20Sopenharmony_ci COLLATION_FILE_NAME = cpu_to_le32(0x01), 5198c2ecf20Sopenharmony_ci COLLATION_UNICODE_STRING = cpu_to_le32(0x02), 5208c2ecf20Sopenharmony_ci COLLATION_NTOFS_ULONG = cpu_to_le32(0x10), 5218c2ecf20Sopenharmony_ci COLLATION_NTOFS_SID = cpu_to_le32(0x11), 5228c2ecf20Sopenharmony_ci COLLATION_NTOFS_SECURITY_HASH = cpu_to_le32(0x12), 5238c2ecf20Sopenharmony_ci COLLATION_NTOFS_ULONGS = cpu_to_le32(0x13), 5248c2ecf20Sopenharmony_ci}; 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_citypedef le32 COLLATION_RULE; 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci/* 5298c2ecf20Sopenharmony_ci * The flags (32-bit) describing attribute properties in the attribute 5308c2ecf20Sopenharmony_ci * definition structure. FIXME: This information is based on Regis's 5318c2ecf20Sopenharmony_ci * information and, according to him, it is not certain and probably 5328c2ecf20Sopenharmony_ci * incomplete. The INDEXABLE flag is fairly certainly correct as only the file 5338c2ecf20Sopenharmony_ci * name attribute has this flag set and this is the only attribute indexed in 5348c2ecf20Sopenharmony_ci * NT4. 5358c2ecf20Sopenharmony_ci */ 5368c2ecf20Sopenharmony_cienum { 5378c2ecf20Sopenharmony_ci ATTR_DEF_INDEXABLE = cpu_to_le32(0x02), /* Attribute can be 5388c2ecf20Sopenharmony_ci indexed. */ 5398c2ecf20Sopenharmony_ci ATTR_DEF_MULTIPLE = cpu_to_le32(0x04), /* Attribute type 5408c2ecf20Sopenharmony_ci can be present multiple times in the 5418c2ecf20Sopenharmony_ci mft records of an inode. */ 5428c2ecf20Sopenharmony_ci ATTR_DEF_NOT_ZERO = cpu_to_le32(0x08), /* Attribute value 5438c2ecf20Sopenharmony_ci must contain at least one non-zero 5448c2ecf20Sopenharmony_ci byte. */ 5458c2ecf20Sopenharmony_ci ATTR_DEF_INDEXED_UNIQUE = cpu_to_le32(0x10), /* Attribute must be 5468c2ecf20Sopenharmony_ci indexed and the attribute value must be 5478c2ecf20Sopenharmony_ci unique for the attribute type in all of 5488c2ecf20Sopenharmony_ci the mft records of an inode. */ 5498c2ecf20Sopenharmony_ci ATTR_DEF_NAMED_UNIQUE = cpu_to_le32(0x20), /* Attribute must be 5508c2ecf20Sopenharmony_ci named and the name must be unique for 5518c2ecf20Sopenharmony_ci the attribute type in all of the mft 5528c2ecf20Sopenharmony_ci records of an inode. */ 5538c2ecf20Sopenharmony_ci ATTR_DEF_RESIDENT = cpu_to_le32(0x40), /* Attribute must be 5548c2ecf20Sopenharmony_ci resident. */ 5558c2ecf20Sopenharmony_ci ATTR_DEF_ALWAYS_LOG = cpu_to_le32(0x80), /* Always log 5568c2ecf20Sopenharmony_ci modifications to this attribute, 5578c2ecf20Sopenharmony_ci regardless of whether it is resident or 5588c2ecf20Sopenharmony_ci non-resident. Without this, only log 5598c2ecf20Sopenharmony_ci modifications if the attribute is 5608c2ecf20Sopenharmony_ci resident. */ 5618c2ecf20Sopenharmony_ci}; 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_citypedef le32 ATTR_DEF_FLAGS; 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci/* 5668c2ecf20Sopenharmony_ci * The data attribute of FILE_AttrDef contains a sequence of attribute 5678c2ecf20Sopenharmony_ci * definitions for the NTFS volume. With this, it is supposed to be safe for an 5688c2ecf20Sopenharmony_ci * older NTFS driver to mount a volume containing a newer NTFS version without 5698c2ecf20Sopenharmony_ci * damaging it (that's the theory. In practice it's: not damaging it too much). 5708c2ecf20Sopenharmony_ci * Entries are sorted by attribute type. The flags describe whether the 5718c2ecf20Sopenharmony_ci * attribute can be resident/non-resident and possibly other things, but the 5728c2ecf20Sopenharmony_ci * actual bits are unknown. 5738c2ecf20Sopenharmony_ci */ 5748c2ecf20Sopenharmony_citypedef struct { 5758c2ecf20Sopenharmony_ci/*hex ofs*/ 5768c2ecf20Sopenharmony_ci/* 0*/ ntfschar name[0x40]; /* Unicode name of the attribute. Zero 5778c2ecf20Sopenharmony_ci terminated. */ 5788c2ecf20Sopenharmony_ci/* 80*/ ATTR_TYPE type; /* Type of the attribute. */ 5798c2ecf20Sopenharmony_ci/* 84*/ le32 display_rule; /* Default display rule. 5808c2ecf20Sopenharmony_ci FIXME: What does it mean? (AIA) */ 5818c2ecf20Sopenharmony_ci/* 88*/ COLLATION_RULE collation_rule; /* Default collation rule. */ 5828c2ecf20Sopenharmony_ci/* 8c*/ ATTR_DEF_FLAGS flags; /* Flags describing the attribute. */ 5838c2ecf20Sopenharmony_ci/* 90*/ sle64 min_size; /* Optional minimum attribute size. */ 5848c2ecf20Sopenharmony_ci/* 98*/ sle64 max_size; /* Maximum size of attribute. */ 5858c2ecf20Sopenharmony_ci/* sizeof() = 0xa0 or 160 bytes */ 5868c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) ATTR_DEF; 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci/* 5898c2ecf20Sopenharmony_ci * Attribute flags (16-bit). 5908c2ecf20Sopenharmony_ci */ 5918c2ecf20Sopenharmony_cienum { 5928c2ecf20Sopenharmony_ci ATTR_IS_COMPRESSED = cpu_to_le16(0x0001), 5938c2ecf20Sopenharmony_ci ATTR_COMPRESSION_MASK = cpu_to_le16(0x00ff), /* Compression method 5948c2ecf20Sopenharmony_ci mask. Also, first 5958c2ecf20Sopenharmony_ci illegal value. */ 5968c2ecf20Sopenharmony_ci ATTR_IS_ENCRYPTED = cpu_to_le16(0x4000), 5978c2ecf20Sopenharmony_ci ATTR_IS_SPARSE = cpu_to_le16(0x8000), 5988c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_citypedef le16 ATTR_FLAGS; 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci/* 6038c2ecf20Sopenharmony_ci * Attribute compression. 6048c2ecf20Sopenharmony_ci * 6058c2ecf20Sopenharmony_ci * Only the data attribute is ever compressed in the current ntfs driver in 6068c2ecf20Sopenharmony_ci * Windows. Further, compression is only applied when the data attribute is 6078c2ecf20Sopenharmony_ci * non-resident. Finally, to use compression, the maximum allowed cluster size 6088c2ecf20Sopenharmony_ci * on a volume is 4kib. 6098c2ecf20Sopenharmony_ci * 6108c2ecf20Sopenharmony_ci * The compression method is based on independently compressing blocks of X 6118c2ecf20Sopenharmony_ci * clusters, where X is determined from the compression_unit value found in the 6128c2ecf20Sopenharmony_ci * non-resident attribute record header (more precisely: X = 2^compression_unit 6138c2ecf20Sopenharmony_ci * clusters). On Windows NT/2k, X always is 16 clusters (compression_unit = 4). 6148c2ecf20Sopenharmony_ci * 6158c2ecf20Sopenharmony_ci * There are three different cases of how a compression block of X clusters 6168c2ecf20Sopenharmony_ci * can be stored: 6178c2ecf20Sopenharmony_ci * 6188c2ecf20Sopenharmony_ci * 1) The data in the block is all zero (a sparse block): 6198c2ecf20Sopenharmony_ci * This is stored as a sparse block in the runlist, i.e. the runlist 6208c2ecf20Sopenharmony_ci * entry has length = X and lcn = -1. The mapping pairs array actually 6218c2ecf20Sopenharmony_ci * uses a delta_lcn value length of 0, i.e. delta_lcn is not present at 6228c2ecf20Sopenharmony_ci * all, which is then interpreted by the driver as lcn = -1. 6238c2ecf20Sopenharmony_ci * NOTE: Even uncompressed files can be sparse on NTFS 3.0 volumes, then 6248c2ecf20Sopenharmony_ci * the same principles apply as above, except that the length is not 6258c2ecf20Sopenharmony_ci * restricted to being any particular value. 6268c2ecf20Sopenharmony_ci * 6278c2ecf20Sopenharmony_ci * 2) The data in the block is not compressed: 6288c2ecf20Sopenharmony_ci * This happens when compression doesn't reduce the size of the block 6298c2ecf20Sopenharmony_ci * in clusters. I.e. if compression has a small effect so that the 6308c2ecf20Sopenharmony_ci * compressed data still occupies X clusters, then the uncompressed data 6318c2ecf20Sopenharmony_ci * is stored in the block. 6328c2ecf20Sopenharmony_ci * This case is recognised by the fact that the runlist entry has 6338c2ecf20Sopenharmony_ci * length = X and lcn >= 0. The mapping pairs array stores this as 6348c2ecf20Sopenharmony_ci * normal with a run length of X and some specific delta_lcn, i.e. 6358c2ecf20Sopenharmony_ci * delta_lcn has to be present. 6368c2ecf20Sopenharmony_ci * 6378c2ecf20Sopenharmony_ci * 3) The data in the block is compressed: 6388c2ecf20Sopenharmony_ci * The common case. This case is recognised by the fact that the run 6398c2ecf20Sopenharmony_ci * list entry has length L < X and lcn >= 0. The mapping pairs array 6408c2ecf20Sopenharmony_ci * stores this as normal with a run length of X and some specific 6418c2ecf20Sopenharmony_ci * delta_lcn, i.e. delta_lcn has to be present. This runlist entry is 6428c2ecf20Sopenharmony_ci * immediately followed by a sparse entry with length = X - L and 6438c2ecf20Sopenharmony_ci * lcn = -1. The latter entry is to make up the vcn counting to the 6448c2ecf20Sopenharmony_ci * full compression block size X. 6458c2ecf20Sopenharmony_ci * 6468c2ecf20Sopenharmony_ci * In fact, life is more complicated because adjacent entries of the same type 6478c2ecf20Sopenharmony_ci * can be coalesced. This means that one has to keep track of the number of 6488c2ecf20Sopenharmony_ci * clusters handled and work on a basis of X clusters at a time being one 6498c2ecf20Sopenharmony_ci * block. An example: if length L > X this means that this particular runlist 6508c2ecf20Sopenharmony_ci * entry contains a block of length X and part of one or more blocks of length 6518c2ecf20Sopenharmony_ci * L - X. Another example: if length L < X, this does not necessarily mean that 6528c2ecf20Sopenharmony_ci * the block is compressed as it might be that the lcn changes inside the block 6538c2ecf20Sopenharmony_ci * and hence the following runlist entry describes the continuation of the 6548c2ecf20Sopenharmony_ci * potentially compressed block. The block would be compressed if the 6558c2ecf20Sopenharmony_ci * following runlist entry describes at least X - L sparse clusters, thus 6568c2ecf20Sopenharmony_ci * making up the compression block length as described in point 3 above. (Of 6578c2ecf20Sopenharmony_ci * course, there can be several runlist entries with small lengths so that the 6588c2ecf20Sopenharmony_ci * sparse entry does not follow the first data containing entry with 6598c2ecf20Sopenharmony_ci * length < X.) 6608c2ecf20Sopenharmony_ci * 6618c2ecf20Sopenharmony_ci * NOTE: At the end of the compressed attribute value, there most likely is not 6628c2ecf20Sopenharmony_ci * just the right amount of data to make up a compression block, thus this data 6638c2ecf20Sopenharmony_ci * is not even attempted to be compressed. It is just stored as is, unless 6648c2ecf20Sopenharmony_ci * the number of clusters it occupies is reduced when compressed in which case 6658c2ecf20Sopenharmony_ci * it is stored as a compressed compression block, complete with sparse 6668c2ecf20Sopenharmony_ci * clusters at the end. 6678c2ecf20Sopenharmony_ci */ 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_ci/* 6708c2ecf20Sopenharmony_ci * Flags of resident attributes (8-bit). 6718c2ecf20Sopenharmony_ci */ 6728c2ecf20Sopenharmony_cienum { 6738c2ecf20Sopenharmony_ci RESIDENT_ATTR_IS_INDEXED = 0x01, /* Attribute is referenced in an index 6748c2ecf20Sopenharmony_ci (has implications for deleting and 6758c2ecf20Sopenharmony_ci modifying the attribute). */ 6768c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_citypedef u8 RESIDENT_ATTR_FLAGS; 6798c2ecf20Sopenharmony_ci 6808c2ecf20Sopenharmony_ci/* 6818c2ecf20Sopenharmony_ci * Attribute record header. Always aligned to 8-byte boundary. 6828c2ecf20Sopenharmony_ci */ 6838c2ecf20Sopenharmony_citypedef struct { 6848c2ecf20Sopenharmony_ci/*Ofs*/ 6858c2ecf20Sopenharmony_ci/* 0*/ ATTR_TYPE type; /* The (32-bit) type of the attribute. */ 6868c2ecf20Sopenharmony_ci/* 4*/ le32 length; /* Byte size of the resident part of the 6878c2ecf20Sopenharmony_ci attribute (aligned to 8-byte boundary). 6888c2ecf20Sopenharmony_ci Used to get to the next attribute. */ 6898c2ecf20Sopenharmony_ci/* 8*/ u8 non_resident; /* If 0, attribute is resident. 6908c2ecf20Sopenharmony_ci If 1, attribute is non-resident. */ 6918c2ecf20Sopenharmony_ci/* 9*/ u8 name_length; /* Unicode character size of name of attribute. 6928c2ecf20Sopenharmony_ci 0 if unnamed. */ 6938c2ecf20Sopenharmony_ci/* 10*/ le16 name_offset; /* If name_length != 0, the byte offset to the 6948c2ecf20Sopenharmony_ci beginning of the name from the attribute 6958c2ecf20Sopenharmony_ci record. Note that the name is stored as a 6968c2ecf20Sopenharmony_ci Unicode string. When creating, place offset 6978c2ecf20Sopenharmony_ci just at the end of the record header. Then, 6988c2ecf20Sopenharmony_ci follow with attribute value or mapping pairs 6998c2ecf20Sopenharmony_ci array, resident and non-resident attributes 7008c2ecf20Sopenharmony_ci respectively, aligning to an 8-byte 7018c2ecf20Sopenharmony_ci boundary. */ 7028c2ecf20Sopenharmony_ci/* 12*/ ATTR_FLAGS flags; /* Flags describing the attribute. */ 7038c2ecf20Sopenharmony_ci/* 14*/ le16 instance; /* The instance of this attribute record. This 7048c2ecf20Sopenharmony_ci number is unique within this mft record (see 7058c2ecf20Sopenharmony_ci MFT_RECORD/next_attribute_instance notes in 7068c2ecf20Sopenharmony_ci in mft.h for more details). */ 7078c2ecf20Sopenharmony_ci/* 16*/ union { 7088c2ecf20Sopenharmony_ci /* Resident attributes. */ 7098c2ecf20Sopenharmony_ci struct { 7108c2ecf20Sopenharmony_ci/* 16 */ le32 value_length;/* Byte size of attribute value. */ 7118c2ecf20Sopenharmony_ci/* 20 */ le16 value_offset;/* Byte offset of the attribute 7128c2ecf20Sopenharmony_ci value from the start of the 7138c2ecf20Sopenharmony_ci attribute record. When creating, 7148c2ecf20Sopenharmony_ci align to 8-byte boundary if we 7158c2ecf20Sopenharmony_ci have a name present as this might 7168c2ecf20Sopenharmony_ci not have a length of a multiple 7178c2ecf20Sopenharmony_ci of 8-bytes. */ 7188c2ecf20Sopenharmony_ci/* 22 */ RESIDENT_ATTR_FLAGS flags; /* See above. */ 7198c2ecf20Sopenharmony_ci/* 23 */ s8 reserved; /* Reserved/alignment to 8-byte 7208c2ecf20Sopenharmony_ci boundary. */ 7218c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) resident; 7228c2ecf20Sopenharmony_ci /* Non-resident attributes. */ 7238c2ecf20Sopenharmony_ci struct { 7248c2ecf20Sopenharmony_ci/* 16*/ leVCN lowest_vcn;/* Lowest valid virtual cluster number 7258c2ecf20Sopenharmony_ci for this portion of the attribute value or 7268c2ecf20Sopenharmony_ci 0 if this is the only extent (usually the 7278c2ecf20Sopenharmony_ci case). - Only when an attribute list is used 7288c2ecf20Sopenharmony_ci does lowest_vcn != 0 ever occur. */ 7298c2ecf20Sopenharmony_ci/* 24*/ leVCN highest_vcn;/* Highest valid vcn of this extent of 7308c2ecf20Sopenharmony_ci the attribute value. - Usually there is only one 7318c2ecf20Sopenharmony_ci portion, so this usually equals the attribute 7328c2ecf20Sopenharmony_ci value size in clusters minus 1. Can be -1 for 7338c2ecf20Sopenharmony_ci zero length files. Can be 0 for "single extent" 7348c2ecf20Sopenharmony_ci attributes. */ 7358c2ecf20Sopenharmony_ci/* 32*/ le16 mapping_pairs_offset; /* Byte offset from the 7368c2ecf20Sopenharmony_ci beginning of the structure to the mapping pairs 7378c2ecf20Sopenharmony_ci array which contains the mappings between the 7388c2ecf20Sopenharmony_ci vcns and the logical cluster numbers (lcns). 7398c2ecf20Sopenharmony_ci When creating, place this at the end of this 7408c2ecf20Sopenharmony_ci record header aligned to 8-byte boundary. */ 7418c2ecf20Sopenharmony_ci/* 34*/ u8 compression_unit; /* The compression unit expressed 7428c2ecf20Sopenharmony_ci as the log to the base 2 of the number of 7438c2ecf20Sopenharmony_ci clusters in a compression unit. 0 means not 7448c2ecf20Sopenharmony_ci compressed. (This effectively limits the 7458c2ecf20Sopenharmony_ci compression unit size to be a power of two 7468c2ecf20Sopenharmony_ci clusters.) WinNT4 only uses a value of 4. 7478c2ecf20Sopenharmony_ci Sparse files have this set to 0 on XPSP2. */ 7488c2ecf20Sopenharmony_ci/* 35*/ u8 reserved[5]; /* Align to 8-byte boundary. */ 7498c2ecf20Sopenharmony_ci/* The sizes below are only used when lowest_vcn is zero, as otherwise it would 7508c2ecf20Sopenharmony_ci be difficult to keep them up-to-date.*/ 7518c2ecf20Sopenharmony_ci/* 40*/ sle64 allocated_size; /* Byte size of disk space 7528c2ecf20Sopenharmony_ci allocated to hold the attribute value. Always 7538c2ecf20Sopenharmony_ci is a multiple of the cluster size. When a file 7548c2ecf20Sopenharmony_ci is compressed, this field is a multiple of the 7558c2ecf20Sopenharmony_ci compression block size (2^compression_unit) and 7568c2ecf20Sopenharmony_ci it represents the logically allocated space 7578c2ecf20Sopenharmony_ci rather than the actual on disk usage. For this 7588c2ecf20Sopenharmony_ci use the compressed_size (see below). */ 7598c2ecf20Sopenharmony_ci/* 48*/ sle64 data_size; /* Byte size of the attribute 7608c2ecf20Sopenharmony_ci value. Can be larger than allocated_size if 7618c2ecf20Sopenharmony_ci attribute value is compressed or sparse. */ 7628c2ecf20Sopenharmony_ci/* 56*/ sle64 initialized_size; /* Byte size of initialized 7638c2ecf20Sopenharmony_ci portion of the attribute value. Usually equals 7648c2ecf20Sopenharmony_ci data_size. */ 7658c2ecf20Sopenharmony_ci/* sizeof(uncompressed attr) = 64*/ 7668c2ecf20Sopenharmony_ci/* 64*/ sle64 compressed_size; /* Byte size of the attribute 7678c2ecf20Sopenharmony_ci value after compression. Only present when 7688c2ecf20Sopenharmony_ci compressed or sparse. Always is a multiple of 7698c2ecf20Sopenharmony_ci the cluster size. Represents the actual amount 7708c2ecf20Sopenharmony_ci of disk space being used on the disk. */ 7718c2ecf20Sopenharmony_ci/* sizeof(compressed attr) = 72*/ 7728c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) non_resident; 7738c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) data; 7748c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) ATTR_RECORD; 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_citypedef ATTR_RECORD ATTR_REC; 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci/* 7798c2ecf20Sopenharmony_ci * File attribute flags (32-bit) appearing in the file_attributes fields of the 7808c2ecf20Sopenharmony_ci * STANDARD_INFORMATION attribute of MFT_RECORDs and the FILENAME_ATTR 7818c2ecf20Sopenharmony_ci * attributes of MFT_RECORDs and directory index entries. 7828c2ecf20Sopenharmony_ci * 7838c2ecf20Sopenharmony_ci * All of the below flags appear in the directory index entries but only some 7848c2ecf20Sopenharmony_ci * appear in the STANDARD_INFORMATION attribute whilst only some others appear 7858c2ecf20Sopenharmony_ci * in the FILENAME_ATTR attribute of MFT_RECORDs. Unless otherwise stated the 7868c2ecf20Sopenharmony_ci * flags appear in all of the above. 7878c2ecf20Sopenharmony_ci */ 7888c2ecf20Sopenharmony_cienum { 7898c2ecf20Sopenharmony_ci FILE_ATTR_READONLY = cpu_to_le32(0x00000001), 7908c2ecf20Sopenharmony_ci FILE_ATTR_HIDDEN = cpu_to_le32(0x00000002), 7918c2ecf20Sopenharmony_ci FILE_ATTR_SYSTEM = cpu_to_le32(0x00000004), 7928c2ecf20Sopenharmony_ci /* Old DOS volid. Unused in NT. = cpu_to_le32(0x00000008), */ 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ci FILE_ATTR_DIRECTORY = cpu_to_le32(0x00000010), 7958c2ecf20Sopenharmony_ci /* Note, FILE_ATTR_DIRECTORY is not considered valid in NT. It is 7968c2ecf20Sopenharmony_ci reserved for the DOS SUBDIRECTORY flag. */ 7978c2ecf20Sopenharmony_ci FILE_ATTR_ARCHIVE = cpu_to_le32(0x00000020), 7988c2ecf20Sopenharmony_ci FILE_ATTR_DEVICE = cpu_to_le32(0x00000040), 7998c2ecf20Sopenharmony_ci FILE_ATTR_NORMAL = cpu_to_le32(0x00000080), 8008c2ecf20Sopenharmony_ci 8018c2ecf20Sopenharmony_ci FILE_ATTR_TEMPORARY = cpu_to_le32(0x00000100), 8028c2ecf20Sopenharmony_ci FILE_ATTR_SPARSE_FILE = cpu_to_le32(0x00000200), 8038c2ecf20Sopenharmony_ci FILE_ATTR_REPARSE_POINT = cpu_to_le32(0x00000400), 8048c2ecf20Sopenharmony_ci FILE_ATTR_COMPRESSED = cpu_to_le32(0x00000800), 8058c2ecf20Sopenharmony_ci 8068c2ecf20Sopenharmony_ci FILE_ATTR_OFFLINE = cpu_to_le32(0x00001000), 8078c2ecf20Sopenharmony_ci FILE_ATTR_NOT_CONTENT_INDEXED = cpu_to_le32(0x00002000), 8088c2ecf20Sopenharmony_ci FILE_ATTR_ENCRYPTED = cpu_to_le32(0x00004000), 8098c2ecf20Sopenharmony_ci 8108c2ecf20Sopenharmony_ci FILE_ATTR_VALID_FLAGS = cpu_to_le32(0x00007fb7), 8118c2ecf20Sopenharmony_ci /* Note, FILE_ATTR_VALID_FLAGS masks out the old DOS VolId and the 8128c2ecf20Sopenharmony_ci FILE_ATTR_DEVICE and preserves everything else. This mask is used 8138c2ecf20Sopenharmony_ci to obtain all flags that are valid for reading. */ 8148c2ecf20Sopenharmony_ci FILE_ATTR_VALID_SET_FLAGS = cpu_to_le32(0x000031a7), 8158c2ecf20Sopenharmony_ci /* Note, FILE_ATTR_VALID_SET_FLAGS masks out the old DOS VolId, the 8168c2ecf20Sopenharmony_ci F_A_DEVICE, F_A_DIRECTORY, F_A_SPARSE_FILE, F_A_REPARSE_POINT, 8178c2ecf20Sopenharmony_ci F_A_COMPRESSED, and F_A_ENCRYPTED and preserves the rest. This mask 8188c2ecf20Sopenharmony_ci is used to obtain all flags that are valid for setting. */ 8198c2ecf20Sopenharmony_ci /* 8208c2ecf20Sopenharmony_ci * The flag FILE_ATTR_DUP_FILENAME_INDEX_PRESENT is present in all 8218c2ecf20Sopenharmony_ci * FILENAME_ATTR attributes but not in the STANDARD_INFORMATION 8228c2ecf20Sopenharmony_ci * attribute of an mft record. 8238c2ecf20Sopenharmony_ci */ 8248c2ecf20Sopenharmony_ci FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT = cpu_to_le32(0x10000000), 8258c2ecf20Sopenharmony_ci /* Note, this is a copy of the corresponding bit from the mft record, 8268c2ecf20Sopenharmony_ci telling us whether this is a directory or not, i.e. whether it has 8278c2ecf20Sopenharmony_ci an index root attribute or not. */ 8288c2ecf20Sopenharmony_ci FILE_ATTR_DUP_VIEW_INDEX_PRESENT = cpu_to_le32(0x20000000), 8298c2ecf20Sopenharmony_ci /* Note, this is a copy of the corresponding bit from the mft record, 8308c2ecf20Sopenharmony_ci telling us whether this file has a view index present (eg. object id 8318c2ecf20Sopenharmony_ci index, quota index, one of the security indexes or the encrypting 8328c2ecf20Sopenharmony_ci filesystem related indexes). */ 8338c2ecf20Sopenharmony_ci}; 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_citypedef le32 FILE_ATTR_FLAGS; 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci/* 8388c2ecf20Sopenharmony_ci * NOTE on times in NTFS: All times are in MS standard time format, i.e. they 8398c2ecf20Sopenharmony_ci * are the number of 100-nanosecond intervals since 1st January 1601, 00:00:00 8408c2ecf20Sopenharmony_ci * universal coordinated time (UTC). (In Linux time starts 1st January 1970, 8418c2ecf20Sopenharmony_ci * 00:00:00 UTC and is stored as the number of 1-second intervals since then.) 8428c2ecf20Sopenharmony_ci */ 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_ci/* 8458c2ecf20Sopenharmony_ci * Attribute: Standard information (0x10). 8468c2ecf20Sopenharmony_ci * 8478c2ecf20Sopenharmony_ci * NOTE: Always resident. 8488c2ecf20Sopenharmony_ci * NOTE: Present in all base file records on a volume. 8498c2ecf20Sopenharmony_ci * NOTE: There is conflicting information about the meaning of each of the time 8508c2ecf20Sopenharmony_ci * fields but the meaning as defined below has been verified to be 8518c2ecf20Sopenharmony_ci * correct by practical experimentation on Windows NT4 SP6a and is hence 8528c2ecf20Sopenharmony_ci * assumed to be the one and only correct interpretation. 8538c2ecf20Sopenharmony_ci */ 8548c2ecf20Sopenharmony_citypedef struct { 8558c2ecf20Sopenharmony_ci/*Ofs*/ 8568c2ecf20Sopenharmony_ci/* 0*/ sle64 creation_time; /* Time file was created. Updated when 8578c2ecf20Sopenharmony_ci a filename is changed(?). */ 8588c2ecf20Sopenharmony_ci/* 8*/ sle64 last_data_change_time; /* Time the data attribute was last 8598c2ecf20Sopenharmony_ci modified. */ 8608c2ecf20Sopenharmony_ci/* 16*/ sle64 last_mft_change_time; /* Time this mft record was last 8618c2ecf20Sopenharmony_ci modified. */ 8628c2ecf20Sopenharmony_ci/* 24*/ sle64 last_access_time; /* Approximate time when the file was 8638c2ecf20Sopenharmony_ci last accessed (obviously this is not 8648c2ecf20Sopenharmony_ci updated on read-only volumes). In 8658c2ecf20Sopenharmony_ci Windows this is only updated when 8668c2ecf20Sopenharmony_ci accessed if some time delta has 8678c2ecf20Sopenharmony_ci passed since the last update. Also, 8688c2ecf20Sopenharmony_ci last access time updates can be 8698c2ecf20Sopenharmony_ci disabled altogether for speed. */ 8708c2ecf20Sopenharmony_ci/* 32*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */ 8718c2ecf20Sopenharmony_ci/* 36*/ union { 8728c2ecf20Sopenharmony_ci /* NTFS 1.2 */ 8738c2ecf20Sopenharmony_ci struct { 8748c2ecf20Sopenharmony_ci /* 36*/ u8 reserved12[12]; /* Reserved/alignment to 8-byte 8758c2ecf20Sopenharmony_ci boundary. */ 8768c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) v1; 8778c2ecf20Sopenharmony_ci /* sizeof() = 48 bytes */ 8788c2ecf20Sopenharmony_ci /* NTFS 3.x */ 8798c2ecf20Sopenharmony_ci struct { 8808c2ecf20Sopenharmony_ci/* 8818c2ecf20Sopenharmony_ci * If a volume has been upgraded from a previous NTFS version, then these 8828c2ecf20Sopenharmony_ci * fields are present only if the file has been accessed since the upgrade. 8838c2ecf20Sopenharmony_ci * Recognize the difference by comparing the length of the resident attribute 8848c2ecf20Sopenharmony_ci * value. If it is 48, then the following fields are missing. If it is 72 then 8858c2ecf20Sopenharmony_ci * the fields are present. Maybe just check like this: 8868c2ecf20Sopenharmony_ci * if (resident.ValueLength < sizeof(STANDARD_INFORMATION)) { 8878c2ecf20Sopenharmony_ci * Assume NTFS 1.2- format. 8888c2ecf20Sopenharmony_ci * If (volume version is 3.x) 8898c2ecf20Sopenharmony_ci * Upgrade attribute to NTFS 3.x format. 8908c2ecf20Sopenharmony_ci * else 8918c2ecf20Sopenharmony_ci * Use NTFS 1.2- format for access. 8928c2ecf20Sopenharmony_ci * } else 8938c2ecf20Sopenharmony_ci * Use NTFS 3.x format for access. 8948c2ecf20Sopenharmony_ci * Only problem is that it might be legal to set the length of the value to 8958c2ecf20Sopenharmony_ci * arbitrarily large values thus spoiling this check. - But chkdsk probably 8968c2ecf20Sopenharmony_ci * views that as a corruption, assuming that it behaves like this for all 8978c2ecf20Sopenharmony_ci * attributes. 8988c2ecf20Sopenharmony_ci */ 8998c2ecf20Sopenharmony_ci /* 36*/ le32 maximum_versions; /* Maximum allowed versions for 9008c2ecf20Sopenharmony_ci file. Zero if version numbering is disabled. */ 9018c2ecf20Sopenharmony_ci /* 40*/ le32 version_number; /* This file's version (if any). 9028c2ecf20Sopenharmony_ci Set to zero if maximum_versions is zero. */ 9038c2ecf20Sopenharmony_ci /* 44*/ le32 class_id; /* Class id from bidirectional 9048c2ecf20Sopenharmony_ci class id index (?). */ 9058c2ecf20Sopenharmony_ci /* 48*/ le32 owner_id; /* Owner_id of the user owning 9068c2ecf20Sopenharmony_ci the file. Translate via $Q index in FILE_Extend 9078c2ecf20Sopenharmony_ci /$Quota to the quota control entry for the user 9088c2ecf20Sopenharmony_ci owning the file. Zero if quotas are disabled. */ 9098c2ecf20Sopenharmony_ci /* 52*/ le32 security_id; /* Security_id for the file. 9108c2ecf20Sopenharmony_ci Translate via $SII index and $SDS data stream 9118c2ecf20Sopenharmony_ci in FILE_Secure to the security descriptor. */ 9128c2ecf20Sopenharmony_ci /* 56*/ le64 quota_charged; /* Byte size of the charge to 9138c2ecf20Sopenharmony_ci the quota for all streams of the file. Note: Is 9148c2ecf20Sopenharmony_ci zero if quotas are disabled. */ 9158c2ecf20Sopenharmony_ci /* 64*/ leUSN usn; /* Last update sequence number 9168c2ecf20Sopenharmony_ci of the file. This is a direct index into the 9178c2ecf20Sopenharmony_ci transaction log file ($UsnJrnl). It is zero if 9188c2ecf20Sopenharmony_ci the usn journal is disabled or this file has 9198c2ecf20Sopenharmony_ci not been subject to logging yet. See usnjrnl.h 9208c2ecf20Sopenharmony_ci for details. */ 9218c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) v3; 9228c2ecf20Sopenharmony_ci /* sizeof() = 72 bytes (NTFS 3.x) */ 9238c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) ver; 9248c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) STANDARD_INFORMATION; 9258c2ecf20Sopenharmony_ci 9268c2ecf20Sopenharmony_ci/* 9278c2ecf20Sopenharmony_ci * Attribute: Attribute list (0x20). 9288c2ecf20Sopenharmony_ci * 9298c2ecf20Sopenharmony_ci * - Can be either resident or non-resident. 9308c2ecf20Sopenharmony_ci * - Value consists of a sequence of variable length, 8-byte aligned, 9318c2ecf20Sopenharmony_ci * ATTR_LIST_ENTRY records. 9328c2ecf20Sopenharmony_ci * - The list is not terminated by anything at all! The only way to know when 9338c2ecf20Sopenharmony_ci * the end is reached is to keep track of the current offset and compare it to 9348c2ecf20Sopenharmony_ci * the attribute value size. 9358c2ecf20Sopenharmony_ci * - The attribute list attribute contains one entry for each attribute of 9368c2ecf20Sopenharmony_ci * the file in which the list is located, except for the list attribute 9378c2ecf20Sopenharmony_ci * itself. The list is sorted: first by attribute type, second by attribute 9388c2ecf20Sopenharmony_ci * name (if present), third by instance number. The extents of one 9398c2ecf20Sopenharmony_ci * non-resident attribute (if present) immediately follow after the initial 9408c2ecf20Sopenharmony_ci * extent. They are ordered by lowest_vcn and have their instace set to zero. 9418c2ecf20Sopenharmony_ci * It is not allowed to have two attributes with all sorting keys equal. 9428c2ecf20Sopenharmony_ci * - Further restrictions: 9438c2ecf20Sopenharmony_ci * - If not resident, the vcn to lcn mapping array has to fit inside the 9448c2ecf20Sopenharmony_ci * base mft record. 9458c2ecf20Sopenharmony_ci * - The attribute list attribute value has a maximum size of 256kb. This 9468c2ecf20Sopenharmony_ci * is imposed by the Windows cache manager. 9478c2ecf20Sopenharmony_ci * - Attribute lists are only used when the attributes of mft record do not 9488c2ecf20Sopenharmony_ci * fit inside the mft record despite all attributes (that can be made 9498c2ecf20Sopenharmony_ci * non-resident) having been made non-resident. This can happen e.g. when: 9508c2ecf20Sopenharmony_ci * - File has a large number of hard links (lots of file name 9518c2ecf20Sopenharmony_ci * attributes present). 9528c2ecf20Sopenharmony_ci * - The mapping pairs array of some non-resident attribute becomes so 9538c2ecf20Sopenharmony_ci * large due to fragmentation that it overflows the mft record. 9548c2ecf20Sopenharmony_ci * - The security descriptor is very complex (not applicable to 9558c2ecf20Sopenharmony_ci * NTFS 3.0 volumes). 9568c2ecf20Sopenharmony_ci * - There are many named streams. 9578c2ecf20Sopenharmony_ci */ 9588c2ecf20Sopenharmony_citypedef struct { 9598c2ecf20Sopenharmony_ci/*Ofs*/ 9608c2ecf20Sopenharmony_ci/* 0*/ ATTR_TYPE type; /* Type of referenced attribute. */ 9618c2ecf20Sopenharmony_ci/* 4*/ le16 length; /* Byte size of this entry (8-byte aligned). */ 9628c2ecf20Sopenharmony_ci/* 6*/ u8 name_length; /* Size in Unicode chars of the name of the 9638c2ecf20Sopenharmony_ci attribute or 0 if unnamed. */ 9648c2ecf20Sopenharmony_ci/* 7*/ u8 name_offset; /* Byte offset to beginning of attribute name 9658c2ecf20Sopenharmony_ci (always set this to where the name would 9668c2ecf20Sopenharmony_ci start even if unnamed). */ 9678c2ecf20Sopenharmony_ci/* 8*/ leVCN lowest_vcn; /* Lowest virtual cluster number of this portion 9688c2ecf20Sopenharmony_ci of the attribute value. This is usually 0. It 9698c2ecf20Sopenharmony_ci is non-zero for the case where one attribute 9708c2ecf20Sopenharmony_ci does not fit into one mft record and thus 9718c2ecf20Sopenharmony_ci several mft records are allocated to hold 9728c2ecf20Sopenharmony_ci this attribute. In the latter case, each mft 9738c2ecf20Sopenharmony_ci record holds one extent of the attribute and 9748c2ecf20Sopenharmony_ci there is one attribute list entry for each 9758c2ecf20Sopenharmony_ci extent. NOTE: This is DEFINITELY a signed 9768c2ecf20Sopenharmony_ci value! The windows driver uses cmp, followed 9778c2ecf20Sopenharmony_ci by jg when comparing this, thus it treats it 9788c2ecf20Sopenharmony_ci as signed. */ 9798c2ecf20Sopenharmony_ci/* 16*/ leMFT_REF mft_reference;/* The reference of the mft record holding 9808c2ecf20Sopenharmony_ci the ATTR_RECORD for this portion of the 9818c2ecf20Sopenharmony_ci attribute value. */ 9828c2ecf20Sopenharmony_ci/* 24*/ le16 instance; /* If lowest_vcn = 0, the instance of the 9838c2ecf20Sopenharmony_ci attribute being referenced; otherwise 0. */ 9848c2ecf20Sopenharmony_ci/* 26*/ ntfschar name[0]; /* Use when creating only. When reading use 9858c2ecf20Sopenharmony_ci name_offset to determine the location of the 9868c2ecf20Sopenharmony_ci name. */ 9878c2ecf20Sopenharmony_ci/* sizeof() = 26 + (attribute_name_length * 2) bytes */ 9888c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) ATTR_LIST_ENTRY; 9898c2ecf20Sopenharmony_ci 9908c2ecf20Sopenharmony_ci/* 9918c2ecf20Sopenharmony_ci * The maximum allowed length for a file name. 9928c2ecf20Sopenharmony_ci */ 9938c2ecf20Sopenharmony_ci#define MAXIMUM_FILE_NAME_LENGTH 255 9948c2ecf20Sopenharmony_ci 9958c2ecf20Sopenharmony_ci/* 9968c2ecf20Sopenharmony_ci * Possible namespaces for filenames in ntfs (8-bit). 9978c2ecf20Sopenharmony_ci */ 9988c2ecf20Sopenharmony_cienum { 9998c2ecf20Sopenharmony_ci FILE_NAME_POSIX = 0x00, 10008c2ecf20Sopenharmony_ci /* This is the largest namespace. It is case sensitive and allows all 10018c2ecf20Sopenharmony_ci Unicode characters except for: '\0' and '/'. Beware that in 10028c2ecf20Sopenharmony_ci WinNT/2k/2003 by default files which eg have the same name except 10038c2ecf20Sopenharmony_ci for their case will not be distinguished by the standard utilities 10048c2ecf20Sopenharmony_ci and thus a "del filename" will delete both "filename" and "fileName" 10058c2ecf20Sopenharmony_ci without warning. However if for example Services For Unix (SFU) are 10068c2ecf20Sopenharmony_ci installed and the case sensitive option was enabled at installation 10078c2ecf20Sopenharmony_ci time, then you can create/access/delete such files. 10088c2ecf20Sopenharmony_ci Note that even SFU places restrictions on the filenames beyond the 10098c2ecf20Sopenharmony_ci '\0' and '/' and in particular the following set of characters is 10108c2ecf20Sopenharmony_ci not allowed: '"', '/', '<', '>', '\'. All other characters, 10118c2ecf20Sopenharmony_ci including the ones no allowed in WIN32 namespace are allowed. 10128c2ecf20Sopenharmony_ci Tested with SFU 3.5 (this is now free) running on Windows XP. */ 10138c2ecf20Sopenharmony_ci FILE_NAME_WIN32 = 0x01, 10148c2ecf20Sopenharmony_ci /* The standard WinNT/2k NTFS long filenames. Case insensitive. All 10158c2ecf20Sopenharmony_ci Unicode chars except: '\0', '"', '*', '/', ':', '<', '>', '?', '\', 10168c2ecf20Sopenharmony_ci and '|'. Further, names cannot end with a '.' or a space. */ 10178c2ecf20Sopenharmony_ci FILE_NAME_DOS = 0x02, 10188c2ecf20Sopenharmony_ci /* The standard DOS filenames (8.3 format). Uppercase only. All 8-bit 10198c2ecf20Sopenharmony_ci characters greater space, except: '"', '*', '+', ',', '/', ':', ';', 10208c2ecf20Sopenharmony_ci '<', '=', '>', '?', and '\'. */ 10218c2ecf20Sopenharmony_ci FILE_NAME_WIN32_AND_DOS = 0x03, 10228c2ecf20Sopenharmony_ci /* 3 means that both the Win32 and the DOS filenames are identical and 10238c2ecf20Sopenharmony_ci hence have been saved in this single filename record. */ 10248c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 10258c2ecf20Sopenharmony_ci 10268c2ecf20Sopenharmony_citypedef u8 FILE_NAME_TYPE_FLAGS; 10278c2ecf20Sopenharmony_ci 10288c2ecf20Sopenharmony_ci/* 10298c2ecf20Sopenharmony_ci * Attribute: Filename (0x30). 10308c2ecf20Sopenharmony_ci * 10318c2ecf20Sopenharmony_ci * NOTE: Always resident. 10328c2ecf20Sopenharmony_ci * NOTE: All fields, except the parent_directory, are only updated when the 10338c2ecf20Sopenharmony_ci * filename is changed. Until then, they just become out of sync with 10348c2ecf20Sopenharmony_ci * reality and the more up to date values are present in the standard 10358c2ecf20Sopenharmony_ci * information attribute. 10368c2ecf20Sopenharmony_ci * NOTE: There is conflicting information about the meaning of each of the time 10378c2ecf20Sopenharmony_ci * fields but the meaning as defined below has been verified to be 10388c2ecf20Sopenharmony_ci * correct by practical experimentation on Windows NT4 SP6a and is hence 10398c2ecf20Sopenharmony_ci * assumed to be the one and only correct interpretation. 10408c2ecf20Sopenharmony_ci */ 10418c2ecf20Sopenharmony_citypedef struct { 10428c2ecf20Sopenharmony_ci/*hex ofs*/ 10438c2ecf20Sopenharmony_ci/* 0*/ leMFT_REF parent_directory; /* Directory this filename is 10448c2ecf20Sopenharmony_ci referenced from. */ 10458c2ecf20Sopenharmony_ci/* 8*/ sle64 creation_time; /* Time file was created. */ 10468c2ecf20Sopenharmony_ci/* 10*/ sle64 last_data_change_time; /* Time the data attribute was last 10478c2ecf20Sopenharmony_ci modified. */ 10488c2ecf20Sopenharmony_ci/* 18*/ sle64 last_mft_change_time; /* Time this mft record was last 10498c2ecf20Sopenharmony_ci modified. */ 10508c2ecf20Sopenharmony_ci/* 20*/ sle64 last_access_time; /* Time this mft record was last 10518c2ecf20Sopenharmony_ci accessed. */ 10528c2ecf20Sopenharmony_ci/* 28*/ sle64 allocated_size; /* Byte size of on-disk allocated space 10538c2ecf20Sopenharmony_ci for the unnamed data attribute. So 10548c2ecf20Sopenharmony_ci for normal $DATA, this is the 10558c2ecf20Sopenharmony_ci allocated_size from the unnamed 10568c2ecf20Sopenharmony_ci $DATA attribute and for compressed 10578c2ecf20Sopenharmony_ci and/or sparse $DATA, this is the 10588c2ecf20Sopenharmony_ci compressed_size from the unnamed 10598c2ecf20Sopenharmony_ci $DATA attribute. For a directory or 10608c2ecf20Sopenharmony_ci other inode without an unnamed $DATA 10618c2ecf20Sopenharmony_ci attribute, this is always 0. NOTE: 10628c2ecf20Sopenharmony_ci This is a multiple of the cluster 10638c2ecf20Sopenharmony_ci size. */ 10648c2ecf20Sopenharmony_ci/* 30*/ sle64 data_size; /* Byte size of actual data in unnamed 10658c2ecf20Sopenharmony_ci data attribute. For a directory or 10668c2ecf20Sopenharmony_ci other inode without an unnamed $DATA 10678c2ecf20Sopenharmony_ci attribute, this is always 0. */ 10688c2ecf20Sopenharmony_ci/* 38*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */ 10698c2ecf20Sopenharmony_ci/* 3c*/ union { 10708c2ecf20Sopenharmony_ci /* 3c*/ struct { 10718c2ecf20Sopenharmony_ci /* 3c*/ le16 packed_ea_size; /* Size of the buffer needed to 10728c2ecf20Sopenharmony_ci pack the extended attributes 10738c2ecf20Sopenharmony_ci (EAs), if such are present.*/ 10748c2ecf20Sopenharmony_ci /* 3e*/ le16 reserved; /* Reserved for alignment. */ 10758c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) ea; 10768c2ecf20Sopenharmony_ci /* 3c*/ struct { 10778c2ecf20Sopenharmony_ci /* 3c*/ le32 reparse_point_tag; /* Type of reparse point, 10788c2ecf20Sopenharmony_ci present only in reparse 10798c2ecf20Sopenharmony_ci points and only if there are 10808c2ecf20Sopenharmony_ci no EAs. */ 10818c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) rp; 10828c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) type; 10838c2ecf20Sopenharmony_ci/* 40*/ u8 file_name_length; /* Length of file name in 10848c2ecf20Sopenharmony_ci (Unicode) characters. */ 10858c2ecf20Sopenharmony_ci/* 41*/ FILE_NAME_TYPE_FLAGS file_name_type; /* Namespace of the file name.*/ 10868c2ecf20Sopenharmony_ci/* 42*/ ntfschar file_name[0]; /* File name in Unicode. */ 10878c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) FILE_NAME_ATTR; 10888c2ecf20Sopenharmony_ci 10898c2ecf20Sopenharmony_ci/* 10908c2ecf20Sopenharmony_ci * GUID structures store globally unique identifiers (GUID). A GUID is a 10918c2ecf20Sopenharmony_ci * 128-bit value consisting of one group of eight hexadecimal digits, followed 10928c2ecf20Sopenharmony_ci * by three groups of four hexadecimal digits each, followed by one group of 10938c2ecf20Sopenharmony_ci * twelve hexadecimal digits. GUIDs are Microsoft's implementation of the 10948c2ecf20Sopenharmony_ci * distributed computing environment (DCE) universally unique identifier (UUID). 10958c2ecf20Sopenharmony_ci * Example of a GUID: 10968c2ecf20Sopenharmony_ci * 1F010768-5A73-BC91-0010A52216A7 10978c2ecf20Sopenharmony_ci */ 10988c2ecf20Sopenharmony_citypedef struct { 10998c2ecf20Sopenharmony_ci le32 data1; /* The first eight hexadecimal digits of the GUID. */ 11008c2ecf20Sopenharmony_ci le16 data2; /* The first group of four hexadecimal digits. */ 11018c2ecf20Sopenharmony_ci le16 data3; /* The second group of four hexadecimal digits. */ 11028c2ecf20Sopenharmony_ci u8 data4[8]; /* The first two bytes are the third group of four 11038c2ecf20Sopenharmony_ci hexadecimal digits. The remaining six bytes are the 11048c2ecf20Sopenharmony_ci final 12 hexadecimal digits. */ 11058c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) GUID; 11068c2ecf20Sopenharmony_ci 11078c2ecf20Sopenharmony_ci/* 11088c2ecf20Sopenharmony_ci * FILE_Extend/$ObjId contains an index named $O. This index contains all 11098c2ecf20Sopenharmony_ci * object_ids present on the volume as the index keys and the corresponding 11108c2ecf20Sopenharmony_ci * mft_record numbers as the index entry data parts. The data part (defined 11118c2ecf20Sopenharmony_ci * below) also contains three other object_ids: 11128c2ecf20Sopenharmony_ci * birth_volume_id - object_id of FILE_Volume on which the file was first 11138c2ecf20Sopenharmony_ci * created. Optional (i.e. can be zero). 11148c2ecf20Sopenharmony_ci * birth_object_id - object_id of file when it was first created. Usually 11158c2ecf20Sopenharmony_ci * equals the object_id. Optional (i.e. can be zero). 11168c2ecf20Sopenharmony_ci * domain_id - Reserved (always zero). 11178c2ecf20Sopenharmony_ci */ 11188c2ecf20Sopenharmony_citypedef struct { 11198c2ecf20Sopenharmony_ci leMFT_REF mft_reference;/* Mft record containing the object_id in 11208c2ecf20Sopenharmony_ci the index entry key. */ 11218c2ecf20Sopenharmony_ci union { 11228c2ecf20Sopenharmony_ci struct { 11238c2ecf20Sopenharmony_ci GUID birth_volume_id; 11248c2ecf20Sopenharmony_ci GUID birth_object_id; 11258c2ecf20Sopenharmony_ci GUID domain_id; 11268c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) origin; 11278c2ecf20Sopenharmony_ci u8 extended_info[48]; 11288c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) opt; 11298c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) OBJ_ID_INDEX_DATA; 11308c2ecf20Sopenharmony_ci 11318c2ecf20Sopenharmony_ci/* 11328c2ecf20Sopenharmony_ci * Attribute: Object id (NTFS 3.0+) (0x40). 11338c2ecf20Sopenharmony_ci * 11348c2ecf20Sopenharmony_ci * NOTE: Always resident. 11358c2ecf20Sopenharmony_ci */ 11368c2ecf20Sopenharmony_citypedef struct { 11378c2ecf20Sopenharmony_ci GUID object_id; /* Unique id assigned to the 11388c2ecf20Sopenharmony_ci file.*/ 11398c2ecf20Sopenharmony_ci /* The following fields are optional. The attribute value size is 16 11408c2ecf20Sopenharmony_ci bytes, i.e. sizeof(GUID), if these are not present at all. Note, 11418c2ecf20Sopenharmony_ci the entries can be present but one or more (or all) can be zero 11428c2ecf20Sopenharmony_ci meaning that that particular value(s) is(are) not defined. */ 11438c2ecf20Sopenharmony_ci union { 11448c2ecf20Sopenharmony_ci struct { 11458c2ecf20Sopenharmony_ci GUID birth_volume_id; /* Unique id of volume on which 11468c2ecf20Sopenharmony_ci the file was first created.*/ 11478c2ecf20Sopenharmony_ci GUID birth_object_id; /* Unique id of file when it was 11488c2ecf20Sopenharmony_ci first created. */ 11498c2ecf20Sopenharmony_ci GUID domain_id; /* Reserved, zero. */ 11508c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) origin; 11518c2ecf20Sopenharmony_ci u8 extended_info[48]; 11528c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) opt; 11538c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) OBJECT_ID_ATTR; 11548c2ecf20Sopenharmony_ci 11558c2ecf20Sopenharmony_ci/* 11568c2ecf20Sopenharmony_ci * The pre-defined IDENTIFIER_AUTHORITIES used as SID_IDENTIFIER_AUTHORITY in 11578c2ecf20Sopenharmony_ci * the SID structure (see below). 11588c2ecf20Sopenharmony_ci */ 11598c2ecf20Sopenharmony_ci//typedef enum { /* SID string prefix. */ 11608c2ecf20Sopenharmony_ci// SECURITY_NULL_SID_AUTHORITY = {0, 0, 0, 0, 0, 0}, /* S-1-0 */ 11618c2ecf20Sopenharmony_ci// SECURITY_WORLD_SID_AUTHORITY = {0, 0, 0, 0, 0, 1}, /* S-1-1 */ 11628c2ecf20Sopenharmony_ci// SECURITY_LOCAL_SID_AUTHORITY = {0, 0, 0, 0, 0, 2}, /* S-1-2 */ 11638c2ecf20Sopenharmony_ci// SECURITY_CREATOR_SID_AUTHORITY = {0, 0, 0, 0, 0, 3}, /* S-1-3 */ 11648c2ecf20Sopenharmony_ci// SECURITY_NON_UNIQUE_AUTHORITY = {0, 0, 0, 0, 0, 4}, /* S-1-4 */ 11658c2ecf20Sopenharmony_ci// SECURITY_NT_SID_AUTHORITY = {0, 0, 0, 0, 0, 5}, /* S-1-5 */ 11668c2ecf20Sopenharmony_ci//} IDENTIFIER_AUTHORITIES; 11678c2ecf20Sopenharmony_ci 11688c2ecf20Sopenharmony_ci/* 11698c2ecf20Sopenharmony_ci * These relative identifiers (RIDs) are used with the above identifier 11708c2ecf20Sopenharmony_ci * authorities to make up universal well-known SIDs. 11718c2ecf20Sopenharmony_ci * 11728c2ecf20Sopenharmony_ci * Note: The relative identifier (RID) refers to the portion of a SID, which 11738c2ecf20Sopenharmony_ci * identifies a user or group in relation to the authority that issued the SID. 11748c2ecf20Sopenharmony_ci * For example, the universal well-known SID Creator Owner ID (S-1-3-0) is 11758c2ecf20Sopenharmony_ci * made up of the identifier authority SECURITY_CREATOR_SID_AUTHORITY (3) and 11768c2ecf20Sopenharmony_ci * the relative identifier SECURITY_CREATOR_OWNER_RID (0). 11778c2ecf20Sopenharmony_ci */ 11788c2ecf20Sopenharmony_citypedef enum { /* Identifier authority. */ 11798c2ecf20Sopenharmony_ci SECURITY_NULL_RID = 0, /* S-1-0 */ 11808c2ecf20Sopenharmony_ci SECURITY_WORLD_RID = 0, /* S-1-1 */ 11818c2ecf20Sopenharmony_ci SECURITY_LOCAL_RID = 0, /* S-1-2 */ 11828c2ecf20Sopenharmony_ci 11838c2ecf20Sopenharmony_ci SECURITY_CREATOR_OWNER_RID = 0, /* S-1-3 */ 11848c2ecf20Sopenharmony_ci SECURITY_CREATOR_GROUP_RID = 1, /* S-1-3 */ 11858c2ecf20Sopenharmony_ci 11868c2ecf20Sopenharmony_ci SECURITY_CREATOR_OWNER_SERVER_RID = 2, /* S-1-3 */ 11878c2ecf20Sopenharmony_ci SECURITY_CREATOR_GROUP_SERVER_RID = 3, /* S-1-3 */ 11888c2ecf20Sopenharmony_ci 11898c2ecf20Sopenharmony_ci SECURITY_DIALUP_RID = 1, 11908c2ecf20Sopenharmony_ci SECURITY_NETWORK_RID = 2, 11918c2ecf20Sopenharmony_ci SECURITY_BATCH_RID = 3, 11928c2ecf20Sopenharmony_ci SECURITY_INTERACTIVE_RID = 4, 11938c2ecf20Sopenharmony_ci SECURITY_SERVICE_RID = 6, 11948c2ecf20Sopenharmony_ci SECURITY_ANONYMOUS_LOGON_RID = 7, 11958c2ecf20Sopenharmony_ci SECURITY_PROXY_RID = 8, 11968c2ecf20Sopenharmony_ci SECURITY_ENTERPRISE_CONTROLLERS_RID=9, 11978c2ecf20Sopenharmony_ci SECURITY_SERVER_LOGON_RID = 9, 11988c2ecf20Sopenharmony_ci SECURITY_PRINCIPAL_SELF_RID = 0xa, 11998c2ecf20Sopenharmony_ci SECURITY_AUTHENTICATED_USER_RID = 0xb, 12008c2ecf20Sopenharmony_ci SECURITY_RESTRICTED_CODE_RID = 0xc, 12018c2ecf20Sopenharmony_ci SECURITY_TERMINAL_SERVER_RID = 0xd, 12028c2ecf20Sopenharmony_ci 12038c2ecf20Sopenharmony_ci SECURITY_LOGON_IDS_RID = 5, 12048c2ecf20Sopenharmony_ci SECURITY_LOGON_IDS_RID_COUNT = 3, 12058c2ecf20Sopenharmony_ci 12068c2ecf20Sopenharmony_ci SECURITY_LOCAL_SYSTEM_RID = 0x12, 12078c2ecf20Sopenharmony_ci 12088c2ecf20Sopenharmony_ci SECURITY_NT_NON_UNIQUE = 0x15, 12098c2ecf20Sopenharmony_ci 12108c2ecf20Sopenharmony_ci SECURITY_BUILTIN_DOMAIN_RID = 0x20, 12118c2ecf20Sopenharmony_ci 12128c2ecf20Sopenharmony_ci /* 12138c2ecf20Sopenharmony_ci * Well-known domain relative sub-authority values (RIDs). 12148c2ecf20Sopenharmony_ci */ 12158c2ecf20Sopenharmony_ci 12168c2ecf20Sopenharmony_ci /* Users. */ 12178c2ecf20Sopenharmony_ci DOMAIN_USER_RID_ADMIN = 0x1f4, 12188c2ecf20Sopenharmony_ci DOMAIN_USER_RID_GUEST = 0x1f5, 12198c2ecf20Sopenharmony_ci DOMAIN_USER_RID_KRBTGT = 0x1f6, 12208c2ecf20Sopenharmony_ci 12218c2ecf20Sopenharmony_ci /* Groups. */ 12228c2ecf20Sopenharmony_ci DOMAIN_GROUP_RID_ADMINS = 0x200, 12238c2ecf20Sopenharmony_ci DOMAIN_GROUP_RID_USERS = 0x201, 12248c2ecf20Sopenharmony_ci DOMAIN_GROUP_RID_GUESTS = 0x202, 12258c2ecf20Sopenharmony_ci DOMAIN_GROUP_RID_COMPUTERS = 0x203, 12268c2ecf20Sopenharmony_ci DOMAIN_GROUP_RID_CONTROLLERS = 0x204, 12278c2ecf20Sopenharmony_ci DOMAIN_GROUP_RID_CERT_ADMINS = 0x205, 12288c2ecf20Sopenharmony_ci DOMAIN_GROUP_RID_SCHEMA_ADMINS = 0x206, 12298c2ecf20Sopenharmony_ci DOMAIN_GROUP_RID_ENTERPRISE_ADMINS= 0x207, 12308c2ecf20Sopenharmony_ci DOMAIN_GROUP_RID_POLICY_ADMINS = 0x208, 12318c2ecf20Sopenharmony_ci 12328c2ecf20Sopenharmony_ci /* Aliases. */ 12338c2ecf20Sopenharmony_ci DOMAIN_ALIAS_RID_ADMINS = 0x220, 12348c2ecf20Sopenharmony_ci DOMAIN_ALIAS_RID_USERS = 0x221, 12358c2ecf20Sopenharmony_ci DOMAIN_ALIAS_RID_GUESTS = 0x222, 12368c2ecf20Sopenharmony_ci DOMAIN_ALIAS_RID_POWER_USERS = 0x223, 12378c2ecf20Sopenharmony_ci 12388c2ecf20Sopenharmony_ci DOMAIN_ALIAS_RID_ACCOUNT_OPS = 0x224, 12398c2ecf20Sopenharmony_ci DOMAIN_ALIAS_RID_SYSTEM_OPS = 0x225, 12408c2ecf20Sopenharmony_ci DOMAIN_ALIAS_RID_PRINT_OPS = 0x226, 12418c2ecf20Sopenharmony_ci DOMAIN_ALIAS_RID_BACKUP_OPS = 0x227, 12428c2ecf20Sopenharmony_ci 12438c2ecf20Sopenharmony_ci DOMAIN_ALIAS_RID_REPLICATOR = 0x228, 12448c2ecf20Sopenharmony_ci DOMAIN_ALIAS_RID_RAS_SERVERS = 0x229, 12458c2ecf20Sopenharmony_ci DOMAIN_ALIAS_RID_PREW2KCOMPACCESS = 0x22a, 12468c2ecf20Sopenharmony_ci} RELATIVE_IDENTIFIERS; 12478c2ecf20Sopenharmony_ci 12488c2ecf20Sopenharmony_ci/* 12498c2ecf20Sopenharmony_ci * The universal well-known SIDs: 12508c2ecf20Sopenharmony_ci * 12518c2ecf20Sopenharmony_ci * NULL_SID S-1-0-0 12528c2ecf20Sopenharmony_ci * WORLD_SID S-1-1-0 12538c2ecf20Sopenharmony_ci * LOCAL_SID S-1-2-0 12548c2ecf20Sopenharmony_ci * CREATOR_OWNER_SID S-1-3-0 12558c2ecf20Sopenharmony_ci * CREATOR_GROUP_SID S-1-3-1 12568c2ecf20Sopenharmony_ci * CREATOR_OWNER_SERVER_SID S-1-3-2 12578c2ecf20Sopenharmony_ci * CREATOR_GROUP_SERVER_SID S-1-3-3 12588c2ecf20Sopenharmony_ci * 12598c2ecf20Sopenharmony_ci * (Non-unique IDs) S-1-4 12608c2ecf20Sopenharmony_ci * 12618c2ecf20Sopenharmony_ci * NT well-known SIDs: 12628c2ecf20Sopenharmony_ci * 12638c2ecf20Sopenharmony_ci * NT_AUTHORITY_SID S-1-5 12648c2ecf20Sopenharmony_ci * DIALUP_SID S-1-5-1 12658c2ecf20Sopenharmony_ci * 12668c2ecf20Sopenharmony_ci * NETWORD_SID S-1-5-2 12678c2ecf20Sopenharmony_ci * BATCH_SID S-1-5-3 12688c2ecf20Sopenharmony_ci * INTERACTIVE_SID S-1-5-4 12698c2ecf20Sopenharmony_ci * SERVICE_SID S-1-5-6 12708c2ecf20Sopenharmony_ci * ANONYMOUS_LOGON_SID S-1-5-7 (aka null logon session) 12718c2ecf20Sopenharmony_ci * PROXY_SID S-1-5-8 12728c2ecf20Sopenharmony_ci * SERVER_LOGON_SID S-1-5-9 (aka domain controller account) 12738c2ecf20Sopenharmony_ci * SELF_SID S-1-5-10 (self RID) 12748c2ecf20Sopenharmony_ci * AUTHENTICATED_USER_SID S-1-5-11 12758c2ecf20Sopenharmony_ci * RESTRICTED_CODE_SID S-1-5-12 (running restricted code) 12768c2ecf20Sopenharmony_ci * TERMINAL_SERVER_SID S-1-5-13 (running on terminal server) 12778c2ecf20Sopenharmony_ci * 12788c2ecf20Sopenharmony_ci * (Logon IDs) S-1-5-5-X-Y 12798c2ecf20Sopenharmony_ci * 12808c2ecf20Sopenharmony_ci * (NT non-unique IDs) S-1-5-0x15-... 12818c2ecf20Sopenharmony_ci * 12828c2ecf20Sopenharmony_ci * (Built-in domain) S-1-5-0x20 12838c2ecf20Sopenharmony_ci */ 12848c2ecf20Sopenharmony_ci 12858c2ecf20Sopenharmony_ci/* 12868c2ecf20Sopenharmony_ci * The SID_IDENTIFIER_AUTHORITY is a 48-bit value used in the SID structure. 12878c2ecf20Sopenharmony_ci * 12888c2ecf20Sopenharmony_ci * NOTE: This is stored as a big endian number, hence the high_part comes 12898c2ecf20Sopenharmony_ci * before the low_part. 12908c2ecf20Sopenharmony_ci */ 12918c2ecf20Sopenharmony_citypedef union { 12928c2ecf20Sopenharmony_ci struct { 12938c2ecf20Sopenharmony_ci u16 high_part; /* High 16-bits. */ 12948c2ecf20Sopenharmony_ci u32 low_part; /* Low 32-bits. */ 12958c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) parts; 12968c2ecf20Sopenharmony_ci u8 value[6]; /* Value as individual bytes. */ 12978c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) SID_IDENTIFIER_AUTHORITY; 12988c2ecf20Sopenharmony_ci 12998c2ecf20Sopenharmony_ci/* 13008c2ecf20Sopenharmony_ci * The SID structure is a variable-length structure used to uniquely identify 13018c2ecf20Sopenharmony_ci * users or groups. SID stands for security identifier. 13028c2ecf20Sopenharmony_ci * 13038c2ecf20Sopenharmony_ci * The standard textual representation of the SID is of the form: 13048c2ecf20Sopenharmony_ci * S-R-I-S-S... 13058c2ecf20Sopenharmony_ci * Where: 13068c2ecf20Sopenharmony_ci * - The first "S" is the literal character 'S' identifying the following 13078c2ecf20Sopenharmony_ci * digits as a SID. 13088c2ecf20Sopenharmony_ci * - R is the revision level of the SID expressed as a sequence of digits 13098c2ecf20Sopenharmony_ci * either in decimal or hexadecimal (if the later, prefixed by "0x"). 13108c2ecf20Sopenharmony_ci * - I is the 48-bit identifier_authority, expressed as digits as R above. 13118c2ecf20Sopenharmony_ci * - S... is one or more sub_authority values, expressed as digits as above. 13128c2ecf20Sopenharmony_ci * 13138c2ecf20Sopenharmony_ci * Example SID; the domain-relative SID of the local Administrators group on 13148c2ecf20Sopenharmony_ci * Windows NT/2k: 13158c2ecf20Sopenharmony_ci * S-1-5-32-544 13168c2ecf20Sopenharmony_ci * This translates to a SID with: 13178c2ecf20Sopenharmony_ci * revision = 1, 13188c2ecf20Sopenharmony_ci * sub_authority_count = 2, 13198c2ecf20Sopenharmony_ci * identifier_authority = {0,0,0,0,0,5}, // SECURITY_NT_AUTHORITY 13208c2ecf20Sopenharmony_ci * sub_authority[0] = 32, // SECURITY_BUILTIN_DOMAIN_RID 13218c2ecf20Sopenharmony_ci * sub_authority[1] = 544 // DOMAIN_ALIAS_RID_ADMINS 13228c2ecf20Sopenharmony_ci */ 13238c2ecf20Sopenharmony_citypedef struct { 13248c2ecf20Sopenharmony_ci u8 revision; 13258c2ecf20Sopenharmony_ci u8 sub_authority_count; 13268c2ecf20Sopenharmony_ci SID_IDENTIFIER_AUTHORITY identifier_authority; 13278c2ecf20Sopenharmony_ci le32 sub_authority[1]; /* At least one sub_authority. */ 13288c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) SID; 13298c2ecf20Sopenharmony_ci 13308c2ecf20Sopenharmony_ci/* 13318c2ecf20Sopenharmony_ci * Current constants for SIDs. 13328c2ecf20Sopenharmony_ci */ 13338c2ecf20Sopenharmony_citypedef enum { 13348c2ecf20Sopenharmony_ci SID_REVISION = 1, /* Current revision level. */ 13358c2ecf20Sopenharmony_ci SID_MAX_SUB_AUTHORITIES = 15, /* Maximum number of those. */ 13368c2ecf20Sopenharmony_ci SID_RECOMMENDED_SUB_AUTHORITIES = 1, /* Will change to around 6 in 13378c2ecf20Sopenharmony_ci a future revision. */ 13388c2ecf20Sopenharmony_ci} SID_CONSTANTS; 13398c2ecf20Sopenharmony_ci 13408c2ecf20Sopenharmony_ci/* 13418c2ecf20Sopenharmony_ci * The predefined ACE types (8-bit, see below). 13428c2ecf20Sopenharmony_ci */ 13438c2ecf20Sopenharmony_cienum { 13448c2ecf20Sopenharmony_ci ACCESS_MIN_MS_ACE_TYPE = 0, 13458c2ecf20Sopenharmony_ci ACCESS_ALLOWED_ACE_TYPE = 0, 13468c2ecf20Sopenharmony_ci ACCESS_DENIED_ACE_TYPE = 1, 13478c2ecf20Sopenharmony_ci SYSTEM_AUDIT_ACE_TYPE = 2, 13488c2ecf20Sopenharmony_ci SYSTEM_ALARM_ACE_TYPE = 3, /* Not implemented as of Win2k. */ 13498c2ecf20Sopenharmony_ci ACCESS_MAX_MS_V2_ACE_TYPE = 3, 13508c2ecf20Sopenharmony_ci 13518c2ecf20Sopenharmony_ci ACCESS_ALLOWED_COMPOUND_ACE_TYPE= 4, 13528c2ecf20Sopenharmony_ci ACCESS_MAX_MS_V3_ACE_TYPE = 4, 13538c2ecf20Sopenharmony_ci 13548c2ecf20Sopenharmony_ci /* The following are Win2k only. */ 13558c2ecf20Sopenharmony_ci ACCESS_MIN_MS_OBJECT_ACE_TYPE = 5, 13568c2ecf20Sopenharmony_ci ACCESS_ALLOWED_OBJECT_ACE_TYPE = 5, 13578c2ecf20Sopenharmony_ci ACCESS_DENIED_OBJECT_ACE_TYPE = 6, 13588c2ecf20Sopenharmony_ci SYSTEM_AUDIT_OBJECT_ACE_TYPE = 7, 13598c2ecf20Sopenharmony_ci SYSTEM_ALARM_OBJECT_ACE_TYPE = 8, 13608c2ecf20Sopenharmony_ci ACCESS_MAX_MS_OBJECT_ACE_TYPE = 8, 13618c2ecf20Sopenharmony_ci 13628c2ecf20Sopenharmony_ci ACCESS_MAX_MS_V4_ACE_TYPE = 8, 13638c2ecf20Sopenharmony_ci 13648c2ecf20Sopenharmony_ci /* This one is for WinNT/2k. */ 13658c2ecf20Sopenharmony_ci ACCESS_MAX_MS_ACE_TYPE = 8, 13668c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 13678c2ecf20Sopenharmony_ci 13688c2ecf20Sopenharmony_citypedef u8 ACE_TYPES; 13698c2ecf20Sopenharmony_ci 13708c2ecf20Sopenharmony_ci/* 13718c2ecf20Sopenharmony_ci * The ACE flags (8-bit) for audit and inheritance (see below). 13728c2ecf20Sopenharmony_ci * 13738c2ecf20Sopenharmony_ci * SUCCESSFUL_ACCESS_ACE_FLAG is only used with system audit and alarm ACE 13748c2ecf20Sopenharmony_ci * types to indicate that a message is generated (in Windows!) for successful 13758c2ecf20Sopenharmony_ci * accesses. 13768c2ecf20Sopenharmony_ci * 13778c2ecf20Sopenharmony_ci * FAILED_ACCESS_ACE_FLAG is only used with system audit and alarm ACE types 13788c2ecf20Sopenharmony_ci * to indicate that a message is generated (in Windows!) for failed accesses. 13798c2ecf20Sopenharmony_ci */ 13808c2ecf20Sopenharmony_cienum { 13818c2ecf20Sopenharmony_ci /* The inheritance flags. */ 13828c2ecf20Sopenharmony_ci OBJECT_INHERIT_ACE = 0x01, 13838c2ecf20Sopenharmony_ci CONTAINER_INHERIT_ACE = 0x02, 13848c2ecf20Sopenharmony_ci NO_PROPAGATE_INHERIT_ACE = 0x04, 13858c2ecf20Sopenharmony_ci INHERIT_ONLY_ACE = 0x08, 13868c2ecf20Sopenharmony_ci INHERITED_ACE = 0x10, /* Win2k only. */ 13878c2ecf20Sopenharmony_ci VALID_INHERIT_FLAGS = 0x1f, 13888c2ecf20Sopenharmony_ci 13898c2ecf20Sopenharmony_ci /* The audit flags. */ 13908c2ecf20Sopenharmony_ci SUCCESSFUL_ACCESS_ACE_FLAG = 0x40, 13918c2ecf20Sopenharmony_ci FAILED_ACCESS_ACE_FLAG = 0x80, 13928c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 13938c2ecf20Sopenharmony_ci 13948c2ecf20Sopenharmony_citypedef u8 ACE_FLAGS; 13958c2ecf20Sopenharmony_ci 13968c2ecf20Sopenharmony_ci/* 13978c2ecf20Sopenharmony_ci * An ACE is an access-control entry in an access-control list (ACL). 13988c2ecf20Sopenharmony_ci * An ACE defines access to an object for a specific user or group or defines 13998c2ecf20Sopenharmony_ci * the types of access that generate system-administration messages or alarms 14008c2ecf20Sopenharmony_ci * for a specific user or group. The user or group is identified by a security 14018c2ecf20Sopenharmony_ci * identifier (SID). 14028c2ecf20Sopenharmony_ci * 14038c2ecf20Sopenharmony_ci * Each ACE starts with an ACE_HEADER structure (aligned on 4-byte boundary), 14048c2ecf20Sopenharmony_ci * which specifies the type and size of the ACE. The format of the subsequent 14058c2ecf20Sopenharmony_ci * data depends on the ACE type. 14068c2ecf20Sopenharmony_ci */ 14078c2ecf20Sopenharmony_citypedef struct { 14088c2ecf20Sopenharmony_ci/*Ofs*/ 14098c2ecf20Sopenharmony_ci/* 0*/ ACE_TYPES type; /* Type of the ACE. */ 14108c2ecf20Sopenharmony_ci/* 1*/ ACE_FLAGS flags; /* Flags describing the ACE. */ 14118c2ecf20Sopenharmony_ci/* 2*/ le16 size; /* Size in bytes of the ACE. */ 14128c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) ACE_HEADER; 14138c2ecf20Sopenharmony_ci 14148c2ecf20Sopenharmony_ci/* 14158c2ecf20Sopenharmony_ci * The access mask (32-bit). Defines the access rights. 14168c2ecf20Sopenharmony_ci * 14178c2ecf20Sopenharmony_ci * The specific rights (bits 0 to 15). These depend on the type of the object 14188c2ecf20Sopenharmony_ci * being secured by the ACE. 14198c2ecf20Sopenharmony_ci */ 14208c2ecf20Sopenharmony_cienum { 14218c2ecf20Sopenharmony_ci /* Specific rights for files and directories are as follows: */ 14228c2ecf20Sopenharmony_ci 14238c2ecf20Sopenharmony_ci /* Right to read data from the file. (FILE) */ 14248c2ecf20Sopenharmony_ci FILE_READ_DATA = cpu_to_le32(0x00000001), 14258c2ecf20Sopenharmony_ci /* Right to list contents of a directory. (DIRECTORY) */ 14268c2ecf20Sopenharmony_ci FILE_LIST_DIRECTORY = cpu_to_le32(0x00000001), 14278c2ecf20Sopenharmony_ci 14288c2ecf20Sopenharmony_ci /* Right to write data to the file. (FILE) */ 14298c2ecf20Sopenharmony_ci FILE_WRITE_DATA = cpu_to_le32(0x00000002), 14308c2ecf20Sopenharmony_ci /* Right to create a file in the directory. (DIRECTORY) */ 14318c2ecf20Sopenharmony_ci FILE_ADD_FILE = cpu_to_le32(0x00000002), 14328c2ecf20Sopenharmony_ci 14338c2ecf20Sopenharmony_ci /* Right to append data to the file. (FILE) */ 14348c2ecf20Sopenharmony_ci FILE_APPEND_DATA = cpu_to_le32(0x00000004), 14358c2ecf20Sopenharmony_ci /* Right to create a subdirectory. (DIRECTORY) */ 14368c2ecf20Sopenharmony_ci FILE_ADD_SUBDIRECTORY = cpu_to_le32(0x00000004), 14378c2ecf20Sopenharmony_ci 14388c2ecf20Sopenharmony_ci /* Right to read extended attributes. (FILE/DIRECTORY) */ 14398c2ecf20Sopenharmony_ci FILE_READ_EA = cpu_to_le32(0x00000008), 14408c2ecf20Sopenharmony_ci 14418c2ecf20Sopenharmony_ci /* Right to write extended attributes. (FILE/DIRECTORY) */ 14428c2ecf20Sopenharmony_ci FILE_WRITE_EA = cpu_to_le32(0x00000010), 14438c2ecf20Sopenharmony_ci 14448c2ecf20Sopenharmony_ci /* Right to execute a file. (FILE) */ 14458c2ecf20Sopenharmony_ci FILE_EXECUTE = cpu_to_le32(0x00000020), 14468c2ecf20Sopenharmony_ci /* Right to traverse the directory. (DIRECTORY) */ 14478c2ecf20Sopenharmony_ci FILE_TRAVERSE = cpu_to_le32(0x00000020), 14488c2ecf20Sopenharmony_ci 14498c2ecf20Sopenharmony_ci /* 14508c2ecf20Sopenharmony_ci * Right to delete a directory and all the files it contains (its 14518c2ecf20Sopenharmony_ci * children), even if the files are read-only. (DIRECTORY) 14528c2ecf20Sopenharmony_ci */ 14538c2ecf20Sopenharmony_ci FILE_DELETE_CHILD = cpu_to_le32(0x00000040), 14548c2ecf20Sopenharmony_ci 14558c2ecf20Sopenharmony_ci /* Right to read file attributes. (FILE/DIRECTORY) */ 14568c2ecf20Sopenharmony_ci FILE_READ_ATTRIBUTES = cpu_to_le32(0x00000080), 14578c2ecf20Sopenharmony_ci 14588c2ecf20Sopenharmony_ci /* Right to change file attributes. (FILE/DIRECTORY) */ 14598c2ecf20Sopenharmony_ci FILE_WRITE_ATTRIBUTES = cpu_to_le32(0x00000100), 14608c2ecf20Sopenharmony_ci 14618c2ecf20Sopenharmony_ci /* 14628c2ecf20Sopenharmony_ci * The standard rights (bits 16 to 23). These are independent of the 14638c2ecf20Sopenharmony_ci * type of object being secured. 14648c2ecf20Sopenharmony_ci */ 14658c2ecf20Sopenharmony_ci 14668c2ecf20Sopenharmony_ci /* Right to delete the object. */ 14678c2ecf20Sopenharmony_ci DELETE = cpu_to_le32(0x00010000), 14688c2ecf20Sopenharmony_ci 14698c2ecf20Sopenharmony_ci /* 14708c2ecf20Sopenharmony_ci * Right to read the information in the object's security descriptor, 14718c2ecf20Sopenharmony_ci * not including the information in the SACL, i.e. right to read the 14728c2ecf20Sopenharmony_ci * security descriptor and owner. 14738c2ecf20Sopenharmony_ci */ 14748c2ecf20Sopenharmony_ci READ_CONTROL = cpu_to_le32(0x00020000), 14758c2ecf20Sopenharmony_ci 14768c2ecf20Sopenharmony_ci /* Right to modify the DACL in the object's security descriptor. */ 14778c2ecf20Sopenharmony_ci WRITE_DAC = cpu_to_le32(0x00040000), 14788c2ecf20Sopenharmony_ci 14798c2ecf20Sopenharmony_ci /* Right to change the owner in the object's security descriptor. */ 14808c2ecf20Sopenharmony_ci WRITE_OWNER = cpu_to_le32(0x00080000), 14818c2ecf20Sopenharmony_ci 14828c2ecf20Sopenharmony_ci /* 14838c2ecf20Sopenharmony_ci * Right to use the object for synchronization. Enables a process to 14848c2ecf20Sopenharmony_ci * wait until the object is in the signalled state. Some object types 14858c2ecf20Sopenharmony_ci * do not support this access right. 14868c2ecf20Sopenharmony_ci */ 14878c2ecf20Sopenharmony_ci SYNCHRONIZE = cpu_to_le32(0x00100000), 14888c2ecf20Sopenharmony_ci 14898c2ecf20Sopenharmony_ci /* 14908c2ecf20Sopenharmony_ci * The following STANDARD_RIGHTS_* are combinations of the above for 14918c2ecf20Sopenharmony_ci * convenience and are defined by the Win32 API. 14928c2ecf20Sopenharmony_ci */ 14938c2ecf20Sopenharmony_ci 14948c2ecf20Sopenharmony_ci /* These are currently defined to READ_CONTROL. */ 14958c2ecf20Sopenharmony_ci STANDARD_RIGHTS_READ = cpu_to_le32(0x00020000), 14968c2ecf20Sopenharmony_ci STANDARD_RIGHTS_WRITE = cpu_to_le32(0x00020000), 14978c2ecf20Sopenharmony_ci STANDARD_RIGHTS_EXECUTE = cpu_to_le32(0x00020000), 14988c2ecf20Sopenharmony_ci 14998c2ecf20Sopenharmony_ci /* Combines DELETE, READ_CONTROL, WRITE_DAC, and WRITE_OWNER access. */ 15008c2ecf20Sopenharmony_ci STANDARD_RIGHTS_REQUIRED = cpu_to_le32(0x000f0000), 15018c2ecf20Sopenharmony_ci 15028c2ecf20Sopenharmony_ci /* 15038c2ecf20Sopenharmony_ci * Combines DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, and 15048c2ecf20Sopenharmony_ci * SYNCHRONIZE access. 15058c2ecf20Sopenharmony_ci */ 15068c2ecf20Sopenharmony_ci STANDARD_RIGHTS_ALL = cpu_to_le32(0x001f0000), 15078c2ecf20Sopenharmony_ci 15088c2ecf20Sopenharmony_ci /* 15098c2ecf20Sopenharmony_ci * The access system ACL and maximum allowed access types (bits 24 to 15108c2ecf20Sopenharmony_ci * 25, bits 26 to 27 are reserved). 15118c2ecf20Sopenharmony_ci */ 15128c2ecf20Sopenharmony_ci ACCESS_SYSTEM_SECURITY = cpu_to_le32(0x01000000), 15138c2ecf20Sopenharmony_ci MAXIMUM_ALLOWED = cpu_to_le32(0x02000000), 15148c2ecf20Sopenharmony_ci 15158c2ecf20Sopenharmony_ci /* 15168c2ecf20Sopenharmony_ci * The generic rights (bits 28 to 31). These map onto the standard and 15178c2ecf20Sopenharmony_ci * specific rights. 15188c2ecf20Sopenharmony_ci */ 15198c2ecf20Sopenharmony_ci 15208c2ecf20Sopenharmony_ci /* Read, write, and execute access. */ 15218c2ecf20Sopenharmony_ci GENERIC_ALL = cpu_to_le32(0x10000000), 15228c2ecf20Sopenharmony_ci 15238c2ecf20Sopenharmony_ci /* Execute access. */ 15248c2ecf20Sopenharmony_ci GENERIC_EXECUTE = cpu_to_le32(0x20000000), 15258c2ecf20Sopenharmony_ci 15268c2ecf20Sopenharmony_ci /* 15278c2ecf20Sopenharmony_ci * Write access. For files, this maps onto: 15288c2ecf20Sopenharmony_ci * FILE_APPEND_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_DATA | 15298c2ecf20Sopenharmony_ci * FILE_WRITE_EA | STANDARD_RIGHTS_WRITE | SYNCHRONIZE 15308c2ecf20Sopenharmony_ci * For directories, the mapping has the same numerical value. See 15318c2ecf20Sopenharmony_ci * above for the descriptions of the rights granted. 15328c2ecf20Sopenharmony_ci */ 15338c2ecf20Sopenharmony_ci GENERIC_WRITE = cpu_to_le32(0x40000000), 15348c2ecf20Sopenharmony_ci 15358c2ecf20Sopenharmony_ci /* 15368c2ecf20Sopenharmony_ci * Read access. For files, this maps onto: 15378c2ecf20Sopenharmony_ci * FILE_READ_ATTRIBUTES | FILE_READ_DATA | FILE_READ_EA | 15388c2ecf20Sopenharmony_ci * STANDARD_RIGHTS_READ | SYNCHRONIZE 15398c2ecf20Sopenharmony_ci * For directories, the mapping has the same numberical value. See 15408c2ecf20Sopenharmony_ci * above for the descriptions of the rights granted. 15418c2ecf20Sopenharmony_ci */ 15428c2ecf20Sopenharmony_ci GENERIC_READ = cpu_to_le32(0x80000000), 15438c2ecf20Sopenharmony_ci}; 15448c2ecf20Sopenharmony_ci 15458c2ecf20Sopenharmony_citypedef le32 ACCESS_MASK; 15468c2ecf20Sopenharmony_ci 15478c2ecf20Sopenharmony_ci/* 15488c2ecf20Sopenharmony_ci * The generic mapping array. Used to denote the mapping of each generic 15498c2ecf20Sopenharmony_ci * access right to a specific access mask. 15508c2ecf20Sopenharmony_ci * 15518c2ecf20Sopenharmony_ci * FIXME: What exactly is this and what is it for? (AIA) 15528c2ecf20Sopenharmony_ci */ 15538c2ecf20Sopenharmony_citypedef struct { 15548c2ecf20Sopenharmony_ci ACCESS_MASK generic_read; 15558c2ecf20Sopenharmony_ci ACCESS_MASK generic_write; 15568c2ecf20Sopenharmony_ci ACCESS_MASK generic_execute; 15578c2ecf20Sopenharmony_ci ACCESS_MASK generic_all; 15588c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) GENERIC_MAPPING; 15598c2ecf20Sopenharmony_ci 15608c2ecf20Sopenharmony_ci/* 15618c2ecf20Sopenharmony_ci * The predefined ACE type structures are as defined below. 15628c2ecf20Sopenharmony_ci */ 15638c2ecf20Sopenharmony_ci 15648c2ecf20Sopenharmony_ci/* 15658c2ecf20Sopenharmony_ci * ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE 15668c2ecf20Sopenharmony_ci */ 15678c2ecf20Sopenharmony_citypedef struct { 15688c2ecf20Sopenharmony_ci/* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */ 15698c2ecf20Sopenharmony_ci ACE_TYPES type; /* Type of the ACE. */ 15708c2ecf20Sopenharmony_ci ACE_FLAGS flags; /* Flags describing the ACE. */ 15718c2ecf20Sopenharmony_ci le16 size; /* Size in bytes of the ACE. */ 15728c2ecf20Sopenharmony_ci/* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */ 15738c2ecf20Sopenharmony_ci 15748c2ecf20Sopenharmony_ci/* 8*/ SID sid; /* The SID associated with the ACE. */ 15758c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, 15768c2ecf20Sopenharmony_ci SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE; 15778c2ecf20Sopenharmony_ci 15788c2ecf20Sopenharmony_ci/* 15798c2ecf20Sopenharmony_ci * The object ACE flags (32-bit). 15808c2ecf20Sopenharmony_ci */ 15818c2ecf20Sopenharmony_cienum { 15828c2ecf20Sopenharmony_ci ACE_OBJECT_TYPE_PRESENT = cpu_to_le32(1), 15838c2ecf20Sopenharmony_ci ACE_INHERITED_OBJECT_TYPE_PRESENT = cpu_to_le32(2), 15848c2ecf20Sopenharmony_ci}; 15858c2ecf20Sopenharmony_ci 15868c2ecf20Sopenharmony_citypedef le32 OBJECT_ACE_FLAGS; 15878c2ecf20Sopenharmony_ci 15888c2ecf20Sopenharmony_citypedef struct { 15898c2ecf20Sopenharmony_ci/* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */ 15908c2ecf20Sopenharmony_ci ACE_TYPES type; /* Type of the ACE. */ 15918c2ecf20Sopenharmony_ci ACE_FLAGS flags; /* Flags describing the ACE. */ 15928c2ecf20Sopenharmony_ci le16 size; /* Size in bytes of the ACE. */ 15938c2ecf20Sopenharmony_ci/* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */ 15948c2ecf20Sopenharmony_ci 15958c2ecf20Sopenharmony_ci/* 8*/ OBJECT_ACE_FLAGS object_flags; /* Flags describing the object ACE. */ 15968c2ecf20Sopenharmony_ci/* 12*/ GUID object_type; 15978c2ecf20Sopenharmony_ci/* 28*/ GUID inherited_object_type; 15988c2ecf20Sopenharmony_ci 15998c2ecf20Sopenharmony_ci/* 44*/ SID sid; /* The SID associated with the ACE. */ 16008c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) ACCESS_ALLOWED_OBJECT_ACE, 16018c2ecf20Sopenharmony_ci ACCESS_DENIED_OBJECT_ACE, 16028c2ecf20Sopenharmony_ci SYSTEM_AUDIT_OBJECT_ACE, 16038c2ecf20Sopenharmony_ci SYSTEM_ALARM_OBJECT_ACE; 16048c2ecf20Sopenharmony_ci 16058c2ecf20Sopenharmony_ci/* 16068c2ecf20Sopenharmony_ci * An ACL is an access-control list (ACL). 16078c2ecf20Sopenharmony_ci * An ACL starts with an ACL header structure, which specifies the size of 16088c2ecf20Sopenharmony_ci * the ACL and the number of ACEs it contains. The ACL header is followed by 16098c2ecf20Sopenharmony_ci * zero or more access control entries (ACEs). The ACL as well as each ACE 16108c2ecf20Sopenharmony_ci * are aligned on 4-byte boundaries. 16118c2ecf20Sopenharmony_ci */ 16128c2ecf20Sopenharmony_citypedef struct { 16138c2ecf20Sopenharmony_ci u8 revision; /* Revision of this ACL. */ 16148c2ecf20Sopenharmony_ci u8 alignment1; 16158c2ecf20Sopenharmony_ci le16 size; /* Allocated space in bytes for ACL. Includes this 16168c2ecf20Sopenharmony_ci header, the ACEs and the remaining free space. */ 16178c2ecf20Sopenharmony_ci le16 ace_count; /* Number of ACEs in the ACL. */ 16188c2ecf20Sopenharmony_ci le16 alignment2; 16198c2ecf20Sopenharmony_ci/* sizeof() = 8 bytes */ 16208c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) ACL; 16218c2ecf20Sopenharmony_ci 16228c2ecf20Sopenharmony_ci/* 16238c2ecf20Sopenharmony_ci * Current constants for ACLs. 16248c2ecf20Sopenharmony_ci */ 16258c2ecf20Sopenharmony_citypedef enum { 16268c2ecf20Sopenharmony_ci /* Current revision. */ 16278c2ecf20Sopenharmony_ci ACL_REVISION = 2, 16288c2ecf20Sopenharmony_ci ACL_REVISION_DS = 4, 16298c2ecf20Sopenharmony_ci 16308c2ecf20Sopenharmony_ci /* History of revisions. */ 16318c2ecf20Sopenharmony_ci ACL_REVISION1 = 1, 16328c2ecf20Sopenharmony_ci MIN_ACL_REVISION = 2, 16338c2ecf20Sopenharmony_ci ACL_REVISION2 = 2, 16348c2ecf20Sopenharmony_ci ACL_REVISION3 = 3, 16358c2ecf20Sopenharmony_ci ACL_REVISION4 = 4, 16368c2ecf20Sopenharmony_ci MAX_ACL_REVISION = 4, 16378c2ecf20Sopenharmony_ci} ACL_CONSTANTS; 16388c2ecf20Sopenharmony_ci 16398c2ecf20Sopenharmony_ci/* 16408c2ecf20Sopenharmony_ci * The security descriptor control flags (16-bit). 16418c2ecf20Sopenharmony_ci * 16428c2ecf20Sopenharmony_ci * SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the SID 16438c2ecf20Sopenharmony_ci * pointed to by the Owner field was provided by a defaulting mechanism 16448c2ecf20Sopenharmony_ci * rather than explicitly provided by the original provider of the 16458c2ecf20Sopenharmony_ci * security descriptor. This may affect the treatment of the SID with 16468c2ecf20Sopenharmony_ci * respect to inheritance of an owner. 16478c2ecf20Sopenharmony_ci * 16488c2ecf20Sopenharmony_ci * SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the SID in 16498c2ecf20Sopenharmony_ci * the Group field was provided by a defaulting mechanism rather than 16508c2ecf20Sopenharmony_ci * explicitly provided by the original provider of the security 16518c2ecf20Sopenharmony_ci * descriptor. This may affect the treatment of the SID with respect to 16528c2ecf20Sopenharmony_ci * inheritance of a primary group. 16538c2ecf20Sopenharmony_ci * 16548c2ecf20Sopenharmony_ci * SE_DACL_PRESENT - This boolean flag, when set, indicates that the security 16558c2ecf20Sopenharmony_ci * descriptor contains a discretionary ACL. If this flag is set and the 16568c2ecf20Sopenharmony_ci * Dacl field of the SECURITY_DESCRIPTOR is null, then a null ACL is 16578c2ecf20Sopenharmony_ci * explicitly being specified. 16588c2ecf20Sopenharmony_ci * 16598c2ecf20Sopenharmony_ci * SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the ACL 16608c2ecf20Sopenharmony_ci * pointed to by the Dacl field was provided by a defaulting mechanism 16618c2ecf20Sopenharmony_ci * rather than explicitly provided by the original provider of the 16628c2ecf20Sopenharmony_ci * security descriptor. This may affect the treatment of the ACL with 16638c2ecf20Sopenharmony_ci * respect to inheritance of an ACL. This flag is ignored if the 16648c2ecf20Sopenharmony_ci * DaclPresent flag is not set. 16658c2ecf20Sopenharmony_ci * 16668c2ecf20Sopenharmony_ci * SE_SACL_PRESENT - This boolean flag, when set, indicates that the security 16678c2ecf20Sopenharmony_ci * descriptor contains a system ACL pointed to by the Sacl field. If this 16688c2ecf20Sopenharmony_ci * flag is set and the Sacl field of the SECURITY_DESCRIPTOR is null, then 16698c2ecf20Sopenharmony_ci * an empty (but present) ACL is being specified. 16708c2ecf20Sopenharmony_ci * 16718c2ecf20Sopenharmony_ci * SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the ACL 16728c2ecf20Sopenharmony_ci * pointed to by the Sacl field was provided by a defaulting mechanism 16738c2ecf20Sopenharmony_ci * rather than explicitly provided by the original provider of the 16748c2ecf20Sopenharmony_ci * security descriptor. This may affect the treatment of the ACL with 16758c2ecf20Sopenharmony_ci * respect to inheritance of an ACL. This flag is ignored if the 16768c2ecf20Sopenharmony_ci * SaclPresent flag is not set. 16778c2ecf20Sopenharmony_ci * 16788c2ecf20Sopenharmony_ci * SE_SELF_RELATIVE - This boolean flag, when set, indicates that the security 16798c2ecf20Sopenharmony_ci * descriptor is in self-relative form. In this form, all fields of the 16808c2ecf20Sopenharmony_ci * security descriptor are contiguous in memory and all pointer fields are 16818c2ecf20Sopenharmony_ci * expressed as offsets from the beginning of the security descriptor. 16828c2ecf20Sopenharmony_ci */ 16838c2ecf20Sopenharmony_cienum { 16848c2ecf20Sopenharmony_ci SE_OWNER_DEFAULTED = cpu_to_le16(0x0001), 16858c2ecf20Sopenharmony_ci SE_GROUP_DEFAULTED = cpu_to_le16(0x0002), 16868c2ecf20Sopenharmony_ci SE_DACL_PRESENT = cpu_to_le16(0x0004), 16878c2ecf20Sopenharmony_ci SE_DACL_DEFAULTED = cpu_to_le16(0x0008), 16888c2ecf20Sopenharmony_ci 16898c2ecf20Sopenharmony_ci SE_SACL_PRESENT = cpu_to_le16(0x0010), 16908c2ecf20Sopenharmony_ci SE_SACL_DEFAULTED = cpu_to_le16(0x0020), 16918c2ecf20Sopenharmony_ci 16928c2ecf20Sopenharmony_ci SE_DACL_AUTO_INHERIT_REQ = cpu_to_le16(0x0100), 16938c2ecf20Sopenharmony_ci SE_SACL_AUTO_INHERIT_REQ = cpu_to_le16(0x0200), 16948c2ecf20Sopenharmony_ci SE_DACL_AUTO_INHERITED = cpu_to_le16(0x0400), 16958c2ecf20Sopenharmony_ci SE_SACL_AUTO_INHERITED = cpu_to_le16(0x0800), 16968c2ecf20Sopenharmony_ci 16978c2ecf20Sopenharmony_ci SE_DACL_PROTECTED = cpu_to_le16(0x1000), 16988c2ecf20Sopenharmony_ci SE_SACL_PROTECTED = cpu_to_le16(0x2000), 16998c2ecf20Sopenharmony_ci SE_RM_CONTROL_VALID = cpu_to_le16(0x4000), 17008c2ecf20Sopenharmony_ci SE_SELF_RELATIVE = cpu_to_le16(0x8000) 17018c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 17028c2ecf20Sopenharmony_ci 17038c2ecf20Sopenharmony_citypedef le16 SECURITY_DESCRIPTOR_CONTROL; 17048c2ecf20Sopenharmony_ci 17058c2ecf20Sopenharmony_ci/* 17068c2ecf20Sopenharmony_ci * Self-relative security descriptor. Contains the owner and group SIDs as well 17078c2ecf20Sopenharmony_ci * as the sacl and dacl ACLs inside the security descriptor itself. 17088c2ecf20Sopenharmony_ci */ 17098c2ecf20Sopenharmony_citypedef struct { 17108c2ecf20Sopenharmony_ci u8 revision; /* Revision level of the security descriptor. */ 17118c2ecf20Sopenharmony_ci u8 alignment; 17128c2ecf20Sopenharmony_ci SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of 17138c2ecf20Sopenharmony_ci the descriptor as well as the following fields. */ 17148c2ecf20Sopenharmony_ci le32 owner; /* Byte offset to a SID representing an object's 17158c2ecf20Sopenharmony_ci owner. If this is NULL, no owner SID is present in 17168c2ecf20Sopenharmony_ci the descriptor. */ 17178c2ecf20Sopenharmony_ci le32 group; /* Byte offset to a SID representing an object's 17188c2ecf20Sopenharmony_ci primary group. If this is NULL, no primary group 17198c2ecf20Sopenharmony_ci SID is present in the descriptor. */ 17208c2ecf20Sopenharmony_ci le32 sacl; /* Byte offset to a system ACL. Only valid, if 17218c2ecf20Sopenharmony_ci SE_SACL_PRESENT is set in the control field. If 17228c2ecf20Sopenharmony_ci SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL 17238c2ecf20Sopenharmony_ci is specified. */ 17248c2ecf20Sopenharmony_ci le32 dacl; /* Byte offset to a discretionary ACL. Only valid, if 17258c2ecf20Sopenharmony_ci SE_DACL_PRESENT is set in the control field. If 17268c2ecf20Sopenharmony_ci SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL 17278c2ecf20Sopenharmony_ci (unconditionally granting access) is specified. */ 17288c2ecf20Sopenharmony_ci/* sizeof() = 0x14 bytes */ 17298c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_RELATIVE; 17308c2ecf20Sopenharmony_ci 17318c2ecf20Sopenharmony_ci/* 17328c2ecf20Sopenharmony_ci * Absolute security descriptor. Does not contain the owner and group SIDs, nor 17338c2ecf20Sopenharmony_ci * the sacl and dacl ACLs inside the security descriptor. Instead, it contains 17348c2ecf20Sopenharmony_ci * pointers to these structures in memory. Obviously, absolute security 17358c2ecf20Sopenharmony_ci * descriptors are only useful for in memory representations of security 17368c2ecf20Sopenharmony_ci * descriptors. On disk, a self-relative security descriptor is used. 17378c2ecf20Sopenharmony_ci */ 17388c2ecf20Sopenharmony_citypedef struct { 17398c2ecf20Sopenharmony_ci u8 revision; /* Revision level of the security descriptor. */ 17408c2ecf20Sopenharmony_ci u8 alignment; 17418c2ecf20Sopenharmony_ci SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of 17428c2ecf20Sopenharmony_ci the descriptor as well as the following fields. */ 17438c2ecf20Sopenharmony_ci SID *owner; /* Points to a SID representing an object's owner. If 17448c2ecf20Sopenharmony_ci this is NULL, no owner SID is present in the 17458c2ecf20Sopenharmony_ci descriptor. */ 17468c2ecf20Sopenharmony_ci SID *group; /* Points to a SID representing an object's primary 17478c2ecf20Sopenharmony_ci group. If this is NULL, no primary group SID is 17488c2ecf20Sopenharmony_ci present in the descriptor. */ 17498c2ecf20Sopenharmony_ci ACL *sacl; /* Points to a system ACL. Only valid, if 17508c2ecf20Sopenharmony_ci SE_SACL_PRESENT is set in the control field. If 17518c2ecf20Sopenharmony_ci SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL 17528c2ecf20Sopenharmony_ci is specified. */ 17538c2ecf20Sopenharmony_ci ACL *dacl; /* Points to a discretionary ACL. Only valid, if 17548c2ecf20Sopenharmony_ci SE_DACL_PRESENT is set in the control field. If 17558c2ecf20Sopenharmony_ci SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL 17568c2ecf20Sopenharmony_ci (unconditionally granting access) is specified. */ 17578c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR; 17588c2ecf20Sopenharmony_ci 17598c2ecf20Sopenharmony_ci/* 17608c2ecf20Sopenharmony_ci * Current constants for security descriptors. 17618c2ecf20Sopenharmony_ci */ 17628c2ecf20Sopenharmony_citypedef enum { 17638c2ecf20Sopenharmony_ci /* Current revision. */ 17648c2ecf20Sopenharmony_ci SECURITY_DESCRIPTOR_REVISION = 1, 17658c2ecf20Sopenharmony_ci SECURITY_DESCRIPTOR_REVISION1 = 1, 17668c2ecf20Sopenharmony_ci 17678c2ecf20Sopenharmony_ci /* The sizes of both the absolute and relative security descriptors is 17688c2ecf20Sopenharmony_ci the same as pointers, at least on ia32 architecture are 32-bit. */ 17698c2ecf20Sopenharmony_ci SECURITY_DESCRIPTOR_MIN_LENGTH = sizeof(SECURITY_DESCRIPTOR), 17708c2ecf20Sopenharmony_ci} SECURITY_DESCRIPTOR_CONSTANTS; 17718c2ecf20Sopenharmony_ci 17728c2ecf20Sopenharmony_ci/* 17738c2ecf20Sopenharmony_ci * Attribute: Security descriptor (0x50). A standard self-relative security 17748c2ecf20Sopenharmony_ci * descriptor. 17758c2ecf20Sopenharmony_ci * 17768c2ecf20Sopenharmony_ci * NOTE: Can be resident or non-resident. 17778c2ecf20Sopenharmony_ci * NOTE: Not used in NTFS 3.0+, as security descriptors are stored centrally 17788c2ecf20Sopenharmony_ci * in FILE_Secure and the correct descriptor is found using the security_id 17798c2ecf20Sopenharmony_ci * from the standard information attribute. 17808c2ecf20Sopenharmony_ci */ 17818c2ecf20Sopenharmony_citypedef SECURITY_DESCRIPTOR_RELATIVE SECURITY_DESCRIPTOR_ATTR; 17828c2ecf20Sopenharmony_ci 17838c2ecf20Sopenharmony_ci/* 17848c2ecf20Sopenharmony_ci * On NTFS 3.0+, all security descriptors are stored in FILE_Secure. Only one 17858c2ecf20Sopenharmony_ci * referenced instance of each unique security descriptor is stored. 17868c2ecf20Sopenharmony_ci * 17878c2ecf20Sopenharmony_ci * FILE_Secure contains no unnamed data attribute, i.e. it has zero length. It 17888c2ecf20Sopenharmony_ci * does, however, contain two indexes ($SDH and $SII) as well as a named data 17898c2ecf20Sopenharmony_ci * stream ($SDS). 17908c2ecf20Sopenharmony_ci * 17918c2ecf20Sopenharmony_ci * Every unique security descriptor is assigned a unique security identifier 17928c2ecf20Sopenharmony_ci * (security_id, not to be confused with a SID). The security_id is unique for 17938c2ecf20Sopenharmony_ci * the NTFS volume and is used as an index into the $SII index, which maps 17948c2ecf20Sopenharmony_ci * security_ids to the security descriptor's storage location within the $SDS 17958c2ecf20Sopenharmony_ci * data attribute. The $SII index is sorted by ascending security_id. 17968c2ecf20Sopenharmony_ci * 17978c2ecf20Sopenharmony_ci * A simple hash is computed from each security descriptor. This hash is used 17988c2ecf20Sopenharmony_ci * as an index into the $SDH index, which maps security descriptor hashes to 17998c2ecf20Sopenharmony_ci * the security descriptor's storage location within the $SDS data attribute. 18008c2ecf20Sopenharmony_ci * The $SDH index is sorted by security descriptor hash and is stored in a B+ 18018c2ecf20Sopenharmony_ci * tree. When searching $SDH (with the intent of determining whether or not a 18028c2ecf20Sopenharmony_ci * new security descriptor is already present in the $SDS data stream), if a 18038c2ecf20Sopenharmony_ci * matching hash is found, but the security descriptors do not match, the 18048c2ecf20Sopenharmony_ci * search in the $SDH index is continued, searching for a next matching hash. 18058c2ecf20Sopenharmony_ci * 18068c2ecf20Sopenharmony_ci * When a precise match is found, the security_id coresponding to the security 18078c2ecf20Sopenharmony_ci * descriptor in the $SDS attribute is read from the found $SDH index entry and 18088c2ecf20Sopenharmony_ci * is stored in the $STANDARD_INFORMATION attribute of the file/directory to 18098c2ecf20Sopenharmony_ci * which the security descriptor is being applied. The $STANDARD_INFORMATION 18108c2ecf20Sopenharmony_ci * attribute is present in all base mft records (i.e. in all files and 18118c2ecf20Sopenharmony_ci * directories). 18128c2ecf20Sopenharmony_ci * 18138c2ecf20Sopenharmony_ci * If a match is not found, the security descriptor is assigned a new unique 18148c2ecf20Sopenharmony_ci * security_id and is added to the $SDS data attribute. Then, entries 18158c2ecf20Sopenharmony_ci * referencing the this security descriptor in the $SDS data attribute are 18168c2ecf20Sopenharmony_ci * added to the $SDH and $SII indexes. 18178c2ecf20Sopenharmony_ci * 18188c2ecf20Sopenharmony_ci * Note: Entries are never deleted from FILE_Secure, even if nothing 18198c2ecf20Sopenharmony_ci * references an entry any more. 18208c2ecf20Sopenharmony_ci */ 18218c2ecf20Sopenharmony_ci 18228c2ecf20Sopenharmony_ci/* 18238c2ecf20Sopenharmony_ci * This header precedes each security descriptor in the $SDS data stream. 18248c2ecf20Sopenharmony_ci * This is also the index entry data part of both the $SII and $SDH indexes. 18258c2ecf20Sopenharmony_ci */ 18268c2ecf20Sopenharmony_citypedef struct { 18278c2ecf20Sopenharmony_ci le32 hash; /* Hash of the security descriptor. */ 18288c2ecf20Sopenharmony_ci le32 security_id; /* The security_id assigned to the descriptor. */ 18298c2ecf20Sopenharmony_ci le64 offset; /* Byte offset of this entry in the $SDS stream. */ 18308c2ecf20Sopenharmony_ci le32 length; /* Size in bytes of this entry in $SDS stream. */ 18318c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_HEADER; 18328c2ecf20Sopenharmony_ci 18338c2ecf20Sopenharmony_ci/* 18348c2ecf20Sopenharmony_ci * The $SDS data stream contains the security descriptors, aligned on 16-byte 18358c2ecf20Sopenharmony_ci * boundaries, sorted by security_id in a B+ tree. Security descriptors cannot 18368c2ecf20Sopenharmony_ci * cross 256kib boundaries (this restriction is imposed by the Windows cache 18378c2ecf20Sopenharmony_ci * manager). Each security descriptor is contained in a SDS_ENTRY structure. 18388c2ecf20Sopenharmony_ci * Also, each security descriptor is stored twice in the $SDS stream with a 18398c2ecf20Sopenharmony_ci * fixed offset of 0x40000 bytes (256kib, the Windows cache manager's max size) 18408c2ecf20Sopenharmony_ci * between them; i.e. if a SDS_ENTRY specifies an offset of 0x51d0, then the 18418c2ecf20Sopenharmony_ci * the first copy of the security descriptor will be at offset 0x51d0 in the 18428c2ecf20Sopenharmony_ci * $SDS data stream and the second copy will be at offset 0x451d0. 18438c2ecf20Sopenharmony_ci */ 18448c2ecf20Sopenharmony_citypedef struct { 18458c2ecf20Sopenharmony_ci/*Ofs*/ 18468c2ecf20Sopenharmony_ci/* 0 SECURITY_DESCRIPTOR_HEADER; -- Unfolded here as gcc doesn't like 18478c2ecf20Sopenharmony_ci unnamed structs. */ 18488c2ecf20Sopenharmony_ci le32 hash; /* Hash of the security descriptor. */ 18498c2ecf20Sopenharmony_ci le32 security_id; /* The security_id assigned to the descriptor. */ 18508c2ecf20Sopenharmony_ci le64 offset; /* Byte offset of this entry in the $SDS stream. */ 18518c2ecf20Sopenharmony_ci le32 length; /* Size in bytes of this entry in $SDS stream. */ 18528c2ecf20Sopenharmony_ci/* 20*/ SECURITY_DESCRIPTOR_RELATIVE sid; /* The self-relative security 18538c2ecf20Sopenharmony_ci descriptor. */ 18548c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) SDS_ENTRY; 18558c2ecf20Sopenharmony_ci 18568c2ecf20Sopenharmony_ci/* 18578c2ecf20Sopenharmony_ci * The index entry key used in the $SII index. The collation type is 18588c2ecf20Sopenharmony_ci * COLLATION_NTOFS_ULONG. 18598c2ecf20Sopenharmony_ci */ 18608c2ecf20Sopenharmony_citypedef struct { 18618c2ecf20Sopenharmony_ci le32 security_id; /* The security_id assigned to the descriptor. */ 18628c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) SII_INDEX_KEY; 18638c2ecf20Sopenharmony_ci 18648c2ecf20Sopenharmony_ci/* 18658c2ecf20Sopenharmony_ci * The index entry key used in the $SDH index. The keys are sorted first by 18668c2ecf20Sopenharmony_ci * hash and then by security_id. The collation rule is 18678c2ecf20Sopenharmony_ci * COLLATION_NTOFS_SECURITY_HASH. 18688c2ecf20Sopenharmony_ci */ 18698c2ecf20Sopenharmony_citypedef struct { 18708c2ecf20Sopenharmony_ci le32 hash; /* Hash of the security descriptor. */ 18718c2ecf20Sopenharmony_ci le32 security_id; /* The security_id assigned to the descriptor. */ 18728c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) SDH_INDEX_KEY; 18738c2ecf20Sopenharmony_ci 18748c2ecf20Sopenharmony_ci/* 18758c2ecf20Sopenharmony_ci * Attribute: Volume name (0x60). 18768c2ecf20Sopenharmony_ci * 18778c2ecf20Sopenharmony_ci * NOTE: Always resident. 18788c2ecf20Sopenharmony_ci * NOTE: Present only in FILE_Volume. 18798c2ecf20Sopenharmony_ci */ 18808c2ecf20Sopenharmony_citypedef struct { 18818c2ecf20Sopenharmony_ci ntfschar name[0]; /* The name of the volume in Unicode. */ 18828c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) VOLUME_NAME; 18838c2ecf20Sopenharmony_ci 18848c2ecf20Sopenharmony_ci/* 18858c2ecf20Sopenharmony_ci * Possible flags for the volume (16-bit). 18868c2ecf20Sopenharmony_ci */ 18878c2ecf20Sopenharmony_cienum { 18888c2ecf20Sopenharmony_ci VOLUME_IS_DIRTY = cpu_to_le16(0x0001), 18898c2ecf20Sopenharmony_ci VOLUME_RESIZE_LOG_FILE = cpu_to_le16(0x0002), 18908c2ecf20Sopenharmony_ci VOLUME_UPGRADE_ON_MOUNT = cpu_to_le16(0x0004), 18918c2ecf20Sopenharmony_ci VOLUME_MOUNTED_ON_NT4 = cpu_to_le16(0x0008), 18928c2ecf20Sopenharmony_ci 18938c2ecf20Sopenharmony_ci VOLUME_DELETE_USN_UNDERWAY = cpu_to_le16(0x0010), 18948c2ecf20Sopenharmony_ci VOLUME_REPAIR_OBJECT_ID = cpu_to_le16(0x0020), 18958c2ecf20Sopenharmony_ci 18968c2ecf20Sopenharmony_ci VOLUME_CHKDSK_UNDERWAY = cpu_to_le16(0x4000), 18978c2ecf20Sopenharmony_ci VOLUME_MODIFIED_BY_CHKDSK = cpu_to_le16(0x8000), 18988c2ecf20Sopenharmony_ci 18998c2ecf20Sopenharmony_ci VOLUME_FLAGS_MASK = cpu_to_le16(0xc03f), 19008c2ecf20Sopenharmony_ci 19018c2ecf20Sopenharmony_ci /* To make our life easier when checking if we must mount read-only. */ 19028c2ecf20Sopenharmony_ci VOLUME_MUST_MOUNT_RO_MASK = cpu_to_le16(0xc027), 19038c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 19048c2ecf20Sopenharmony_ci 19058c2ecf20Sopenharmony_citypedef le16 VOLUME_FLAGS; 19068c2ecf20Sopenharmony_ci 19078c2ecf20Sopenharmony_ci/* 19088c2ecf20Sopenharmony_ci * Attribute: Volume information (0x70). 19098c2ecf20Sopenharmony_ci * 19108c2ecf20Sopenharmony_ci * NOTE: Always resident. 19118c2ecf20Sopenharmony_ci * NOTE: Present only in FILE_Volume. 19128c2ecf20Sopenharmony_ci * NOTE: Windows 2000 uses NTFS 3.0 while Windows NT4 service pack 6a uses 19138c2ecf20Sopenharmony_ci * NTFS 1.2. I haven't personally seen other values yet. 19148c2ecf20Sopenharmony_ci */ 19158c2ecf20Sopenharmony_citypedef struct { 19168c2ecf20Sopenharmony_ci le64 reserved; /* Not used (yet?). */ 19178c2ecf20Sopenharmony_ci u8 major_ver; /* Major version of the ntfs format. */ 19188c2ecf20Sopenharmony_ci u8 minor_ver; /* Minor version of the ntfs format. */ 19198c2ecf20Sopenharmony_ci VOLUME_FLAGS flags; /* Bit array of VOLUME_* flags. */ 19208c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) VOLUME_INFORMATION; 19218c2ecf20Sopenharmony_ci 19228c2ecf20Sopenharmony_ci/* 19238c2ecf20Sopenharmony_ci * Attribute: Data attribute (0x80). 19248c2ecf20Sopenharmony_ci * 19258c2ecf20Sopenharmony_ci * NOTE: Can be resident or non-resident. 19268c2ecf20Sopenharmony_ci * 19278c2ecf20Sopenharmony_ci * Data contents of a file (i.e. the unnamed stream) or of a named stream. 19288c2ecf20Sopenharmony_ci */ 19298c2ecf20Sopenharmony_citypedef struct { 19308c2ecf20Sopenharmony_ci u8 data[0]; /* The file's data contents. */ 19318c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) DATA_ATTR; 19328c2ecf20Sopenharmony_ci 19338c2ecf20Sopenharmony_ci/* 19348c2ecf20Sopenharmony_ci * Index header flags (8-bit). 19358c2ecf20Sopenharmony_ci */ 19368c2ecf20Sopenharmony_cienum { 19378c2ecf20Sopenharmony_ci /* 19388c2ecf20Sopenharmony_ci * When index header is in an index root attribute: 19398c2ecf20Sopenharmony_ci */ 19408c2ecf20Sopenharmony_ci SMALL_INDEX = 0, /* The index is small enough to fit inside the index 19418c2ecf20Sopenharmony_ci root attribute and there is no index allocation 19428c2ecf20Sopenharmony_ci attribute present. */ 19438c2ecf20Sopenharmony_ci LARGE_INDEX = 1, /* The index is too large to fit in the index root 19448c2ecf20Sopenharmony_ci attribute and/or an index allocation attribute is 19458c2ecf20Sopenharmony_ci present. */ 19468c2ecf20Sopenharmony_ci /* 19478c2ecf20Sopenharmony_ci * When index header is in an index block, i.e. is part of index 19488c2ecf20Sopenharmony_ci * allocation attribute: 19498c2ecf20Sopenharmony_ci */ 19508c2ecf20Sopenharmony_ci LEAF_NODE = 0, /* This is a leaf node, i.e. there are no more nodes 19518c2ecf20Sopenharmony_ci branching off it. */ 19528c2ecf20Sopenharmony_ci INDEX_NODE = 1, /* This node indexes other nodes, i.e. it is not a leaf 19538c2ecf20Sopenharmony_ci node. */ 19548c2ecf20Sopenharmony_ci NODE_MASK = 1, /* Mask for accessing the *_NODE bits. */ 19558c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 19568c2ecf20Sopenharmony_ci 19578c2ecf20Sopenharmony_citypedef u8 INDEX_HEADER_FLAGS; 19588c2ecf20Sopenharmony_ci 19598c2ecf20Sopenharmony_ci/* 19608c2ecf20Sopenharmony_ci * This is the header for indexes, describing the INDEX_ENTRY records, which 19618c2ecf20Sopenharmony_ci * follow the INDEX_HEADER. Together the index header and the index entries 19628c2ecf20Sopenharmony_ci * make up a complete index. 19638c2ecf20Sopenharmony_ci * 19648c2ecf20Sopenharmony_ci * IMPORTANT NOTE: The offset, length and size structure members are counted 19658c2ecf20Sopenharmony_ci * relative to the start of the index header structure and not relative to the 19668c2ecf20Sopenharmony_ci * start of the index root or index allocation structures themselves. 19678c2ecf20Sopenharmony_ci */ 19688c2ecf20Sopenharmony_citypedef struct { 19698c2ecf20Sopenharmony_ci le32 entries_offset; /* Byte offset to first INDEX_ENTRY 19708c2ecf20Sopenharmony_ci aligned to 8-byte boundary. */ 19718c2ecf20Sopenharmony_ci le32 index_length; /* Data size of the index in bytes, 19728c2ecf20Sopenharmony_ci i.e. bytes used from allocated 19738c2ecf20Sopenharmony_ci size, aligned to 8-byte boundary. */ 19748c2ecf20Sopenharmony_ci le32 allocated_size; /* Byte size of this index (block), 19758c2ecf20Sopenharmony_ci multiple of 8 bytes. */ 19768c2ecf20Sopenharmony_ci /* NOTE: For the index root attribute, the above two numbers are always 19778c2ecf20Sopenharmony_ci equal, as the attribute is resident and it is resized as needed. In 19788c2ecf20Sopenharmony_ci the case of the index allocation attribute the attribute is not 19798c2ecf20Sopenharmony_ci resident and hence the allocated_size is a fixed value and must 19808c2ecf20Sopenharmony_ci equal the index_block_size specified by the INDEX_ROOT attribute 19818c2ecf20Sopenharmony_ci corresponding to the INDEX_ALLOCATION attribute this INDEX_BLOCK 19828c2ecf20Sopenharmony_ci belongs to. */ 19838c2ecf20Sopenharmony_ci INDEX_HEADER_FLAGS flags; /* Bit field of INDEX_HEADER_FLAGS. */ 19848c2ecf20Sopenharmony_ci u8 reserved[3]; /* Reserved/align to 8-byte boundary. */ 19858c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) INDEX_HEADER; 19868c2ecf20Sopenharmony_ci 19878c2ecf20Sopenharmony_ci/* 19888c2ecf20Sopenharmony_ci * Attribute: Index root (0x90). 19898c2ecf20Sopenharmony_ci * 19908c2ecf20Sopenharmony_ci * NOTE: Always resident. 19918c2ecf20Sopenharmony_ci * 19928c2ecf20Sopenharmony_ci * This is followed by a sequence of index entries (INDEX_ENTRY structures) 19938c2ecf20Sopenharmony_ci * as described by the index header. 19948c2ecf20Sopenharmony_ci * 19958c2ecf20Sopenharmony_ci * When a directory is small enough to fit inside the index root then this 19968c2ecf20Sopenharmony_ci * is the only attribute describing the directory. When the directory is too 19978c2ecf20Sopenharmony_ci * large to fit in the index root, on the other hand, two additional attributes 19988c2ecf20Sopenharmony_ci * are present: an index allocation attribute, containing sub-nodes of the B+ 19998c2ecf20Sopenharmony_ci * directory tree (see below), and a bitmap attribute, describing which virtual 20008c2ecf20Sopenharmony_ci * cluster numbers (vcns) in the index allocation attribute are in use by an 20018c2ecf20Sopenharmony_ci * index block. 20028c2ecf20Sopenharmony_ci * 20038c2ecf20Sopenharmony_ci * NOTE: The root directory (FILE_root) contains an entry for itself. Other 20048c2ecf20Sopenharmony_ci * directories do not contain entries for themselves, though. 20058c2ecf20Sopenharmony_ci */ 20068c2ecf20Sopenharmony_citypedef struct { 20078c2ecf20Sopenharmony_ci ATTR_TYPE type; /* Type of the indexed attribute. Is 20088c2ecf20Sopenharmony_ci $FILE_NAME for directories, zero 20098c2ecf20Sopenharmony_ci for view indexes. No other values 20108c2ecf20Sopenharmony_ci allowed. */ 20118c2ecf20Sopenharmony_ci COLLATION_RULE collation_rule; /* Collation rule used to sort the 20128c2ecf20Sopenharmony_ci index entries. If type is $FILE_NAME, 20138c2ecf20Sopenharmony_ci this must be COLLATION_FILE_NAME. */ 20148c2ecf20Sopenharmony_ci le32 index_block_size; /* Size of each index block in bytes (in 20158c2ecf20Sopenharmony_ci the index allocation attribute). */ 20168c2ecf20Sopenharmony_ci u8 clusters_per_index_block; /* Cluster size of each index block (in 20178c2ecf20Sopenharmony_ci the index allocation attribute), when 20188c2ecf20Sopenharmony_ci an index block is >= than a cluster, 20198c2ecf20Sopenharmony_ci otherwise this will be the log of 20208c2ecf20Sopenharmony_ci the size (like how the encoding of 20218c2ecf20Sopenharmony_ci the mft record size and the index 20228c2ecf20Sopenharmony_ci record size found in the boot sector 20238c2ecf20Sopenharmony_ci work). Has to be a power of 2. */ 20248c2ecf20Sopenharmony_ci u8 reserved[3]; /* Reserved/align to 8-byte boundary. */ 20258c2ecf20Sopenharmony_ci INDEX_HEADER index; /* Index header describing the 20268c2ecf20Sopenharmony_ci following index entries. */ 20278c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) INDEX_ROOT; 20288c2ecf20Sopenharmony_ci 20298c2ecf20Sopenharmony_ci/* 20308c2ecf20Sopenharmony_ci * Attribute: Index allocation (0xa0). 20318c2ecf20Sopenharmony_ci * 20328c2ecf20Sopenharmony_ci * NOTE: Always non-resident (doesn't make sense to be resident anyway!). 20338c2ecf20Sopenharmony_ci * 20348c2ecf20Sopenharmony_ci * This is an array of index blocks. Each index block starts with an 20358c2ecf20Sopenharmony_ci * INDEX_BLOCK structure containing an index header, followed by a sequence of 20368c2ecf20Sopenharmony_ci * index entries (INDEX_ENTRY structures), as described by the INDEX_HEADER. 20378c2ecf20Sopenharmony_ci */ 20388c2ecf20Sopenharmony_citypedef struct { 20398c2ecf20Sopenharmony_ci/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ 20408c2ecf20Sopenharmony_ci NTFS_RECORD_TYPE magic; /* Magic is "INDX". */ 20418c2ecf20Sopenharmony_ci le16 usa_ofs; /* See NTFS_RECORD definition. */ 20428c2ecf20Sopenharmony_ci le16 usa_count; /* See NTFS_RECORD definition. */ 20438c2ecf20Sopenharmony_ci 20448c2ecf20Sopenharmony_ci/* 8*/ sle64 lsn; /* $LogFile sequence number of the last 20458c2ecf20Sopenharmony_ci modification of this index block. */ 20468c2ecf20Sopenharmony_ci/* 16*/ leVCN index_block_vcn; /* Virtual cluster number of the index block. 20478c2ecf20Sopenharmony_ci If the cluster_size on the volume is <= the 20488c2ecf20Sopenharmony_ci index_block_size of the directory, 20498c2ecf20Sopenharmony_ci index_block_vcn counts in units of clusters, 20508c2ecf20Sopenharmony_ci and in units of sectors otherwise. */ 20518c2ecf20Sopenharmony_ci/* 24*/ INDEX_HEADER index; /* Describes the following index entries. */ 20528c2ecf20Sopenharmony_ci/* sizeof()= 40 (0x28) bytes */ 20538c2ecf20Sopenharmony_ci/* 20548c2ecf20Sopenharmony_ci * When creating the index block, we place the update sequence array at this 20558c2ecf20Sopenharmony_ci * offset, i.e. before we start with the index entries. This also makes sense, 20568c2ecf20Sopenharmony_ci * otherwise we could run into problems with the update sequence array 20578c2ecf20Sopenharmony_ci * containing in itself the last two bytes of a sector which would mean that 20588c2ecf20Sopenharmony_ci * multi sector transfer protection wouldn't work. As you can't protect data 20598c2ecf20Sopenharmony_ci * by overwriting it since you then can't get it back... 20608c2ecf20Sopenharmony_ci * When reading use the data from the ntfs record header. 20618c2ecf20Sopenharmony_ci */ 20628c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) INDEX_BLOCK; 20638c2ecf20Sopenharmony_ci 20648c2ecf20Sopenharmony_citypedef INDEX_BLOCK INDEX_ALLOCATION; 20658c2ecf20Sopenharmony_ci 20668c2ecf20Sopenharmony_ci/* 20678c2ecf20Sopenharmony_ci * The system file FILE_Extend/$Reparse contains an index named $R listing 20688c2ecf20Sopenharmony_ci * all reparse points on the volume. The index entry keys are as defined 20698c2ecf20Sopenharmony_ci * below. Note, that there is no index data associated with the index entries. 20708c2ecf20Sopenharmony_ci * 20718c2ecf20Sopenharmony_ci * The index entries are sorted by the index key file_id. The collation rule is 20728c2ecf20Sopenharmony_ci * COLLATION_NTOFS_ULONGS. FIXME: Verify whether the reparse_tag is not the 20738c2ecf20Sopenharmony_ci * primary key / is not a key at all. (AIA) 20748c2ecf20Sopenharmony_ci */ 20758c2ecf20Sopenharmony_citypedef struct { 20768c2ecf20Sopenharmony_ci le32 reparse_tag; /* Reparse point type (inc. flags). */ 20778c2ecf20Sopenharmony_ci leMFT_REF file_id; /* Mft record of the file containing the 20788c2ecf20Sopenharmony_ci reparse point attribute. */ 20798c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) REPARSE_INDEX_KEY; 20808c2ecf20Sopenharmony_ci 20818c2ecf20Sopenharmony_ci/* 20828c2ecf20Sopenharmony_ci * Quota flags (32-bit). 20838c2ecf20Sopenharmony_ci * 20848c2ecf20Sopenharmony_ci * The user quota flags. Names explain meaning. 20858c2ecf20Sopenharmony_ci */ 20868c2ecf20Sopenharmony_cienum { 20878c2ecf20Sopenharmony_ci QUOTA_FLAG_DEFAULT_LIMITS = cpu_to_le32(0x00000001), 20888c2ecf20Sopenharmony_ci QUOTA_FLAG_LIMIT_REACHED = cpu_to_le32(0x00000002), 20898c2ecf20Sopenharmony_ci QUOTA_FLAG_ID_DELETED = cpu_to_le32(0x00000004), 20908c2ecf20Sopenharmony_ci 20918c2ecf20Sopenharmony_ci QUOTA_FLAG_USER_MASK = cpu_to_le32(0x00000007), 20928c2ecf20Sopenharmony_ci /* This is a bit mask for the user quota flags. */ 20938c2ecf20Sopenharmony_ci 20948c2ecf20Sopenharmony_ci /* 20958c2ecf20Sopenharmony_ci * These flags are only present in the quota defaults index entry, i.e. 20968c2ecf20Sopenharmony_ci * in the entry where owner_id = QUOTA_DEFAULTS_ID. 20978c2ecf20Sopenharmony_ci */ 20988c2ecf20Sopenharmony_ci QUOTA_FLAG_TRACKING_ENABLED = cpu_to_le32(0x00000010), 20998c2ecf20Sopenharmony_ci QUOTA_FLAG_ENFORCEMENT_ENABLED = cpu_to_le32(0x00000020), 21008c2ecf20Sopenharmony_ci QUOTA_FLAG_TRACKING_REQUESTED = cpu_to_le32(0x00000040), 21018c2ecf20Sopenharmony_ci QUOTA_FLAG_LOG_THRESHOLD = cpu_to_le32(0x00000080), 21028c2ecf20Sopenharmony_ci 21038c2ecf20Sopenharmony_ci QUOTA_FLAG_LOG_LIMIT = cpu_to_le32(0x00000100), 21048c2ecf20Sopenharmony_ci QUOTA_FLAG_OUT_OF_DATE = cpu_to_le32(0x00000200), 21058c2ecf20Sopenharmony_ci QUOTA_FLAG_CORRUPT = cpu_to_le32(0x00000400), 21068c2ecf20Sopenharmony_ci QUOTA_FLAG_PENDING_DELETES = cpu_to_le32(0x00000800), 21078c2ecf20Sopenharmony_ci}; 21088c2ecf20Sopenharmony_ci 21098c2ecf20Sopenharmony_citypedef le32 QUOTA_FLAGS; 21108c2ecf20Sopenharmony_ci 21118c2ecf20Sopenharmony_ci/* 21128c2ecf20Sopenharmony_ci * The system file FILE_Extend/$Quota contains two indexes $O and $Q. Quotas 21138c2ecf20Sopenharmony_ci * are on a per volume and per user basis. 21148c2ecf20Sopenharmony_ci * 21158c2ecf20Sopenharmony_ci * The $Q index contains one entry for each existing user_id on the volume. The 21168c2ecf20Sopenharmony_ci * index key is the user_id of the user/group owning this quota control entry, 21178c2ecf20Sopenharmony_ci * i.e. the key is the owner_id. The user_id of the owner of a file, i.e. the 21188c2ecf20Sopenharmony_ci * owner_id, is found in the standard information attribute. The collation rule 21198c2ecf20Sopenharmony_ci * for $Q is COLLATION_NTOFS_ULONG. 21208c2ecf20Sopenharmony_ci * 21218c2ecf20Sopenharmony_ci * The $O index contains one entry for each user/group who has been assigned 21228c2ecf20Sopenharmony_ci * a quota on that volume. The index key holds the SID of the user_id the 21238c2ecf20Sopenharmony_ci * entry belongs to, i.e. the owner_id. The collation rule for $O is 21248c2ecf20Sopenharmony_ci * COLLATION_NTOFS_SID. 21258c2ecf20Sopenharmony_ci * 21268c2ecf20Sopenharmony_ci * The $O index entry data is the user_id of the user corresponding to the SID. 21278c2ecf20Sopenharmony_ci * This user_id is used as an index into $Q to find the quota control entry 21288c2ecf20Sopenharmony_ci * associated with the SID. 21298c2ecf20Sopenharmony_ci * 21308c2ecf20Sopenharmony_ci * The $Q index entry data is the quota control entry and is defined below. 21318c2ecf20Sopenharmony_ci */ 21328c2ecf20Sopenharmony_citypedef struct { 21338c2ecf20Sopenharmony_ci le32 version; /* Currently equals 2. */ 21348c2ecf20Sopenharmony_ci QUOTA_FLAGS flags; /* Flags describing this quota entry. */ 21358c2ecf20Sopenharmony_ci le64 bytes_used; /* How many bytes of the quota are in use. */ 21368c2ecf20Sopenharmony_ci sle64 change_time; /* Last time this quota entry was changed. */ 21378c2ecf20Sopenharmony_ci sle64 threshold; /* Soft quota (-1 if not limited). */ 21388c2ecf20Sopenharmony_ci sle64 limit; /* Hard quota (-1 if not limited). */ 21398c2ecf20Sopenharmony_ci sle64 exceeded_time; /* How long the soft quota has been exceeded. */ 21408c2ecf20Sopenharmony_ci SID sid; /* The SID of the user/object associated with 21418c2ecf20Sopenharmony_ci this quota entry. Equals zero for the quota 21428c2ecf20Sopenharmony_ci defaults entry (and in fact on a WinXP 21438c2ecf20Sopenharmony_ci volume, it is not present at all). */ 21448c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) QUOTA_CONTROL_ENTRY; 21458c2ecf20Sopenharmony_ci 21468c2ecf20Sopenharmony_ci/* 21478c2ecf20Sopenharmony_ci * Predefined owner_id values (32-bit). 21488c2ecf20Sopenharmony_ci */ 21498c2ecf20Sopenharmony_cienum { 21508c2ecf20Sopenharmony_ci QUOTA_INVALID_ID = cpu_to_le32(0x00000000), 21518c2ecf20Sopenharmony_ci QUOTA_DEFAULTS_ID = cpu_to_le32(0x00000001), 21528c2ecf20Sopenharmony_ci QUOTA_FIRST_USER_ID = cpu_to_le32(0x00000100), 21538c2ecf20Sopenharmony_ci}; 21548c2ecf20Sopenharmony_ci 21558c2ecf20Sopenharmony_ci/* 21568c2ecf20Sopenharmony_ci * Current constants for quota control entries. 21578c2ecf20Sopenharmony_ci */ 21588c2ecf20Sopenharmony_citypedef enum { 21598c2ecf20Sopenharmony_ci /* Current version. */ 21608c2ecf20Sopenharmony_ci QUOTA_VERSION = 2, 21618c2ecf20Sopenharmony_ci} QUOTA_CONTROL_ENTRY_CONSTANTS; 21628c2ecf20Sopenharmony_ci 21638c2ecf20Sopenharmony_ci/* 21648c2ecf20Sopenharmony_ci * Index entry flags (16-bit). 21658c2ecf20Sopenharmony_ci */ 21668c2ecf20Sopenharmony_cienum { 21678c2ecf20Sopenharmony_ci INDEX_ENTRY_NODE = cpu_to_le16(1), /* This entry contains a 21688c2ecf20Sopenharmony_ci sub-node, i.e. a reference to an index block in form of 21698c2ecf20Sopenharmony_ci a virtual cluster number (see below). */ 21708c2ecf20Sopenharmony_ci INDEX_ENTRY_END = cpu_to_le16(2), /* This signifies the last 21718c2ecf20Sopenharmony_ci entry in an index block. The index entry does not 21728c2ecf20Sopenharmony_ci represent a file but it can point to a sub-node. */ 21738c2ecf20Sopenharmony_ci 21748c2ecf20Sopenharmony_ci INDEX_ENTRY_SPACE_FILLER = cpu_to_le16(0xffff), /* gcc: Force 21758c2ecf20Sopenharmony_ci enum bit width to 16-bit. */ 21768c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 21778c2ecf20Sopenharmony_ci 21788c2ecf20Sopenharmony_citypedef le16 INDEX_ENTRY_FLAGS; 21798c2ecf20Sopenharmony_ci 21808c2ecf20Sopenharmony_ci/* 21818c2ecf20Sopenharmony_ci * This the index entry header (see below). 21828c2ecf20Sopenharmony_ci */ 21838c2ecf20Sopenharmony_citypedef struct { 21848c2ecf20Sopenharmony_ci/* 0*/ union { 21858c2ecf20Sopenharmony_ci struct { /* Only valid when INDEX_ENTRY_END is not set. */ 21868c2ecf20Sopenharmony_ci leMFT_REF indexed_file; /* The mft reference of the file 21878c2ecf20Sopenharmony_ci described by this index 21888c2ecf20Sopenharmony_ci entry. Used for directory 21898c2ecf20Sopenharmony_ci indexes. */ 21908c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) dir; 21918c2ecf20Sopenharmony_ci struct { /* Used for views/indexes to find the entry's data. */ 21928c2ecf20Sopenharmony_ci le16 data_offset; /* Data byte offset from this 21938c2ecf20Sopenharmony_ci INDEX_ENTRY. Follows the 21948c2ecf20Sopenharmony_ci index key. */ 21958c2ecf20Sopenharmony_ci le16 data_length; /* Data length in bytes. */ 21968c2ecf20Sopenharmony_ci le32 reservedV; /* Reserved (zero). */ 21978c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) vi; 21988c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) data; 21998c2ecf20Sopenharmony_ci/* 8*/ le16 length; /* Byte size of this index entry, multiple of 22008c2ecf20Sopenharmony_ci 8-bytes. */ 22018c2ecf20Sopenharmony_ci/* 10*/ le16 key_length; /* Byte size of the key value, which is in the 22028c2ecf20Sopenharmony_ci index entry. It follows field reserved. Not 22038c2ecf20Sopenharmony_ci multiple of 8-bytes. */ 22048c2ecf20Sopenharmony_ci/* 12*/ INDEX_ENTRY_FLAGS flags; /* Bit field of INDEX_ENTRY_* flags. */ 22058c2ecf20Sopenharmony_ci/* 14*/ le16 reserved; /* Reserved/align to 8-byte boundary. */ 22068c2ecf20Sopenharmony_ci/* sizeof() = 16 bytes */ 22078c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) INDEX_ENTRY_HEADER; 22088c2ecf20Sopenharmony_ci 22098c2ecf20Sopenharmony_ci/* 22108c2ecf20Sopenharmony_ci * This is an index entry. A sequence of such entries follows each INDEX_HEADER 22118c2ecf20Sopenharmony_ci * structure. Together they make up a complete index. The index follows either 22128c2ecf20Sopenharmony_ci * an index root attribute or an index allocation attribute. 22138c2ecf20Sopenharmony_ci * 22148c2ecf20Sopenharmony_ci * NOTE: Before NTFS 3.0 only filename attributes were indexed. 22158c2ecf20Sopenharmony_ci */ 22168c2ecf20Sopenharmony_citypedef struct { 22178c2ecf20Sopenharmony_ci/*Ofs*/ 22188c2ecf20Sopenharmony_ci/* 0 INDEX_ENTRY_HEADER; -- Unfolded here as gcc dislikes unnamed structs. */ 22198c2ecf20Sopenharmony_ci union { 22208c2ecf20Sopenharmony_ci struct { /* Only valid when INDEX_ENTRY_END is not set. */ 22218c2ecf20Sopenharmony_ci leMFT_REF indexed_file; /* The mft reference of the file 22228c2ecf20Sopenharmony_ci described by this index 22238c2ecf20Sopenharmony_ci entry. Used for directory 22248c2ecf20Sopenharmony_ci indexes. */ 22258c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) dir; 22268c2ecf20Sopenharmony_ci struct { /* Used for views/indexes to find the entry's data. */ 22278c2ecf20Sopenharmony_ci le16 data_offset; /* Data byte offset from this 22288c2ecf20Sopenharmony_ci INDEX_ENTRY. Follows the 22298c2ecf20Sopenharmony_ci index key. */ 22308c2ecf20Sopenharmony_ci le16 data_length; /* Data length in bytes. */ 22318c2ecf20Sopenharmony_ci le32 reservedV; /* Reserved (zero). */ 22328c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) vi; 22338c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) data; 22348c2ecf20Sopenharmony_ci le16 length; /* Byte size of this index entry, multiple of 22358c2ecf20Sopenharmony_ci 8-bytes. */ 22368c2ecf20Sopenharmony_ci le16 key_length; /* Byte size of the key value, which is in the 22378c2ecf20Sopenharmony_ci index entry. It follows field reserved. Not 22388c2ecf20Sopenharmony_ci multiple of 8-bytes. */ 22398c2ecf20Sopenharmony_ci INDEX_ENTRY_FLAGS flags; /* Bit field of INDEX_ENTRY_* flags. */ 22408c2ecf20Sopenharmony_ci le16 reserved; /* Reserved/align to 8-byte boundary. */ 22418c2ecf20Sopenharmony_ci 22428c2ecf20Sopenharmony_ci/* 16*/ union { /* The key of the indexed attribute. NOTE: Only present 22438c2ecf20Sopenharmony_ci if INDEX_ENTRY_END bit in flags is not set. NOTE: On 22448c2ecf20Sopenharmony_ci NTFS versions before 3.0 the only valid key is the 22458c2ecf20Sopenharmony_ci FILE_NAME_ATTR. On NTFS 3.0+ the following 22468c2ecf20Sopenharmony_ci additional index keys are defined: */ 22478c2ecf20Sopenharmony_ci FILE_NAME_ATTR file_name;/* $I30 index in directories. */ 22488c2ecf20Sopenharmony_ci SII_INDEX_KEY sii; /* $SII index in $Secure. */ 22498c2ecf20Sopenharmony_ci SDH_INDEX_KEY sdh; /* $SDH index in $Secure. */ 22508c2ecf20Sopenharmony_ci GUID object_id; /* $O index in FILE_Extend/$ObjId: The 22518c2ecf20Sopenharmony_ci object_id of the mft record found in 22528c2ecf20Sopenharmony_ci the data part of the index. */ 22538c2ecf20Sopenharmony_ci REPARSE_INDEX_KEY reparse; /* $R index in 22548c2ecf20Sopenharmony_ci FILE_Extend/$Reparse. */ 22558c2ecf20Sopenharmony_ci SID sid; /* $O index in FILE_Extend/$Quota: 22568c2ecf20Sopenharmony_ci SID of the owner of the user_id. */ 22578c2ecf20Sopenharmony_ci le32 owner_id; /* $Q index in FILE_Extend/$Quota: 22588c2ecf20Sopenharmony_ci user_id of the owner of the quota 22598c2ecf20Sopenharmony_ci control entry in the data part of 22608c2ecf20Sopenharmony_ci the index. */ 22618c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) key; 22628c2ecf20Sopenharmony_ci /* The (optional) index data is inserted here when creating. */ 22638c2ecf20Sopenharmony_ci // leVCN vcn; /* If INDEX_ENTRY_NODE bit in flags is set, the last 22648c2ecf20Sopenharmony_ci // eight bytes of this index entry contain the virtual 22658c2ecf20Sopenharmony_ci // cluster number of the index block that holds the 22668c2ecf20Sopenharmony_ci // entries immediately preceding the current entry (the 22678c2ecf20Sopenharmony_ci // vcn references the corresponding cluster in the data 22688c2ecf20Sopenharmony_ci // of the non-resident index allocation attribute). If 22698c2ecf20Sopenharmony_ci // the key_length is zero, then the vcn immediately 22708c2ecf20Sopenharmony_ci // follows the INDEX_ENTRY_HEADER. Regardless of 22718c2ecf20Sopenharmony_ci // key_length, the address of the 8-byte boundary 22728c2ecf20Sopenharmony_ci // aligned vcn of INDEX_ENTRY{_HEADER} *ie is given by 22738c2ecf20Sopenharmony_ci // (char*)ie + le16_to_cpu(ie*)->length) - sizeof(VCN), 22748c2ecf20Sopenharmony_ci // where sizeof(VCN) can be hardcoded as 8 if wanted. */ 22758c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) INDEX_ENTRY; 22768c2ecf20Sopenharmony_ci 22778c2ecf20Sopenharmony_ci/* 22788c2ecf20Sopenharmony_ci * Attribute: Bitmap (0xb0). 22798c2ecf20Sopenharmony_ci * 22808c2ecf20Sopenharmony_ci * Contains an array of bits (aka a bitfield). 22818c2ecf20Sopenharmony_ci * 22828c2ecf20Sopenharmony_ci * When used in conjunction with the index allocation attribute, each bit 22838c2ecf20Sopenharmony_ci * corresponds to one index block within the index allocation attribute. Thus 22848c2ecf20Sopenharmony_ci * the number of bits in the bitmap * index block size / cluster size is the 22858c2ecf20Sopenharmony_ci * number of clusters in the index allocation attribute. 22868c2ecf20Sopenharmony_ci */ 22878c2ecf20Sopenharmony_citypedef struct { 22888c2ecf20Sopenharmony_ci u8 bitmap[0]; /* Array of bits. */ 22898c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) BITMAP_ATTR; 22908c2ecf20Sopenharmony_ci 22918c2ecf20Sopenharmony_ci/* 22928c2ecf20Sopenharmony_ci * The reparse point tag defines the type of the reparse point. It also 22938c2ecf20Sopenharmony_ci * includes several flags, which further describe the reparse point. 22948c2ecf20Sopenharmony_ci * 22958c2ecf20Sopenharmony_ci * The reparse point tag is an unsigned 32-bit value divided in three parts: 22968c2ecf20Sopenharmony_ci * 22978c2ecf20Sopenharmony_ci * 1. The least significant 16 bits (i.e. bits 0 to 15) specifiy the type of 22988c2ecf20Sopenharmony_ci * the reparse point. 22998c2ecf20Sopenharmony_ci * 2. The 13 bits after this (i.e. bits 16 to 28) are reserved for future use. 23008c2ecf20Sopenharmony_ci * 3. The most significant three bits are flags describing the reparse point. 23018c2ecf20Sopenharmony_ci * They are defined as follows: 23028c2ecf20Sopenharmony_ci * bit 29: Name surrogate bit. If set, the filename is an alias for 23038c2ecf20Sopenharmony_ci * another object in the system. 23048c2ecf20Sopenharmony_ci * bit 30: High-latency bit. If set, accessing the first byte of data will 23058c2ecf20Sopenharmony_ci * be slow. (E.g. the data is stored on a tape drive.) 23068c2ecf20Sopenharmony_ci * bit 31: Microsoft bit. If set, the tag is owned by Microsoft. User 23078c2ecf20Sopenharmony_ci * defined tags have to use zero here. 23088c2ecf20Sopenharmony_ci * 23098c2ecf20Sopenharmony_ci * These are the predefined reparse point tags: 23108c2ecf20Sopenharmony_ci */ 23118c2ecf20Sopenharmony_cienum { 23128c2ecf20Sopenharmony_ci IO_REPARSE_TAG_IS_ALIAS = cpu_to_le32(0x20000000), 23138c2ecf20Sopenharmony_ci IO_REPARSE_TAG_IS_HIGH_LATENCY = cpu_to_le32(0x40000000), 23148c2ecf20Sopenharmony_ci IO_REPARSE_TAG_IS_MICROSOFT = cpu_to_le32(0x80000000), 23158c2ecf20Sopenharmony_ci 23168c2ecf20Sopenharmony_ci IO_REPARSE_TAG_RESERVED_ZERO = cpu_to_le32(0x00000000), 23178c2ecf20Sopenharmony_ci IO_REPARSE_TAG_RESERVED_ONE = cpu_to_le32(0x00000001), 23188c2ecf20Sopenharmony_ci IO_REPARSE_TAG_RESERVED_RANGE = cpu_to_le32(0x00000001), 23198c2ecf20Sopenharmony_ci 23208c2ecf20Sopenharmony_ci IO_REPARSE_TAG_NSS = cpu_to_le32(0x68000005), 23218c2ecf20Sopenharmony_ci IO_REPARSE_TAG_NSS_RECOVER = cpu_to_le32(0x68000006), 23228c2ecf20Sopenharmony_ci IO_REPARSE_TAG_SIS = cpu_to_le32(0x68000007), 23238c2ecf20Sopenharmony_ci IO_REPARSE_TAG_DFS = cpu_to_le32(0x68000008), 23248c2ecf20Sopenharmony_ci 23258c2ecf20Sopenharmony_ci IO_REPARSE_TAG_MOUNT_POINT = cpu_to_le32(0x88000003), 23268c2ecf20Sopenharmony_ci 23278c2ecf20Sopenharmony_ci IO_REPARSE_TAG_HSM = cpu_to_le32(0xa8000004), 23288c2ecf20Sopenharmony_ci 23298c2ecf20Sopenharmony_ci IO_REPARSE_TAG_SYMBOLIC_LINK = cpu_to_le32(0xe8000000), 23308c2ecf20Sopenharmony_ci 23318c2ecf20Sopenharmony_ci IO_REPARSE_TAG_VALID_VALUES = cpu_to_le32(0xe000ffff), 23328c2ecf20Sopenharmony_ci}; 23338c2ecf20Sopenharmony_ci 23348c2ecf20Sopenharmony_ci/* 23358c2ecf20Sopenharmony_ci * Attribute: Reparse point (0xc0). 23368c2ecf20Sopenharmony_ci * 23378c2ecf20Sopenharmony_ci * NOTE: Can be resident or non-resident. 23388c2ecf20Sopenharmony_ci */ 23398c2ecf20Sopenharmony_citypedef struct { 23408c2ecf20Sopenharmony_ci le32 reparse_tag; /* Reparse point type (inc. flags). */ 23418c2ecf20Sopenharmony_ci le16 reparse_data_length; /* Byte size of reparse data. */ 23428c2ecf20Sopenharmony_ci le16 reserved; /* Align to 8-byte boundary. */ 23438c2ecf20Sopenharmony_ci u8 reparse_data[0]; /* Meaning depends on reparse_tag. */ 23448c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) REPARSE_POINT; 23458c2ecf20Sopenharmony_ci 23468c2ecf20Sopenharmony_ci/* 23478c2ecf20Sopenharmony_ci * Attribute: Extended attribute (EA) information (0xd0). 23488c2ecf20Sopenharmony_ci * 23498c2ecf20Sopenharmony_ci * NOTE: Always resident. (Is this true???) 23508c2ecf20Sopenharmony_ci */ 23518c2ecf20Sopenharmony_citypedef struct { 23528c2ecf20Sopenharmony_ci le16 ea_length; /* Byte size of the packed extended 23538c2ecf20Sopenharmony_ci attributes. */ 23548c2ecf20Sopenharmony_ci le16 need_ea_count; /* The number of extended attributes which have 23558c2ecf20Sopenharmony_ci the NEED_EA bit set. */ 23568c2ecf20Sopenharmony_ci le32 ea_query_length; /* Byte size of the buffer required to query 23578c2ecf20Sopenharmony_ci the extended attributes when calling 23588c2ecf20Sopenharmony_ci ZwQueryEaFile() in Windows NT/2k. I.e. the 23598c2ecf20Sopenharmony_ci byte size of the unpacked extended 23608c2ecf20Sopenharmony_ci attributes. */ 23618c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) EA_INFORMATION; 23628c2ecf20Sopenharmony_ci 23638c2ecf20Sopenharmony_ci/* 23648c2ecf20Sopenharmony_ci * Extended attribute flags (8-bit). 23658c2ecf20Sopenharmony_ci */ 23668c2ecf20Sopenharmony_cienum { 23678c2ecf20Sopenharmony_ci NEED_EA = 0x80 /* If set the file to which the EA belongs 23688c2ecf20Sopenharmony_ci cannot be interpreted without understanding 23698c2ecf20Sopenharmony_ci the associates extended attributes. */ 23708c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 23718c2ecf20Sopenharmony_ci 23728c2ecf20Sopenharmony_citypedef u8 EA_FLAGS; 23738c2ecf20Sopenharmony_ci 23748c2ecf20Sopenharmony_ci/* 23758c2ecf20Sopenharmony_ci * Attribute: Extended attribute (EA) (0xe0). 23768c2ecf20Sopenharmony_ci * 23778c2ecf20Sopenharmony_ci * NOTE: Can be resident or non-resident. 23788c2ecf20Sopenharmony_ci * 23798c2ecf20Sopenharmony_ci * Like the attribute list and the index buffer list, the EA attribute value is 23808c2ecf20Sopenharmony_ci * a sequence of EA_ATTR variable length records. 23818c2ecf20Sopenharmony_ci */ 23828c2ecf20Sopenharmony_citypedef struct { 23838c2ecf20Sopenharmony_ci le32 next_entry_offset; /* Offset to the next EA_ATTR. */ 23848c2ecf20Sopenharmony_ci EA_FLAGS flags; /* Flags describing the EA. */ 23858c2ecf20Sopenharmony_ci u8 ea_name_length; /* Length of the name of the EA in bytes 23868c2ecf20Sopenharmony_ci excluding the '\0' byte terminator. */ 23878c2ecf20Sopenharmony_ci le16 ea_value_length; /* Byte size of the EA's value. */ 23888c2ecf20Sopenharmony_ci u8 ea_name[0]; /* Name of the EA. Note this is ASCII, not 23898c2ecf20Sopenharmony_ci Unicode and it is zero terminated. */ 23908c2ecf20Sopenharmony_ci u8 ea_value[0]; /* The value of the EA. Immediately follows 23918c2ecf20Sopenharmony_ci the name. */ 23928c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) EA_ATTR; 23938c2ecf20Sopenharmony_ci 23948c2ecf20Sopenharmony_ci/* 23958c2ecf20Sopenharmony_ci * Attribute: Property set (0xf0). 23968c2ecf20Sopenharmony_ci * 23978c2ecf20Sopenharmony_ci * Intended to support Native Structure Storage (NSS) - a feature removed from 23988c2ecf20Sopenharmony_ci * NTFS 3.0 during beta testing. 23998c2ecf20Sopenharmony_ci */ 24008c2ecf20Sopenharmony_citypedef struct { 24018c2ecf20Sopenharmony_ci /* Irrelevant as feature unused. */ 24028c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) PROPERTY_SET; 24038c2ecf20Sopenharmony_ci 24048c2ecf20Sopenharmony_ci/* 24058c2ecf20Sopenharmony_ci * Attribute: Logged utility stream (0x100). 24068c2ecf20Sopenharmony_ci * 24078c2ecf20Sopenharmony_ci * NOTE: Can be resident or non-resident. 24088c2ecf20Sopenharmony_ci * 24098c2ecf20Sopenharmony_ci * Operations on this attribute are logged to the journal ($LogFile) like 24108c2ecf20Sopenharmony_ci * normal metadata changes. 24118c2ecf20Sopenharmony_ci * 24128c2ecf20Sopenharmony_ci * Used by the Encrypting File System (EFS). All encrypted files have this 24138c2ecf20Sopenharmony_ci * attribute with the name $EFS. 24148c2ecf20Sopenharmony_ci */ 24158c2ecf20Sopenharmony_citypedef struct { 24168c2ecf20Sopenharmony_ci /* Can be anything the creator chooses. */ 24178c2ecf20Sopenharmony_ci /* EFS uses it as follows: */ 24188c2ecf20Sopenharmony_ci // FIXME: Type this info, verifying it along the way. (AIA) 24198c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)) LOGGED_UTILITY_STREAM, EFS_ATTR; 24208c2ecf20Sopenharmony_ci 24218c2ecf20Sopenharmony_ci#endif /* _LINUX_NTFS_LAYOUT_H */ 2422