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