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