2 * FreeLoader NTFS support
3 * Copyright (C) 2004 Filip Navara <xnavara@volny.cz>
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.
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.
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.
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
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
46 #define NTFS_ATTR_NORMAL 0
47 #define NTFS_ATTR_COMPRESSED 1
48 #define NTFS_ATTR_RESIDENT 2
49 #define NTFS_ATTR_ENCRYPTED 0x4000
51 #define NTFS_SMALL_INDEX 0
52 #define NTFS_LARGE_INDEX 1
54 #define NTFS_INDEX_ENTRY_NODE 1
55 #define NTFS_INDEX_ENTRY_END 2
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
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
69 UCHAR MediaDescriptor
; // Media descriptor byte
71 USHORT SectorsPerTrack
; // Number of sectors in a track
72 USHORT NumberOfHeads
; // Number of heads on the disk
74 UCHAR DriveNumber
; // Int 0x13 drive number (e.g. 0x80)
76 UCHAR BootSignature
; // Extended boot signature (0x80)
78 ULONGLONG VolumeSectorCount
; // Number of sectors in the volume
79 ULONGLONG MftLocation
;
80 ULONGLONG MftMirrorLocation
;
81 CHAR ClustersPerMftRecord
; // Clusters per MFT Record
83 CHAR ClustersPerIndexRecord
; // Clusters per Index Record
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
;
93 USHORT USAOffset
; // Offset to the Update Sequence Array from the start of the ntfs record
95 } PACKED NTFS_RECORD
, *PNTFS_RECORD
;
100 USHORT USAOffset
; // Offset to the Update Sequence Array from the start of the ntfs record
102 ULONGLONG LogSequenceNumber
;
103 USHORT SequenceNumber
;
105 USHORT AttributesOffset
;
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
;
124 // Resident attributes
131 // Non-resident attributes
135 ULONGLONG HighestVCN
;
136 USHORT MappingPairsOffset
;
137 UCHAR CompressionUnit
;
139 LONGLONG AllocatedSize
;
141 LONGLONG InitializedSize
;
142 LONGLONG CompressedSize
;
143 } PACKED NonResident
;
145 } PACKED NTFS_ATTR_RECORD
, *PNTFS_ATTR_RECORD
;
154 } PACKED NTFS_INDEX_HEADER
, *PNTFS_INDEX_HEADER
;
160 ULONG IndexBlockSize
;
161 UCHAR ClustersPerIndexBlock
;
163 NTFS_INDEX_HEADER IndexHeader
;
164 } PACKED NTFS_INDEX_ROOT
, *PNTFS_INDEX_ROOT
;
168 ULONGLONG ParentDirectory
;
169 LONGLONG CreationTime
;
170 LONGLONG LastDataChangeTime
;
171 LONGLONG LastMftChangeTime
;
172 LONGLONG LastAccessTime
;
173 LONGLONG AllocatedSize
;
175 ULONG FileAttributes
;
176 USHORT PackedExtendedAttributeSize
;
178 UCHAR FileNameLength
;
181 } PACKED NTFS_FILE_NAME_ATTR
, *PNTFS_FILE_NAME_ATTR
;
188 ULONGLONG IndexedFile
;
201 NTFS_FILE_NAME_ATTR FileName
;
202 } PACKED NTFS_INDEX_ENTRY
, *PNTFS_INDEX_ENTRY
;
206 PNTFS_ATTR_RECORD Record
;
208 ULONGLONG CacheRunOffset
;
209 LONGLONG CacheRunStartLCN
;
210 ULONGLONG CacheRunLength
;
211 LONGLONG CacheRunLastLCN
;
212 ULONGLONG CacheRunCurrentOffset
;
213 } NTFS_ATTR_CONTEXT
, *PNTFS_ATTR_CONTEXT
;
217 NTFS_ATTR_CONTEXT DataContext
;
219 } PACKED NTFS_FILE_HANDLE
, *PNTFS_FILE_HANDLE
;
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
);
228 #endif // #defined __NTFS_H