blob: e23fa104ed54c70371361b926d8eb202366f284b [file] [log] [blame]
Steve Kondik2111ad72013-07-07 12:07:44 -07001/*
2 * layout.h - Ntfs on-disk layout structures. Originated from the Linux-NTFS project.
3 *
4 * Copyright (c) 2000-2005 Anton Altaparmakov
5 * Copyright (c) 2005 Yura Pakhuchiy
6 * Copyright (c) 2005-2006 Szabolcs Szakacsits
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 NTFS-3G
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 _NTFS_LAYOUT_H
25#define _NTFS_LAYOUT_H
26
27#include "types.h"
28#include "endians.h"
29#include "support.h"
30
31/* The NTFS oem_id */
32#define magicNTFS const_cpu_to_le64(0x202020205346544e) /* "NTFS " */
33#define NTFS_SB_MAGIC 0x5346544e /* 'NTFS' */
34
35/*
36 * Location of bootsector on partition:
37 * The standard NTFS_BOOT_SECTOR is on sector 0 of the partition.
38 * On NT4 and above there is one backup copy of the boot sector to
39 * be found on the last sector of the partition (not normally accessible
40 * from within Windows as the bootsector contained number of sectors
41 * value is one less than the actual value!).
42 * On versions of NT 3.51 and earlier, the backup copy was located at
43 * number of sectors/2 (integer divide), i.e. in the middle of the volume.
44 */
45
46/**
47 * struct BIOS_PARAMETER_BLOCK - BIOS parameter block (bpb) structure.
48 */
49typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -070050 le16 bytes_per_sector; /* Size of a sector in bytes. */
Steve Kondik2111ad72013-07-07 12:07:44 -070051 u8 sectors_per_cluster; /* Size of a cluster in sectors. */
Steve Kondike68cb602016-08-28 00:45:36 -070052 le16 reserved_sectors; /* zero */
Steve Kondik2111ad72013-07-07 12:07:44 -070053 u8 fats; /* zero */
Steve Kondike68cb602016-08-28 00:45:36 -070054 le16 root_entries; /* zero */
55 le16 sectors; /* zero */
Steve Kondik2111ad72013-07-07 12:07:44 -070056 u8 media_type; /* 0xf8 = hard disk */
Steve Kondike68cb602016-08-28 00:45:36 -070057 le16 sectors_per_fat; /* zero */
58/*0x0d*/le16 sectors_per_track; /* Required to boot Windows. */
59/*0x0f*/le16 heads; /* Required to boot Windows. */
60/*0x11*/le32 hidden_sectors; /* Offset to the start of the partition
Steve Kondik2111ad72013-07-07 12:07:44 -070061 relative to the disk in sectors.
62 Required to boot Windows. */
Steve Kondike68cb602016-08-28 00:45:36 -070063/*0x15*/le32 large_sectors; /* zero */
Steve Kondik2111ad72013-07-07 12:07:44 -070064/* sizeof() = 25 (0x19) bytes */
65} __attribute__((__packed__)) BIOS_PARAMETER_BLOCK;
66
67/**
68 * struct NTFS_BOOT_SECTOR - NTFS boot sector structure.
69 */
70typedef struct {
71 u8 jump[3]; /* Irrelevant (jump to boot up code).*/
Steve Kondike68cb602016-08-28 00:45:36 -070072 le64 oem_id; /* Magic "NTFS ". */
Steve Kondik2111ad72013-07-07 12:07:44 -070073/*0x0b*/BIOS_PARAMETER_BLOCK bpb; /* See BIOS_PARAMETER_BLOCK. */
74 u8 physical_drive; /* 0x00 floppy, 0x80 hard disk */
75 u8 current_head; /* zero */
76 u8 extended_boot_signature; /* 0x80 */
77 u8 reserved2; /* zero */
Steve Kondike68cb602016-08-28 00:45:36 -070078/*0x28*/sle64 number_of_sectors; /* Number of sectors in volume. Gives
Steve Kondik2111ad72013-07-07 12:07:44 -070079 maximum volume size of 2^63 sectors.
80 Assuming standard sector size of 512
81 bytes, the maximum byte size is
82 approx. 4.7x10^21 bytes. (-; */
Steve Kondike68cb602016-08-28 00:45:36 -070083 sle64 mft_lcn; /* Cluster location of mft data. */
84 sle64 mftmirr_lcn; /* Cluster location of copy of mft. */
Steve Kondik2111ad72013-07-07 12:07:44 -070085 s8 clusters_per_mft_record; /* Mft record size in clusters. */
86 u8 reserved0[3]; /* zero */
87 s8 clusters_per_index_record; /* Index block size in clusters. */
88 u8 reserved1[3]; /* zero */
Steve Kondike68cb602016-08-28 00:45:36 -070089 le64 volume_serial_number; /* Irrelevant (serial number). */
90 le32 checksum; /* Boot sector checksum. */
Steve Kondik2111ad72013-07-07 12:07:44 -070091/*0x54*/u8 bootstrap[426]; /* Irrelevant (boot up code). */
Steve Kondike68cb602016-08-28 00:45:36 -070092 le16 end_of_sector_marker; /* End of bootsector magic. Always is
Steve Kondik2111ad72013-07-07 12:07:44 -070093 0xaa55 in little endian. */
94/* sizeof() = 512 (0x200) bytes */
95} __attribute__((__packed__)) NTFS_BOOT_SECTOR;
96
97/**
98 * enum NTFS_RECORD_TYPES -
99 *
100 * Magic identifiers present at the beginning of all ntfs record containing
101 * records (like mft records for example).
102 */
103typedef enum {
104 /* Found in $MFT/$DATA. */
105 magic_FILE = const_cpu_to_le32(0x454c4946), /* Mft entry. */
106 magic_INDX = const_cpu_to_le32(0x58444e49), /* Index buffer. */
107 magic_HOLE = const_cpu_to_le32(0x454c4f48), /* ? (NTFS 3.0+?) */
108
109 /* Found in $LogFile/$DATA. */
110 magic_RSTR = const_cpu_to_le32(0x52545352), /* Restart page. */
111 magic_RCRD = const_cpu_to_le32(0x44524352), /* Log record page. */
112
113 /* Found in $LogFile/$DATA. (May be found in $MFT/$DATA, also?) */
114 magic_CHKD = const_cpu_to_le32(0x444b4843), /* Modified by chkdsk. */
115
116 /* Found in all ntfs record containing records. */
117 magic_BAAD = const_cpu_to_le32(0x44414142), /* Failed multi sector
118 transfer was detected. */
119
120 /*
121 * Found in $LogFile/$DATA when a page is full or 0xff bytes and is
122 * thus not initialized. User has to initialize the page before using
123 * it.
124 */
125 magic_empty = const_cpu_to_le32(0xffffffff),/* Record is empty and has
126 to be initialized before
127 it can be used. */
128} NTFS_RECORD_TYPES;
129
130/*
131 * Generic magic comparison macros. Finally found a use for the ## preprocessor
132 * operator! (-8
133 */
134#define ntfs_is_magic(x, m) ( (u32)(x) == (u32)magic_##m )
135#define ntfs_is_magicp(p, m) ( *(u32*)(p) == (u32)magic_##m )
136
137/*
138 * Specialised magic comparison macros for the NTFS_RECORD_TYPES defined above.
139 */
140#define ntfs_is_file_record(x) ( ntfs_is_magic (x, FILE) )
141#define ntfs_is_file_recordp(p) ( ntfs_is_magicp(p, FILE) )
142#define ntfs_is_mft_record(x) ( ntfs_is_file_record(x) )
143#define ntfs_is_mft_recordp(p) ( ntfs_is_file_recordp(p) )
144#define ntfs_is_indx_record(x) ( ntfs_is_magic (x, INDX) )
145#define ntfs_is_indx_recordp(p) ( ntfs_is_magicp(p, INDX) )
146#define ntfs_is_hole_record(x) ( ntfs_is_magic (x, HOLE) )
147#define ntfs_is_hole_recordp(p) ( ntfs_is_magicp(p, HOLE) )
148
149#define ntfs_is_rstr_record(x) ( ntfs_is_magic (x, RSTR) )
150#define ntfs_is_rstr_recordp(p) ( ntfs_is_magicp(p, RSTR) )
151#define ntfs_is_rcrd_record(x) ( ntfs_is_magic (x, RCRD) )
152#define ntfs_is_rcrd_recordp(p) ( ntfs_is_magicp(p, RCRD) )
153
154#define ntfs_is_chkd_record(x) ( ntfs_is_magic (x, CHKD) )
155#define ntfs_is_chkd_recordp(p) ( ntfs_is_magicp(p, CHKD) )
156
157#define ntfs_is_baad_record(x) ( ntfs_is_magic (x, BAAD) )
158#define ntfs_is_baad_recordp(p) ( ntfs_is_magicp(p, BAAD) )
159
160#define ntfs_is_empty_record(x) ( ntfs_is_magic (x, empty) )
161#define ntfs_is_empty_recordp(p) ( ntfs_is_magicp(p, empty) )
162
163
164#define NTFS_BLOCK_SIZE 512
165#define NTFS_BLOCK_SIZE_BITS 9
166
167/**
168 * struct NTFS_RECORD -
169 *
Steve Kondike68cb602016-08-28 00:45:36 -0700170 * The Update Sequence Array (usa) is an array of the le16 values which belong
Steve Kondik2111ad72013-07-07 12:07:44 -0700171 * to the end of each sector protected by the update sequence record in which
172 * this array is contained. Note that the first entry is the Update Sequence
173 * Number (usn), a cyclic counter of how many times the protected record has
174 * been written to disk. The values 0 and -1 (ie. 0xffff) are not used. All
Steve Kondike68cb602016-08-28 00:45:36 -0700175 * last le16's of each sector have to be equal to the usn (during reading) or
Steve Kondik2111ad72013-07-07 12:07:44 -0700176 * are set to it (during writing). If they are not, an incomplete multi sector
177 * transfer has occurred when the data was written.
178 * The maximum size for the update sequence array is fixed to:
179 * maximum size = usa_ofs + (usa_count * 2) = 510 bytes
Steve Kondike68cb602016-08-28 00:45:36 -0700180 * The 510 bytes comes from the fact that the last le16 in the array has to
181 * (obviously) finish before the last le16 of the first 512-byte sector.
Steve Kondik2111ad72013-07-07 12:07:44 -0700182 * This formula can be used as a consistency check in that usa_ofs +
183 * (usa_count * 2) has to be less than or equal to 510.
184 */
185typedef struct {
186 NTFS_RECORD_TYPES magic;/* A four-byte magic identifying the
187 record type and/or status. */
Steve Kondike68cb602016-08-28 00:45:36 -0700188 le16 usa_ofs; /* Offset to the Update Sequence Array (usa)
Steve Kondik2111ad72013-07-07 12:07:44 -0700189 from the start of the ntfs record. */
Steve Kondike68cb602016-08-28 00:45:36 -0700190 le16 usa_count; /* Number of le16 sized entries in the usa
Steve Kondik2111ad72013-07-07 12:07:44 -0700191 including the Update Sequence Number (usn),
192 thus the number of fixups is the usa_count
193 minus 1. */
194} __attribute__((__packed__)) NTFS_RECORD;
195
196/**
197 * enum NTFS_SYSTEM_FILES - System files mft record numbers.
198 *
199 * All these files are always marked as used in the bitmap attribute of the
200 * mft; presumably in order to avoid accidental allocation for random other
201 * mft records. Also, the sequence number for each of the system files is
202 * always equal to their mft record number and it is never modified.
203 */
204typedef enum {
205 FILE_MFT = 0, /* Master file table (mft). Data attribute
206 contains the entries and bitmap attribute
207 records which ones are in use (bit==1). */
208 FILE_MFTMirr = 1, /* Mft mirror: copy of first four mft records
209 in data attribute. If cluster size > 4kiB,
210 copy of first N mft records, with
211 N = cluster_size / mft_record_size. */
212 FILE_LogFile = 2, /* Journalling log in data attribute. */
213 FILE_Volume = 3, /* Volume name attribute and volume information
214 attribute (flags and ntfs version). Windows
215 refers to this file as volume DASD (Direct
216 Access Storage Device). */
217 FILE_AttrDef = 4, /* Array of attribute definitions in data
218 attribute. */
219 FILE_root = 5, /* Root directory. */
220 FILE_Bitmap = 6, /* Allocation bitmap of all clusters (lcns) in
221 data attribute. */
222 FILE_Boot = 7, /* Boot sector (always at cluster 0) in data
223 attribute. */
224 FILE_BadClus = 8, /* Contains all bad clusters in the non-resident
225 data attribute. */
226 FILE_Secure = 9, /* Shared security descriptors in data attribute
227 and two indexes into the descriptors.
228 Appeared in Windows 2000. Before that, this
229 file was named $Quota but was unused. */
230 FILE_UpCase = 10, /* Uppercase equivalents of all 65536 Unicode
231 characters in data attribute. */
232 FILE_Extend = 11, /* Directory containing other system files (eg.
233 $ObjId, $Quota, $Reparse and $UsnJrnl). This
234 is new to NTFS3.0. */
235 FILE_reserved12 = 12, /* Reserved for future use (records 12-15). */
236 FILE_reserved13 = 13,
237 FILE_reserved14 = 14,
Steve Kondik79165c32015-11-09 19:43:00 -0800238 FILE_mft_data = 15, /* Reserved for first extent of $MFT:$DATA */
Steve Kondik2111ad72013-07-07 12:07:44 -0700239 FILE_first_user = 16, /* First user file, used as test limit for
240 whether to allow opening a file or not. */
241} NTFS_SYSTEM_FILES;
242
243/**
244 * enum MFT_RECORD_FLAGS -
245 *
246 * These are the so far known MFT_RECORD_* flags (16-bit) which contain
247 * information about the mft record in which they are present.
248 *
249 * MFT_RECORD_IS_4 exists on all $Extend sub-files.
250 * It seems that it marks it is a metadata file with MFT record >24, however,
251 * it is unknown if it is limited to metadata files only.
252 *
253 * MFT_RECORD_IS_VIEW_INDEX exists on every metafile with a non directory
254 * index, that means an INDEX_ROOT and an INDEX_ALLOCATION with a name other
255 * than "$I30". It is unknown if it is limited to metadata files only.
256 */
257typedef enum {
258 MFT_RECORD_IN_USE = const_cpu_to_le16(0x0001),
259 MFT_RECORD_IS_DIRECTORY = const_cpu_to_le16(0x0002),
260 MFT_RECORD_IS_4 = const_cpu_to_le16(0x0004),
261 MFT_RECORD_IS_VIEW_INDEX = const_cpu_to_le16(0x0008),
262 MFT_REC_SPACE_FILLER = 0xffff, /* Just to make flags
263 16-bit. */
264} __attribute__((__packed__)) MFT_RECORD_FLAGS;
265
266/*
267 * mft references (aka file references or file record segment references) are
268 * used whenever a structure needs to refer to a record in the mft.
269 *
270 * A reference consists of a 48-bit index into the mft and a 16-bit sequence
271 * number used to detect stale references.
272 *
273 * For error reporting purposes we treat the 48-bit index as a signed quantity.
274 *
275 * The sequence number is a circular counter (skipping 0) describing how many
276 * times the referenced mft record has been (re)used. This has to match the
277 * sequence number of the mft record being referenced, otherwise the reference
278 * is considered stale and removed (FIXME: only ntfsck or the driver itself?).
279 *
280 * If the sequence number is zero it is assumed that no sequence number
281 * consistency checking should be performed.
282 *
283 * FIXME: Since inodes are 32-bit as of now, the driver needs to always check
284 * for high_part being 0 and if not either BUG(), cause a panic() or handle
285 * the situation in some other way. This shouldn't be a problem as a volume has
286 * to become HUGE in order to need more than 32-bits worth of mft records.
287 * Assuming the standard mft record size of 1kb only the records (never mind
288 * the non-resident attributes, etc.) would require 4Tb of space on their own
289 * for the first 32 bits worth of records. This is only if some strange person
290 * doesn't decide to foul play and make the mft sparse which would be a really
291 * horrible thing to do as it would trash our current driver implementation. )-:
292 * Do I hear screams "we want 64-bit inodes!" ?!? (-;
293 *
294 * FIXME: The mft zone is defined as the first 12% of the volume. This space is
295 * reserved so that the mft can grow contiguously and hence doesn't become
296 * fragmented. Volume free space includes the empty part of the mft zone and
297 * when the volume's free 88% are used up, the mft zone is shrunk by a factor
298 * of 2, thus making more space available for more files/data. This process is
299 * repeated every time there is no more free space except for the mft zone until
300 * there really is no more free space.
301 */
302
303/*
304 * Typedef the MFT_REF as a 64-bit value for easier handling.
305 * Also define two unpacking macros to get to the reference (MREF) and
306 * sequence number (MSEQNO) respectively.
307 * The _LE versions are to be applied on little endian MFT_REFs.
308 * Note: The _LE versions will return a CPU endian formatted value!
309 */
310#define MFT_REF_MASK_CPU 0x0000ffffffffffffULL
311#define MFT_REF_MASK_LE const_cpu_to_le64(MFT_REF_MASK_CPU)
312
313typedef u64 MFT_REF;
314typedef le64 leMFT_REF; /* a little-endian MFT_MREF */
315
316#define MK_MREF(m, s) ((MFT_REF)(((MFT_REF)(s) << 48) | \
317 ((MFT_REF)(m) & MFT_REF_MASK_CPU)))
318#define MK_LE_MREF(m, s) const_cpu_to_le64(((MFT_REF)(((MFT_REF)(s) << 48) | \
319 ((MFT_REF)(m) & MFT_REF_MASK_CPU))))
320
321#define MREF(x) ((u64)((x) & MFT_REF_MASK_CPU))
322#define MSEQNO(x) ((u16)(((x) >> 48) & 0xffff))
323#define MREF_LE(x) ((u64)(const_le64_to_cpu(x) & MFT_REF_MASK_CPU))
324#define MSEQNO_LE(x) ((u16)((const_le64_to_cpu(x) >> 48) & 0xffff))
325
326#define IS_ERR_MREF(x) (((x) & 0x0000800000000000ULL) ? 1 : 0)
327#define ERR_MREF(x) ((u64)((s64)(x)))
328#define MREF_ERR(x) ((int)((s64)(x)))
329
330/**
331 * struct MFT_RECORD - An MFT record layout (NTFS 3.1+)
332 *
333 * The mft record header present at the beginning of every record in the mft.
334 * This is followed by a sequence of variable length attribute records which
335 * is terminated by an attribute of type AT_END which is a truncated attribute
336 * in that it only consists of the attribute type code AT_END and none of the
337 * other members of the attribute structure are present.
338 */
339typedef struct {
340/*Ofs*/
341/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */
342 NTFS_RECORD_TYPES magic;/* Usually the magic is "FILE". */
Steve Kondike68cb602016-08-28 00:45:36 -0700343 le16 usa_ofs; /* See NTFS_RECORD definition above. */
344 le16 usa_count; /* See NTFS_RECORD definition above. */
Steve Kondik2111ad72013-07-07 12:07:44 -0700345
Steve Kondike68cb602016-08-28 00:45:36 -0700346/* 8*/ leLSN lsn; /* $LogFile sequence number for this record.
Steve Kondik2111ad72013-07-07 12:07:44 -0700347 Changed every time the record is modified. */
Steve Kondike68cb602016-08-28 00:45:36 -0700348/* 16*/ le16 sequence_number; /* Number of times this mft record has been
Steve Kondik2111ad72013-07-07 12:07:44 -0700349 reused. (See description for MFT_REF
350 above.) NOTE: The increment (skipping zero)
351 is done when the file is deleted. NOTE: If
352 this is zero it is left zero. */
Steve Kondike68cb602016-08-28 00:45:36 -0700353/* 18*/ le16 link_count; /* Number of hard links, i.e. the number of
Steve Kondik2111ad72013-07-07 12:07:44 -0700354 directory entries referencing this record.
355 NOTE: Only used in mft base records.
356 NOTE: When deleting a directory entry we
357 check the link_count and if it is 1 we
358 delete the file. Otherwise we delete the
359 FILE_NAME_ATTR being referenced by the
360 directory entry from the mft record and
361 decrement the link_count.
362 FIXME: Careful with Win32 + DOS names! */
Steve Kondike68cb602016-08-28 00:45:36 -0700363/* 20*/ le16 attrs_offset; /* Byte offset to the first attribute in this
Steve Kondik2111ad72013-07-07 12:07:44 -0700364 mft record from the start of the mft record.
365 NOTE: Must be aligned to 8-byte boundary. */
366/* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file
367 is deleted, the MFT_RECORD_IN_USE flag is
368 set to zero. */
Steve Kondike68cb602016-08-28 00:45:36 -0700369/* 24*/ le32 bytes_in_use; /* Number of bytes used in this mft record.
Steve Kondik2111ad72013-07-07 12:07:44 -0700370 NOTE: Must be aligned to 8-byte boundary. */
Steve Kondike68cb602016-08-28 00:45:36 -0700371/* 28*/ le32 bytes_allocated; /* Number of bytes allocated for this mft
Steve Kondik2111ad72013-07-07 12:07:44 -0700372 record. This should be equal to the mft
373 record size. */
Steve Kondike68cb602016-08-28 00:45:36 -0700374/* 32*/ leMFT_REF base_mft_record;
375 /* This is zero for base mft records.
Steve Kondik2111ad72013-07-07 12:07:44 -0700376 When it is not zero it is a mft reference
377 pointing to the base mft record to which
378 this record belongs (this is then used to
379 locate the attribute list attribute present
380 in the base record which describes this
381 extension record and hence might need
382 modification when the extension record
383 itself is modified, also locating the
384 attribute list also means finding the other
385 potential extents, belonging to the non-base
386 mft record). */
Steve Kondike68cb602016-08-28 00:45:36 -0700387/* 40*/ le16 next_attr_instance; /* The instance number that will be
Steve Kondik2111ad72013-07-07 12:07:44 -0700388 assigned to the next attribute added to this
389 mft record. NOTE: Incremented each time
390 after it is used. NOTE: Every time the mft
391 record is reused this number is set to zero.
392 NOTE: The first instance number is always 0.
393 */
394/* The below fields are specific to NTFS 3.1+ (Windows XP and above): */
Steve Kondike68cb602016-08-28 00:45:36 -0700395/* 42*/ le16 reserved; /* Reserved/alignment. */
396/* 44*/ le32 mft_record_number; /* Number of this mft record. */
Steve Kondik2111ad72013-07-07 12:07:44 -0700397/* sizeof() = 48 bytes */
398/*
399 * When (re)using the mft record, we place the update sequence array at this
400 * offset, i.e. before we start with the attributes. This also makes sense,
401 * otherwise we could run into problems with the update sequence array
402 * containing in itself the last two bytes of a sector which would mean that
403 * multi sector transfer protection wouldn't work. As you can't protect data
404 * by overwriting it since you then can't get it back...
405 * When reading we obviously use the data from the ntfs record header.
406 */
407} __attribute__((__packed__)) MFT_RECORD;
408
409/**
410 * struct MFT_RECORD_OLD - An MFT record layout (NTFS <=3.0)
411 *
412 * This is the version without the NTFS 3.1+ specific fields.
413 */
414typedef struct {
415/*Ofs*/
416/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */
417 NTFS_RECORD_TYPES magic;/* Usually the magic is "FILE". */
Steve Kondike68cb602016-08-28 00:45:36 -0700418 le16 usa_ofs; /* See NTFS_RECORD definition above. */
419 le16 usa_count; /* See NTFS_RECORD definition above. */
Steve Kondik2111ad72013-07-07 12:07:44 -0700420
Steve Kondike68cb602016-08-28 00:45:36 -0700421/* 8*/ leLSN lsn; /* $LogFile sequence number for this record.
Steve Kondik2111ad72013-07-07 12:07:44 -0700422 Changed every time the record is modified. */
Steve Kondike68cb602016-08-28 00:45:36 -0700423/* 16*/ le16 sequence_number; /* Number of times this mft record has been
Steve Kondik2111ad72013-07-07 12:07:44 -0700424 reused. (See description for MFT_REF
425 above.) NOTE: The increment (skipping zero)
426 is done when the file is deleted. NOTE: If
427 this is zero it is left zero. */
Steve Kondike68cb602016-08-28 00:45:36 -0700428/* 18*/ le16 link_count; /* Number of hard links, i.e. the number of
Steve Kondik2111ad72013-07-07 12:07:44 -0700429 directory entries referencing this record.
430 NOTE: Only used in mft base records.
431 NOTE: When deleting a directory entry we
432 check the link_count and if it is 1 we
433 delete the file. Otherwise we delete the
434 FILE_NAME_ATTR being referenced by the
435 directory entry from the mft record and
436 decrement the link_count.
437 FIXME: Careful with Win32 + DOS names! */
Steve Kondike68cb602016-08-28 00:45:36 -0700438/* 20*/ le16 attrs_offset; /* Byte offset to the first attribute in this
Steve Kondik2111ad72013-07-07 12:07:44 -0700439 mft record from the start of the mft record.
440 NOTE: Must be aligned to 8-byte boundary. */
441/* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file
442 is deleted, the MFT_RECORD_IN_USE flag is
443 set to zero. */
Steve Kondike68cb602016-08-28 00:45:36 -0700444/* 24*/ le32 bytes_in_use; /* Number of bytes used in this mft record.
Steve Kondik2111ad72013-07-07 12:07:44 -0700445 NOTE: Must be aligned to 8-byte boundary. */
Steve Kondike68cb602016-08-28 00:45:36 -0700446/* 28*/ le32 bytes_allocated; /* Number of bytes allocated for this mft
Steve Kondik2111ad72013-07-07 12:07:44 -0700447 record. This should be equal to the mft
448 record size. */
Steve Kondike68cb602016-08-28 00:45:36 -0700449/* 32*/ leMFT_REF base_mft_record;
450 /* This is zero for base mft records.
Steve Kondik2111ad72013-07-07 12:07:44 -0700451 When it is not zero it is a mft reference
452 pointing to the base mft record to which
453 this record belongs (this is then used to
454 locate the attribute list attribute present
455 in the base record which describes this
456 extension record and hence might need
457 modification when the extension record
458 itself is modified, also locating the
459 attribute list also means finding the other
460 potential extents, belonging to the non-base
461 mft record). */
Steve Kondike68cb602016-08-28 00:45:36 -0700462/* 40*/ le16 next_attr_instance; /* The instance number that will be
Steve Kondik2111ad72013-07-07 12:07:44 -0700463 assigned to the next attribute added to this
464 mft record. NOTE: Incremented each time
465 after it is used. NOTE: Every time the mft
466 record is reused this number is set to zero.
467 NOTE: The first instance number is always 0.
468 */
469/* sizeof() = 42 bytes */
470/*
471 * When (re)using the mft record, we place the update sequence array at this
472 * offset, i.e. before we start with the attributes. This also makes sense,
473 * otherwise we could run into problems with the update sequence array
474 * containing in itself the last two bytes of a sector which would mean that
475 * multi sector transfer protection wouldn't work. As you can't protect data
476 * by overwriting it since you then can't get it back...
477 * When reading we obviously use the data from the ntfs record header.
478 */
479} __attribute__((__packed__)) MFT_RECORD_OLD;
480
481/**
482 * enum ATTR_TYPES - System defined attributes (32-bit).
483 *
484 * Each attribute type has a corresponding attribute name (Unicode string of
485 * maximum 64 character length) as described by the attribute definitions
486 * present in the data attribute of the $AttrDef system file.
487 *
488 * On NTFS 3.0 volumes the names are just as the types are named in the below
489 * enum exchanging AT_ for the dollar sign ($). If that isn't a revealing
490 * choice of symbol... (-;
491 */
492typedef enum {
493 AT_UNUSED = const_cpu_to_le32( 0),
494 AT_STANDARD_INFORMATION = const_cpu_to_le32( 0x10),
495 AT_ATTRIBUTE_LIST = const_cpu_to_le32( 0x20),
496 AT_FILE_NAME = const_cpu_to_le32( 0x30),
497 AT_OBJECT_ID = const_cpu_to_le32( 0x40),
498 AT_SECURITY_DESCRIPTOR = const_cpu_to_le32( 0x50),
499 AT_VOLUME_NAME = const_cpu_to_le32( 0x60),
500 AT_VOLUME_INFORMATION = const_cpu_to_le32( 0x70),
501 AT_DATA = const_cpu_to_le32( 0x80),
502 AT_INDEX_ROOT = const_cpu_to_le32( 0x90),
503 AT_INDEX_ALLOCATION = const_cpu_to_le32( 0xa0),
504 AT_BITMAP = const_cpu_to_le32( 0xb0),
505 AT_REPARSE_POINT = const_cpu_to_le32( 0xc0),
506 AT_EA_INFORMATION = const_cpu_to_le32( 0xd0),
507 AT_EA = const_cpu_to_le32( 0xe0),
508 AT_PROPERTY_SET = const_cpu_to_le32( 0xf0),
509 AT_LOGGED_UTILITY_STREAM = const_cpu_to_le32( 0x100),
510 AT_FIRST_USER_DEFINED_ATTRIBUTE = const_cpu_to_le32( 0x1000),
511 AT_END = const_cpu_to_le32(0xffffffff),
512} ATTR_TYPES;
513
514/**
515 * enum COLLATION_RULES - The collation rules for sorting views/indexes/etc
516 * (32-bit).
517 *
518 * COLLATION_UNICODE_STRING - Collate Unicode strings by comparing their binary
519 * Unicode values, except that when a character can be uppercased, the
520 * upper case value collates before the lower case one.
521 * COLLATION_FILE_NAME - Collate file names as Unicode strings. The collation
522 * is done very much like COLLATION_UNICODE_STRING. In fact I have no idea
523 * what the difference is. Perhaps the difference is that file names
524 * would treat some special characters in an odd way (see
525 * unistr.c::ntfs_collate_names() and unistr.c::legal_ansi_char_array[]
526 * for what I mean but COLLATION_UNICODE_STRING would not give any special
527 * treatment to any characters at all, but this is speculation.
Steve Kondike68cb602016-08-28 00:45:36 -0700528 * COLLATION_NTOFS_ULONG - Sorting is done according to ascending le32 key
Steve Kondik2111ad72013-07-07 12:07:44 -0700529 * values. E.g. used for $SII index in FILE_Secure, which sorts by
Steve Kondike68cb602016-08-28 00:45:36 -0700530 * security_id (le32).
Steve Kondik2111ad72013-07-07 12:07:44 -0700531 * COLLATION_NTOFS_SID - Sorting is done according to ascending SID values.
532 * E.g. used for $O index in FILE_Extend/$Quota.
533 * COLLATION_NTOFS_SECURITY_HASH - Sorting is done first by ascending hash
534 * values and second by ascending security_id values. E.g. used for $SDH
535 * index in FILE_Secure.
536 * COLLATION_NTOFS_ULONGS - Sorting is done according to a sequence of ascending
Steve Kondike68cb602016-08-28 00:45:36 -0700537 * le32 key values. E.g. used for $O index in FILE_Extend/$ObjId, which
Steve Kondik2111ad72013-07-07 12:07:44 -0700538 * sorts by object_id (16-byte), by splitting up the object_id in four
Steve Kondike68cb602016-08-28 00:45:36 -0700539 * le32 values and using them as individual keys. E.g. take the following
Steve Kondik2111ad72013-07-07 12:07:44 -0700540 * two security_ids, stored as follows on disk:
541 * 1st: a1 61 65 b7 65 7b d4 11 9e 3d 00 e0 81 10 42 59
542 * 2nd: 38 14 37 d2 d2 f3 d4 11 a5 21 c8 6b 79 b1 97 45
Steve Kondike68cb602016-08-28 00:45:36 -0700543 * To compare them, they are split into four le32 values each, like so:
Steve Kondik2111ad72013-07-07 12:07:44 -0700544 * 1st: 0xb76561a1 0x11d47b65 0xe0003d9e 0x59421081
545 * 2nd: 0xd2371438 0x11d4f3d2 0x6bc821a5 0x4597b179
546 * Now, it is apparent why the 2nd object_id collates after the 1st: the
Steve Kondike68cb602016-08-28 00:45:36 -0700547 * first le32 value of the 1st object_id is less than the first le32 of
548 * the 2nd object_id. If the first le32 values of both object_ids were
549 * equal then the second le32 values would be compared, etc.
Steve Kondik2111ad72013-07-07 12:07:44 -0700550 */
551typedef enum {
552 COLLATION_BINARY = const_cpu_to_le32(0), /* Collate by binary
553 compare where the first byte is most
554 significant. */
555 COLLATION_FILE_NAME = const_cpu_to_le32(1), /* Collate file names
556 as Unicode strings. */
557 COLLATION_UNICODE_STRING = const_cpu_to_le32(2), /* Collate Unicode
558 strings by comparing their binary
559 Unicode values, except that when a
560 character can be uppercased, the upper
561 case value collates before the lower
562 case one. */
563 COLLATION_NTOFS_ULONG = const_cpu_to_le32(16),
564 COLLATION_NTOFS_SID = const_cpu_to_le32(17),
565 COLLATION_NTOFS_SECURITY_HASH = const_cpu_to_le32(18),
566 COLLATION_NTOFS_ULONGS = const_cpu_to_le32(19),
567} COLLATION_RULES;
568
569/**
570 * enum ATTR_DEF_FLAGS -
571 *
572 * The flags (32-bit) describing attribute properties in the attribute
573 * definition structure. FIXME: This information is based on Regis's
574 * information and, according to him, it is not certain and probably
575 * incomplete. The INDEXABLE flag is fairly certainly correct as only the file
576 * name attribute has this flag set and this is the only attribute indexed in
577 * NT4.
578 */
579typedef enum {
580 ATTR_DEF_INDEXABLE = const_cpu_to_le32(0x02), /* Attribute can be
581 indexed. */
582 ATTR_DEF_MULTIPLE = const_cpu_to_le32(0x04), /* Attribute type
583 can be present multiple times in the
584 mft records of an inode. */
585 ATTR_DEF_NOT_ZERO = const_cpu_to_le32(0x08), /* Attribute value
586 must contain at least one non-zero
587 byte. */
588 ATTR_DEF_INDEXED_UNIQUE = const_cpu_to_le32(0x10), /* Attribute must be
589 indexed and the attribute value must be
590 unique for the attribute type in all of
591 the mft records of an inode. */
592 ATTR_DEF_NAMED_UNIQUE = const_cpu_to_le32(0x20), /* Attribute must be
593 named and the name must be unique for
594 the attribute type in all of the mft
595 records of an inode. */
596 ATTR_DEF_RESIDENT = const_cpu_to_le32(0x40), /* Attribute must be
597 resident. */
598 ATTR_DEF_ALWAYS_LOG = const_cpu_to_le32(0x80), /* Always log
599 modifications to this attribute,
600 regardless of whether it is resident or
601 non-resident. Without this, only log
602 modifications if the attribute is
603 resident. */
604} ATTR_DEF_FLAGS;
605
606/**
607 * struct ATTR_DEF -
608 *
609 * The data attribute of FILE_AttrDef contains a sequence of attribute
610 * definitions for the NTFS volume. With this, it is supposed to be safe for an
611 * older NTFS driver to mount a volume containing a newer NTFS version without
612 * damaging it (that's the theory. In practice it's: not damaging it too much).
613 * Entries are sorted by attribute type. The flags describe whether the
614 * attribute can be resident/non-resident and possibly other things, but the
615 * actual bits are unknown.
616 */
617typedef struct {
618/*hex ofs*/
619/* 0*/ ntfschar name[0x40]; /* Unicode name of the attribute. Zero
620 terminated. */
621/* 80*/ ATTR_TYPES type; /* Type of the attribute. */
Steve Kondike68cb602016-08-28 00:45:36 -0700622/* 84*/ le32 display_rule; /* Default display rule.
Steve Kondik2111ad72013-07-07 12:07:44 -0700623 FIXME: What does it mean? (AIA) */
624/* 88*/ COLLATION_RULES collation_rule; /* Default collation rule. */
625/* 8c*/ ATTR_DEF_FLAGS flags; /* Flags describing the attribute. */
Steve Kondike68cb602016-08-28 00:45:36 -0700626/* 90*/ sle64 min_size; /* Optional minimum attribute size. */
627/* 98*/ sle64 max_size; /* Maximum size of attribute. */
Steve Kondik2111ad72013-07-07 12:07:44 -0700628/* sizeof() = 0xa0 or 160 bytes */
629} __attribute__((__packed__)) ATTR_DEF;
630
631/**
632 * enum ATTR_FLAGS - Attribute flags (16-bit).
633 */
634typedef enum {
635 ATTR_IS_COMPRESSED = const_cpu_to_le16(0x0001),
636 ATTR_COMPRESSION_MASK = const_cpu_to_le16(0x00ff), /* Compression
637 method mask. Also, first
638 illegal value. */
639 ATTR_IS_ENCRYPTED = const_cpu_to_le16(0x4000),
640 ATTR_IS_SPARSE = const_cpu_to_le16(0x8000),
641} __attribute__((__packed__)) ATTR_FLAGS;
642
643/*
644 * Attribute compression.
645 *
646 * Only the data attribute is ever compressed in the current ntfs driver in
647 * Windows. Further, compression is only applied when the data attribute is
648 * non-resident. Finally, to use compression, the maximum allowed cluster size
649 * on a volume is 4kib.
650 *
651 * The compression method is based on independently compressing blocks of X
652 * clusters, where X is determined from the compression_unit value found in the
653 * non-resident attribute record header (more precisely: X = 2^compression_unit
654 * clusters). On Windows NT/2k, X always is 16 clusters (compression_unit = 4).
655 *
656 * There are three different cases of how a compression block of X clusters
657 * can be stored:
658 *
659 * 1) The data in the block is all zero (a sparse block):
660 * This is stored as a sparse block in the runlist, i.e. the runlist
661 * entry has length = X and lcn = -1. The mapping pairs array actually
662 * uses a delta_lcn value length of 0, i.e. delta_lcn is not present at
663 * all, which is then interpreted by the driver as lcn = -1.
664 * NOTE: Even uncompressed files can be sparse on NTFS 3.0 volumes, then
665 * the same principles apply as above, except that the length is not
666 * restricted to being any particular value.
667 *
668 * 2) The data in the block is not compressed:
669 * This happens when compression doesn't reduce the size of the block
670 * in clusters. I.e. if compression has a small effect so that the
671 * compressed data still occupies X clusters, then the uncompressed data
672 * is stored in the block.
673 * This case is recognised by the fact that the runlist entry has
674 * length = X and lcn >= 0. The mapping pairs array stores this as
675 * normal with a run length of X and some specific delta_lcn, i.e.
676 * delta_lcn has to be present.
677 *
678 * 3) The data in the block is compressed:
679 * The common case. This case is recognised by the fact that the run
680 * list entry has length L < X and lcn >= 0. The mapping pairs array
681 * stores this as normal with a run length of X and some specific
682 * delta_lcn, i.e. delta_lcn has to be present. This runlist entry is
683 * immediately followed by a sparse entry with length = X - L and
684 * lcn = -1. The latter entry is to make up the vcn counting to the
685 * full compression block size X.
686 *
687 * In fact, life is more complicated because adjacent entries of the same type
688 * can be coalesced. This means that one has to keep track of the number of
689 * clusters handled and work on a basis of X clusters at a time being one
690 * block. An example: if length L > X this means that this particular runlist
691 * entry contains a block of length X and part of one or more blocks of length
692 * L - X. Another example: if length L < X, this does not necessarily mean that
693 * the block is compressed as it might be that the lcn changes inside the block
694 * and hence the following runlist entry describes the continuation of the
695 * potentially compressed block. The block would be compressed if the
696 * following runlist entry describes at least X - L sparse clusters, thus
697 * making up the compression block length as described in point 3 above. (Of
698 * course, there can be several runlist entries with small lengths so that the
699 * sparse entry does not follow the first data containing entry with
700 * length < X.)
701 *
702 * NOTE: At the end of the compressed attribute value, there most likely is not
703 * just the right amount of data to make up a compression block, thus this data
704 * is not even attempted to be compressed. It is just stored as is, unless
705 * the number of clusters it occupies is reduced when compressed in which case
706 * it is stored as a compressed compression block, complete with sparse
707 * clusters at the end.
708 */
709
710/**
711 * enum RESIDENT_ATTR_FLAGS - Flags of resident attributes (8-bit).
712 */
713typedef enum {
714 RESIDENT_ATTR_IS_INDEXED = 0x01, /* Attribute is referenced in an index
715 (has implications for deleting and
716 modifying the attribute). */
717} __attribute__((__packed__)) RESIDENT_ATTR_FLAGS;
718
719/**
720 * struct ATTR_RECORD - Attribute record header.
721 *
722 * Always aligned to 8-byte boundary.
723 */
724typedef struct {
725/*Ofs*/
726/* 0*/ ATTR_TYPES type; /* The (32-bit) type of the attribute. */
Steve Kondike68cb602016-08-28 00:45:36 -0700727/* 4*/ le32 length; /* Byte size of the resident part of the
Steve Kondik2111ad72013-07-07 12:07:44 -0700728 attribute (aligned to 8-byte boundary).
729 Used to get to the next attribute. */
730/* 8*/ u8 non_resident; /* If 0, attribute is resident.
731 If 1, attribute is non-resident. */
732/* 9*/ u8 name_length; /* Unicode character size of name of attribute.
733 0 if unnamed. */
Steve Kondike68cb602016-08-28 00:45:36 -0700734/* 10*/ le16 name_offset; /* If name_length != 0, the byte offset to the
Steve Kondik2111ad72013-07-07 12:07:44 -0700735 beginning of the name from the attribute
736 record. Note that the name is stored as a
737 Unicode string. When creating, place offset
738 just at the end of the record header. Then,
739 follow with attribute value or mapping pairs
740 array, resident and non-resident attributes
741 respectively, aligning to an 8-byte
742 boundary. */
743/* 12*/ ATTR_FLAGS flags; /* Flags describing the attribute. */
Steve Kondike68cb602016-08-28 00:45:36 -0700744/* 14*/ le16 instance; /* The instance of this attribute record. This
Steve Kondik2111ad72013-07-07 12:07:44 -0700745 number is unique within this mft record (see
746 MFT_RECORD/next_attribute_instance notes
747 above for more details). */
748/* 16*/ union {
749 /* Resident attributes. */
750 struct {
Steve Kondike68cb602016-08-28 00:45:36 -0700751/* 16 */ le32 value_length; /* Byte size of attribute value. */
752/* 20 */ le16 value_offset; /* Byte offset of the attribute
Steve Kondik2111ad72013-07-07 12:07:44 -0700753 value from the start of the
754 attribute record. When creating,
755 align to 8-byte boundary if we
756 have a name present as this might
757 not have a length of a multiple
758 of 8-bytes. */
759/* 22 */ RESIDENT_ATTR_FLAGS resident_flags; /* See above. */
760/* 23 */ s8 reservedR; /* Reserved/alignment to 8-byte
761 boundary. */
762/* 24 */ void *resident_end[0]; /* Use offsetof(ATTR_RECORD,
763 resident_end) to get size of
764 a resident attribute. */
765 } __attribute__((__packed__));
766 /* Non-resident attributes. */
767 struct {
Steve Kondike68cb602016-08-28 00:45:36 -0700768/* 16*/ leVCN lowest_vcn; /* Lowest valid virtual cluster number
Steve Kondik2111ad72013-07-07 12:07:44 -0700769 for this portion of the attribute value or
770 0 if this is the only extent (usually the
771 case). - Only when an attribute list is used
772 does lowest_vcn != 0 ever occur. */
Steve Kondike68cb602016-08-28 00:45:36 -0700773/* 24*/ leVCN highest_vcn; /* Highest valid vcn of this extent of
Steve Kondik2111ad72013-07-07 12:07:44 -0700774 the attribute value. - Usually there is only one
775 portion, so this usually equals the attribute
776 value size in clusters minus 1. Can be -1 for
777 zero length files. Can be 0 for "single extent"
778 attributes. */
Steve Kondike68cb602016-08-28 00:45:36 -0700779/* 32*/ le16 mapping_pairs_offset; /* Byte offset from the
Steve Kondik2111ad72013-07-07 12:07:44 -0700780 beginning of the structure to the mapping pairs
781 array which contains the mappings between the
782 vcns and the logical cluster numbers (lcns).
783 When creating, place this at the end of this
784 record header aligned to 8-byte boundary. */
785/* 34*/ u8 compression_unit; /* The compression unit expressed
786 as the log to the base 2 of the number of
787 clusters in a compression unit. 0 means not
788 compressed. (This effectively limits the
789 compression unit size to be a power of two
790 clusters.) WinNT4 only uses a value of 4. */
791/* 35*/ u8 reserved1[5]; /* Align to 8-byte boundary. */
792/* The sizes below are only used when lowest_vcn is zero, as otherwise it would
793 be difficult to keep them up-to-date.*/
Steve Kondike68cb602016-08-28 00:45:36 -0700794/* 40*/ sle64 allocated_size; /* Byte size of disk space
Steve Kondik2111ad72013-07-07 12:07:44 -0700795 allocated to hold the attribute value. Always
796 is a multiple of the cluster size. When a file
797 is compressed, this field is a multiple of the
798 compression block size (2^compression_unit) and
799 it represents the logically allocated space
800 rather than the actual on disk usage. For this
801 use the compressed_size (see below). */
Steve Kondike68cb602016-08-28 00:45:36 -0700802/* 48*/ sle64 data_size; /* Byte size of the attribute
Steve Kondik2111ad72013-07-07 12:07:44 -0700803 value. Can be larger than allocated_size if
804 attribute value is compressed or sparse. */
Steve Kondike68cb602016-08-28 00:45:36 -0700805/* 56*/ sle64 initialized_size; /* Byte size of initialized
Steve Kondik2111ad72013-07-07 12:07:44 -0700806 portion of the attribute value. Usually equals
807 data_size. */
808/* 64 */ void *non_resident_end[0]; /* Use offsetof(ATTR_RECORD,
809 non_resident_end) to get
810 size of a non resident
811 attribute. */
812/* sizeof(uncompressed attr) = 64*/
Steve Kondike68cb602016-08-28 00:45:36 -0700813/* 64*/ sle64 compressed_size; /* Byte size of the attribute
Steve Kondik2111ad72013-07-07 12:07:44 -0700814 value after compression. Only present when
815 compressed. Always is a multiple of the
816 cluster size. Represents the actual amount of
817 disk space being used on the disk. */
818/* 72 */ void *compressed_end[0];
819 /* Use offsetof(ATTR_RECORD, compressed_end) to
820 get size of a compressed attribute. */
821/* sizeof(compressed attr) = 72*/
822 } __attribute__((__packed__));
823 } __attribute__((__packed__));
824} __attribute__((__packed__)) ATTR_RECORD;
825
826typedef ATTR_RECORD ATTR_REC;
827
828/**
829 * enum FILE_ATTR_FLAGS - File attribute flags (32-bit).
830 */
831typedef enum {
832 /*
833 * These flags are only present in the STANDARD_INFORMATION attribute
834 * (in the field file_attributes).
835 */
836 FILE_ATTR_READONLY = const_cpu_to_le32(0x00000001),
837 FILE_ATTR_HIDDEN = const_cpu_to_le32(0x00000002),
838 FILE_ATTR_SYSTEM = const_cpu_to_le32(0x00000004),
Steve Kondike68cb602016-08-28 00:45:36 -0700839 /* Old DOS volid. Unused in NT. = const_cpu_to_le32(0x00000008), */
Steve Kondik2111ad72013-07-07 12:07:44 -0700840
841 FILE_ATTR_DIRECTORY = const_cpu_to_le32(0x00000010),
842 /* FILE_ATTR_DIRECTORY is not considered valid in NT. It is reserved
843 for the DOS SUBDIRECTORY flag. */
844 FILE_ATTR_ARCHIVE = const_cpu_to_le32(0x00000020),
845 FILE_ATTR_DEVICE = const_cpu_to_le32(0x00000040),
846 FILE_ATTR_NORMAL = const_cpu_to_le32(0x00000080),
847
848 FILE_ATTR_TEMPORARY = const_cpu_to_le32(0x00000100),
849 FILE_ATTR_SPARSE_FILE = const_cpu_to_le32(0x00000200),
850 FILE_ATTR_REPARSE_POINT = const_cpu_to_le32(0x00000400),
851 FILE_ATTR_COMPRESSED = const_cpu_to_le32(0x00000800),
852
853 FILE_ATTR_OFFLINE = const_cpu_to_le32(0x00001000),
854 FILE_ATTR_NOT_CONTENT_INDEXED = const_cpu_to_le32(0x00002000),
855 FILE_ATTR_ENCRYPTED = const_cpu_to_le32(0x00004000),
856
857 FILE_ATTR_VALID_FLAGS = const_cpu_to_le32(0x00007fb7),
858 /* FILE_ATTR_VALID_FLAGS masks out the old DOS VolId and the
859 FILE_ATTR_DEVICE and preserves everything else. This mask
860 is used to obtain all flags that are valid for reading. */
861 FILE_ATTR_VALID_SET_FLAGS = const_cpu_to_le32(0x000031a7),
862 /* FILE_ATTR_VALID_SET_FLAGS masks out the old DOS VolId, the
863 FILE_ATTR_DEVICE, FILE_ATTR_DIRECTORY, FILE_ATTR_SPARSE_FILE,
864 FILE_ATTR_REPARSE_POINT, FILE_ATRE_COMPRESSED and FILE_ATTR_ENCRYPTED
865 and preserves the rest. This mask is used to to obtain all flags that
866 are valid for setting. */
867
868 /**
869 * FILE_ATTR_I30_INDEX_PRESENT - Is it a directory?
870 *
871 * This is a copy of the MFT_RECORD_IS_DIRECTORY bit from the mft
872 * record, telling us whether this is a directory or not, i.e. whether
873 * it has an index root attribute named "$I30" or not.
874 *
875 * This flag is only present in the FILE_NAME attribute (in the
876 * file_attributes field).
877 */
878 FILE_ATTR_I30_INDEX_PRESENT = const_cpu_to_le32(0x10000000),
879
880 /**
881 * FILE_ATTR_VIEW_INDEX_PRESENT - Does have a non-directory index?
882 *
883 * This is a copy of the MFT_RECORD_IS_VIEW_INDEX bit from the mft
884 * record, telling us whether this file has a view index present (eg.
885 * object id index, quota index, one of the security indexes and the
886 * reparse points index).
887 *
888 * This flag is only present in the $STANDARD_INFORMATION and
889 * $FILE_NAME attributes.
890 */
891 FILE_ATTR_VIEW_INDEX_PRESENT = const_cpu_to_le32(0x20000000),
892} __attribute__((__packed__)) FILE_ATTR_FLAGS;
893
894/*
895 * NOTE on times in NTFS: All times are in MS standard time format, i.e. they
896 * are the number of 100-nanosecond intervals since 1st January 1601, 00:00:00
897 * universal coordinated time (UTC). (In Linux time starts 1st January 1970,
898 * 00:00:00 UTC and is stored as the number of 1-second intervals since then.)
899 */
900
901/**
902 * struct STANDARD_INFORMATION - Attribute: Standard information (0x10).
903 *
904 * NOTE: Always resident.
905 * NOTE: Present in all base file records on a volume.
906 * NOTE: There is conflicting information about the meaning of each of the time
907 * fields but the meaning as defined below has been verified to be
908 * correct by practical experimentation on Windows NT4 SP6a and is hence
909 * assumed to be the one and only correct interpretation.
910 */
911typedef struct {
912/*Ofs*/
Steve Kondike68cb602016-08-28 00:45:36 -0700913/* 0*/ sle64 creation_time; /* Time file was created. Updated when
Steve Kondik2111ad72013-07-07 12:07:44 -0700914 a filename is changed(?). */
Steve Kondike68cb602016-08-28 00:45:36 -0700915/* 8*/ sle64 last_data_change_time; /* Time the data attribute was last
Steve Kondik2111ad72013-07-07 12:07:44 -0700916 modified. */
Steve Kondike68cb602016-08-28 00:45:36 -0700917/* 16*/ sle64 last_mft_change_time; /* Time this mft record was last
Steve Kondik2111ad72013-07-07 12:07:44 -0700918 modified. */
Steve Kondike68cb602016-08-28 00:45:36 -0700919/* 24*/ sle64 last_access_time; /* Approximate time when the file was
Steve Kondik2111ad72013-07-07 12:07:44 -0700920 last accessed (obviously this is not
921 updated on read-only volumes). In
922 Windows this is only updated when
923 accessed if some time delta has
924 passed since the last update. Also,
925 last access times updates can be
926 disabled altogether for speed. */
927/* 32*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */
928/* 36*/ union {
929 /* NTFS 1.2 (and previous, presumably) */
930 struct {
931 /* 36 */ u8 reserved12[12]; /* Reserved/alignment to 8-byte
932 boundary. */
933 /* 48 */ void *v1_end[0]; /* Marker for offsetof(). */
934 } __attribute__((__packed__));
935/* sizeof() = 48 bytes */
936 /* NTFS 3.0 */
937 struct {
938/*
939 * If a volume has been upgraded from a previous NTFS version, then these
940 * fields are present only if the file has been accessed since the upgrade.
941 * Recognize the difference by comparing the length of the resident attribute
942 * value. If it is 48, then the following fields are missing. If it is 72 then
943 * the fields are present. Maybe just check like this:
944 * if (resident.ValueLength < sizeof(STANDARD_INFORMATION)) {
945 * Assume NTFS 1.2- format.
946 * If (volume version is 3.0+)
947 * Upgrade attribute to NTFS 3.0 format.
948 * else
949 * Use NTFS 1.2- format for access.
950 * } else
951 * Use NTFS 3.0 format for access.
952 * Only problem is that it might be legal to set the length of the value to
953 * arbitrarily large values thus spoiling this check. - But chkdsk probably
954 * views that as a corruption, assuming that it behaves like this for all
955 * attributes.
956 */
Steve Kondike68cb602016-08-28 00:45:36 -0700957 /* 36*/ le32 maximum_versions; /* Maximum allowed versions for
Steve Kondik2111ad72013-07-07 12:07:44 -0700958 file. Zero if version numbering is disabled. */
Steve Kondike68cb602016-08-28 00:45:36 -0700959 /* 40*/ le32 version_number; /* This file's version (if any).
Steve Kondik2111ad72013-07-07 12:07:44 -0700960 Set to zero if maximum_versions is zero. */
Steve Kondike68cb602016-08-28 00:45:36 -0700961 /* 44*/ le32 class_id; /* Class id from bidirectional
Steve Kondik2111ad72013-07-07 12:07:44 -0700962 class id index (?). */
Steve Kondike68cb602016-08-28 00:45:36 -0700963 /* 48*/ le32 owner_id; /* Owner_id of the user owning
Steve Kondik2111ad72013-07-07 12:07:44 -0700964 the file. Translate via $Q index in FILE_Extend
965 /$Quota to the quota control entry for the user
966 owning the file. Zero if quotas are disabled. */
Steve Kondike68cb602016-08-28 00:45:36 -0700967 /* 52*/ le32 security_id; /* Security_id for the file.
Steve Kondik2111ad72013-07-07 12:07:44 -0700968 Translate via $SII index and $SDS data stream
969 in FILE_Secure to the security descriptor. */
Steve Kondike68cb602016-08-28 00:45:36 -0700970 /* 56*/ le64 quota_charged; /* Byte size of the charge to
Steve Kondik2111ad72013-07-07 12:07:44 -0700971 the quota for all streams of the file. Note: Is
972 zero if quotas are disabled. */
Steve Kondike68cb602016-08-28 00:45:36 -0700973 /* 64*/ le64 usn; /* Last update sequence number
Steve Kondik2111ad72013-07-07 12:07:44 -0700974 of the file. This is a direct index into the
975 change (aka usn) journal file. It is zero if
976 the usn journal is disabled.
977 NOTE: To disable the journal need to delete
978 the journal file itself and to then walk the
979 whole mft and set all Usn entries in all mft
980 records to zero! (This can take a while!)
981 The journal is FILE_Extend/$UsnJrnl. Win2k
982 will recreate the journal and initiate
983 logging if necessary when mounting the
984 partition. This, in contrast to disabling the
985 journal is a very fast process, so the user
986 won't even notice it. */
987 /* 72*/ void *v3_end[0]; /* Marker for offsetof(). */
988 } __attribute__((__packed__));
989 } __attribute__((__packed__));
990/* sizeof() = 72 bytes (NTFS 3.0) */
991} __attribute__((__packed__)) STANDARD_INFORMATION;
992
993/**
994 * struct ATTR_LIST_ENTRY - Attribute: Attribute list (0x20).
995 *
996 * - Can be either resident or non-resident.
997 * - Value consists of a sequence of variable length, 8-byte aligned,
998 * ATTR_LIST_ENTRY records.
999 * - The attribute list attribute contains one entry for each attribute of
1000 * the file in which the list is located, except for the list attribute
1001 * itself. The list is sorted: first by attribute type, second by attribute
1002 * name (if present), third by instance number. The extents of one
1003 * non-resident attribute (if present) immediately follow after the initial
1004 * extent. They are ordered by lowest_vcn and have their instance set to zero.
1005 * It is not allowed to have two attributes with all sorting keys equal.
1006 * - Further restrictions:
1007 * - If not resident, the vcn to lcn mapping array has to fit inside the
1008 * base mft record.
1009 * - The attribute list attribute value has a maximum size of 256kb. This
1010 * is imposed by the Windows cache manager.
1011 * - Attribute lists are only used when the attributes of mft record do not
1012 * fit inside the mft record despite all attributes (that can be made
1013 * non-resident) having been made non-resident. This can happen e.g. when:
1014 * - File has a large number of hard links (lots of file name
1015 * attributes present).
1016 * - The mapping pairs array of some non-resident attribute becomes so
1017 * large due to fragmentation that it overflows the mft record.
1018 * - The security descriptor is very complex (not applicable to
1019 * NTFS 3.0 volumes).
1020 * - There are many named streams.
1021 */
1022typedef struct {
1023/*Ofs*/
1024/* 0*/ ATTR_TYPES type; /* Type of referenced attribute. */
Steve Kondike68cb602016-08-28 00:45:36 -07001025/* 4*/ le16 length; /* Byte size of this entry. */
Steve Kondik2111ad72013-07-07 12:07:44 -07001026/* 6*/ u8 name_length; /* Size in Unicode chars of the name of the
1027 attribute or 0 if unnamed. */
1028/* 7*/ u8 name_offset; /* Byte offset to beginning of attribute name
1029 (always set this to where the name would
1030 start even if unnamed). */
Steve Kondike68cb602016-08-28 00:45:36 -07001031/* 8*/ leVCN lowest_vcn; /* Lowest virtual cluster number of this portion
Steve Kondik2111ad72013-07-07 12:07:44 -07001032 of the attribute value. This is usually 0. It
1033 is non-zero for the case where one attribute
1034 does not fit into one mft record and thus
1035 several mft records are allocated to hold
1036 this attribute. In the latter case, each mft
1037 record holds one extent of the attribute and
1038 there is one attribute list entry for each
1039 extent. NOTE: This is DEFINITELY a signed
1040 value! The windows driver uses cmp, followed
1041 by jg when comparing this, thus it treats it
1042 as signed. */
Steve Kondike68cb602016-08-28 00:45:36 -07001043/* 16*/ leMFT_REF mft_reference;/* The reference of the mft record holding
Steve Kondik2111ad72013-07-07 12:07:44 -07001044 the ATTR_RECORD for this portion of the
1045 attribute value. */
Steve Kondike68cb602016-08-28 00:45:36 -07001046/* 24*/ le16 instance; /* If lowest_vcn = 0, the instance of the
Steve Kondik2111ad72013-07-07 12:07:44 -07001047 attribute being referenced; otherwise 0. */
1048/* 26*/ ntfschar name[0]; /* Use when creating only. When reading use
1049 name_offset to determine the location of the
1050 name. */
1051/* sizeof() = 26 + (attribute_name_length * 2) bytes */
1052} __attribute__((__packed__)) ATTR_LIST_ENTRY;
1053
1054/*
1055 * The maximum allowed length for a file name.
1056 */
1057#define NTFS_MAX_NAME_LEN 255
1058
1059/**
1060 * enum FILE_NAME_TYPE_FLAGS - Possible namespaces for filenames in ntfs.
1061 * (8-bit).
1062 */
1063typedef enum {
1064 FILE_NAME_POSIX = 0x00,
1065 /* This is the largest namespace. It is case sensitive and
1066 allows all Unicode characters except for: '\0' and '/'.
1067 Beware that in WinNT/2k files which eg have the same name
1068 except for their case will not be distinguished by the
1069 standard utilities and thus a "del filename" will delete
1070 both "filename" and "fileName" without warning. */
1071 FILE_NAME_WIN32 = 0x01,
1072 /* The standard WinNT/2k NTFS long filenames. Case insensitive.
1073 All Unicode chars except: '\0', '"', '*', '/', ':', '<',
1074 '>', '?', '\' and '|'. Further, names cannot end with a '.'
1075 or a space. */
1076 FILE_NAME_DOS = 0x02,
1077 /* The standard DOS filenames (8.3 format). Uppercase only.
1078 All 8-bit characters greater space, except: '"', '*', '+',
1079 ',', '/', ':', ';', '<', '=', '>', '?' and '\'. */
1080 FILE_NAME_WIN32_AND_DOS = 0x03,
1081 /* 3 means that both the Win32 and the DOS filenames are
1082 identical and hence have been saved in this single filename
1083 record. */
1084} __attribute__((__packed__)) FILE_NAME_TYPE_FLAGS;
1085
1086/**
1087 * struct FILE_NAME_ATTR - Attribute: Filename (0x30).
1088 *
1089 * NOTE: Always resident.
1090 * NOTE: All fields, except the parent_directory, are only updated when the
1091 * filename is changed. Until then, they just become out of sync with
1092 * reality and the more up to date values are present in the standard
1093 * information attribute.
1094 * NOTE: There is conflicting information about the meaning of each of the time
1095 * fields but the meaning as defined below has been verified to be
1096 * correct by practical experimentation on Windows NT4 SP6a and is hence
1097 * assumed to be the one and only correct interpretation.
1098 */
1099typedef struct {
1100/*hex ofs*/
Steve Kondike68cb602016-08-28 00:45:36 -07001101/* 0*/ leMFT_REF parent_directory; /* Directory this filename is
Steve Kondik2111ad72013-07-07 12:07:44 -07001102 referenced from. */
Steve Kondike68cb602016-08-28 00:45:36 -07001103/* 8*/ sle64 creation_time; /* Time file was created. */
1104/* 10*/ sle64 last_data_change_time; /* Time the data attribute was last
Steve Kondik2111ad72013-07-07 12:07:44 -07001105 modified. */
Steve Kondike68cb602016-08-28 00:45:36 -07001106/* 18*/ sle64 last_mft_change_time; /* Time this mft record was last
Steve Kondik2111ad72013-07-07 12:07:44 -07001107 modified. */
Steve Kondike68cb602016-08-28 00:45:36 -07001108/* 20*/ sle64 last_access_time; /* Last time this mft record was
Steve Kondik2111ad72013-07-07 12:07:44 -07001109 accessed. */
Steve Kondike68cb602016-08-28 00:45:36 -07001110/* 28*/ sle64 allocated_size; /* Byte size of on-disk allocated space
Steve Kondik2111ad72013-07-07 12:07:44 -07001111 for the data attribute. So for
1112 normal $DATA, this is the
1113 allocated_size from the unnamed
1114 $DATA attribute and for compressed
1115 and/or sparse $DATA, this is the
1116 compressed_size from the unnamed
1117 $DATA attribute. NOTE: This is a
1118 multiple of the cluster size. */
Steve Kondike68cb602016-08-28 00:45:36 -07001119/* 30*/ sle64 data_size; /* Byte size of actual data in data
Steve Kondik2111ad72013-07-07 12:07:44 -07001120 attribute. */
1121/* 38*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */
1122/* 3c*/ union {
1123 /* 3c*/ struct {
Steve Kondike68cb602016-08-28 00:45:36 -07001124 /* 3c*/ le16 packed_ea_size; /* Size of the buffer needed to
Steve Kondik2111ad72013-07-07 12:07:44 -07001125 pack the extended attributes
1126 (EAs), if such are present.*/
Steve Kondike68cb602016-08-28 00:45:36 -07001127 /* 3e*/ le16 reserved; /* Reserved for alignment. */
Steve Kondik2111ad72013-07-07 12:07:44 -07001128 } __attribute__((__packed__));
Steve Kondike68cb602016-08-28 00:45:36 -07001129 /* 3c*/ le32 reparse_point_tag; /* Type of reparse point,
Steve Kondik2111ad72013-07-07 12:07:44 -07001130 present only in reparse
1131 points and only if there are
1132 no EAs. */
1133 } __attribute__((__packed__));
1134/* 40*/ u8 file_name_length; /* Length of file name in
1135 (Unicode) characters. */
1136/* 41*/ FILE_NAME_TYPE_FLAGS file_name_type; /* Namespace of the file name.*/
1137/* 42*/ ntfschar file_name[0]; /* File name in Unicode. */
1138} __attribute__((__packed__)) FILE_NAME_ATTR;
1139
1140/**
1141 * struct GUID - GUID structures store globally unique identifiers (GUID).
1142 *
1143 * A GUID is a 128-bit value consisting of one group of eight hexadecimal
1144 * digits, followed by three groups of four hexadecimal digits each, followed
1145 * by one group of twelve hexadecimal digits. GUIDs are Microsoft's
1146 * implementation of the distributed computing environment (DCE) universally
1147 * unique identifier (UUID).
1148 *
1149 * Example of a GUID:
1150 * 1F010768-5A73-BC91-0010-A52216A7227B
1151 */
1152typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07001153 le32 data1; /* The first eight hexadecimal digits of the GUID. */
1154 le16 data2; /* The first group of four hexadecimal digits. */
1155 le16 data3; /* The second group of four hexadecimal digits. */
Steve Kondik2111ad72013-07-07 12:07:44 -07001156 u8 data4[8]; /* The first two bytes are the third group of four
1157 hexadecimal digits. The remaining six bytes are the
1158 final 12 hexadecimal digits. */
1159} __attribute__((__packed__)) GUID;
1160
1161/**
1162 * struct OBJ_ID_INDEX_DATA - FILE_Extend/$ObjId contains an index named $O.
1163 *
1164 * This index contains all object_ids present on the volume as the index keys
1165 * and the corresponding mft_record numbers as the index entry data parts.
1166 *
1167 * The data part (defined below) also contains three other object_ids:
1168 * birth_volume_id - object_id of FILE_Volume on which the file was first
1169 * created. Optional (i.e. can be zero).
1170 * birth_object_id - object_id of file when it was first created. Usually
1171 * equals the object_id. Optional (i.e. can be zero).
1172 * domain_id - Reserved (always zero).
1173 */
1174typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07001175 leMFT_REF mft_reference; /* Mft record containing the object_id
1176 in the index entry key. */
Steve Kondik2111ad72013-07-07 12:07:44 -07001177 union {
1178 struct {
1179 GUID birth_volume_id;
1180 GUID birth_object_id;
1181 GUID domain_id;
1182 } __attribute__((__packed__));
1183 u8 extended_info[48];
1184 } __attribute__((__packed__));
1185} __attribute__((__packed__)) OBJ_ID_INDEX_DATA;
1186
1187/**
1188 * struct OBJECT_ID_ATTR - Attribute: Object id (NTFS 3.0+) (0x40).
1189 *
1190 * NOTE: Always resident.
1191 */
1192typedef struct {
1193 GUID object_id; /* Unique id assigned to the
1194 file.*/
1195 /* The following fields are optional. The attribute value size is 16
1196 bytes, i.e. sizeof(GUID), if these are not present at all. Note,
1197 the entries can be present but one or more (or all) can be zero
1198 meaning that that particular value(s) is(are) not defined. Note,
1199 when the fields are missing here, it is well possible that they are
1200 to be found within the $Extend/$ObjId system file indexed under the
1201 above object_id. */
1202 union {
1203 struct {
1204 GUID birth_volume_id; /* Unique id of volume on which
1205 the file was first created.*/
1206 GUID birth_object_id; /* Unique id of file when it was
1207 first created. */
1208 GUID domain_id; /* Reserved, zero. */
1209 } __attribute__((__packed__));
1210 u8 extended_info[48];
1211 } __attribute__((__packed__));
1212} __attribute__((__packed__)) OBJECT_ID_ATTR;
1213
1214#if 0
1215/**
1216 * enum IDENTIFIER_AUTHORITIES -
1217 *
1218 * The pre-defined IDENTIFIER_AUTHORITIES used as SID_IDENTIFIER_AUTHORITY in
1219 * the SID structure (see below).
1220 */
1221typedef enum { /* SID string prefix. */
1222 SECURITY_NULL_SID_AUTHORITY = {0, 0, 0, 0, 0, 0}, /* S-1-0 */
1223 SECURITY_WORLD_SID_AUTHORITY = {0, 0, 0, 0, 0, 1}, /* S-1-1 */
1224 SECURITY_LOCAL_SID_AUTHORITY = {0, 0, 0, 0, 0, 2}, /* S-1-2 */
1225 SECURITY_CREATOR_SID_AUTHORITY = {0, 0, 0, 0, 0, 3}, /* S-1-3 */
1226 SECURITY_NON_UNIQUE_AUTHORITY = {0, 0, 0, 0, 0, 4}, /* S-1-4 */
1227 SECURITY_NT_SID_AUTHORITY = {0, 0, 0, 0, 0, 5}, /* S-1-5 */
1228} IDENTIFIER_AUTHORITIES;
1229#endif
1230
1231/**
1232 * enum RELATIVE_IDENTIFIERS -
1233 *
1234 * These relative identifiers (RIDs) are used with the above identifier
1235 * authorities to make up universal well-known SIDs.
1236 *
1237 * Note: The relative identifier (RID) refers to the portion of a SID, which
1238 * identifies a user or group in relation to the authority that issued the SID.
1239 * For example, the universal well-known SID Creator Owner ID (S-1-3-0) is
1240 * made up of the identifier authority SECURITY_CREATOR_SID_AUTHORITY (3) and
1241 * the relative identifier SECURITY_CREATOR_OWNER_RID (0).
1242 */
1243typedef enum { /* Identifier authority. */
1244 SECURITY_NULL_RID = 0, /* S-1-0 */
1245 SECURITY_WORLD_RID = 0, /* S-1-1 */
1246 SECURITY_LOCAL_RID = 0, /* S-1-2 */
1247
1248 SECURITY_CREATOR_OWNER_RID = 0, /* S-1-3 */
1249 SECURITY_CREATOR_GROUP_RID = 1, /* S-1-3 */
1250
1251 SECURITY_CREATOR_OWNER_SERVER_RID = 2, /* S-1-3 */
1252 SECURITY_CREATOR_GROUP_SERVER_RID = 3, /* S-1-3 */
1253
1254 SECURITY_DIALUP_RID = 1,
1255 SECURITY_NETWORK_RID = 2,
1256 SECURITY_BATCH_RID = 3,
1257 SECURITY_INTERACTIVE_RID = 4,
1258 SECURITY_SERVICE_RID = 6,
1259 SECURITY_ANONYMOUS_LOGON_RID = 7,
1260 SECURITY_PROXY_RID = 8,
1261 SECURITY_ENTERPRISE_CONTROLLERS_RID=9,
1262 SECURITY_SERVER_LOGON_RID = 9,
1263 SECURITY_PRINCIPAL_SELF_RID = 0xa,
1264 SECURITY_AUTHENTICATED_USER_RID = 0xb,
1265 SECURITY_RESTRICTED_CODE_RID = 0xc,
1266 SECURITY_TERMINAL_SERVER_RID = 0xd,
1267
1268 SECURITY_LOGON_IDS_RID = 5,
1269 SECURITY_LOGON_IDS_RID_COUNT = 3,
1270
1271 SECURITY_LOCAL_SYSTEM_RID = 0x12,
1272
1273 SECURITY_NT_NON_UNIQUE = 0x15,
1274
1275 SECURITY_BUILTIN_DOMAIN_RID = 0x20,
1276
1277 /*
1278 * Well-known domain relative sub-authority values (RIDs).
1279 */
1280
1281 /* Users. */
1282 DOMAIN_USER_RID_ADMIN = 0x1f4,
1283 DOMAIN_USER_RID_GUEST = 0x1f5,
1284 DOMAIN_USER_RID_KRBTGT = 0x1f6,
1285
1286 /* Groups. */
1287 DOMAIN_GROUP_RID_ADMINS = 0x200,
1288 DOMAIN_GROUP_RID_USERS = 0x201,
1289 DOMAIN_GROUP_RID_GUESTS = 0x202,
1290 DOMAIN_GROUP_RID_COMPUTERS = 0x203,
1291 DOMAIN_GROUP_RID_CONTROLLERS = 0x204,
1292 DOMAIN_GROUP_RID_CERT_ADMINS = 0x205,
1293 DOMAIN_GROUP_RID_SCHEMA_ADMINS = 0x206,
1294 DOMAIN_GROUP_RID_ENTERPRISE_ADMINS= 0x207,
1295 DOMAIN_GROUP_RID_POLICY_ADMINS = 0x208,
1296
1297 /* Aliases. */
1298 DOMAIN_ALIAS_RID_ADMINS = 0x220,
1299 DOMAIN_ALIAS_RID_USERS = 0x221,
1300 DOMAIN_ALIAS_RID_GUESTS = 0x222,
1301 DOMAIN_ALIAS_RID_POWER_USERS = 0x223,
1302
1303 DOMAIN_ALIAS_RID_ACCOUNT_OPS = 0x224,
1304 DOMAIN_ALIAS_RID_SYSTEM_OPS = 0x225,
1305 DOMAIN_ALIAS_RID_PRINT_OPS = 0x226,
1306 DOMAIN_ALIAS_RID_BACKUP_OPS = 0x227,
1307
1308 DOMAIN_ALIAS_RID_REPLICATOR = 0x228,
1309 DOMAIN_ALIAS_RID_RAS_SERVERS = 0x229,
1310 DOMAIN_ALIAS_RID_PREW2KCOMPACCESS = 0x22a,
1311} RELATIVE_IDENTIFIERS;
1312
1313/*
1314 * The universal well-known SIDs:
1315 *
1316 * NULL_SID S-1-0-0
1317 * WORLD_SID S-1-1-0
1318 * LOCAL_SID S-1-2-0
1319 * CREATOR_OWNER_SID S-1-3-0
1320 * CREATOR_GROUP_SID S-1-3-1
1321 * CREATOR_OWNER_SERVER_SID S-1-3-2
1322 * CREATOR_GROUP_SERVER_SID S-1-3-3
1323 *
1324 * (Non-unique IDs) S-1-4
1325 *
1326 * NT well-known SIDs:
1327 *
1328 * NT_AUTHORITY_SID S-1-5
1329 * DIALUP_SID S-1-5-1
1330 *
1331 * NETWORD_SID S-1-5-2
1332 * BATCH_SID S-1-5-3
1333 * INTERACTIVE_SID S-1-5-4
1334 * SERVICE_SID S-1-5-6
1335 * ANONYMOUS_LOGON_SID S-1-5-7 (aka null logon session)
1336 * PROXY_SID S-1-5-8
1337 * SERVER_LOGON_SID S-1-5-9 (aka domain controller account)
1338 * SELF_SID S-1-5-10 (self RID)
1339 * AUTHENTICATED_USER_SID S-1-5-11
1340 * RESTRICTED_CODE_SID S-1-5-12 (running restricted code)
1341 * TERMINAL_SERVER_SID S-1-5-13 (running on terminal server)
1342 *
1343 * (Logon IDs) S-1-5-5-X-Y
1344 *
1345 * (NT non-unique IDs) S-1-5-0x15-...
1346 *
1347 * (Built-in domain) S-1-5-0x20
1348 */
1349
1350/**
1351 * union SID_IDENTIFIER_AUTHORITY - A 48-bit value used in the SID structure
1352 *
1353 * NOTE: This is stored as a big endian number.
1354 */
1355typedef union {
1356 struct {
Steve Kondike68cb602016-08-28 00:45:36 -07001357 be16 high_part; /* High 16-bits. */
1358 be32 low_part; /* Low 32-bits. */
Steve Kondik2111ad72013-07-07 12:07:44 -07001359 } __attribute__((__packed__));
1360 u8 value[6]; /* Value as individual bytes. */
1361} __attribute__((__packed__)) SID_IDENTIFIER_AUTHORITY;
1362
1363/**
1364 * struct SID -
1365 *
1366 * The SID structure is a variable-length structure used to uniquely identify
1367 * users or groups. SID stands for security identifier.
1368 *
1369 * The standard textual representation of the SID is of the form:
1370 * S-R-I-S-S...
1371 * Where:
1372 * - The first "S" is the literal character 'S' identifying the following
1373 * digits as a SID.
1374 * - R is the revision level of the SID expressed as a sequence of digits
1375 * in decimal.
1376 * - I is the 48-bit identifier_authority, expressed as digits in decimal,
1377 * if I < 2^32, or hexadecimal prefixed by "0x", if I >= 2^32.
1378 * - S... is one or more sub_authority values, expressed as digits in
1379 * decimal.
1380 *
1381 * Example SID; the domain-relative SID of the local Administrators group on
1382 * Windows NT/2k:
1383 * S-1-5-32-544
1384 * This translates to a SID with:
1385 * revision = 1,
1386 * sub_authority_count = 2,
1387 * identifier_authority = {0,0,0,0,0,5}, // SECURITY_NT_AUTHORITY
1388 * sub_authority[0] = 32, // SECURITY_BUILTIN_DOMAIN_RID
1389 * sub_authority[1] = 544 // DOMAIN_ALIAS_RID_ADMINS
1390 */
1391typedef struct {
1392 u8 revision;
1393 u8 sub_authority_count;
1394 SID_IDENTIFIER_AUTHORITY identifier_authority;
Steve Kondike68cb602016-08-28 00:45:36 -07001395 le32 sub_authority[1]; /* At least one sub_authority. */
Steve Kondik2111ad72013-07-07 12:07:44 -07001396} __attribute__((__packed__)) SID;
1397
1398/**
1399 * enum SID_CONSTANTS - Current constants for SIDs.
1400 */
1401typedef enum {
1402 SID_REVISION = 1, /* Current revision level. */
1403 SID_MAX_SUB_AUTHORITIES = 15, /* Maximum number of those. */
1404 SID_RECOMMENDED_SUB_AUTHORITIES = 1, /* Will change to around 6 in
1405 a future revision. */
1406} SID_CONSTANTS;
1407
1408/**
1409 * enum ACE_TYPES - The predefined ACE types (8-bit, see below).
1410 */
1411typedef enum {
1412 ACCESS_MIN_MS_ACE_TYPE = 0,
1413 ACCESS_ALLOWED_ACE_TYPE = 0,
1414 ACCESS_DENIED_ACE_TYPE = 1,
1415 SYSTEM_AUDIT_ACE_TYPE = 2,
1416 SYSTEM_ALARM_ACE_TYPE = 3, /* Not implemented as of Win2k. */
1417 ACCESS_MAX_MS_V2_ACE_TYPE = 3,
1418
1419 ACCESS_ALLOWED_COMPOUND_ACE_TYPE= 4,
1420 ACCESS_MAX_MS_V3_ACE_TYPE = 4,
1421
1422 /* The following are Win2k only. */
1423 ACCESS_MIN_MS_OBJECT_ACE_TYPE = 5,
1424 ACCESS_ALLOWED_OBJECT_ACE_TYPE = 5,
1425 ACCESS_DENIED_OBJECT_ACE_TYPE = 6,
1426 SYSTEM_AUDIT_OBJECT_ACE_TYPE = 7,
1427 SYSTEM_ALARM_OBJECT_ACE_TYPE = 8,
1428 ACCESS_MAX_MS_OBJECT_ACE_TYPE = 8,
1429
1430 ACCESS_MAX_MS_V4_ACE_TYPE = 8,
1431
1432 /* This one is for WinNT&2k. */
1433 ACCESS_MAX_MS_ACE_TYPE = 8,
1434} __attribute__((__packed__)) ACE_TYPES;
1435
1436/**
1437 * enum ACE_FLAGS - The ACE flags (8-bit) for audit and inheritance.
1438 *
1439 * SUCCESSFUL_ACCESS_ACE_FLAG is only used with system audit and alarm ACE
1440 * types to indicate that a message is generated (in Windows!) for successful
1441 * accesses.
1442 *
1443 * FAILED_ACCESS_ACE_FLAG is only used with system audit and alarm ACE types
1444 * to indicate that a message is generated (in Windows!) for failed accesses.
1445 */
1446typedef enum {
1447 /* The inheritance flags. */
1448 OBJECT_INHERIT_ACE = 0x01,
1449 CONTAINER_INHERIT_ACE = 0x02,
1450 NO_PROPAGATE_INHERIT_ACE = 0x04,
1451 INHERIT_ONLY_ACE = 0x08,
1452 INHERITED_ACE = 0x10, /* Win2k only. */
1453 VALID_INHERIT_FLAGS = 0x1f,
1454
1455 /* The audit flags. */
1456 SUCCESSFUL_ACCESS_ACE_FLAG = 0x40,
1457 FAILED_ACCESS_ACE_FLAG = 0x80,
1458} __attribute__((__packed__)) ACE_FLAGS;
1459
1460/**
1461 * struct ACE_HEADER -
1462 *
1463 * An ACE is an access-control entry in an access-control list (ACL).
1464 * An ACE defines access to an object for a specific user or group or defines
1465 * the types of access that generate system-administration messages or alarms
1466 * for a specific user or group. The user or group is identified by a security
1467 * identifier (SID).
1468 *
1469 * Each ACE starts with an ACE_HEADER structure (aligned on 4-byte boundary),
1470 * which specifies the type and size of the ACE. The format of the subsequent
1471 * data depends on the ACE type.
1472 */
1473typedef struct {
1474 ACE_TYPES type; /* Type of the ACE. */
1475 ACE_FLAGS flags; /* Flags describing the ACE. */
Steve Kondike68cb602016-08-28 00:45:36 -07001476 le16 size; /* Size in bytes of the ACE. */
Steve Kondik2111ad72013-07-07 12:07:44 -07001477} __attribute__((__packed__)) ACE_HEADER;
1478
1479/**
1480 * enum ACCESS_MASK - The access mask (32-bit).
1481 *
1482 * Defines the access rights.
1483 */
1484typedef enum {
1485 /*
1486 * The specific rights (bits 0 to 15). Depend on the type of the
1487 * object being secured by the ACE.
1488 */
1489
1490 /* Specific rights for files and directories are as follows: */
1491
1492 /* Right to read data from the file. (FILE) */
1493 FILE_READ_DATA = const_cpu_to_le32(0x00000001),
1494 /* Right to list contents of a directory. (DIRECTORY) */
1495 FILE_LIST_DIRECTORY = const_cpu_to_le32(0x00000001),
1496
1497 /* Right to write data to the file. (FILE) */
1498 FILE_WRITE_DATA = const_cpu_to_le32(0x00000002),
1499 /* Right to create a file in the directory. (DIRECTORY) */
1500 FILE_ADD_FILE = const_cpu_to_le32(0x00000002),
1501
1502 /* Right to append data to the file. (FILE) */
1503 FILE_APPEND_DATA = const_cpu_to_le32(0x00000004),
1504 /* Right to create a subdirectory. (DIRECTORY) */
1505 FILE_ADD_SUBDIRECTORY = const_cpu_to_le32(0x00000004),
1506
1507 /* Right to read extended attributes. (FILE/DIRECTORY) */
1508 FILE_READ_EA = const_cpu_to_le32(0x00000008),
1509
1510 /* Right to write extended attributes. (FILE/DIRECTORY) */
1511 FILE_WRITE_EA = const_cpu_to_le32(0x00000010),
1512
1513 /* Right to execute a file. (FILE) */
1514 FILE_EXECUTE = const_cpu_to_le32(0x00000020),
1515 /* Right to traverse the directory. (DIRECTORY) */
1516 FILE_TRAVERSE = const_cpu_to_le32(0x00000020),
1517
1518 /*
1519 * Right to delete a directory and all the files it contains (its
1520 * children), even if the files are read-only. (DIRECTORY)
1521 */
1522 FILE_DELETE_CHILD = const_cpu_to_le32(0x00000040),
1523
1524 /* Right to read file attributes. (FILE/DIRECTORY) */
1525 FILE_READ_ATTRIBUTES = const_cpu_to_le32(0x00000080),
1526
1527 /* Right to change file attributes. (FILE/DIRECTORY) */
1528 FILE_WRITE_ATTRIBUTES = const_cpu_to_le32(0x00000100),
1529
1530 /*
1531 * The standard rights (bits 16 to 23). Are independent of the type of
1532 * object being secured.
1533 */
1534
1535 /* Right to delete the object. */
1536 DELETE = const_cpu_to_le32(0x00010000),
1537
1538 /*
1539 * Right to read the information in the object's security descriptor,
1540 * not including the information in the SACL. I.e. right to read the
1541 * security descriptor and owner.
1542 */
1543 READ_CONTROL = const_cpu_to_le32(0x00020000),
1544
1545 /* Right to modify the DACL in the object's security descriptor. */
1546 WRITE_DAC = const_cpu_to_le32(0x00040000),
1547
1548 /* Right to change the owner in the object's security descriptor. */
1549 WRITE_OWNER = const_cpu_to_le32(0x00080000),
1550
1551 /*
1552 * Right to use the object for synchronization. Enables a process to
1553 * wait until the object is in the signalled state. Some object types
1554 * do not support this access right.
1555 */
1556 SYNCHRONIZE = const_cpu_to_le32(0x00100000),
1557
1558 /*
1559 * The following STANDARD_RIGHTS_* are combinations of the above for
1560 * convenience and are defined by the Win32 API.
1561 */
1562
1563 /* These are currently defined to READ_CONTROL. */
1564 STANDARD_RIGHTS_READ = const_cpu_to_le32(0x00020000),
1565 STANDARD_RIGHTS_WRITE = const_cpu_to_le32(0x00020000),
1566 STANDARD_RIGHTS_EXECUTE = const_cpu_to_le32(0x00020000),
1567
1568 /* Combines DELETE, READ_CONTROL, WRITE_DAC, and WRITE_OWNER access. */
1569 STANDARD_RIGHTS_REQUIRED = const_cpu_to_le32(0x000f0000),
1570
1571 /*
1572 * Combines DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, and
1573 * SYNCHRONIZE access.
1574 */
1575 STANDARD_RIGHTS_ALL = const_cpu_to_le32(0x001f0000),
1576
1577 /*
1578 * The access system ACL and maximum allowed access types (bits 24 to
1579 * 25, bits 26 to 27 are reserved).
1580 */
1581 ACCESS_SYSTEM_SECURITY = const_cpu_to_le32(0x01000000),
1582 MAXIMUM_ALLOWED = const_cpu_to_le32(0x02000000),
1583
1584 /*
1585 * The generic rights (bits 28 to 31). These map onto the standard and
1586 * specific rights.
1587 */
1588
1589 /* Read, write, and execute access. */
1590 GENERIC_ALL = const_cpu_to_le32(0x10000000),
1591
1592 /* Execute access. */
1593 GENERIC_EXECUTE = const_cpu_to_le32(0x20000000),
1594
1595 /*
1596 * Write access. For files, this maps onto:
1597 * FILE_APPEND_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_DATA |
1598 * FILE_WRITE_EA | STANDARD_RIGHTS_WRITE | SYNCHRONIZE
1599 * For directories, the mapping has the same numerical value. See
1600 * above for the descriptions of the rights granted.
1601 */
1602 GENERIC_WRITE = const_cpu_to_le32(0x40000000),
1603
1604 /*
1605 * Read access. For files, this maps onto:
1606 * FILE_READ_ATTRIBUTES | FILE_READ_DATA | FILE_READ_EA |
1607 * STANDARD_RIGHTS_READ | SYNCHRONIZE
1608 * For directories, the mapping has the same numerical value. See
1609 * above for the descriptions of the rights granted.
1610 */
1611 GENERIC_READ = const_cpu_to_le32(0x80000000),
1612} ACCESS_MASK;
1613
1614/**
1615 * struct GENERIC_MAPPING -
1616 *
1617 * The generic mapping array. Used to denote the mapping of each generic
1618 * access right to a specific access mask.
1619 *
1620 * FIXME: What exactly is this and what is it for? (AIA)
1621 */
1622typedef struct {
1623 ACCESS_MASK generic_read;
1624 ACCESS_MASK generic_write;
1625 ACCESS_MASK generic_execute;
1626 ACCESS_MASK generic_all;
1627} __attribute__((__packed__)) GENERIC_MAPPING;
1628
1629/*
1630 * The predefined ACE type structures are as defined below.
1631 */
1632
1633/**
1634 * struct ACCESS_DENIED_ACE -
1635 *
1636 * ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE
1637 */
1638typedef struct {
1639/* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */
1640 ACE_TYPES type; /* Type of the ACE. */
1641 ACE_FLAGS flags; /* Flags describing the ACE. */
Steve Kondike68cb602016-08-28 00:45:36 -07001642 le16 size; /* Size in bytes of the ACE. */
Steve Kondik2111ad72013-07-07 12:07:44 -07001643
1644/* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */
1645/* 8*/ SID sid; /* The SID associated with the ACE. */
1646} __attribute__((__packed__)) ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE,
1647 SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE;
1648
1649/**
1650 * enum OBJECT_ACE_FLAGS - The object ACE flags (32-bit).
1651 */
1652typedef enum {
1653 ACE_OBJECT_TYPE_PRESENT = const_cpu_to_le32(1),
1654 ACE_INHERITED_OBJECT_TYPE_PRESENT = const_cpu_to_le32(2),
1655} OBJECT_ACE_FLAGS;
1656
1657/**
1658 * struct ACCESS_ALLOWED_OBJECT_ACE -
1659 */
1660typedef struct {
1661/* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */
1662 ACE_TYPES type; /* Type of the ACE. */
1663 ACE_FLAGS flags; /* Flags describing the ACE. */
Steve Kondike68cb602016-08-28 00:45:36 -07001664 le16 size; /* Size in bytes of the ACE. */
Steve Kondik2111ad72013-07-07 12:07:44 -07001665
1666/* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */
1667/* 8*/ OBJECT_ACE_FLAGS object_flags; /* Flags describing the object ACE. */
1668/* 12*/ GUID object_type;
1669/* 28*/ GUID inherited_object_type;
1670/* 44*/ SID sid; /* The SID associated with the ACE. */
1671} __attribute__((__packed__)) ACCESS_ALLOWED_OBJECT_ACE,
1672 ACCESS_DENIED_OBJECT_ACE,
1673 SYSTEM_AUDIT_OBJECT_ACE,
1674 SYSTEM_ALARM_OBJECT_ACE;
1675
1676/**
1677 * struct ACL - An ACL is an access-control list (ACL).
1678 *
1679 * An ACL starts with an ACL header structure, which specifies the size of
1680 * the ACL and the number of ACEs it contains. The ACL header is followed by
1681 * zero or more access control entries (ACEs). The ACL as well as each ACE
1682 * are aligned on 4-byte boundaries.
1683 */
1684typedef struct {
1685 u8 revision; /* Revision of this ACL. */
1686 u8 alignment1;
Steve Kondike68cb602016-08-28 00:45:36 -07001687 le16 size; /* Allocated space in bytes for ACL. Includes this
Steve Kondik2111ad72013-07-07 12:07:44 -07001688 header, the ACEs and the remaining free space. */
Steve Kondike68cb602016-08-28 00:45:36 -07001689 le16 ace_count; /* Number of ACEs in the ACL. */
1690 le16 alignment2;
Steve Kondik2111ad72013-07-07 12:07:44 -07001691/* sizeof() = 8 bytes */
1692} __attribute__((__packed__)) ACL;
1693
1694/**
1695 * enum ACL_CONSTANTS - Current constants for ACLs.
1696 */
1697typedef enum {
1698 /* Current revision. */
1699 ACL_REVISION = 2,
1700 ACL_REVISION_DS = 4,
1701
1702 /* History of revisions. */
1703 ACL_REVISION1 = 1,
1704 MIN_ACL_REVISION = 2,
1705 ACL_REVISION2 = 2,
1706 ACL_REVISION3 = 3,
1707 ACL_REVISION4 = 4,
1708 MAX_ACL_REVISION = 4,
1709} ACL_CONSTANTS;
1710
1711/**
1712 * enum SECURITY_DESCRIPTOR_CONTROL -
1713 *
1714 * The security descriptor control flags (16-bit).
1715 *
1716 * SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the
1717 * SID pointed to by the Owner field was provided by a
1718 * defaulting mechanism rather than explicitly provided by the
1719 * original provider of the security descriptor. This may
1720 * affect the treatment of the SID with respect to inheritance
1721 * of an owner.
1722 *
1723 * SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the
1724 * SID in the Group field was provided by a defaulting mechanism
1725 * rather than explicitly provided by the original provider of
1726 * the security descriptor. This may affect the treatment of
1727 * the SID with respect to inheritance of a primary group.
1728 *
1729 * SE_DACL_PRESENT - This boolean flag, when set, indicates that the
1730 * security descriptor contains a discretionary ACL. If this
1731 * flag is set and the Dacl field of the SECURITY_DESCRIPTOR is
1732 * null, then a null ACL is explicitly being specified.
1733 *
1734 * SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the
1735 * ACL pointed to by the Dacl field was provided by a defaulting
1736 * mechanism rather than explicitly provided by the original
1737 * provider of the security descriptor. This may affect the
1738 * treatment of the ACL with respect to inheritance of an ACL.
1739 * This flag is ignored if the DaclPresent flag is not set.
1740 *
1741 * SE_SACL_PRESENT - This boolean flag, when set, indicates that the
1742 * security descriptor contains a system ACL pointed to by the
1743 * Sacl field. If this flag is set and the Sacl field of the
1744 * SECURITY_DESCRIPTOR is null, then an empty (but present)
1745 * ACL is being specified.
1746 *
1747 * SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the
1748 * ACL pointed to by the Sacl field was provided by a defaulting
1749 * mechanism rather than explicitly provided by the original
1750 * provider of the security descriptor. This may affect the
1751 * treatment of the ACL with respect to inheritance of an ACL.
1752 * This flag is ignored if the SaclPresent flag is not set.
1753 *
1754 * SE_SELF_RELATIVE - This boolean flag, when set, indicates that the
1755 * security descriptor is in self-relative form. In this form,
1756 * all fields of the security descriptor are contiguous in memory
1757 * and all pointer fields are expressed as offsets from the
1758 * beginning of the security descriptor.
1759 */
1760typedef enum {
1761 SE_OWNER_DEFAULTED = const_cpu_to_le16(0x0001),
1762 SE_GROUP_DEFAULTED = const_cpu_to_le16(0x0002),
1763 SE_DACL_PRESENT = const_cpu_to_le16(0x0004),
1764 SE_DACL_DEFAULTED = const_cpu_to_le16(0x0008),
1765 SE_SACL_PRESENT = const_cpu_to_le16(0x0010),
1766 SE_SACL_DEFAULTED = const_cpu_to_le16(0x0020),
1767 SE_DACL_AUTO_INHERIT_REQ = const_cpu_to_le16(0x0100),
1768 SE_SACL_AUTO_INHERIT_REQ = const_cpu_to_le16(0x0200),
1769 SE_DACL_AUTO_INHERITED = const_cpu_to_le16(0x0400),
1770 SE_SACL_AUTO_INHERITED = const_cpu_to_le16(0x0800),
1771 SE_DACL_PROTECTED = const_cpu_to_le16(0x1000),
1772 SE_SACL_PROTECTED = const_cpu_to_le16(0x2000),
1773 SE_RM_CONTROL_VALID = const_cpu_to_le16(0x4000),
1774 SE_SELF_RELATIVE = const_cpu_to_le16(0x8000),
1775} __attribute__((__packed__)) SECURITY_DESCRIPTOR_CONTROL;
1776
1777/**
1778 * struct SECURITY_DESCRIPTOR_RELATIVE -
1779 *
1780 * Self-relative security descriptor. Contains the owner and group SIDs as well
1781 * as the sacl and dacl ACLs inside the security descriptor itself.
1782 */
1783typedef struct {
1784 u8 revision; /* Revision level of the security descriptor. */
1785 u8 alignment;
1786 SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of
1787 the descriptor as well as the following fields. */
Steve Kondike68cb602016-08-28 00:45:36 -07001788 le32 owner; /* Byte offset to a SID representing an object's
Steve Kondik2111ad72013-07-07 12:07:44 -07001789 owner. If this is NULL, no owner SID is present in
1790 the descriptor. */
Steve Kondike68cb602016-08-28 00:45:36 -07001791 le32 group; /* Byte offset to a SID representing an object's
Steve Kondik2111ad72013-07-07 12:07:44 -07001792 primary group. If this is NULL, no primary group
1793 SID is present in the descriptor. */
Steve Kondike68cb602016-08-28 00:45:36 -07001794 le32 sacl; /* Byte offset to a system ACL. Only valid, if
Steve Kondik2111ad72013-07-07 12:07:44 -07001795 SE_SACL_PRESENT is set in the control field. If
1796 SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL
1797 is specified. */
Steve Kondike68cb602016-08-28 00:45:36 -07001798 le32 dacl; /* Byte offset to a discretionary ACL. Only valid, if
Steve Kondik2111ad72013-07-07 12:07:44 -07001799 SE_DACL_PRESENT is set in the control field. If
1800 SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL
1801 (unconditionally granting access) is specified. */
1802/* sizeof() = 0x14 bytes */
1803} __attribute__((__packed__)) SECURITY_DESCRIPTOR_RELATIVE;
1804
1805/**
1806 * struct SECURITY_DESCRIPTOR - Absolute security descriptor.
1807 *
1808 * Does not contain the owner and group SIDs, nor the sacl and dacl ACLs inside
1809 * the security descriptor. Instead, it contains pointers to these structures
1810 * in memory. Obviously, absolute security descriptors are only useful for in
1811 * memory representations of security descriptors.
1812 *
1813 * On disk, a self-relative security descriptor is used.
1814 */
1815typedef struct {
1816 u8 revision; /* Revision level of the security descriptor. */
1817 u8 alignment;
1818 SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of
1819 the descriptor as well as the following fields. */
1820 SID *owner; /* Points to a SID representing an object's owner. If
1821 this is NULL, no owner SID is present in the
1822 descriptor. */
1823 SID *group; /* Points to a SID representing an object's primary
1824 group. If this is NULL, no primary group SID is
1825 present in the descriptor. */
1826 ACL *sacl; /* Points to a system ACL. Only valid, if
1827 SE_SACL_PRESENT is set in the control field. If
1828 SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL
1829 is specified. */
1830 ACL *dacl; /* Points to a discretionary ACL. Only valid, if
1831 SE_DACL_PRESENT is set in the control field. If
1832 SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL
1833 (unconditionally granting access) is specified. */
1834} __attribute__((__packed__)) SECURITY_DESCRIPTOR;
1835
1836/**
1837 * enum SECURITY_DESCRIPTOR_CONSTANTS -
1838 *
1839 * Current constants for security descriptors.
1840 */
1841typedef enum {
1842 /* Current revision. */
1843 SECURITY_DESCRIPTOR_REVISION = 1,
1844 SECURITY_DESCRIPTOR_REVISION1 = 1,
1845
1846 /* The sizes of both the absolute and relative security descriptors is
1847 the same as pointers, at least on ia32 architecture are 32-bit. */
1848 SECURITY_DESCRIPTOR_MIN_LENGTH = sizeof(SECURITY_DESCRIPTOR),
1849} SECURITY_DESCRIPTOR_CONSTANTS;
1850
1851/*
1852 * Attribute: Security descriptor (0x50).
1853 *
1854 * A standard self-relative security descriptor.
1855 *
1856 * NOTE: Can be resident or non-resident.
1857 * NOTE: Not used in NTFS 3.0+, as security descriptors are stored centrally
1858 * in FILE_Secure and the correct descriptor is found using the security_id
1859 * from the standard information attribute.
1860 */
1861typedef SECURITY_DESCRIPTOR_RELATIVE SECURITY_DESCRIPTOR_ATTR;
1862
1863/*
1864 * On NTFS 3.0+, all security descriptors are stored in FILE_Secure. Only one
1865 * referenced instance of each unique security descriptor is stored.
1866 *
1867 * FILE_Secure contains no unnamed data attribute, i.e. it has zero length. It
1868 * does, however, contain two indexes ($SDH and $SII) as well as a named data
1869 * stream ($SDS).
1870 *
1871 * Every unique security descriptor is assigned a unique security identifier
1872 * (security_id, not to be confused with a SID). The security_id is unique for
1873 * the NTFS volume and is used as an index into the $SII index, which maps
1874 * security_ids to the security descriptor's storage location within the $SDS
1875 * data attribute. The $SII index is sorted by ascending security_id.
1876 *
1877 * A simple hash is computed from each security descriptor. This hash is used
1878 * as an index into the $SDH index, which maps security descriptor hashes to
1879 * the security descriptor's storage location within the $SDS data attribute.
1880 * The $SDH index is sorted by security descriptor hash and is stored in a B+
1881 * tree. When searching $SDH (with the intent of determining whether or not a
1882 * new security descriptor is already present in the $SDS data stream), if a
1883 * matching hash is found, but the security descriptors do not match, the
1884 * search in the $SDH index is continued, searching for a next matching hash.
1885 *
1886 * When a precise match is found, the security_id corresponding to the security
1887 * descriptor in the $SDS attribute is read from the found $SDH index entry and
1888 * is stored in the $STANDARD_INFORMATION attribute of the file/directory to
1889 * which the security descriptor is being applied. The $STANDARD_INFORMATION
1890 * attribute is present in all base mft records (i.e. in all files and
1891 * directories).
1892 *
1893 * If a match is not found, the security descriptor is assigned a new unique
1894 * security_id and is added to the $SDS data attribute. Then, entries
1895 * referencing the this security descriptor in the $SDS data attribute are
1896 * added to the $SDH and $SII indexes.
1897 *
1898 * Note: Entries are never deleted from FILE_Secure, even if nothing
1899 * references an entry any more.
1900 */
1901
1902/**
1903 * struct SECURITY_DESCRIPTOR_HEADER -
1904 *
1905 * This header precedes each security descriptor in the $SDS data stream.
1906 * This is also the index entry data part of both the $SII and $SDH indexes.
1907 */
1908typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07001909 le32 hash; /* Hash of the security descriptor. */
1910 le32 security_id; /* The security_id assigned to the descriptor. */
1911 le64 offset; /* Byte offset of this entry in the $SDS stream. */
1912 le32 length; /* Size in bytes of this entry in $SDS stream. */
Steve Kondik2111ad72013-07-07 12:07:44 -07001913} __attribute__((__packed__)) SECURITY_DESCRIPTOR_HEADER;
1914
1915/**
1916 * struct SDH_INDEX_DATA -
1917 */
1918typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07001919 le32 hash; /* Hash of the security descriptor. */
1920 le32 security_id; /* The security_id assigned to the descriptor. */
1921 le64 offset; /* Byte offset of this entry in the $SDS stream. */
1922 le32 length; /* Size in bytes of this entry in $SDS stream. */
1923 le32 reserved_II; /* Padding - always unicode "II" or zero. This field
Steve Kondik2111ad72013-07-07 12:07:44 -07001924 isn't counted in INDEX_ENTRY's data_length. */
1925} __attribute__((__packed__)) SDH_INDEX_DATA;
1926
1927/**
1928 * struct SII_INDEX_DATA -
1929 */
1930typedef SECURITY_DESCRIPTOR_HEADER SII_INDEX_DATA;
1931
1932/**
1933 * struct SDS_ENTRY -
1934 *
1935 * The $SDS data stream contains the security descriptors, aligned on 16-byte
1936 * boundaries, sorted by security_id in a B+ tree. Security descriptors cannot
1937 * cross 256kib boundaries (this restriction is imposed by the Windows cache
1938 * manager). Each security descriptor is contained in a SDS_ENTRY structure.
1939 * Also, each security descriptor is stored twice in the $SDS stream with a
1940 * fixed offset of 0x40000 bytes (256kib, the Windows cache manager's max size)
1941 * between them; i.e. if a SDS_ENTRY specifies an offset of 0x51d0, then the
1942 * the first copy of the security descriptor will be at offset 0x51d0 in the
1943 * $SDS data stream and the second copy will be at offset 0x451d0.
1944 */
1945typedef struct {
1946/* 0 SECURITY_DESCRIPTOR_HEADER; -- Unfolded here as gcc doesn't like
1947 unnamed structs. */
Steve Kondike68cb602016-08-28 00:45:36 -07001948 le32 hash; /* Hash of the security descriptor. */
1949 le32 security_id; /* The security_id assigned to the descriptor. */
1950 le64 offset; /* Byte offset of this entry in the $SDS stream. */
1951 le32 length; /* Size in bytes of this entry in $SDS stream. */
Steve Kondik2111ad72013-07-07 12:07:44 -07001952/* 20*/ SECURITY_DESCRIPTOR_RELATIVE sid; /* The self-relative security
1953 descriptor. */
1954} __attribute__((__packed__)) SDS_ENTRY;
1955
1956/**
1957 * struct SII_INDEX_KEY - The index entry key used in the $SII index.
1958 *
1959 * The collation type is COLLATION_NTOFS_ULONG.
1960 */
1961typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07001962 le32 security_id; /* The security_id assigned to the descriptor. */
Steve Kondik2111ad72013-07-07 12:07:44 -07001963} __attribute__((__packed__)) SII_INDEX_KEY;
1964
1965/**
1966 * struct SDH_INDEX_KEY - The index entry key used in the $SDH index.
1967 *
1968 * The keys are sorted first by hash and then by security_id.
1969 * The collation rule is COLLATION_NTOFS_SECURITY_HASH.
1970 */
1971typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07001972 le32 hash; /* Hash of the security descriptor. */
1973 le32 security_id; /* The security_id assigned to the descriptor. */
Steve Kondik2111ad72013-07-07 12:07:44 -07001974} __attribute__((__packed__)) SDH_INDEX_KEY;
1975
1976/**
1977 * struct VOLUME_NAME - Attribute: Volume name (0x60).
1978 *
1979 * NOTE: Always resident.
1980 * NOTE: Present only in FILE_Volume.
1981 */
1982typedef struct {
1983 ntfschar name[0]; /* The name of the volume in Unicode. */
1984} __attribute__((__packed__)) VOLUME_NAME;
1985
1986/**
1987 * enum VOLUME_FLAGS - Possible flags for the volume (16-bit).
1988 */
1989typedef enum {
1990 VOLUME_IS_DIRTY = const_cpu_to_le16(0x0001),
1991 VOLUME_RESIZE_LOG_FILE = const_cpu_to_le16(0x0002),
1992 VOLUME_UPGRADE_ON_MOUNT = const_cpu_to_le16(0x0004),
1993 VOLUME_MOUNTED_ON_NT4 = const_cpu_to_le16(0x0008),
1994 VOLUME_DELETE_USN_UNDERWAY = const_cpu_to_le16(0x0010),
1995 VOLUME_REPAIR_OBJECT_ID = const_cpu_to_le16(0x0020),
1996 VOLUME_CHKDSK_UNDERWAY = const_cpu_to_le16(0x4000),
1997 VOLUME_MODIFIED_BY_CHKDSK = const_cpu_to_le16(0x8000),
1998 VOLUME_FLAGS_MASK = const_cpu_to_le16(0xc03f),
1999} __attribute__((__packed__)) VOLUME_FLAGS;
2000
2001/**
2002 * struct VOLUME_INFORMATION - Attribute: Volume information (0x70).
2003 *
2004 * NOTE: Always resident.
2005 * NOTE: Present only in FILE_Volume.
2006 * NOTE: Windows 2000 uses NTFS 3.0 while Windows NT4 service pack 6a uses
2007 * NTFS 1.2. I haven't personally seen other values yet.
2008 */
2009typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002010 le64 reserved; /* Not used (yet?). */
Steve Kondik2111ad72013-07-07 12:07:44 -07002011 u8 major_ver; /* Major version of the ntfs format. */
2012 u8 minor_ver; /* Minor version of the ntfs format. */
2013 VOLUME_FLAGS flags; /* Bit array of VOLUME_* flags. */
2014} __attribute__((__packed__)) VOLUME_INFORMATION;
2015
2016/**
2017 * struct DATA_ATTR - Attribute: Data attribute (0x80).
2018 *
2019 * NOTE: Can be resident or non-resident.
2020 *
2021 * Data contents of a file (i.e. the unnamed stream) or of a named stream.
2022 */
2023typedef struct {
2024 u8 data[0]; /* The file's data contents. */
2025} __attribute__((__packed__)) DATA_ATTR;
2026
2027/**
2028 * enum INDEX_HEADER_FLAGS - Index header flags (8-bit).
2029 */
2030typedef enum {
2031 /* When index header is in an index root attribute: */
2032 SMALL_INDEX = 0, /* The index is small enough to fit inside the
2033 index root attribute and there is no index
2034 allocation attribute present. */
2035 LARGE_INDEX = 1, /* The index is too large to fit in the index
2036 root attribute and/or an index allocation
2037 attribute is present. */
2038 /*
2039 * When index header is in an index block, i.e. is part of index
2040 * allocation attribute:
2041 */
2042 LEAF_NODE = 0, /* This is a leaf node, i.e. there are no more
2043 nodes branching off it. */
2044 INDEX_NODE = 1, /* This node indexes other nodes, i.e. is not a
2045 leaf node. */
2046 NODE_MASK = 1, /* Mask for accessing the *_NODE bits. */
2047} __attribute__((__packed__)) INDEX_HEADER_FLAGS;
2048
2049/**
2050 * struct INDEX_HEADER -
2051 *
2052 * This is the header for indexes, describing the INDEX_ENTRY records, which
2053 * follow the INDEX_HEADER. Together the index header and the index entries
2054 * make up a complete index.
2055 *
2056 * IMPORTANT NOTE: The offset, length and size structure members are counted
2057 * relative to the start of the index header structure and not relative to the
2058 * start of the index root or index allocation structures themselves.
2059 */
2060typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002061/* 0*/ le32 entries_offset; /* Byte offset from the INDEX_HEADER to first
Steve Kondik2111ad72013-07-07 12:07:44 -07002062 INDEX_ENTRY, aligned to 8-byte boundary. */
Steve Kondike68cb602016-08-28 00:45:36 -07002063/* 4*/ le32 index_length; /* Data size in byte of the INDEX_ENTRY's,
Steve Kondik2111ad72013-07-07 12:07:44 -07002064 including the INDEX_HEADER, aligned to 8. */
Steve Kondike68cb602016-08-28 00:45:36 -07002065/* 8*/ le32 allocated_size; /* Allocated byte size of this index (block),
Steve Kondik2111ad72013-07-07 12:07:44 -07002066 multiple of 8 bytes. See more below. */
2067 /*
2068 For the index root attribute, the above two numbers are always
2069 equal, as the attribute is resident and it is resized as needed.
2070
2071 For the index allocation attribute, the attribute is not resident
2072 and the allocated_size is equal to the index_block_size specified
2073 by the corresponding INDEX_ROOT attribute minus the INDEX_BLOCK
2074 size not counting the INDEX_HEADER part (i.e. minus -24).
2075 */
2076/* 12*/ INDEX_HEADER_FLAGS ih_flags; /* Bit field of INDEX_HEADER_FLAGS. */
2077/* 13*/ u8 reserved[3]; /* Reserved/align to 8-byte boundary.*/
2078/* sizeof() == 16 */
2079} __attribute__((__packed__)) INDEX_HEADER;
2080
2081/**
2082 * struct INDEX_ROOT - Attribute: Index root (0x90).
2083 *
2084 * NOTE: Always resident.
2085 *
2086 * This is followed by a sequence of index entries (INDEX_ENTRY structures)
2087 * as described by the index header.
2088 *
2089 * When a directory is small enough to fit inside the index root then this
2090 * is the only attribute describing the directory. When the directory is too
2091 * large to fit in the index root, on the other hand, two additional attributes
2092 * are present: an index allocation attribute, containing sub-nodes of the B+
2093 * directory tree (see below), and a bitmap attribute, describing which virtual
2094 * cluster numbers (vcns) in the index allocation attribute are in use by an
2095 * index block.
2096 *
2097 * NOTE: The root directory (FILE_root) contains an entry for itself. Other
2098 * directories do not contain entries for themselves, though.
2099 */
2100typedef struct {
2101/* 0*/ ATTR_TYPES type; /* Type of the indexed attribute. Is
2102 $FILE_NAME for directories, zero
2103 for view indexes. No other values
2104 allowed. */
2105/* 4*/ COLLATION_RULES collation_rule; /* Collation rule used to sort the
2106 index entries. If type is $FILE_NAME,
2107 this must be COLLATION_FILE_NAME. */
Steve Kondike68cb602016-08-28 00:45:36 -07002108/* 8*/ le32 index_block_size; /* Size of index block in bytes (in
Steve Kondik2111ad72013-07-07 12:07:44 -07002109 the index allocation attribute). */
2110/* 12*/ s8 clusters_per_index_block; /* Size of index block in clusters (in
2111 the index allocation attribute), when
2112 an index block is >= than a cluster,
2113 otherwise sectors per index block. */
2114/* 13*/ u8 reserved[3]; /* Reserved/align to 8-byte boundary. */
2115/* 16*/ INDEX_HEADER index; /* Index header describing the
2116 following index entries. */
2117/* sizeof()= 32 bytes */
2118} __attribute__((__packed__)) INDEX_ROOT;
2119
2120/**
2121 * struct INDEX_BLOCK - Attribute: Index allocation (0xa0).
2122 *
2123 * NOTE: Always non-resident (doesn't make sense to be resident anyway!).
2124 *
2125 * This is an array of index blocks. Each index block starts with an
2126 * INDEX_BLOCK structure containing an index header, followed by a sequence of
2127 * index entries (INDEX_ENTRY structures), as described by the INDEX_HEADER.
2128 */
2129typedef struct {
2130/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */
2131 NTFS_RECORD_TYPES magic;/* Magic is "INDX". */
Steve Kondike68cb602016-08-28 00:45:36 -07002132 le16 usa_ofs; /* See NTFS_RECORD definition. */
2133 le16 usa_count; /* See NTFS_RECORD definition. */
Steve Kondik2111ad72013-07-07 12:07:44 -07002134
Steve Kondike68cb602016-08-28 00:45:36 -07002135/* 8*/ leLSN lsn; /* $LogFile sequence number of the last
Steve Kondik2111ad72013-07-07 12:07:44 -07002136 modification of this index block. */
Steve Kondike68cb602016-08-28 00:45:36 -07002137/* 16*/ leVCN index_block_vcn; /* Virtual cluster number of the index block. */
Steve Kondik2111ad72013-07-07 12:07:44 -07002138/* 24*/ INDEX_HEADER index; /* Describes the following index entries. */
2139/* sizeof()= 40 (0x28) bytes */
2140/*
2141 * When creating the index block, we place the update sequence array at this
2142 * offset, i.e. before we start with the index entries. This also makes sense,
2143 * otherwise we could run into problems with the update sequence array
2144 * containing in itself the last two bytes of a sector which would mean that
2145 * multi sector transfer protection wouldn't work. As you can't protect data
2146 * by overwriting it since you then can't get it back...
2147 * When reading use the data from the ntfs record header.
2148 */
2149} __attribute__((__packed__)) INDEX_BLOCK;
2150
2151typedef INDEX_BLOCK INDEX_ALLOCATION;
2152
2153/**
2154 * struct REPARSE_INDEX_KEY -
2155 *
2156 * The system file FILE_Extend/$Reparse contains an index named $R listing
2157 * all reparse points on the volume. The index entry keys are as defined
2158 * below. Note, that there is no index data associated with the index entries.
2159 *
2160 * The index entries are sorted by the index key file_id. The collation rule is
2161 * COLLATION_NTOFS_ULONGS. FIXME: Verify whether the reparse_tag is not the
2162 * primary key / is not a key at all. (AIA)
2163 */
2164typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002165 le32 reparse_tag; /* Reparse point type (inc. flags). */
2166 leMFT_REF file_id; /* Mft record of the file containing the
Steve Kondik2111ad72013-07-07 12:07:44 -07002167 reparse point attribute. */
2168} __attribute__((__packed__)) REPARSE_INDEX_KEY;
2169
2170/**
2171 * enum QUOTA_FLAGS - Quota flags (32-bit).
2172 */
2173typedef enum {
2174 /* The user quota flags. Names explain meaning. */
2175 QUOTA_FLAG_DEFAULT_LIMITS = const_cpu_to_le32(0x00000001),
2176 QUOTA_FLAG_LIMIT_REACHED = const_cpu_to_le32(0x00000002),
2177 QUOTA_FLAG_ID_DELETED = const_cpu_to_le32(0x00000004),
2178
2179 QUOTA_FLAG_USER_MASK = const_cpu_to_le32(0x00000007),
2180 /* Bit mask for user quota flags. */
2181
2182 /* These flags are only present in the quota defaults index entry,
2183 i.e. in the entry where owner_id = QUOTA_DEFAULTS_ID. */
2184 QUOTA_FLAG_TRACKING_ENABLED = const_cpu_to_le32(0x00000010),
2185 QUOTA_FLAG_ENFORCEMENT_ENABLED = const_cpu_to_le32(0x00000020),
2186 QUOTA_FLAG_TRACKING_REQUESTED = const_cpu_to_le32(0x00000040),
2187 QUOTA_FLAG_LOG_THRESHOLD = const_cpu_to_le32(0x00000080),
2188 QUOTA_FLAG_LOG_LIMIT = const_cpu_to_le32(0x00000100),
2189 QUOTA_FLAG_OUT_OF_DATE = const_cpu_to_le32(0x00000200),
2190 QUOTA_FLAG_CORRUPT = const_cpu_to_le32(0x00000400),
2191 QUOTA_FLAG_PENDING_DELETES = const_cpu_to_le32(0x00000800),
2192} QUOTA_FLAGS;
2193
2194/**
2195 * struct QUOTA_CONTROL_ENTRY -
2196 *
2197 * The system file FILE_Extend/$Quota contains two indexes $O and $Q. Quotas
2198 * are on a per volume and per user basis.
2199 *
2200 * The $Q index contains one entry for each existing user_id on the volume. The
2201 * index key is the user_id of the user/group owning this quota control entry,
2202 * i.e. the key is the owner_id. The user_id of the owner of a file, i.e. the
2203 * owner_id, is found in the standard information attribute. The collation rule
2204 * for $Q is COLLATION_NTOFS_ULONG.
2205 *
2206 * The $O index contains one entry for each user/group who has been assigned
2207 * a quota on that volume. The index key holds the SID of the user_id the
2208 * entry belongs to, i.e. the owner_id. The collation rule for $O is
2209 * COLLATION_NTOFS_SID.
2210 *
2211 * The $O index entry data is the user_id of the user corresponding to the SID.
2212 * This user_id is used as an index into $Q to find the quota control entry
2213 * associated with the SID.
2214 *
2215 * The $Q index entry data is the quota control entry and is defined below.
2216 */
2217typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002218 le32 version; /* Currently equals 2. */
Steve Kondik2111ad72013-07-07 12:07:44 -07002219 QUOTA_FLAGS flags; /* Flags describing this quota entry. */
Steve Kondike68cb602016-08-28 00:45:36 -07002220 le64 bytes_used; /* How many bytes of the quota are in use. */
2221 sle64 change_time; /* Last time this quota entry was changed. */
2222 sle64 threshold; /* Soft quota (-1 if not limited). */
2223 sle64 limit; /* Hard quota (-1 if not limited). */
2224 sle64 exceeded_time; /* How long the soft quota has been exceeded. */
Steve Kondik2111ad72013-07-07 12:07:44 -07002225/* The below field is NOT present for the quota defaults entry. */
2226 SID sid; /* The SID of the user/object associated with
2227 this quota entry. If this field is missing
2228 then the INDEX_ENTRY is padded to a multiple
2229 of 8 with zeros which are not counted in
2230 the data_length field. If the sid is present
2231 then this structure is padded with zeros to
2232 a multiple of 8 and the padding is counted in
2233 the INDEX_ENTRY's data_length. */
2234} __attribute__((__packed__)) QUOTA_CONTROL_ENTRY;
2235
2236/**
2237 * struct QUOTA_O_INDEX_DATA -
2238 */
2239typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002240 le32 owner_id;
2241 le32 unknown; /* Always 32. Seems to be padding and it's not
Steve Kondik2111ad72013-07-07 12:07:44 -07002242 counted in the INDEX_ENTRY's data_length.
2243 This field shouldn't be really here. */
2244} __attribute__((__packed__)) QUOTA_O_INDEX_DATA;
2245
2246/**
2247 * enum PREDEFINED_OWNER_IDS - Predefined owner_id values (32-bit).
2248 */
2249typedef enum {
2250 QUOTA_INVALID_ID = const_cpu_to_le32(0x00000000),
2251 QUOTA_DEFAULTS_ID = const_cpu_to_le32(0x00000001),
2252 QUOTA_FIRST_USER_ID = const_cpu_to_le32(0x00000100),
2253} PREDEFINED_OWNER_IDS;
2254
2255/**
2256 * enum INDEX_ENTRY_FLAGS - Index entry flags (16-bit).
2257 */
2258typedef enum {
2259 INDEX_ENTRY_NODE = const_cpu_to_le16(1), /* This entry contains a
2260 sub-node, i.e. a reference to an index
2261 block in form of a virtual cluster
2262 number (see below). */
2263 INDEX_ENTRY_END = const_cpu_to_le16(2), /* This signifies the last
2264 entry in an index block. The index
2265 entry does not represent a file but it
2266 can point to a sub-node. */
2267 INDEX_ENTRY_SPACE_FILLER = 0xffff, /* Just to force 16-bit width. */
2268} __attribute__((__packed__)) INDEX_ENTRY_FLAGS;
2269
2270/**
2271 * struct INDEX_ENTRY_HEADER - This the index entry header (see below).
2272 *
2273 * ==========================================================
2274 * !!!!! SEE DESCRIPTION OF THE FIELDS AT INDEX_ENTRY !!!!!
2275 * ==========================================================
2276 */
2277typedef struct {
2278/* 0*/ union {
Steve Kondike68cb602016-08-28 00:45:36 -07002279 leMFT_REF indexed_file;
Steve Kondik2111ad72013-07-07 12:07:44 -07002280 struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002281 le16 data_offset;
2282 le16 data_length;
2283 le32 reservedV;
Steve Kondik2111ad72013-07-07 12:07:44 -07002284 } __attribute__((__packed__));
2285 } __attribute__((__packed__));
Steve Kondike68cb602016-08-28 00:45:36 -07002286/* 8*/ le16 length;
2287/* 10*/ le16 key_length;
Steve Kondik2111ad72013-07-07 12:07:44 -07002288/* 12*/ INDEX_ENTRY_FLAGS flags;
Steve Kondike68cb602016-08-28 00:45:36 -07002289/* 14*/ le16 reserved;
Steve Kondik2111ad72013-07-07 12:07:44 -07002290/* sizeof() = 16 bytes */
2291} __attribute__((__packed__)) INDEX_ENTRY_HEADER;
2292
2293/**
2294 * struct INDEX_ENTRY - This is an index entry.
2295 *
2296 * A sequence of such entries follows each INDEX_HEADER structure. Together
2297 * they make up a complete index. The index follows either an index root
2298 * attribute or an index allocation attribute.
2299 *
2300 * NOTE: Before NTFS 3.0 only filename attributes were indexed.
2301 */
2302typedef struct {
2303/* 0 INDEX_ENTRY_HEADER; -- Unfolded here as gcc dislikes unnamed structs. */
2304 union { /* Only valid when INDEX_ENTRY_END is not set. */
Steve Kondike68cb602016-08-28 00:45:36 -07002305 leMFT_REF indexed_file; /* The mft reference of the file
Steve Kondik2111ad72013-07-07 12:07:44 -07002306 described by this index
2307 entry. Used for directory
2308 indexes. */
2309 struct { /* Used for views/indexes to find the entry's data. */
Steve Kondike68cb602016-08-28 00:45:36 -07002310 le16 data_offset; /* Data byte offset from this
Steve Kondik2111ad72013-07-07 12:07:44 -07002311 INDEX_ENTRY. Follows the
2312 index key. */
Steve Kondike68cb602016-08-28 00:45:36 -07002313 le16 data_length; /* Data length in bytes. */
2314 le32 reservedV; /* Reserved (zero). */
Steve Kondik2111ad72013-07-07 12:07:44 -07002315 } __attribute__((__packed__));
2316 } __attribute__((__packed__));
Steve Kondike68cb602016-08-28 00:45:36 -07002317/* 8*/ le16 length; /* Byte size of this index entry, multiple of
Steve Kondik2111ad72013-07-07 12:07:44 -07002318 8-bytes. Size includes INDEX_ENTRY_HEADER
2319 and the optional subnode VCN. See below. */
Steve Kondike68cb602016-08-28 00:45:36 -07002320/* 10*/ le16 key_length; /* Byte size of the key value, which is in the
Steve Kondik2111ad72013-07-07 12:07:44 -07002321 index entry. It follows field reserved. Not
2322 multiple of 8-bytes. */
2323/* 12*/ INDEX_ENTRY_FLAGS ie_flags; /* Bit field of INDEX_ENTRY_* flags. */
Steve Kondike68cb602016-08-28 00:45:36 -07002324/* 14*/ le16 reserved; /* Reserved/align to 8-byte boundary. */
Steve Kondik2111ad72013-07-07 12:07:44 -07002325/* End of INDEX_ENTRY_HEADER */
2326/* 16*/ union { /* The key of the indexed attribute. NOTE: Only present
2327 if INDEX_ENTRY_END bit in flags is not set. NOTE: On
2328 NTFS versions before 3.0 the only valid key is the
2329 FILE_NAME_ATTR. On NTFS 3.0+ the following
2330 additional index keys are defined: */
2331 FILE_NAME_ATTR file_name;/* $I30 index in directories. */
2332 SII_INDEX_KEY sii; /* $SII index in $Secure. */
2333 SDH_INDEX_KEY sdh; /* $SDH index in $Secure. */
2334 GUID object_id; /* $O index in FILE_Extend/$ObjId: The
2335 object_id of the mft record found in
2336 the data part of the index. */
2337 REPARSE_INDEX_KEY reparse; /* $R index in
2338 FILE_Extend/$Reparse. */
2339 SID sid; /* $O index in FILE_Extend/$Quota:
2340 SID of the owner of the user_id. */
Steve Kondike68cb602016-08-28 00:45:36 -07002341 le32 owner_id; /* $Q index in FILE_Extend/$Quota:
Steve Kondik2111ad72013-07-07 12:07:44 -07002342 user_id of the owner of the quota
2343 control entry in the data part of
2344 the index. */
2345 } __attribute__((__packed__)) key;
2346 /* The (optional) index data is inserted here when creating.
Steve Kondike68cb602016-08-28 00:45:36 -07002347 leVCN vcn; If INDEX_ENTRY_NODE bit in ie_flags is set, the last
Steve Kondik2111ad72013-07-07 12:07:44 -07002348 eight bytes of this index entry contain the virtual
2349 cluster number of the index block that holds the
2350 entries immediately preceding the current entry.
2351
2352 If the key_length is zero, then the vcn immediately
2353 follows the INDEX_ENTRY_HEADER.
2354
2355 The address of the vcn of "ie" INDEX_ENTRY is given by
2356 (char*)ie + le16_to_cpu(ie->length) - sizeof(VCN)
2357 */
2358} __attribute__((__packed__)) INDEX_ENTRY;
2359
2360/**
2361 * struct BITMAP_ATTR - Attribute: Bitmap (0xb0).
2362 *
2363 * Contains an array of bits (aka a bitfield).
2364 *
2365 * When used in conjunction with the index allocation attribute, each bit
2366 * corresponds to one index block within the index allocation attribute. Thus
2367 * the number of bits in the bitmap * index block size / cluster size is the
2368 * number of clusters in the index allocation attribute.
2369 */
2370typedef struct {
2371 u8 bitmap[0]; /* Array of bits. */
2372} __attribute__((__packed__)) BITMAP_ATTR;
2373
2374/**
2375 * enum PREDEFINED_REPARSE_TAGS -
2376 *
2377 * The reparse point tag defines the type of the reparse point. It also
2378 * includes several flags, which further describe the reparse point.
2379 *
2380 * The reparse point tag is an unsigned 32-bit value divided in three parts:
2381 *
2382 * 1. The least significant 16 bits (i.e. bits 0 to 15) specify the type of
2383 * the reparse point.
2384 * 2. The 13 bits after this (i.e. bits 16 to 28) are reserved for future use.
2385 * 3. The most significant three bits are flags describing the reparse point.
2386 * They are defined as follows:
2387 * bit 29: Name surrogate bit. If set, the filename is an alias for
2388 * another object in the system.
2389 * bit 30: High-latency bit. If set, accessing the first byte of data will
2390 * be slow. (E.g. the data is stored on a tape drive.)
2391 * bit 31: Microsoft bit. If set, the tag is owned by Microsoft. User
2392 * defined tags have to use zero here.
2393 */
2394typedef enum {
2395 IO_REPARSE_TAG_IS_ALIAS = const_cpu_to_le32(0x20000000),
2396 IO_REPARSE_TAG_IS_HIGH_LATENCY = const_cpu_to_le32(0x40000000),
2397 IO_REPARSE_TAG_IS_MICROSOFT = const_cpu_to_le32(0x80000000),
2398
2399 IO_REPARSE_TAG_RESERVED_ZERO = const_cpu_to_le32(0x00000000),
2400 IO_REPARSE_TAG_RESERVED_ONE = const_cpu_to_le32(0x00000001),
2401 IO_REPARSE_TAG_RESERVED_RANGE = const_cpu_to_le32(0x00000001),
2402
2403 IO_REPARSE_TAG_CSV = const_cpu_to_le32(0x80000009),
2404 IO_REPARSE_TAG_DEDUP = const_cpu_to_le32(0x80000013),
2405 IO_REPARSE_TAG_DFS = const_cpu_to_le32(0x8000000A),
2406 IO_REPARSE_TAG_DFSR = const_cpu_to_le32(0x80000012),
2407 IO_REPARSE_TAG_HSM = const_cpu_to_le32(0xC0000004),
2408 IO_REPARSE_TAG_HSM2 = const_cpu_to_le32(0x80000006),
2409 IO_REPARSE_TAG_MOUNT_POINT = const_cpu_to_le32(0xA0000003),
2410 IO_REPARSE_TAG_NFS = const_cpu_to_le32(0x80000014),
2411 IO_REPARSE_TAG_SIS = const_cpu_to_le32(0x80000007),
2412 IO_REPARSE_TAG_SYMLINK = const_cpu_to_le32(0xA000000C),
2413 IO_REPARSE_TAG_WIM = const_cpu_to_le32(0x80000008),
Steve Kondike68cb602016-08-28 00:45:36 -07002414 IO_REPARSE_TAG_WOF = const_cpu_to_le32(0x80000017),
Steve Kondik2111ad72013-07-07 12:07:44 -07002415
2416 IO_REPARSE_TAG_VALID_VALUES = const_cpu_to_le32(0xf000ffff),
2417} PREDEFINED_REPARSE_TAGS;
2418
2419/**
2420 * struct REPARSE_POINT - Attribute: Reparse point (0xc0).
2421 *
2422 * NOTE: Can be resident or non-resident.
2423 */
2424typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002425 le32 reparse_tag; /* Reparse point type (inc. flags). */
2426 le16 reparse_data_length; /* Byte size of reparse data. */
2427 le16 reserved; /* Align to 8-byte boundary. */
Steve Kondik2111ad72013-07-07 12:07:44 -07002428 u8 reparse_data[0]; /* Meaning depends on reparse_tag. */
2429} __attribute__((__packed__)) REPARSE_POINT;
2430
2431/**
2432 * struct EA_INFORMATION - Attribute: Extended attribute information (0xd0).
2433 *
2434 * NOTE: Always resident.
2435 */
2436typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002437 le16 ea_length; /* Byte size of the packed extended
Steve Kondik2111ad72013-07-07 12:07:44 -07002438 attributes. */
Steve Kondike68cb602016-08-28 00:45:36 -07002439 le16 need_ea_count; /* The number of extended attributes which have
Steve Kondik2111ad72013-07-07 12:07:44 -07002440 the NEED_EA bit set. */
Steve Kondike68cb602016-08-28 00:45:36 -07002441 le32 ea_query_length; /* Byte size of the buffer required to query
Steve Kondik2111ad72013-07-07 12:07:44 -07002442 the extended attributes when calling
2443 ZwQueryEaFile() in Windows NT/2k. I.e. the
2444 byte size of the unpacked extended
2445 attributes. */
2446} __attribute__((__packed__)) EA_INFORMATION;
2447
2448/**
2449 * enum EA_FLAGS - Extended attribute flags (8-bit).
2450 */
2451typedef enum {
2452 NEED_EA = 0x80, /* Indicate that the file to which the EA
2453 belongs cannot be interpreted without
2454 understanding the associated extended
2455 attributes. */
2456} __attribute__((__packed__)) EA_FLAGS;
2457
2458/**
2459 * struct EA_ATTR - Attribute: Extended attribute (EA) (0xe0).
2460 *
2461 * Like the attribute list and the index buffer list, the EA attribute value is
2462 * a sequence of EA_ATTR variable length records.
2463 *
2464 * FIXME: It appears weird that the EA name is not Unicode. Is it true?
2465 * FIXME: It seems that name is always uppercased. Is it true?
2466 */
2467typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002468 le32 next_entry_offset; /* Offset to the next EA_ATTR. */
Steve Kondik2111ad72013-07-07 12:07:44 -07002469 EA_FLAGS flags; /* Flags describing the EA. */
2470 u8 name_length; /* Length of the name of the extended
2471 attribute in bytes. */
Steve Kondike68cb602016-08-28 00:45:36 -07002472 le16 value_length; /* Byte size of the EA's value. */
Steve Kondik2111ad72013-07-07 12:07:44 -07002473 u8 name[0]; /* Name of the EA. */
2474 u8 value[0]; /* The value of the EA. Immediately
2475 follows the name. */
2476} __attribute__((__packed__)) EA_ATTR;
2477
2478/**
2479 * struct PROPERTY_SET - Attribute: Property set (0xf0).
2480 *
2481 * Intended to support Native Structure Storage (NSS) - a feature removed from
2482 * NTFS 3.0 during beta testing.
2483 */
2484typedef struct {
2485 /* Irrelevant as feature unused. */
2486} __attribute__((__packed__)) PROPERTY_SET;
2487
2488/**
2489 * struct LOGGED_UTILITY_STREAM - Attribute: Logged utility stream (0x100).
2490 *
2491 * NOTE: Can be resident or non-resident.
2492 *
2493 * Operations on this attribute are logged to the journal ($LogFile) like
2494 * normal metadata changes.
2495 *
2496 * Used by the Encrypting File System (EFS). All encrypted files have this
2497 * attribute with the name $EFS. See below for the relevant structures.
2498 */
2499typedef struct {
2500 /* Can be anything the creator chooses. */
2501} __attribute__((__packed__)) LOGGED_UTILITY_STREAM;
2502
2503/*
2504 * $EFS Data Structure:
2505 *
2506 * The following information is about the data structures that are contained
2507 * inside a logged utility stream (0x100) with a name of "$EFS".
2508 *
2509 * The stream starts with an instance of EFS_ATTR_HEADER.
2510 *
2511 * Next, at offsets offset_to_ddf_array and offset_to_drf_array (unless any of
2512 * them is 0) there is a EFS_DF_ARRAY_HEADER immediately followed by a sequence
2513 * of multiple data decryption/recovery fields.
2514 *
2515 * Each data decryption/recovery field starts with a EFS_DF_HEADER and the next
2516 * one (if it exists) can be found by adding EFS_DF_HEADER->df_length bytes to
2517 * the offset of the beginning of the current EFS_DF_HEADER.
2518 *
2519 * The data decryption/recovery field contains an EFS_DF_CERTIFICATE_HEADER, a
2520 * SID, an optional GUID, an optional container name, a non-optional user name,
2521 * and the encrypted FEK.
2522 *
2523 * Note all the below are best guesses so may have mistakes/inaccuracies.
2524 * Corrections/clarifications/additions are always welcome!
2525 *
2526 * Ntfs.sys takes an EFS value length of <= 0x54 or > 0x40000 to BSOD, i.e. it
2527 * is invalid.
2528 */
2529
2530/**
2531 * struct EFS_ATTR_HEADER - "$EFS" header.
2532 *
2533 * The header of the Logged utility stream (0x100) attribute named "$EFS".
2534 */
2535typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002536/* 0*/ le32 length; /* Length of EFS attribute in bytes. */
2537 le32 state; /* Always 0? */
2538 le32 version; /* Efs version. Always 2? */
2539 le32 crypto_api_version; /* Always 0? */
Steve Kondik2111ad72013-07-07 12:07:44 -07002540/* 16*/ u8 unknown4[16]; /* MD5 hash of decrypted FEK? This field is
2541 created with a call to UuidCreate() so is
2542 unlikely to be an MD5 hash and is more
2543 likely to be GUID of this encrytped file
2544 or something like that. */
2545/* 32*/ u8 unknown5[16]; /* MD5 hash of DDFs? */
2546/* 48*/ u8 unknown6[16]; /* MD5 hash of DRFs? */
Steve Kondike68cb602016-08-28 00:45:36 -07002547/* 64*/ le32 offset_to_ddf_array;/* Offset in bytes to the array of data
Steve Kondik2111ad72013-07-07 12:07:44 -07002548 decryption fields (DDF), see below. Zero if
2549 no DDFs are present. */
Steve Kondike68cb602016-08-28 00:45:36 -07002550 le32 offset_to_drf_array;/* Offset in bytes to the array of data
Steve Kondik2111ad72013-07-07 12:07:44 -07002551 recovery fields (DRF), see below. Zero if
2552 no DRFs are present. */
Steve Kondike68cb602016-08-28 00:45:36 -07002553 le32 reserved; /* Reserved. */
Steve Kondik2111ad72013-07-07 12:07:44 -07002554} __attribute__((__packed__)) EFS_ATTR_HEADER;
2555
2556/**
2557 * struct EFS_DF_ARRAY_HEADER -
2558 */
2559typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002560 le32 df_count; /* Number of data decryption/recovery fields in
Steve Kondik2111ad72013-07-07 12:07:44 -07002561 the array. */
2562} __attribute__((__packed__)) EFS_DF_ARRAY_HEADER;
2563
2564/**
2565 * struct EFS_DF_HEADER -
2566 */
2567typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002568/* 0*/ le32 df_length; /* Length of this data decryption/recovery
Steve Kondik2111ad72013-07-07 12:07:44 -07002569 field in bytes. */
Steve Kondike68cb602016-08-28 00:45:36 -07002570 le32 cred_header_offset; /* Offset in bytes to the credential header. */
2571 le32 fek_size; /* Size in bytes of the encrypted file
Steve Kondik2111ad72013-07-07 12:07:44 -07002572 encryption key (FEK). */
Steve Kondike68cb602016-08-28 00:45:36 -07002573 le32 fek_offset; /* Offset in bytes to the FEK from the start of
Steve Kondik2111ad72013-07-07 12:07:44 -07002574 the data decryption/recovery field. */
Steve Kondike68cb602016-08-28 00:45:36 -07002575/* 16*/ le32 unknown1; /* always 0? Might be just padding. */
Steve Kondik2111ad72013-07-07 12:07:44 -07002576} __attribute__((__packed__)) EFS_DF_HEADER;
2577
2578/**
2579 * struct EFS_DF_CREDENTIAL_HEADER -
2580 */
2581typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002582/* 0*/ le32 cred_length; /* Length of this credential in bytes. */
2583 le32 sid_offset; /* Offset in bytes to the user's sid from start
Steve Kondik2111ad72013-07-07 12:07:44 -07002584 of this structure. Zero if no sid is
2585 present. */
Steve Kondike68cb602016-08-28 00:45:36 -07002586/* 8*/ le32 type; /* Type of this credential:
Steve Kondik2111ad72013-07-07 12:07:44 -07002587 1 = CryptoAPI container.
2588 2 = Unexpected type.
2589 3 = Certificate thumbprint.
2590 other = Unknown type. */
2591 union {
2592 /* CryptoAPI container. */
2593 struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002594/* 12*/ le32 container_name_offset; /* Offset in bytes to
Steve Kondik2111ad72013-07-07 12:07:44 -07002595 the name of the container from start of this
2596 structure (may not be zero). */
Steve Kondike68cb602016-08-28 00:45:36 -07002597/* 16*/ le32 provider_name_offset; /* Offset in bytes to
Steve Kondik2111ad72013-07-07 12:07:44 -07002598 the name of the provider from start of this
2599 structure (may not be zero). */
Steve Kondike68cb602016-08-28 00:45:36 -07002600 le32 public_key_blob_offset; /* Offset in bytes to
Steve Kondik2111ad72013-07-07 12:07:44 -07002601 the public key blob from start of this
2602 structure. */
Steve Kondike68cb602016-08-28 00:45:36 -07002603/* 24*/ le32 public_key_blob_size; /* Size in bytes of
Steve Kondik2111ad72013-07-07 12:07:44 -07002604 public key blob. */
2605 } __attribute__((__packed__));
2606 /* Certificate thumbprint. */
2607 struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002608/* 12*/ le32 cert_thumbprint_header_size; /* Size in
Steve Kondik2111ad72013-07-07 12:07:44 -07002609 bytes of the header of the certificate
2610 thumbprint. */
Steve Kondike68cb602016-08-28 00:45:36 -07002611/* 16*/ le32 cert_thumbprint_header_offset; /* Offset in
Steve Kondik2111ad72013-07-07 12:07:44 -07002612 bytes to the header of the certificate
2613 thumbprint from start of this structure. */
Steve Kondike68cb602016-08-28 00:45:36 -07002614 le32 unknown1; /* Always 0? Might be padding... */
2615 le32 unknown2; /* Always 0? Might be padding... */
Steve Kondik2111ad72013-07-07 12:07:44 -07002616 } __attribute__((__packed__));
2617 } __attribute__((__packed__));
2618} __attribute__((__packed__)) EFS_DF_CREDENTIAL_HEADER;
2619
2620typedef EFS_DF_CREDENTIAL_HEADER EFS_DF_CRED_HEADER;
2621
2622/**
2623 * struct EFS_DF_CERTIFICATE_THUMBPRINT_HEADER -
2624 */
2625typedef struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002626/* 0*/ le32 thumbprint_offset; /* Offset in bytes to the thumbprint. */
2627 le32 thumbprint_size; /* Size of thumbprint in bytes. */
2628/* 8*/ le32 container_name_offset; /* Offset in bytes to the name of the
Steve Kondik2111ad72013-07-07 12:07:44 -07002629 container from start of this
2630 structure or 0 if no name present. */
Steve Kondike68cb602016-08-28 00:45:36 -07002631 le32 provider_name_offset; /* Offset in bytes to the name of the
Steve Kondik2111ad72013-07-07 12:07:44 -07002632 cryptographic provider from start of
2633 this structure or 0 if no name
2634 present. */
Steve Kondike68cb602016-08-28 00:45:36 -07002635/* 16*/ le32 user_name_offset; /* Offset in bytes to the user name
Steve Kondik2111ad72013-07-07 12:07:44 -07002636 from start of this structure or 0 if
2637 no user name present. (This is also
2638 known as lpDisplayInformation.) */
2639} __attribute__((__packed__)) EFS_DF_CERTIFICATE_THUMBPRINT_HEADER;
2640
2641typedef EFS_DF_CERTIFICATE_THUMBPRINT_HEADER EFS_DF_CERT_THUMBPRINT_HEADER;
2642
2643typedef enum {
2644 INTX_SYMBOLIC_LINK =
2645 const_cpu_to_le64(0x014B4E4C78746E49ULL), /* "IntxLNK\1" */
2646 INTX_CHARACTER_DEVICE =
2647 const_cpu_to_le64(0x0052484378746E49ULL), /* "IntxCHR\0" */
2648 INTX_BLOCK_DEVICE =
2649 const_cpu_to_le64(0x004B4C4278746E49ULL), /* "IntxBLK\0" */
2650} INTX_FILE_TYPES;
2651
2652typedef struct {
2653 INTX_FILE_TYPES magic; /* Intx file magic. */
2654 union {
2655 /* For character and block devices. */
2656 struct {
Steve Kondike68cb602016-08-28 00:45:36 -07002657 le64 major; /* Major device number. */
2658 le64 minor; /* Minor device number. */
Steve Kondik2111ad72013-07-07 12:07:44 -07002659 void *device_end[0]; /* Marker for offsetof(). */
2660 } __attribute__((__packed__));
2661 /* For symbolic links. */
2662 ntfschar target[0];
2663 } __attribute__((__packed__));
2664} __attribute__((__packed__)) INTX_FILE;
2665
2666#endif /* defined _NTFS_LAYOUT_H */