162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * layout.h - All NTFS associated on-disk structures. Part of the Linux-NTFS 462306a36Sopenharmony_ci * project. 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Copyright (c) 2001-2005 Anton Altaparmakov 762306a36Sopenharmony_ci * Copyright (c) 2002 Richard Russon 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifndef _LINUX_NTFS_LAYOUT_H 1162306a36Sopenharmony_ci#define _LINUX_NTFS_LAYOUT_H 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#include <linux/types.h> 1462306a36Sopenharmony_ci#include <linux/bitops.h> 1562306a36Sopenharmony_ci#include <linux/list.h> 1662306a36Sopenharmony_ci#include <asm/byteorder.h> 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci#include "types.h" 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci/* The NTFS oem_id "NTFS " */ 2162306a36Sopenharmony_ci#define magicNTFS cpu_to_le64(0x202020205346544eULL) 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci/* 2462306a36Sopenharmony_ci * Location of bootsector on partition: 2562306a36Sopenharmony_ci * The standard NTFS_BOOT_SECTOR is on sector 0 of the partition. 2662306a36Sopenharmony_ci * On NT4 and above there is one backup copy of the boot sector to 2762306a36Sopenharmony_ci * be found on the last sector of the partition (not normally accessible 2862306a36Sopenharmony_ci * from within Windows as the bootsector contained number of sectors 2962306a36Sopenharmony_ci * value is one less than the actual value!). 3062306a36Sopenharmony_ci * On versions of NT 3.51 and earlier, the backup copy was located at 3162306a36Sopenharmony_ci * number of sectors/2 (integer divide), i.e. in the middle of the volume. 3262306a36Sopenharmony_ci */ 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci/* 3562306a36Sopenharmony_ci * BIOS parameter block (bpb) structure. 3662306a36Sopenharmony_ci */ 3762306a36Sopenharmony_citypedef struct { 3862306a36Sopenharmony_ci le16 bytes_per_sector; /* Size of a sector in bytes. */ 3962306a36Sopenharmony_ci u8 sectors_per_cluster; /* Size of a cluster in sectors. */ 4062306a36Sopenharmony_ci le16 reserved_sectors; /* zero */ 4162306a36Sopenharmony_ci u8 fats; /* zero */ 4262306a36Sopenharmony_ci le16 root_entries; /* zero */ 4362306a36Sopenharmony_ci le16 sectors; /* zero */ 4462306a36Sopenharmony_ci u8 media_type; /* 0xf8 = hard disk */ 4562306a36Sopenharmony_ci le16 sectors_per_fat; /* zero */ 4662306a36Sopenharmony_ci le16 sectors_per_track; /* irrelevant */ 4762306a36Sopenharmony_ci le16 heads; /* irrelevant */ 4862306a36Sopenharmony_ci le32 hidden_sectors; /* zero */ 4962306a36Sopenharmony_ci le32 large_sectors; /* zero */ 5062306a36Sopenharmony_ci} __attribute__ ((__packed__)) BIOS_PARAMETER_BLOCK; 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci/* 5362306a36Sopenharmony_ci * NTFS boot sector structure. 5462306a36Sopenharmony_ci */ 5562306a36Sopenharmony_citypedef struct { 5662306a36Sopenharmony_ci u8 jump[3]; /* Irrelevant (jump to boot up code).*/ 5762306a36Sopenharmony_ci le64 oem_id; /* Magic "NTFS ". */ 5862306a36Sopenharmony_ci BIOS_PARAMETER_BLOCK bpb; /* See BIOS_PARAMETER_BLOCK. */ 5962306a36Sopenharmony_ci u8 unused[4]; /* zero, NTFS diskedit.exe states that 6062306a36Sopenharmony_ci this is actually: 6162306a36Sopenharmony_ci __u8 physical_drive; // 0x80 6262306a36Sopenharmony_ci __u8 current_head; // zero 6362306a36Sopenharmony_ci __u8 extended_boot_signature; 6462306a36Sopenharmony_ci // 0x80 6562306a36Sopenharmony_ci __u8 unused; // zero 6662306a36Sopenharmony_ci */ 6762306a36Sopenharmony_ci/*0x28*/sle64 number_of_sectors; /* Number of sectors in volume. Gives 6862306a36Sopenharmony_ci maximum volume size of 2^63 sectors. 6962306a36Sopenharmony_ci Assuming standard sector size of 512 7062306a36Sopenharmony_ci bytes, the maximum byte size is 7162306a36Sopenharmony_ci approx. 4.7x10^21 bytes. (-; */ 7262306a36Sopenharmony_ci sle64 mft_lcn; /* Cluster location of mft data. */ 7362306a36Sopenharmony_ci sle64 mftmirr_lcn; /* Cluster location of copy of mft. */ 7462306a36Sopenharmony_ci s8 clusters_per_mft_record; /* Mft record size in clusters. */ 7562306a36Sopenharmony_ci u8 reserved0[3]; /* zero */ 7662306a36Sopenharmony_ci s8 clusters_per_index_record; /* Index block size in clusters. */ 7762306a36Sopenharmony_ci u8 reserved1[3]; /* zero */ 7862306a36Sopenharmony_ci le64 volume_serial_number; /* Irrelevant (serial number). */ 7962306a36Sopenharmony_ci le32 checksum; /* Boot sector checksum. */ 8062306a36Sopenharmony_ci/*0x54*/u8 bootstrap[426]; /* Irrelevant (boot up code). */ 8162306a36Sopenharmony_ci le16 end_of_sector_marker; /* End of bootsector magic. Always is 8262306a36Sopenharmony_ci 0xaa55 in little endian. */ 8362306a36Sopenharmony_ci/* sizeof() = 512 (0x200) bytes */ 8462306a36Sopenharmony_ci} __attribute__ ((__packed__)) NTFS_BOOT_SECTOR; 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci/* 8762306a36Sopenharmony_ci * Magic identifiers present at the beginning of all ntfs record containing 8862306a36Sopenharmony_ci * records (like mft records for example). 8962306a36Sopenharmony_ci */ 9062306a36Sopenharmony_cienum { 9162306a36Sopenharmony_ci /* Found in $MFT/$DATA. */ 9262306a36Sopenharmony_ci magic_FILE = cpu_to_le32(0x454c4946), /* Mft entry. */ 9362306a36Sopenharmony_ci magic_INDX = cpu_to_le32(0x58444e49), /* Index buffer. */ 9462306a36Sopenharmony_ci magic_HOLE = cpu_to_le32(0x454c4f48), /* ? (NTFS 3.0+?) */ 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci /* Found in $LogFile/$DATA. */ 9762306a36Sopenharmony_ci magic_RSTR = cpu_to_le32(0x52545352), /* Restart page. */ 9862306a36Sopenharmony_ci magic_RCRD = cpu_to_le32(0x44524352), /* Log record page. */ 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci /* Found in $LogFile/$DATA. (May be found in $MFT/$DATA, also?) */ 10162306a36Sopenharmony_ci magic_CHKD = cpu_to_le32(0x444b4843), /* Modified by chkdsk. */ 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci /* Found in all ntfs record containing records. */ 10462306a36Sopenharmony_ci magic_BAAD = cpu_to_le32(0x44414142), /* Failed multi sector 10562306a36Sopenharmony_ci transfer was detected. */ 10662306a36Sopenharmony_ci /* 10762306a36Sopenharmony_ci * Found in $LogFile/$DATA when a page is full of 0xff bytes and is 10862306a36Sopenharmony_ci * thus not initialized. Page must be initialized before using it. 10962306a36Sopenharmony_ci */ 11062306a36Sopenharmony_ci magic_empty = cpu_to_le32(0xffffffff) /* Record is empty. */ 11162306a36Sopenharmony_ci}; 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_citypedef le32 NTFS_RECORD_TYPE; 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci/* 11662306a36Sopenharmony_ci * Generic magic comparison macros. Finally found a use for the ## preprocessor 11762306a36Sopenharmony_ci * operator! (-8 11862306a36Sopenharmony_ci */ 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_cistatic inline bool __ntfs_is_magic(le32 x, NTFS_RECORD_TYPE r) 12162306a36Sopenharmony_ci{ 12262306a36Sopenharmony_ci return (x == r); 12362306a36Sopenharmony_ci} 12462306a36Sopenharmony_ci#define ntfs_is_magic(x, m) __ntfs_is_magic(x, magic_##m) 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_cistatic inline bool __ntfs_is_magicp(le32 *p, NTFS_RECORD_TYPE r) 12762306a36Sopenharmony_ci{ 12862306a36Sopenharmony_ci return (*p == r); 12962306a36Sopenharmony_ci} 13062306a36Sopenharmony_ci#define ntfs_is_magicp(p, m) __ntfs_is_magicp(p, magic_##m) 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci/* 13362306a36Sopenharmony_ci * Specialised magic comparison macros for the NTFS_RECORD_TYPEs defined above. 13462306a36Sopenharmony_ci */ 13562306a36Sopenharmony_ci#define ntfs_is_file_record(x) ( ntfs_is_magic (x, FILE) ) 13662306a36Sopenharmony_ci#define ntfs_is_file_recordp(p) ( ntfs_is_magicp(p, FILE) ) 13762306a36Sopenharmony_ci#define ntfs_is_mft_record(x) ( ntfs_is_file_record (x) ) 13862306a36Sopenharmony_ci#define ntfs_is_mft_recordp(p) ( ntfs_is_file_recordp(p) ) 13962306a36Sopenharmony_ci#define ntfs_is_indx_record(x) ( ntfs_is_magic (x, INDX) ) 14062306a36Sopenharmony_ci#define ntfs_is_indx_recordp(p) ( ntfs_is_magicp(p, INDX) ) 14162306a36Sopenharmony_ci#define ntfs_is_hole_record(x) ( ntfs_is_magic (x, HOLE) ) 14262306a36Sopenharmony_ci#define ntfs_is_hole_recordp(p) ( ntfs_is_magicp(p, HOLE) ) 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci#define ntfs_is_rstr_record(x) ( ntfs_is_magic (x, RSTR) ) 14562306a36Sopenharmony_ci#define ntfs_is_rstr_recordp(p) ( ntfs_is_magicp(p, RSTR) ) 14662306a36Sopenharmony_ci#define ntfs_is_rcrd_record(x) ( ntfs_is_magic (x, RCRD) ) 14762306a36Sopenharmony_ci#define ntfs_is_rcrd_recordp(p) ( ntfs_is_magicp(p, RCRD) ) 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci#define ntfs_is_chkd_record(x) ( ntfs_is_magic (x, CHKD) ) 15062306a36Sopenharmony_ci#define ntfs_is_chkd_recordp(p) ( ntfs_is_magicp(p, CHKD) ) 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci#define ntfs_is_baad_record(x) ( ntfs_is_magic (x, BAAD) ) 15362306a36Sopenharmony_ci#define ntfs_is_baad_recordp(p) ( ntfs_is_magicp(p, BAAD) ) 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci#define ntfs_is_empty_record(x) ( ntfs_is_magic (x, empty) ) 15662306a36Sopenharmony_ci#define ntfs_is_empty_recordp(p) ( ntfs_is_magicp(p, empty) ) 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci/* 15962306a36Sopenharmony_ci * The Update Sequence Array (usa) is an array of the le16 values which belong 16062306a36Sopenharmony_ci * to the end of each sector protected by the update sequence record in which 16162306a36Sopenharmony_ci * this array is contained. Note that the first entry is the Update Sequence 16262306a36Sopenharmony_ci * Number (usn), a cyclic counter of how many times the protected record has 16362306a36Sopenharmony_ci * been written to disk. The values 0 and -1 (ie. 0xffff) are not used. All 16462306a36Sopenharmony_ci * last le16's of each sector have to be equal to the usn (during reading) or 16562306a36Sopenharmony_ci * are set to it (during writing). If they are not, an incomplete multi sector 16662306a36Sopenharmony_ci * transfer has occurred when the data was written. 16762306a36Sopenharmony_ci * The maximum size for the update sequence array is fixed to: 16862306a36Sopenharmony_ci * maximum size = usa_ofs + (usa_count * 2) = 510 bytes 16962306a36Sopenharmony_ci * The 510 bytes comes from the fact that the last le16 in the array has to 17062306a36Sopenharmony_ci * (obviously) finish before the last le16 of the first 512-byte sector. 17162306a36Sopenharmony_ci * This formula can be used as a consistency check in that usa_ofs + 17262306a36Sopenharmony_ci * (usa_count * 2) has to be less than or equal to 510. 17362306a36Sopenharmony_ci */ 17462306a36Sopenharmony_citypedef struct { 17562306a36Sopenharmony_ci NTFS_RECORD_TYPE magic; /* A four-byte magic identifying the record 17662306a36Sopenharmony_ci type and/or status. */ 17762306a36Sopenharmony_ci le16 usa_ofs; /* Offset to the Update Sequence Array (usa) 17862306a36Sopenharmony_ci from the start of the ntfs record. */ 17962306a36Sopenharmony_ci le16 usa_count; /* Number of le16 sized entries in the usa 18062306a36Sopenharmony_ci including the Update Sequence Number (usn), 18162306a36Sopenharmony_ci thus the number of fixups is the usa_count 18262306a36Sopenharmony_ci minus 1. */ 18362306a36Sopenharmony_ci} __attribute__ ((__packed__)) NTFS_RECORD; 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci/* 18662306a36Sopenharmony_ci * System files mft record numbers. All these files are always marked as used 18762306a36Sopenharmony_ci * in the bitmap attribute of the mft; presumably in order to avoid accidental 18862306a36Sopenharmony_ci * allocation for random other mft records. Also, the sequence number for each 18962306a36Sopenharmony_ci * of the system files is always equal to their mft record number and it is 19062306a36Sopenharmony_ci * never modified. 19162306a36Sopenharmony_ci */ 19262306a36Sopenharmony_citypedef enum { 19362306a36Sopenharmony_ci FILE_MFT = 0, /* Master file table (mft). Data attribute 19462306a36Sopenharmony_ci contains the entries and bitmap attribute 19562306a36Sopenharmony_ci records which ones are in use (bit==1). */ 19662306a36Sopenharmony_ci FILE_MFTMirr = 1, /* Mft mirror: copy of first four mft records 19762306a36Sopenharmony_ci in data attribute. If cluster size > 4kiB, 19862306a36Sopenharmony_ci copy of first N mft records, with 19962306a36Sopenharmony_ci N = cluster_size / mft_record_size. */ 20062306a36Sopenharmony_ci FILE_LogFile = 2, /* Journalling log in data attribute. */ 20162306a36Sopenharmony_ci FILE_Volume = 3, /* Volume name attribute and volume information 20262306a36Sopenharmony_ci attribute (flags and ntfs version). Windows 20362306a36Sopenharmony_ci refers to this file as volume DASD (Direct 20462306a36Sopenharmony_ci Access Storage Device). */ 20562306a36Sopenharmony_ci FILE_AttrDef = 4, /* Array of attribute definitions in data 20662306a36Sopenharmony_ci attribute. */ 20762306a36Sopenharmony_ci FILE_root = 5, /* Root directory. */ 20862306a36Sopenharmony_ci FILE_Bitmap = 6, /* Allocation bitmap of all clusters (lcns) in 20962306a36Sopenharmony_ci data attribute. */ 21062306a36Sopenharmony_ci FILE_Boot = 7, /* Boot sector (always at cluster 0) in data 21162306a36Sopenharmony_ci attribute. */ 21262306a36Sopenharmony_ci FILE_BadClus = 8, /* Contains all bad clusters in the non-resident 21362306a36Sopenharmony_ci data attribute. */ 21462306a36Sopenharmony_ci FILE_Secure = 9, /* Shared security descriptors in data attribute 21562306a36Sopenharmony_ci and two indexes into the descriptors. 21662306a36Sopenharmony_ci Appeared in Windows 2000. Before that, this 21762306a36Sopenharmony_ci file was named $Quota but was unused. */ 21862306a36Sopenharmony_ci FILE_UpCase = 10, /* Uppercase equivalents of all 65536 Unicode 21962306a36Sopenharmony_ci characters in data attribute. */ 22062306a36Sopenharmony_ci FILE_Extend = 11, /* Directory containing other system files (eg. 22162306a36Sopenharmony_ci $ObjId, $Quota, $Reparse and $UsnJrnl). This 22262306a36Sopenharmony_ci is new to NTFS3.0. */ 22362306a36Sopenharmony_ci FILE_reserved12 = 12, /* Reserved for future use (records 12-15). */ 22462306a36Sopenharmony_ci FILE_reserved13 = 13, 22562306a36Sopenharmony_ci FILE_reserved14 = 14, 22662306a36Sopenharmony_ci FILE_reserved15 = 15, 22762306a36Sopenharmony_ci FILE_first_user = 16, /* First user file, used as test limit for 22862306a36Sopenharmony_ci whether to allow opening a file or not. */ 22962306a36Sopenharmony_ci} NTFS_SYSTEM_FILES; 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ci/* 23262306a36Sopenharmony_ci * These are the so far known MFT_RECORD_* flags (16-bit) which contain 23362306a36Sopenharmony_ci * information about the mft record in which they are present. 23462306a36Sopenharmony_ci */ 23562306a36Sopenharmony_cienum { 23662306a36Sopenharmony_ci MFT_RECORD_IN_USE = cpu_to_le16(0x0001), 23762306a36Sopenharmony_ci MFT_RECORD_IS_DIRECTORY = cpu_to_le16(0x0002), 23862306a36Sopenharmony_ci} __attribute__ ((__packed__)); 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_citypedef le16 MFT_RECORD_FLAGS; 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ci/* 24362306a36Sopenharmony_ci * mft references (aka file references or file record segment references) are 24462306a36Sopenharmony_ci * used whenever a structure needs to refer to a record in the mft. 24562306a36Sopenharmony_ci * 24662306a36Sopenharmony_ci * A reference consists of a 48-bit index into the mft and a 16-bit sequence 24762306a36Sopenharmony_ci * number used to detect stale references. 24862306a36Sopenharmony_ci * 24962306a36Sopenharmony_ci * For error reporting purposes we treat the 48-bit index as a signed quantity. 25062306a36Sopenharmony_ci * 25162306a36Sopenharmony_ci * The sequence number is a circular counter (skipping 0) describing how many 25262306a36Sopenharmony_ci * times the referenced mft record has been (re)used. This has to match the 25362306a36Sopenharmony_ci * sequence number of the mft record being referenced, otherwise the reference 25462306a36Sopenharmony_ci * is considered stale and removed (FIXME: only ntfsck or the driver itself?). 25562306a36Sopenharmony_ci * 25662306a36Sopenharmony_ci * If the sequence number is zero it is assumed that no sequence number 25762306a36Sopenharmony_ci * consistency checking should be performed. 25862306a36Sopenharmony_ci * 25962306a36Sopenharmony_ci * FIXME: Since inodes are 32-bit as of now, the driver needs to always check 26062306a36Sopenharmony_ci * for high_part being 0 and if not either BUG(), cause a panic() or handle 26162306a36Sopenharmony_ci * the situation in some other way. This shouldn't be a problem as a volume has 26262306a36Sopenharmony_ci * to become HUGE in order to need more than 32-bits worth of mft records. 26362306a36Sopenharmony_ci * Assuming the standard mft record size of 1kb only the records (never mind 26462306a36Sopenharmony_ci * the non-resident attributes, etc.) would require 4Tb of space on their own 26562306a36Sopenharmony_ci * for the first 32 bits worth of records. This is only if some strange person 26662306a36Sopenharmony_ci * doesn't decide to foul play and make the mft sparse which would be a really 26762306a36Sopenharmony_ci * horrible thing to do as it would trash our current driver implementation. )-: 26862306a36Sopenharmony_ci * Do I hear screams "we want 64-bit inodes!" ?!? (-; 26962306a36Sopenharmony_ci * 27062306a36Sopenharmony_ci * FIXME: The mft zone is defined as the first 12% of the volume. This space is 27162306a36Sopenharmony_ci * reserved so that the mft can grow contiguously and hence doesn't become 27262306a36Sopenharmony_ci * fragmented. Volume free space includes the empty part of the mft zone and 27362306a36Sopenharmony_ci * when the volume's free 88% are used up, the mft zone is shrunk by a factor 27462306a36Sopenharmony_ci * of 2, thus making more space available for more files/data. This process is 27562306a36Sopenharmony_ci * repeated every time there is no more free space except for the mft zone until 27662306a36Sopenharmony_ci * there really is no more free space. 27762306a36Sopenharmony_ci */ 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_ci/* 28062306a36Sopenharmony_ci * Typedef the MFT_REF as a 64-bit value for easier handling. 28162306a36Sopenharmony_ci * Also define two unpacking macros to get to the reference (MREF) and 28262306a36Sopenharmony_ci * sequence number (MSEQNO) respectively. 28362306a36Sopenharmony_ci * The _LE versions are to be applied on little endian MFT_REFs. 28462306a36Sopenharmony_ci * Note: The _LE versions will return a CPU endian formatted value! 28562306a36Sopenharmony_ci */ 28662306a36Sopenharmony_ci#define MFT_REF_MASK_CPU 0x0000ffffffffffffULL 28762306a36Sopenharmony_ci#define MFT_REF_MASK_LE cpu_to_le64(MFT_REF_MASK_CPU) 28862306a36Sopenharmony_ci 28962306a36Sopenharmony_citypedef u64 MFT_REF; 29062306a36Sopenharmony_citypedef le64 leMFT_REF; 29162306a36Sopenharmony_ci 29262306a36Sopenharmony_ci#define MK_MREF(m, s) ((MFT_REF)(((MFT_REF)(s) << 48) | \ 29362306a36Sopenharmony_ci ((MFT_REF)(m) & MFT_REF_MASK_CPU))) 29462306a36Sopenharmony_ci#define MK_LE_MREF(m, s) cpu_to_le64(MK_MREF(m, s)) 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ci#define MREF(x) ((unsigned long)((x) & MFT_REF_MASK_CPU)) 29762306a36Sopenharmony_ci#define MSEQNO(x) ((u16)(((x) >> 48) & 0xffff)) 29862306a36Sopenharmony_ci#define MREF_LE(x) ((unsigned long)(le64_to_cpu(x) & MFT_REF_MASK_CPU)) 29962306a36Sopenharmony_ci#define MSEQNO_LE(x) ((u16)((le64_to_cpu(x) >> 48) & 0xffff)) 30062306a36Sopenharmony_ci 30162306a36Sopenharmony_ci#define IS_ERR_MREF(x) (((x) & 0x0000800000000000ULL) ? true : false) 30262306a36Sopenharmony_ci#define ERR_MREF(x) ((u64)((s64)(x))) 30362306a36Sopenharmony_ci#define MREF_ERR(x) ((int)((s64)(x))) 30462306a36Sopenharmony_ci 30562306a36Sopenharmony_ci/* 30662306a36Sopenharmony_ci * The mft record header present at the beginning of every record in the mft. 30762306a36Sopenharmony_ci * This is followed by a sequence of variable length attribute records which 30862306a36Sopenharmony_ci * is terminated by an attribute of type AT_END which is a truncated attribute 30962306a36Sopenharmony_ci * in that it only consists of the attribute type code AT_END and none of the 31062306a36Sopenharmony_ci * other members of the attribute structure are present. 31162306a36Sopenharmony_ci */ 31262306a36Sopenharmony_citypedef struct { 31362306a36Sopenharmony_ci/*Ofs*/ 31462306a36Sopenharmony_ci/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ 31562306a36Sopenharmony_ci NTFS_RECORD_TYPE magic; /* Usually the magic is "FILE". */ 31662306a36Sopenharmony_ci le16 usa_ofs; /* See NTFS_RECORD definition above. */ 31762306a36Sopenharmony_ci le16 usa_count; /* See NTFS_RECORD definition above. */ 31862306a36Sopenharmony_ci 31962306a36Sopenharmony_ci/* 8*/ le64 lsn; /* $LogFile sequence number for this record. 32062306a36Sopenharmony_ci Changed every time the record is modified. */ 32162306a36Sopenharmony_ci/* 16*/ le16 sequence_number; /* Number of times this mft record has been 32262306a36Sopenharmony_ci reused. (See description for MFT_REF 32362306a36Sopenharmony_ci above.) NOTE: The increment (skipping zero) 32462306a36Sopenharmony_ci is done when the file is deleted. NOTE: If 32562306a36Sopenharmony_ci this is zero it is left zero. */ 32662306a36Sopenharmony_ci/* 18*/ le16 link_count; /* Number of hard links, i.e. the number of 32762306a36Sopenharmony_ci directory entries referencing this record. 32862306a36Sopenharmony_ci NOTE: Only used in mft base records. 32962306a36Sopenharmony_ci NOTE: When deleting a directory entry we 33062306a36Sopenharmony_ci check the link_count and if it is 1 we 33162306a36Sopenharmony_ci delete the file. Otherwise we delete the 33262306a36Sopenharmony_ci FILE_NAME_ATTR being referenced by the 33362306a36Sopenharmony_ci directory entry from the mft record and 33462306a36Sopenharmony_ci decrement the link_count. 33562306a36Sopenharmony_ci FIXME: Careful with Win32 + DOS names! */ 33662306a36Sopenharmony_ci/* 20*/ le16 attrs_offset; /* Byte offset to the first attribute in this 33762306a36Sopenharmony_ci mft record from the start of the mft record. 33862306a36Sopenharmony_ci NOTE: Must be aligned to 8-byte boundary. */ 33962306a36Sopenharmony_ci/* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file 34062306a36Sopenharmony_ci is deleted, the MFT_RECORD_IN_USE flag is 34162306a36Sopenharmony_ci set to zero. */ 34262306a36Sopenharmony_ci/* 24*/ le32 bytes_in_use; /* Number of bytes used in this mft record. 34362306a36Sopenharmony_ci NOTE: Must be aligned to 8-byte boundary. */ 34462306a36Sopenharmony_ci/* 28*/ le32 bytes_allocated; /* Number of bytes allocated for this mft 34562306a36Sopenharmony_ci record. This should be equal to the mft 34662306a36Sopenharmony_ci record size. */ 34762306a36Sopenharmony_ci/* 32*/ leMFT_REF base_mft_record;/* This is zero for base mft records. 34862306a36Sopenharmony_ci When it is not zero it is a mft reference 34962306a36Sopenharmony_ci pointing to the base mft record to which 35062306a36Sopenharmony_ci this record belongs (this is then used to 35162306a36Sopenharmony_ci locate the attribute list attribute present 35262306a36Sopenharmony_ci in the base record which describes this 35362306a36Sopenharmony_ci extension record and hence might need 35462306a36Sopenharmony_ci modification when the extension record 35562306a36Sopenharmony_ci itself is modified, also locating the 35662306a36Sopenharmony_ci attribute list also means finding the other 35762306a36Sopenharmony_ci potential extents, belonging to the non-base 35862306a36Sopenharmony_ci mft record). */ 35962306a36Sopenharmony_ci/* 40*/ le16 next_attr_instance;/* The instance number that will be assigned to 36062306a36Sopenharmony_ci the next attribute added to this mft record. 36162306a36Sopenharmony_ci NOTE: Incremented each time after it is used. 36262306a36Sopenharmony_ci NOTE: Every time the mft record is reused 36362306a36Sopenharmony_ci this number is set to zero. NOTE: The first 36462306a36Sopenharmony_ci instance number is always 0. */ 36562306a36Sopenharmony_ci/* The below fields are specific to NTFS 3.1+ (Windows XP and above): */ 36662306a36Sopenharmony_ci/* 42*/ le16 reserved; /* Reserved/alignment. */ 36762306a36Sopenharmony_ci/* 44*/ le32 mft_record_number; /* Number of this mft record. */ 36862306a36Sopenharmony_ci/* sizeof() = 48 bytes */ 36962306a36Sopenharmony_ci/* 37062306a36Sopenharmony_ci * When (re)using the mft record, we place the update sequence array at this 37162306a36Sopenharmony_ci * offset, i.e. before we start with the attributes. This also makes sense, 37262306a36Sopenharmony_ci * otherwise we could run into problems with the update sequence array 37362306a36Sopenharmony_ci * containing in itself the last two bytes of a sector which would mean that 37462306a36Sopenharmony_ci * multi sector transfer protection wouldn't work. As you can't protect data 37562306a36Sopenharmony_ci * by overwriting it since you then can't get it back... 37662306a36Sopenharmony_ci * When reading we obviously use the data from the ntfs record header. 37762306a36Sopenharmony_ci */ 37862306a36Sopenharmony_ci} __attribute__ ((__packed__)) MFT_RECORD; 37962306a36Sopenharmony_ci 38062306a36Sopenharmony_ci/* This is the version without the NTFS 3.1+ specific fields. */ 38162306a36Sopenharmony_citypedef struct { 38262306a36Sopenharmony_ci/*Ofs*/ 38362306a36Sopenharmony_ci/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ 38462306a36Sopenharmony_ci NTFS_RECORD_TYPE magic; /* Usually the magic is "FILE". */ 38562306a36Sopenharmony_ci le16 usa_ofs; /* See NTFS_RECORD definition above. */ 38662306a36Sopenharmony_ci le16 usa_count; /* See NTFS_RECORD definition above. */ 38762306a36Sopenharmony_ci 38862306a36Sopenharmony_ci/* 8*/ le64 lsn; /* $LogFile sequence number for this record. 38962306a36Sopenharmony_ci Changed every time the record is modified. */ 39062306a36Sopenharmony_ci/* 16*/ le16 sequence_number; /* Number of times this mft record has been 39162306a36Sopenharmony_ci reused. (See description for MFT_REF 39262306a36Sopenharmony_ci above.) NOTE: The increment (skipping zero) 39362306a36Sopenharmony_ci is done when the file is deleted. NOTE: If 39462306a36Sopenharmony_ci this is zero it is left zero. */ 39562306a36Sopenharmony_ci/* 18*/ le16 link_count; /* Number of hard links, i.e. the number of 39662306a36Sopenharmony_ci directory entries referencing this record. 39762306a36Sopenharmony_ci NOTE: Only used in mft base records. 39862306a36Sopenharmony_ci NOTE: When deleting a directory entry we 39962306a36Sopenharmony_ci check the link_count and if it is 1 we 40062306a36Sopenharmony_ci delete the file. Otherwise we delete the 40162306a36Sopenharmony_ci FILE_NAME_ATTR being referenced by the 40262306a36Sopenharmony_ci directory entry from the mft record and 40362306a36Sopenharmony_ci decrement the link_count. 40462306a36Sopenharmony_ci FIXME: Careful with Win32 + DOS names! */ 40562306a36Sopenharmony_ci/* 20*/ le16 attrs_offset; /* Byte offset to the first attribute in this 40662306a36Sopenharmony_ci mft record from the start of the mft record. 40762306a36Sopenharmony_ci NOTE: Must be aligned to 8-byte boundary. */ 40862306a36Sopenharmony_ci/* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file 40962306a36Sopenharmony_ci is deleted, the MFT_RECORD_IN_USE flag is 41062306a36Sopenharmony_ci set to zero. */ 41162306a36Sopenharmony_ci/* 24*/ le32 bytes_in_use; /* Number of bytes used in this mft record. 41262306a36Sopenharmony_ci NOTE: Must be aligned to 8-byte boundary. */ 41362306a36Sopenharmony_ci/* 28*/ le32 bytes_allocated; /* Number of bytes allocated for this mft 41462306a36Sopenharmony_ci record. This should be equal to the mft 41562306a36Sopenharmony_ci record size. */ 41662306a36Sopenharmony_ci/* 32*/ leMFT_REF base_mft_record;/* This is zero for base mft records. 41762306a36Sopenharmony_ci When it is not zero it is a mft reference 41862306a36Sopenharmony_ci pointing to the base mft record to which 41962306a36Sopenharmony_ci this record belongs (this is then used to 42062306a36Sopenharmony_ci locate the attribute list attribute present 42162306a36Sopenharmony_ci in the base record which describes this 42262306a36Sopenharmony_ci extension record and hence might need 42362306a36Sopenharmony_ci modification when the extension record 42462306a36Sopenharmony_ci itself is modified, also locating the 42562306a36Sopenharmony_ci attribute list also means finding the other 42662306a36Sopenharmony_ci potential extents, belonging to the non-base 42762306a36Sopenharmony_ci mft record). */ 42862306a36Sopenharmony_ci/* 40*/ le16 next_attr_instance;/* The instance number that will be assigned to 42962306a36Sopenharmony_ci the next attribute added to this mft record. 43062306a36Sopenharmony_ci NOTE: Incremented each time after it is used. 43162306a36Sopenharmony_ci NOTE: Every time the mft record is reused 43262306a36Sopenharmony_ci this number is set to zero. NOTE: The first 43362306a36Sopenharmony_ci instance number is always 0. */ 43462306a36Sopenharmony_ci/* sizeof() = 42 bytes */ 43562306a36Sopenharmony_ci/* 43662306a36Sopenharmony_ci * When (re)using the mft record, we place the update sequence array at this 43762306a36Sopenharmony_ci * offset, i.e. before we start with the attributes. This also makes sense, 43862306a36Sopenharmony_ci * otherwise we could run into problems with the update sequence array 43962306a36Sopenharmony_ci * containing in itself the last two bytes of a sector which would mean that 44062306a36Sopenharmony_ci * multi sector transfer protection wouldn't work. As you can't protect data 44162306a36Sopenharmony_ci * by overwriting it since you then can't get it back... 44262306a36Sopenharmony_ci * When reading we obviously use the data from the ntfs record header. 44362306a36Sopenharmony_ci */ 44462306a36Sopenharmony_ci} __attribute__ ((__packed__)) MFT_RECORD_OLD; 44562306a36Sopenharmony_ci 44662306a36Sopenharmony_ci/* 44762306a36Sopenharmony_ci * System defined attributes (32-bit). Each attribute type has a corresponding 44862306a36Sopenharmony_ci * attribute name (Unicode string of maximum 64 character length) as described 44962306a36Sopenharmony_ci * by the attribute definitions present in the data attribute of the $AttrDef 45062306a36Sopenharmony_ci * system file. On NTFS 3.0 volumes the names are just as the types are named 45162306a36Sopenharmony_ci * in the below defines exchanging AT_ for the dollar sign ($). If that is not 45262306a36Sopenharmony_ci * a revealing choice of symbol I do not know what is... (-; 45362306a36Sopenharmony_ci */ 45462306a36Sopenharmony_cienum { 45562306a36Sopenharmony_ci AT_UNUSED = cpu_to_le32( 0), 45662306a36Sopenharmony_ci AT_STANDARD_INFORMATION = cpu_to_le32( 0x10), 45762306a36Sopenharmony_ci AT_ATTRIBUTE_LIST = cpu_to_le32( 0x20), 45862306a36Sopenharmony_ci AT_FILE_NAME = cpu_to_le32( 0x30), 45962306a36Sopenharmony_ci AT_OBJECT_ID = cpu_to_le32( 0x40), 46062306a36Sopenharmony_ci AT_SECURITY_DESCRIPTOR = cpu_to_le32( 0x50), 46162306a36Sopenharmony_ci AT_VOLUME_NAME = cpu_to_le32( 0x60), 46262306a36Sopenharmony_ci AT_VOLUME_INFORMATION = cpu_to_le32( 0x70), 46362306a36Sopenharmony_ci AT_DATA = cpu_to_le32( 0x80), 46462306a36Sopenharmony_ci AT_INDEX_ROOT = cpu_to_le32( 0x90), 46562306a36Sopenharmony_ci AT_INDEX_ALLOCATION = cpu_to_le32( 0xa0), 46662306a36Sopenharmony_ci AT_BITMAP = cpu_to_le32( 0xb0), 46762306a36Sopenharmony_ci AT_REPARSE_POINT = cpu_to_le32( 0xc0), 46862306a36Sopenharmony_ci AT_EA_INFORMATION = cpu_to_le32( 0xd0), 46962306a36Sopenharmony_ci AT_EA = cpu_to_le32( 0xe0), 47062306a36Sopenharmony_ci AT_PROPERTY_SET = cpu_to_le32( 0xf0), 47162306a36Sopenharmony_ci AT_LOGGED_UTILITY_STREAM = cpu_to_le32( 0x100), 47262306a36Sopenharmony_ci AT_FIRST_USER_DEFINED_ATTRIBUTE = cpu_to_le32( 0x1000), 47362306a36Sopenharmony_ci AT_END = cpu_to_le32(0xffffffff) 47462306a36Sopenharmony_ci}; 47562306a36Sopenharmony_ci 47662306a36Sopenharmony_citypedef le32 ATTR_TYPE; 47762306a36Sopenharmony_ci 47862306a36Sopenharmony_ci/* 47962306a36Sopenharmony_ci * The collation rules for sorting views/indexes/etc (32-bit). 48062306a36Sopenharmony_ci * 48162306a36Sopenharmony_ci * COLLATION_BINARY - Collate by binary compare where the first byte is most 48262306a36Sopenharmony_ci * significant. 48362306a36Sopenharmony_ci * COLLATION_UNICODE_STRING - Collate Unicode strings by comparing their binary 48462306a36Sopenharmony_ci * Unicode values, except that when a character can be uppercased, the 48562306a36Sopenharmony_ci * upper case value collates before the lower case one. 48662306a36Sopenharmony_ci * COLLATION_FILE_NAME - Collate file names as Unicode strings. The collation 48762306a36Sopenharmony_ci * is done very much like COLLATION_UNICODE_STRING. In fact I have no idea 48862306a36Sopenharmony_ci * what the difference is. Perhaps the difference is that file names 48962306a36Sopenharmony_ci * would treat some special characters in an odd way (see 49062306a36Sopenharmony_ci * unistr.c::ntfs_collate_names() and unistr.c::legal_ansi_char_array[] 49162306a36Sopenharmony_ci * for what I mean but COLLATION_UNICODE_STRING would not give any special 49262306a36Sopenharmony_ci * treatment to any characters at all, but this is speculation. 49362306a36Sopenharmony_ci * COLLATION_NTOFS_ULONG - Sorting is done according to ascending le32 key 49462306a36Sopenharmony_ci * values. E.g. used for $SII index in FILE_Secure, which sorts by 49562306a36Sopenharmony_ci * security_id (le32). 49662306a36Sopenharmony_ci * COLLATION_NTOFS_SID - Sorting is done according to ascending SID values. 49762306a36Sopenharmony_ci * E.g. used for $O index in FILE_Extend/$Quota. 49862306a36Sopenharmony_ci * COLLATION_NTOFS_SECURITY_HASH - Sorting is done first by ascending hash 49962306a36Sopenharmony_ci * values and second by ascending security_id values. E.g. used for $SDH 50062306a36Sopenharmony_ci * index in FILE_Secure. 50162306a36Sopenharmony_ci * COLLATION_NTOFS_ULONGS - Sorting is done according to a sequence of ascending 50262306a36Sopenharmony_ci * le32 key values. E.g. used for $O index in FILE_Extend/$ObjId, which 50362306a36Sopenharmony_ci * sorts by object_id (16-byte), by splitting up the object_id in four 50462306a36Sopenharmony_ci * le32 values and using them as individual keys. E.g. take the following 50562306a36Sopenharmony_ci * two security_ids, stored as follows on disk: 50662306a36Sopenharmony_ci * 1st: a1 61 65 b7 65 7b d4 11 9e 3d 00 e0 81 10 42 59 50762306a36Sopenharmony_ci * 2nd: 38 14 37 d2 d2 f3 d4 11 a5 21 c8 6b 79 b1 97 45 50862306a36Sopenharmony_ci * To compare them, they are split into four le32 values each, like so: 50962306a36Sopenharmony_ci * 1st: 0xb76561a1 0x11d47b65 0xe0003d9e 0x59421081 51062306a36Sopenharmony_ci * 2nd: 0xd2371438 0x11d4f3d2 0x6bc821a5 0x4597b179 51162306a36Sopenharmony_ci * Now, it is apparent why the 2nd object_id collates after the 1st: the 51262306a36Sopenharmony_ci * first le32 value of the 1st object_id is less than the first le32 of 51362306a36Sopenharmony_ci * the 2nd object_id. If the first le32 values of both object_ids were 51462306a36Sopenharmony_ci * equal then the second le32 values would be compared, etc. 51562306a36Sopenharmony_ci */ 51662306a36Sopenharmony_cienum { 51762306a36Sopenharmony_ci COLLATION_BINARY = cpu_to_le32(0x00), 51862306a36Sopenharmony_ci COLLATION_FILE_NAME = cpu_to_le32(0x01), 51962306a36Sopenharmony_ci COLLATION_UNICODE_STRING = cpu_to_le32(0x02), 52062306a36Sopenharmony_ci COLLATION_NTOFS_ULONG = cpu_to_le32(0x10), 52162306a36Sopenharmony_ci COLLATION_NTOFS_SID = cpu_to_le32(0x11), 52262306a36Sopenharmony_ci COLLATION_NTOFS_SECURITY_HASH = cpu_to_le32(0x12), 52362306a36Sopenharmony_ci COLLATION_NTOFS_ULONGS = cpu_to_le32(0x13), 52462306a36Sopenharmony_ci}; 52562306a36Sopenharmony_ci 52662306a36Sopenharmony_citypedef le32 COLLATION_RULE; 52762306a36Sopenharmony_ci 52862306a36Sopenharmony_ci/* 52962306a36Sopenharmony_ci * The flags (32-bit) describing attribute properties in the attribute 53062306a36Sopenharmony_ci * definition structure. FIXME: This information is based on Regis's 53162306a36Sopenharmony_ci * information and, according to him, it is not certain and probably 53262306a36Sopenharmony_ci * incomplete. The INDEXABLE flag is fairly certainly correct as only the file 53362306a36Sopenharmony_ci * name attribute has this flag set and this is the only attribute indexed in 53462306a36Sopenharmony_ci * NT4. 53562306a36Sopenharmony_ci */ 53662306a36Sopenharmony_cienum { 53762306a36Sopenharmony_ci ATTR_DEF_INDEXABLE = cpu_to_le32(0x02), /* Attribute can be 53862306a36Sopenharmony_ci indexed. */ 53962306a36Sopenharmony_ci ATTR_DEF_MULTIPLE = cpu_to_le32(0x04), /* Attribute type 54062306a36Sopenharmony_ci can be present multiple times in the 54162306a36Sopenharmony_ci mft records of an inode. */ 54262306a36Sopenharmony_ci ATTR_DEF_NOT_ZERO = cpu_to_le32(0x08), /* Attribute value 54362306a36Sopenharmony_ci must contain at least one non-zero 54462306a36Sopenharmony_ci byte. */ 54562306a36Sopenharmony_ci ATTR_DEF_INDEXED_UNIQUE = cpu_to_le32(0x10), /* Attribute must be 54662306a36Sopenharmony_ci indexed and the attribute value must be 54762306a36Sopenharmony_ci unique for the attribute type in all of 54862306a36Sopenharmony_ci the mft records of an inode. */ 54962306a36Sopenharmony_ci ATTR_DEF_NAMED_UNIQUE = cpu_to_le32(0x20), /* Attribute must be 55062306a36Sopenharmony_ci named and the name must be unique for 55162306a36Sopenharmony_ci the attribute type in all of the mft 55262306a36Sopenharmony_ci records of an inode. */ 55362306a36Sopenharmony_ci ATTR_DEF_RESIDENT = cpu_to_le32(0x40), /* Attribute must be 55462306a36Sopenharmony_ci resident. */ 55562306a36Sopenharmony_ci ATTR_DEF_ALWAYS_LOG = cpu_to_le32(0x80), /* Always log 55662306a36Sopenharmony_ci modifications to this attribute, 55762306a36Sopenharmony_ci regardless of whether it is resident or 55862306a36Sopenharmony_ci non-resident. Without this, only log 55962306a36Sopenharmony_ci modifications if the attribute is 56062306a36Sopenharmony_ci resident. */ 56162306a36Sopenharmony_ci}; 56262306a36Sopenharmony_ci 56362306a36Sopenharmony_citypedef le32 ATTR_DEF_FLAGS; 56462306a36Sopenharmony_ci 56562306a36Sopenharmony_ci/* 56662306a36Sopenharmony_ci * The data attribute of FILE_AttrDef contains a sequence of attribute 56762306a36Sopenharmony_ci * definitions for the NTFS volume. With this, it is supposed to be safe for an 56862306a36Sopenharmony_ci * older NTFS driver to mount a volume containing a newer NTFS version without 56962306a36Sopenharmony_ci * damaging it (that's the theory. In practice it's: not damaging it too much). 57062306a36Sopenharmony_ci * Entries are sorted by attribute type. The flags describe whether the 57162306a36Sopenharmony_ci * attribute can be resident/non-resident and possibly other things, but the 57262306a36Sopenharmony_ci * actual bits are unknown. 57362306a36Sopenharmony_ci */ 57462306a36Sopenharmony_citypedef struct { 57562306a36Sopenharmony_ci/*hex ofs*/ 57662306a36Sopenharmony_ci/* 0*/ ntfschar name[0x40]; /* Unicode name of the attribute. Zero 57762306a36Sopenharmony_ci terminated. */ 57862306a36Sopenharmony_ci/* 80*/ ATTR_TYPE type; /* Type of the attribute. */ 57962306a36Sopenharmony_ci/* 84*/ le32 display_rule; /* Default display rule. 58062306a36Sopenharmony_ci FIXME: What does it mean? (AIA) */ 58162306a36Sopenharmony_ci/* 88*/ COLLATION_RULE collation_rule; /* Default collation rule. */ 58262306a36Sopenharmony_ci/* 8c*/ ATTR_DEF_FLAGS flags; /* Flags describing the attribute. */ 58362306a36Sopenharmony_ci/* 90*/ sle64 min_size; /* Optional minimum attribute size. */ 58462306a36Sopenharmony_ci/* 98*/ sle64 max_size; /* Maximum size of attribute. */ 58562306a36Sopenharmony_ci/* sizeof() = 0xa0 or 160 bytes */ 58662306a36Sopenharmony_ci} __attribute__ ((__packed__)) ATTR_DEF; 58762306a36Sopenharmony_ci 58862306a36Sopenharmony_ci/* 58962306a36Sopenharmony_ci * Attribute flags (16-bit). 59062306a36Sopenharmony_ci */ 59162306a36Sopenharmony_cienum { 59262306a36Sopenharmony_ci ATTR_IS_COMPRESSED = cpu_to_le16(0x0001), 59362306a36Sopenharmony_ci ATTR_COMPRESSION_MASK = cpu_to_le16(0x00ff), /* Compression method 59462306a36Sopenharmony_ci mask. Also, first 59562306a36Sopenharmony_ci illegal value. */ 59662306a36Sopenharmony_ci ATTR_IS_ENCRYPTED = cpu_to_le16(0x4000), 59762306a36Sopenharmony_ci ATTR_IS_SPARSE = cpu_to_le16(0x8000), 59862306a36Sopenharmony_ci} __attribute__ ((__packed__)); 59962306a36Sopenharmony_ci 60062306a36Sopenharmony_citypedef le16 ATTR_FLAGS; 60162306a36Sopenharmony_ci 60262306a36Sopenharmony_ci/* 60362306a36Sopenharmony_ci * Attribute compression. 60462306a36Sopenharmony_ci * 60562306a36Sopenharmony_ci * Only the data attribute is ever compressed in the current ntfs driver in 60662306a36Sopenharmony_ci * Windows. Further, compression is only applied when the data attribute is 60762306a36Sopenharmony_ci * non-resident. Finally, to use compression, the maximum allowed cluster size 60862306a36Sopenharmony_ci * on a volume is 4kib. 60962306a36Sopenharmony_ci * 61062306a36Sopenharmony_ci * The compression method is based on independently compressing blocks of X 61162306a36Sopenharmony_ci * clusters, where X is determined from the compression_unit value found in the 61262306a36Sopenharmony_ci * non-resident attribute record header (more precisely: X = 2^compression_unit 61362306a36Sopenharmony_ci * clusters). On Windows NT/2k, X always is 16 clusters (compression_unit = 4). 61462306a36Sopenharmony_ci * 61562306a36Sopenharmony_ci * There are three different cases of how a compression block of X clusters 61662306a36Sopenharmony_ci * can be stored: 61762306a36Sopenharmony_ci * 61862306a36Sopenharmony_ci * 1) The data in the block is all zero (a sparse block): 61962306a36Sopenharmony_ci * This is stored as a sparse block in the runlist, i.e. the runlist 62062306a36Sopenharmony_ci * entry has length = X and lcn = -1. The mapping pairs array actually 62162306a36Sopenharmony_ci * uses a delta_lcn value length of 0, i.e. delta_lcn is not present at 62262306a36Sopenharmony_ci * all, which is then interpreted by the driver as lcn = -1. 62362306a36Sopenharmony_ci * NOTE: Even uncompressed files can be sparse on NTFS 3.0 volumes, then 62462306a36Sopenharmony_ci * the same principles apply as above, except that the length is not 62562306a36Sopenharmony_ci * restricted to being any particular value. 62662306a36Sopenharmony_ci * 62762306a36Sopenharmony_ci * 2) The data in the block is not compressed: 62862306a36Sopenharmony_ci * This happens when compression doesn't reduce the size of the block 62962306a36Sopenharmony_ci * in clusters. I.e. if compression has a small effect so that the 63062306a36Sopenharmony_ci * compressed data still occupies X clusters, then the uncompressed data 63162306a36Sopenharmony_ci * is stored in the block. 63262306a36Sopenharmony_ci * This case is recognised by the fact that the runlist entry has 63362306a36Sopenharmony_ci * length = X and lcn >= 0. The mapping pairs array stores this as 63462306a36Sopenharmony_ci * normal with a run length of X and some specific delta_lcn, i.e. 63562306a36Sopenharmony_ci * delta_lcn has to be present. 63662306a36Sopenharmony_ci * 63762306a36Sopenharmony_ci * 3) The data in the block is compressed: 63862306a36Sopenharmony_ci * The common case. This case is recognised by the fact that the run 63962306a36Sopenharmony_ci * list entry has length L < X and lcn >= 0. The mapping pairs array 64062306a36Sopenharmony_ci * stores this as normal with a run length of X and some specific 64162306a36Sopenharmony_ci * delta_lcn, i.e. delta_lcn has to be present. This runlist entry is 64262306a36Sopenharmony_ci * immediately followed by a sparse entry with length = X - L and 64362306a36Sopenharmony_ci * lcn = -1. The latter entry is to make up the vcn counting to the 64462306a36Sopenharmony_ci * full compression block size X. 64562306a36Sopenharmony_ci * 64662306a36Sopenharmony_ci * In fact, life is more complicated because adjacent entries of the same type 64762306a36Sopenharmony_ci * can be coalesced. This means that one has to keep track of the number of 64862306a36Sopenharmony_ci * clusters handled and work on a basis of X clusters at a time being one 64962306a36Sopenharmony_ci * block. An example: if length L > X this means that this particular runlist 65062306a36Sopenharmony_ci * entry contains a block of length X and part of one or more blocks of length 65162306a36Sopenharmony_ci * L - X. Another example: if length L < X, this does not necessarily mean that 65262306a36Sopenharmony_ci * the block is compressed as it might be that the lcn changes inside the block 65362306a36Sopenharmony_ci * and hence the following runlist entry describes the continuation of the 65462306a36Sopenharmony_ci * potentially compressed block. The block would be compressed if the 65562306a36Sopenharmony_ci * following runlist entry describes at least X - L sparse clusters, thus 65662306a36Sopenharmony_ci * making up the compression block length as described in point 3 above. (Of 65762306a36Sopenharmony_ci * course, there can be several runlist entries with small lengths so that the 65862306a36Sopenharmony_ci * sparse entry does not follow the first data containing entry with 65962306a36Sopenharmony_ci * length < X.) 66062306a36Sopenharmony_ci * 66162306a36Sopenharmony_ci * NOTE: At the end of the compressed attribute value, there most likely is not 66262306a36Sopenharmony_ci * just the right amount of data to make up a compression block, thus this data 66362306a36Sopenharmony_ci * is not even attempted to be compressed. It is just stored as is, unless 66462306a36Sopenharmony_ci * the number of clusters it occupies is reduced when compressed in which case 66562306a36Sopenharmony_ci * it is stored as a compressed compression block, complete with sparse 66662306a36Sopenharmony_ci * clusters at the end. 66762306a36Sopenharmony_ci */ 66862306a36Sopenharmony_ci 66962306a36Sopenharmony_ci/* 67062306a36Sopenharmony_ci * Flags of resident attributes (8-bit). 67162306a36Sopenharmony_ci */ 67262306a36Sopenharmony_cienum { 67362306a36Sopenharmony_ci RESIDENT_ATTR_IS_INDEXED = 0x01, /* Attribute is referenced in an index 67462306a36Sopenharmony_ci (has implications for deleting and 67562306a36Sopenharmony_ci modifying the attribute). */ 67662306a36Sopenharmony_ci} __attribute__ ((__packed__)); 67762306a36Sopenharmony_ci 67862306a36Sopenharmony_citypedef u8 RESIDENT_ATTR_FLAGS; 67962306a36Sopenharmony_ci 68062306a36Sopenharmony_ci/* 68162306a36Sopenharmony_ci * Attribute record header. Always aligned to 8-byte boundary. 68262306a36Sopenharmony_ci */ 68362306a36Sopenharmony_citypedef struct { 68462306a36Sopenharmony_ci/*Ofs*/ 68562306a36Sopenharmony_ci/* 0*/ ATTR_TYPE type; /* The (32-bit) type of the attribute. */ 68662306a36Sopenharmony_ci/* 4*/ le32 length; /* Byte size of the resident part of the 68762306a36Sopenharmony_ci attribute (aligned to 8-byte boundary). 68862306a36Sopenharmony_ci Used to get to the next attribute. */ 68962306a36Sopenharmony_ci/* 8*/ u8 non_resident; /* If 0, attribute is resident. 69062306a36Sopenharmony_ci If 1, attribute is non-resident. */ 69162306a36Sopenharmony_ci/* 9*/ u8 name_length; /* Unicode character size of name of attribute. 69262306a36Sopenharmony_ci 0 if unnamed. */ 69362306a36Sopenharmony_ci/* 10*/ le16 name_offset; /* If name_length != 0, the byte offset to the 69462306a36Sopenharmony_ci beginning of the name from the attribute 69562306a36Sopenharmony_ci record. Note that the name is stored as a 69662306a36Sopenharmony_ci Unicode string. When creating, place offset 69762306a36Sopenharmony_ci just at the end of the record header. Then, 69862306a36Sopenharmony_ci follow with attribute value or mapping pairs 69962306a36Sopenharmony_ci array, resident and non-resident attributes 70062306a36Sopenharmony_ci respectively, aligning to an 8-byte 70162306a36Sopenharmony_ci boundary. */ 70262306a36Sopenharmony_ci/* 12*/ ATTR_FLAGS flags; /* Flags describing the attribute. */ 70362306a36Sopenharmony_ci/* 14*/ le16 instance; /* The instance of this attribute record. This 70462306a36Sopenharmony_ci number is unique within this mft record (see 70562306a36Sopenharmony_ci MFT_RECORD/next_attribute_instance notes in 70662306a36Sopenharmony_ci mft.h for more details). */ 70762306a36Sopenharmony_ci/* 16*/ union { 70862306a36Sopenharmony_ci /* Resident attributes. */ 70962306a36Sopenharmony_ci struct { 71062306a36Sopenharmony_ci/* 16 */ le32 value_length;/* Byte size of attribute value. */ 71162306a36Sopenharmony_ci/* 20 */ le16 value_offset;/* Byte offset of the attribute 71262306a36Sopenharmony_ci value from the start of the 71362306a36Sopenharmony_ci attribute record. When creating, 71462306a36Sopenharmony_ci align to 8-byte boundary if we 71562306a36Sopenharmony_ci have a name present as this might 71662306a36Sopenharmony_ci not have a length of a multiple 71762306a36Sopenharmony_ci of 8-bytes. */ 71862306a36Sopenharmony_ci/* 22 */ RESIDENT_ATTR_FLAGS flags; /* See above. */ 71962306a36Sopenharmony_ci/* 23 */ s8 reserved; /* Reserved/alignment to 8-byte 72062306a36Sopenharmony_ci boundary. */ 72162306a36Sopenharmony_ci } __attribute__ ((__packed__)) resident; 72262306a36Sopenharmony_ci /* Non-resident attributes. */ 72362306a36Sopenharmony_ci struct { 72462306a36Sopenharmony_ci/* 16*/ leVCN lowest_vcn;/* Lowest valid virtual cluster number 72562306a36Sopenharmony_ci for this portion of the attribute value or 72662306a36Sopenharmony_ci 0 if this is the only extent (usually the 72762306a36Sopenharmony_ci case). - Only when an attribute list is used 72862306a36Sopenharmony_ci does lowest_vcn != 0 ever occur. */ 72962306a36Sopenharmony_ci/* 24*/ leVCN highest_vcn;/* Highest valid vcn of this extent of 73062306a36Sopenharmony_ci the attribute value. - Usually there is only one 73162306a36Sopenharmony_ci portion, so this usually equals the attribute 73262306a36Sopenharmony_ci value size in clusters minus 1. Can be -1 for 73362306a36Sopenharmony_ci zero length files. Can be 0 for "single extent" 73462306a36Sopenharmony_ci attributes. */ 73562306a36Sopenharmony_ci/* 32*/ le16 mapping_pairs_offset; /* Byte offset from the 73662306a36Sopenharmony_ci beginning of the structure to the mapping pairs 73762306a36Sopenharmony_ci array which contains the mappings between the 73862306a36Sopenharmony_ci vcns and the logical cluster numbers (lcns). 73962306a36Sopenharmony_ci When creating, place this at the end of this 74062306a36Sopenharmony_ci record header aligned to 8-byte boundary. */ 74162306a36Sopenharmony_ci/* 34*/ u8 compression_unit; /* The compression unit expressed 74262306a36Sopenharmony_ci as the log to the base 2 of the number of 74362306a36Sopenharmony_ci clusters in a compression unit. 0 means not 74462306a36Sopenharmony_ci compressed. (This effectively limits the 74562306a36Sopenharmony_ci compression unit size to be a power of two 74662306a36Sopenharmony_ci clusters.) WinNT4 only uses a value of 4. 74762306a36Sopenharmony_ci Sparse files have this set to 0 on XPSP2. */ 74862306a36Sopenharmony_ci/* 35*/ u8 reserved[5]; /* Align to 8-byte boundary. */ 74962306a36Sopenharmony_ci/* The sizes below are only used when lowest_vcn is zero, as otherwise it would 75062306a36Sopenharmony_ci be difficult to keep them up-to-date.*/ 75162306a36Sopenharmony_ci/* 40*/ sle64 allocated_size; /* Byte size of disk space 75262306a36Sopenharmony_ci allocated to hold the attribute value. Always 75362306a36Sopenharmony_ci is a multiple of the cluster size. When a file 75462306a36Sopenharmony_ci is compressed, this field is a multiple of the 75562306a36Sopenharmony_ci compression block size (2^compression_unit) and 75662306a36Sopenharmony_ci it represents the logically allocated space 75762306a36Sopenharmony_ci rather than the actual on disk usage. For this 75862306a36Sopenharmony_ci use the compressed_size (see below). */ 75962306a36Sopenharmony_ci/* 48*/ sle64 data_size; /* Byte size of the attribute 76062306a36Sopenharmony_ci value. Can be larger than allocated_size if 76162306a36Sopenharmony_ci attribute value is compressed or sparse. */ 76262306a36Sopenharmony_ci/* 56*/ sle64 initialized_size; /* Byte size of initialized 76362306a36Sopenharmony_ci portion of the attribute value. Usually equals 76462306a36Sopenharmony_ci data_size. */ 76562306a36Sopenharmony_ci/* sizeof(uncompressed attr) = 64*/ 76662306a36Sopenharmony_ci/* 64*/ sle64 compressed_size; /* Byte size of the attribute 76762306a36Sopenharmony_ci value after compression. Only present when 76862306a36Sopenharmony_ci compressed or sparse. Always is a multiple of 76962306a36Sopenharmony_ci the cluster size. Represents the actual amount 77062306a36Sopenharmony_ci of disk space being used on the disk. */ 77162306a36Sopenharmony_ci/* sizeof(compressed attr) = 72*/ 77262306a36Sopenharmony_ci } __attribute__ ((__packed__)) non_resident; 77362306a36Sopenharmony_ci } __attribute__ ((__packed__)) data; 77462306a36Sopenharmony_ci} __attribute__ ((__packed__)) ATTR_RECORD; 77562306a36Sopenharmony_ci 77662306a36Sopenharmony_citypedef ATTR_RECORD ATTR_REC; 77762306a36Sopenharmony_ci 77862306a36Sopenharmony_ci/* 77962306a36Sopenharmony_ci * File attribute flags (32-bit) appearing in the file_attributes fields of the 78062306a36Sopenharmony_ci * STANDARD_INFORMATION attribute of MFT_RECORDs and the FILENAME_ATTR 78162306a36Sopenharmony_ci * attributes of MFT_RECORDs and directory index entries. 78262306a36Sopenharmony_ci * 78362306a36Sopenharmony_ci * All of the below flags appear in the directory index entries but only some 78462306a36Sopenharmony_ci * appear in the STANDARD_INFORMATION attribute whilst only some others appear 78562306a36Sopenharmony_ci * in the FILENAME_ATTR attribute of MFT_RECORDs. Unless otherwise stated the 78662306a36Sopenharmony_ci * flags appear in all of the above. 78762306a36Sopenharmony_ci */ 78862306a36Sopenharmony_cienum { 78962306a36Sopenharmony_ci FILE_ATTR_READONLY = cpu_to_le32(0x00000001), 79062306a36Sopenharmony_ci FILE_ATTR_HIDDEN = cpu_to_le32(0x00000002), 79162306a36Sopenharmony_ci FILE_ATTR_SYSTEM = cpu_to_le32(0x00000004), 79262306a36Sopenharmony_ci /* Old DOS volid. Unused in NT. = cpu_to_le32(0x00000008), */ 79362306a36Sopenharmony_ci 79462306a36Sopenharmony_ci FILE_ATTR_DIRECTORY = cpu_to_le32(0x00000010), 79562306a36Sopenharmony_ci /* Note, FILE_ATTR_DIRECTORY is not considered valid in NT. It is 79662306a36Sopenharmony_ci reserved for the DOS SUBDIRECTORY flag. */ 79762306a36Sopenharmony_ci FILE_ATTR_ARCHIVE = cpu_to_le32(0x00000020), 79862306a36Sopenharmony_ci FILE_ATTR_DEVICE = cpu_to_le32(0x00000040), 79962306a36Sopenharmony_ci FILE_ATTR_NORMAL = cpu_to_le32(0x00000080), 80062306a36Sopenharmony_ci 80162306a36Sopenharmony_ci FILE_ATTR_TEMPORARY = cpu_to_le32(0x00000100), 80262306a36Sopenharmony_ci FILE_ATTR_SPARSE_FILE = cpu_to_le32(0x00000200), 80362306a36Sopenharmony_ci FILE_ATTR_REPARSE_POINT = cpu_to_le32(0x00000400), 80462306a36Sopenharmony_ci FILE_ATTR_COMPRESSED = cpu_to_le32(0x00000800), 80562306a36Sopenharmony_ci 80662306a36Sopenharmony_ci FILE_ATTR_OFFLINE = cpu_to_le32(0x00001000), 80762306a36Sopenharmony_ci FILE_ATTR_NOT_CONTENT_INDEXED = cpu_to_le32(0x00002000), 80862306a36Sopenharmony_ci FILE_ATTR_ENCRYPTED = cpu_to_le32(0x00004000), 80962306a36Sopenharmony_ci 81062306a36Sopenharmony_ci FILE_ATTR_VALID_FLAGS = cpu_to_le32(0x00007fb7), 81162306a36Sopenharmony_ci /* Note, FILE_ATTR_VALID_FLAGS masks out the old DOS VolId and the 81262306a36Sopenharmony_ci FILE_ATTR_DEVICE and preserves everything else. This mask is used 81362306a36Sopenharmony_ci to obtain all flags that are valid for reading. */ 81462306a36Sopenharmony_ci FILE_ATTR_VALID_SET_FLAGS = cpu_to_le32(0x000031a7), 81562306a36Sopenharmony_ci /* Note, FILE_ATTR_VALID_SET_FLAGS masks out the old DOS VolId, the 81662306a36Sopenharmony_ci F_A_DEVICE, F_A_DIRECTORY, F_A_SPARSE_FILE, F_A_REPARSE_POINT, 81762306a36Sopenharmony_ci F_A_COMPRESSED, and F_A_ENCRYPTED and preserves the rest. This mask 81862306a36Sopenharmony_ci is used to obtain all flags that are valid for setting. */ 81962306a36Sopenharmony_ci /* 82062306a36Sopenharmony_ci * The flag FILE_ATTR_DUP_FILENAME_INDEX_PRESENT is present in all 82162306a36Sopenharmony_ci * FILENAME_ATTR attributes but not in the STANDARD_INFORMATION 82262306a36Sopenharmony_ci * attribute of an mft record. 82362306a36Sopenharmony_ci */ 82462306a36Sopenharmony_ci FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT = cpu_to_le32(0x10000000), 82562306a36Sopenharmony_ci /* Note, this is a copy of the corresponding bit from the mft record, 82662306a36Sopenharmony_ci telling us whether this is a directory or not, i.e. whether it has 82762306a36Sopenharmony_ci an index root attribute or not. */ 82862306a36Sopenharmony_ci FILE_ATTR_DUP_VIEW_INDEX_PRESENT = cpu_to_le32(0x20000000), 82962306a36Sopenharmony_ci /* Note, this is a copy of the corresponding bit from the mft record, 83062306a36Sopenharmony_ci telling us whether this file has a view index present (eg. object id 83162306a36Sopenharmony_ci index, quota index, one of the security indexes or the encrypting 83262306a36Sopenharmony_ci filesystem related indexes). */ 83362306a36Sopenharmony_ci}; 83462306a36Sopenharmony_ci 83562306a36Sopenharmony_citypedef le32 FILE_ATTR_FLAGS; 83662306a36Sopenharmony_ci 83762306a36Sopenharmony_ci/* 83862306a36Sopenharmony_ci * NOTE on times in NTFS: All times are in MS standard time format, i.e. they 83962306a36Sopenharmony_ci * are the number of 100-nanosecond intervals since 1st January 1601, 00:00:00 84062306a36Sopenharmony_ci * universal coordinated time (UTC). (In Linux time starts 1st January 1970, 84162306a36Sopenharmony_ci * 00:00:00 UTC and is stored as the number of 1-second intervals since then.) 84262306a36Sopenharmony_ci */ 84362306a36Sopenharmony_ci 84462306a36Sopenharmony_ci/* 84562306a36Sopenharmony_ci * Attribute: Standard information (0x10). 84662306a36Sopenharmony_ci * 84762306a36Sopenharmony_ci * NOTE: Always resident. 84862306a36Sopenharmony_ci * NOTE: Present in all base file records on a volume. 84962306a36Sopenharmony_ci * NOTE: There is conflicting information about the meaning of each of the time 85062306a36Sopenharmony_ci * fields but the meaning as defined below has been verified to be 85162306a36Sopenharmony_ci * correct by practical experimentation on Windows NT4 SP6a and is hence 85262306a36Sopenharmony_ci * assumed to be the one and only correct interpretation. 85362306a36Sopenharmony_ci */ 85462306a36Sopenharmony_citypedef struct { 85562306a36Sopenharmony_ci/*Ofs*/ 85662306a36Sopenharmony_ci/* 0*/ sle64 creation_time; /* Time file was created. Updated when 85762306a36Sopenharmony_ci a filename is changed(?). */ 85862306a36Sopenharmony_ci/* 8*/ sle64 last_data_change_time; /* Time the data attribute was last 85962306a36Sopenharmony_ci modified. */ 86062306a36Sopenharmony_ci/* 16*/ sle64 last_mft_change_time; /* Time this mft record was last 86162306a36Sopenharmony_ci modified. */ 86262306a36Sopenharmony_ci/* 24*/ sle64 last_access_time; /* Approximate time when the file was 86362306a36Sopenharmony_ci last accessed (obviously this is not 86462306a36Sopenharmony_ci updated on read-only volumes). In 86562306a36Sopenharmony_ci Windows this is only updated when 86662306a36Sopenharmony_ci accessed if some time delta has 86762306a36Sopenharmony_ci passed since the last update. Also, 86862306a36Sopenharmony_ci last access time updates can be 86962306a36Sopenharmony_ci disabled altogether for speed. */ 87062306a36Sopenharmony_ci/* 32*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */ 87162306a36Sopenharmony_ci/* 36*/ union { 87262306a36Sopenharmony_ci /* NTFS 1.2 */ 87362306a36Sopenharmony_ci struct { 87462306a36Sopenharmony_ci /* 36*/ u8 reserved12[12]; /* Reserved/alignment to 8-byte 87562306a36Sopenharmony_ci boundary. */ 87662306a36Sopenharmony_ci } __attribute__ ((__packed__)) v1; 87762306a36Sopenharmony_ci /* sizeof() = 48 bytes */ 87862306a36Sopenharmony_ci /* NTFS 3.x */ 87962306a36Sopenharmony_ci struct { 88062306a36Sopenharmony_ci/* 88162306a36Sopenharmony_ci * If a volume has been upgraded from a previous NTFS version, then these 88262306a36Sopenharmony_ci * fields are present only if the file has been accessed since the upgrade. 88362306a36Sopenharmony_ci * Recognize the difference by comparing the length of the resident attribute 88462306a36Sopenharmony_ci * value. If it is 48, then the following fields are missing. If it is 72 then 88562306a36Sopenharmony_ci * the fields are present. Maybe just check like this: 88662306a36Sopenharmony_ci * if (resident.ValueLength < sizeof(STANDARD_INFORMATION)) { 88762306a36Sopenharmony_ci * Assume NTFS 1.2- format. 88862306a36Sopenharmony_ci * If (volume version is 3.x) 88962306a36Sopenharmony_ci * Upgrade attribute to NTFS 3.x format. 89062306a36Sopenharmony_ci * else 89162306a36Sopenharmony_ci * Use NTFS 1.2- format for access. 89262306a36Sopenharmony_ci * } else 89362306a36Sopenharmony_ci * Use NTFS 3.x format for access. 89462306a36Sopenharmony_ci * Only problem is that it might be legal to set the length of the value to 89562306a36Sopenharmony_ci * arbitrarily large values thus spoiling this check. - But chkdsk probably 89662306a36Sopenharmony_ci * views that as a corruption, assuming that it behaves like this for all 89762306a36Sopenharmony_ci * attributes. 89862306a36Sopenharmony_ci */ 89962306a36Sopenharmony_ci /* 36*/ le32 maximum_versions; /* Maximum allowed versions for 90062306a36Sopenharmony_ci file. Zero if version numbering is disabled. */ 90162306a36Sopenharmony_ci /* 40*/ le32 version_number; /* This file's version (if any). 90262306a36Sopenharmony_ci Set to zero if maximum_versions is zero. */ 90362306a36Sopenharmony_ci /* 44*/ le32 class_id; /* Class id from bidirectional 90462306a36Sopenharmony_ci class id index (?). */ 90562306a36Sopenharmony_ci /* 48*/ le32 owner_id; /* Owner_id of the user owning 90662306a36Sopenharmony_ci the file. Translate via $Q index in FILE_Extend 90762306a36Sopenharmony_ci /$Quota to the quota control entry for the user 90862306a36Sopenharmony_ci owning the file. Zero if quotas are disabled. */ 90962306a36Sopenharmony_ci /* 52*/ le32 security_id; /* Security_id for the file. 91062306a36Sopenharmony_ci Translate via $SII index and $SDS data stream 91162306a36Sopenharmony_ci in FILE_Secure to the security descriptor. */ 91262306a36Sopenharmony_ci /* 56*/ le64 quota_charged; /* Byte size of the charge to 91362306a36Sopenharmony_ci the quota for all streams of the file. Note: Is 91462306a36Sopenharmony_ci zero if quotas are disabled. */ 91562306a36Sopenharmony_ci /* 64*/ leUSN usn; /* Last update sequence number 91662306a36Sopenharmony_ci of the file. This is a direct index into the 91762306a36Sopenharmony_ci transaction log file ($UsnJrnl). It is zero if 91862306a36Sopenharmony_ci the usn journal is disabled or this file has 91962306a36Sopenharmony_ci not been subject to logging yet. See usnjrnl.h 92062306a36Sopenharmony_ci for details. */ 92162306a36Sopenharmony_ci } __attribute__ ((__packed__)) v3; 92262306a36Sopenharmony_ci /* sizeof() = 72 bytes (NTFS 3.x) */ 92362306a36Sopenharmony_ci } __attribute__ ((__packed__)) ver; 92462306a36Sopenharmony_ci} __attribute__ ((__packed__)) STANDARD_INFORMATION; 92562306a36Sopenharmony_ci 92662306a36Sopenharmony_ci/* 92762306a36Sopenharmony_ci * Attribute: Attribute list (0x20). 92862306a36Sopenharmony_ci * 92962306a36Sopenharmony_ci * - Can be either resident or non-resident. 93062306a36Sopenharmony_ci * - Value consists of a sequence of variable length, 8-byte aligned, 93162306a36Sopenharmony_ci * ATTR_LIST_ENTRY records. 93262306a36Sopenharmony_ci * - The list is not terminated by anything at all! The only way to know when 93362306a36Sopenharmony_ci * the end is reached is to keep track of the current offset and compare it to 93462306a36Sopenharmony_ci * the attribute value size. 93562306a36Sopenharmony_ci * - The attribute list attribute contains one entry for each attribute of 93662306a36Sopenharmony_ci * the file in which the list is located, except for the list attribute 93762306a36Sopenharmony_ci * itself. The list is sorted: first by attribute type, second by attribute 93862306a36Sopenharmony_ci * name (if present), third by instance number. The extents of one 93962306a36Sopenharmony_ci * non-resident attribute (if present) immediately follow after the initial 94062306a36Sopenharmony_ci * extent. They are ordered by lowest_vcn and have their instace set to zero. 94162306a36Sopenharmony_ci * It is not allowed to have two attributes with all sorting keys equal. 94262306a36Sopenharmony_ci * - Further restrictions: 94362306a36Sopenharmony_ci * - If not resident, the vcn to lcn mapping array has to fit inside the 94462306a36Sopenharmony_ci * base mft record. 94562306a36Sopenharmony_ci * - The attribute list attribute value has a maximum size of 256kb. This 94662306a36Sopenharmony_ci * is imposed by the Windows cache manager. 94762306a36Sopenharmony_ci * - Attribute lists are only used when the attributes of mft record do not 94862306a36Sopenharmony_ci * fit inside the mft record despite all attributes (that can be made 94962306a36Sopenharmony_ci * non-resident) having been made non-resident. This can happen e.g. when: 95062306a36Sopenharmony_ci * - File has a large number of hard links (lots of file name 95162306a36Sopenharmony_ci * attributes present). 95262306a36Sopenharmony_ci * - The mapping pairs array of some non-resident attribute becomes so 95362306a36Sopenharmony_ci * large due to fragmentation that it overflows the mft record. 95462306a36Sopenharmony_ci * - The security descriptor is very complex (not applicable to 95562306a36Sopenharmony_ci * NTFS 3.0 volumes). 95662306a36Sopenharmony_ci * - There are many named streams. 95762306a36Sopenharmony_ci */ 95862306a36Sopenharmony_citypedef struct { 95962306a36Sopenharmony_ci/*Ofs*/ 96062306a36Sopenharmony_ci/* 0*/ ATTR_TYPE type; /* Type of referenced attribute. */ 96162306a36Sopenharmony_ci/* 4*/ le16 length; /* Byte size of this entry (8-byte aligned). */ 96262306a36Sopenharmony_ci/* 6*/ u8 name_length; /* Size in Unicode chars of the name of the 96362306a36Sopenharmony_ci attribute or 0 if unnamed. */ 96462306a36Sopenharmony_ci/* 7*/ u8 name_offset; /* Byte offset to beginning of attribute name 96562306a36Sopenharmony_ci (always set this to where the name would 96662306a36Sopenharmony_ci start even if unnamed). */ 96762306a36Sopenharmony_ci/* 8*/ leVCN lowest_vcn; /* Lowest virtual cluster number of this portion 96862306a36Sopenharmony_ci of the attribute value. This is usually 0. It 96962306a36Sopenharmony_ci is non-zero for the case where one attribute 97062306a36Sopenharmony_ci does not fit into one mft record and thus 97162306a36Sopenharmony_ci several mft records are allocated to hold 97262306a36Sopenharmony_ci this attribute. In the latter case, each mft 97362306a36Sopenharmony_ci record holds one extent of the attribute and 97462306a36Sopenharmony_ci there is one attribute list entry for each 97562306a36Sopenharmony_ci extent. NOTE: This is DEFINITELY a signed 97662306a36Sopenharmony_ci value! The windows driver uses cmp, followed 97762306a36Sopenharmony_ci by jg when comparing this, thus it treats it 97862306a36Sopenharmony_ci as signed. */ 97962306a36Sopenharmony_ci/* 16*/ leMFT_REF mft_reference;/* The reference of the mft record holding 98062306a36Sopenharmony_ci the ATTR_RECORD for this portion of the 98162306a36Sopenharmony_ci attribute value. */ 98262306a36Sopenharmony_ci/* 24*/ le16 instance; /* If lowest_vcn = 0, the instance of the 98362306a36Sopenharmony_ci attribute being referenced; otherwise 0. */ 98462306a36Sopenharmony_ci/* 26*/ ntfschar name[0]; /* Use when creating only. When reading use 98562306a36Sopenharmony_ci name_offset to determine the location of the 98662306a36Sopenharmony_ci name. */ 98762306a36Sopenharmony_ci/* sizeof() = 26 + (attribute_name_length * 2) bytes */ 98862306a36Sopenharmony_ci} __attribute__ ((__packed__)) ATTR_LIST_ENTRY; 98962306a36Sopenharmony_ci 99062306a36Sopenharmony_ci/* 99162306a36Sopenharmony_ci * The maximum allowed length for a file name. 99262306a36Sopenharmony_ci */ 99362306a36Sopenharmony_ci#define MAXIMUM_FILE_NAME_LENGTH 255 99462306a36Sopenharmony_ci 99562306a36Sopenharmony_ci/* 99662306a36Sopenharmony_ci * Possible namespaces for filenames in ntfs (8-bit). 99762306a36Sopenharmony_ci */ 99862306a36Sopenharmony_cienum { 99962306a36Sopenharmony_ci FILE_NAME_POSIX = 0x00, 100062306a36Sopenharmony_ci /* This is the largest namespace. It is case sensitive and allows all 100162306a36Sopenharmony_ci Unicode characters except for: '\0' and '/'. Beware that in 100262306a36Sopenharmony_ci WinNT/2k/2003 by default files which eg have the same name except 100362306a36Sopenharmony_ci for their case will not be distinguished by the standard utilities 100462306a36Sopenharmony_ci and thus a "del filename" will delete both "filename" and "fileName" 100562306a36Sopenharmony_ci without warning. However if for example Services For Unix (SFU) are 100662306a36Sopenharmony_ci installed and the case sensitive option was enabled at installation 100762306a36Sopenharmony_ci time, then you can create/access/delete such files. 100862306a36Sopenharmony_ci Note that even SFU places restrictions on the filenames beyond the 100962306a36Sopenharmony_ci '\0' and '/' and in particular the following set of characters is 101062306a36Sopenharmony_ci not allowed: '"', '/', '<', '>', '\'. All other characters, 101162306a36Sopenharmony_ci including the ones no allowed in WIN32 namespace are allowed. 101262306a36Sopenharmony_ci Tested with SFU 3.5 (this is now free) running on Windows XP. */ 101362306a36Sopenharmony_ci FILE_NAME_WIN32 = 0x01, 101462306a36Sopenharmony_ci /* The standard WinNT/2k NTFS long filenames. Case insensitive. All 101562306a36Sopenharmony_ci Unicode chars except: '\0', '"', '*', '/', ':', '<', '>', '?', '\', 101662306a36Sopenharmony_ci and '|'. Further, names cannot end with a '.' or a space. */ 101762306a36Sopenharmony_ci FILE_NAME_DOS = 0x02, 101862306a36Sopenharmony_ci /* The standard DOS filenames (8.3 format). Uppercase only. All 8-bit 101962306a36Sopenharmony_ci characters greater space, except: '"', '*', '+', ',', '/', ':', ';', 102062306a36Sopenharmony_ci '<', '=', '>', '?', and '\'. */ 102162306a36Sopenharmony_ci FILE_NAME_WIN32_AND_DOS = 0x03, 102262306a36Sopenharmony_ci /* 3 means that both the Win32 and the DOS filenames are identical and 102362306a36Sopenharmony_ci hence have been saved in this single filename record. */ 102462306a36Sopenharmony_ci} __attribute__ ((__packed__)); 102562306a36Sopenharmony_ci 102662306a36Sopenharmony_citypedef u8 FILE_NAME_TYPE_FLAGS; 102762306a36Sopenharmony_ci 102862306a36Sopenharmony_ci/* 102962306a36Sopenharmony_ci * Attribute: Filename (0x30). 103062306a36Sopenharmony_ci * 103162306a36Sopenharmony_ci * NOTE: Always resident. 103262306a36Sopenharmony_ci * NOTE: All fields, except the parent_directory, are only updated when the 103362306a36Sopenharmony_ci * filename is changed. Until then, they just become out of sync with 103462306a36Sopenharmony_ci * reality and the more up to date values are present in the standard 103562306a36Sopenharmony_ci * information attribute. 103662306a36Sopenharmony_ci * NOTE: There is conflicting information about the meaning of each of the time 103762306a36Sopenharmony_ci * fields but the meaning as defined below has been verified to be 103862306a36Sopenharmony_ci * correct by practical experimentation on Windows NT4 SP6a and is hence 103962306a36Sopenharmony_ci * assumed to be the one and only correct interpretation. 104062306a36Sopenharmony_ci */ 104162306a36Sopenharmony_citypedef struct { 104262306a36Sopenharmony_ci/*hex ofs*/ 104362306a36Sopenharmony_ci/* 0*/ leMFT_REF parent_directory; /* Directory this filename is 104462306a36Sopenharmony_ci referenced from. */ 104562306a36Sopenharmony_ci/* 8*/ sle64 creation_time; /* Time file was created. */ 104662306a36Sopenharmony_ci/* 10*/ sle64 last_data_change_time; /* Time the data attribute was last 104762306a36Sopenharmony_ci modified. */ 104862306a36Sopenharmony_ci/* 18*/ sle64 last_mft_change_time; /* Time this mft record was last 104962306a36Sopenharmony_ci modified. */ 105062306a36Sopenharmony_ci/* 20*/ sle64 last_access_time; /* Time this mft record was last 105162306a36Sopenharmony_ci accessed. */ 105262306a36Sopenharmony_ci/* 28*/ sle64 allocated_size; /* Byte size of on-disk allocated space 105362306a36Sopenharmony_ci for the unnamed data attribute. So 105462306a36Sopenharmony_ci for normal $DATA, this is the 105562306a36Sopenharmony_ci allocated_size from the unnamed 105662306a36Sopenharmony_ci $DATA attribute and for compressed 105762306a36Sopenharmony_ci and/or sparse $DATA, this is the 105862306a36Sopenharmony_ci compressed_size from the unnamed 105962306a36Sopenharmony_ci $DATA attribute. For a directory or 106062306a36Sopenharmony_ci other inode without an unnamed $DATA 106162306a36Sopenharmony_ci attribute, this is always 0. NOTE: 106262306a36Sopenharmony_ci This is a multiple of the cluster 106362306a36Sopenharmony_ci size. */ 106462306a36Sopenharmony_ci/* 30*/ sle64 data_size; /* Byte size of actual data in unnamed 106562306a36Sopenharmony_ci data attribute. For a directory or 106662306a36Sopenharmony_ci other inode without an unnamed $DATA 106762306a36Sopenharmony_ci attribute, this is always 0. */ 106862306a36Sopenharmony_ci/* 38*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */ 106962306a36Sopenharmony_ci/* 3c*/ union { 107062306a36Sopenharmony_ci /* 3c*/ struct { 107162306a36Sopenharmony_ci /* 3c*/ le16 packed_ea_size; /* Size of the buffer needed to 107262306a36Sopenharmony_ci pack the extended attributes 107362306a36Sopenharmony_ci (EAs), if such are present.*/ 107462306a36Sopenharmony_ci /* 3e*/ le16 reserved; /* Reserved for alignment. */ 107562306a36Sopenharmony_ci } __attribute__ ((__packed__)) ea; 107662306a36Sopenharmony_ci /* 3c*/ struct { 107762306a36Sopenharmony_ci /* 3c*/ le32 reparse_point_tag; /* Type of reparse point, 107862306a36Sopenharmony_ci present only in reparse 107962306a36Sopenharmony_ci points and only if there are 108062306a36Sopenharmony_ci no EAs. */ 108162306a36Sopenharmony_ci } __attribute__ ((__packed__)) rp; 108262306a36Sopenharmony_ci } __attribute__ ((__packed__)) type; 108362306a36Sopenharmony_ci/* 40*/ u8 file_name_length; /* Length of file name in 108462306a36Sopenharmony_ci (Unicode) characters. */ 108562306a36Sopenharmony_ci/* 41*/ FILE_NAME_TYPE_FLAGS file_name_type; /* Namespace of the file name.*/ 108662306a36Sopenharmony_ci/* 42*/ ntfschar file_name[0]; /* File name in Unicode. */ 108762306a36Sopenharmony_ci} __attribute__ ((__packed__)) FILE_NAME_ATTR; 108862306a36Sopenharmony_ci 108962306a36Sopenharmony_ci/* 109062306a36Sopenharmony_ci * GUID structures store globally unique identifiers (GUID). A GUID is a 109162306a36Sopenharmony_ci * 128-bit value consisting of one group of eight hexadecimal digits, followed 109262306a36Sopenharmony_ci * by three groups of four hexadecimal digits each, followed by one group of 109362306a36Sopenharmony_ci * twelve hexadecimal digits. GUIDs are Microsoft's implementation of the 109462306a36Sopenharmony_ci * distributed computing environment (DCE) universally unique identifier (UUID). 109562306a36Sopenharmony_ci * Example of a GUID: 109662306a36Sopenharmony_ci * 1F010768-5A73-BC91-0010A52216A7 109762306a36Sopenharmony_ci */ 109862306a36Sopenharmony_citypedef struct { 109962306a36Sopenharmony_ci le32 data1; /* The first eight hexadecimal digits of the GUID. */ 110062306a36Sopenharmony_ci le16 data2; /* The first group of four hexadecimal digits. */ 110162306a36Sopenharmony_ci le16 data3; /* The second group of four hexadecimal digits. */ 110262306a36Sopenharmony_ci u8 data4[8]; /* The first two bytes are the third group of four 110362306a36Sopenharmony_ci hexadecimal digits. The remaining six bytes are the 110462306a36Sopenharmony_ci final 12 hexadecimal digits. */ 110562306a36Sopenharmony_ci} __attribute__ ((__packed__)) GUID; 110662306a36Sopenharmony_ci 110762306a36Sopenharmony_ci/* 110862306a36Sopenharmony_ci * FILE_Extend/$ObjId contains an index named $O. This index contains all 110962306a36Sopenharmony_ci * object_ids present on the volume as the index keys and the corresponding 111062306a36Sopenharmony_ci * mft_record numbers as the index entry data parts. The data part (defined 111162306a36Sopenharmony_ci * below) also contains three other object_ids: 111262306a36Sopenharmony_ci * birth_volume_id - object_id of FILE_Volume on which the file was first 111362306a36Sopenharmony_ci * created. Optional (i.e. can be zero). 111462306a36Sopenharmony_ci * birth_object_id - object_id of file when it was first created. Usually 111562306a36Sopenharmony_ci * equals the object_id. Optional (i.e. can be zero). 111662306a36Sopenharmony_ci * domain_id - Reserved (always zero). 111762306a36Sopenharmony_ci */ 111862306a36Sopenharmony_citypedef struct { 111962306a36Sopenharmony_ci leMFT_REF mft_reference;/* Mft record containing the object_id in 112062306a36Sopenharmony_ci the index entry key. */ 112162306a36Sopenharmony_ci union { 112262306a36Sopenharmony_ci struct { 112362306a36Sopenharmony_ci GUID birth_volume_id; 112462306a36Sopenharmony_ci GUID birth_object_id; 112562306a36Sopenharmony_ci GUID domain_id; 112662306a36Sopenharmony_ci } __attribute__ ((__packed__)) origin; 112762306a36Sopenharmony_ci u8 extended_info[48]; 112862306a36Sopenharmony_ci } __attribute__ ((__packed__)) opt; 112962306a36Sopenharmony_ci} __attribute__ ((__packed__)) OBJ_ID_INDEX_DATA; 113062306a36Sopenharmony_ci 113162306a36Sopenharmony_ci/* 113262306a36Sopenharmony_ci * Attribute: Object id (NTFS 3.0+) (0x40). 113362306a36Sopenharmony_ci * 113462306a36Sopenharmony_ci * NOTE: Always resident. 113562306a36Sopenharmony_ci */ 113662306a36Sopenharmony_citypedef struct { 113762306a36Sopenharmony_ci GUID object_id; /* Unique id assigned to the 113862306a36Sopenharmony_ci file.*/ 113962306a36Sopenharmony_ci /* The following fields are optional. The attribute value size is 16 114062306a36Sopenharmony_ci bytes, i.e. sizeof(GUID), if these are not present at all. Note, 114162306a36Sopenharmony_ci the entries can be present but one or more (or all) can be zero 114262306a36Sopenharmony_ci meaning that that particular value(s) is(are) not defined. */ 114362306a36Sopenharmony_ci union { 114462306a36Sopenharmony_ci struct { 114562306a36Sopenharmony_ci GUID birth_volume_id; /* Unique id of volume on which 114662306a36Sopenharmony_ci the file was first created.*/ 114762306a36Sopenharmony_ci GUID birth_object_id; /* Unique id of file when it was 114862306a36Sopenharmony_ci first created. */ 114962306a36Sopenharmony_ci GUID domain_id; /* Reserved, zero. */ 115062306a36Sopenharmony_ci } __attribute__ ((__packed__)) origin; 115162306a36Sopenharmony_ci u8 extended_info[48]; 115262306a36Sopenharmony_ci } __attribute__ ((__packed__)) opt; 115362306a36Sopenharmony_ci} __attribute__ ((__packed__)) OBJECT_ID_ATTR; 115462306a36Sopenharmony_ci 115562306a36Sopenharmony_ci/* 115662306a36Sopenharmony_ci * The pre-defined IDENTIFIER_AUTHORITIES used as SID_IDENTIFIER_AUTHORITY in 115762306a36Sopenharmony_ci * the SID structure (see below). 115862306a36Sopenharmony_ci */ 115962306a36Sopenharmony_ci//typedef enum { /* SID string prefix. */ 116062306a36Sopenharmony_ci// SECURITY_NULL_SID_AUTHORITY = {0, 0, 0, 0, 0, 0}, /* S-1-0 */ 116162306a36Sopenharmony_ci// SECURITY_WORLD_SID_AUTHORITY = {0, 0, 0, 0, 0, 1}, /* S-1-1 */ 116262306a36Sopenharmony_ci// SECURITY_LOCAL_SID_AUTHORITY = {0, 0, 0, 0, 0, 2}, /* S-1-2 */ 116362306a36Sopenharmony_ci// SECURITY_CREATOR_SID_AUTHORITY = {0, 0, 0, 0, 0, 3}, /* S-1-3 */ 116462306a36Sopenharmony_ci// SECURITY_NON_UNIQUE_AUTHORITY = {0, 0, 0, 0, 0, 4}, /* S-1-4 */ 116562306a36Sopenharmony_ci// SECURITY_NT_SID_AUTHORITY = {0, 0, 0, 0, 0, 5}, /* S-1-5 */ 116662306a36Sopenharmony_ci//} IDENTIFIER_AUTHORITIES; 116762306a36Sopenharmony_ci 116862306a36Sopenharmony_ci/* 116962306a36Sopenharmony_ci * These relative identifiers (RIDs) are used with the above identifier 117062306a36Sopenharmony_ci * authorities to make up universal well-known SIDs. 117162306a36Sopenharmony_ci * 117262306a36Sopenharmony_ci * Note: The relative identifier (RID) refers to the portion of a SID, which 117362306a36Sopenharmony_ci * identifies a user or group in relation to the authority that issued the SID. 117462306a36Sopenharmony_ci * For example, the universal well-known SID Creator Owner ID (S-1-3-0) is 117562306a36Sopenharmony_ci * made up of the identifier authority SECURITY_CREATOR_SID_AUTHORITY (3) and 117662306a36Sopenharmony_ci * the relative identifier SECURITY_CREATOR_OWNER_RID (0). 117762306a36Sopenharmony_ci */ 117862306a36Sopenharmony_citypedef enum { /* Identifier authority. */ 117962306a36Sopenharmony_ci SECURITY_NULL_RID = 0, /* S-1-0 */ 118062306a36Sopenharmony_ci SECURITY_WORLD_RID = 0, /* S-1-1 */ 118162306a36Sopenharmony_ci SECURITY_LOCAL_RID = 0, /* S-1-2 */ 118262306a36Sopenharmony_ci 118362306a36Sopenharmony_ci SECURITY_CREATOR_OWNER_RID = 0, /* S-1-3 */ 118462306a36Sopenharmony_ci SECURITY_CREATOR_GROUP_RID = 1, /* S-1-3 */ 118562306a36Sopenharmony_ci 118662306a36Sopenharmony_ci SECURITY_CREATOR_OWNER_SERVER_RID = 2, /* S-1-3 */ 118762306a36Sopenharmony_ci SECURITY_CREATOR_GROUP_SERVER_RID = 3, /* S-1-3 */ 118862306a36Sopenharmony_ci 118962306a36Sopenharmony_ci SECURITY_DIALUP_RID = 1, 119062306a36Sopenharmony_ci SECURITY_NETWORK_RID = 2, 119162306a36Sopenharmony_ci SECURITY_BATCH_RID = 3, 119262306a36Sopenharmony_ci SECURITY_INTERACTIVE_RID = 4, 119362306a36Sopenharmony_ci SECURITY_SERVICE_RID = 6, 119462306a36Sopenharmony_ci SECURITY_ANONYMOUS_LOGON_RID = 7, 119562306a36Sopenharmony_ci SECURITY_PROXY_RID = 8, 119662306a36Sopenharmony_ci SECURITY_ENTERPRISE_CONTROLLERS_RID=9, 119762306a36Sopenharmony_ci SECURITY_SERVER_LOGON_RID = 9, 119862306a36Sopenharmony_ci SECURITY_PRINCIPAL_SELF_RID = 0xa, 119962306a36Sopenharmony_ci SECURITY_AUTHENTICATED_USER_RID = 0xb, 120062306a36Sopenharmony_ci SECURITY_RESTRICTED_CODE_RID = 0xc, 120162306a36Sopenharmony_ci SECURITY_TERMINAL_SERVER_RID = 0xd, 120262306a36Sopenharmony_ci 120362306a36Sopenharmony_ci SECURITY_LOGON_IDS_RID = 5, 120462306a36Sopenharmony_ci SECURITY_LOGON_IDS_RID_COUNT = 3, 120562306a36Sopenharmony_ci 120662306a36Sopenharmony_ci SECURITY_LOCAL_SYSTEM_RID = 0x12, 120762306a36Sopenharmony_ci 120862306a36Sopenharmony_ci SECURITY_NT_NON_UNIQUE = 0x15, 120962306a36Sopenharmony_ci 121062306a36Sopenharmony_ci SECURITY_BUILTIN_DOMAIN_RID = 0x20, 121162306a36Sopenharmony_ci 121262306a36Sopenharmony_ci /* 121362306a36Sopenharmony_ci * Well-known domain relative sub-authority values (RIDs). 121462306a36Sopenharmony_ci */ 121562306a36Sopenharmony_ci 121662306a36Sopenharmony_ci /* Users. */ 121762306a36Sopenharmony_ci DOMAIN_USER_RID_ADMIN = 0x1f4, 121862306a36Sopenharmony_ci DOMAIN_USER_RID_GUEST = 0x1f5, 121962306a36Sopenharmony_ci DOMAIN_USER_RID_KRBTGT = 0x1f6, 122062306a36Sopenharmony_ci 122162306a36Sopenharmony_ci /* Groups. */ 122262306a36Sopenharmony_ci DOMAIN_GROUP_RID_ADMINS = 0x200, 122362306a36Sopenharmony_ci DOMAIN_GROUP_RID_USERS = 0x201, 122462306a36Sopenharmony_ci DOMAIN_GROUP_RID_GUESTS = 0x202, 122562306a36Sopenharmony_ci DOMAIN_GROUP_RID_COMPUTERS = 0x203, 122662306a36Sopenharmony_ci DOMAIN_GROUP_RID_CONTROLLERS = 0x204, 122762306a36Sopenharmony_ci DOMAIN_GROUP_RID_CERT_ADMINS = 0x205, 122862306a36Sopenharmony_ci DOMAIN_GROUP_RID_SCHEMA_ADMINS = 0x206, 122962306a36Sopenharmony_ci DOMAIN_GROUP_RID_ENTERPRISE_ADMINS= 0x207, 123062306a36Sopenharmony_ci DOMAIN_GROUP_RID_POLICY_ADMINS = 0x208, 123162306a36Sopenharmony_ci 123262306a36Sopenharmony_ci /* Aliases. */ 123362306a36Sopenharmony_ci DOMAIN_ALIAS_RID_ADMINS = 0x220, 123462306a36Sopenharmony_ci DOMAIN_ALIAS_RID_USERS = 0x221, 123562306a36Sopenharmony_ci DOMAIN_ALIAS_RID_GUESTS = 0x222, 123662306a36Sopenharmony_ci DOMAIN_ALIAS_RID_POWER_USERS = 0x223, 123762306a36Sopenharmony_ci 123862306a36Sopenharmony_ci DOMAIN_ALIAS_RID_ACCOUNT_OPS = 0x224, 123962306a36Sopenharmony_ci DOMAIN_ALIAS_RID_SYSTEM_OPS = 0x225, 124062306a36Sopenharmony_ci DOMAIN_ALIAS_RID_PRINT_OPS = 0x226, 124162306a36Sopenharmony_ci DOMAIN_ALIAS_RID_BACKUP_OPS = 0x227, 124262306a36Sopenharmony_ci 124362306a36Sopenharmony_ci DOMAIN_ALIAS_RID_REPLICATOR = 0x228, 124462306a36Sopenharmony_ci DOMAIN_ALIAS_RID_RAS_SERVERS = 0x229, 124562306a36Sopenharmony_ci DOMAIN_ALIAS_RID_PREW2KCOMPACCESS = 0x22a, 124662306a36Sopenharmony_ci} RELATIVE_IDENTIFIERS; 124762306a36Sopenharmony_ci 124862306a36Sopenharmony_ci/* 124962306a36Sopenharmony_ci * The universal well-known SIDs: 125062306a36Sopenharmony_ci * 125162306a36Sopenharmony_ci * NULL_SID S-1-0-0 125262306a36Sopenharmony_ci * WORLD_SID S-1-1-0 125362306a36Sopenharmony_ci * LOCAL_SID S-1-2-0 125462306a36Sopenharmony_ci * CREATOR_OWNER_SID S-1-3-0 125562306a36Sopenharmony_ci * CREATOR_GROUP_SID S-1-3-1 125662306a36Sopenharmony_ci * CREATOR_OWNER_SERVER_SID S-1-3-2 125762306a36Sopenharmony_ci * CREATOR_GROUP_SERVER_SID S-1-3-3 125862306a36Sopenharmony_ci * 125962306a36Sopenharmony_ci * (Non-unique IDs) S-1-4 126062306a36Sopenharmony_ci * 126162306a36Sopenharmony_ci * NT well-known SIDs: 126262306a36Sopenharmony_ci * 126362306a36Sopenharmony_ci * NT_AUTHORITY_SID S-1-5 126462306a36Sopenharmony_ci * DIALUP_SID S-1-5-1 126562306a36Sopenharmony_ci * 126662306a36Sopenharmony_ci * NETWORD_SID S-1-5-2 126762306a36Sopenharmony_ci * BATCH_SID S-1-5-3 126862306a36Sopenharmony_ci * INTERACTIVE_SID S-1-5-4 126962306a36Sopenharmony_ci * SERVICE_SID S-1-5-6 127062306a36Sopenharmony_ci * ANONYMOUS_LOGON_SID S-1-5-7 (aka null logon session) 127162306a36Sopenharmony_ci * PROXY_SID S-1-5-8 127262306a36Sopenharmony_ci * SERVER_LOGON_SID S-1-5-9 (aka domain controller account) 127362306a36Sopenharmony_ci * SELF_SID S-1-5-10 (self RID) 127462306a36Sopenharmony_ci * AUTHENTICATED_USER_SID S-1-5-11 127562306a36Sopenharmony_ci * RESTRICTED_CODE_SID S-1-5-12 (running restricted code) 127662306a36Sopenharmony_ci * TERMINAL_SERVER_SID S-1-5-13 (running on terminal server) 127762306a36Sopenharmony_ci * 127862306a36Sopenharmony_ci * (Logon IDs) S-1-5-5-X-Y 127962306a36Sopenharmony_ci * 128062306a36Sopenharmony_ci * (NT non-unique IDs) S-1-5-0x15-... 128162306a36Sopenharmony_ci * 128262306a36Sopenharmony_ci * (Built-in domain) S-1-5-0x20 128362306a36Sopenharmony_ci */ 128462306a36Sopenharmony_ci 128562306a36Sopenharmony_ci/* 128662306a36Sopenharmony_ci * The SID_IDENTIFIER_AUTHORITY is a 48-bit value used in the SID structure. 128762306a36Sopenharmony_ci * 128862306a36Sopenharmony_ci * NOTE: This is stored as a big endian number, hence the high_part comes 128962306a36Sopenharmony_ci * before the low_part. 129062306a36Sopenharmony_ci */ 129162306a36Sopenharmony_citypedef union { 129262306a36Sopenharmony_ci struct { 129362306a36Sopenharmony_ci u16 high_part; /* High 16-bits. */ 129462306a36Sopenharmony_ci u32 low_part; /* Low 32-bits. */ 129562306a36Sopenharmony_ci } __attribute__ ((__packed__)) parts; 129662306a36Sopenharmony_ci u8 value[6]; /* Value as individual bytes. */ 129762306a36Sopenharmony_ci} __attribute__ ((__packed__)) SID_IDENTIFIER_AUTHORITY; 129862306a36Sopenharmony_ci 129962306a36Sopenharmony_ci/* 130062306a36Sopenharmony_ci * The SID structure is a variable-length structure used to uniquely identify 130162306a36Sopenharmony_ci * users or groups. SID stands for security identifier. 130262306a36Sopenharmony_ci * 130362306a36Sopenharmony_ci * The standard textual representation of the SID is of the form: 130462306a36Sopenharmony_ci * S-R-I-S-S... 130562306a36Sopenharmony_ci * Where: 130662306a36Sopenharmony_ci * - The first "S" is the literal character 'S' identifying the following 130762306a36Sopenharmony_ci * digits as a SID. 130862306a36Sopenharmony_ci * - R is the revision level of the SID expressed as a sequence of digits 130962306a36Sopenharmony_ci * either in decimal or hexadecimal (if the later, prefixed by "0x"). 131062306a36Sopenharmony_ci * - I is the 48-bit identifier_authority, expressed as digits as R above. 131162306a36Sopenharmony_ci * - S... is one or more sub_authority values, expressed as digits as above. 131262306a36Sopenharmony_ci * 131362306a36Sopenharmony_ci * Example SID; the domain-relative SID of the local Administrators group on 131462306a36Sopenharmony_ci * Windows NT/2k: 131562306a36Sopenharmony_ci * S-1-5-32-544 131662306a36Sopenharmony_ci * This translates to a SID with: 131762306a36Sopenharmony_ci * revision = 1, 131862306a36Sopenharmony_ci * sub_authority_count = 2, 131962306a36Sopenharmony_ci * identifier_authority = {0,0,0,0,0,5}, // SECURITY_NT_AUTHORITY 132062306a36Sopenharmony_ci * sub_authority[0] = 32, // SECURITY_BUILTIN_DOMAIN_RID 132162306a36Sopenharmony_ci * sub_authority[1] = 544 // DOMAIN_ALIAS_RID_ADMINS 132262306a36Sopenharmony_ci */ 132362306a36Sopenharmony_citypedef struct { 132462306a36Sopenharmony_ci u8 revision; 132562306a36Sopenharmony_ci u8 sub_authority_count; 132662306a36Sopenharmony_ci SID_IDENTIFIER_AUTHORITY identifier_authority; 132762306a36Sopenharmony_ci le32 sub_authority[1]; /* At least one sub_authority. */ 132862306a36Sopenharmony_ci} __attribute__ ((__packed__)) SID; 132962306a36Sopenharmony_ci 133062306a36Sopenharmony_ci/* 133162306a36Sopenharmony_ci * Current constants for SIDs. 133262306a36Sopenharmony_ci */ 133362306a36Sopenharmony_citypedef enum { 133462306a36Sopenharmony_ci SID_REVISION = 1, /* Current revision level. */ 133562306a36Sopenharmony_ci SID_MAX_SUB_AUTHORITIES = 15, /* Maximum number of those. */ 133662306a36Sopenharmony_ci SID_RECOMMENDED_SUB_AUTHORITIES = 1, /* Will change to around 6 in 133762306a36Sopenharmony_ci a future revision. */ 133862306a36Sopenharmony_ci} SID_CONSTANTS; 133962306a36Sopenharmony_ci 134062306a36Sopenharmony_ci/* 134162306a36Sopenharmony_ci * The predefined ACE types (8-bit, see below). 134262306a36Sopenharmony_ci */ 134362306a36Sopenharmony_cienum { 134462306a36Sopenharmony_ci ACCESS_MIN_MS_ACE_TYPE = 0, 134562306a36Sopenharmony_ci ACCESS_ALLOWED_ACE_TYPE = 0, 134662306a36Sopenharmony_ci ACCESS_DENIED_ACE_TYPE = 1, 134762306a36Sopenharmony_ci SYSTEM_AUDIT_ACE_TYPE = 2, 134862306a36Sopenharmony_ci SYSTEM_ALARM_ACE_TYPE = 3, /* Not implemented as of Win2k. */ 134962306a36Sopenharmony_ci ACCESS_MAX_MS_V2_ACE_TYPE = 3, 135062306a36Sopenharmony_ci 135162306a36Sopenharmony_ci ACCESS_ALLOWED_COMPOUND_ACE_TYPE= 4, 135262306a36Sopenharmony_ci ACCESS_MAX_MS_V3_ACE_TYPE = 4, 135362306a36Sopenharmony_ci 135462306a36Sopenharmony_ci /* The following are Win2k only. */ 135562306a36Sopenharmony_ci ACCESS_MIN_MS_OBJECT_ACE_TYPE = 5, 135662306a36Sopenharmony_ci ACCESS_ALLOWED_OBJECT_ACE_TYPE = 5, 135762306a36Sopenharmony_ci ACCESS_DENIED_OBJECT_ACE_TYPE = 6, 135862306a36Sopenharmony_ci SYSTEM_AUDIT_OBJECT_ACE_TYPE = 7, 135962306a36Sopenharmony_ci SYSTEM_ALARM_OBJECT_ACE_TYPE = 8, 136062306a36Sopenharmony_ci ACCESS_MAX_MS_OBJECT_ACE_TYPE = 8, 136162306a36Sopenharmony_ci 136262306a36Sopenharmony_ci ACCESS_MAX_MS_V4_ACE_TYPE = 8, 136362306a36Sopenharmony_ci 136462306a36Sopenharmony_ci /* This one is for WinNT/2k. */ 136562306a36Sopenharmony_ci ACCESS_MAX_MS_ACE_TYPE = 8, 136662306a36Sopenharmony_ci} __attribute__ ((__packed__)); 136762306a36Sopenharmony_ci 136862306a36Sopenharmony_citypedef u8 ACE_TYPES; 136962306a36Sopenharmony_ci 137062306a36Sopenharmony_ci/* 137162306a36Sopenharmony_ci * The ACE flags (8-bit) for audit and inheritance (see below). 137262306a36Sopenharmony_ci * 137362306a36Sopenharmony_ci * SUCCESSFUL_ACCESS_ACE_FLAG is only used with system audit and alarm ACE 137462306a36Sopenharmony_ci * types to indicate that a message is generated (in Windows!) for successful 137562306a36Sopenharmony_ci * accesses. 137662306a36Sopenharmony_ci * 137762306a36Sopenharmony_ci * FAILED_ACCESS_ACE_FLAG is only used with system audit and alarm ACE types 137862306a36Sopenharmony_ci * to indicate that a message is generated (in Windows!) for failed accesses. 137962306a36Sopenharmony_ci */ 138062306a36Sopenharmony_cienum { 138162306a36Sopenharmony_ci /* The inheritance flags. */ 138262306a36Sopenharmony_ci OBJECT_INHERIT_ACE = 0x01, 138362306a36Sopenharmony_ci CONTAINER_INHERIT_ACE = 0x02, 138462306a36Sopenharmony_ci NO_PROPAGATE_INHERIT_ACE = 0x04, 138562306a36Sopenharmony_ci INHERIT_ONLY_ACE = 0x08, 138662306a36Sopenharmony_ci INHERITED_ACE = 0x10, /* Win2k only. */ 138762306a36Sopenharmony_ci VALID_INHERIT_FLAGS = 0x1f, 138862306a36Sopenharmony_ci 138962306a36Sopenharmony_ci /* The audit flags. */ 139062306a36Sopenharmony_ci SUCCESSFUL_ACCESS_ACE_FLAG = 0x40, 139162306a36Sopenharmony_ci FAILED_ACCESS_ACE_FLAG = 0x80, 139262306a36Sopenharmony_ci} __attribute__ ((__packed__)); 139362306a36Sopenharmony_ci 139462306a36Sopenharmony_citypedef u8 ACE_FLAGS; 139562306a36Sopenharmony_ci 139662306a36Sopenharmony_ci/* 139762306a36Sopenharmony_ci * An ACE is an access-control entry in an access-control list (ACL). 139862306a36Sopenharmony_ci * An ACE defines access to an object for a specific user or group or defines 139962306a36Sopenharmony_ci * the types of access that generate system-administration messages or alarms 140062306a36Sopenharmony_ci * for a specific user or group. The user or group is identified by a security 140162306a36Sopenharmony_ci * identifier (SID). 140262306a36Sopenharmony_ci * 140362306a36Sopenharmony_ci * Each ACE starts with an ACE_HEADER structure (aligned on 4-byte boundary), 140462306a36Sopenharmony_ci * which specifies the type and size of the ACE. The format of the subsequent 140562306a36Sopenharmony_ci * data depends on the ACE type. 140662306a36Sopenharmony_ci */ 140762306a36Sopenharmony_citypedef struct { 140862306a36Sopenharmony_ci/*Ofs*/ 140962306a36Sopenharmony_ci/* 0*/ ACE_TYPES type; /* Type of the ACE. */ 141062306a36Sopenharmony_ci/* 1*/ ACE_FLAGS flags; /* Flags describing the ACE. */ 141162306a36Sopenharmony_ci/* 2*/ le16 size; /* Size in bytes of the ACE. */ 141262306a36Sopenharmony_ci} __attribute__ ((__packed__)) ACE_HEADER; 141362306a36Sopenharmony_ci 141462306a36Sopenharmony_ci/* 141562306a36Sopenharmony_ci * The access mask (32-bit). Defines the access rights. 141662306a36Sopenharmony_ci * 141762306a36Sopenharmony_ci * The specific rights (bits 0 to 15). These depend on the type of the object 141862306a36Sopenharmony_ci * being secured by the ACE. 141962306a36Sopenharmony_ci */ 142062306a36Sopenharmony_cienum { 142162306a36Sopenharmony_ci /* Specific rights for files and directories are as follows: */ 142262306a36Sopenharmony_ci 142362306a36Sopenharmony_ci /* Right to read data from the file. (FILE) */ 142462306a36Sopenharmony_ci FILE_READ_DATA = cpu_to_le32(0x00000001), 142562306a36Sopenharmony_ci /* Right to list contents of a directory. (DIRECTORY) */ 142662306a36Sopenharmony_ci FILE_LIST_DIRECTORY = cpu_to_le32(0x00000001), 142762306a36Sopenharmony_ci 142862306a36Sopenharmony_ci /* Right to write data to the file. (FILE) */ 142962306a36Sopenharmony_ci FILE_WRITE_DATA = cpu_to_le32(0x00000002), 143062306a36Sopenharmony_ci /* Right to create a file in the directory. (DIRECTORY) */ 143162306a36Sopenharmony_ci FILE_ADD_FILE = cpu_to_le32(0x00000002), 143262306a36Sopenharmony_ci 143362306a36Sopenharmony_ci /* Right to append data to the file. (FILE) */ 143462306a36Sopenharmony_ci FILE_APPEND_DATA = cpu_to_le32(0x00000004), 143562306a36Sopenharmony_ci /* Right to create a subdirectory. (DIRECTORY) */ 143662306a36Sopenharmony_ci FILE_ADD_SUBDIRECTORY = cpu_to_le32(0x00000004), 143762306a36Sopenharmony_ci 143862306a36Sopenharmony_ci /* Right to read extended attributes. (FILE/DIRECTORY) */ 143962306a36Sopenharmony_ci FILE_READ_EA = cpu_to_le32(0x00000008), 144062306a36Sopenharmony_ci 144162306a36Sopenharmony_ci /* Right to write extended attributes. (FILE/DIRECTORY) */ 144262306a36Sopenharmony_ci FILE_WRITE_EA = cpu_to_le32(0x00000010), 144362306a36Sopenharmony_ci 144462306a36Sopenharmony_ci /* Right to execute a file. (FILE) */ 144562306a36Sopenharmony_ci FILE_EXECUTE = cpu_to_le32(0x00000020), 144662306a36Sopenharmony_ci /* Right to traverse the directory. (DIRECTORY) */ 144762306a36Sopenharmony_ci FILE_TRAVERSE = cpu_to_le32(0x00000020), 144862306a36Sopenharmony_ci 144962306a36Sopenharmony_ci /* 145062306a36Sopenharmony_ci * Right to delete a directory and all the files it contains (its 145162306a36Sopenharmony_ci * children), even if the files are read-only. (DIRECTORY) 145262306a36Sopenharmony_ci */ 145362306a36Sopenharmony_ci FILE_DELETE_CHILD = cpu_to_le32(0x00000040), 145462306a36Sopenharmony_ci 145562306a36Sopenharmony_ci /* Right to read file attributes. (FILE/DIRECTORY) */ 145662306a36Sopenharmony_ci FILE_READ_ATTRIBUTES = cpu_to_le32(0x00000080), 145762306a36Sopenharmony_ci 145862306a36Sopenharmony_ci /* Right to change file attributes. (FILE/DIRECTORY) */ 145962306a36Sopenharmony_ci FILE_WRITE_ATTRIBUTES = cpu_to_le32(0x00000100), 146062306a36Sopenharmony_ci 146162306a36Sopenharmony_ci /* 146262306a36Sopenharmony_ci * The standard rights (bits 16 to 23). These are independent of the 146362306a36Sopenharmony_ci * type of object being secured. 146462306a36Sopenharmony_ci */ 146562306a36Sopenharmony_ci 146662306a36Sopenharmony_ci /* Right to delete the object. */ 146762306a36Sopenharmony_ci DELETE = cpu_to_le32(0x00010000), 146862306a36Sopenharmony_ci 146962306a36Sopenharmony_ci /* 147062306a36Sopenharmony_ci * Right to read the information in the object's security descriptor, 147162306a36Sopenharmony_ci * not including the information in the SACL, i.e. right to read the 147262306a36Sopenharmony_ci * security descriptor and owner. 147362306a36Sopenharmony_ci */ 147462306a36Sopenharmony_ci READ_CONTROL = cpu_to_le32(0x00020000), 147562306a36Sopenharmony_ci 147662306a36Sopenharmony_ci /* Right to modify the DACL in the object's security descriptor. */ 147762306a36Sopenharmony_ci WRITE_DAC = cpu_to_le32(0x00040000), 147862306a36Sopenharmony_ci 147962306a36Sopenharmony_ci /* Right to change the owner in the object's security descriptor. */ 148062306a36Sopenharmony_ci WRITE_OWNER = cpu_to_le32(0x00080000), 148162306a36Sopenharmony_ci 148262306a36Sopenharmony_ci /* 148362306a36Sopenharmony_ci * Right to use the object for synchronization. Enables a process to 148462306a36Sopenharmony_ci * wait until the object is in the signalled state. Some object types 148562306a36Sopenharmony_ci * do not support this access right. 148662306a36Sopenharmony_ci */ 148762306a36Sopenharmony_ci SYNCHRONIZE = cpu_to_le32(0x00100000), 148862306a36Sopenharmony_ci 148962306a36Sopenharmony_ci /* 149062306a36Sopenharmony_ci * The following STANDARD_RIGHTS_* are combinations of the above for 149162306a36Sopenharmony_ci * convenience and are defined by the Win32 API. 149262306a36Sopenharmony_ci */ 149362306a36Sopenharmony_ci 149462306a36Sopenharmony_ci /* These are currently defined to READ_CONTROL. */ 149562306a36Sopenharmony_ci STANDARD_RIGHTS_READ = cpu_to_le32(0x00020000), 149662306a36Sopenharmony_ci STANDARD_RIGHTS_WRITE = cpu_to_le32(0x00020000), 149762306a36Sopenharmony_ci STANDARD_RIGHTS_EXECUTE = cpu_to_le32(0x00020000), 149862306a36Sopenharmony_ci 149962306a36Sopenharmony_ci /* Combines DELETE, READ_CONTROL, WRITE_DAC, and WRITE_OWNER access. */ 150062306a36Sopenharmony_ci STANDARD_RIGHTS_REQUIRED = cpu_to_le32(0x000f0000), 150162306a36Sopenharmony_ci 150262306a36Sopenharmony_ci /* 150362306a36Sopenharmony_ci * Combines DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, and 150462306a36Sopenharmony_ci * SYNCHRONIZE access. 150562306a36Sopenharmony_ci */ 150662306a36Sopenharmony_ci STANDARD_RIGHTS_ALL = cpu_to_le32(0x001f0000), 150762306a36Sopenharmony_ci 150862306a36Sopenharmony_ci /* 150962306a36Sopenharmony_ci * The access system ACL and maximum allowed access types (bits 24 to 151062306a36Sopenharmony_ci * 25, bits 26 to 27 are reserved). 151162306a36Sopenharmony_ci */ 151262306a36Sopenharmony_ci ACCESS_SYSTEM_SECURITY = cpu_to_le32(0x01000000), 151362306a36Sopenharmony_ci MAXIMUM_ALLOWED = cpu_to_le32(0x02000000), 151462306a36Sopenharmony_ci 151562306a36Sopenharmony_ci /* 151662306a36Sopenharmony_ci * The generic rights (bits 28 to 31). These map onto the standard and 151762306a36Sopenharmony_ci * specific rights. 151862306a36Sopenharmony_ci */ 151962306a36Sopenharmony_ci 152062306a36Sopenharmony_ci /* Read, write, and execute access. */ 152162306a36Sopenharmony_ci GENERIC_ALL = cpu_to_le32(0x10000000), 152262306a36Sopenharmony_ci 152362306a36Sopenharmony_ci /* Execute access. */ 152462306a36Sopenharmony_ci GENERIC_EXECUTE = cpu_to_le32(0x20000000), 152562306a36Sopenharmony_ci 152662306a36Sopenharmony_ci /* 152762306a36Sopenharmony_ci * Write access. For files, this maps onto: 152862306a36Sopenharmony_ci * FILE_APPEND_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_DATA | 152962306a36Sopenharmony_ci * FILE_WRITE_EA | STANDARD_RIGHTS_WRITE | SYNCHRONIZE 153062306a36Sopenharmony_ci * For directories, the mapping has the same numerical value. See 153162306a36Sopenharmony_ci * above for the descriptions of the rights granted. 153262306a36Sopenharmony_ci */ 153362306a36Sopenharmony_ci GENERIC_WRITE = cpu_to_le32(0x40000000), 153462306a36Sopenharmony_ci 153562306a36Sopenharmony_ci /* 153662306a36Sopenharmony_ci * Read access. For files, this maps onto: 153762306a36Sopenharmony_ci * FILE_READ_ATTRIBUTES | FILE_READ_DATA | FILE_READ_EA | 153862306a36Sopenharmony_ci * STANDARD_RIGHTS_READ | SYNCHRONIZE 153962306a36Sopenharmony_ci * For directories, the mapping has the same numberical value. See 154062306a36Sopenharmony_ci * above for the descriptions of the rights granted. 154162306a36Sopenharmony_ci */ 154262306a36Sopenharmony_ci GENERIC_READ = cpu_to_le32(0x80000000), 154362306a36Sopenharmony_ci}; 154462306a36Sopenharmony_ci 154562306a36Sopenharmony_citypedef le32 ACCESS_MASK; 154662306a36Sopenharmony_ci 154762306a36Sopenharmony_ci/* 154862306a36Sopenharmony_ci * The generic mapping array. Used to denote the mapping of each generic 154962306a36Sopenharmony_ci * access right to a specific access mask. 155062306a36Sopenharmony_ci * 155162306a36Sopenharmony_ci * FIXME: What exactly is this and what is it for? (AIA) 155262306a36Sopenharmony_ci */ 155362306a36Sopenharmony_citypedef struct { 155462306a36Sopenharmony_ci ACCESS_MASK generic_read; 155562306a36Sopenharmony_ci ACCESS_MASK generic_write; 155662306a36Sopenharmony_ci ACCESS_MASK generic_execute; 155762306a36Sopenharmony_ci ACCESS_MASK generic_all; 155862306a36Sopenharmony_ci} __attribute__ ((__packed__)) GENERIC_MAPPING; 155962306a36Sopenharmony_ci 156062306a36Sopenharmony_ci/* 156162306a36Sopenharmony_ci * The predefined ACE type structures are as defined below. 156262306a36Sopenharmony_ci */ 156362306a36Sopenharmony_ci 156462306a36Sopenharmony_ci/* 156562306a36Sopenharmony_ci * ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE 156662306a36Sopenharmony_ci */ 156762306a36Sopenharmony_citypedef struct { 156862306a36Sopenharmony_ci/* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */ 156962306a36Sopenharmony_ci ACE_TYPES type; /* Type of the ACE. */ 157062306a36Sopenharmony_ci ACE_FLAGS flags; /* Flags describing the ACE. */ 157162306a36Sopenharmony_ci le16 size; /* Size in bytes of the ACE. */ 157262306a36Sopenharmony_ci/* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */ 157362306a36Sopenharmony_ci 157462306a36Sopenharmony_ci/* 8*/ SID sid; /* The SID associated with the ACE. */ 157562306a36Sopenharmony_ci} __attribute__ ((__packed__)) ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, 157662306a36Sopenharmony_ci SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE; 157762306a36Sopenharmony_ci 157862306a36Sopenharmony_ci/* 157962306a36Sopenharmony_ci * The object ACE flags (32-bit). 158062306a36Sopenharmony_ci */ 158162306a36Sopenharmony_cienum { 158262306a36Sopenharmony_ci ACE_OBJECT_TYPE_PRESENT = cpu_to_le32(1), 158362306a36Sopenharmony_ci ACE_INHERITED_OBJECT_TYPE_PRESENT = cpu_to_le32(2), 158462306a36Sopenharmony_ci}; 158562306a36Sopenharmony_ci 158662306a36Sopenharmony_citypedef le32 OBJECT_ACE_FLAGS; 158762306a36Sopenharmony_ci 158862306a36Sopenharmony_citypedef struct { 158962306a36Sopenharmony_ci/* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */ 159062306a36Sopenharmony_ci ACE_TYPES type; /* Type of the ACE. */ 159162306a36Sopenharmony_ci ACE_FLAGS flags; /* Flags describing the ACE. */ 159262306a36Sopenharmony_ci le16 size; /* Size in bytes of the ACE. */ 159362306a36Sopenharmony_ci/* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */ 159462306a36Sopenharmony_ci 159562306a36Sopenharmony_ci/* 8*/ OBJECT_ACE_FLAGS object_flags; /* Flags describing the object ACE. */ 159662306a36Sopenharmony_ci/* 12*/ GUID object_type; 159762306a36Sopenharmony_ci/* 28*/ GUID inherited_object_type; 159862306a36Sopenharmony_ci 159962306a36Sopenharmony_ci/* 44*/ SID sid; /* The SID associated with the ACE. */ 160062306a36Sopenharmony_ci} __attribute__ ((__packed__)) ACCESS_ALLOWED_OBJECT_ACE, 160162306a36Sopenharmony_ci ACCESS_DENIED_OBJECT_ACE, 160262306a36Sopenharmony_ci SYSTEM_AUDIT_OBJECT_ACE, 160362306a36Sopenharmony_ci SYSTEM_ALARM_OBJECT_ACE; 160462306a36Sopenharmony_ci 160562306a36Sopenharmony_ci/* 160662306a36Sopenharmony_ci * An ACL is an access-control list (ACL). 160762306a36Sopenharmony_ci * An ACL starts with an ACL header structure, which specifies the size of 160862306a36Sopenharmony_ci * the ACL and the number of ACEs it contains. The ACL header is followed by 160962306a36Sopenharmony_ci * zero or more access control entries (ACEs). The ACL as well as each ACE 161062306a36Sopenharmony_ci * are aligned on 4-byte boundaries. 161162306a36Sopenharmony_ci */ 161262306a36Sopenharmony_citypedef struct { 161362306a36Sopenharmony_ci u8 revision; /* Revision of this ACL. */ 161462306a36Sopenharmony_ci u8 alignment1; 161562306a36Sopenharmony_ci le16 size; /* Allocated space in bytes for ACL. Includes this 161662306a36Sopenharmony_ci header, the ACEs and the remaining free space. */ 161762306a36Sopenharmony_ci le16 ace_count; /* Number of ACEs in the ACL. */ 161862306a36Sopenharmony_ci le16 alignment2; 161962306a36Sopenharmony_ci/* sizeof() = 8 bytes */ 162062306a36Sopenharmony_ci} __attribute__ ((__packed__)) ACL; 162162306a36Sopenharmony_ci 162262306a36Sopenharmony_ci/* 162362306a36Sopenharmony_ci * Current constants for ACLs. 162462306a36Sopenharmony_ci */ 162562306a36Sopenharmony_citypedef enum { 162662306a36Sopenharmony_ci /* Current revision. */ 162762306a36Sopenharmony_ci ACL_REVISION = 2, 162862306a36Sopenharmony_ci ACL_REVISION_DS = 4, 162962306a36Sopenharmony_ci 163062306a36Sopenharmony_ci /* History of revisions. */ 163162306a36Sopenharmony_ci ACL_REVISION1 = 1, 163262306a36Sopenharmony_ci MIN_ACL_REVISION = 2, 163362306a36Sopenharmony_ci ACL_REVISION2 = 2, 163462306a36Sopenharmony_ci ACL_REVISION3 = 3, 163562306a36Sopenharmony_ci ACL_REVISION4 = 4, 163662306a36Sopenharmony_ci MAX_ACL_REVISION = 4, 163762306a36Sopenharmony_ci} ACL_CONSTANTS; 163862306a36Sopenharmony_ci 163962306a36Sopenharmony_ci/* 164062306a36Sopenharmony_ci * The security descriptor control flags (16-bit). 164162306a36Sopenharmony_ci * 164262306a36Sopenharmony_ci * SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the SID 164362306a36Sopenharmony_ci * pointed to by the Owner field was provided by a defaulting mechanism 164462306a36Sopenharmony_ci * rather than explicitly provided by the original provider of the 164562306a36Sopenharmony_ci * security descriptor. This may affect the treatment of the SID with 164662306a36Sopenharmony_ci * respect to inheritance of an owner. 164762306a36Sopenharmony_ci * 164862306a36Sopenharmony_ci * SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the SID in 164962306a36Sopenharmony_ci * the Group field was provided by a defaulting mechanism rather than 165062306a36Sopenharmony_ci * explicitly provided by the original provider of the security 165162306a36Sopenharmony_ci * descriptor. This may affect the treatment of the SID with respect to 165262306a36Sopenharmony_ci * inheritance of a primary group. 165362306a36Sopenharmony_ci * 165462306a36Sopenharmony_ci * SE_DACL_PRESENT - This boolean flag, when set, indicates that the security 165562306a36Sopenharmony_ci * descriptor contains a discretionary ACL. If this flag is set and the 165662306a36Sopenharmony_ci * Dacl field of the SECURITY_DESCRIPTOR is null, then a null ACL is 165762306a36Sopenharmony_ci * explicitly being specified. 165862306a36Sopenharmony_ci * 165962306a36Sopenharmony_ci * SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the ACL 166062306a36Sopenharmony_ci * pointed to by the Dacl field was provided by a defaulting mechanism 166162306a36Sopenharmony_ci * rather than explicitly provided by the original provider of the 166262306a36Sopenharmony_ci * security descriptor. This may affect the treatment of the ACL with 166362306a36Sopenharmony_ci * respect to inheritance of an ACL. This flag is ignored if the 166462306a36Sopenharmony_ci * DaclPresent flag is not set. 166562306a36Sopenharmony_ci * 166662306a36Sopenharmony_ci * SE_SACL_PRESENT - This boolean flag, when set, indicates that the security 166762306a36Sopenharmony_ci * descriptor contains a system ACL pointed to by the Sacl field. If this 166862306a36Sopenharmony_ci * flag is set and the Sacl field of the SECURITY_DESCRIPTOR is null, then 166962306a36Sopenharmony_ci * an empty (but present) ACL is being specified. 167062306a36Sopenharmony_ci * 167162306a36Sopenharmony_ci * SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the ACL 167262306a36Sopenharmony_ci * pointed to by the Sacl field was provided by a defaulting mechanism 167362306a36Sopenharmony_ci * rather than explicitly provided by the original provider of the 167462306a36Sopenharmony_ci * security descriptor. This may affect the treatment of the ACL with 167562306a36Sopenharmony_ci * respect to inheritance of an ACL. This flag is ignored if the 167662306a36Sopenharmony_ci * SaclPresent flag is not set. 167762306a36Sopenharmony_ci * 167862306a36Sopenharmony_ci * SE_SELF_RELATIVE - This boolean flag, when set, indicates that the security 167962306a36Sopenharmony_ci * descriptor is in self-relative form. In this form, all fields of the 168062306a36Sopenharmony_ci * security descriptor are contiguous in memory and all pointer fields are 168162306a36Sopenharmony_ci * expressed as offsets from the beginning of the security descriptor. 168262306a36Sopenharmony_ci */ 168362306a36Sopenharmony_cienum { 168462306a36Sopenharmony_ci SE_OWNER_DEFAULTED = cpu_to_le16(0x0001), 168562306a36Sopenharmony_ci SE_GROUP_DEFAULTED = cpu_to_le16(0x0002), 168662306a36Sopenharmony_ci SE_DACL_PRESENT = cpu_to_le16(0x0004), 168762306a36Sopenharmony_ci SE_DACL_DEFAULTED = cpu_to_le16(0x0008), 168862306a36Sopenharmony_ci 168962306a36Sopenharmony_ci SE_SACL_PRESENT = cpu_to_le16(0x0010), 169062306a36Sopenharmony_ci SE_SACL_DEFAULTED = cpu_to_le16(0x0020), 169162306a36Sopenharmony_ci 169262306a36Sopenharmony_ci SE_DACL_AUTO_INHERIT_REQ = cpu_to_le16(0x0100), 169362306a36Sopenharmony_ci SE_SACL_AUTO_INHERIT_REQ = cpu_to_le16(0x0200), 169462306a36Sopenharmony_ci SE_DACL_AUTO_INHERITED = cpu_to_le16(0x0400), 169562306a36Sopenharmony_ci SE_SACL_AUTO_INHERITED = cpu_to_le16(0x0800), 169662306a36Sopenharmony_ci 169762306a36Sopenharmony_ci SE_DACL_PROTECTED = cpu_to_le16(0x1000), 169862306a36Sopenharmony_ci SE_SACL_PROTECTED = cpu_to_le16(0x2000), 169962306a36Sopenharmony_ci SE_RM_CONTROL_VALID = cpu_to_le16(0x4000), 170062306a36Sopenharmony_ci SE_SELF_RELATIVE = cpu_to_le16(0x8000) 170162306a36Sopenharmony_ci} __attribute__ ((__packed__)); 170262306a36Sopenharmony_ci 170362306a36Sopenharmony_citypedef le16 SECURITY_DESCRIPTOR_CONTROL; 170462306a36Sopenharmony_ci 170562306a36Sopenharmony_ci/* 170662306a36Sopenharmony_ci * Self-relative security descriptor. Contains the owner and group SIDs as well 170762306a36Sopenharmony_ci * as the sacl and dacl ACLs inside the security descriptor itself. 170862306a36Sopenharmony_ci */ 170962306a36Sopenharmony_citypedef struct { 171062306a36Sopenharmony_ci u8 revision; /* Revision level of the security descriptor. */ 171162306a36Sopenharmony_ci u8 alignment; 171262306a36Sopenharmony_ci SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of 171362306a36Sopenharmony_ci the descriptor as well as the following fields. */ 171462306a36Sopenharmony_ci le32 owner; /* Byte offset to a SID representing an object's 171562306a36Sopenharmony_ci owner. If this is NULL, no owner SID is present in 171662306a36Sopenharmony_ci the descriptor. */ 171762306a36Sopenharmony_ci le32 group; /* Byte offset to a SID representing an object's 171862306a36Sopenharmony_ci primary group. If this is NULL, no primary group 171962306a36Sopenharmony_ci SID is present in the descriptor. */ 172062306a36Sopenharmony_ci le32 sacl; /* Byte offset to a system ACL. Only valid, if 172162306a36Sopenharmony_ci SE_SACL_PRESENT is set in the control field. If 172262306a36Sopenharmony_ci SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL 172362306a36Sopenharmony_ci is specified. */ 172462306a36Sopenharmony_ci le32 dacl; /* Byte offset to a discretionary ACL. Only valid, if 172562306a36Sopenharmony_ci SE_DACL_PRESENT is set in the control field. If 172662306a36Sopenharmony_ci SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL 172762306a36Sopenharmony_ci (unconditionally granting access) is specified. */ 172862306a36Sopenharmony_ci/* sizeof() = 0x14 bytes */ 172962306a36Sopenharmony_ci} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_RELATIVE; 173062306a36Sopenharmony_ci 173162306a36Sopenharmony_ci/* 173262306a36Sopenharmony_ci * Absolute security descriptor. Does not contain the owner and group SIDs, nor 173362306a36Sopenharmony_ci * the sacl and dacl ACLs inside the security descriptor. Instead, it contains 173462306a36Sopenharmony_ci * pointers to these structures in memory. Obviously, absolute security 173562306a36Sopenharmony_ci * descriptors are only useful for in memory representations of security 173662306a36Sopenharmony_ci * descriptors. On disk, a self-relative security descriptor is used. 173762306a36Sopenharmony_ci */ 173862306a36Sopenharmony_citypedef struct { 173962306a36Sopenharmony_ci u8 revision; /* Revision level of the security descriptor. */ 174062306a36Sopenharmony_ci u8 alignment; 174162306a36Sopenharmony_ci SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of 174262306a36Sopenharmony_ci the descriptor as well as the following fields. */ 174362306a36Sopenharmony_ci SID *owner; /* Points to a SID representing an object's owner. If 174462306a36Sopenharmony_ci this is NULL, no owner SID is present in the 174562306a36Sopenharmony_ci descriptor. */ 174662306a36Sopenharmony_ci SID *group; /* Points to a SID representing an object's primary 174762306a36Sopenharmony_ci group. If this is NULL, no primary group SID is 174862306a36Sopenharmony_ci present in the descriptor. */ 174962306a36Sopenharmony_ci ACL *sacl; /* Points to a system ACL. Only valid, if 175062306a36Sopenharmony_ci SE_SACL_PRESENT is set in the control field. If 175162306a36Sopenharmony_ci SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL 175262306a36Sopenharmony_ci is specified. */ 175362306a36Sopenharmony_ci ACL *dacl; /* Points to a discretionary ACL. Only valid, if 175462306a36Sopenharmony_ci SE_DACL_PRESENT is set in the control field. If 175562306a36Sopenharmony_ci SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL 175662306a36Sopenharmony_ci (unconditionally granting access) is specified. */ 175762306a36Sopenharmony_ci} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR; 175862306a36Sopenharmony_ci 175962306a36Sopenharmony_ci/* 176062306a36Sopenharmony_ci * Current constants for security descriptors. 176162306a36Sopenharmony_ci */ 176262306a36Sopenharmony_citypedef enum { 176362306a36Sopenharmony_ci /* Current revision. */ 176462306a36Sopenharmony_ci SECURITY_DESCRIPTOR_REVISION = 1, 176562306a36Sopenharmony_ci SECURITY_DESCRIPTOR_REVISION1 = 1, 176662306a36Sopenharmony_ci 176762306a36Sopenharmony_ci /* The sizes of both the absolute and relative security descriptors is 176862306a36Sopenharmony_ci the same as pointers, at least on ia32 architecture are 32-bit. */ 176962306a36Sopenharmony_ci SECURITY_DESCRIPTOR_MIN_LENGTH = sizeof(SECURITY_DESCRIPTOR), 177062306a36Sopenharmony_ci} SECURITY_DESCRIPTOR_CONSTANTS; 177162306a36Sopenharmony_ci 177262306a36Sopenharmony_ci/* 177362306a36Sopenharmony_ci * Attribute: Security descriptor (0x50). A standard self-relative security 177462306a36Sopenharmony_ci * descriptor. 177562306a36Sopenharmony_ci * 177662306a36Sopenharmony_ci * NOTE: Can be resident or non-resident. 177762306a36Sopenharmony_ci * NOTE: Not used in NTFS 3.0+, as security descriptors are stored centrally 177862306a36Sopenharmony_ci * in FILE_Secure and the correct descriptor is found using the security_id 177962306a36Sopenharmony_ci * from the standard information attribute. 178062306a36Sopenharmony_ci */ 178162306a36Sopenharmony_citypedef SECURITY_DESCRIPTOR_RELATIVE SECURITY_DESCRIPTOR_ATTR; 178262306a36Sopenharmony_ci 178362306a36Sopenharmony_ci/* 178462306a36Sopenharmony_ci * On NTFS 3.0+, all security descriptors are stored in FILE_Secure. Only one 178562306a36Sopenharmony_ci * referenced instance of each unique security descriptor is stored. 178662306a36Sopenharmony_ci * 178762306a36Sopenharmony_ci * FILE_Secure contains no unnamed data attribute, i.e. it has zero length. It 178862306a36Sopenharmony_ci * does, however, contain two indexes ($SDH and $SII) as well as a named data 178962306a36Sopenharmony_ci * stream ($SDS). 179062306a36Sopenharmony_ci * 179162306a36Sopenharmony_ci * Every unique security descriptor is assigned a unique security identifier 179262306a36Sopenharmony_ci * (security_id, not to be confused with a SID). The security_id is unique for 179362306a36Sopenharmony_ci * the NTFS volume and is used as an index into the $SII index, which maps 179462306a36Sopenharmony_ci * security_ids to the security descriptor's storage location within the $SDS 179562306a36Sopenharmony_ci * data attribute. The $SII index is sorted by ascending security_id. 179662306a36Sopenharmony_ci * 179762306a36Sopenharmony_ci * A simple hash is computed from each security descriptor. This hash is used 179862306a36Sopenharmony_ci * as an index into the $SDH index, which maps security descriptor hashes to 179962306a36Sopenharmony_ci * the security descriptor's storage location within the $SDS data attribute. 180062306a36Sopenharmony_ci * The $SDH index is sorted by security descriptor hash and is stored in a B+ 180162306a36Sopenharmony_ci * tree. When searching $SDH (with the intent of determining whether or not a 180262306a36Sopenharmony_ci * new security descriptor is already present in the $SDS data stream), if a 180362306a36Sopenharmony_ci * matching hash is found, but the security descriptors do not match, the 180462306a36Sopenharmony_ci * search in the $SDH index is continued, searching for a next matching hash. 180562306a36Sopenharmony_ci * 180662306a36Sopenharmony_ci * When a precise match is found, the security_id coresponding to the security 180762306a36Sopenharmony_ci * descriptor in the $SDS attribute is read from the found $SDH index entry and 180862306a36Sopenharmony_ci * is stored in the $STANDARD_INFORMATION attribute of the file/directory to 180962306a36Sopenharmony_ci * which the security descriptor is being applied. The $STANDARD_INFORMATION 181062306a36Sopenharmony_ci * attribute is present in all base mft records (i.e. in all files and 181162306a36Sopenharmony_ci * directories). 181262306a36Sopenharmony_ci * 181362306a36Sopenharmony_ci * If a match is not found, the security descriptor is assigned a new unique 181462306a36Sopenharmony_ci * security_id and is added to the $SDS data attribute. Then, entries 181562306a36Sopenharmony_ci * referencing the this security descriptor in the $SDS data attribute are 181662306a36Sopenharmony_ci * added to the $SDH and $SII indexes. 181762306a36Sopenharmony_ci * 181862306a36Sopenharmony_ci * Note: Entries are never deleted from FILE_Secure, even if nothing 181962306a36Sopenharmony_ci * references an entry any more. 182062306a36Sopenharmony_ci */ 182162306a36Sopenharmony_ci 182262306a36Sopenharmony_ci/* 182362306a36Sopenharmony_ci * This header precedes each security descriptor in the $SDS data stream. 182462306a36Sopenharmony_ci * This is also the index entry data part of both the $SII and $SDH indexes. 182562306a36Sopenharmony_ci */ 182662306a36Sopenharmony_citypedef struct { 182762306a36Sopenharmony_ci le32 hash; /* Hash of the security descriptor. */ 182862306a36Sopenharmony_ci le32 security_id; /* The security_id assigned to the descriptor. */ 182962306a36Sopenharmony_ci le64 offset; /* Byte offset of this entry in the $SDS stream. */ 183062306a36Sopenharmony_ci le32 length; /* Size in bytes of this entry in $SDS stream. */ 183162306a36Sopenharmony_ci} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_HEADER; 183262306a36Sopenharmony_ci 183362306a36Sopenharmony_ci/* 183462306a36Sopenharmony_ci * The $SDS data stream contains the security descriptors, aligned on 16-byte 183562306a36Sopenharmony_ci * boundaries, sorted by security_id in a B+ tree. Security descriptors cannot 183662306a36Sopenharmony_ci * cross 256kib boundaries (this restriction is imposed by the Windows cache 183762306a36Sopenharmony_ci * manager). Each security descriptor is contained in a SDS_ENTRY structure. 183862306a36Sopenharmony_ci * Also, each security descriptor is stored twice in the $SDS stream with a 183962306a36Sopenharmony_ci * fixed offset of 0x40000 bytes (256kib, the Windows cache manager's max size) 184062306a36Sopenharmony_ci * between them; i.e. if a SDS_ENTRY specifies an offset of 0x51d0, then the 184162306a36Sopenharmony_ci * first copy of the security descriptor will be at offset 0x51d0 in the 184262306a36Sopenharmony_ci * $SDS data stream and the second copy will be at offset 0x451d0. 184362306a36Sopenharmony_ci */ 184462306a36Sopenharmony_citypedef struct { 184562306a36Sopenharmony_ci/*Ofs*/ 184662306a36Sopenharmony_ci/* 0 SECURITY_DESCRIPTOR_HEADER; -- Unfolded here as gcc doesn't like 184762306a36Sopenharmony_ci unnamed structs. */ 184862306a36Sopenharmony_ci le32 hash; /* Hash of the security descriptor. */ 184962306a36Sopenharmony_ci le32 security_id; /* The security_id assigned to the descriptor. */ 185062306a36Sopenharmony_ci le64 offset; /* Byte offset of this entry in the $SDS stream. */ 185162306a36Sopenharmony_ci le32 length; /* Size in bytes of this entry in $SDS stream. */ 185262306a36Sopenharmony_ci/* 20*/ SECURITY_DESCRIPTOR_RELATIVE sid; /* The self-relative security 185362306a36Sopenharmony_ci descriptor. */ 185462306a36Sopenharmony_ci} __attribute__ ((__packed__)) SDS_ENTRY; 185562306a36Sopenharmony_ci 185662306a36Sopenharmony_ci/* 185762306a36Sopenharmony_ci * The index entry key used in the $SII index. The collation type is 185862306a36Sopenharmony_ci * COLLATION_NTOFS_ULONG. 185962306a36Sopenharmony_ci */ 186062306a36Sopenharmony_citypedef struct { 186162306a36Sopenharmony_ci le32 security_id; /* The security_id assigned to the descriptor. */ 186262306a36Sopenharmony_ci} __attribute__ ((__packed__)) SII_INDEX_KEY; 186362306a36Sopenharmony_ci 186462306a36Sopenharmony_ci/* 186562306a36Sopenharmony_ci * The index entry key used in the $SDH index. The keys are sorted first by 186662306a36Sopenharmony_ci * hash and then by security_id. The collation rule is 186762306a36Sopenharmony_ci * COLLATION_NTOFS_SECURITY_HASH. 186862306a36Sopenharmony_ci */ 186962306a36Sopenharmony_citypedef struct { 187062306a36Sopenharmony_ci le32 hash; /* Hash of the security descriptor. */ 187162306a36Sopenharmony_ci le32 security_id; /* The security_id assigned to the descriptor. */ 187262306a36Sopenharmony_ci} __attribute__ ((__packed__)) SDH_INDEX_KEY; 187362306a36Sopenharmony_ci 187462306a36Sopenharmony_ci/* 187562306a36Sopenharmony_ci * Attribute: Volume name (0x60). 187662306a36Sopenharmony_ci * 187762306a36Sopenharmony_ci * NOTE: Always resident. 187862306a36Sopenharmony_ci * NOTE: Present only in FILE_Volume. 187962306a36Sopenharmony_ci */ 188062306a36Sopenharmony_citypedef struct { 188162306a36Sopenharmony_ci ntfschar name[0]; /* The name of the volume in Unicode. */ 188262306a36Sopenharmony_ci} __attribute__ ((__packed__)) VOLUME_NAME; 188362306a36Sopenharmony_ci 188462306a36Sopenharmony_ci/* 188562306a36Sopenharmony_ci * Possible flags for the volume (16-bit). 188662306a36Sopenharmony_ci */ 188762306a36Sopenharmony_cienum { 188862306a36Sopenharmony_ci VOLUME_IS_DIRTY = cpu_to_le16(0x0001), 188962306a36Sopenharmony_ci VOLUME_RESIZE_LOG_FILE = cpu_to_le16(0x0002), 189062306a36Sopenharmony_ci VOLUME_UPGRADE_ON_MOUNT = cpu_to_le16(0x0004), 189162306a36Sopenharmony_ci VOLUME_MOUNTED_ON_NT4 = cpu_to_le16(0x0008), 189262306a36Sopenharmony_ci 189362306a36Sopenharmony_ci VOLUME_DELETE_USN_UNDERWAY = cpu_to_le16(0x0010), 189462306a36Sopenharmony_ci VOLUME_REPAIR_OBJECT_ID = cpu_to_le16(0x0020), 189562306a36Sopenharmony_ci 189662306a36Sopenharmony_ci VOLUME_CHKDSK_UNDERWAY = cpu_to_le16(0x4000), 189762306a36Sopenharmony_ci VOLUME_MODIFIED_BY_CHKDSK = cpu_to_le16(0x8000), 189862306a36Sopenharmony_ci 189962306a36Sopenharmony_ci VOLUME_FLAGS_MASK = cpu_to_le16(0xc03f), 190062306a36Sopenharmony_ci 190162306a36Sopenharmony_ci /* To make our life easier when checking if we must mount read-only. */ 190262306a36Sopenharmony_ci VOLUME_MUST_MOUNT_RO_MASK = cpu_to_le16(0xc027), 190362306a36Sopenharmony_ci} __attribute__ ((__packed__)); 190462306a36Sopenharmony_ci 190562306a36Sopenharmony_citypedef le16 VOLUME_FLAGS; 190662306a36Sopenharmony_ci 190762306a36Sopenharmony_ci/* 190862306a36Sopenharmony_ci * Attribute: Volume information (0x70). 190962306a36Sopenharmony_ci * 191062306a36Sopenharmony_ci * NOTE: Always resident. 191162306a36Sopenharmony_ci * NOTE: Present only in FILE_Volume. 191262306a36Sopenharmony_ci * NOTE: Windows 2000 uses NTFS 3.0 while Windows NT4 service pack 6a uses 191362306a36Sopenharmony_ci * NTFS 1.2. I haven't personally seen other values yet. 191462306a36Sopenharmony_ci */ 191562306a36Sopenharmony_citypedef struct { 191662306a36Sopenharmony_ci le64 reserved; /* Not used (yet?). */ 191762306a36Sopenharmony_ci u8 major_ver; /* Major version of the ntfs format. */ 191862306a36Sopenharmony_ci u8 minor_ver; /* Minor version of the ntfs format. */ 191962306a36Sopenharmony_ci VOLUME_FLAGS flags; /* Bit array of VOLUME_* flags. */ 192062306a36Sopenharmony_ci} __attribute__ ((__packed__)) VOLUME_INFORMATION; 192162306a36Sopenharmony_ci 192262306a36Sopenharmony_ci/* 192362306a36Sopenharmony_ci * Attribute: Data attribute (0x80). 192462306a36Sopenharmony_ci * 192562306a36Sopenharmony_ci * NOTE: Can be resident or non-resident. 192662306a36Sopenharmony_ci * 192762306a36Sopenharmony_ci * Data contents of a file (i.e. the unnamed stream) or of a named stream. 192862306a36Sopenharmony_ci */ 192962306a36Sopenharmony_citypedef struct { 193062306a36Sopenharmony_ci u8 data[0]; /* The file's data contents. */ 193162306a36Sopenharmony_ci} __attribute__ ((__packed__)) DATA_ATTR; 193262306a36Sopenharmony_ci 193362306a36Sopenharmony_ci/* 193462306a36Sopenharmony_ci * Index header flags (8-bit). 193562306a36Sopenharmony_ci */ 193662306a36Sopenharmony_cienum { 193762306a36Sopenharmony_ci /* 193862306a36Sopenharmony_ci * When index header is in an index root attribute: 193962306a36Sopenharmony_ci */ 194062306a36Sopenharmony_ci SMALL_INDEX = 0, /* The index is small enough to fit inside the index 194162306a36Sopenharmony_ci root attribute and there is no index allocation 194262306a36Sopenharmony_ci attribute present. */ 194362306a36Sopenharmony_ci LARGE_INDEX = 1, /* The index is too large to fit in the index root 194462306a36Sopenharmony_ci attribute and/or an index allocation attribute is 194562306a36Sopenharmony_ci present. */ 194662306a36Sopenharmony_ci /* 194762306a36Sopenharmony_ci * When index header is in an index block, i.e. is part of index 194862306a36Sopenharmony_ci * allocation attribute: 194962306a36Sopenharmony_ci */ 195062306a36Sopenharmony_ci LEAF_NODE = 0, /* This is a leaf node, i.e. there are no more nodes 195162306a36Sopenharmony_ci branching off it. */ 195262306a36Sopenharmony_ci INDEX_NODE = 1, /* This node indexes other nodes, i.e. it is not a leaf 195362306a36Sopenharmony_ci node. */ 195462306a36Sopenharmony_ci NODE_MASK = 1, /* Mask for accessing the *_NODE bits. */ 195562306a36Sopenharmony_ci} __attribute__ ((__packed__)); 195662306a36Sopenharmony_ci 195762306a36Sopenharmony_citypedef u8 INDEX_HEADER_FLAGS; 195862306a36Sopenharmony_ci 195962306a36Sopenharmony_ci/* 196062306a36Sopenharmony_ci * This is the header for indexes, describing the INDEX_ENTRY records, which 196162306a36Sopenharmony_ci * follow the INDEX_HEADER. Together the index header and the index entries 196262306a36Sopenharmony_ci * make up a complete index. 196362306a36Sopenharmony_ci * 196462306a36Sopenharmony_ci * IMPORTANT NOTE: The offset, length and size structure members are counted 196562306a36Sopenharmony_ci * relative to the start of the index header structure and not relative to the 196662306a36Sopenharmony_ci * start of the index root or index allocation structures themselves. 196762306a36Sopenharmony_ci */ 196862306a36Sopenharmony_citypedef struct { 196962306a36Sopenharmony_ci le32 entries_offset; /* Byte offset to first INDEX_ENTRY 197062306a36Sopenharmony_ci aligned to 8-byte boundary. */ 197162306a36Sopenharmony_ci le32 index_length; /* Data size of the index in bytes, 197262306a36Sopenharmony_ci i.e. bytes used from allocated 197362306a36Sopenharmony_ci size, aligned to 8-byte boundary. */ 197462306a36Sopenharmony_ci le32 allocated_size; /* Byte size of this index (block), 197562306a36Sopenharmony_ci multiple of 8 bytes. */ 197662306a36Sopenharmony_ci /* NOTE: For the index root attribute, the above two numbers are always 197762306a36Sopenharmony_ci equal, as the attribute is resident and it is resized as needed. In 197862306a36Sopenharmony_ci the case of the index allocation attribute the attribute is not 197962306a36Sopenharmony_ci resident and hence the allocated_size is a fixed value and must 198062306a36Sopenharmony_ci equal the index_block_size specified by the INDEX_ROOT attribute 198162306a36Sopenharmony_ci corresponding to the INDEX_ALLOCATION attribute this INDEX_BLOCK 198262306a36Sopenharmony_ci belongs to. */ 198362306a36Sopenharmony_ci INDEX_HEADER_FLAGS flags; /* Bit field of INDEX_HEADER_FLAGS. */ 198462306a36Sopenharmony_ci u8 reserved[3]; /* Reserved/align to 8-byte boundary. */ 198562306a36Sopenharmony_ci} __attribute__ ((__packed__)) INDEX_HEADER; 198662306a36Sopenharmony_ci 198762306a36Sopenharmony_ci/* 198862306a36Sopenharmony_ci * Attribute: Index root (0x90). 198962306a36Sopenharmony_ci * 199062306a36Sopenharmony_ci * NOTE: Always resident. 199162306a36Sopenharmony_ci * 199262306a36Sopenharmony_ci * This is followed by a sequence of index entries (INDEX_ENTRY structures) 199362306a36Sopenharmony_ci * as described by the index header. 199462306a36Sopenharmony_ci * 199562306a36Sopenharmony_ci * When a directory is small enough to fit inside the index root then this 199662306a36Sopenharmony_ci * is the only attribute describing the directory. When the directory is too 199762306a36Sopenharmony_ci * large to fit in the index root, on the other hand, two additional attributes 199862306a36Sopenharmony_ci * are present: an index allocation attribute, containing sub-nodes of the B+ 199962306a36Sopenharmony_ci * directory tree (see below), and a bitmap attribute, describing which virtual 200062306a36Sopenharmony_ci * cluster numbers (vcns) in the index allocation attribute are in use by an 200162306a36Sopenharmony_ci * index block. 200262306a36Sopenharmony_ci * 200362306a36Sopenharmony_ci * NOTE: The root directory (FILE_root) contains an entry for itself. Other 200462306a36Sopenharmony_ci * directories do not contain entries for themselves, though. 200562306a36Sopenharmony_ci */ 200662306a36Sopenharmony_citypedef struct { 200762306a36Sopenharmony_ci ATTR_TYPE type; /* Type of the indexed attribute. Is 200862306a36Sopenharmony_ci $FILE_NAME for directories, zero 200962306a36Sopenharmony_ci for view indexes. No other values 201062306a36Sopenharmony_ci allowed. */ 201162306a36Sopenharmony_ci COLLATION_RULE collation_rule; /* Collation rule used to sort the 201262306a36Sopenharmony_ci index entries. If type is $FILE_NAME, 201362306a36Sopenharmony_ci this must be COLLATION_FILE_NAME. */ 201462306a36Sopenharmony_ci le32 index_block_size; /* Size of each index block in bytes (in 201562306a36Sopenharmony_ci the index allocation attribute). */ 201662306a36Sopenharmony_ci u8 clusters_per_index_block; /* Cluster size of each index block (in 201762306a36Sopenharmony_ci the index allocation attribute), when 201862306a36Sopenharmony_ci an index block is >= than a cluster, 201962306a36Sopenharmony_ci otherwise this will be the log of 202062306a36Sopenharmony_ci the size (like how the encoding of 202162306a36Sopenharmony_ci the mft record size and the index 202262306a36Sopenharmony_ci record size found in the boot sector 202362306a36Sopenharmony_ci work). Has to be a power of 2. */ 202462306a36Sopenharmony_ci u8 reserved[3]; /* Reserved/align to 8-byte boundary. */ 202562306a36Sopenharmony_ci INDEX_HEADER index; /* Index header describing the 202662306a36Sopenharmony_ci following index entries. */ 202762306a36Sopenharmony_ci} __attribute__ ((__packed__)) INDEX_ROOT; 202862306a36Sopenharmony_ci 202962306a36Sopenharmony_ci/* 203062306a36Sopenharmony_ci * Attribute: Index allocation (0xa0). 203162306a36Sopenharmony_ci * 203262306a36Sopenharmony_ci * NOTE: Always non-resident (doesn't make sense to be resident anyway!). 203362306a36Sopenharmony_ci * 203462306a36Sopenharmony_ci * This is an array of index blocks. Each index block starts with an 203562306a36Sopenharmony_ci * INDEX_BLOCK structure containing an index header, followed by a sequence of 203662306a36Sopenharmony_ci * index entries (INDEX_ENTRY structures), as described by the INDEX_HEADER. 203762306a36Sopenharmony_ci */ 203862306a36Sopenharmony_citypedef struct { 203962306a36Sopenharmony_ci/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ 204062306a36Sopenharmony_ci NTFS_RECORD_TYPE magic; /* Magic is "INDX". */ 204162306a36Sopenharmony_ci le16 usa_ofs; /* See NTFS_RECORD definition. */ 204262306a36Sopenharmony_ci le16 usa_count; /* See NTFS_RECORD definition. */ 204362306a36Sopenharmony_ci 204462306a36Sopenharmony_ci/* 8*/ sle64 lsn; /* $LogFile sequence number of the last 204562306a36Sopenharmony_ci modification of this index block. */ 204662306a36Sopenharmony_ci/* 16*/ leVCN index_block_vcn; /* Virtual cluster number of the index block. 204762306a36Sopenharmony_ci If the cluster_size on the volume is <= the 204862306a36Sopenharmony_ci index_block_size of the directory, 204962306a36Sopenharmony_ci index_block_vcn counts in units of clusters, 205062306a36Sopenharmony_ci and in units of sectors otherwise. */ 205162306a36Sopenharmony_ci/* 24*/ INDEX_HEADER index; /* Describes the following index entries. */ 205262306a36Sopenharmony_ci/* sizeof()= 40 (0x28) bytes */ 205362306a36Sopenharmony_ci/* 205462306a36Sopenharmony_ci * When creating the index block, we place the update sequence array at this 205562306a36Sopenharmony_ci * offset, i.e. before we start with the index entries. This also makes sense, 205662306a36Sopenharmony_ci * otherwise we could run into problems with the update sequence array 205762306a36Sopenharmony_ci * containing in itself the last two bytes of a sector which would mean that 205862306a36Sopenharmony_ci * multi sector transfer protection wouldn't work. As you can't protect data 205962306a36Sopenharmony_ci * by overwriting it since you then can't get it back... 206062306a36Sopenharmony_ci * When reading use the data from the ntfs record header. 206162306a36Sopenharmony_ci */ 206262306a36Sopenharmony_ci} __attribute__ ((__packed__)) INDEX_BLOCK; 206362306a36Sopenharmony_ci 206462306a36Sopenharmony_citypedef INDEX_BLOCK INDEX_ALLOCATION; 206562306a36Sopenharmony_ci 206662306a36Sopenharmony_ci/* 206762306a36Sopenharmony_ci * The system file FILE_Extend/$Reparse contains an index named $R listing 206862306a36Sopenharmony_ci * all reparse points on the volume. The index entry keys are as defined 206962306a36Sopenharmony_ci * below. Note, that there is no index data associated with the index entries. 207062306a36Sopenharmony_ci * 207162306a36Sopenharmony_ci * The index entries are sorted by the index key file_id. The collation rule is 207262306a36Sopenharmony_ci * COLLATION_NTOFS_ULONGS. FIXME: Verify whether the reparse_tag is not the 207362306a36Sopenharmony_ci * primary key / is not a key at all. (AIA) 207462306a36Sopenharmony_ci */ 207562306a36Sopenharmony_citypedef struct { 207662306a36Sopenharmony_ci le32 reparse_tag; /* Reparse point type (inc. flags). */ 207762306a36Sopenharmony_ci leMFT_REF file_id; /* Mft record of the file containing the 207862306a36Sopenharmony_ci reparse point attribute. */ 207962306a36Sopenharmony_ci} __attribute__ ((__packed__)) REPARSE_INDEX_KEY; 208062306a36Sopenharmony_ci 208162306a36Sopenharmony_ci/* 208262306a36Sopenharmony_ci * Quota flags (32-bit). 208362306a36Sopenharmony_ci * 208462306a36Sopenharmony_ci * The user quota flags. Names explain meaning. 208562306a36Sopenharmony_ci */ 208662306a36Sopenharmony_cienum { 208762306a36Sopenharmony_ci QUOTA_FLAG_DEFAULT_LIMITS = cpu_to_le32(0x00000001), 208862306a36Sopenharmony_ci QUOTA_FLAG_LIMIT_REACHED = cpu_to_le32(0x00000002), 208962306a36Sopenharmony_ci QUOTA_FLAG_ID_DELETED = cpu_to_le32(0x00000004), 209062306a36Sopenharmony_ci 209162306a36Sopenharmony_ci QUOTA_FLAG_USER_MASK = cpu_to_le32(0x00000007), 209262306a36Sopenharmony_ci /* This is a bit mask for the user quota flags. */ 209362306a36Sopenharmony_ci 209462306a36Sopenharmony_ci /* 209562306a36Sopenharmony_ci * These flags are only present in the quota defaults index entry, i.e. 209662306a36Sopenharmony_ci * in the entry where owner_id = QUOTA_DEFAULTS_ID. 209762306a36Sopenharmony_ci */ 209862306a36Sopenharmony_ci QUOTA_FLAG_TRACKING_ENABLED = cpu_to_le32(0x00000010), 209962306a36Sopenharmony_ci QUOTA_FLAG_ENFORCEMENT_ENABLED = cpu_to_le32(0x00000020), 210062306a36Sopenharmony_ci QUOTA_FLAG_TRACKING_REQUESTED = cpu_to_le32(0x00000040), 210162306a36Sopenharmony_ci QUOTA_FLAG_LOG_THRESHOLD = cpu_to_le32(0x00000080), 210262306a36Sopenharmony_ci 210362306a36Sopenharmony_ci QUOTA_FLAG_LOG_LIMIT = cpu_to_le32(0x00000100), 210462306a36Sopenharmony_ci QUOTA_FLAG_OUT_OF_DATE = cpu_to_le32(0x00000200), 210562306a36Sopenharmony_ci QUOTA_FLAG_CORRUPT = cpu_to_le32(0x00000400), 210662306a36Sopenharmony_ci QUOTA_FLAG_PENDING_DELETES = cpu_to_le32(0x00000800), 210762306a36Sopenharmony_ci}; 210862306a36Sopenharmony_ci 210962306a36Sopenharmony_citypedef le32 QUOTA_FLAGS; 211062306a36Sopenharmony_ci 211162306a36Sopenharmony_ci/* 211262306a36Sopenharmony_ci * The system file FILE_Extend/$Quota contains two indexes $O and $Q. Quotas 211362306a36Sopenharmony_ci * are on a per volume and per user basis. 211462306a36Sopenharmony_ci * 211562306a36Sopenharmony_ci * The $Q index contains one entry for each existing user_id on the volume. The 211662306a36Sopenharmony_ci * index key is the user_id of the user/group owning this quota control entry, 211762306a36Sopenharmony_ci * i.e. the key is the owner_id. The user_id of the owner of a file, i.e. the 211862306a36Sopenharmony_ci * owner_id, is found in the standard information attribute. The collation rule 211962306a36Sopenharmony_ci * for $Q is COLLATION_NTOFS_ULONG. 212062306a36Sopenharmony_ci * 212162306a36Sopenharmony_ci * The $O index contains one entry for each user/group who has been assigned 212262306a36Sopenharmony_ci * a quota on that volume. The index key holds the SID of the user_id the 212362306a36Sopenharmony_ci * entry belongs to, i.e. the owner_id. The collation rule for $O is 212462306a36Sopenharmony_ci * COLLATION_NTOFS_SID. 212562306a36Sopenharmony_ci * 212662306a36Sopenharmony_ci * The $O index entry data is the user_id of the user corresponding to the SID. 212762306a36Sopenharmony_ci * This user_id is used as an index into $Q to find the quota control entry 212862306a36Sopenharmony_ci * associated with the SID. 212962306a36Sopenharmony_ci * 213062306a36Sopenharmony_ci * The $Q index entry data is the quota control entry and is defined below. 213162306a36Sopenharmony_ci */ 213262306a36Sopenharmony_citypedef struct { 213362306a36Sopenharmony_ci le32 version; /* Currently equals 2. */ 213462306a36Sopenharmony_ci QUOTA_FLAGS flags; /* Flags describing this quota entry. */ 213562306a36Sopenharmony_ci le64 bytes_used; /* How many bytes of the quota are in use. */ 213662306a36Sopenharmony_ci sle64 change_time; /* Last time this quota entry was changed. */ 213762306a36Sopenharmony_ci sle64 threshold; /* Soft quota (-1 if not limited). */ 213862306a36Sopenharmony_ci sle64 limit; /* Hard quota (-1 if not limited). */ 213962306a36Sopenharmony_ci sle64 exceeded_time; /* How long the soft quota has been exceeded. */ 214062306a36Sopenharmony_ci SID sid; /* The SID of the user/object associated with 214162306a36Sopenharmony_ci this quota entry. Equals zero for the quota 214262306a36Sopenharmony_ci defaults entry (and in fact on a WinXP 214362306a36Sopenharmony_ci volume, it is not present at all). */ 214462306a36Sopenharmony_ci} __attribute__ ((__packed__)) QUOTA_CONTROL_ENTRY; 214562306a36Sopenharmony_ci 214662306a36Sopenharmony_ci/* 214762306a36Sopenharmony_ci * Predefined owner_id values (32-bit). 214862306a36Sopenharmony_ci */ 214962306a36Sopenharmony_cienum { 215062306a36Sopenharmony_ci QUOTA_INVALID_ID = cpu_to_le32(0x00000000), 215162306a36Sopenharmony_ci QUOTA_DEFAULTS_ID = cpu_to_le32(0x00000001), 215262306a36Sopenharmony_ci QUOTA_FIRST_USER_ID = cpu_to_le32(0x00000100), 215362306a36Sopenharmony_ci}; 215462306a36Sopenharmony_ci 215562306a36Sopenharmony_ci/* 215662306a36Sopenharmony_ci * Current constants for quota control entries. 215762306a36Sopenharmony_ci */ 215862306a36Sopenharmony_citypedef enum { 215962306a36Sopenharmony_ci /* Current version. */ 216062306a36Sopenharmony_ci QUOTA_VERSION = 2, 216162306a36Sopenharmony_ci} QUOTA_CONTROL_ENTRY_CONSTANTS; 216262306a36Sopenharmony_ci 216362306a36Sopenharmony_ci/* 216462306a36Sopenharmony_ci * Index entry flags (16-bit). 216562306a36Sopenharmony_ci */ 216662306a36Sopenharmony_cienum { 216762306a36Sopenharmony_ci INDEX_ENTRY_NODE = cpu_to_le16(1), /* This entry contains a 216862306a36Sopenharmony_ci sub-node, i.e. a reference to an index block in form of 216962306a36Sopenharmony_ci a virtual cluster number (see below). */ 217062306a36Sopenharmony_ci INDEX_ENTRY_END = cpu_to_le16(2), /* This signifies the last 217162306a36Sopenharmony_ci entry in an index block. The index entry does not 217262306a36Sopenharmony_ci represent a file but it can point to a sub-node. */ 217362306a36Sopenharmony_ci 217462306a36Sopenharmony_ci INDEX_ENTRY_SPACE_FILLER = cpu_to_le16(0xffff), /* gcc: Force 217562306a36Sopenharmony_ci enum bit width to 16-bit. */ 217662306a36Sopenharmony_ci} __attribute__ ((__packed__)); 217762306a36Sopenharmony_ci 217862306a36Sopenharmony_citypedef le16 INDEX_ENTRY_FLAGS; 217962306a36Sopenharmony_ci 218062306a36Sopenharmony_ci/* 218162306a36Sopenharmony_ci * This the index entry header (see below). 218262306a36Sopenharmony_ci */ 218362306a36Sopenharmony_citypedef struct { 218462306a36Sopenharmony_ci/* 0*/ union { 218562306a36Sopenharmony_ci struct { /* Only valid when INDEX_ENTRY_END is not set. */ 218662306a36Sopenharmony_ci leMFT_REF indexed_file; /* The mft reference of the file 218762306a36Sopenharmony_ci described by this index 218862306a36Sopenharmony_ci entry. Used for directory 218962306a36Sopenharmony_ci indexes. */ 219062306a36Sopenharmony_ci } __attribute__ ((__packed__)) dir; 219162306a36Sopenharmony_ci struct { /* Used for views/indexes to find the entry's data. */ 219262306a36Sopenharmony_ci le16 data_offset; /* Data byte offset from this 219362306a36Sopenharmony_ci INDEX_ENTRY. Follows the 219462306a36Sopenharmony_ci index key. */ 219562306a36Sopenharmony_ci le16 data_length; /* Data length in bytes. */ 219662306a36Sopenharmony_ci le32 reservedV; /* Reserved (zero). */ 219762306a36Sopenharmony_ci } __attribute__ ((__packed__)) vi; 219862306a36Sopenharmony_ci } __attribute__ ((__packed__)) data; 219962306a36Sopenharmony_ci/* 8*/ le16 length; /* Byte size of this index entry, multiple of 220062306a36Sopenharmony_ci 8-bytes. */ 220162306a36Sopenharmony_ci/* 10*/ le16 key_length; /* Byte size of the key value, which is in the 220262306a36Sopenharmony_ci index entry. It follows field reserved. Not 220362306a36Sopenharmony_ci multiple of 8-bytes. */ 220462306a36Sopenharmony_ci/* 12*/ INDEX_ENTRY_FLAGS flags; /* Bit field of INDEX_ENTRY_* flags. */ 220562306a36Sopenharmony_ci/* 14*/ le16 reserved; /* Reserved/align to 8-byte boundary. */ 220662306a36Sopenharmony_ci/* sizeof() = 16 bytes */ 220762306a36Sopenharmony_ci} __attribute__ ((__packed__)) INDEX_ENTRY_HEADER; 220862306a36Sopenharmony_ci 220962306a36Sopenharmony_ci/* 221062306a36Sopenharmony_ci * This is an index entry. A sequence of such entries follows each INDEX_HEADER 221162306a36Sopenharmony_ci * structure. Together they make up a complete index. The index follows either 221262306a36Sopenharmony_ci * an index root attribute or an index allocation attribute. 221362306a36Sopenharmony_ci * 221462306a36Sopenharmony_ci * NOTE: Before NTFS 3.0 only filename attributes were indexed. 221562306a36Sopenharmony_ci */ 221662306a36Sopenharmony_citypedef struct { 221762306a36Sopenharmony_ci/*Ofs*/ 221862306a36Sopenharmony_ci/* 0 INDEX_ENTRY_HEADER; -- Unfolded here as gcc dislikes unnamed structs. */ 221962306a36Sopenharmony_ci union { 222062306a36Sopenharmony_ci struct { /* Only valid when INDEX_ENTRY_END is not set. */ 222162306a36Sopenharmony_ci leMFT_REF indexed_file; /* The mft reference of the file 222262306a36Sopenharmony_ci described by this index 222362306a36Sopenharmony_ci entry. Used for directory 222462306a36Sopenharmony_ci indexes. */ 222562306a36Sopenharmony_ci } __attribute__ ((__packed__)) dir; 222662306a36Sopenharmony_ci struct { /* Used for views/indexes to find the entry's data. */ 222762306a36Sopenharmony_ci le16 data_offset; /* Data byte offset from this 222862306a36Sopenharmony_ci INDEX_ENTRY. Follows the 222962306a36Sopenharmony_ci index key. */ 223062306a36Sopenharmony_ci le16 data_length; /* Data length in bytes. */ 223162306a36Sopenharmony_ci le32 reservedV; /* Reserved (zero). */ 223262306a36Sopenharmony_ci } __attribute__ ((__packed__)) vi; 223362306a36Sopenharmony_ci } __attribute__ ((__packed__)) data; 223462306a36Sopenharmony_ci le16 length; /* Byte size of this index entry, multiple of 223562306a36Sopenharmony_ci 8-bytes. */ 223662306a36Sopenharmony_ci le16 key_length; /* Byte size of the key value, which is in the 223762306a36Sopenharmony_ci index entry. It follows field reserved. Not 223862306a36Sopenharmony_ci multiple of 8-bytes. */ 223962306a36Sopenharmony_ci INDEX_ENTRY_FLAGS flags; /* Bit field of INDEX_ENTRY_* flags. */ 224062306a36Sopenharmony_ci le16 reserved; /* Reserved/align to 8-byte boundary. */ 224162306a36Sopenharmony_ci 224262306a36Sopenharmony_ci/* 16*/ union { /* The key of the indexed attribute. NOTE: Only present 224362306a36Sopenharmony_ci if INDEX_ENTRY_END bit in flags is not set. NOTE: On 224462306a36Sopenharmony_ci NTFS versions before 3.0 the only valid key is the 224562306a36Sopenharmony_ci FILE_NAME_ATTR. On NTFS 3.0+ the following 224662306a36Sopenharmony_ci additional index keys are defined: */ 224762306a36Sopenharmony_ci FILE_NAME_ATTR file_name;/* $I30 index in directories. */ 224862306a36Sopenharmony_ci SII_INDEX_KEY sii; /* $SII index in $Secure. */ 224962306a36Sopenharmony_ci SDH_INDEX_KEY sdh; /* $SDH index in $Secure. */ 225062306a36Sopenharmony_ci GUID object_id; /* $O index in FILE_Extend/$ObjId: The 225162306a36Sopenharmony_ci object_id of the mft record found in 225262306a36Sopenharmony_ci the data part of the index. */ 225362306a36Sopenharmony_ci REPARSE_INDEX_KEY reparse; /* $R index in 225462306a36Sopenharmony_ci FILE_Extend/$Reparse. */ 225562306a36Sopenharmony_ci SID sid; /* $O index in FILE_Extend/$Quota: 225662306a36Sopenharmony_ci SID of the owner of the user_id. */ 225762306a36Sopenharmony_ci le32 owner_id; /* $Q index in FILE_Extend/$Quota: 225862306a36Sopenharmony_ci user_id of the owner of the quota 225962306a36Sopenharmony_ci control entry in the data part of 226062306a36Sopenharmony_ci the index. */ 226162306a36Sopenharmony_ci } __attribute__ ((__packed__)) key; 226262306a36Sopenharmony_ci /* The (optional) index data is inserted here when creating. */ 226362306a36Sopenharmony_ci // leVCN vcn; /* If INDEX_ENTRY_NODE bit in flags is set, the last 226462306a36Sopenharmony_ci // eight bytes of this index entry contain the virtual 226562306a36Sopenharmony_ci // cluster number of the index block that holds the 226662306a36Sopenharmony_ci // entries immediately preceding the current entry (the 226762306a36Sopenharmony_ci // vcn references the corresponding cluster in the data 226862306a36Sopenharmony_ci // of the non-resident index allocation attribute). If 226962306a36Sopenharmony_ci // the key_length is zero, then the vcn immediately 227062306a36Sopenharmony_ci // follows the INDEX_ENTRY_HEADER. Regardless of 227162306a36Sopenharmony_ci // key_length, the address of the 8-byte boundary 227262306a36Sopenharmony_ci // aligned vcn of INDEX_ENTRY{_HEADER} *ie is given by 227362306a36Sopenharmony_ci // (char*)ie + le16_to_cpu(ie*)->length) - sizeof(VCN), 227462306a36Sopenharmony_ci // where sizeof(VCN) can be hardcoded as 8 if wanted. */ 227562306a36Sopenharmony_ci} __attribute__ ((__packed__)) INDEX_ENTRY; 227662306a36Sopenharmony_ci 227762306a36Sopenharmony_ci/* 227862306a36Sopenharmony_ci * Attribute: Bitmap (0xb0). 227962306a36Sopenharmony_ci * 228062306a36Sopenharmony_ci * Contains an array of bits (aka a bitfield). 228162306a36Sopenharmony_ci * 228262306a36Sopenharmony_ci * When used in conjunction with the index allocation attribute, each bit 228362306a36Sopenharmony_ci * corresponds to one index block within the index allocation attribute. Thus 228462306a36Sopenharmony_ci * the number of bits in the bitmap * index block size / cluster size is the 228562306a36Sopenharmony_ci * number of clusters in the index allocation attribute. 228662306a36Sopenharmony_ci */ 228762306a36Sopenharmony_citypedef struct { 228862306a36Sopenharmony_ci u8 bitmap[0]; /* Array of bits. */ 228962306a36Sopenharmony_ci} __attribute__ ((__packed__)) BITMAP_ATTR; 229062306a36Sopenharmony_ci 229162306a36Sopenharmony_ci/* 229262306a36Sopenharmony_ci * The reparse point tag defines the type of the reparse point. It also 229362306a36Sopenharmony_ci * includes several flags, which further describe the reparse point. 229462306a36Sopenharmony_ci * 229562306a36Sopenharmony_ci * The reparse point tag is an unsigned 32-bit value divided in three parts: 229662306a36Sopenharmony_ci * 229762306a36Sopenharmony_ci * 1. The least significant 16 bits (i.e. bits 0 to 15) specifiy the type of 229862306a36Sopenharmony_ci * the reparse point. 229962306a36Sopenharmony_ci * 2. The 13 bits after this (i.e. bits 16 to 28) are reserved for future use. 230062306a36Sopenharmony_ci * 3. The most significant three bits are flags describing the reparse point. 230162306a36Sopenharmony_ci * They are defined as follows: 230262306a36Sopenharmony_ci * bit 29: Name surrogate bit. If set, the filename is an alias for 230362306a36Sopenharmony_ci * another object in the system. 230462306a36Sopenharmony_ci * bit 30: High-latency bit. If set, accessing the first byte of data will 230562306a36Sopenharmony_ci * be slow. (E.g. the data is stored on a tape drive.) 230662306a36Sopenharmony_ci * bit 31: Microsoft bit. If set, the tag is owned by Microsoft. User 230762306a36Sopenharmony_ci * defined tags have to use zero here. 230862306a36Sopenharmony_ci * 230962306a36Sopenharmony_ci * These are the predefined reparse point tags: 231062306a36Sopenharmony_ci */ 231162306a36Sopenharmony_cienum { 231262306a36Sopenharmony_ci IO_REPARSE_TAG_IS_ALIAS = cpu_to_le32(0x20000000), 231362306a36Sopenharmony_ci IO_REPARSE_TAG_IS_HIGH_LATENCY = cpu_to_le32(0x40000000), 231462306a36Sopenharmony_ci IO_REPARSE_TAG_IS_MICROSOFT = cpu_to_le32(0x80000000), 231562306a36Sopenharmony_ci 231662306a36Sopenharmony_ci IO_REPARSE_TAG_RESERVED_ZERO = cpu_to_le32(0x00000000), 231762306a36Sopenharmony_ci IO_REPARSE_TAG_RESERVED_ONE = cpu_to_le32(0x00000001), 231862306a36Sopenharmony_ci IO_REPARSE_TAG_RESERVED_RANGE = cpu_to_le32(0x00000001), 231962306a36Sopenharmony_ci 232062306a36Sopenharmony_ci IO_REPARSE_TAG_NSS = cpu_to_le32(0x68000005), 232162306a36Sopenharmony_ci IO_REPARSE_TAG_NSS_RECOVER = cpu_to_le32(0x68000006), 232262306a36Sopenharmony_ci IO_REPARSE_TAG_SIS = cpu_to_le32(0x68000007), 232362306a36Sopenharmony_ci IO_REPARSE_TAG_DFS = cpu_to_le32(0x68000008), 232462306a36Sopenharmony_ci 232562306a36Sopenharmony_ci IO_REPARSE_TAG_MOUNT_POINT = cpu_to_le32(0x88000003), 232662306a36Sopenharmony_ci 232762306a36Sopenharmony_ci IO_REPARSE_TAG_HSM = cpu_to_le32(0xa8000004), 232862306a36Sopenharmony_ci 232962306a36Sopenharmony_ci IO_REPARSE_TAG_SYMBOLIC_LINK = cpu_to_le32(0xe8000000), 233062306a36Sopenharmony_ci 233162306a36Sopenharmony_ci IO_REPARSE_TAG_VALID_VALUES = cpu_to_le32(0xe000ffff), 233262306a36Sopenharmony_ci}; 233362306a36Sopenharmony_ci 233462306a36Sopenharmony_ci/* 233562306a36Sopenharmony_ci * Attribute: Reparse point (0xc0). 233662306a36Sopenharmony_ci * 233762306a36Sopenharmony_ci * NOTE: Can be resident or non-resident. 233862306a36Sopenharmony_ci */ 233962306a36Sopenharmony_citypedef struct { 234062306a36Sopenharmony_ci le32 reparse_tag; /* Reparse point type (inc. flags). */ 234162306a36Sopenharmony_ci le16 reparse_data_length; /* Byte size of reparse data. */ 234262306a36Sopenharmony_ci le16 reserved; /* Align to 8-byte boundary. */ 234362306a36Sopenharmony_ci u8 reparse_data[0]; /* Meaning depends on reparse_tag. */ 234462306a36Sopenharmony_ci} __attribute__ ((__packed__)) REPARSE_POINT; 234562306a36Sopenharmony_ci 234662306a36Sopenharmony_ci/* 234762306a36Sopenharmony_ci * Attribute: Extended attribute (EA) information (0xd0). 234862306a36Sopenharmony_ci * 234962306a36Sopenharmony_ci * NOTE: Always resident. (Is this true???) 235062306a36Sopenharmony_ci */ 235162306a36Sopenharmony_citypedef struct { 235262306a36Sopenharmony_ci le16 ea_length; /* Byte size of the packed extended 235362306a36Sopenharmony_ci attributes. */ 235462306a36Sopenharmony_ci le16 need_ea_count; /* The number of extended attributes which have 235562306a36Sopenharmony_ci the NEED_EA bit set. */ 235662306a36Sopenharmony_ci le32 ea_query_length; /* Byte size of the buffer required to query 235762306a36Sopenharmony_ci the extended attributes when calling 235862306a36Sopenharmony_ci ZwQueryEaFile() in Windows NT/2k. I.e. the 235962306a36Sopenharmony_ci byte size of the unpacked extended 236062306a36Sopenharmony_ci attributes. */ 236162306a36Sopenharmony_ci} __attribute__ ((__packed__)) EA_INFORMATION; 236262306a36Sopenharmony_ci 236362306a36Sopenharmony_ci/* 236462306a36Sopenharmony_ci * Extended attribute flags (8-bit). 236562306a36Sopenharmony_ci */ 236662306a36Sopenharmony_cienum { 236762306a36Sopenharmony_ci NEED_EA = 0x80 /* If set the file to which the EA belongs 236862306a36Sopenharmony_ci cannot be interpreted without understanding 236962306a36Sopenharmony_ci the associates extended attributes. */ 237062306a36Sopenharmony_ci} __attribute__ ((__packed__)); 237162306a36Sopenharmony_ci 237262306a36Sopenharmony_citypedef u8 EA_FLAGS; 237362306a36Sopenharmony_ci 237462306a36Sopenharmony_ci/* 237562306a36Sopenharmony_ci * Attribute: Extended attribute (EA) (0xe0). 237662306a36Sopenharmony_ci * 237762306a36Sopenharmony_ci * NOTE: Can be resident or non-resident. 237862306a36Sopenharmony_ci * 237962306a36Sopenharmony_ci * Like the attribute list and the index buffer list, the EA attribute value is 238062306a36Sopenharmony_ci * a sequence of EA_ATTR variable length records. 238162306a36Sopenharmony_ci */ 238262306a36Sopenharmony_citypedef struct { 238362306a36Sopenharmony_ci le32 next_entry_offset; /* Offset to the next EA_ATTR. */ 238462306a36Sopenharmony_ci EA_FLAGS flags; /* Flags describing the EA. */ 238562306a36Sopenharmony_ci u8 ea_name_length; /* Length of the name of the EA in bytes 238662306a36Sopenharmony_ci excluding the '\0' byte terminator. */ 238762306a36Sopenharmony_ci le16 ea_value_length; /* Byte size of the EA's value. */ 238862306a36Sopenharmony_ci u8 ea_name[0]; /* Name of the EA. Note this is ASCII, not 238962306a36Sopenharmony_ci Unicode and it is zero terminated. */ 239062306a36Sopenharmony_ci u8 ea_value[0]; /* The value of the EA. Immediately follows 239162306a36Sopenharmony_ci the name. */ 239262306a36Sopenharmony_ci} __attribute__ ((__packed__)) EA_ATTR; 239362306a36Sopenharmony_ci 239462306a36Sopenharmony_ci/* 239562306a36Sopenharmony_ci * Attribute: Property set (0xf0). 239662306a36Sopenharmony_ci * 239762306a36Sopenharmony_ci * Intended to support Native Structure Storage (NSS) - a feature removed from 239862306a36Sopenharmony_ci * NTFS 3.0 during beta testing. 239962306a36Sopenharmony_ci */ 240062306a36Sopenharmony_citypedef struct { 240162306a36Sopenharmony_ci /* Irrelevant as feature unused. */ 240262306a36Sopenharmony_ci} __attribute__ ((__packed__)) PROPERTY_SET; 240362306a36Sopenharmony_ci 240462306a36Sopenharmony_ci/* 240562306a36Sopenharmony_ci * Attribute: Logged utility stream (0x100). 240662306a36Sopenharmony_ci * 240762306a36Sopenharmony_ci * NOTE: Can be resident or non-resident. 240862306a36Sopenharmony_ci * 240962306a36Sopenharmony_ci * Operations on this attribute are logged to the journal ($LogFile) like 241062306a36Sopenharmony_ci * normal metadata changes. 241162306a36Sopenharmony_ci * 241262306a36Sopenharmony_ci * Used by the Encrypting File System (EFS). All encrypted files have this 241362306a36Sopenharmony_ci * attribute with the name $EFS. 241462306a36Sopenharmony_ci */ 241562306a36Sopenharmony_citypedef struct { 241662306a36Sopenharmony_ci /* Can be anything the creator chooses. */ 241762306a36Sopenharmony_ci /* EFS uses it as follows: */ 241862306a36Sopenharmony_ci // FIXME: Type this info, verifying it along the way. (AIA) 241962306a36Sopenharmony_ci} __attribute__ ((__packed__)) LOGGED_UTILITY_STREAM, EFS_ATTR; 242062306a36Sopenharmony_ci 242162306a36Sopenharmony_ci#endif /* _LINUX_NTFS_LAYOUT_H */ 2422