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 #include <pshpack1.h> 69 typedef struct 70 { 71 UCHAR JumpBoot[3]; // Jump to the boot loader routine 72 CHAR SystemId[8]; // System Id ("NTFS ") 73 USHORT BytesPerSector; // Bytes per sector 74 UCHAR SectorsPerCluster; // Number of sectors in a cluster 75 UCHAR Unused1[7]; 76 UCHAR MediaDescriptor; // Media descriptor byte 77 UCHAR Unused2[2]; 78 USHORT SectorsPerTrack; // Number of sectors in a track 79 USHORT NumberOfHeads; // Number of heads on the disk 80 UCHAR Unused3[8]; 81 UCHAR DriveNumber; // Int 0x13 drive number (e.g. 0x80) 82 UCHAR CurrentHead; 83 UCHAR BootSignature; // Extended boot signature (0x80) 84 UCHAR Unused4; 85 ULONGLONG VolumeSectorCount; // Number of sectors in the volume 86 ULONGLONG MftLocation; 87 ULONGLONG MftMirrorLocation; 88 CHAR ClustersPerMftRecord; // Clusters per MFT Record 89 UCHAR Unused5[3]; 90 CHAR ClustersPerIndexRecord; // Clusters per Index Record 91 UCHAR Unused6[3]; 92 ULONGLONG VolumeSerialNumber; // Volume serial number 93 UCHAR BootCodeAndData[430]; // The remainder of the boot sector 94 USHORT BootSectorMagic; // 0xAA55 95 } NTFS_BOOTSECTOR, *PNTFS_BOOTSECTOR; 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 } NTFS_RECORD, *PNTFS_RECORD; 103 104 typedef struct 105 { 106 ULONG Magic; 107 USHORT USAOffset; // Offset to the Update Sequence Array from the start of the ntfs record 108 USHORT USACount; 109 ULONGLONG LogSequenceNumber; 110 USHORT SequenceNumber; 111 USHORT LinkCount; 112 USHORT AttributesOffset; 113 USHORT Flags; 114 ULONG BytesInUse; // Number of bytes used in this mft record. 115 ULONG BytesAllocated; 116 ULONGLONG BaseMFTRecord; 117 USHORT NextAttributeInstance; 118 } NTFS_MFT_RECORD, *PNTFS_MFT_RECORD; 119 120 typedef struct 121 { 122 ULONG Type; 123 ULONG Length; 124 UCHAR IsNonResident; 125 UCHAR NameLength; 126 USHORT NameOffset; 127 USHORT Flags; 128 USHORT Instance; 129 union 130 { 131 // Resident attributes 132 struct 133 { 134 ULONG ValueLength; 135 USHORT ValueOffset; 136 UCHAR Flags; 137 UCHAR Reserved; 138 } Resident; 139 // Non-resident attributes 140 struct 141 { 142 ULONGLONG LowestVCN; 143 ULONGLONG HighestVCN; 144 USHORT MappingPairsOffset; 145 USHORT CompressionUnit; 146 UCHAR Reserved[4]; 147 LONGLONG AllocatedSize; 148 LONGLONG DataSize; 149 LONGLONG InitializedSize; 150 LONGLONG CompressedSize; 151 } NonResident; 152 }; 153 } NTFS_ATTR_RECORD, *PNTFS_ATTR_RECORD; 154 155 typedef struct 156 { 157 ULONG EntriesOffset; 158 ULONG IndexLength; 159 ULONG AllocatedSize; 160 UCHAR Flags; 161 UCHAR Reserved[3]; 162 } NTFS_INDEX_HEADER, *PNTFS_INDEX_HEADER; 163 164 typedef struct 165 { 166 ULONG Type; 167 ULONG CollationRule; 168 ULONG IndexBlockSize; 169 UCHAR ClustersPerIndexBlock; 170 UCHAR Reserved[3]; 171 NTFS_INDEX_HEADER IndexHeader; 172 } NTFS_INDEX_ROOT, *PNTFS_INDEX_ROOT; 173 174 typedef struct 175 { 176 ULONGLONG ParentDirectory; 177 LONGLONG CreationTime; 178 LONGLONG LastDataChangeTime; 179 LONGLONG LastMftChangeTime; 180 LONGLONG LastAccessTime; 181 LONGLONG AllocatedSize; 182 LONGLONG DataSize; 183 ULONG FileAttributes; 184 USHORT PackedExtendedAttributeSize; 185 USHORT Reserved; 186 UCHAR FileNameLength; 187 UCHAR FileNameType; 188 WCHAR FileName[0]; 189 } NTFS_FILE_NAME_ATTR, *PNTFS_FILE_NAME_ATTR; 190 191 typedef struct 192 { 193 ULONG Type; 194 USHORT RecLength; 195 UCHAR NameLength; 196 UCHAR NameOffset; 197 ULONGLONG StartingVCN; 198 ULONGLONG BaseFileRef; 199 USHORT AttrId; 200 PWCHAR Name; 201 } NTFS_ATTR_LIST_ATTR, *PNTFS_ATTR_LIST_ATTR; 202 203 typedef struct 204 { 205 union 206 { 207 struct 208 { 209 ULONGLONG IndexedFile; 210 } Directory; 211 struct 212 { 213 USHORT DataOffset; 214 USHORT DataLength; 215 ULONG Reserved; 216 } ViewIndex; 217 } Data; 218 USHORT Length; 219 USHORT KeyLength; 220 USHORT Flags; 221 USHORT Reserved; 222 NTFS_FILE_NAME_ATTR FileName; 223 } NTFS_INDEX_ENTRY, *PNTFS_INDEX_ENTRY; 224 #include <poppack.h> 225 226 typedef struct 227 { 228 PUCHAR CacheRun; 229 ULONGLONG CacheRunOffset; 230 LONGLONG CacheRunStartLCN; 231 ULONGLONG CacheRunLength; 232 LONGLONG CacheRunLastLCN; 233 ULONGLONG CacheRunCurrentOffset; 234 NTFS_ATTR_RECORD Record; 235 } NTFS_ATTR_CONTEXT, *PNTFS_ATTR_CONTEXT; 236 237 typedef struct _NTFS_VOLUME_INFO *PNTFS_VOLUME_INFO; 238 239 #include <pshpack1.h> 240 typedef struct 241 { 242 PNTFS_ATTR_CONTEXT DataContext; 243 ULONGLONG Offset; 244 PNTFS_VOLUME_INFO Volume; 245 } NTFS_FILE_HANDLE, *PNTFS_FILE_HANDLE; 246 #include <poppack.h> 247 248 const DEVVTBL* NtfsMount(ULONG DeviceId); 249