VirtualBox

source: vbox/trunk/include/iprt/formats/ntfs.h@ 73886

Last change on this file since 73886 was 69925, checked in by vboxsync, 7 years ago

iprt/ntfsvfs.cpp: Made opening and traversing directories work.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 31.0 KB
Line 
1/* $Id: ntfs.h 69925 2017-12-05 00:06:59Z vboxsync $ */
2/** @file
3 * IPRT, NT File System (NTFS).
4 */
5
6/*
7 * Copyright (C) 2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___iprt_formats_ntfs_h
28#define ___iprt_formats_ntfs_h
29
30#include <iprt/formats/fat.h>
31
32
33/** @defgroup grp_rt_formats_ntfs NT File System (NTFS) structures and definitions
34 * @ingroup grp_rt_formats
35 * @{
36 */
37
38/** Value of the FATBOOTSECTOR::achOemName for an NTFS file system. */
39#define NTFS_OEM_ID_MAGIC "NTFS "
40
41
42/** @name NTFS_MFT_IDX_XXX - Predefined MFT indexes.
43 * @{ */
44#define NTFS_MFT_IDX_MFT 0 /**< The MFT itself. */
45#define NTFS_MFT_IDX_MFT_MIRROR 1 /**< Mirror MFT (partial?). */
46#define NTFS_MFT_IDX_LOG_FILE 2 /**< Journalling log. */
47#define NTFS_MFT_IDX_VOLUME 3 /**< Volume attributes. */
48#define NTFS_MFT_IDX_ATTRIB_DEF 4 /**< Attribute definitions. */
49#define NTFS_MFT_IDX_ROOT 5 /**< The root directory. */
50#define NTFS_MFT_IDX_BITMAP 6 /**< Allocation bitmap. */
51#define NTFS_MFT_IDX_BOOT 7 /**< The boot sector. */
52#define NTFS_MFT_IDX_BAD_CLUSTER 8 /**< Bad cluster table. */
53#define NTFS_MFT_IDX_SECURITY 9 /**< Shared security descriptors (w2k and later). */
54#define NTFS_MFT_IDX_UP_CASE 10 /**< Unicode upper case table. */
55#define NTFS_MFT_IDX_EXTEND 11 /**< Directory containing further system files. */
56#define NTFS_MFT_IDX_FIRST_USER 16 /**< The first user file. */
57/** @} */
58
59/**
60 * NTFS MFT record reference.
61 */
62typedef union NTFSMFTREF
63{
64 /** unsigned 64-bit view. */
65 uint64_t u64;
66 /** unsigned 32-bit view. */
67 uint32_t au32[2];
68 /** unsigned 16-bit view. */
69 uint16_t au16[4];
70
71 /** Structured view. */
72 struct
73 {
74 /** Index of the master file table record. */
75 uint64_t idxMft : 48;
76 /** MFT record reuse sequence number (for catching dangling references). */
77 uint64_t uRecReuseSeqNo : 16;
78 } s;
79} NTFSMFTREF;
80AssertCompileSize(NTFSMFTREF, 8);
81/** Pointer to a NTFS MFT record reference. */
82typedef NTFSMFTREF *PNTFSMFTREF;
83/** Pointer to a const NTFS MFT record reference. */
84typedef NTFSMFTREF const *PCNTFSMFTREF;
85
86/** @name NTFSMFTREF_GET_IDX
87 * Gets the MFT index number (host endian) from a MFT reference. */
88/** @name NTFSMFTREF_GET_SEQ
89 * Gets the MFT reuse sequence number (host endian) from a MFT reference. */
90/** @name NTFSMFTREF_SET_IDX
91 * Sets the MFT index number of a MFT reference. */
92/** @name NTFSMFTREF_SET_SEQ
93 * Sets the MFT reuse sequence number of a MFT reference. */
94/** @name NTFSMFTREF_SET
95 * Sets the values of a MFT reference. */
96#ifdef RT_LITTLE_ENDIAN
97# define NTFSMFTREF_GET_IDX(a_pMftRef) ((a_pMftRef)->s.idxMft)
98# define NTFSMFTREF_GET_SEQ(a_pMftRef) ((a_pMftRef)->s.uRecReuseSeqNo)
99# define NTFSMFTREF_SET_SEQ(a_pMftRef, a_uValue) do { (a_pMftRef)->s.uRecReuseSeqNo = (a_uValue); } while (0)
100# define NTFSMFTREF_SET_IDX(a_pMftRef, a_uValue) do { (a_pMftRef)->s.idxMft = (a_uValue); } while (0)
101# define NTFSMFTREF_SET(a_pMftRef, a_idx, a_uSeq) \
102 do { \
103 (a_pMftRef)->s.idxMft = (a_idx); \
104 (a_pMftRef)->s.uRecReuseSeqNo = (a_uSeq); \
105 } while (0)
106#else
107# define NTFSMFTREF_GET_IDX(a_pMftRef) (RT_LE2H_U64((a_pMftRef)->u64) & UINT64_C(0x0000ffffffffffff))
108# define NTFSMFTREF_GET_SEQ(a_pMftRef) RT_LE2H_U16((uint16_t)(a_pMftRef)->u64)
109# define NTFSMFTREF_SET_SEQ(a_pMftRef, a_uValue) do { (a_pMftRef)->au16[3] = RT_H2LE_U16(a_uValue); } while (0)
110# define NTFSMFTREF_SET_IDX(a_pMftRef, a_uValue) \
111 do { \
112 (a_pMftRef)->au32[0] = RT_H2LE_U32((uint32_t)(a_uValue)); \
113 (a_pMftRef)->au16[2] = RT_H2LE_U16((uint16_t)((a_uValue) >> 32)); \
114 } while (0)
115# define NTFSMFTREF_SET(a_pMftRef, a_idx, a_uSeq) \
116 do { \
117 (a_pMftRef)->au32[0] = RT_H2LE_U32((uint32_t)(a_idx)); \
118 (a_pMftRef)->au16[2] = RT_H2LE_U16((uint16_t)((a_idx) >> 32)); \
119 (a_pMftRef)->au16[3] = RT_H2LE_U16((uint16_t)(a_uSeq)); \
120 } while (0)
121#endif
122/** Check that the reference is zero. */
123#define NTFSMFTREF_IS_ZERO(a_pMftRef) ((a_pMftRef)->u64 == 0)
124
125
126/**
127 * NTFS record header.
128 */
129typedef struct NTFSRECHDR
130{
131 /** Magic number (usually ASCII). */
132 uint32_t uMagic;
133 /** Offset of the update sequence array from the start of the record. */
134 uint16_t offUpdateSeqArray;
135 /** Number of entries in the update sequence array. (uint16_t sized entries) */
136 uint16_t cUpdateSeqEntries;
137} NTFSRECHDR;
138AssertCompileSize(NTFSRECHDR, 8);
139/** Pointer to a NTFS record header. */
140typedef NTFSRECHDR *PNTFSRECHDR;
141/** Pointer to a const NTFS record header. */
142typedef NTFSRECHDR const *PCNTFSRECHDR;
143
144/** The multi-sector update sequence stride.
145 * @see https://msdn.microsoft.com/en-us/library/bb470212%28v=vs.85%29.aspx
146 * @see NTFSRECHDR::offUpdateSeqArray, NTFSRECHDR::cUpdateSeqEntries
147 */
148#define NTFS_MULTI_SECTOR_STRIDE 512
149
150
151/**
152 * NTFS file record (in the MFT).
153 */
154typedef struct NTFSRECFILE
155{
156 /** 0x00: Header with NTFSREC_MAGIC_FILE. */
157 NTFSRECHDR Hdr;
158 /** 0x08: Log file sequence number. */
159 uint64_t uLsn;
160 /** 0x10: MFT record reuse sequence number (for dangling MFT references). */
161 uint16_t uRecReuseSeqNo;
162 /** 0x12: Number of hard links. */
163 uint16_t cLinks;
164 /** 0x14: Offset of the first attribute (relative to start of record). */
165 uint16_t offFirstAttrib;
166 /** 0x16: Record flags (NTFSRECFILE_F_XXX). */
167 uint16_t fFlags;
168 /** 0x18: Number of byte in use in this MFT record. */
169 uint32_t cbRecUsed;
170 /** 0x1c: The MFT record size. */
171 uint32_t cbRecSize;
172 /** 0x20: Reference to the base MFT record. */
173 NTFSMFTREF BaseMftRec;
174 /** 0x28: Next attribute instance number. */
175 uint16_t idNextAttrib;
176 /** 0x2a: Padding if NTFS 3.1+, update sequence array if older. */
177 uint16_t uPaddingOrUsa;
178 /** 0x2c: MFT index of this record. */
179 uint32_t idxMftSelf;
180} NTFSRECFILE;
181AssertCompileSize(NTFSRECFILE, 0x30);
182/** Pointer to a NTFS file record. */
183typedef NTFSRECFILE *PNTFSRECFILE;
184/** Pointer to a const NTFS file record. */
185typedef NTFSRECFILE const *PCNTFSRECFILE;
186
187
188/** NTFS 'FILE' record magic value. */
189#define NTFSREC_MAGIC_FILE RT_H2LE_U32_C(UINT32_C(0x454c4946))
190
191/** @name NTFSRECFILE_F_XXX - NTFSRECFILE::fFlags.
192 * @{ */
193/** MFT record is in use. */
194#define NTFSRECFILE_F_IN_USE RT_H2LE_U16_C(UINT16_C(0x0001))
195/** Directory record. */
196#define NTFSRECFILE_F_DIRECTORY RT_H2LE_U16_C(UINT16_C(0x0002))
197/** @} */
198
199
200/** @name NTFS_AT_XXX - Attribute types
201 * @{ */
202#define NTFS_AT_UNUSED RT_H2LE_U32_C(UINT32_C(0x00000000))
203/** NTFSATSTDINFO */
204#define NTFS_AT_STANDARD_INFORMATION RT_H2LE_U32_C(UINT32_C(0x00000010))
205/** NTFSATLISTENTRY */
206#define NTFS_AT_ATTRIBUTE_LIST RT_H2LE_U32_C(UINT32_C(0x00000020))
207/** NTFSATFILENAME */
208#define NTFS_AT_FILENAME RT_H2LE_U32_C(UINT32_C(0x00000030))
209#define NTFS_AT_OBJECT_ID RT_H2LE_U32_C(UINT32_C(0x00000040))
210#define NTFS_AT_SECURITY_DESCRIPTOR RT_H2LE_U32_C(UINT32_C(0x00000050))
211#define NTFS_AT_VOLUME_NAME RT_H2LE_U32_C(UINT32_C(0x00000060))
212/** NTFSATVOLUMEINFO */
213#define NTFS_AT_VOLUME_INFORMATION RT_H2LE_U32_C(UINT32_C(0x00000070))
214#define NTFS_AT_DATA RT_H2LE_U32_C(UINT32_C(0x00000080))
215/** NTFSATINDEXROOT */
216#define NTFS_AT_INDEX_ROOT RT_H2LE_U32_C(UINT32_C(0x00000090))
217#define NTFS_AT_INDEX_ALLOCATION RT_H2LE_U32_C(UINT32_C(0x000000a0))
218#define NTFS_AT_BITMAP RT_H2LE_U32_C(UINT32_C(0x000000b0))
219#define NTFS_AT_REPARSE_POINT RT_H2LE_U32_C(UINT32_C(0x000000c0))
220#define NTFS_AT_EA_INFORMATION RT_H2LE_U32_C(UINT32_C(0x000000d0))
221#define NTFS_AT_EA RT_H2LE_U32_C(UINT32_C(0x000000e0))
222#define NTFS_AT_PROPERTY_SET RT_H2LE_U32_C(UINT32_C(0x000000f0))
223#define NTFS_AT_LOGGED_UTILITY_STREAM RT_H2LE_U32_C(UINT32_C(0x00000100))
224#define NTFS_AT_FIRST_USER_DEFINED RT_H2LE_U32_C(UINT32_C(0x00001000))
225#define NTFS_AT_END RT_H2LE_U32_C(UINT32_C(0xffffffff))
226/** @} */
227
228/** @name NTFS_AF_XXX - Attribute flags.
229 * @{ */
230#define NTFS_AF_COMPR_FMT_NONE RT_H2LE_U16_C(UINT16_C(0x0000))
231/** See RtlCompressBuffer / COMPRESSION_FORMAT_LZNT1. */
232#define NTFS_AF_COMPR_FMT_LZNT1 RT_H2LE_U16_C(UINT16_C(0x0001))
233/** See RtlCompressBuffer / COMPRESSION_FORMAT_XPRESS_HUFF. */
234#define NTFS_AF_COMPR_FMT_XPRESS RT_H2LE_U16_C(UINT16_C(0x0002))
235/** See RtlCompressBuffer / COMPRESSION_FORMAT_XPRESS_HUFF. */
236#define NTFS_AF_COMPR_FMT_XPRESS_HUFF RT_H2LE_U16_C(UINT16_C(0x0003))
237#define NTFS_AF_COMPR_FMT_MASK RT_H2LE_U16_C(UINT16_C(0x00ff))
238#define NTFS_AF_ENCRYPTED RT_H2LE_U16_C(UINT16_C(0x4000))
239#define NTFS_AF_SPARSE RT_H2LE_U16_C(UINT16_C(0x8000))
240/** @} */
241
242/**
243 * NTFS attribute header.
244 *
245 * This has three forms:
246 * - Resident
247 * - Non-resident, no compression
248 * - Non-resident, compressed.
249 *
250 * Each form translates to a different header size.
251 */
252typedef struct NTFSATTRIBHDR
253{
254 /** 0x00: Attribute type (NTFS_AT_XXX). */
255 uint32_t uAttrType;
256 /** 0x04: Length of this attribute (resident part). */
257 uint32_t cbAttrib;
258 /** 0x08: Set (1) if non-resident attribute, 0 if resident. */
259 uint8_t fNonResident;
260 /** 0x09: Attribute name length (can be zero). */
261 uint8_t cwcName;
262 /** 0x0a: Offset of the name string (relative to the start of this header). */
263 uint16_t offName;
264 /** 0x0c: NTFS_AF_XXX. */
265 uint16_t fFlags;
266 /** 0x0e: Attribute instance number. Unique within the MFT record. */
267 uint16_t idAttrib;
268 /** 0x10: Data depending on the fNonResident member value. */
269 union
270 {
271 /** Resident attributes. */
272 struct
273 {
274 /** 0x10: Attribute value length. */
275 uint32_t cbValue;
276 /** 0x14: Offset of the value (relative to the start of this header). */
277 uint16_t offValue;
278 /** 0x16: NTFS_RES_AF_XXX. */
279 uint8_t fFlags;
280 /** 0x17: Reserved. */
281 uint8_t bReserved;
282 } Res;
283
284 /** Non-resident attributes. */
285 struct
286 {
287 /** 0x10: The first virtual cluster containing data.
288 *
289 * This is mainly for internal checking when the run list doesn't fit in one
290 * MFT record. It can also be used to avoid recording a sparse run at the
291 * beginning of the data covered by this attribute record. */
292 int64_t iVcnFirst;
293 /** 0x18: The last virtual cluster containing data (inclusive). */
294 int64_t iVcnLast;
295 /** 0x20: Offset of the mapping pair program. This program gives us a mapping
296 * between VNC and LCN for the attribute value. */
297 uint16_t offMappingPairs;
298 /** 0x22: Power of two compression unit size in clusters (cbCluster << uCompessionUnit).
299 * Zero means uncompressed. */
300 uint8_t uCompressionUnit;
301 /** 0x23: Reserved */
302 uint8_t abReserved[5];
303 /** 0x28: Allocated size (rouneded to cluster).
304 * @note Only set in the first attribute record (iVcnFirst == 0). */
305 int64_t cbAllocated;
306 /** 0x30: The exact length of the data.
307 * @note Only set in the first attribute record (iVcnFirst == 0). */
308 int64_t cbData;
309 /** 0x38: The length of the initialized data. (Not necessarily
310 * rounded up to cluster size.)
311 * @note Only set in the first attribute record (iVcnFirst == 0). */
312 int64_t cbInitialized;
313 /** 0x40: Compressed size if compressed, otherwise absent. */
314 int64_t cbCompressed;
315 } NonRes;
316 } u;
317} NTFSATTRIBHDR;
318AssertCompileSize(NTFSATTRIBHDR, 0x48);
319AssertCompileMemberOffset(NTFSATTRIBHDR, u.Res, 0x10);
320AssertCompileMemberOffset(NTFSATTRIBHDR, u.Res.bReserved, 0x17);
321AssertCompileMemberOffset(NTFSATTRIBHDR, u.NonRes, 0x10);
322AssertCompileMemberOffset(NTFSATTRIBHDR, u.NonRes.cbCompressed, 0x40);
323/** Pointer to a NTFS attribute header. */
324typedef NTFSATTRIBHDR *PNTFSATTRIBHDR;
325/** Pointer to a const NTFS attribute header. */
326typedef NTFSATTRIBHDR const *PCNTFSATTRIBHDR;
327
328/** @name NTFSATTRIBHDR_SIZE_XXX - Attribute header sizes.
329 * @{ */
330/** Attribute header size for resident values. */
331#define NTFSATTRIBHDR_SIZE_RESIDENT (0x18)
332/** Attribute header size for uncompressed non-resident values. */
333#define NTFSATTRIBHDR_SIZE_NONRES_UNCOMPRESSED (0x40)
334/** Attribute header size for compressed non-resident values. */
335#define NTFSATTRIBHDR_SIZE_NONRES_COMPRESSED (0x48)
336/** @} */
337
338/** Get the pointer to the embedded name from an attribute.
339 * @note ASSUMES the caller check that there is a name. */
340#define NTFSATTRIBHDR_GET_NAME(a_pAttrHdr) ( (PRTUTF16)((uintptr_t)(a_pAttrHdr) + (a_pAttrHdr)->offName) )
341
342/** Get the pointer to resident value.
343 * @note ASSUMES the caller checks that it's resident and valid. */
344#define NTFSATTRIBHDR_GET_RES_VALUE_PTR(a_pAttrHdr) ( (uint8_t *)(a_pAttrHdr) + (a_pAttrHdr)->u.Res.offValue )
345
346
347/** @name NTFS_RES_AF_XXX
348 * @{ */
349/** Attribute is referenced in an index. */
350#define NTFS_RES_AF_INDEXED UINT8_C(0x01)
351/** @} */
352
353/**
354 * Attribute list entry (NTFS_AT_ATTRIBUTE_LIST).
355 *
356 * This is used to deal with a file having attributes in more than one MFT
357 * record. A prominent example is an fragment file (unnamed data attribute)
358 * which mapping pairs doesn't fit in a single MFT record.
359 *
360 * This attribute can be non-resident, however it's mapping pair program must
361 * fit in the base MFT record.
362 */
363typedef struct NTFSATLISTENTRY
364{
365 /** 0x00: Attribute type (NTFS_AT_XXX). */
366 uint32_t uAttrType;
367 /** 0x04: Length of this entry. */
368 uint16_t cbEntry;
369 /** 0x06: Attribute name length (zero if none). */
370 uint8_t cwcName;
371 /** 0x07: Name offset. */
372 uint8_t offName;
373 /** 0x08: The first VNC for this part of the attribute value. */
374 int64_t iVcnFirst;
375 /** 0x10: The MFT record holding the actual attribute. */
376 NTFSMFTREF InMftRec;
377 /** 0x18: Attribute instance number. Unique within the MFT record. */
378 uint16_t idAttrib;
379 /** 0x1a: Maybe where the attribute name starts. */
380 RTUTF16 wszName[RT_FLEXIBLE_ARRAY];
381} NTFSATLISTENTRY;
382AssertCompileMemberOffset(NTFSATLISTENTRY, idAttrib, 0x18);
383/** Pointer to a NTFS attribute list entry. */
384typedef NTFSATLISTENTRY *PNTFSATLISTENTRY;
385/** Pointer to a const NTFS attribute list entry. */
386typedef NTFSATLISTENTRY const *PCNTFSATLISTENTRY;
387
388/** Unaligned minimum entry size (no name). */
389#define NTFSATLISTENTRY_SIZE_MINIMAL 0x1a
390
391
392
393/**
394 * NTFS standard file info attribute (NTFS_AT_STANDARD_INFORMATION).
395 */
396typedef struct NTFSATSTDINFO
397{
398 /** 0x00: Creation timestamp. */
399 int64_t iCreationTime;
400 /** 0x08: Last data modification timestamp. */
401 int64_t iLastDataModTime;
402 /** 0x10: Last MFT record modification timestamp. */
403 int64_t iLastMftModTime;
404 /** 0x18: Last access timestamp. */
405 int64_t iLastAccessTime;
406 /** 0x20: File attributes. */
407 uint32_t fFileAttribs;
408 /** 0x24: Maximum number of file versions allowed.
409 * @note NTFS 3.x, padding in 1.2 */
410 uint32_t cMaxFileVersions;
411 /** 0x28: Current file version number.
412 * @note NTFS 3.x, padding in 1.2 */
413 uint32_t uFileVersion;
414 /** 0x2c: Class ID (whatever that is).
415 * @note NTFS 3.x, padding in 1.2 */
416 uint32_t idClass;
417 /** 0x30: Owner ID.
418 * Translated via $Q index in NTFS_MFT_IDX_EXTENDED/$Quota.
419 * @note NTFS 3.x, not present in 1.2 */
420 uint32_t idOwner;
421 /** 0x34: Security ID. Translated via $SII index and $SDS data stream in
422 * NTFS_MFT_IDX_SECURITY.
423 * @note NTFS 3.x, not present in 1.2 */
424 uint32_t idSecurity;
425 /** 0x38: Total quota charged for this file.
426 * @note NTFS 3.x, not present in 1.2 */
427 uint64_t cbQuotaChared;
428 /** 0x40: Last update sequence number, index into $UsnJrnl.
429 * @note NTFS 3.x, not present in 1.2 */
430 uint64_t idxUpdateSequence;
431} NTFSATSTDINFO;
432AssertCompileSize(NTFSATSTDINFO, 0x48);
433/** Pointer to NTFS standard file info. */
434typedef NTFSATSTDINFO *PNTFSATSTDINFO;
435/** Pointer to const NTFS standard file info. */
436typedef NTFSATSTDINFO const *PCNTFSATSTDINFO;
437
438/** The size of NTFSATSTDINFO in NTFS v1.2 and earlier. */
439#define NTFSATSTDINFO_SIZE_NTFS_V12 (0x30)
440
441/** @name NTFS_FA_XXX - NTFS file attributes (host endian).
442 * @{ */
443#define NTFS_FA_READONLY UINT32_C(0x00000001)
444#define NTFS_FA_HIDDEN UINT32_C(0x00000002)
445#define NTFS_FA_SYSTEM UINT32_C(0x00000004)
446#define NTFS_FA_DIRECTORY UINT32_C(0x00000010)
447#define NTFS_FA_ARCHIVE UINT32_C(0x00000020)
448#define NTFS_FA_DEVICE UINT32_C(0x00000040)
449#define NTFS_FA_NORMAL UINT32_C(0x00000080)
450#define NTFS_FA_TEMPORARY UINT32_C(0x00000100)
451#define NTFS_FA_SPARSE_FILE UINT32_C(0x00000200)
452#define NTFS_FA_REPARSE_POINT UINT32_C(0x00000400)
453#define NTFS_FA_COMPRESSED UINT32_C(0x00000800)
454#define NTFS_FA_OFFLINE UINT32_C(0x00001000)
455#define NTFS_FA_NOT_CONTENT_INDEXED UINT32_C(0x00002000)
456#define NTFS_FA_ENCRYPTED UINT32_C(0x00004000)
457#define NTFS_FA_VALID_FLAGS UINT32_C(0x00007fb7)
458#define NTFS_FA_VALID_SET_FLAGS UINT32_C(0x000031a7)
459#define NTFS_FA_DUP_FILE_NAME_INDEX_PRESENT UINT32_C(0x10000000) /**< This means directory apparently. */
460#define NTFS_FA_DUP_VIEW_INDEX_PRESENT UINT32_C(0x20000000) /**< ?? */
461/** @} */
462
463
464
465/**
466 * NTFS filename attribute (NTFS_AT_FILENAME).
467 */
468typedef struct NTFSATFILENAME
469{
470 /** 0x00: The parent directory MFT record. */
471 NTFSMFTREF ParentDirMftRec;
472 /** 0x08: Creation timestamp. */
473 int64_t iCreationTime;
474 /** 0x10: Last data modification timestamp. */
475 int64_t iLastDataModTime;
476 /** 0x18: Last MFT record modification timestamp. */
477 int64_t iLastMftModTime;
478 /** 0x20: Last access timestamp. */
479 int64_t iLastAccessTime;
480 /** 0x28: Allocated disk space for the unnamed data attribute. */
481 int64_t cbAllocated;
482 /** 0x30: Actual size of unnamed data attribute. */
483 int64_t cbData;
484 /** 0x38: File attributes (NTFS_FA_XXX). */
485 uint32_t fFileAttribs;
486 union
487 {
488 /** 0x3c: Packed EA length. */
489 uint16_t cbPackedEas;
490 /** 0x3c: Reparse tag, if no EAs. */
491 uint32_t uReparseTag;
492 } u;
493 /** 0x40: Filename length in unicode chars. */
494 uint8_t cwcFilename;
495 /** 0x41: Filename type (NTFS_FILENAME_T_XXX). */
496 uint8_t fFilenameType;
497 /** 0x42: The filename. */
498 RTUTF16 wszFilename[RT_FLEXIBLE_ARRAY];
499} NTFSATFILENAME;
500AssertCompileMemberOffset(NTFSATFILENAME, cbData, 0x30);
501AssertCompileMemberOffset(NTFSATFILENAME, u.cbPackedEas, 0x3c);
502AssertCompileMemberOffset(NTFSATFILENAME, u.uReparseTag, 0x3c);
503AssertCompileMemberOffset(NTFSATFILENAME, wszFilename, 0x42);
504/** Pointer to a NTFS filename attribute. */
505typedef NTFSATFILENAME *PNTFSATFILENAME;
506/** Pointer to a const NTFS filename attribute. */
507typedef NTFSATFILENAME const *PCNTFSATFILENAME;
508
509/** @name NTFS_FILENAME_T_XXX - filename types
510 * @{ */
511#define NTFS_FILENAME_T_POSIX 0
512#define NTFS_FILENAME_T_WINDOWS 1
513#define NTFS_FILENAME_T_DOS 2
514#define NTFS_FILENAME_T_WINDOWS_AND_DSO 3
515/** @} */
516
517
518/**
519 * NTFS volume information (NTFS_AT_VOLUME_INFORMATION).
520 *
521 * This is found in the special NTFS_MFT_IDX_VOLUME file.
522 */
523typedef struct NTFSATVOLUMEINFO
524{
525 /** 0x00: Reserved bytes. */
526 uint8_t abReserved[8];
527 /** 0x08: Major NTFS version number. */
528 uint8_t uMajorVersion;
529 /** 0x09: Minor NTFS version number. */
530 uint8_t uMinorVersion;
531 /** 0x0a: Volume flags (NTFS_VOLUME_F_XXX) */
532 uint16_t fFlags;
533} NTFSATVOLUMEINFO;
534AssertCompileSize(NTFSATVOLUMEINFO, 12);
535/** Pointer to NTFS volume information. */
536typedef NTFSATVOLUMEINFO *PNTFSATVOLUMEINFO;
537/** Pointer to const NTFS volume information. */
538typedef NTFSATVOLUMEINFO const *PCNTFSATVOLUMEINFO;
539
540/** @name NTFS_VOLUME_F_XXX
541 * @{ */
542#define NTFS_VOLUME_F_DIRTY RT_H2LE_U16_C(0x0001) /**< Volume is dirty. */
543#define NTFS_VOLUME_F_RESIZE_LOG_FILE RT_H2LE_U16_C(0x0002) /**< */
544#define NTFS_VOLUME_F_UPGRADE_ON_MOUNT RT_H2LE_U16_C(0x0004) /**< */
545#define NTFS_VOLUME_F_MOUNTED_ON_NT4 RT_H2LE_U16_C(0x0008) /**< */
546#define NTFS_VOLUME_F_DELETE_USN_UNDERWAY RT_H2LE_U16_C(0x0010) /**< */
547#define NTFS_VOLUME_F_REPAIR_OBJECT_ID RT_H2LE_U16_C(0x0020) /**< */
548#define NTFS_VOLUME_F_CHKDSK_UNDERWAY RT_H2LE_U16_C(0x4000) /**< */
549#define NTFS_VOLUME_F_MODIFIED_BY_CHKDSK RT_H2LE_U16_C(0x8000) /**< */
550
551#define NTFS_VOLUME_F_KNOWN_MASK RT_H2LE_U16_C(0xc03f)
552#define NTFS_VOLUME_F_MOUNT_READONLY_MASK RT_H2LE_U16_C(0xc027)
553/** @} */
554
555
556/** The attribute name used by the index attributes on NTFS directories,
557 * ASCII stirng variant. */
558#define NTFS_DIR_ATTRIBUTE_NAME "$I30"
559
560/**
561 * NTFS index header.
562 *
563 * This is used by NTFSATINDEXROOT and NTFSATINDEXALLOC as a prelude to the
564 * sequence of entries in a node.
565 */
566typedef struct NTFSINDEXHDR
567{
568 /** 0x00: Offset of the first entry relative to this header. */
569 uint32_t offFirstEntry;
570 /** 0x04: Current index size in bytes, including this header. */
571 uint32_t cbUsed;
572 /** 0x08: Number of bytes allocated for the index (including this header). */
573 uint32_t cbAllocated;
574 /** 0x0c: Flags (NTFSINDEXHDR_F_XXX). */
575 uint8_t fFlags;
576 /** 0x0d: Reserved bytes. */
577 uint8_t abReserved[3];
578 /* NTFSIDXENTRYHDR sequence typically follows here */
579} NTFSINDEXHDR;
580AssertCompileSize(NTFSINDEXHDR, 16);
581/** Pointer to a NTFS index header. */
582typedef NTFSINDEXHDR *PNTFSINDEXHDR;
583/** Pointer to a const NTFS index header. */
584typedef NTFSINDEXHDR const *PCNTFSINDEXHDR;
585
586/** @name NTFSINDEXHDR_F_XXX
587 * @{ */
588/** An internal node (as opposed to a leaf node if clear).
589 * This means that the entries will have trailing node references (VCN). */
590#define NTFSINDEXHDR_F_INTERNAL UINT8_C(0x01)
591/** @} */
592
593/** Gets the pointer to the first entry header for an index. */
594#define NTFSINDEXHDR_GET_FIRST_ENTRY(a_pIndexHdr) \
595 ( (PNTFSIDXENTRYHDR)((uint8_t *)(a_pIndexHdr) + RT_LE2H_U32((a_pIndexHdr)->offFirstEntry)) )
596
597
598/**
599 * NTFS index root node (NTFS_AT_INDEX_ROOT).
600 *
601 * This is a generic index structure, but is most prominently used for
602 * implementating directories. The index is structured like B-tree, meaning
603 * each node contains multiple entries, and each entry contains data regardless
604 * of whether it's a leaf node or not.
605 *
606 * The index is sorted in ascending order according to the collation rules
607 * defined by the root node (NTFSATINDEXROOT::uCollationRules, see also (see
608 * NTFS_COLLATION_XXX).
609 *
610 * @note The root directory contains a '.' entry, others don't.
611 */
612typedef struct NTFSATINDEXROOT
613{
614 /** 0x00: The index type (NTFSATINDEXROOT_TYPE_XXX). */
615 uint32_t uType;
616 /** 0x04: The sorting rules to use (NTFS_COLLATION_XXX). */
617 uint32_t uCollationRules;
618 /** 0x08: Number of bytes in
619 * Index node size (in bytes). */
620 uint32_t cbIndexNode;
621 /** 0x0c: Number of node addresses per node.
622 * This sounds weird right? A subnode is generally addressed as a virtual
623 * cluster when cbIndexNode >= cbCluster, but when clusters are large NTFS uses
624 * 512 bytes chunks.
625 *
626 * (You would've thought it would be simpler to just use cbIndexNode as the
627 * addressing unit, maybe storing the log2 here to avoid a ffs call.) */
628 uint8_t cAddressesPerIndexNode;
629 /** 0x0d: Reserved padding or something. */
630 uint8_t abReserved[3];
631 /** 0x10: Index header detailing the entries that follows. */
632 NTFSINDEXHDR Hdr;
633 /* 0x20: NTFSIDXENTRYHDR sequence typically follows here */
634} NTFSATINDEXROOT;
635AssertCompileSize(NTFSATINDEXROOT, 32);
636/** Pointer to a NTFS index root. */
637typedef NTFSATINDEXROOT *PNTFSATINDEXROOT;
638/** Pointer to a const NTFS index root. */
639typedef NTFSATINDEXROOT const *PCNTFSATINDEXROOT;
640
641/** @name NTFSATINDEXROOT_TYPE_XXX
642 * @{ */
643/** View index. */
644#define NTFSATINDEXROOT_TYPE_VIEW RT_H2LE_U32_C(UINT32_C(0x00000000))
645/** Directory index, NTFSATFILENAME follows NTFSINDEXENTRY. */
646#define NTFSATINDEXROOT_TYPE_DIR RT_H2LE_U32_C(UINT32_C(0x00000030))
647/** @} */
648
649/** @name NTFS_COLLATION_XXX - index sorting rules
650 * @{ */
651/** Little endian binary compare (or plain byte compare if you like). */
652#define NTFS_COLLATION_BINARY RT_H2LE_U32_C(UINT32_C(0x00000000))
653/** Same as NTFS_COLLATION_UNICODE_STRING. */
654#define NTFS_COLLATION_FILENAME RT_H2LE_U32_C(UINT32_C(0x00000001))
655/** Compare the uppercased unicode characters. */
656#define NTFS_COLLATION_UNICODE_STRING RT_H2LE_U32_C(UINT32_C(0x00000002))
657
658/** Single little endian 32-bit unsigned integer value as sort key. */
659#define NTFS_COLLATION_UINT32 RT_H2LE_U32_C(UINT32_C(0x00000010))
660/** Little endian SID value as sort key. */
661#define NTFS_COLLATION_SID RT_H2LE_U32_C(UINT32_C(0x00000011))
662/** Two little endian 32-bit unsigned integer values used as sorting key. */
663#define NTFS_COLLATION_UINT32_PAIR RT_H2LE_U32_C(UINT32_C(0x00000012))
664/** Sequence of little endian 32-bit unsigned integer values used as sorting key. */
665#define NTFS_COLLATION_UINT32_SEQ RT_H2LE_U32_C(UINT32_C(0x00000013))
666/** @} */
667
668
669/**
670 * NTFS index non-root node.
671 */
672typedef struct NTFSATINDEXALLOC
673{
674 /** 0x00: Header with NTFSREC_MAGIC_INDEX_ALLOC. */
675 NTFSRECHDR RecHdr;
676 /** 0x08: Log file sequence number. */
677 uint64_t uLsn;
678 /** 0x10: The node address of this node (for consistency checking and
679 * perhaps data reconstruction).
680 * @see NTFSATINDEXROOT::cAddressesPerIndexNode for node addressing. */
681 int64_t iSelfAddress;
682 /** 0x18: Index header detailing the entries that follows. */
683 NTFSINDEXHDR Hdr;
684 /* 0x28: NTFSIDXENTRYHDR sequence typically follows here */
685} NTFSATINDEXALLOC;
686AssertCompileSize(NTFSATINDEXALLOC, 40);
687/** Pointer to a NTFS index non-root node. */
688typedef NTFSATINDEXALLOC *PNTFSATINDEXALLOC;
689/** Pointer to a const NTFS index non-root node. */
690typedef NTFSATINDEXALLOC const *PCNTFSATINDEXALLOC;
691
692/** NTFS 'INDX' attribute magic value (NTFSATINDEXALLOC).
693 * @todo sort out the record / attribute name clash here. */
694#define NTFSREC_MAGIC_INDEX_ALLOC RT_H2LE_U32_C(UINT32_C(0x58444e49))
695
696
697/**
698 * NTFS index entry header.
699 *
700 * Each entry in a node starts with this header. It is immediately followed by
701 * the key data (NTFSIDXENTRYHDR::cbKey). When
702 *
703 */
704typedef struct NTFSIDXENTRYHDR
705{
706 union
707 {
708 /** 0x00: NTFSATINDEXROOT_TYPE_DIR: Reference to the MFT record being indexed here.
709 * @note This is invalid if NTFSIDXENTRYHDR_F_END is set (no key data). */
710 NTFSMFTREF FileMftRec;
711 /** 0x00: NTFSATINDEXROOT_TYPE_VIEW: Go figure later if necessary. */
712 struct
713 {
714 /** 0x00: Offset to the data relative to this header.
715 * @note This is invalid if NTFSIDXENTRYHDR_F_END is set (no key data). */
716 uint16_t offData;
717 /** 0x02: Size of data at offData.
718 * @note This is invalid if NTFSIDXENTRYHDR_F_END is set (no key data). */
719 uint16_t cbData;
720 /** 0x04: Reserved. */
721 uint32_t uReserved;
722 } View;
723 } u;
724
725 /** 0x08: Size of this entry, 8-byte aligned. */
726 uint16_t cbEntry;
727 /** 0x0a: Key length (unaligned). */
728 uint16_t cbKey;
729 /** 0x0c: Entry flags, NTFSIDXENTRYHDR_F_XXX. */
730 uint16_t fFlags;
731 /** 0x0e: Reserved. */
732 uint16_t uReserved;
733} NTFSIDXENTRYHDR;
734AssertCompileSize(NTFSIDXENTRYHDR, 16);
735/** Pointer to a NTFS index entry header. */
736typedef NTFSIDXENTRYHDR *PNTFSIDXENTRYHDR;
737/** Pointer to a const NTFS index entry header. */
738typedef NTFSIDXENTRYHDR const *PCNTFSIDXENTRYHDR;
739
740/** @name NTFSIDXENTRYHDR_F_XXX - NTFSIDXENTRYHDR::fFlags
741 * @{ */
742/** Indicates an internal node (as opposed to a leaf node).
743 * This indicates that there is a 64-bit integer value at the very end of the
744 * entry (NTFSIDXENTRYHDR::cbEntry - 8) giving the virtual cluster number of the
745 * subnode. The subnode and all its decendants contain keys that are lower than
746 * the key in this entry.
747 */
748#define NTFSIDXENTRYHDR_F_INTERNAL RT_H2LE_U16_C(UINT16_C(0x0001))
749/** Set if special end entry in a node.
750 * This does not have any key data, but can point to a subnode with
751 * higher keys. */
752#define NTFSIDXENTRYHDR_F_END RT_H2LE_U16_C(UINT16_C(0x0002))
753/** @} */
754
755/** Gets the pointer to the next index entry header. */
756#define NTFSIDXENTRYHDR_GET_NEXT(a_pEntryHdr) \
757 ( (PNTFSIDXENTRYHDR)((uintptr_t)(a_pEntryHdr) + RT_LE2H_U16((a_pEntryHdr)->cbEntry)) )
758/** Gets the subnode address from an index entry.
759 * @see NTFSATINDEXROOT::cAddressesPerIndexNode for node addressing.
760 * @note Only invoke when NTFSIDXENTRYHDR_F_INTERNAL is set! */
761#define NTFSIDXENTRYHDR_GET_SUBNODE(a_pEntryHdr) \
762 ( *(int64_t *)((uintptr_t)(a_pEntryHdr) + RT_LE2H_U16((a_pEntryHdr)->cbEntry) - sizeof(int64_t)) )
763
764/** @} */
765
766#endif
767
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette