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