Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * layout.h - All NTFS associated on-disk structures. Part of the Linux-NTFS |
| 3 | * project. |
| 4 | * |
Anton Altaparmakov | c002f42 | 2005-02-03 12:02:56 +0000 | [diff] [blame] | 5 | * Copyright (c) 2001-2005 Anton Altaparmakov |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Copyright (c) 2002 Richard Russon |
| 7 | * |
| 8 | * This program/include file is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as published |
| 10 | * by the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program/include file is distributed in the hope that it will be |
| 14 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
| 15 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program (in the main directory of the Linux-NTFS |
| 20 | * distribution in the file COPYING); if not, write to the Free Software |
| 21 | * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #ifndef _LINUX_NTFS_LAYOUT_H |
| 25 | #define _LINUX_NTFS_LAYOUT_H |
| 26 | |
| 27 | #include <linux/types.h> |
| 28 | #include <linux/bitops.h> |
| 29 | #include <linux/list.h> |
| 30 | #include <asm/byteorder.h> |
| 31 | |
| 32 | #include "types.h" |
| 33 | |
| 34 | /* |
| 35 | * Constant endianness conversion defines. |
| 36 | */ |
| 37 | #define const_le16_to_cpu(x) __constant_le16_to_cpu(x) |
| 38 | #define const_le32_to_cpu(x) __constant_le32_to_cpu(x) |
| 39 | #define const_le64_to_cpu(x) __constant_le64_to_cpu(x) |
| 40 | |
| 41 | #define const_cpu_to_le16(x) __constant_cpu_to_le16(x) |
| 42 | #define const_cpu_to_le32(x) __constant_cpu_to_le32(x) |
| 43 | #define const_cpu_to_le64(x) __constant_cpu_to_le64(x) |
| 44 | |
| 45 | /* The NTFS oem_id "NTFS " */ |
| 46 | #define magicNTFS const_cpu_to_le64(0x202020205346544eULL) |
| 47 | |
| 48 | /* |
| 49 | * Location of bootsector on partition: |
| 50 | * The standard NTFS_BOOT_SECTOR is on sector 0 of the partition. |
| 51 | * On NT4 and above there is one backup copy of the boot sector to |
| 52 | * be found on the last sector of the partition (not normally accessible |
| 53 | * from within Windows as the bootsector contained number of sectors |
| 54 | * value is one less than the actual value!). |
| 55 | * On versions of NT 3.51 and earlier, the backup copy was located at |
| 56 | * number of sectors/2 (integer divide), i.e. in the middle of the volume. |
| 57 | */ |
| 58 | |
| 59 | /* |
| 60 | * BIOS parameter block (bpb) structure. |
| 61 | */ |
| 62 | typedef struct { |
| 63 | le16 bytes_per_sector; /* Size of a sector in bytes. */ |
| 64 | u8 sectors_per_cluster; /* Size of a cluster in sectors. */ |
| 65 | le16 reserved_sectors; /* zero */ |
| 66 | u8 fats; /* zero */ |
| 67 | le16 root_entries; /* zero */ |
| 68 | le16 sectors; /* zero */ |
| 69 | u8 media_type; /* 0xf8 = hard disk */ |
| 70 | le16 sectors_per_fat; /* zero */ |
| 71 | le16 sectors_per_track; /* irrelevant */ |
| 72 | le16 heads; /* irrelevant */ |
| 73 | le32 hidden_sectors; /* zero */ |
| 74 | le32 large_sectors; /* zero */ |
| 75 | } __attribute__ ((__packed__)) BIOS_PARAMETER_BLOCK; |
| 76 | |
| 77 | /* |
| 78 | * NTFS boot sector structure. |
| 79 | */ |
| 80 | typedef struct { |
| 81 | u8 jump[3]; /* Irrelevant (jump to boot up code).*/ |
| 82 | le64 oem_id; /* Magic "NTFS ". */ |
| 83 | BIOS_PARAMETER_BLOCK bpb; /* See BIOS_PARAMETER_BLOCK. */ |
| 84 | u8 unused[4]; /* zero, NTFS diskedit.exe states that |
| 85 | this is actually: |
| 86 | __u8 physical_drive; // 0x80 |
| 87 | __u8 current_head; // zero |
| 88 | __u8 extended_boot_signature; |
| 89 | // 0x80 |
| 90 | __u8 unused; // zero |
| 91 | */ |
| 92 | /*0x28*/sle64 number_of_sectors; /* Number of sectors in volume. Gives |
| 93 | maximum volume size of 2^63 sectors. |
| 94 | Assuming standard sector size of 512 |
| 95 | bytes, the maximum byte size is |
| 96 | approx. 4.7x10^21 bytes. (-; */ |
| 97 | sle64 mft_lcn; /* Cluster location of mft data. */ |
| 98 | sle64 mftmirr_lcn; /* Cluster location of copy of mft. */ |
| 99 | s8 clusters_per_mft_record; /* Mft record size in clusters. */ |
| 100 | u8 reserved0[3]; /* zero */ |
| 101 | s8 clusters_per_index_record; /* Index block size in clusters. */ |
| 102 | u8 reserved1[3]; /* zero */ |
| 103 | le64 volume_serial_number; /* Irrelevant (serial number). */ |
| 104 | le32 checksum; /* Boot sector checksum. */ |
| 105 | /*0x54*/u8 bootstrap[426]; /* Irrelevant (boot up code). */ |
| 106 | le16 end_of_sector_marker; /* End of bootsector magic. Always is |
| 107 | 0xaa55 in little endian. */ |
| 108 | /* sizeof() = 512 (0x200) bytes */ |
| 109 | } __attribute__ ((__packed__)) NTFS_BOOT_SECTOR; |
| 110 | |
| 111 | /* |
| 112 | * Magic identifiers present at the beginning of all ntfs record containing |
| 113 | * records (like mft records for example). |
| 114 | */ |
| 115 | enum { |
| 116 | /* Found in $MFT/$DATA. */ |
| 117 | magic_FILE = const_cpu_to_le32(0x454c4946), /* Mft entry. */ |
| 118 | magic_INDX = const_cpu_to_le32(0x58444e49), /* Index buffer. */ |
| 119 | magic_HOLE = const_cpu_to_le32(0x454c4f48), /* ? (NTFS 3.0+?) */ |
| 120 | |
| 121 | /* Found in $LogFile/$DATA. */ |
| 122 | magic_RSTR = const_cpu_to_le32(0x52545352), /* Restart page. */ |
| 123 | magic_RCRD = const_cpu_to_le32(0x44524352), /* Log record page. */ |
| 124 | |
| 125 | /* Found in $LogFile/$DATA. (May be found in $MFT/$DATA, also?) */ |
Anton Altaparmakov | 838bf96 | 2005-09-26 10:45:46 +0100 | [diff] [blame] | 126 | magic_CHKD = const_cpu_to_le32(0x444b4843), /* Modified by chkdsk. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | /* Found in all ntfs record containing records. */ |
| 129 | magic_BAAD = const_cpu_to_le32(0x44414142), /* Failed multi sector |
| 130 | transfer was detected. */ |
| 131 | /* |
| 132 | * Found in $LogFile/$DATA when a page is full of 0xff bytes and is |
| 133 | * thus not initialized. Page must be initialized before using it. |
| 134 | */ |
| 135 | magic_empty = const_cpu_to_le32(0xffffffff) /* Record is empty. */ |
| 136 | }; |
| 137 | |
| 138 | typedef le32 NTFS_RECORD_TYPE; |
| 139 | |
| 140 | /* |
| 141 | * Generic magic comparison macros. Finally found a use for the ## preprocessor |
| 142 | * operator! (-8 |
| 143 | */ |
| 144 | |
Richard Knutsson | c49c311 | 2006-09-30 23:27:12 -0700 | [diff] [blame] | 145 | static inline bool __ntfs_is_magic(le32 x, NTFS_RECORD_TYPE r) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
| 147 | return (x == r); |
| 148 | } |
| 149 | #define ntfs_is_magic(x, m) __ntfs_is_magic(x, magic_##m) |
| 150 | |
Richard Knutsson | c49c311 | 2006-09-30 23:27:12 -0700 | [diff] [blame] | 151 | static inline bool __ntfs_is_magicp(le32 *p, NTFS_RECORD_TYPE r) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
| 153 | return (*p == r); |
| 154 | } |
| 155 | #define ntfs_is_magicp(p, m) __ntfs_is_magicp(p, magic_##m) |
| 156 | |
| 157 | /* |
| 158 | * Specialised magic comparison macros for the NTFS_RECORD_TYPEs defined above. |
| 159 | */ |
| 160 | #define ntfs_is_file_record(x) ( ntfs_is_magic (x, FILE) ) |
| 161 | #define ntfs_is_file_recordp(p) ( ntfs_is_magicp(p, FILE) ) |
| 162 | #define ntfs_is_mft_record(x) ( ntfs_is_file_record (x) ) |
| 163 | #define ntfs_is_mft_recordp(p) ( ntfs_is_file_recordp(p) ) |
| 164 | #define ntfs_is_indx_record(x) ( ntfs_is_magic (x, INDX) ) |
| 165 | #define ntfs_is_indx_recordp(p) ( ntfs_is_magicp(p, INDX) ) |
| 166 | #define ntfs_is_hole_record(x) ( ntfs_is_magic (x, HOLE) ) |
| 167 | #define ntfs_is_hole_recordp(p) ( ntfs_is_magicp(p, HOLE) ) |
| 168 | |
| 169 | #define ntfs_is_rstr_record(x) ( ntfs_is_magic (x, RSTR) ) |
| 170 | #define ntfs_is_rstr_recordp(p) ( ntfs_is_magicp(p, RSTR) ) |
| 171 | #define ntfs_is_rcrd_record(x) ( ntfs_is_magic (x, RCRD) ) |
| 172 | #define ntfs_is_rcrd_recordp(p) ( ntfs_is_magicp(p, RCRD) ) |
| 173 | |
| 174 | #define ntfs_is_chkd_record(x) ( ntfs_is_magic (x, CHKD) ) |
| 175 | #define ntfs_is_chkd_recordp(p) ( ntfs_is_magicp(p, CHKD) ) |
| 176 | |
| 177 | #define ntfs_is_baad_record(x) ( ntfs_is_magic (x, BAAD) ) |
| 178 | #define ntfs_is_baad_recordp(p) ( ntfs_is_magicp(p, BAAD) ) |
| 179 | |
| 180 | #define ntfs_is_empty_record(x) ( ntfs_is_magic (x, empty) ) |
| 181 | #define ntfs_is_empty_recordp(p) ( ntfs_is_magicp(p, empty) ) |
| 182 | |
| 183 | /* |
| 184 | * The Update Sequence Array (usa) is an array of the le16 values which belong |
| 185 | * to the end of each sector protected by the update sequence record in which |
| 186 | * this array is contained. Note that the first entry is the Update Sequence |
| 187 | * Number (usn), a cyclic counter of how many times the protected record has |
| 188 | * been written to disk. The values 0 and -1 (ie. 0xffff) are not used. All |
| 189 | * last le16's of each sector have to be equal to the usn (during reading) or |
| 190 | * are set to it (during writing). If they are not, an incomplete multi sector |
| 191 | * transfer has occurred when the data was written. |
| 192 | * The maximum size for the update sequence array is fixed to: |
| 193 | * maximum size = usa_ofs + (usa_count * 2) = 510 bytes |
| 194 | * The 510 bytes comes from the fact that the last le16 in the array has to |
| 195 | * (obviously) finish before the last le16 of the first 512-byte sector. |
| 196 | * This formula can be used as a consistency check in that usa_ofs + |
| 197 | * (usa_count * 2) has to be less than or equal to 510. |
| 198 | */ |
| 199 | typedef struct { |
| 200 | NTFS_RECORD_TYPE magic; /* A four-byte magic identifying the record |
| 201 | type and/or status. */ |
| 202 | le16 usa_ofs; /* Offset to the Update Sequence Array (usa) |
| 203 | from the start of the ntfs record. */ |
| 204 | le16 usa_count; /* Number of le16 sized entries in the usa |
| 205 | including the Update Sequence Number (usn), |
| 206 | thus the number of fixups is the usa_count |
| 207 | minus 1. */ |
| 208 | } __attribute__ ((__packed__)) NTFS_RECORD; |
| 209 | |
| 210 | /* |
| 211 | * System files mft record numbers. All these files are always marked as used |
| 212 | * in the bitmap attribute of the mft; presumably in order to avoid accidental |
| 213 | * allocation for random other mft records. Also, the sequence number for each |
| 214 | * of the system files is always equal to their mft record number and it is |
| 215 | * never modified. |
| 216 | */ |
| 217 | typedef enum { |
| 218 | FILE_MFT = 0, /* Master file table (mft). Data attribute |
| 219 | contains the entries and bitmap attribute |
| 220 | records which ones are in use (bit==1). */ |
| 221 | FILE_MFTMirr = 1, /* Mft mirror: copy of first four mft records |
| 222 | in data attribute. If cluster size > 4kiB, |
| 223 | copy of first N mft records, with |
| 224 | N = cluster_size / mft_record_size. */ |
| 225 | FILE_LogFile = 2, /* Journalling log in data attribute. */ |
| 226 | FILE_Volume = 3, /* Volume name attribute and volume information |
| 227 | attribute (flags and ntfs version). Windows |
| 228 | refers to this file as volume DASD (Direct |
| 229 | Access Storage Device). */ |
| 230 | FILE_AttrDef = 4, /* Array of attribute definitions in data |
| 231 | attribute. */ |
| 232 | FILE_root = 5, /* Root directory. */ |
| 233 | FILE_Bitmap = 6, /* Allocation bitmap of all clusters (lcns) in |
| 234 | data attribute. */ |
| 235 | FILE_Boot = 7, /* Boot sector (always at cluster 0) in data |
| 236 | attribute. */ |
| 237 | FILE_BadClus = 8, /* Contains all bad clusters in the non-resident |
| 238 | data attribute. */ |
| 239 | FILE_Secure = 9, /* Shared security descriptors in data attribute |
| 240 | and two indexes into the descriptors. |
| 241 | Appeared in Windows 2000. Before that, this |
| 242 | file was named $Quota but was unused. */ |
| 243 | FILE_UpCase = 10, /* Uppercase equivalents of all 65536 Unicode |
| 244 | characters in data attribute. */ |
| 245 | FILE_Extend = 11, /* Directory containing other system files (eg. |
| 246 | $ObjId, $Quota, $Reparse and $UsnJrnl). This |
| 247 | is new to NTFS3.0. */ |
| 248 | FILE_reserved12 = 12, /* Reserved for future use (records 12-15). */ |
| 249 | FILE_reserved13 = 13, |
| 250 | FILE_reserved14 = 14, |
| 251 | FILE_reserved15 = 15, |
| 252 | FILE_first_user = 16, /* First user file, used as test limit for |
| 253 | whether to allow opening a file or not. */ |
| 254 | } NTFS_SYSTEM_FILES; |
| 255 | |
| 256 | /* |
| 257 | * These are the so far known MFT_RECORD_* flags (16-bit) which contain |
| 258 | * information about the mft record in which they are present. |
| 259 | */ |
| 260 | enum { |
| 261 | MFT_RECORD_IN_USE = const_cpu_to_le16(0x0001), |
| 262 | MFT_RECORD_IS_DIRECTORY = const_cpu_to_le16(0x0002), |
| 263 | } __attribute__ ((__packed__)); |
| 264 | |
| 265 | typedef le16 MFT_RECORD_FLAGS; |
| 266 | |
| 267 | /* |
| 268 | * mft references (aka file references or file record segment references) are |
| 269 | * used whenever a structure needs to refer to a record in the mft. |
| 270 | * |
| 271 | * A reference consists of a 48-bit index into the mft and a 16-bit sequence |
| 272 | * number used to detect stale references. |
| 273 | * |
| 274 | * For error reporting purposes we treat the 48-bit index as a signed quantity. |
| 275 | * |
| 276 | * The sequence number is a circular counter (skipping 0) describing how many |
| 277 | * times the referenced mft record has been (re)used. This has to match the |
| 278 | * sequence number of the mft record being referenced, otherwise the reference |
| 279 | * is considered stale and removed (FIXME: only ntfsck or the driver itself?). |
| 280 | * |
| 281 | * If the sequence number is zero it is assumed that no sequence number |
| 282 | * consistency checking should be performed. |
| 283 | * |
| 284 | * FIXME: Since inodes are 32-bit as of now, the driver needs to always check |
| 285 | * for high_part being 0 and if not either BUG(), cause a panic() or handle |
| 286 | * the situation in some other way. This shouldn't be a problem as a volume has |
| 287 | * to become HUGE in order to need more than 32-bits worth of mft records. |
| 288 | * Assuming the standard mft record size of 1kb only the records (never mind |
| 289 | * the non-resident attributes, etc.) would require 4Tb of space on their own |
| 290 | * for the first 32 bits worth of records. This is only if some strange person |
| 291 | * doesn't decide to foul play and make the mft sparse which would be a really |
| 292 | * horrible thing to do as it would trash our current driver implementation. )-: |
| 293 | * Do I hear screams "we want 64-bit inodes!" ?!? (-; |
| 294 | * |
| 295 | * FIXME: The mft zone is defined as the first 12% of the volume. This space is |
| 296 | * reserved so that the mft can grow contiguously and hence doesn't become |
| 297 | * fragmented. Volume free space includes the empty part of the mft zone and |
| 298 | * when the volume's free 88% are used up, the mft zone is shrunk by a factor |
| 299 | * of 2, thus making more space available for more files/data. This process is |
| 300 | * repeated everytime there is no more free space except for the mft zone until |
| 301 | * there really is no more free space. |
| 302 | */ |
| 303 | |
| 304 | /* |
| 305 | * Typedef the MFT_REF as a 64-bit value for easier handling. |
| 306 | * Also define two unpacking macros to get to the reference (MREF) and |
| 307 | * sequence number (MSEQNO) respectively. |
| 308 | * The _LE versions are to be applied on little endian MFT_REFs. |
| 309 | * Note: The _LE versions will return a CPU endian formatted value! |
| 310 | */ |
Anton Altaparmakov | e2fcc61 | 2005-09-26 17:02:41 +0100 | [diff] [blame] | 311 | #define MFT_REF_MASK_CPU 0x0000ffffffffffffULL |
Anton Altaparmakov | c394e45 | 2005-10-04 13:08:53 +0100 | [diff] [blame] | 312 | #define MFT_REF_MASK_LE const_cpu_to_le64(MFT_REF_MASK_CPU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | typedef u64 MFT_REF; |
| 315 | typedef le64 leMFT_REF; |
| 316 | |
| 317 | #define MK_MREF(m, s) ((MFT_REF)(((MFT_REF)(s) << 48) | \ |
Anton Altaparmakov | e2fcc61 | 2005-09-26 17:02:41 +0100 | [diff] [blame] | 318 | ((MFT_REF)(m) & MFT_REF_MASK_CPU))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | #define MK_LE_MREF(m, s) cpu_to_le64(MK_MREF(m, s)) |
| 320 | |
Anton Altaparmakov | e2fcc61 | 2005-09-26 17:02:41 +0100 | [diff] [blame] | 321 | #define MREF(x) ((unsigned long)((x) & MFT_REF_MASK_CPU)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | #define MSEQNO(x) ((u16)(((x) >> 48) & 0xffff)) |
Anton Altaparmakov | e2fcc61 | 2005-09-26 17:02:41 +0100 | [diff] [blame] | 323 | #define MREF_LE(x) ((unsigned long)(le64_to_cpu(x) & MFT_REF_MASK_CPU)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | #define MSEQNO_LE(x) ((u16)((le64_to_cpu(x) >> 48) & 0xffff)) |
| 325 | |
Richard Knutsson | c49c311 | 2006-09-30 23:27:12 -0700 | [diff] [blame] | 326 | #define IS_ERR_MREF(x) (((x) & 0x0000800000000000ULL) ? true : false) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | #define ERR_MREF(x) ((u64)((s64)(x))) |
| 328 | #define MREF_ERR(x) ((int)((s64)(x))) |
| 329 | |
| 330 | /* |
| 331 | * The mft record header present at the beginning of every record in the mft. |
| 332 | * This is followed by a sequence of variable length attribute records which |
| 333 | * is terminated by an attribute of type AT_END which is a truncated attribute |
| 334 | * in that it only consists of the attribute type code AT_END and none of the |
| 335 | * other members of the attribute structure are present. |
| 336 | */ |
| 337 | typedef struct { |
| 338 | /*Ofs*/ |
| 339 | /* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ |
| 340 | NTFS_RECORD_TYPE magic; /* Usually the magic is "FILE". */ |
| 341 | le16 usa_ofs; /* See NTFS_RECORD definition above. */ |
| 342 | le16 usa_count; /* See NTFS_RECORD definition above. */ |
| 343 | |
| 344 | /* 8*/ le64 lsn; /* $LogFile sequence number for this record. |
| 345 | Changed every time the record is modified. */ |
| 346 | /* 16*/ le16 sequence_number; /* Number of times this mft record has been |
| 347 | reused. (See description for MFT_REF |
| 348 | above.) NOTE: The increment (skipping zero) |
| 349 | is done when the file is deleted. NOTE: If |
| 350 | this is zero it is left zero. */ |
| 351 | /* 18*/ le16 link_count; /* Number of hard links, i.e. the number of |
| 352 | directory entries referencing this record. |
| 353 | NOTE: Only used in mft base records. |
| 354 | NOTE: When deleting a directory entry we |
| 355 | check the link_count and if it is 1 we |
| 356 | delete the file. Otherwise we delete the |
| 357 | FILE_NAME_ATTR being referenced by the |
| 358 | directory entry from the mft record and |
| 359 | decrement the link_count. |
| 360 | FIXME: Careful with Win32 + DOS names! */ |
| 361 | /* 20*/ le16 attrs_offset; /* Byte offset to the first attribute in this |
| 362 | mft record from the start of the mft record. |
| 363 | NOTE: Must be aligned to 8-byte boundary. */ |
| 364 | /* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file |
| 365 | is deleted, the MFT_RECORD_IN_USE flag is |
| 366 | set to zero. */ |
| 367 | /* 24*/ le32 bytes_in_use; /* Number of bytes used in this mft record. |
| 368 | NOTE: Must be aligned to 8-byte boundary. */ |
| 369 | /* 28*/ le32 bytes_allocated; /* Number of bytes allocated for this mft |
| 370 | record. This should be equal to the mft |
| 371 | record size. */ |
| 372 | /* 32*/ leMFT_REF base_mft_record;/* This is zero for base mft records. |
| 373 | When it is not zero it is a mft reference |
| 374 | pointing to the base mft record to which |
| 375 | this record belongs (this is then used to |
| 376 | locate the attribute list attribute present |
| 377 | in the base record which describes this |
| 378 | extension record and hence might need |
| 379 | modification when the extension record |
| 380 | itself is modified, also locating the |
| 381 | attribute list also means finding the other |
| 382 | potential extents, belonging to the non-base |
| 383 | mft record). */ |
| 384 | /* 40*/ le16 next_attr_instance;/* The instance number that will be assigned to |
| 385 | the next attribute added to this mft record. |
| 386 | NOTE: Incremented each time after it is used. |
| 387 | NOTE: Every time the mft record is reused |
| 388 | this number is set to zero. NOTE: The first |
| 389 | instance number is always 0. */ |
| 390 | /* The below fields are specific to NTFS 3.1+ (Windows XP and above): */ |
| 391 | /* 42*/ le16 reserved; /* Reserved/alignment. */ |
| 392 | /* 44*/ le32 mft_record_number; /* Number of this mft record. */ |
| 393 | /* sizeof() = 48 bytes */ |
| 394 | /* |
| 395 | * When (re)using the mft record, we place the update sequence array at this |
| 396 | * offset, i.e. before we start with the attributes. This also makes sense, |
| 397 | * otherwise we could run into problems with the update sequence array |
| 398 | * containing in itself the last two bytes of a sector which would mean that |
| 399 | * multi sector transfer protection wouldn't work. As you can't protect data |
| 400 | * by overwriting it since you then can't get it back... |
| 401 | * When reading we obviously use the data from the ntfs record header. |
| 402 | */ |
| 403 | } __attribute__ ((__packed__)) MFT_RECORD; |
| 404 | |
| 405 | /* This is the version without the NTFS 3.1+ specific fields. */ |
| 406 | typedef struct { |
| 407 | /*Ofs*/ |
| 408 | /* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ |
| 409 | NTFS_RECORD_TYPE magic; /* Usually the magic is "FILE". */ |
| 410 | le16 usa_ofs; /* See NTFS_RECORD definition above. */ |
| 411 | le16 usa_count; /* See NTFS_RECORD definition above. */ |
| 412 | |
| 413 | /* 8*/ le64 lsn; /* $LogFile sequence number for this record. |
| 414 | Changed every time the record is modified. */ |
| 415 | /* 16*/ le16 sequence_number; /* Number of times this mft record has been |
| 416 | reused. (See description for MFT_REF |
| 417 | above.) NOTE: The increment (skipping zero) |
| 418 | is done when the file is deleted. NOTE: If |
| 419 | this is zero it is left zero. */ |
| 420 | /* 18*/ le16 link_count; /* Number of hard links, i.e. the number of |
| 421 | directory entries referencing this record. |
| 422 | NOTE: Only used in mft base records. |
| 423 | NOTE: When deleting a directory entry we |
| 424 | check the link_count and if it is 1 we |
| 425 | delete the file. Otherwise we delete the |
| 426 | FILE_NAME_ATTR being referenced by the |
| 427 | directory entry from the mft record and |
| 428 | decrement the link_count. |
| 429 | FIXME: Careful with Win32 + DOS names! */ |
| 430 | /* 20*/ le16 attrs_offset; /* Byte offset to the first attribute in this |
| 431 | mft record from the start of the mft record. |
| 432 | NOTE: Must be aligned to 8-byte boundary. */ |
| 433 | /* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file |
| 434 | is deleted, the MFT_RECORD_IN_USE flag is |
| 435 | set to zero. */ |
| 436 | /* 24*/ le32 bytes_in_use; /* Number of bytes used in this mft record. |
| 437 | NOTE: Must be aligned to 8-byte boundary. */ |
| 438 | /* 28*/ le32 bytes_allocated; /* Number of bytes allocated for this mft |
| 439 | record. This should be equal to the mft |
| 440 | record size. */ |
| 441 | /* 32*/ leMFT_REF base_mft_record;/* This is zero for base mft records. |
| 442 | When it is not zero it is a mft reference |
| 443 | pointing to the base mft record to which |
| 444 | this record belongs (this is then used to |
| 445 | locate the attribute list attribute present |
| 446 | in the base record which describes this |
| 447 | extension record and hence might need |
| 448 | modification when the extension record |
| 449 | itself is modified, also locating the |
| 450 | attribute list also means finding the other |
| 451 | potential extents, belonging to the non-base |
| 452 | mft record). */ |
| 453 | /* 40*/ le16 next_attr_instance;/* The instance number that will be assigned to |
| 454 | the next attribute added to this mft record. |
| 455 | NOTE: Incremented each time after it is used. |
| 456 | NOTE: Every time the mft record is reused |
| 457 | this number is set to zero. NOTE: The first |
| 458 | instance number is always 0. */ |
| 459 | /* sizeof() = 42 bytes */ |
| 460 | /* |
| 461 | * When (re)using the mft record, we place the update sequence array at this |
| 462 | * offset, i.e. before we start with the attributes. This also makes sense, |
| 463 | * otherwise we could run into problems with the update sequence array |
| 464 | * containing in itself the last two bytes of a sector which would mean that |
| 465 | * multi sector transfer protection wouldn't work. As you can't protect data |
| 466 | * by overwriting it since you then can't get it back... |
| 467 | * When reading we obviously use the data from the ntfs record header. |
| 468 | */ |
| 469 | } __attribute__ ((__packed__)) MFT_RECORD_OLD; |
| 470 | |
| 471 | /* |
| 472 | * System defined attributes (32-bit). Each attribute type has a corresponding |
| 473 | * attribute name (Unicode string of maximum 64 character length) as described |
| 474 | * by the attribute definitions present in the data attribute of the $AttrDef |
| 475 | * system file. On NTFS 3.0 volumes the names are just as the types are named |
| 476 | * in the below defines exchanging AT_ for the dollar sign ($). If that is not |
| 477 | * a revealing choice of symbol I do not know what is... (-; |
| 478 | */ |
| 479 | enum { |
| 480 | AT_UNUSED = const_cpu_to_le32( 0), |
| 481 | AT_STANDARD_INFORMATION = const_cpu_to_le32( 0x10), |
| 482 | AT_ATTRIBUTE_LIST = const_cpu_to_le32( 0x20), |
| 483 | AT_FILE_NAME = const_cpu_to_le32( 0x30), |
| 484 | AT_OBJECT_ID = const_cpu_to_le32( 0x40), |
| 485 | AT_SECURITY_DESCRIPTOR = const_cpu_to_le32( 0x50), |
| 486 | AT_VOLUME_NAME = const_cpu_to_le32( 0x60), |
| 487 | AT_VOLUME_INFORMATION = const_cpu_to_le32( 0x70), |
| 488 | AT_DATA = const_cpu_to_le32( 0x80), |
| 489 | AT_INDEX_ROOT = const_cpu_to_le32( 0x90), |
| 490 | AT_INDEX_ALLOCATION = const_cpu_to_le32( 0xa0), |
| 491 | AT_BITMAP = const_cpu_to_le32( 0xb0), |
| 492 | AT_REPARSE_POINT = const_cpu_to_le32( 0xc0), |
| 493 | AT_EA_INFORMATION = const_cpu_to_le32( 0xd0), |
| 494 | AT_EA = const_cpu_to_le32( 0xe0), |
| 495 | AT_PROPERTY_SET = const_cpu_to_le32( 0xf0), |
| 496 | AT_LOGGED_UTILITY_STREAM = const_cpu_to_le32( 0x100), |
| 497 | AT_FIRST_USER_DEFINED_ATTRIBUTE = const_cpu_to_le32( 0x1000), |
| 498 | AT_END = const_cpu_to_le32(0xffffffff) |
| 499 | }; |
| 500 | |
| 501 | typedef le32 ATTR_TYPE; |
| 502 | |
| 503 | /* |
| 504 | * The collation rules for sorting views/indexes/etc (32-bit). |
| 505 | * |
| 506 | * COLLATION_BINARY - Collate by binary compare where the first byte is most |
| 507 | * significant. |
| 508 | * COLLATION_UNICODE_STRING - Collate Unicode strings by comparing their binary |
| 509 | * Unicode values, except that when a character can be uppercased, the |
| 510 | * upper case value collates before the lower case one. |
| 511 | * COLLATION_FILE_NAME - Collate file names as Unicode strings. The collation |
| 512 | * is done very much like COLLATION_UNICODE_STRING. In fact I have no idea |
| 513 | * what the difference is. Perhaps the difference is that file names |
| 514 | * would treat some special characters in an odd way (see |
| 515 | * unistr.c::ntfs_collate_names() and unistr.c::legal_ansi_char_array[] |
| 516 | * for what I mean but COLLATION_UNICODE_STRING would not give any special |
| 517 | * treatment to any characters at all, but this is speculation. |
| 518 | * COLLATION_NTOFS_ULONG - Sorting is done according to ascending le32 key |
| 519 | * values. E.g. used for $SII index in FILE_Secure, which sorts by |
| 520 | * security_id (le32). |
| 521 | * COLLATION_NTOFS_SID - Sorting is done according to ascending SID values. |
| 522 | * E.g. used for $O index in FILE_Extend/$Quota. |
| 523 | * COLLATION_NTOFS_SECURITY_HASH - Sorting is done first by ascending hash |
| 524 | * values and second by ascending security_id values. E.g. used for $SDH |
| 525 | * index in FILE_Secure. |
| 526 | * COLLATION_NTOFS_ULONGS - Sorting is done according to a sequence of ascending |
| 527 | * le32 key values. E.g. used for $O index in FILE_Extend/$ObjId, which |
| 528 | * sorts by object_id (16-byte), by splitting up the object_id in four |
| 529 | * le32 values and using them as individual keys. E.g. take the following |
| 530 | * two security_ids, stored as follows on disk: |
| 531 | * 1st: a1 61 65 b7 65 7b d4 11 9e 3d 00 e0 81 10 42 59 |
| 532 | * 2nd: 38 14 37 d2 d2 f3 d4 11 a5 21 c8 6b 79 b1 97 45 |
| 533 | * To compare them, they are split into four le32 values each, like so: |
| 534 | * 1st: 0xb76561a1 0x11d47b65 0xe0003d9e 0x59421081 |
| 535 | * 2nd: 0xd2371438 0x11d4f3d2 0x6bc821a5 0x4597b179 |
| 536 | * Now, it is apparent why the 2nd object_id collates after the 1st: the |
| 537 | * first le32 value of the 1st object_id is less than the first le32 of |
| 538 | * the 2nd object_id. If the first le32 values of both object_ids were |
| 539 | * equal then the second le32 values would be compared, etc. |
| 540 | */ |
| 541 | enum { |
| 542 | COLLATION_BINARY = const_cpu_to_le32(0x00), |
| 543 | COLLATION_FILE_NAME = const_cpu_to_le32(0x01), |
| 544 | COLLATION_UNICODE_STRING = const_cpu_to_le32(0x02), |
| 545 | COLLATION_NTOFS_ULONG = const_cpu_to_le32(0x10), |
| 546 | COLLATION_NTOFS_SID = const_cpu_to_le32(0x11), |
| 547 | COLLATION_NTOFS_SECURITY_HASH = const_cpu_to_le32(0x12), |
Anton Altaparmakov | bb3cf33 | 2005-04-06 13:34:31 +0100 | [diff] [blame] | 548 | COLLATION_NTOFS_ULONGS = const_cpu_to_le32(0x13), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | }; |
| 550 | |
| 551 | typedef le32 COLLATION_RULE; |
| 552 | |
| 553 | /* |
| 554 | * The flags (32-bit) describing attribute properties in the attribute |
Anton Altaparmakov | bb3cf33 | 2005-04-06 13:34:31 +0100 | [diff] [blame] | 555 | * definition structure. FIXME: This information is based on Regis's |
| 556 | * information and, according to him, it is not certain and probably |
| 557 | * incomplete. The INDEXABLE flag is fairly certainly correct as only the file |
| 558 | * name attribute has this flag set and this is the only attribute indexed in |
| 559 | * NT4. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | */ |
| 561 | enum { |
Anton Altaparmakov | bb3cf33 | 2005-04-06 13:34:31 +0100 | [diff] [blame] | 562 | ATTR_DEF_INDEXABLE = const_cpu_to_le32(0x02), /* Attribute can be |
| 563 | indexed. */ |
| 564 | ATTR_DEF_MULTIPLE = const_cpu_to_le32(0x04), /* Attribute type |
| 565 | can be present multiple times in the |
| 566 | mft records of an inode. */ |
| 567 | ATTR_DEF_NOT_ZERO = const_cpu_to_le32(0x08), /* Attribute value |
| 568 | must contain at least one non-zero |
| 569 | byte. */ |
| 570 | ATTR_DEF_INDEXED_UNIQUE = const_cpu_to_le32(0x10), /* Attribute must be |
| 571 | indexed and the attribute value must be |
| 572 | unique for the attribute type in all of |
| 573 | the mft records of an inode. */ |
| 574 | ATTR_DEF_NAMED_UNIQUE = const_cpu_to_le32(0x20), /* Attribute must be |
| 575 | named and the name must be unique for |
| 576 | the attribute type in all of the mft |
| 577 | records of an inode. */ |
| 578 | ATTR_DEF_RESIDENT = const_cpu_to_le32(0x40), /* Attribute must be |
| 579 | resident. */ |
| 580 | ATTR_DEF_ALWAYS_LOG = const_cpu_to_le32(0x80), /* Always log |
| 581 | modifications to this attribute, |
| 582 | regardless of whether it is resident or |
| 583 | non-resident. Without this, only log |
| 584 | modifications if the attribute is |
| 585 | resident. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | }; |
| 587 | |
| 588 | typedef le32 ATTR_DEF_FLAGS; |
| 589 | |
| 590 | /* |
| 591 | * The data attribute of FILE_AttrDef contains a sequence of attribute |
| 592 | * definitions for the NTFS volume. With this, it is supposed to be safe for an |
| 593 | * older NTFS driver to mount a volume containing a newer NTFS version without |
| 594 | * damaging it (that's the theory. In practice it's: not damaging it too much). |
| 595 | * Entries are sorted by attribute type. The flags describe whether the |
| 596 | * attribute can be resident/non-resident and possibly other things, but the |
| 597 | * actual bits are unknown. |
| 598 | */ |
| 599 | typedef struct { |
| 600 | /*hex ofs*/ |
| 601 | /* 0*/ ntfschar name[0x40]; /* Unicode name of the attribute. Zero |
| 602 | terminated. */ |
| 603 | /* 80*/ ATTR_TYPE type; /* Type of the attribute. */ |
| 604 | /* 84*/ le32 display_rule; /* Default display rule. |
| 605 | FIXME: What does it mean? (AIA) */ |
| 606 | /* 88*/ COLLATION_RULE collation_rule; /* Default collation rule. */ |
| 607 | /* 8c*/ ATTR_DEF_FLAGS flags; /* Flags describing the attribute. */ |
| 608 | /* 90*/ sle64 min_size; /* Optional minimum attribute size. */ |
| 609 | /* 98*/ sle64 max_size; /* Maximum size of attribute. */ |
| 610 | /* sizeof() = 0xa0 or 160 bytes */ |
| 611 | } __attribute__ ((__packed__)) ATTR_DEF; |
| 612 | |
| 613 | /* |
| 614 | * Attribute flags (16-bit). |
| 615 | */ |
| 616 | enum { |
| 617 | ATTR_IS_COMPRESSED = const_cpu_to_le16(0x0001), |
| 618 | ATTR_COMPRESSION_MASK = const_cpu_to_le16(0x00ff), /* Compression method |
| 619 | mask. Also, first |
| 620 | illegal value. */ |
| 621 | ATTR_IS_ENCRYPTED = const_cpu_to_le16(0x4000), |
| 622 | ATTR_IS_SPARSE = const_cpu_to_le16(0x8000), |
| 623 | } __attribute__ ((__packed__)); |
| 624 | |
| 625 | typedef le16 ATTR_FLAGS; |
| 626 | |
| 627 | /* |
| 628 | * Attribute compression. |
| 629 | * |
| 630 | * Only the data attribute is ever compressed in the current ntfs driver in |
| 631 | * Windows. Further, compression is only applied when the data attribute is |
| 632 | * non-resident. Finally, to use compression, the maximum allowed cluster size |
| 633 | * on a volume is 4kib. |
| 634 | * |
| 635 | * The compression method is based on independently compressing blocks of X |
| 636 | * clusters, where X is determined from the compression_unit value found in the |
| 637 | * non-resident attribute record header (more precisely: X = 2^compression_unit |
| 638 | * clusters). On Windows NT/2k, X always is 16 clusters (compression_unit = 4). |
| 639 | * |
| 640 | * There are three different cases of how a compression block of X clusters |
| 641 | * can be stored: |
| 642 | * |
| 643 | * 1) The data in the block is all zero (a sparse block): |
| 644 | * This is stored as a sparse block in the runlist, i.e. the runlist |
| 645 | * entry has length = X and lcn = -1. The mapping pairs array actually |
| 646 | * uses a delta_lcn value length of 0, i.e. delta_lcn is not present at |
| 647 | * all, which is then interpreted by the driver as lcn = -1. |
| 648 | * NOTE: Even uncompressed files can be sparse on NTFS 3.0 volumes, then |
| 649 | * the same principles apply as above, except that the length is not |
| 650 | * restricted to being any particular value. |
| 651 | * |
| 652 | * 2) The data in the block is not compressed: |
| 653 | * This happens when compression doesn't reduce the size of the block |
| 654 | * in clusters. I.e. if compression has a small effect so that the |
| 655 | * compressed data still occupies X clusters, then the uncompressed data |
| 656 | * is stored in the block. |
| 657 | * This case is recognised by the fact that the runlist entry has |
| 658 | * length = X and lcn >= 0. The mapping pairs array stores this as |
| 659 | * normal with a run length of X and some specific delta_lcn, i.e. |
| 660 | * delta_lcn has to be present. |
| 661 | * |
| 662 | * 3) The data in the block is compressed: |
| 663 | * The common case. This case is recognised by the fact that the run |
| 664 | * list entry has length L < X and lcn >= 0. The mapping pairs array |
| 665 | * stores this as normal with a run length of X and some specific |
| 666 | * delta_lcn, i.e. delta_lcn has to be present. This runlist entry is |
| 667 | * immediately followed by a sparse entry with length = X - L and |
| 668 | * lcn = -1. The latter entry is to make up the vcn counting to the |
| 669 | * full compression block size X. |
| 670 | * |
| 671 | * In fact, life is more complicated because adjacent entries of the same type |
| 672 | * can be coalesced. This means that one has to keep track of the number of |
| 673 | * clusters handled and work on a basis of X clusters at a time being one |
| 674 | * block. An example: if length L > X this means that this particular runlist |
| 675 | * entry contains a block of length X and part of one or more blocks of length |
| 676 | * L - X. Another example: if length L < X, this does not necessarily mean that |
| 677 | * the block is compressed as it might be that the lcn changes inside the block |
| 678 | * and hence the following runlist entry describes the continuation of the |
| 679 | * potentially compressed block. The block would be compressed if the |
| 680 | * following runlist entry describes at least X - L sparse clusters, thus |
| 681 | * making up the compression block length as described in point 3 above. (Of |
| 682 | * course, there can be several runlist entries with small lengths so that the |
| 683 | * sparse entry does not follow the first data containing entry with |
| 684 | * length < X.) |
| 685 | * |
| 686 | * NOTE: At the end of the compressed attribute value, there most likely is not |
| 687 | * just the right amount of data to make up a compression block, thus this data |
| 688 | * is not even attempted to be compressed. It is just stored as is, unless |
| 689 | * the number of clusters it occupies is reduced when compressed in which case |
| 690 | * it is stored as a compressed compression block, complete with sparse |
| 691 | * clusters at the end. |
| 692 | */ |
| 693 | |
| 694 | /* |
| 695 | * Flags of resident attributes (8-bit). |
| 696 | */ |
| 697 | enum { |
| 698 | RESIDENT_ATTR_IS_INDEXED = 0x01, /* Attribute is referenced in an index |
| 699 | (has implications for deleting and |
| 700 | modifying the attribute). */ |
| 701 | } __attribute__ ((__packed__)); |
| 702 | |
| 703 | typedef u8 RESIDENT_ATTR_FLAGS; |
| 704 | |
| 705 | /* |
| 706 | * Attribute record header. Always aligned to 8-byte boundary. |
| 707 | */ |
| 708 | typedef struct { |
| 709 | /*Ofs*/ |
| 710 | /* 0*/ ATTR_TYPE type; /* The (32-bit) type of the attribute. */ |
| 711 | /* 4*/ le32 length; /* Byte size of the resident part of the |
| 712 | attribute (aligned to 8-byte boundary). |
| 713 | Used to get to the next attribute. */ |
| 714 | /* 8*/ u8 non_resident; /* If 0, attribute is resident. |
| 715 | If 1, attribute is non-resident. */ |
| 716 | /* 9*/ u8 name_length; /* Unicode character size of name of attribute. |
| 717 | 0 if unnamed. */ |
| 718 | /* 10*/ le16 name_offset; /* If name_length != 0, the byte offset to the |
| 719 | beginning of the name from the attribute |
| 720 | record. Note that the name is stored as a |
| 721 | Unicode string. When creating, place offset |
| 722 | just at the end of the record header. Then, |
| 723 | follow with attribute value or mapping pairs |
| 724 | array, resident and non-resident attributes |
| 725 | respectively, aligning to an 8-byte |
| 726 | boundary. */ |
| 727 | /* 12*/ ATTR_FLAGS flags; /* Flags describing the attribute. */ |
| 728 | /* 14*/ le16 instance; /* The instance of this attribute record. This |
| 729 | number is unique within this mft record (see |
| 730 | MFT_RECORD/next_attribute_instance notes in |
| 731 | in mft.h for more details). */ |
| 732 | /* 16*/ union { |
| 733 | /* Resident attributes. */ |
| 734 | struct { |
| 735 | /* 16 */ le32 value_length;/* Byte size of attribute value. */ |
| 736 | /* 20 */ le16 value_offset;/* Byte offset of the attribute |
| 737 | value from the start of the |
| 738 | attribute record. When creating, |
| 739 | align to 8-byte boundary if we |
| 740 | have a name present as this might |
| 741 | not have a length of a multiple |
| 742 | of 8-bytes. */ |
| 743 | /* 22 */ RESIDENT_ATTR_FLAGS flags; /* See above. */ |
| 744 | /* 23 */ s8 reserved; /* Reserved/alignment to 8-byte |
| 745 | boundary. */ |
| 746 | } __attribute__ ((__packed__)) resident; |
| 747 | /* Non-resident attributes. */ |
| 748 | struct { |
| 749 | /* 16*/ leVCN lowest_vcn;/* Lowest valid virtual cluster number |
| 750 | for this portion of the attribute value or |
| 751 | 0 if this is the only extent (usually the |
| 752 | case). - Only when an attribute list is used |
| 753 | does lowest_vcn != 0 ever occur. */ |
| 754 | /* 24*/ leVCN highest_vcn;/* Highest valid vcn of this extent of |
| 755 | the attribute value. - Usually there is only one |
| 756 | portion, so this usually equals the attribute |
| 757 | value size in clusters minus 1. Can be -1 for |
| 758 | zero length files. Can be 0 for "single extent" |
| 759 | attributes. */ |
| 760 | /* 32*/ le16 mapping_pairs_offset; /* Byte offset from the |
| 761 | beginning of the structure to the mapping pairs |
| 762 | array which contains the mappings between the |
| 763 | vcns and the logical cluster numbers (lcns). |
| 764 | When creating, place this at the end of this |
| 765 | record header aligned to 8-byte boundary. */ |
| 766 | /* 34*/ u8 compression_unit; /* The compression unit expressed |
| 767 | as the log to the base 2 of the number of |
Anton Altaparmakov | 9451f85 | 2005-03-03 14:43:43 +0000 | [diff] [blame] | 768 | clusters in a compression unit. 0 means not |
| 769 | compressed. (This effectively limits the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | compression unit size to be a power of two |
Anton Altaparmakov | 9451f85 | 2005-03-03 14:43:43 +0000 | [diff] [blame] | 771 | clusters.) WinNT4 only uses a value of 4. |
Anton Altaparmakov | a0646a1 | 2006-03-23 15:53:03 +0000 | [diff] [blame] | 772 | Sparse files have this set to 0 on XPSP2. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | /* 35*/ u8 reserved[5]; /* Align to 8-byte boundary. */ |
| 774 | /* The sizes below are only used when lowest_vcn is zero, as otherwise it would |
| 775 | be difficult to keep them up-to-date.*/ |
| 776 | /* 40*/ sle64 allocated_size; /* Byte size of disk space |
| 777 | allocated to hold the attribute value. Always |
| 778 | is a multiple of the cluster size. When a file |
| 779 | is compressed, this field is a multiple of the |
| 780 | compression block size (2^compression_unit) and |
| 781 | it represents the logically allocated space |
| 782 | rather than the actual on disk usage. For this |
| 783 | use the compressed_size (see below). */ |
| 784 | /* 48*/ sle64 data_size; /* Byte size of the attribute |
| 785 | value. Can be larger than allocated_size if |
| 786 | attribute value is compressed or sparse. */ |
| 787 | /* 56*/ sle64 initialized_size; /* Byte size of initialized |
| 788 | portion of the attribute value. Usually equals |
| 789 | data_size. */ |
| 790 | /* sizeof(uncompressed attr) = 64*/ |
| 791 | /* 64*/ sle64 compressed_size; /* Byte size of the attribute |
Anton Altaparmakov | 9451f85 | 2005-03-03 14:43:43 +0000 | [diff] [blame] | 792 | value after compression. Only present when |
| 793 | compressed or sparse. Always is a multiple of |
| 794 | the cluster size. Represents the actual amount |
| 795 | of disk space being used on the disk. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | /* sizeof(compressed attr) = 72*/ |
| 797 | } __attribute__ ((__packed__)) non_resident; |
| 798 | } __attribute__ ((__packed__)) data; |
| 799 | } __attribute__ ((__packed__)) ATTR_RECORD; |
| 800 | |
| 801 | typedef ATTR_RECORD ATTR_REC; |
| 802 | |
| 803 | /* |
Anton Altaparmakov | 2c2c8c1 | 2006-03-23 16:09:40 +0000 | [diff] [blame] | 804 | * File attribute flags (32-bit) appearing in the file_attributes fields of the |
| 805 | * STANDARD_INFORMATION attribute of MFT_RECORDs and the FILENAME_ATTR |
| 806 | * attributes of MFT_RECORDs and directory index entries. |
| 807 | * |
| 808 | * All of the below flags appear in the directory index entries but only some |
| 809 | * appear in the STANDARD_INFORMATION attribute whilst only some others appear |
| 810 | * in the FILENAME_ATTR attribute of MFT_RECORDs. Unless otherwise stated the |
| 811 | * flags appear in all of the above. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | */ |
| 813 | enum { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | FILE_ATTR_READONLY = const_cpu_to_le32(0x00000001), |
| 815 | FILE_ATTR_HIDDEN = const_cpu_to_le32(0x00000002), |
| 816 | FILE_ATTR_SYSTEM = const_cpu_to_le32(0x00000004), |
| 817 | /* Old DOS volid. Unused in NT. = const_cpu_to_le32(0x00000008), */ |
| 818 | |
| 819 | FILE_ATTR_DIRECTORY = const_cpu_to_le32(0x00000010), |
| 820 | /* Note, FILE_ATTR_DIRECTORY is not considered valid in NT. It is |
| 821 | reserved for the DOS SUBDIRECTORY flag. */ |
| 822 | FILE_ATTR_ARCHIVE = const_cpu_to_le32(0x00000020), |
| 823 | FILE_ATTR_DEVICE = const_cpu_to_le32(0x00000040), |
| 824 | FILE_ATTR_NORMAL = const_cpu_to_le32(0x00000080), |
| 825 | |
| 826 | FILE_ATTR_TEMPORARY = const_cpu_to_le32(0x00000100), |
| 827 | FILE_ATTR_SPARSE_FILE = const_cpu_to_le32(0x00000200), |
| 828 | FILE_ATTR_REPARSE_POINT = const_cpu_to_le32(0x00000400), |
| 829 | FILE_ATTR_COMPRESSED = const_cpu_to_le32(0x00000800), |
| 830 | |
| 831 | FILE_ATTR_OFFLINE = const_cpu_to_le32(0x00001000), |
| 832 | FILE_ATTR_NOT_CONTENT_INDEXED = const_cpu_to_le32(0x00002000), |
| 833 | FILE_ATTR_ENCRYPTED = const_cpu_to_le32(0x00004000), |
| 834 | |
| 835 | FILE_ATTR_VALID_FLAGS = const_cpu_to_le32(0x00007fb7), |
| 836 | /* Note, FILE_ATTR_VALID_FLAGS masks out the old DOS VolId and the |
| 837 | FILE_ATTR_DEVICE and preserves everything else. This mask is used |
| 838 | to obtain all flags that are valid for reading. */ |
| 839 | FILE_ATTR_VALID_SET_FLAGS = const_cpu_to_le32(0x000031a7), |
| 840 | /* Note, FILE_ATTR_VALID_SET_FLAGS masks out the old DOS VolId, the |
| 841 | F_A_DEVICE, F_A_DIRECTORY, F_A_SPARSE_FILE, F_A_REPARSE_POINT, |
| 842 | F_A_COMPRESSED, and F_A_ENCRYPTED and preserves the rest. This mask |
| 843 | is used to to obtain all flags that are valid for setting. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | /* |
Anton Altaparmakov | 2c2c8c1 | 2006-03-23 16:09:40 +0000 | [diff] [blame] | 845 | * The flag FILE_ATTR_DUP_FILENAME_INDEX_PRESENT is present in all |
| 846 | * FILENAME_ATTR attributes but not in the STANDARD_INFORMATION |
| 847 | * attribute of an mft record. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | */ |
| 849 | FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT = const_cpu_to_le32(0x10000000), |
| 850 | /* Note, this is a copy of the corresponding bit from the mft record, |
| 851 | telling us whether this is a directory or not, i.e. whether it has |
| 852 | an index root attribute or not. */ |
| 853 | FILE_ATTR_DUP_VIEW_INDEX_PRESENT = const_cpu_to_le32(0x20000000), |
| 854 | /* Note, this is a copy of the corresponding bit from the mft record, |
| 855 | telling us whether this file has a view index present (eg. object id |
| 856 | index, quota index, one of the security indexes or the encrypting |
Anton Altaparmakov | c002f42 | 2005-02-03 12:02:56 +0000 | [diff] [blame] | 857 | filesystem related indexes). */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | }; |
| 859 | |
| 860 | typedef le32 FILE_ATTR_FLAGS; |
| 861 | |
| 862 | /* |
| 863 | * NOTE on times in NTFS: All times are in MS standard time format, i.e. they |
| 864 | * are the number of 100-nanosecond intervals since 1st January 1601, 00:00:00 |
| 865 | * universal coordinated time (UTC). (In Linux time starts 1st January 1970, |
| 866 | * 00:00:00 UTC and is stored as the number of 1-second intervals since then.) |
| 867 | */ |
| 868 | |
| 869 | /* |
| 870 | * Attribute: Standard information (0x10). |
| 871 | * |
| 872 | * NOTE: Always resident. |
| 873 | * NOTE: Present in all base file records on a volume. |
| 874 | * NOTE: There is conflicting information about the meaning of each of the time |
| 875 | * fields but the meaning as defined below has been verified to be |
| 876 | * correct by practical experimentation on Windows NT4 SP6a and is hence |
| 877 | * assumed to be the one and only correct interpretation. |
| 878 | */ |
| 879 | typedef struct { |
| 880 | /*Ofs*/ |
| 881 | /* 0*/ sle64 creation_time; /* Time file was created. Updated when |
| 882 | a filename is changed(?). */ |
| 883 | /* 8*/ sle64 last_data_change_time; /* Time the data attribute was last |
| 884 | modified. */ |
| 885 | /* 16*/ sle64 last_mft_change_time; /* Time this mft record was last |
| 886 | modified. */ |
| 887 | /* 24*/ sle64 last_access_time; /* Approximate time when the file was |
| 888 | last accessed (obviously this is not |
| 889 | updated on read-only volumes). In |
| 890 | Windows this is only updated when |
| 891 | accessed if some time delta has |
| 892 | passed since the last update. Also, |
Anton Altaparmakov | 2c2c8c1 | 2006-03-23 16:09:40 +0000 | [diff] [blame] | 893 | last access time updates can be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | disabled altogether for speed. */ |
| 895 | /* 32*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */ |
| 896 | /* 36*/ union { |
| 897 | /* NTFS 1.2 */ |
| 898 | struct { |
| 899 | /* 36*/ u8 reserved12[12]; /* Reserved/alignment to 8-byte |
| 900 | boundary. */ |
| 901 | } __attribute__ ((__packed__)) v1; |
| 902 | /* sizeof() = 48 bytes */ |
| 903 | /* NTFS 3.x */ |
| 904 | struct { |
| 905 | /* |
| 906 | * If a volume has been upgraded from a previous NTFS version, then these |
| 907 | * fields are present only if the file has been accessed since the upgrade. |
| 908 | * Recognize the difference by comparing the length of the resident attribute |
| 909 | * value. If it is 48, then the following fields are missing. If it is 72 then |
| 910 | * the fields are present. Maybe just check like this: |
| 911 | * if (resident.ValueLength < sizeof(STANDARD_INFORMATION)) { |
| 912 | * Assume NTFS 1.2- format. |
| 913 | * If (volume version is 3.x) |
| 914 | * Upgrade attribute to NTFS 3.x format. |
| 915 | * else |
| 916 | * Use NTFS 1.2- format for access. |
| 917 | * } else |
| 918 | * Use NTFS 3.x format for access. |
| 919 | * Only problem is that it might be legal to set the length of the value to |
| 920 | * arbitrarily large values thus spoiling this check. - But chkdsk probably |
| 921 | * views that as a corruption, assuming that it behaves like this for all |
| 922 | * attributes. |
| 923 | */ |
| 924 | /* 36*/ le32 maximum_versions; /* Maximum allowed versions for |
| 925 | file. Zero if version numbering is disabled. */ |
| 926 | /* 40*/ le32 version_number; /* This file's version (if any). |
| 927 | Set to zero if maximum_versions is zero. */ |
| 928 | /* 44*/ le32 class_id; /* Class id from bidirectional |
| 929 | class id index (?). */ |
| 930 | /* 48*/ le32 owner_id; /* Owner_id of the user owning |
| 931 | the file. Translate via $Q index in FILE_Extend |
| 932 | /$Quota to the quota control entry for the user |
| 933 | owning the file. Zero if quotas are disabled. */ |
| 934 | /* 52*/ le32 security_id; /* Security_id for the file. |
| 935 | Translate via $SII index and $SDS data stream |
| 936 | in FILE_Secure to the security descriptor. */ |
| 937 | /* 56*/ le64 quota_charged; /* Byte size of the charge to |
| 938 | the quota for all streams of the file. Note: Is |
| 939 | zero if quotas are disabled. */ |
Anton Altaparmakov | 9f993fe | 2005-06-25 16:15:36 +0100 | [diff] [blame] | 940 | /* 64*/ leUSN usn; /* Last update sequence number |
Anton Altaparmakov | 3f2faef | 2005-06-25 15:28:56 +0100 | [diff] [blame] | 941 | of the file. This is a direct index into the |
| 942 | transaction log file ($UsnJrnl). It is zero if |
| 943 | the usn journal is disabled or this file has |
| 944 | not been subject to logging yet. See usnjrnl.h |
| 945 | for details. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | } __attribute__ ((__packed__)) v3; |
| 947 | /* sizeof() = 72 bytes (NTFS 3.x) */ |
| 948 | } __attribute__ ((__packed__)) ver; |
| 949 | } __attribute__ ((__packed__)) STANDARD_INFORMATION; |
| 950 | |
| 951 | /* |
| 952 | * Attribute: Attribute list (0x20). |
| 953 | * |
| 954 | * - Can be either resident or non-resident. |
| 955 | * - Value consists of a sequence of variable length, 8-byte aligned, |
| 956 | * ATTR_LIST_ENTRY records. |
| 957 | * - The list is not terminated by anything at all! The only way to know when |
| 958 | * the end is reached is to keep track of the current offset and compare it to |
| 959 | * the attribute value size. |
| 960 | * - The attribute list attribute contains one entry for each attribute of |
| 961 | * the file in which the list is located, except for the list attribute |
| 962 | * itself. The list is sorted: first by attribute type, second by attribute |
| 963 | * name (if present), third by instance number. The extents of one |
| 964 | * non-resident attribute (if present) immediately follow after the initial |
| 965 | * extent. They are ordered by lowest_vcn and have their instace set to zero. |
| 966 | * It is not allowed to have two attributes with all sorting keys equal. |
| 967 | * - Further restrictions: |
| 968 | * - If not resident, the vcn to lcn mapping array has to fit inside the |
| 969 | * base mft record. |
| 970 | * - The attribute list attribute value has a maximum size of 256kb. This |
| 971 | * is imposed by the Windows cache manager. |
| 972 | * - Attribute lists are only used when the attributes of mft record do not |
| 973 | * fit inside the mft record despite all attributes (that can be made |
| 974 | * non-resident) having been made non-resident. This can happen e.g. when: |
| 975 | * - File has a large number of hard links (lots of file name |
| 976 | * attributes present). |
| 977 | * - The mapping pairs array of some non-resident attribute becomes so |
| 978 | * large due to fragmentation that it overflows the mft record. |
| 979 | * - The security descriptor is very complex (not applicable to |
| 980 | * NTFS 3.0 volumes). |
| 981 | * - There are many named streams. |
| 982 | */ |
| 983 | typedef struct { |
| 984 | /*Ofs*/ |
| 985 | /* 0*/ ATTR_TYPE type; /* Type of referenced attribute. */ |
| 986 | /* 4*/ le16 length; /* Byte size of this entry (8-byte aligned). */ |
| 987 | /* 6*/ u8 name_length; /* Size in Unicode chars of the name of the |
| 988 | attribute or 0 if unnamed. */ |
| 989 | /* 7*/ u8 name_offset; /* Byte offset to beginning of attribute name |
| 990 | (always set this to where the name would |
| 991 | start even if unnamed). */ |
| 992 | /* 8*/ leVCN lowest_vcn; /* Lowest virtual cluster number of this portion |
| 993 | of the attribute value. This is usually 0. It |
| 994 | is non-zero for the case where one attribute |
| 995 | does not fit into one mft record and thus |
| 996 | several mft records are allocated to hold |
| 997 | this attribute. In the latter case, each mft |
| 998 | record holds one extent of the attribute and |
| 999 | there is one attribute list entry for each |
| 1000 | extent. NOTE: This is DEFINITELY a signed |
| 1001 | value! The windows driver uses cmp, followed |
| 1002 | by jg when comparing this, thus it treats it |
| 1003 | as signed. */ |
| 1004 | /* 16*/ leMFT_REF mft_reference;/* The reference of the mft record holding |
| 1005 | the ATTR_RECORD for this portion of the |
| 1006 | attribute value. */ |
| 1007 | /* 24*/ le16 instance; /* If lowest_vcn = 0, the instance of the |
| 1008 | attribute being referenced; otherwise 0. */ |
| 1009 | /* 26*/ ntfschar name[0]; /* Use when creating only. When reading use |
| 1010 | name_offset to determine the location of the |
| 1011 | name. */ |
| 1012 | /* sizeof() = 26 + (attribute_name_length * 2) bytes */ |
| 1013 | } __attribute__ ((__packed__)) ATTR_LIST_ENTRY; |
| 1014 | |
| 1015 | /* |
| 1016 | * The maximum allowed length for a file name. |
| 1017 | */ |
| 1018 | #define MAXIMUM_FILE_NAME_LENGTH 255 |
| 1019 | |
| 1020 | /* |
| 1021 | * Possible namespaces for filenames in ntfs (8-bit). |
| 1022 | */ |
| 1023 | enum { |
| 1024 | FILE_NAME_POSIX = 0x00, |
| 1025 | /* This is the largest namespace. It is case sensitive and allows all |
| 1026 | Unicode characters except for: '\0' and '/'. Beware that in |
Anton Altaparmakov | 7d0ffdb | 2005-10-19 12:21:19 +0100 | [diff] [blame] | 1027 | WinNT/2k/2003 by default files which eg have the same name except |
| 1028 | for their case will not be distinguished by the standard utilities |
| 1029 | and thus a "del filename" will delete both "filename" and "fileName" |
| 1030 | without warning. However if for example Services For Unix (SFU) are |
| 1031 | installed and the case sensitive option was enabled at installation |
| 1032 | time, then you can create/access/delete such files. |
| 1033 | Note that even SFU places restrictions on the filenames beyond the |
| 1034 | '\0' and '/' and in particular the following set of characters is |
| 1035 | not allowed: '"', '/', '<', '>', '\'. All other characters, |
| 1036 | including the ones no allowed in WIN32 namespace are allowed. |
| 1037 | Tested with SFU 3.5 (this is now free) running on Windows XP. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | FILE_NAME_WIN32 = 0x01, |
| 1039 | /* The standard WinNT/2k NTFS long filenames. Case insensitive. All |
| 1040 | Unicode chars except: '\0', '"', '*', '/', ':', '<', '>', '?', '\', |
| 1041 | and '|'. Further, names cannot end with a '.' or a space. */ |
| 1042 | FILE_NAME_DOS = 0x02, |
| 1043 | /* The standard DOS filenames (8.3 format). Uppercase only. All 8-bit |
| 1044 | characters greater space, except: '"', '*', '+', ',', '/', ':', ';', |
| 1045 | '<', '=', '>', '?', and '\'. */ |
| 1046 | FILE_NAME_WIN32_AND_DOS = 0x03, |
| 1047 | /* 3 means that both the Win32 and the DOS filenames are identical and |
| 1048 | hence have been saved in this single filename record. */ |
| 1049 | } __attribute__ ((__packed__)); |
| 1050 | |
| 1051 | typedef u8 FILE_NAME_TYPE_FLAGS; |
| 1052 | |
| 1053 | /* |
| 1054 | * Attribute: Filename (0x30). |
| 1055 | * |
| 1056 | * NOTE: Always resident. |
| 1057 | * NOTE: All fields, except the parent_directory, are only updated when the |
| 1058 | * filename is changed. Until then, they just become out of sync with |
| 1059 | * reality and the more up to date values are present in the standard |
| 1060 | * information attribute. |
| 1061 | * NOTE: There is conflicting information about the meaning of each of the time |
| 1062 | * fields but the meaning as defined below has been verified to be |
| 1063 | * correct by practical experimentation on Windows NT4 SP6a and is hence |
| 1064 | * assumed to be the one and only correct interpretation. |
| 1065 | */ |
| 1066 | typedef struct { |
| 1067 | /*hex ofs*/ |
| 1068 | /* 0*/ leMFT_REF parent_directory; /* Directory this filename is |
| 1069 | referenced from. */ |
| 1070 | /* 8*/ sle64 creation_time; /* Time file was created. */ |
| 1071 | /* 10*/ sle64 last_data_change_time; /* Time the data attribute was last |
| 1072 | modified. */ |
| 1073 | /* 18*/ sle64 last_mft_change_time; /* Time this mft record was last |
| 1074 | modified. */ |
| 1075 | /* 20*/ sle64 last_access_time; /* Time this mft record was last |
| 1076 | accessed. */ |
Anton Altaparmakov | 3672b63 | 2006-02-24 09:55:07 +0000 | [diff] [blame] | 1077 | /* 28*/ sle64 allocated_size; /* Byte size of on-disk allocated space |
Anton Altaparmakov | a0646a1 | 2006-03-23 15:53:03 +0000 | [diff] [blame] | 1078 | for the unnamed data attribute. So |
| 1079 | for normal $DATA, this is the |
Anton Altaparmakov | 3672b63 | 2006-02-24 09:55:07 +0000 | [diff] [blame] | 1080 | allocated_size from the unnamed |
| 1081 | $DATA attribute and for compressed |
| 1082 | and/or sparse $DATA, this is the |
| 1083 | compressed_size from the unnamed |
Anton Altaparmakov | a0646a1 | 2006-03-23 15:53:03 +0000 | [diff] [blame] | 1084 | $DATA attribute. For a directory or |
| 1085 | other inode without an unnamed $DATA |
| 1086 | attribute, this is always 0. NOTE: |
| 1087 | This is a multiple of the cluster |
| 1088 | size. */ |
| 1089 | /* 30*/ sle64 data_size; /* Byte size of actual data in unnamed |
| 1090 | data attribute. For a directory or |
| 1091 | other inode without an unnamed $DATA |
| 1092 | attribute, this is always 0. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | /* 38*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */ |
| 1094 | /* 3c*/ union { |
| 1095 | /* 3c*/ struct { |
| 1096 | /* 3c*/ le16 packed_ea_size; /* Size of the buffer needed to |
| 1097 | pack the extended attributes |
| 1098 | (EAs), if such are present.*/ |
| 1099 | /* 3e*/ le16 reserved; /* Reserved for alignment. */ |
| 1100 | } __attribute__ ((__packed__)) ea; |
| 1101 | /* 3c*/ struct { |
| 1102 | /* 3c*/ le32 reparse_point_tag; /* Type of reparse point, |
| 1103 | present only in reparse |
| 1104 | points and only if there are |
| 1105 | no EAs. */ |
| 1106 | } __attribute__ ((__packed__)) rp; |
| 1107 | } __attribute__ ((__packed__)) type; |
| 1108 | /* 40*/ u8 file_name_length; /* Length of file name in |
| 1109 | (Unicode) characters. */ |
| 1110 | /* 41*/ FILE_NAME_TYPE_FLAGS file_name_type; /* Namespace of the file name.*/ |
| 1111 | /* 42*/ ntfschar file_name[0]; /* File name in Unicode. */ |
| 1112 | } __attribute__ ((__packed__)) FILE_NAME_ATTR; |
| 1113 | |
| 1114 | /* |
| 1115 | * GUID structures store globally unique identifiers (GUID). A GUID is a |
| 1116 | * 128-bit value consisting of one group of eight hexadecimal digits, followed |
| 1117 | * by three groups of four hexadecimal digits each, followed by one group of |
| 1118 | * twelve hexadecimal digits. GUIDs are Microsoft's implementation of the |
| 1119 | * distributed computing environment (DCE) universally unique identifier (UUID). |
| 1120 | * Example of a GUID: |
| 1121 | * 1F010768-5A73-BC91-0010A52216A7 |
| 1122 | */ |
| 1123 | typedef struct { |
| 1124 | le32 data1; /* The first eight hexadecimal digits of the GUID. */ |
| 1125 | le16 data2; /* The first group of four hexadecimal digits. */ |
| 1126 | le16 data3; /* The second group of four hexadecimal digits. */ |
| 1127 | u8 data4[8]; /* The first two bytes are the third group of four |
| 1128 | hexadecimal digits. The remaining six bytes are the |
| 1129 | final 12 hexadecimal digits. */ |
| 1130 | } __attribute__ ((__packed__)) GUID; |
| 1131 | |
| 1132 | /* |
| 1133 | * FILE_Extend/$ObjId contains an index named $O. This index contains all |
| 1134 | * object_ids present on the volume as the index keys and the corresponding |
| 1135 | * mft_record numbers as the index entry data parts. The data part (defined |
| 1136 | * below) also contains three other object_ids: |
| 1137 | * birth_volume_id - object_id of FILE_Volume on which the file was first |
| 1138 | * created. Optional (i.e. can be zero). |
| 1139 | * birth_object_id - object_id of file when it was first created. Usually |
| 1140 | * equals the object_id. Optional (i.e. can be zero). |
| 1141 | * domain_id - Reserved (always zero). |
| 1142 | */ |
| 1143 | typedef struct { |
| 1144 | leMFT_REF mft_reference;/* Mft record containing the object_id in |
| 1145 | the index entry key. */ |
| 1146 | union { |
| 1147 | struct { |
| 1148 | GUID birth_volume_id; |
| 1149 | GUID birth_object_id; |
| 1150 | GUID domain_id; |
| 1151 | } __attribute__ ((__packed__)) origin; |
| 1152 | u8 extended_info[48]; |
| 1153 | } __attribute__ ((__packed__)) opt; |
| 1154 | } __attribute__ ((__packed__)) OBJ_ID_INDEX_DATA; |
| 1155 | |
| 1156 | /* |
| 1157 | * Attribute: Object id (NTFS 3.0+) (0x40). |
| 1158 | * |
| 1159 | * NOTE: Always resident. |
| 1160 | */ |
| 1161 | typedef struct { |
| 1162 | GUID object_id; /* Unique id assigned to the |
| 1163 | file.*/ |
| 1164 | /* The following fields are optional. The attribute value size is 16 |
| 1165 | bytes, i.e. sizeof(GUID), if these are not present at all. Note, |
| 1166 | the entries can be present but one or more (or all) can be zero |
| 1167 | meaning that that particular value(s) is(are) not defined. */ |
| 1168 | union { |
| 1169 | struct { |
| 1170 | GUID birth_volume_id; /* Unique id of volume on which |
| 1171 | the file was first created.*/ |
| 1172 | GUID birth_object_id; /* Unique id of file when it was |
| 1173 | first created. */ |
| 1174 | GUID domain_id; /* Reserved, zero. */ |
| 1175 | } __attribute__ ((__packed__)) origin; |
| 1176 | u8 extended_info[48]; |
| 1177 | } __attribute__ ((__packed__)) opt; |
| 1178 | } __attribute__ ((__packed__)) OBJECT_ID_ATTR; |
| 1179 | |
| 1180 | /* |
| 1181 | * The pre-defined IDENTIFIER_AUTHORITIES used as SID_IDENTIFIER_AUTHORITY in |
| 1182 | * the SID structure (see below). |
| 1183 | */ |
| 1184 | //typedef enum { /* SID string prefix. */ |
| 1185 | // SECURITY_NULL_SID_AUTHORITY = {0, 0, 0, 0, 0, 0}, /* S-1-0 */ |
| 1186 | // SECURITY_WORLD_SID_AUTHORITY = {0, 0, 0, 0, 0, 1}, /* S-1-1 */ |
| 1187 | // SECURITY_LOCAL_SID_AUTHORITY = {0, 0, 0, 0, 0, 2}, /* S-1-2 */ |
| 1188 | // SECURITY_CREATOR_SID_AUTHORITY = {0, 0, 0, 0, 0, 3}, /* S-1-3 */ |
| 1189 | // SECURITY_NON_UNIQUE_AUTHORITY = {0, 0, 0, 0, 0, 4}, /* S-1-4 */ |
| 1190 | // SECURITY_NT_SID_AUTHORITY = {0, 0, 0, 0, 0, 5}, /* S-1-5 */ |
| 1191 | //} IDENTIFIER_AUTHORITIES; |
| 1192 | |
| 1193 | /* |
| 1194 | * These relative identifiers (RIDs) are used with the above identifier |
| 1195 | * authorities to make up universal well-known SIDs. |
| 1196 | * |
| 1197 | * Note: The relative identifier (RID) refers to the portion of a SID, which |
| 1198 | * identifies a user or group in relation to the authority that issued the SID. |
| 1199 | * For example, the universal well-known SID Creator Owner ID (S-1-3-0) is |
| 1200 | * made up of the identifier authority SECURITY_CREATOR_SID_AUTHORITY (3) and |
| 1201 | * the relative identifier SECURITY_CREATOR_OWNER_RID (0). |
| 1202 | */ |
| 1203 | typedef enum { /* Identifier authority. */ |
| 1204 | SECURITY_NULL_RID = 0, /* S-1-0 */ |
| 1205 | SECURITY_WORLD_RID = 0, /* S-1-1 */ |
| 1206 | SECURITY_LOCAL_RID = 0, /* S-1-2 */ |
| 1207 | |
| 1208 | SECURITY_CREATOR_OWNER_RID = 0, /* S-1-3 */ |
| 1209 | SECURITY_CREATOR_GROUP_RID = 1, /* S-1-3 */ |
| 1210 | |
| 1211 | SECURITY_CREATOR_OWNER_SERVER_RID = 2, /* S-1-3 */ |
| 1212 | SECURITY_CREATOR_GROUP_SERVER_RID = 3, /* S-1-3 */ |
| 1213 | |
| 1214 | SECURITY_DIALUP_RID = 1, |
| 1215 | SECURITY_NETWORK_RID = 2, |
| 1216 | SECURITY_BATCH_RID = 3, |
| 1217 | SECURITY_INTERACTIVE_RID = 4, |
| 1218 | SECURITY_SERVICE_RID = 6, |
| 1219 | SECURITY_ANONYMOUS_LOGON_RID = 7, |
| 1220 | SECURITY_PROXY_RID = 8, |
| 1221 | SECURITY_ENTERPRISE_CONTROLLERS_RID=9, |
| 1222 | SECURITY_SERVER_LOGON_RID = 9, |
| 1223 | SECURITY_PRINCIPAL_SELF_RID = 0xa, |
| 1224 | SECURITY_AUTHENTICATED_USER_RID = 0xb, |
| 1225 | SECURITY_RESTRICTED_CODE_RID = 0xc, |
| 1226 | SECURITY_TERMINAL_SERVER_RID = 0xd, |
| 1227 | |
| 1228 | SECURITY_LOGON_IDS_RID = 5, |
| 1229 | SECURITY_LOGON_IDS_RID_COUNT = 3, |
| 1230 | |
| 1231 | SECURITY_LOCAL_SYSTEM_RID = 0x12, |
| 1232 | |
| 1233 | SECURITY_NT_NON_UNIQUE = 0x15, |
| 1234 | |
| 1235 | SECURITY_BUILTIN_DOMAIN_RID = 0x20, |
| 1236 | |
| 1237 | /* |
| 1238 | * Well-known domain relative sub-authority values (RIDs). |
| 1239 | */ |
| 1240 | |
| 1241 | /* Users. */ |
| 1242 | DOMAIN_USER_RID_ADMIN = 0x1f4, |
| 1243 | DOMAIN_USER_RID_GUEST = 0x1f5, |
| 1244 | DOMAIN_USER_RID_KRBTGT = 0x1f6, |
| 1245 | |
| 1246 | /* Groups. */ |
| 1247 | DOMAIN_GROUP_RID_ADMINS = 0x200, |
| 1248 | DOMAIN_GROUP_RID_USERS = 0x201, |
| 1249 | DOMAIN_GROUP_RID_GUESTS = 0x202, |
| 1250 | DOMAIN_GROUP_RID_COMPUTERS = 0x203, |
| 1251 | DOMAIN_GROUP_RID_CONTROLLERS = 0x204, |
| 1252 | DOMAIN_GROUP_RID_CERT_ADMINS = 0x205, |
| 1253 | DOMAIN_GROUP_RID_SCHEMA_ADMINS = 0x206, |
| 1254 | DOMAIN_GROUP_RID_ENTERPRISE_ADMINS= 0x207, |
| 1255 | DOMAIN_GROUP_RID_POLICY_ADMINS = 0x208, |
| 1256 | |
| 1257 | /* Aliases. */ |
| 1258 | DOMAIN_ALIAS_RID_ADMINS = 0x220, |
| 1259 | DOMAIN_ALIAS_RID_USERS = 0x221, |
| 1260 | DOMAIN_ALIAS_RID_GUESTS = 0x222, |
| 1261 | DOMAIN_ALIAS_RID_POWER_USERS = 0x223, |
| 1262 | |
| 1263 | DOMAIN_ALIAS_RID_ACCOUNT_OPS = 0x224, |
| 1264 | DOMAIN_ALIAS_RID_SYSTEM_OPS = 0x225, |
| 1265 | DOMAIN_ALIAS_RID_PRINT_OPS = 0x226, |
| 1266 | DOMAIN_ALIAS_RID_BACKUP_OPS = 0x227, |
| 1267 | |
| 1268 | DOMAIN_ALIAS_RID_REPLICATOR = 0x228, |
| 1269 | DOMAIN_ALIAS_RID_RAS_SERVERS = 0x229, |
| 1270 | DOMAIN_ALIAS_RID_PREW2KCOMPACCESS = 0x22a, |
| 1271 | } RELATIVE_IDENTIFIERS; |
| 1272 | |
| 1273 | /* |
| 1274 | * The universal well-known SIDs: |
| 1275 | * |
| 1276 | * NULL_SID S-1-0-0 |
| 1277 | * WORLD_SID S-1-1-0 |
| 1278 | * LOCAL_SID S-1-2-0 |
| 1279 | * CREATOR_OWNER_SID S-1-3-0 |
| 1280 | * CREATOR_GROUP_SID S-1-3-1 |
| 1281 | * CREATOR_OWNER_SERVER_SID S-1-3-2 |
| 1282 | * CREATOR_GROUP_SERVER_SID S-1-3-3 |
| 1283 | * |
| 1284 | * (Non-unique IDs) S-1-4 |
| 1285 | * |
| 1286 | * NT well-known SIDs: |
| 1287 | * |
| 1288 | * NT_AUTHORITY_SID S-1-5 |
| 1289 | * DIALUP_SID S-1-5-1 |
| 1290 | * |
| 1291 | * NETWORD_SID S-1-5-2 |
| 1292 | * BATCH_SID S-1-5-3 |
| 1293 | * INTERACTIVE_SID S-1-5-4 |
| 1294 | * SERVICE_SID S-1-5-6 |
| 1295 | * ANONYMOUS_LOGON_SID S-1-5-7 (aka null logon session) |
| 1296 | * PROXY_SID S-1-5-8 |
| 1297 | * SERVER_LOGON_SID S-1-5-9 (aka domain controller account) |
| 1298 | * SELF_SID S-1-5-10 (self RID) |
| 1299 | * AUTHENTICATED_USER_SID S-1-5-11 |
| 1300 | * RESTRICTED_CODE_SID S-1-5-12 (running restricted code) |
| 1301 | * TERMINAL_SERVER_SID S-1-5-13 (running on terminal server) |
| 1302 | * |
| 1303 | * (Logon IDs) S-1-5-5-X-Y |
| 1304 | * |
| 1305 | * (NT non-unique IDs) S-1-5-0x15-... |
| 1306 | * |
| 1307 | * (Built-in domain) S-1-5-0x20 |
| 1308 | */ |
| 1309 | |
| 1310 | /* |
| 1311 | * The SID_IDENTIFIER_AUTHORITY is a 48-bit value used in the SID structure. |
| 1312 | * |
| 1313 | * NOTE: This is stored as a big endian number, hence the high_part comes |
| 1314 | * before the low_part. |
| 1315 | */ |
| 1316 | typedef union { |
| 1317 | struct { |
| 1318 | u16 high_part; /* High 16-bits. */ |
| 1319 | u32 low_part; /* Low 32-bits. */ |
| 1320 | } __attribute__ ((__packed__)) parts; |
| 1321 | u8 value[6]; /* Value as individual bytes. */ |
| 1322 | } __attribute__ ((__packed__)) SID_IDENTIFIER_AUTHORITY; |
| 1323 | |
| 1324 | /* |
| 1325 | * The SID structure is a variable-length structure used to uniquely identify |
| 1326 | * users or groups. SID stands for security identifier. |
| 1327 | * |
| 1328 | * The standard textual representation of the SID is of the form: |
| 1329 | * S-R-I-S-S... |
| 1330 | * Where: |
| 1331 | * - The first "S" is the literal character 'S' identifying the following |
| 1332 | * digits as a SID. |
| 1333 | * - R is the revision level of the SID expressed as a sequence of digits |
| 1334 | * either in decimal or hexadecimal (if the later, prefixed by "0x"). |
| 1335 | * - I is the 48-bit identifier_authority, expressed as digits as R above. |
| 1336 | * - S... is one or more sub_authority values, expressed as digits as above. |
| 1337 | * |
| 1338 | * Example SID; the domain-relative SID of the local Administrators group on |
| 1339 | * Windows NT/2k: |
| 1340 | * S-1-5-32-544 |
| 1341 | * This translates to a SID with: |
| 1342 | * revision = 1, |
| 1343 | * sub_authority_count = 2, |
| 1344 | * identifier_authority = {0,0,0,0,0,5}, // SECURITY_NT_AUTHORITY |
| 1345 | * sub_authority[0] = 32, // SECURITY_BUILTIN_DOMAIN_RID |
| 1346 | * sub_authority[1] = 544 // DOMAIN_ALIAS_RID_ADMINS |
| 1347 | */ |
| 1348 | typedef struct { |
| 1349 | u8 revision; |
| 1350 | u8 sub_authority_count; |
| 1351 | SID_IDENTIFIER_AUTHORITY identifier_authority; |
| 1352 | le32 sub_authority[1]; /* At least one sub_authority. */ |
| 1353 | } __attribute__ ((__packed__)) SID; |
| 1354 | |
| 1355 | /* |
| 1356 | * Current constants for SIDs. |
| 1357 | */ |
| 1358 | typedef enum { |
| 1359 | SID_REVISION = 1, /* Current revision level. */ |
| 1360 | SID_MAX_SUB_AUTHORITIES = 15, /* Maximum number of those. */ |
| 1361 | SID_RECOMMENDED_SUB_AUTHORITIES = 1, /* Will change to around 6 in |
| 1362 | a future revision. */ |
| 1363 | } SID_CONSTANTS; |
| 1364 | |
| 1365 | /* |
| 1366 | * The predefined ACE types (8-bit, see below). |
| 1367 | */ |
| 1368 | enum { |
| 1369 | ACCESS_MIN_MS_ACE_TYPE = 0, |
| 1370 | ACCESS_ALLOWED_ACE_TYPE = 0, |
| 1371 | ACCESS_DENIED_ACE_TYPE = 1, |
| 1372 | SYSTEM_AUDIT_ACE_TYPE = 2, |
| 1373 | SYSTEM_ALARM_ACE_TYPE = 3, /* Not implemented as of Win2k. */ |
| 1374 | ACCESS_MAX_MS_V2_ACE_TYPE = 3, |
| 1375 | |
| 1376 | ACCESS_ALLOWED_COMPOUND_ACE_TYPE= 4, |
| 1377 | ACCESS_MAX_MS_V3_ACE_TYPE = 4, |
| 1378 | |
| 1379 | /* The following are Win2k only. */ |
| 1380 | ACCESS_MIN_MS_OBJECT_ACE_TYPE = 5, |
| 1381 | ACCESS_ALLOWED_OBJECT_ACE_TYPE = 5, |
| 1382 | ACCESS_DENIED_OBJECT_ACE_TYPE = 6, |
| 1383 | SYSTEM_AUDIT_OBJECT_ACE_TYPE = 7, |
| 1384 | SYSTEM_ALARM_OBJECT_ACE_TYPE = 8, |
| 1385 | ACCESS_MAX_MS_OBJECT_ACE_TYPE = 8, |
| 1386 | |
| 1387 | ACCESS_MAX_MS_V4_ACE_TYPE = 8, |
| 1388 | |
| 1389 | /* This one is for WinNT/2k. */ |
| 1390 | ACCESS_MAX_MS_ACE_TYPE = 8, |
| 1391 | } __attribute__ ((__packed__)); |
| 1392 | |
| 1393 | typedef u8 ACE_TYPES; |
| 1394 | |
| 1395 | /* |
| 1396 | * The ACE flags (8-bit) for audit and inheritance (see below). |
| 1397 | * |
| 1398 | * SUCCESSFUL_ACCESS_ACE_FLAG is only used with system audit and alarm ACE |
| 1399 | * types to indicate that a message is generated (in Windows!) for successful |
| 1400 | * accesses. |
| 1401 | * |
| 1402 | * FAILED_ACCESS_ACE_FLAG is only used with system audit and alarm ACE types |
| 1403 | * to indicate that a message is generated (in Windows!) for failed accesses. |
| 1404 | */ |
| 1405 | enum { |
| 1406 | /* The inheritance flags. */ |
| 1407 | OBJECT_INHERIT_ACE = 0x01, |
| 1408 | CONTAINER_INHERIT_ACE = 0x02, |
| 1409 | NO_PROPAGATE_INHERIT_ACE = 0x04, |
| 1410 | INHERIT_ONLY_ACE = 0x08, |
| 1411 | INHERITED_ACE = 0x10, /* Win2k only. */ |
| 1412 | VALID_INHERIT_FLAGS = 0x1f, |
| 1413 | |
| 1414 | /* The audit flags. */ |
| 1415 | SUCCESSFUL_ACCESS_ACE_FLAG = 0x40, |
| 1416 | FAILED_ACCESS_ACE_FLAG = 0x80, |
| 1417 | } __attribute__ ((__packed__)); |
| 1418 | |
| 1419 | typedef u8 ACE_FLAGS; |
| 1420 | |
| 1421 | /* |
| 1422 | * An ACE is an access-control entry in an access-control list (ACL). |
| 1423 | * An ACE defines access to an object for a specific user or group or defines |
| 1424 | * the types of access that generate system-administration messages or alarms |
| 1425 | * for a specific user or group. The user or group is identified by a security |
| 1426 | * identifier (SID). |
| 1427 | * |
| 1428 | * Each ACE starts with an ACE_HEADER structure (aligned on 4-byte boundary), |
| 1429 | * which specifies the type and size of the ACE. The format of the subsequent |
| 1430 | * data depends on the ACE type. |
| 1431 | */ |
| 1432 | typedef struct { |
| 1433 | /*Ofs*/ |
| 1434 | /* 0*/ ACE_TYPES type; /* Type of the ACE. */ |
| 1435 | /* 1*/ ACE_FLAGS flags; /* Flags describing the ACE. */ |
| 1436 | /* 2*/ le16 size; /* Size in bytes of the ACE. */ |
| 1437 | } __attribute__ ((__packed__)) ACE_HEADER; |
| 1438 | |
| 1439 | /* |
| 1440 | * The access mask (32-bit). Defines the access rights. |
| 1441 | * |
| 1442 | * The specific rights (bits 0 to 15). These depend on the type of the object |
| 1443 | * being secured by the ACE. |
| 1444 | */ |
| 1445 | enum { |
| 1446 | /* Specific rights for files and directories are as follows: */ |
| 1447 | |
| 1448 | /* Right to read data from the file. (FILE) */ |
| 1449 | FILE_READ_DATA = const_cpu_to_le32(0x00000001), |
| 1450 | /* Right to list contents of a directory. (DIRECTORY) */ |
| 1451 | FILE_LIST_DIRECTORY = const_cpu_to_le32(0x00000001), |
| 1452 | |
| 1453 | /* Right to write data to the file. (FILE) */ |
| 1454 | FILE_WRITE_DATA = const_cpu_to_le32(0x00000002), |
| 1455 | /* Right to create a file in the directory. (DIRECTORY) */ |
| 1456 | FILE_ADD_FILE = const_cpu_to_le32(0x00000002), |
| 1457 | |
| 1458 | /* Right to append data to the file. (FILE) */ |
| 1459 | FILE_APPEND_DATA = const_cpu_to_le32(0x00000004), |
| 1460 | /* Right to create a subdirectory. (DIRECTORY) */ |
| 1461 | FILE_ADD_SUBDIRECTORY = const_cpu_to_le32(0x00000004), |
| 1462 | |
| 1463 | /* Right to read extended attributes. (FILE/DIRECTORY) */ |
| 1464 | FILE_READ_EA = const_cpu_to_le32(0x00000008), |
| 1465 | |
| 1466 | /* Right to write extended attributes. (FILE/DIRECTORY) */ |
| 1467 | FILE_WRITE_EA = const_cpu_to_le32(0x00000010), |
| 1468 | |
| 1469 | /* Right to execute a file. (FILE) */ |
| 1470 | FILE_EXECUTE = const_cpu_to_le32(0x00000020), |
| 1471 | /* Right to traverse the directory. (DIRECTORY) */ |
| 1472 | FILE_TRAVERSE = const_cpu_to_le32(0x00000020), |
| 1473 | |
| 1474 | /* |
| 1475 | * Right to delete a directory and all the files it contains (its |
| 1476 | * children), even if the files are read-only. (DIRECTORY) |
| 1477 | */ |
| 1478 | FILE_DELETE_CHILD = const_cpu_to_le32(0x00000040), |
| 1479 | |
| 1480 | /* Right to read file attributes. (FILE/DIRECTORY) */ |
| 1481 | FILE_READ_ATTRIBUTES = const_cpu_to_le32(0x00000080), |
| 1482 | |
| 1483 | /* Right to change file attributes. (FILE/DIRECTORY) */ |
| 1484 | FILE_WRITE_ATTRIBUTES = const_cpu_to_le32(0x00000100), |
| 1485 | |
| 1486 | /* |
| 1487 | * The standard rights (bits 16 to 23). These are independent of the |
| 1488 | * type of object being secured. |
| 1489 | */ |
| 1490 | |
| 1491 | /* Right to delete the object. */ |
| 1492 | DELETE = const_cpu_to_le32(0x00010000), |
| 1493 | |
| 1494 | /* |
| 1495 | * Right to read the information in the object's security descriptor, |
| 1496 | * not including the information in the SACL, i.e. right to read the |
| 1497 | * security descriptor and owner. |
| 1498 | */ |
| 1499 | READ_CONTROL = const_cpu_to_le32(0x00020000), |
| 1500 | |
| 1501 | /* Right to modify the DACL in the object's security descriptor. */ |
| 1502 | WRITE_DAC = const_cpu_to_le32(0x00040000), |
| 1503 | |
| 1504 | /* Right to change the owner in the object's security descriptor. */ |
| 1505 | WRITE_OWNER = const_cpu_to_le32(0x00080000), |
| 1506 | |
| 1507 | /* |
| 1508 | * Right to use the object for synchronization. Enables a process to |
| 1509 | * wait until the object is in the signalled state. Some object types |
| 1510 | * do not support this access right. |
| 1511 | */ |
| 1512 | SYNCHRONIZE = const_cpu_to_le32(0x00100000), |
| 1513 | |
| 1514 | /* |
| 1515 | * The following STANDARD_RIGHTS_* are combinations of the above for |
| 1516 | * convenience and are defined by the Win32 API. |
| 1517 | */ |
| 1518 | |
| 1519 | /* These are currently defined to READ_CONTROL. */ |
| 1520 | STANDARD_RIGHTS_READ = const_cpu_to_le32(0x00020000), |
| 1521 | STANDARD_RIGHTS_WRITE = const_cpu_to_le32(0x00020000), |
| 1522 | STANDARD_RIGHTS_EXECUTE = const_cpu_to_le32(0x00020000), |
| 1523 | |
| 1524 | /* Combines DELETE, READ_CONTROL, WRITE_DAC, and WRITE_OWNER access. */ |
| 1525 | STANDARD_RIGHTS_REQUIRED = const_cpu_to_le32(0x000f0000), |
| 1526 | |
| 1527 | /* |
| 1528 | * Combines DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, and |
| 1529 | * SYNCHRONIZE access. |
| 1530 | */ |
| 1531 | STANDARD_RIGHTS_ALL = const_cpu_to_le32(0x001f0000), |
| 1532 | |
| 1533 | /* |
| 1534 | * The access system ACL and maximum allowed access types (bits 24 to |
| 1535 | * 25, bits 26 to 27 are reserved). |
| 1536 | */ |
| 1537 | ACCESS_SYSTEM_SECURITY = const_cpu_to_le32(0x01000000), |
| 1538 | MAXIMUM_ALLOWED = const_cpu_to_le32(0x02000000), |
| 1539 | |
| 1540 | /* |
| 1541 | * The generic rights (bits 28 to 31). These map onto the standard and |
| 1542 | * specific rights. |
| 1543 | */ |
| 1544 | |
| 1545 | /* Read, write, and execute access. */ |
| 1546 | GENERIC_ALL = const_cpu_to_le32(0x10000000), |
| 1547 | |
| 1548 | /* Execute access. */ |
| 1549 | GENERIC_EXECUTE = const_cpu_to_le32(0x20000000), |
| 1550 | |
| 1551 | /* |
| 1552 | * Write access. For files, this maps onto: |
| 1553 | * FILE_APPEND_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_DATA | |
| 1554 | * FILE_WRITE_EA | STANDARD_RIGHTS_WRITE | SYNCHRONIZE |
| 1555 | * For directories, the mapping has the same numerical value. See |
| 1556 | * above for the descriptions of the rights granted. |
| 1557 | */ |
| 1558 | GENERIC_WRITE = const_cpu_to_le32(0x40000000), |
| 1559 | |
| 1560 | /* |
| 1561 | * Read access. For files, this maps onto: |
| 1562 | * FILE_READ_ATTRIBUTES | FILE_READ_DATA | FILE_READ_EA | |
| 1563 | * STANDARD_RIGHTS_READ | SYNCHRONIZE |
| 1564 | * For directories, the mapping has the same numberical value. See |
| 1565 | * above for the descriptions of the rights granted. |
| 1566 | */ |
| 1567 | GENERIC_READ = const_cpu_to_le32(0x80000000), |
| 1568 | }; |
| 1569 | |
| 1570 | typedef le32 ACCESS_MASK; |
| 1571 | |
| 1572 | /* |
| 1573 | * The generic mapping array. Used to denote the mapping of each generic |
| 1574 | * access right to a specific access mask. |
| 1575 | * |
| 1576 | * FIXME: What exactly is this and what is it for? (AIA) |
| 1577 | */ |
| 1578 | typedef struct { |
| 1579 | ACCESS_MASK generic_read; |
| 1580 | ACCESS_MASK generic_write; |
| 1581 | ACCESS_MASK generic_execute; |
| 1582 | ACCESS_MASK generic_all; |
| 1583 | } __attribute__ ((__packed__)) GENERIC_MAPPING; |
| 1584 | |
| 1585 | /* |
| 1586 | * The predefined ACE type structures are as defined below. |
| 1587 | */ |
| 1588 | |
| 1589 | /* |
| 1590 | * ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE |
| 1591 | */ |
| 1592 | typedef struct { |
| 1593 | /* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */ |
| 1594 | ACE_TYPES type; /* Type of the ACE. */ |
| 1595 | ACE_FLAGS flags; /* Flags describing the ACE. */ |
| 1596 | le16 size; /* Size in bytes of the ACE. */ |
| 1597 | /* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */ |
| 1598 | |
| 1599 | /* 8*/ SID sid; /* The SID associated with the ACE. */ |
| 1600 | } __attribute__ ((__packed__)) ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, |
| 1601 | SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE; |
| 1602 | |
| 1603 | /* |
| 1604 | * The object ACE flags (32-bit). |
| 1605 | */ |
| 1606 | enum { |
| 1607 | ACE_OBJECT_TYPE_PRESENT = const_cpu_to_le32(1), |
| 1608 | ACE_INHERITED_OBJECT_TYPE_PRESENT = const_cpu_to_le32(2), |
| 1609 | }; |
| 1610 | |
| 1611 | typedef le32 OBJECT_ACE_FLAGS; |
| 1612 | |
| 1613 | typedef struct { |
| 1614 | /* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */ |
| 1615 | ACE_TYPES type; /* Type of the ACE. */ |
| 1616 | ACE_FLAGS flags; /* Flags describing the ACE. */ |
| 1617 | le16 size; /* Size in bytes of the ACE. */ |
| 1618 | /* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */ |
| 1619 | |
| 1620 | /* 8*/ OBJECT_ACE_FLAGS object_flags; /* Flags describing the object ACE. */ |
| 1621 | /* 12*/ GUID object_type; |
| 1622 | /* 28*/ GUID inherited_object_type; |
| 1623 | |
| 1624 | /* 44*/ SID sid; /* The SID associated with the ACE. */ |
| 1625 | } __attribute__ ((__packed__)) ACCESS_ALLOWED_OBJECT_ACE, |
| 1626 | ACCESS_DENIED_OBJECT_ACE, |
| 1627 | SYSTEM_AUDIT_OBJECT_ACE, |
| 1628 | SYSTEM_ALARM_OBJECT_ACE; |
| 1629 | |
| 1630 | /* |
| 1631 | * An ACL is an access-control list (ACL). |
| 1632 | * An ACL starts with an ACL header structure, which specifies the size of |
| 1633 | * the ACL and the number of ACEs it contains. The ACL header is followed by |
| 1634 | * zero or more access control entries (ACEs). The ACL as well as each ACE |
| 1635 | * are aligned on 4-byte boundaries. |
| 1636 | */ |
| 1637 | typedef struct { |
| 1638 | u8 revision; /* Revision of this ACL. */ |
| 1639 | u8 alignment1; |
| 1640 | le16 size; /* Allocated space in bytes for ACL. Includes this |
| 1641 | header, the ACEs and the remaining free space. */ |
| 1642 | le16 ace_count; /* Number of ACEs in the ACL. */ |
| 1643 | le16 alignment2; |
| 1644 | /* sizeof() = 8 bytes */ |
| 1645 | } __attribute__ ((__packed__)) ACL; |
| 1646 | |
| 1647 | /* |
| 1648 | * Current constants for ACLs. |
| 1649 | */ |
| 1650 | typedef enum { |
| 1651 | /* Current revision. */ |
| 1652 | ACL_REVISION = 2, |
| 1653 | ACL_REVISION_DS = 4, |
| 1654 | |
| 1655 | /* History of revisions. */ |
| 1656 | ACL_REVISION1 = 1, |
| 1657 | MIN_ACL_REVISION = 2, |
| 1658 | ACL_REVISION2 = 2, |
| 1659 | ACL_REVISION3 = 3, |
| 1660 | ACL_REVISION4 = 4, |
| 1661 | MAX_ACL_REVISION = 4, |
| 1662 | } ACL_CONSTANTS; |
| 1663 | |
| 1664 | /* |
| 1665 | * The security descriptor control flags (16-bit). |
| 1666 | * |
| 1667 | * SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the SID |
| 1668 | * pointed to by the Owner field was provided by a defaulting mechanism |
| 1669 | * rather than explicitly provided by the original provider of the |
| 1670 | * security descriptor. This may affect the treatment of the SID with |
| 1671 | * respect to inheritence of an owner. |
| 1672 | * |
| 1673 | * SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the SID in |
| 1674 | * the Group field was provided by a defaulting mechanism rather than |
| 1675 | * explicitly provided by the original provider of the security |
| 1676 | * descriptor. This may affect the treatment of the SID with respect to |
| 1677 | * inheritence of a primary group. |
| 1678 | * |
| 1679 | * SE_DACL_PRESENT - This boolean flag, when set, indicates that the security |
| 1680 | * descriptor contains a discretionary ACL. If this flag is set and the |
| 1681 | * Dacl field of the SECURITY_DESCRIPTOR is null, then a null ACL is |
| 1682 | * explicitly being specified. |
| 1683 | * |
| 1684 | * SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the ACL |
| 1685 | * pointed to by the Dacl field was provided by a defaulting mechanism |
| 1686 | * rather than explicitly provided by the original provider of the |
| 1687 | * security descriptor. This may affect the treatment of the ACL with |
| 1688 | * respect to inheritence of an ACL. This flag is ignored if the |
| 1689 | * DaclPresent flag is not set. |
| 1690 | * |
| 1691 | * SE_SACL_PRESENT - This boolean flag, when set, indicates that the security |
| 1692 | * descriptor contains a system ACL pointed to by the Sacl field. If this |
| 1693 | * flag is set and the Sacl field of the SECURITY_DESCRIPTOR is null, then |
| 1694 | * an empty (but present) ACL is being specified. |
| 1695 | * |
| 1696 | * SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the ACL |
| 1697 | * pointed to by the Sacl field was provided by a defaulting mechanism |
| 1698 | * rather than explicitly provided by the original provider of the |
| 1699 | * security descriptor. This may affect the treatment of the ACL with |
| 1700 | * respect to inheritence of an ACL. This flag is ignored if the |
| 1701 | * SaclPresent flag is not set. |
| 1702 | * |
| 1703 | * SE_SELF_RELATIVE - This boolean flag, when set, indicates that the security |
| 1704 | * descriptor is in self-relative form. In this form, all fields of the |
| 1705 | * security descriptor are contiguous in memory and all pointer fields are |
| 1706 | * expressed as offsets from the beginning of the security descriptor. |
| 1707 | */ |
| 1708 | enum { |
| 1709 | SE_OWNER_DEFAULTED = const_cpu_to_le16(0x0001), |
| 1710 | SE_GROUP_DEFAULTED = const_cpu_to_le16(0x0002), |
| 1711 | SE_DACL_PRESENT = const_cpu_to_le16(0x0004), |
| 1712 | SE_DACL_DEFAULTED = const_cpu_to_le16(0x0008), |
| 1713 | |
| 1714 | SE_SACL_PRESENT = const_cpu_to_le16(0x0010), |
| 1715 | SE_SACL_DEFAULTED = const_cpu_to_le16(0x0020), |
| 1716 | |
| 1717 | SE_DACL_AUTO_INHERIT_REQ = const_cpu_to_le16(0x0100), |
| 1718 | SE_SACL_AUTO_INHERIT_REQ = const_cpu_to_le16(0x0200), |
| 1719 | SE_DACL_AUTO_INHERITED = const_cpu_to_le16(0x0400), |
| 1720 | SE_SACL_AUTO_INHERITED = const_cpu_to_le16(0x0800), |
| 1721 | |
| 1722 | SE_DACL_PROTECTED = const_cpu_to_le16(0x1000), |
| 1723 | SE_SACL_PROTECTED = const_cpu_to_le16(0x2000), |
| 1724 | SE_RM_CONTROL_VALID = const_cpu_to_le16(0x4000), |
| 1725 | SE_SELF_RELATIVE = const_cpu_to_le16(0x8000) |
| 1726 | } __attribute__ ((__packed__)); |
| 1727 | |
| 1728 | typedef le16 SECURITY_DESCRIPTOR_CONTROL; |
| 1729 | |
| 1730 | /* |
| 1731 | * Self-relative security descriptor. Contains the owner and group SIDs as well |
| 1732 | * as the sacl and dacl ACLs inside the security descriptor itself. |
| 1733 | */ |
| 1734 | typedef struct { |
| 1735 | u8 revision; /* Revision level of the security descriptor. */ |
| 1736 | u8 alignment; |
| 1737 | SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of |
| 1738 | the descriptor as well as the following fields. */ |
| 1739 | le32 owner; /* Byte offset to a SID representing an object's |
| 1740 | owner. If this is NULL, no owner SID is present in |
| 1741 | the descriptor. */ |
| 1742 | le32 group; /* Byte offset to a SID representing an object's |
| 1743 | primary group. If this is NULL, no primary group |
| 1744 | SID is present in the descriptor. */ |
| 1745 | le32 sacl; /* Byte offset to a system ACL. Only valid, if |
| 1746 | SE_SACL_PRESENT is set in the control field. If |
| 1747 | SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL |
| 1748 | is specified. */ |
| 1749 | le32 dacl; /* Byte offset to a discretionary ACL. Only valid, if |
| 1750 | SE_DACL_PRESENT is set in the control field. If |
| 1751 | SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL |
| 1752 | (unconditionally granting access) is specified. */ |
| 1753 | /* sizeof() = 0x14 bytes */ |
| 1754 | } __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_RELATIVE; |
| 1755 | |
| 1756 | /* |
| 1757 | * Absolute security descriptor. Does not contain the owner and group SIDs, nor |
| 1758 | * the sacl and dacl ACLs inside the security descriptor. Instead, it contains |
| 1759 | * pointers to these structures in memory. Obviously, absolute security |
| 1760 | * descriptors are only useful for in memory representations of security |
| 1761 | * descriptors. On disk, a self-relative security descriptor is used. |
| 1762 | */ |
| 1763 | typedef struct { |
| 1764 | u8 revision; /* Revision level of the security descriptor. */ |
| 1765 | u8 alignment; |
| 1766 | SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of |
| 1767 | the descriptor as well as the following fields. */ |
| 1768 | SID *owner; /* Points to a SID representing an object's owner. If |
| 1769 | this is NULL, no owner SID is present in the |
| 1770 | descriptor. */ |
| 1771 | SID *group; /* Points to a SID representing an object's primary |
| 1772 | group. If this is NULL, no primary group SID is |
| 1773 | present in the descriptor. */ |
| 1774 | ACL *sacl; /* Points to a system ACL. Only valid, if |
| 1775 | SE_SACL_PRESENT is set in the control field. If |
| 1776 | SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL |
| 1777 | is specified. */ |
| 1778 | ACL *dacl; /* Points to a discretionary ACL. Only valid, if |
| 1779 | SE_DACL_PRESENT is set in the control field. If |
| 1780 | SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL |
| 1781 | (unconditionally granting access) is specified. */ |
| 1782 | } __attribute__ ((__packed__)) SECURITY_DESCRIPTOR; |
| 1783 | |
| 1784 | /* |
| 1785 | * Current constants for security descriptors. |
| 1786 | */ |
| 1787 | typedef enum { |
| 1788 | /* Current revision. */ |
| 1789 | SECURITY_DESCRIPTOR_REVISION = 1, |
| 1790 | SECURITY_DESCRIPTOR_REVISION1 = 1, |
| 1791 | |
| 1792 | /* The sizes of both the absolute and relative security descriptors is |
| 1793 | the same as pointers, at least on ia32 architecture are 32-bit. */ |
| 1794 | SECURITY_DESCRIPTOR_MIN_LENGTH = sizeof(SECURITY_DESCRIPTOR), |
| 1795 | } SECURITY_DESCRIPTOR_CONSTANTS; |
| 1796 | |
| 1797 | /* |
| 1798 | * Attribute: Security descriptor (0x50). A standard self-relative security |
| 1799 | * descriptor. |
| 1800 | * |
| 1801 | * NOTE: Can be resident or non-resident. |
| 1802 | * NOTE: Not used in NTFS 3.0+, as security descriptors are stored centrally |
| 1803 | * in FILE_Secure and the correct descriptor is found using the security_id |
| 1804 | * from the standard information attribute. |
| 1805 | */ |
| 1806 | typedef SECURITY_DESCRIPTOR_RELATIVE SECURITY_DESCRIPTOR_ATTR; |
| 1807 | |
| 1808 | /* |
| 1809 | * On NTFS 3.0+, all security descriptors are stored in FILE_Secure. Only one |
| 1810 | * referenced instance of each unique security descriptor is stored. |
| 1811 | * |
| 1812 | * FILE_Secure contains no unnamed data attribute, i.e. it has zero length. It |
| 1813 | * does, however, contain two indexes ($SDH and $SII) as well as a named data |
| 1814 | * stream ($SDS). |
| 1815 | * |
| 1816 | * Every unique security descriptor is assigned a unique security identifier |
| 1817 | * (security_id, not to be confused with a SID). The security_id is unique for |
| 1818 | * the NTFS volume and is used as an index into the $SII index, which maps |
| 1819 | * security_ids to the security descriptor's storage location within the $SDS |
| 1820 | * data attribute. The $SII index is sorted by ascending security_id. |
| 1821 | * |
| 1822 | * A simple hash is computed from each security descriptor. This hash is used |
| 1823 | * as an index into the $SDH index, which maps security descriptor hashes to |
| 1824 | * the security descriptor's storage location within the $SDS data attribute. |
| 1825 | * The $SDH index is sorted by security descriptor hash and is stored in a B+ |
| 1826 | * tree. When searching $SDH (with the intent of determining whether or not a |
| 1827 | * new security descriptor is already present in the $SDS data stream), if a |
| 1828 | * matching hash is found, but the security descriptors do not match, the |
| 1829 | * search in the $SDH index is continued, searching for a next matching hash. |
| 1830 | * |
| 1831 | * When a precise match is found, the security_id coresponding to the security |
| 1832 | * descriptor in the $SDS attribute is read from the found $SDH index entry and |
| 1833 | * is stored in the $STANDARD_INFORMATION attribute of the file/directory to |
| 1834 | * which the security descriptor is being applied. The $STANDARD_INFORMATION |
| 1835 | * attribute is present in all base mft records (i.e. in all files and |
| 1836 | * directories). |
| 1837 | * |
| 1838 | * If a match is not found, the security descriptor is assigned a new unique |
| 1839 | * security_id and is added to the $SDS data attribute. Then, entries |
| 1840 | * referencing the this security descriptor in the $SDS data attribute are |
| 1841 | * added to the $SDH and $SII indexes. |
| 1842 | * |
| 1843 | * Note: Entries are never deleted from FILE_Secure, even if nothing |
| 1844 | * references an entry any more. |
| 1845 | */ |
| 1846 | |
| 1847 | /* |
| 1848 | * This header precedes each security descriptor in the $SDS data stream. |
| 1849 | * This is also the index entry data part of both the $SII and $SDH indexes. |
| 1850 | */ |
| 1851 | typedef struct { |
| 1852 | le32 hash; /* Hash of the security descriptor. */ |
| 1853 | le32 security_id; /* The security_id assigned to the descriptor. */ |
| 1854 | le64 offset; /* Byte offset of this entry in the $SDS stream. */ |
| 1855 | le32 length; /* Size in bytes of this entry in $SDS stream. */ |
| 1856 | } __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_HEADER; |
| 1857 | |
| 1858 | /* |
| 1859 | * The $SDS data stream contains the security descriptors, aligned on 16-byte |
| 1860 | * boundaries, sorted by security_id in a B+ tree. Security descriptors cannot |
| 1861 | * cross 256kib boundaries (this restriction is imposed by the Windows cache |
| 1862 | * manager). Each security descriptor is contained in a SDS_ENTRY structure. |
| 1863 | * Also, each security descriptor is stored twice in the $SDS stream with a |
| 1864 | * fixed offset of 0x40000 bytes (256kib, the Windows cache manager's max size) |
| 1865 | * between them; i.e. if a SDS_ENTRY specifies an offset of 0x51d0, then the |
| 1866 | * the first copy of the security descriptor will be at offset 0x51d0 in the |
| 1867 | * $SDS data stream and the second copy will be at offset 0x451d0. |
| 1868 | */ |
| 1869 | typedef struct { |
| 1870 | /*Ofs*/ |
| 1871 | /* 0 SECURITY_DESCRIPTOR_HEADER; -- Unfolded here as gcc doesn't like |
| 1872 | unnamed structs. */ |
| 1873 | le32 hash; /* Hash of the security descriptor. */ |
| 1874 | le32 security_id; /* The security_id assigned to the descriptor. */ |
| 1875 | le64 offset; /* Byte offset of this entry in the $SDS stream. */ |
| 1876 | le32 length; /* Size in bytes of this entry in $SDS stream. */ |
| 1877 | /* 20*/ SECURITY_DESCRIPTOR_RELATIVE sid; /* The self-relative security |
| 1878 | descriptor. */ |
| 1879 | } __attribute__ ((__packed__)) SDS_ENTRY; |
| 1880 | |
| 1881 | /* |
| 1882 | * The index entry key used in the $SII index. The collation type is |
| 1883 | * COLLATION_NTOFS_ULONG. |
| 1884 | */ |
| 1885 | typedef struct { |
| 1886 | le32 security_id; /* The security_id assigned to the descriptor. */ |
| 1887 | } __attribute__ ((__packed__)) SII_INDEX_KEY; |
| 1888 | |
| 1889 | /* |
| 1890 | * The index entry key used in the $SDH index. The keys are sorted first by |
| 1891 | * hash and then by security_id. The collation rule is |
| 1892 | * COLLATION_NTOFS_SECURITY_HASH. |
| 1893 | */ |
| 1894 | typedef struct { |
| 1895 | le32 hash; /* Hash of the security descriptor. */ |
| 1896 | le32 security_id; /* The security_id assigned to the descriptor. */ |
| 1897 | } __attribute__ ((__packed__)) SDH_INDEX_KEY; |
| 1898 | |
| 1899 | /* |
| 1900 | * Attribute: Volume name (0x60). |
| 1901 | * |
| 1902 | * NOTE: Always resident. |
| 1903 | * NOTE: Present only in FILE_Volume. |
| 1904 | */ |
| 1905 | typedef struct { |
| 1906 | ntfschar name[0]; /* The name of the volume in Unicode. */ |
| 1907 | } __attribute__ ((__packed__)) VOLUME_NAME; |
| 1908 | |
| 1909 | /* |
| 1910 | * Possible flags for the volume (16-bit). |
| 1911 | */ |
| 1912 | enum { |
| 1913 | VOLUME_IS_DIRTY = const_cpu_to_le16(0x0001), |
| 1914 | VOLUME_RESIZE_LOG_FILE = const_cpu_to_le16(0x0002), |
| 1915 | VOLUME_UPGRADE_ON_MOUNT = const_cpu_to_le16(0x0004), |
| 1916 | VOLUME_MOUNTED_ON_NT4 = const_cpu_to_le16(0x0008), |
| 1917 | |
| 1918 | VOLUME_DELETE_USN_UNDERWAY = const_cpu_to_le16(0x0010), |
| 1919 | VOLUME_REPAIR_OBJECT_ID = const_cpu_to_le16(0x0020), |
| 1920 | |
Anton Altaparmakov | 3672b63 | 2006-02-24 09:55:07 +0000 | [diff] [blame] | 1921 | VOLUME_CHKDSK_UNDERWAY = const_cpu_to_le16(0x4000), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | VOLUME_MODIFIED_BY_CHKDSK = const_cpu_to_le16(0x8000), |
| 1923 | |
Anton Altaparmakov | 3672b63 | 2006-02-24 09:55:07 +0000 | [diff] [blame] | 1924 | VOLUME_FLAGS_MASK = const_cpu_to_le16(0xc03f), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | |
| 1926 | /* To make our life easier when checking if we must mount read-only. */ |
Anton Altaparmakov | 3672b63 | 2006-02-24 09:55:07 +0000 | [diff] [blame] | 1927 | VOLUME_MUST_MOUNT_RO_MASK = const_cpu_to_le16(0xc027), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | } __attribute__ ((__packed__)); |
| 1929 | |
| 1930 | typedef le16 VOLUME_FLAGS; |
| 1931 | |
| 1932 | /* |
| 1933 | * Attribute: Volume information (0x70). |
| 1934 | * |
| 1935 | * NOTE: Always resident. |
| 1936 | * NOTE: Present only in FILE_Volume. |
| 1937 | * NOTE: Windows 2000 uses NTFS 3.0 while Windows NT4 service pack 6a uses |
| 1938 | * NTFS 1.2. I haven't personally seen other values yet. |
| 1939 | */ |
| 1940 | typedef struct { |
| 1941 | le64 reserved; /* Not used (yet?). */ |
| 1942 | u8 major_ver; /* Major version of the ntfs format. */ |
| 1943 | u8 minor_ver; /* Minor version of the ntfs format. */ |
| 1944 | VOLUME_FLAGS flags; /* Bit array of VOLUME_* flags. */ |
| 1945 | } __attribute__ ((__packed__)) VOLUME_INFORMATION; |
| 1946 | |
| 1947 | /* |
| 1948 | * Attribute: Data attribute (0x80). |
| 1949 | * |
| 1950 | * NOTE: Can be resident or non-resident. |
| 1951 | * |
| 1952 | * Data contents of a file (i.e. the unnamed stream) or of a named stream. |
| 1953 | */ |
| 1954 | typedef struct { |
| 1955 | u8 data[0]; /* The file's data contents. */ |
| 1956 | } __attribute__ ((__packed__)) DATA_ATTR; |
| 1957 | |
| 1958 | /* |
| 1959 | * Index header flags (8-bit). |
| 1960 | */ |
| 1961 | enum { |
| 1962 | /* |
| 1963 | * When index header is in an index root attribute: |
| 1964 | */ |
| 1965 | SMALL_INDEX = 0, /* The index is small enough to fit inside the index |
| 1966 | root attribute and there is no index allocation |
| 1967 | attribute present. */ |
| 1968 | LARGE_INDEX = 1, /* The index is too large to fit in the index root |
| 1969 | attribute and/or an index allocation attribute is |
| 1970 | present. */ |
| 1971 | /* |
| 1972 | * When index header is in an index block, i.e. is part of index |
| 1973 | * allocation attribute: |
| 1974 | */ |
| 1975 | LEAF_NODE = 0, /* This is a leaf node, i.e. there are no more nodes |
| 1976 | branching off it. */ |
| 1977 | INDEX_NODE = 1, /* This node indexes other nodes, i.e. it is not a leaf |
| 1978 | node. */ |
| 1979 | NODE_MASK = 1, /* Mask for accessing the *_NODE bits. */ |
| 1980 | } __attribute__ ((__packed__)); |
| 1981 | |
| 1982 | typedef u8 INDEX_HEADER_FLAGS; |
| 1983 | |
| 1984 | /* |
| 1985 | * This is the header for indexes, describing the INDEX_ENTRY records, which |
| 1986 | * follow the INDEX_HEADER. Together the index header and the index entries |
| 1987 | * make up a complete index. |
| 1988 | * |
| 1989 | * IMPORTANT NOTE: The offset, length and size structure members are counted |
| 1990 | * relative to the start of the index header structure and not relative to the |
| 1991 | * start of the index root or index allocation structures themselves. |
| 1992 | */ |
| 1993 | typedef struct { |
| 1994 | le32 entries_offset; /* Byte offset to first INDEX_ENTRY |
| 1995 | aligned to 8-byte boundary. */ |
| 1996 | le32 index_length; /* Data size of the index in bytes, |
| 1997 | i.e. bytes used from allocated |
| 1998 | size, aligned to 8-byte boundary. */ |
| 1999 | le32 allocated_size; /* Byte size of this index (block), |
| 2000 | multiple of 8 bytes. */ |
| 2001 | /* NOTE: For the index root attribute, the above two numbers are always |
| 2002 | equal, as the attribute is resident and it is resized as needed. In |
| 2003 | the case of the index allocation attribute the attribute is not |
| 2004 | resident and hence the allocated_size is a fixed value and must |
| 2005 | equal the index_block_size specified by the INDEX_ROOT attribute |
| 2006 | corresponding to the INDEX_ALLOCATION attribute this INDEX_BLOCK |
| 2007 | belongs to. */ |
| 2008 | INDEX_HEADER_FLAGS flags; /* Bit field of INDEX_HEADER_FLAGS. */ |
| 2009 | u8 reserved[3]; /* Reserved/align to 8-byte boundary. */ |
| 2010 | } __attribute__ ((__packed__)) INDEX_HEADER; |
| 2011 | |
| 2012 | /* |
| 2013 | * Attribute: Index root (0x90). |
| 2014 | * |
| 2015 | * NOTE: Always resident. |
| 2016 | * |
| 2017 | * This is followed by a sequence of index entries (INDEX_ENTRY structures) |
| 2018 | * as described by the index header. |
| 2019 | * |
| 2020 | * When a directory is small enough to fit inside the index root then this |
| 2021 | * is the only attribute describing the directory. When the directory is too |
| 2022 | * large to fit in the index root, on the other hand, two aditional attributes |
| 2023 | * are present: an index allocation attribute, containing sub-nodes of the B+ |
| 2024 | * directory tree (see below), and a bitmap attribute, describing which virtual |
| 2025 | * cluster numbers (vcns) in the index allocation attribute are in use by an |
| 2026 | * index block. |
| 2027 | * |
| 2028 | * NOTE: The root directory (FILE_root) contains an entry for itself. Other |
| 2029 | * dircetories do not contain entries for themselves, though. |
| 2030 | */ |
| 2031 | typedef struct { |
| 2032 | ATTR_TYPE type; /* Type of the indexed attribute. Is |
| 2033 | $FILE_NAME for directories, zero |
| 2034 | for view indexes. No other values |
| 2035 | allowed. */ |
| 2036 | COLLATION_RULE collation_rule; /* Collation rule used to sort the |
| 2037 | index entries. If type is $FILE_NAME, |
| 2038 | this must be COLLATION_FILE_NAME. */ |
| 2039 | le32 index_block_size; /* Size of each index block in bytes (in |
| 2040 | the index allocation attribute). */ |
| 2041 | u8 clusters_per_index_block; /* Cluster size of each index block (in |
| 2042 | the index allocation attribute), when |
| 2043 | an index block is >= than a cluster, |
| 2044 | otherwise this will be the log of |
| 2045 | the size (like how the encoding of |
| 2046 | the mft record size and the index |
| 2047 | record size found in the boot sector |
| 2048 | work). Has to be a power of 2. */ |
| 2049 | u8 reserved[3]; /* Reserved/align to 8-byte boundary. */ |
| 2050 | INDEX_HEADER index; /* Index header describing the |
| 2051 | following index entries. */ |
| 2052 | } __attribute__ ((__packed__)) INDEX_ROOT; |
| 2053 | |
| 2054 | /* |
| 2055 | * Attribute: Index allocation (0xa0). |
| 2056 | * |
| 2057 | * NOTE: Always non-resident (doesn't make sense to be resident anyway!). |
| 2058 | * |
| 2059 | * This is an array of index blocks. Each index block starts with an |
| 2060 | * INDEX_BLOCK structure containing an index header, followed by a sequence of |
| 2061 | * index entries (INDEX_ENTRY structures), as described by the INDEX_HEADER. |
| 2062 | */ |
| 2063 | typedef struct { |
| 2064 | /* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ |
| 2065 | NTFS_RECORD_TYPE magic; /* Magic is "INDX". */ |
| 2066 | le16 usa_ofs; /* See NTFS_RECORD definition. */ |
| 2067 | le16 usa_count; /* See NTFS_RECORD definition. */ |
| 2068 | |
| 2069 | /* 8*/ sle64 lsn; /* $LogFile sequence number of the last |
| 2070 | modification of this index block. */ |
| 2071 | /* 16*/ leVCN index_block_vcn; /* Virtual cluster number of the index block. |
| 2072 | If the cluster_size on the volume is <= the |
| 2073 | index_block_size of the directory, |
| 2074 | index_block_vcn counts in units of clusters, |
| 2075 | and in units of sectors otherwise. */ |
| 2076 | /* 24*/ INDEX_HEADER index; /* Describes the following index entries. */ |
| 2077 | /* sizeof()= 40 (0x28) bytes */ |
| 2078 | /* |
| 2079 | * When creating the index block, we place the update sequence array at this |
| 2080 | * offset, i.e. before we start with the index entries. This also makes sense, |
| 2081 | * otherwise we could run into problems with the update sequence array |
| 2082 | * containing in itself the last two bytes of a sector which would mean that |
| 2083 | * multi sector transfer protection wouldn't work. As you can't protect data |
| 2084 | * by overwriting it since you then can't get it back... |
| 2085 | * When reading use the data from the ntfs record header. |
| 2086 | */ |
| 2087 | } __attribute__ ((__packed__)) INDEX_BLOCK; |
| 2088 | |
| 2089 | typedef INDEX_BLOCK INDEX_ALLOCATION; |
| 2090 | |
| 2091 | /* |
| 2092 | * The system file FILE_Extend/$Reparse contains an index named $R listing |
| 2093 | * all reparse points on the volume. The index entry keys are as defined |
| 2094 | * below. Note, that there is no index data associated with the index entries. |
| 2095 | * |
| 2096 | * The index entries are sorted by the index key file_id. The collation rule is |
| 2097 | * COLLATION_NTOFS_ULONGS. FIXME: Verify whether the reparse_tag is not the |
| 2098 | * primary key / is not a key at all. (AIA) |
| 2099 | */ |
| 2100 | typedef struct { |
| 2101 | le32 reparse_tag; /* Reparse point type (inc. flags). */ |
| 2102 | leMFT_REF file_id; /* Mft record of the file containing the |
| 2103 | reparse point attribute. */ |
| 2104 | } __attribute__ ((__packed__)) REPARSE_INDEX_KEY; |
| 2105 | |
| 2106 | /* |
| 2107 | * Quota flags (32-bit). |
| 2108 | * |
| 2109 | * The user quota flags. Names explain meaning. |
| 2110 | */ |
| 2111 | enum { |
| 2112 | QUOTA_FLAG_DEFAULT_LIMITS = const_cpu_to_le32(0x00000001), |
| 2113 | QUOTA_FLAG_LIMIT_REACHED = const_cpu_to_le32(0x00000002), |
| 2114 | QUOTA_FLAG_ID_DELETED = const_cpu_to_le32(0x00000004), |
| 2115 | |
| 2116 | QUOTA_FLAG_USER_MASK = const_cpu_to_le32(0x00000007), |
| 2117 | /* This is a bit mask for the user quota flags. */ |
| 2118 | |
| 2119 | /* |
| 2120 | * These flags are only present in the quota defaults index entry, i.e. |
| 2121 | * in the entry where owner_id = QUOTA_DEFAULTS_ID. |
| 2122 | */ |
| 2123 | QUOTA_FLAG_TRACKING_ENABLED = const_cpu_to_le32(0x00000010), |
| 2124 | QUOTA_FLAG_ENFORCEMENT_ENABLED = const_cpu_to_le32(0x00000020), |
| 2125 | QUOTA_FLAG_TRACKING_REQUESTED = const_cpu_to_le32(0x00000040), |
| 2126 | QUOTA_FLAG_LOG_THRESHOLD = const_cpu_to_le32(0x00000080), |
| 2127 | |
| 2128 | QUOTA_FLAG_LOG_LIMIT = const_cpu_to_le32(0x00000100), |
| 2129 | QUOTA_FLAG_OUT_OF_DATE = const_cpu_to_le32(0x00000200), |
| 2130 | QUOTA_FLAG_CORRUPT = const_cpu_to_le32(0x00000400), |
| 2131 | QUOTA_FLAG_PENDING_DELETES = const_cpu_to_le32(0x00000800), |
| 2132 | }; |
| 2133 | |
| 2134 | typedef le32 QUOTA_FLAGS; |
| 2135 | |
| 2136 | /* |
| 2137 | * The system file FILE_Extend/$Quota contains two indexes $O and $Q. Quotas |
| 2138 | * are on a per volume and per user basis. |
| 2139 | * |
| 2140 | * The $Q index contains one entry for each existing user_id on the volume. The |
| 2141 | * index key is the user_id of the user/group owning this quota control entry, |
| 2142 | * i.e. the key is the owner_id. The user_id of the owner of a file, i.e. the |
| 2143 | * owner_id, is found in the standard information attribute. The collation rule |
| 2144 | * for $Q is COLLATION_NTOFS_ULONG. |
| 2145 | * |
| 2146 | * The $O index contains one entry for each user/group who has been assigned |
| 2147 | * a quota on that volume. The index key holds the SID of the user_id the |
| 2148 | * entry belongs to, i.e. the owner_id. The collation rule for $O is |
| 2149 | * COLLATION_NTOFS_SID. |
| 2150 | * |
| 2151 | * The $O index entry data is the user_id of the user corresponding to the SID. |
| 2152 | * This user_id is used as an index into $Q to find the quota control entry |
| 2153 | * associated with the SID. |
| 2154 | * |
| 2155 | * The $Q index entry data is the quota control entry and is defined below. |
| 2156 | */ |
| 2157 | typedef struct { |
| 2158 | le32 version; /* Currently equals 2. */ |
| 2159 | QUOTA_FLAGS flags; /* Flags describing this quota entry. */ |
| 2160 | le64 bytes_used; /* How many bytes of the quota are in use. */ |
| 2161 | sle64 change_time; /* Last time this quota entry was changed. */ |
| 2162 | sle64 threshold; /* Soft quota (-1 if not limited). */ |
| 2163 | sle64 limit; /* Hard quota (-1 if not limited). */ |
| 2164 | sle64 exceeded_time; /* How long the soft quota has been exceeded. */ |
| 2165 | SID sid; /* The SID of the user/object associated with |
| 2166 | this quota entry. Equals zero for the quota |
| 2167 | defaults entry (and in fact on a WinXP |
| 2168 | volume, it is not present at all). */ |
| 2169 | } __attribute__ ((__packed__)) QUOTA_CONTROL_ENTRY; |
| 2170 | |
| 2171 | /* |
| 2172 | * Predefined owner_id values (32-bit). |
| 2173 | */ |
| 2174 | enum { |
| 2175 | QUOTA_INVALID_ID = const_cpu_to_le32(0x00000000), |
| 2176 | QUOTA_DEFAULTS_ID = const_cpu_to_le32(0x00000001), |
| 2177 | QUOTA_FIRST_USER_ID = const_cpu_to_le32(0x00000100), |
| 2178 | }; |
| 2179 | |
| 2180 | /* |
| 2181 | * Current constants for quota control entries. |
| 2182 | */ |
| 2183 | typedef enum { |
| 2184 | /* Current version. */ |
| 2185 | QUOTA_VERSION = 2, |
| 2186 | } QUOTA_CONTROL_ENTRY_CONSTANTS; |
| 2187 | |
| 2188 | /* |
| 2189 | * Index entry flags (16-bit). |
| 2190 | */ |
| 2191 | enum { |
| 2192 | INDEX_ENTRY_NODE = const_cpu_to_le16(1), /* This entry contains a |
| 2193 | sub-node, i.e. a reference to an index block in form of |
| 2194 | a virtual cluster number (see below). */ |
| 2195 | INDEX_ENTRY_END = const_cpu_to_le16(2), /* This signifies the last |
| 2196 | entry in an index block. The index entry does not |
| 2197 | represent a file but it can point to a sub-node. */ |
| 2198 | |
| 2199 | INDEX_ENTRY_SPACE_FILLER = const_cpu_to_le16(0xffff), /* gcc: Force |
| 2200 | enum bit width to 16-bit. */ |
| 2201 | } __attribute__ ((__packed__)); |
| 2202 | |
| 2203 | typedef le16 INDEX_ENTRY_FLAGS; |
| 2204 | |
| 2205 | /* |
| 2206 | * This the index entry header (see below). |
| 2207 | */ |
| 2208 | typedef struct { |
| 2209 | /* 0*/ union { |
| 2210 | struct { /* Only valid when INDEX_ENTRY_END is not set. */ |
| 2211 | leMFT_REF indexed_file; /* The mft reference of the file |
| 2212 | described by this index |
| 2213 | entry. Used for directory |
| 2214 | indexes. */ |
| 2215 | } __attribute__ ((__packed__)) dir; |
| 2216 | struct { /* Used for views/indexes to find the entry's data. */ |
| 2217 | le16 data_offset; /* Data byte offset from this |
| 2218 | INDEX_ENTRY. Follows the |
| 2219 | index key. */ |
| 2220 | le16 data_length; /* Data length in bytes. */ |
| 2221 | le32 reservedV; /* Reserved (zero). */ |
| 2222 | } __attribute__ ((__packed__)) vi; |
| 2223 | } __attribute__ ((__packed__)) data; |
| 2224 | /* 8*/ le16 length; /* Byte size of this index entry, multiple of |
| 2225 | 8-bytes. */ |
| 2226 | /* 10*/ le16 key_length; /* Byte size of the key value, which is in the |
| 2227 | index entry. It follows field reserved. Not |
| 2228 | multiple of 8-bytes. */ |
| 2229 | /* 12*/ INDEX_ENTRY_FLAGS flags; /* Bit field of INDEX_ENTRY_* flags. */ |
| 2230 | /* 14*/ le16 reserved; /* Reserved/align to 8-byte boundary. */ |
| 2231 | /* sizeof() = 16 bytes */ |
| 2232 | } __attribute__ ((__packed__)) INDEX_ENTRY_HEADER; |
| 2233 | |
| 2234 | /* |
| 2235 | * This is an index entry. A sequence of such entries follows each INDEX_HEADER |
| 2236 | * structure. Together they make up a complete index. The index follows either |
| 2237 | * an index root attribute or an index allocation attribute. |
| 2238 | * |
| 2239 | * NOTE: Before NTFS 3.0 only filename attributes were indexed. |
| 2240 | */ |
| 2241 | typedef struct { |
| 2242 | /*Ofs*/ |
| 2243 | /* 0 INDEX_ENTRY_HEADER; -- Unfolded here as gcc dislikes unnamed structs. */ |
| 2244 | union { |
| 2245 | struct { /* Only valid when INDEX_ENTRY_END is not set. */ |
| 2246 | leMFT_REF indexed_file; /* The mft reference of the file |
| 2247 | described by this index |
| 2248 | entry. Used for directory |
| 2249 | indexes. */ |
| 2250 | } __attribute__ ((__packed__)) dir; |
| 2251 | struct { /* Used for views/indexes to find the entry's data. */ |
| 2252 | le16 data_offset; /* Data byte offset from this |
| 2253 | INDEX_ENTRY. Follows the |
| 2254 | index key. */ |
| 2255 | le16 data_length; /* Data length in bytes. */ |
| 2256 | le32 reservedV; /* Reserved (zero). */ |
| 2257 | } __attribute__ ((__packed__)) vi; |
| 2258 | } __attribute__ ((__packed__)) data; |
| 2259 | le16 length; /* Byte size of this index entry, multiple of |
| 2260 | 8-bytes. */ |
| 2261 | le16 key_length; /* Byte size of the key value, which is in the |
| 2262 | index entry. It follows field reserved. Not |
| 2263 | multiple of 8-bytes. */ |
| 2264 | INDEX_ENTRY_FLAGS flags; /* Bit field of INDEX_ENTRY_* flags. */ |
| 2265 | le16 reserved; /* Reserved/align to 8-byte boundary. */ |
| 2266 | |
| 2267 | /* 16*/ union { /* The key of the indexed attribute. NOTE: Only present |
| 2268 | if INDEX_ENTRY_END bit in flags is not set. NOTE: On |
| 2269 | NTFS versions before 3.0 the only valid key is the |
| 2270 | FILE_NAME_ATTR. On NTFS 3.0+ the following |
| 2271 | additional index keys are defined: */ |
| 2272 | FILE_NAME_ATTR file_name;/* $I30 index in directories. */ |
| 2273 | SII_INDEX_KEY sii; /* $SII index in $Secure. */ |
| 2274 | SDH_INDEX_KEY sdh; /* $SDH index in $Secure. */ |
| 2275 | GUID object_id; /* $O index in FILE_Extend/$ObjId: The |
| 2276 | object_id of the mft record found in |
| 2277 | the data part of the index. */ |
| 2278 | REPARSE_INDEX_KEY reparse; /* $R index in |
| 2279 | FILE_Extend/$Reparse. */ |
| 2280 | SID sid; /* $O index in FILE_Extend/$Quota: |
| 2281 | SID of the owner of the user_id. */ |
| 2282 | le32 owner_id; /* $Q index in FILE_Extend/$Quota: |
| 2283 | user_id of the owner of the quota |
| 2284 | control entry in the data part of |
| 2285 | the index. */ |
| 2286 | } __attribute__ ((__packed__)) key; |
| 2287 | /* The (optional) index data is inserted here when creating. */ |
| 2288 | // leVCN vcn; /* If INDEX_ENTRY_NODE bit in flags is set, the last |
| 2289 | // eight bytes of this index entry contain the virtual |
| 2290 | // cluster number of the index block that holds the |
| 2291 | // entries immediately preceding the current entry (the |
| 2292 | // vcn references the corresponding cluster in the data |
| 2293 | // of the non-resident index allocation attribute). If |
| 2294 | // the key_length is zero, then the vcn immediately |
| 2295 | // follows the INDEX_ENTRY_HEADER. Regardless of |
| 2296 | // key_length, the address of the 8-byte boundary |
| 2297 | // alligned vcn of INDEX_ENTRY{_HEADER} *ie is given by |
| 2298 | // (char*)ie + le16_to_cpu(ie*)->length) - sizeof(VCN), |
| 2299 | // where sizeof(VCN) can be hardcoded as 8 if wanted. */ |
| 2300 | } __attribute__ ((__packed__)) INDEX_ENTRY; |
| 2301 | |
| 2302 | /* |
| 2303 | * Attribute: Bitmap (0xb0). |
| 2304 | * |
| 2305 | * Contains an array of bits (aka a bitfield). |
| 2306 | * |
| 2307 | * When used in conjunction with the index allocation attribute, each bit |
| 2308 | * corresponds to one index block within the index allocation attribute. Thus |
| 2309 | * the number of bits in the bitmap * index block size / cluster size is the |
| 2310 | * number of clusters in the index allocation attribute. |
| 2311 | */ |
| 2312 | typedef struct { |
| 2313 | u8 bitmap[0]; /* Array of bits. */ |
| 2314 | } __attribute__ ((__packed__)) BITMAP_ATTR; |
| 2315 | |
| 2316 | /* |
| 2317 | * The reparse point tag defines the type of the reparse point. It also |
| 2318 | * includes several flags, which further describe the reparse point. |
| 2319 | * |
| 2320 | * The reparse point tag is an unsigned 32-bit value divided in three parts: |
| 2321 | * |
| 2322 | * 1. The least significant 16 bits (i.e. bits 0 to 15) specifiy the type of |
| 2323 | * the reparse point. |
| 2324 | * 2. The 13 bits after this (i.e. bits 16 to 28) are reserved for future use. |
| 2325 | * 3. The most significant three bits are flags describing the reparse point. |
| 2326 | * They are defined as follows: |
| 2327 | * bit 29: Name surrogate bit. If set, the filename is an alias for |
| 2328 | * another object in the system. |
| 2329 | * bit 30: High-latency bit. If set, accessing the first byte of data will |
| 2330 | * be slow. (E.g. the data is stored on a tape drive.) |
| 2331 | * bit 31: Microsoft bit. If set, the tag is owned by Microsoft. User |
| 2332 | * defined tags have to use zero here. |
| 2333 | * |
| 2334 | * These are the predefined reparse point tags: |
| 2335 | */ |
| 2336 | enum { |
| 2337 | IO_REPARSE_TAG_IS_ALIAS = const_cpu_to_le32(0x20000000), |
| 2338 | IO_REPARSE_TAG_IS_HIGH_LATENCY = const_cpu_to_le32(0x40000000), |
| 2339 | IO_REPARSE_TAG_IS_MICROSOFT = const_cpu_to_le32(0x80000000), |
| 2340 | |
| 2341 | IO_REPARSE_TAG_RESERVED_ZERO = const_cpu_to_le32(0x00000000), |
| 2342 | IO_REPARSE_TAG_RESERVED_ONE = const_cpu_to_le32(0x00000001), |
| 2343 | IO_REPARSE_TAG_RESERVED_RANGE = const_cpu_to_le32(0x00000001), |
| 2344 | |
| 2345 | IO_REPARSE_TAG_NSS = const_cpu_to_le32(0x68000005), |
| 2346 | IO_REPARSE_TAG_NSS_RECOVER = const_cpu_to_le32(0x68000006), |
| 2347 | IO_REPARSE_TAG_SIS = const_cpu_to_le32(0x68000007), |
| 2348 | IO_REPARSE_TAG_DFS = const_cpu_to_le32(0x68000008), |
| 2349 | |
| 2350 | IO_REPARSE_TAG_MOUNT_POINT = const_cpu_to_le32(0x88000003), |
| 2351 | |
| 2352 | IO_REPARSE_TAG_HSM = const_cpu_to_le32(0xa8000004), |
| 2353 | |
| 2354 | IO_REPARSE_TAG_SYMBOLIC_LINK = const_cpu_to_le32(0xe8000000), |
| 2355 | |
| 2356 | IO_REPARSE_TAG_VALID_VALUES = const_cpu_to_le32(0xe000ffff), |
| 2357 | }; |
| 2358 | |
| 2359 | /* |
| 2360 | * Attribute: Reparse point (0xc0). |
| 2361 | * |
| 2362 | * NOTE: Can be resident or non-resident. |
| 2363 | */ |
| 2364 | typedef struct { |
| 2365 | le32 reparse_tag; /* Reparse point type (inc. flags). */ |
| 2366 | le16 reparse_data_length; /* Byte size of reparse data. */ |
| 2367 | le16 reserved; /* Align to 8-byte boundary. */ |
| 2368 | u8 reparse_data[0]; /* Meaning depends on reparse_tag. */ |
| 2369 | } __attribute__ ((__packed__)) REPARSE_POINT; |
| 2370 | |
| 2371 | /* |
| 2372 | * Attribute: Extended attribute (EA) information (0xd0). |
| 2373 | * |
| 2374 | * NOTE: Always resident. (Is this true???) |
| 2375 | */ |
| 2376 | typedef struct { |
| 2377 | le16 ea_length; /* Byte size of the packed extended |
| 2378 | attributes. */ |
| 2379 | le16 need_ea_count; /* The number of extended attributes which have |
| 2380 | the NEED_EA bit set. */ |
| 2381 | le32 ea_query_length; /* Byte size of the buffer required to query |
| 2382 | the extended attributes when calling |
| 2383 | ZwQueryEaFile() in Windows NT/2k. I.e. the |
| 2384 | byte size of the unpacked extended |
| 2385 | attributes. */ |
| 2386 | } __attribute__ ((__packed__)) EA_INFORMATION; |
| 2387 | |
| 2388 | /* |
| 2389 | * Extended attribute flags (8-bit). |
| 2390 | */ |
| 2391 | enum { |
Anton Altaparmakov | c9c2009 | 2005-10-24 09:00:51 +0100 | [diff] [blame] | 2392 | NEED_EA = 0x80 /* If set the file to which the EA belongs |
| 2393 | cannot be interpreted without understanding |
| 2394 | the associates extended attributes. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | } __attribute__ ((__packed__)); |
| 2396 | |
| 2397 | typedef u8 EA_FLAGS; |
| 2398 | |
| 2399 | /* |
| 2400 | * Attribute: Extended attribute (EA) (0xe0). |
| 2401 | * |
Anton Altaparmakov | 7d0ffdb | 2005-10-19 12:21:19 +0100 | [diff] [blame] | 2402 | * NOTE: Can be resident or non-resident. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | * |
| 2404 | * Like the attribute list and the index buffer list, the EA attribute value is |
| 2405 | * a sequence of EA_ATTR variable length records. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | */ |
| 2407 | typedef struct { |
| 2408 | le32 next_entry_offset; /* Offset to the next EA_ATTR. */ |
| 2409 | EA_FLAGS flags; /* Flags describing the EA. */ |
Anton Altaparmakov | 7d0ffdb | 2005-10-19 12:21:19 +0100 | [diff] [blame] | 2410 | u8 ea_name_length; /* Length of the name of the EA in bytes |
| 2411 | excluding the '\0' byte terminator. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | le16 ea_value_length; /* Byte size of the EA's value. */ |
Anton Altaparmakov | 7d0ffdb | 2005-10-19 12:21:19 +0100 | [diff] [blame] | 2413 | u8 ea_name[0]; /* Name of the EA. Note this is ASCII, not |
| 2414 | Unicode and it is zero terminated. */ |
| 2415 | u8 ea_value[0]; /* The value of the EA. Immediately follows |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | the name. */ |
| 2417 | } __attribute__ ((__packed__)) EA_ATTR; |
| 2418 | |
| 2419 | /* |
| 2420 | * Attribute: Property set (0xf0). |
| 2421 | * |
| 2422 | * Intended to support Native Structure Storage (NSS) - a feature removed from |
| 2423 | * NTFS 3.0 during beta testing. |
| 2424 | */ |
| 2425 | typedef struct { |
| 2426 | /* Irrelevant as feature unused. */ |
| 2427 | } __attribute__ ((__packed__)) PROPERTY_SET; |
| 2428 | |
| 2429 | /* |
| 2430 | * Attribute: Logged utility stream (0x100). |
| 2431 | * |
| 2432 | * NOTE: Can be resident or non-resident. |
| 2433 | * |
| 2434 | * Operations on this attribute are logged to the journal ($LogFile) like |
| 2435 | * normal metadata changes. |
| 2436 | * |
| 2437 | * Used by the Encrypting File System (EFS). All encrypted files have this |
| 2438 | * attribute with the name $EFS. |
| 2439 | */ |
| 2440 | typedef struct { |
| 2441 | /* Can be anything the creator chooses. */ |
| 2442 | /* EFS uses it as follows: */ |
| 2443 | // FIXME: Type this info, verifying it along the way. (AIA) |
| 2444 | } __attribute__ ((__packed__)) LOGGED_UTILITY_STREAM, EFS_ATTR; |
| 2445 | |
| 2446 | #endif /* _LINUX_NTFS_LAYOUT_H */ |