xref: /reactos/boot/freeldr/freeldr/include/fs/ntfs.h (revision d01f9489)
1 /*
2  *  FreeLoader NTFS support
3  *  Copyright (C) 2004  Filip Navara  <xnavara@volny.cz>
4  *  Copyright (C) 2011  Pierre Schweitzer <pierre.schweitzer@reactos.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License along
17  *  with this program; if not, write to the Free Software Foundation, Inc.,
18  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #pragma once
22 
23 #define NTFS_FILE_MFT                0
24 #define NTFS_FILE_MFTMIRR            1
25 #define NTFS_FILE_LOGFILE            2
26 #define NTFS_FILE_VOLUME            3
27 #define NTFS_FILE_ATTRDEF            4
28 #define NTFS_FILE_ROOT                5
29 #define NTFS_FILE_BITMAP            6
30 #define NTFS_FILE_BOOT                7
31 #define NTFS_FILE_BADCLUS            8
32 #define NTFS_FILE_QUOTA                9
33 #define NTFS_FILE_UPCASE            10
34 #define NTFS_FILE_EXTEND            11
35 
36 #define NTFS_ATTR_TYPE_STANDARD_INFORMATION    0x10
37 #define NTFS_ATTR_TYPE_ATTRIBUTE_LIST        0x20
38 #define NTFS_ATTR_TYPE_FILENAME            0x30
39 #define NTFS_ATTR_TYPE_OBJECT_ID        0x40
40 #define NTFS_ATTR_TYPE_SECURITY_DESCRIPTOR    0x50
41 #define NTFS_ATTR_TYPE_VOLUME_NAME        0x60
42 #define NTFS_ATTR_TYPE_VOLUME_INFORMATION    0x70
43 #define NTFS_ATTR_TYPE_DATA            0x80
44 #define NTFS_ATTR_TYPE_INDEX_ROOT        0x90
45 #define NTFS_ATTR_TYPE_INDEX_ALLOCATION        0xa0
46 #define NTFS_ATTR_TYPE_BITMAP            0xb0
47 #define NTFS_ATTR_TYPE_REPARSE_POINT    0xc0
48 #define NTFS_ATTR_TYPE_EA_INFORMATION    0xd0
49 #define NTFS_ATTR_TYPE_EA            0xe0
50 #define NTFS_ATTR_TYPE_END            0xffffffff
51 
52 #define NTFS_ATTR_NORMAL            0
53 #define NTFS_ATTR_COMPRESSED            1
54 #define NTFS_ATTR_RESIDENT            2
55 #define NTFS_ATTR_ENCRYPTED            0x4000
56 
57 #define NTFS_SMALL_INDEX            0
58 #define NTFS_LARGE_INDEX            1
59 
60 #define NTFS_INDEX_ENTRY_NODE            1
61 #define NTFS_INDEX_ENTRY_END            2
62 
63 #define NTFS_FILE_NAME_POSIX            0
64 #define NTFS_FILE_NAME_WIN32            1
65 #define NTFS_FILE_NAME_DOS            2
66 #define NTFS_FILE_NAME_WIN32_AND_DOS        3
67 
68 #define NTFS_MFT_MASK 0x0000FFFFFFFFFFFFULL
69 
70 #include <pshpack1.h>
71 typedef struct
72 {
73     UCHAR        JumpBoot[3];            // Jump to the boot loader routine
74     CHAR        SystemId[8];            // System Id ("NTFS    ")
75     USHORT        BytesPerSector;            // Bytes per sector
76     UCHAR        SectorsPerCluster;        // Number of sectors in a cluster
77     UCHAR        Unused1[7];
78     UCHAR        MediaDescriptor;        // Media descriptor byte
79     UCHAR        Unused2[2];
80     USHORT        SectorsPerTrack;        // Number of sectors in a track
81     USHORT        NumberOfHeads;            // Number of heads on the disk
82     UCHAR        Unused3[8];
83     UCHAR        DriveNumber;            // Int 0x13 drive number (e.g. 0x80)
84     UCHAR        CurrentHead;
85     UCHAR        BootSignature;            // Extended boot signature (0x80)
86     UCHAR        Unused4;
87     ULONGLONG        VolumeSectorCount;        // Number of sectors in the volume
88     ULONGLONG        MftLocation;
89     ULONGLONG        MftMirrorLocation;
90     CHAR        ClustersPerMftRecord;        // Clusters per MFT Record
91     UCHAR        Unused5[3];
92     CHAR        ClustersPerIndexRecord;        // Clusters per Index Record
93     UCHAR        Unused6[3];
94     ULONGLONG        VolumeSerialNumber;        // Volume serial number
95     UCHAR        BootCodeAndData[430];        // The remainder of the boot sector
96     USHORT        BootSectorMagic;        // 0xAA55
97 } NTFS_BOOTSECTOR, *PNTFS_BOOTSECTOR;
98 
99 typedef struct
100 {
101     ULONG        Magic;
102     USHORT        USAOffset;                    // Offset to the Update Sequence Array from the start of the ntfs record
103     USHORT        USACount;
104 } NTFS_RECORD, *PNTFS_RECORD;
105 
106 typedef struct
107 {
108     ULONG        Magic;
109     USHORT        USAOffset;                    // Offset to the Update Sequence Array from the start of the ntfs record
110     USHORT        USACount;
111     ULONGLONG        LogSequenceNumber;
112     USHORT        SequenceNumber;
113     USHORT        LinkCount;
114     USHORT        AttributesOffset;
115     USHORT        Flags;
116     ULONG        BytesInUse;                    // Number of bytes used in this mft record.
117     ULONG        BytesAllocated;
118     ULONGLONG        BaseMFTRecord;
119     USHORT        NextAttributeInstance;
120     USHORT        Padding;                     // Align to 4 UCHAR boundary (NTFS 3.1+ (Windows XP and above))
121     ULONG        MFTRecordNumber;             // Number of this MFT Record (NTFS 3.1+ (Windows XP and above))
122 } NTFS_MFT_RECORD, *PNTFS_MFT_RECORD;
123 
124 typedef struct
125 {
126     ULONG        Type;
127     ULONG        Length;
128     UCHAR        IsNonResident;
129     UCHAR        NameLength;
130     USHORT        NameOffset;
131     USHORT        Flags;
132     USHORT        Instance;
133     union
134     {
135         // Resident attributes
136         struct
137         {
138             ULONG        ValueLength;
139             USHORT        ValueOffset;
140             UCHAR        Flags;
141             UCHAR        Reserved;
142         } Resident;
143         // Non-resident attributes
144         struct
145         {
146             ULONGLONG        LowestVCN;
147             ULONGLONG        HighestVCN;
148             USHORT        MappingPairsOffset;
149             USHORT        CompressionUnit;
150             UCHAR        Reserved[4];
151             LONGLONG        AllocatedSize;
152             LONGLONG        DataSize;
153             LONGLONG        InitializedSize;
154             LONGLONG        CompressedSize;
155         } NonResident;
156     };
157 } NTFS_ATTR_RECORD, *PNTFS_ATTR_RECORD;
158 
159 typedef struct
160 {
161     ULONG        EntriesOffset;
162     ULONG        IndexLength;
163     ULONG        AllocatedSize;
164     UCHAR        Flags;
165     UCHAR        Reserved[3];
166 } NTFS_INDEX_HEADER, *PNTFS_INDEX_HEADER;
167 
168 typedef struct
169 {
170     ULONG        Type;
171     ULONG        CollationRule;
172     ULONG        IndexBlockSize;
173     UCHAR        ClustersPerIndexBlock;
174     UCHAR        Reserved[3];
175     NTFS_INDEX_HEADER    IndexHeader;
176 } NTFS_INDEX_ROOT, *PNTFS_INDEX_ROOT;
177 
178 typedef struct
179 {
180     ULONGLONG        ParentDirectory;
181     LONGLONG        CreationTime;
182     LONGLONG        LastDataChangeTime;
183     LONGLONG        LastMftChangeTime;
184     LONGLONG        LastAccessTime;
185     LONGLONG        AllocatedSize;
186     LONGLONG        DataSize;
187     ULONG        FileAttributes;
188     USHORT        PackedExtendedAttributeSize;
189     USHORT        Reserved;
190     UCHAR        FileNameLength;
191     UCHAR        FileNameType;
192     WCHAR        FileName[1];
193 } NTFS_FILE_NAME_ATTR, *PNTFS_FILE_NAME_ATTR;
194 
195 typedef struct
196 {
197     ULONG        Type;
198     USHORT        RecLength;
199     UCHAR        NameLength;
200     UCHAR        NameOffset;
201     ULONGLONG    StartingVCN;
202     ULONGLONG    BaseFileRef;
203     USHORT        AttrId;
204     WCHAR        Name[1];
205 } NTFS_ATTR_LIST_ATTR, *PNTFS_ATTR_LIST_ATTR;
206 
207 typedef struct
208 {
209     union
210     {
211         struct
212         {
213             ULONGLONG    IndexedFile;
214         } Directory;
215         struct
216         {
217             USHORT    DataOffset;
218             USHORT    DataLength;
219             ULONG    Reserved;
220         } ViewIndex;
221     } Data;
222     USHORT            Length;
223     USHORT            KeyLength;
224     USHORT            Flags;
225     USHORT            Reserved;
226     NTFS_FILE_NAME_ATTR    FileName;
227 } NTFS_INDEX_ENTRY, *PNTFS_INDEX_ENTRY;
228 #include <poppack.h>
229 
230 typedef struct
231 {
232     PUCHAR            CacheRun;
233     ULONGLONG            CacheRunOffset;
234     LONGLONG            CacheRunStartLCN;
235     ULONGLONG            CacheRunLength;
236     LONGLONG            CacheRunLastLCN;
237     ULONGLONG            CacheRunCurrentOffset;
238     NTFS_ATTR_RECORD    Record;
239 } NTFS_ATTR_CONTEXT, *PNTFS_ATTR_CONTEXT;
240 
241 typedef struct _NTFS_VOLUME_INFO *PNTFS_VOLUME_INFO;
242 
243 #include <pshpack1.h>
244 typedef struct
245 {
246     PNTFS_ATTR_CONTEXT    DataContext;
247     ULONGLONG            Offset;
248     PNTFS_VOLUME_INFO    Volume;
249 } NTFS_FILE_HANDLE, *PNTFS_FILE_HANDLE;
250 #include <poppack.h>
251 
252 const DEVVTBL* NtfsMount(ULONG DeviceId);
253