ae64c3785000885010a5739861ad3025870a510d
[reactos.git] / reactos / boot / freeldr / freeldr / fs / ntfs.h
1 /*
2 * FreeLoader NTFS support
3 * Copyright (C) 2004 Filip Navara <xnavara@volny.cz>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __NTFS_H
21 #define __NTFS_H
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
35 #define NTFS_ATTR_TYPE_STANDARD_INFORMATION 0x10
36 #define NTFS_ATTR_TYPE_ATTRIBUTE_LIST 0x20
37 #define NTFS_ATTR_TYPE_FILENAME 0x30
38 #define NTFS_ATTR_TYPE_SECURITY_DESCRIPTOR 0x50
39 #define NTFS_ATTR_TYPE_DATA 0x80
40 #define NTFS_ATTR_TYPE_INDEX_ROOT 0x90
41 #define NTFS_ATTR_TYPE_INDEX_ALLOCATION 0xa0
42 #define NTFS_ATTR_TYPE_BITMAP 0xb0
43 #define NTFS_ATTR_TYPE_SYMLINK 0xc0
44 #define NTFS_ATTR_TYPE_END 0xffffffff
45
46 #define NTFS_ATTR_NORMAL 0
47 #define NTFS_ATTR_COMPRESSED 1
48 #define NTFS_ATTR_RESIDENT 2
49 #define NTFS_ATTR_ENCRYPTED 0x4000
50
51 #define NTFS_SMALL_INDEX 0
52 #define NTFS_LARGE_INDEX 1
53
54 #define NTFS_INDEX_ENTRY_NODE 1
55 #define NTFS_INDEX_ENTRY_END 2
56
57 #define NTFS_FILE_NAME_POSIX 0
58 #define NTFS_FILE_NAME_WIN32 1
59 #define NTFS_FILE_NAME_DOS 2
60 #define NTFS_FILE_NAME_WIN32_AND_DOS 3
61
62 typedef struct
63 {
64 UCHAR JumpBoot[3]; // Jump to the boot loader routine
65 CHAR SystemId[8]; // System Id ("NTFS ")
66 USHORT BytesPerSector; // Bytes per sector
67 UCHAR SectorsPerCluster; // Number of sectors in a cluster
68 UCHAR Unused1[7];
69 UCHAR MediaDescriptor; // Media descriptor byte
70 UCHAR Unused2[2];
71 USHORT SectorsPerTrack; // Number of sectors in a track
72 USHORT NumberOfHeads; // Number of heads on the disk
73 UCHAR Unused3[8];
74 UCHAR DriveNumber; // Int 0x13 drive number (e.g. 0x80)
75 UCHAR CurrentHead;
76 UCHAR BootSignature; // Extended boot signature (0x80)
77 UCHAR Unused4;
78 ULONGLONG VolumeSectorCount; // Number of sectors in the volume
79 ULONGLONG MftLocation;
80 ULONGLONG MftMirrorLocation;
81 CHAR ClustersPerMftRecord; // Clusters per MFT Record
82 UCHAR Unused5[3];
83 CHAR ClustersPerIndexRecord; // Clusters per Index Record
84 UCHAR Unused6[3];
85 ULONGLONG VolumeSerialNumber; // Volume serial number
86 UCHAR BootCodeAndData[430]; // The remainder of the boot sector
87 USHORT BootSectorMagic; // 0xAA55
88 } PACKED NTFS_BOOTSECTOR, *PNTFS_BOOTSECTOR;
89
90 typedef struct
91 {
92 ULONG Magic;
93 USHORT USAOffset; // Offset to the Update Sequence Array from the start of the ntfs record
94 USHORT USACount;
95 } PACKED NTFS_RECORD, *PNTFS_RECORD;
96
97 typedef struct
98 {
99 ULONG Magic;
100 USHORT USAOffset; // Offset to the Update Sequence Array from the start of the ntfs record
101 USHORT USACount;
102 ULONGLONG LogSequenceNumber;
103 USHORT SequenceNumber;
104 USHORT LinkCount;
105 USHORT AttributesOffset;
106 USHORT Flags;
107 ULONG BytesInUse; // Number of bytes used in this mft record.
108 ULONG BytesAllocated;
109 ULONGLONG BaseMFTRecord;
110 USHORT NextAttributeInstance;
111 } PACKED NTFS_MFT_RECORD, *PNTFS_MFT_RECORD;
112
113 typedef struct
114 {
115 ULONG Type;
116 ULONG Length;
117 UCHAR IsNonResident;
118 UCHAR NameLength;
119 USHORT NameOffset;
120 USHORT Flags;
121 USHORT Instance;
122 union
123 {
124 // Resident attributes
125 struct
126 {
127 ULONG ValueLength;
128 USHORT ValueOffset;
129 USHORT Flags;
130 } PACKED Resident;
131 // Non-resident attributes
132 struct
133 {
134 ULONGLONG LowestVCN;
135 ULONGLONG HighestVCN;
136 USHORT MappingPairsOffset;
137 UCHAR CompressionUnit;
138 UCHAR Reserved[5];
139 LONGLONG AllocatedSize;
140 LONGLONG DataSize;
141 LONGLONG InitializedSize;
142 LONGLONG CompressedSize;
143 } PACKED NonResident;
144 } PACKED;
145 } PACKED NTFS_ATTR_RECORD, *PNTFS_ATTR_RECORD;
146
147 typedef struct
148 {
149 ULONG EntriesOffset;
150 ULONG IndexLength;
151 ULONG AllocatedSize;
152 UCHAR Flags;
153 UCHAR Reserved[3];
154 } PACKED NTFS_INDEX_HEADER, *PNTFS_INDEX_HEADER;
155
156 typedef struct
157 {
158 ULONG Type;
159 ULONG CollationRule;
160 ULONG IndexBlockSize;
161 UCHAR ClustersPerIndexBlock;
162 UCHAR Reserved[3];
163 NTFS_INDEX_HEADER IndexHeader;
164 } PACKED NTFS_INDEX_ROOT, *PNTFS_INDEX_ROOT;
165
166 typedef struct
167 {
168 ULONGLONG ParentDirectory;
169 LONGLONG CreationTime;
170 LONGLONG LastDataChangeTime;
171 LONGLONG LastMftChangeTime;
172 LONGLONG LastAccessTime;
173 LONGLONG AllocatedSize;
174 LONGLONG DataSize;
175 ULONG FileAttributes;
176 USHORT PackedExtendedAttributeSize;
177 USHORT Reserved;
178 UCHAR FileNameLength;
179 UCHAR FileNameType;
180 WCHAR FileName[0];
181 } PACKED NTFS_FILE_NAME_ATTR, *PNTFS_FILE_NAME_ATTR;
182
183 typedef struct {
184 union
185 {
186 struct
187 {
188 ULONGLONG IndexedFile;
189 } PACKED Directory;
190 struct
191 {
192 USHORT DataOffset;
193 USHORT DataLength;
194 ULONG Reserved;
195 } PACKED ViewIndex;
196 } PACKED Data;
197 USHORT Length;
198 USHORT KeyLength;
199 USHORT Flags;
200 USHORT Reserved;
201 NTFS_FILE_NAME_ATTR FileName;
202 } PACKED NTFS_INDEX_ENTRY, *PNTFS_INDEX_ENTRY;
203
204 typedef struct
205 {
206 PNTFS_ATTR_RECORD Record;
207 PUCHAR CacheRun;
208 ULONGLONG CacheRunOffset;
209 LONGLONG CacheRunStartLCN;
210 ULONGLONG CacheRunLength;
211 LONGLONG CacheRunLastLCN;
212 ULONGLONG CacheRunCurrentOffset;
213 } NTFS_ATTR_CONTEXT, *PNTFS_ATTR_CONTEXT;
214
215 typedef struct
216 {
217 NTFS_ATTR_CONTEXT DataContext;
218 ULONGLONG Offset;
219 } PACKED NTFS_FILE_HANDLE, *PNTFS_FILE_HANDLE;
220
221 BOOL NtfsOpenVolume(ULONG DriveNumber, ULONG VolumeStartSector);
222 FILE* NtfsOpenFile(PCHAR FileName);
223 BOOL NtfsReadFile(FILE *FileHandle, ULONG BytesToRead, ULONG* BytesRead, PVOID Buffer);
224 ULONG NtfsGetFileSize(FILE *FileHandle);
225 VOID NtfsSetFilePointer(FILE *FileHandle, ULONG NewFilePointer);
226 ULONG NtfsGetFilePointer(FILE *FileHandle);
227
228 #endif // #defined __NTFS_H