ReactOS  0.4.13-dev-563-g0561610
ntfs.h File Reference
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for ntfs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  NTFS_BOOTSECTOR
 
struct  NTFS_RECORD
 
struct  NTFS_MFT_RECORD
 
struct  NTFS_ATTR_RECORD
 
struct  NTFS_INDEX_HEADER
 
struct  NTFS_INDEX_ROOT
 
struct  NTFS_FILE_NAME_ATTR
 
struct  NTFS_ATTR_LIST_ATTR
 
struct  NTFS_INDEX_ENTRY
 
struct  NTFS_ATTR_CONTEXT
 
struct  NTFS_FILE_HANDLE
 

Macros

#define NTFS_FILE_MFT   0
 
#define NTFS_FILE_MFTMIRR   1
 
#define NTFS_FILE_LOGFILE   2
 
#define NTFS_FILE_VOLUME   3
 
#define NTFS_FILE_ATTRDEF   4
 
#define NTFS_FILE_ROOT   5
 
#define NTFS_FILE_BITMAP   6
 
#define NTFS_FILE_BOOT   7
 
#define NTFS_FILE_BADCLUS   8
 
#define NTFS_FILE_QUOTA   9
 
#define NTFS_FILE_UPCASE   10
 
#define NTFS_FILE_EXTEND   11
 
#define NTFS_ATTR_TYPE_STANDARD_INFORMATION   0x10
 
#define NTFS_ATTR_TYPE_ATTRIBUTE_LIST   0x20
 
#define NTFS_ATTR_TYPE_FILENAME   0x30
 
#define NTFS_ATTR_TYPE_OBJECT_ID   0x40
 
#define NTFS_ATTR_TYPE_SECURITY_DESCRIPTOR   0x50
 
#define NTFS_ATTR_TYPE_VOLUME_NAME   0x60
 
#define NTFS_ATTR_TYPE_VOLUME_INFORMATION   0x70
 
#define NTFS_ATTR_TYPE_DATA   0x80
 
#define NTFS_ATTR_TYPE_INDEX_ROOT   0x90
 
#define NTFS_ATTR_TYPE_INDEX_ALLOCATION   0xa0
 
#define NTFS_ATTR_TYPE_BITMAP   0xb0
 
#define NTFS_ATTR_TYPE_REPARSE_POINT   0xc0
 
#define NTFS_ATTR_TYPE_EA_INFORMATION   0xd0
 
#define NTFS_ATTR_TYPE_EA   0xe0
 
#define NTFS_ATTR_TYPE_END   0xffffffff
 
#define NTFS_ATTR_NORMAL   0
 
#define NTFS_ATTR_COMPRESSED   1
 
#define NTFS_ATTR_RESIDENT   2
 
#define NTFS_ATTR_ENCRYPTED   0x4000
 
#define NTFS_SMALL_INDEX   0
 
#define NTFS_LARGE_INDEX   1
 
#define NTFS_INDEX_ENTRY_NODE   1
 
#define NTFS_INDEX_ENTRY_END   2
 
#define NTFS_FILE_NAME_POSIX   0
 
#define NTFS_FILE_NAME_WIN32   1
 
#define NTFS_FILE_NAME_DOS   2
 
#define NTFS_FILE_NAME_WIN32_AND_DOS   3
 

Typedefs

typedef struct NTFS_BOOTSECTORPNTFS_BOOTSECTOR
 
typedef struct NTFS_RECORDPNTFS_RECORD
 
typedef struct NTFS_MFT_RECORDPNTFS_MFT_RECORD
 
typedef struct NTFS_ATTR_RECORDPNTFS_ATTR_RECORD
 
typedef struct NTFS_INDEX_HEADERPNTFS_INDEX_HEADER
 
typedef struct NTFS_INDEX_ROOTPNTFS_INDEX_ROOT
 
typedef struct NTFS_FILE_NAME_ATTRPNTFS_FILE_NAME_ATTR
 
typedef struct NTFS_ATTR_LIST_ATTRPNTFS_ATTR_LIST_ATTR
 
typedef struct NTFS_INDEX_ENTRYPNTFS_INDEX_ENTRY
 
typedef struct NTFS_ATTR_CONTEXTPNTFS_ATTR_CONTEXT
 
typedef struct _NTFS_VOLUME_INFOPNTFS_VOLUME_INFO
 
typedef struct NTFS_FILE_HANDLEPNTFS_FILE_HANDLE
 

Functions

const DEVVTBLNtfsMount (ULONG DeviceId)
 

Macro Definition Documentation

◆ NTFS_ATTR_COMPRESSED

#define NTFS_ATTR_COMPRESSED   1

Definition at line 53 of file ntfs.h.

◆ NTFS_ATTR_ENCRYPTED

#define NTFS_ATTR_ENCRYPTED   0x4000

Definition at line 55 of file ntfs.h.

◆ NTFS_ATTR_NORMAL

#define NTFS_ATTR_NORMAL   0

Definition at line 52 of file ntfs.h.

◆ NTFS_ATTR_RESIDENT

#define NTFS_ATTR_RESIDENT   2

Definition at line 54 of file ntfs.h.

◆ NTFS_ATTR_TYPE_ATTRIBUTE_LIST

#define NTFS_ATTR_TYPE_ATTRIBUTE_LIST   0x20

Definition at line 37 of file ntfs.h.

◆ NTFS_ATTR_TYPE_BITMAP

#define NTFS_ATTR_TYPE_BITMAP   0xb0

Definition at line 46 of file ntfs.h.

◆ NTFS_ATTR_TYPE_DATA

#define NTFS_ATTR_TYPE_DATA   0x80

Definition at line 43 of file ntfs.h.

◆ NTFS_ATTR_TYPE_EA

#define NTFS_ATTR_TYPE_EA   0xe0

Definition at line 49 of file ntfs.h.

◆ NTFS_ATTR_TYPE_EA_INFORMATION

#define NTFS_ATTR_TYPE_EA_INFORMATION   0xd0

Definition at line 48 of file ntfs.h.

◆ NTFS_ATTR_TYPE_END

#define NTFS_ATTR_TYPE_END   0xffffffff

Definition at line 50 of file ntfs.h.

◆ NTFS_ATTR_TYPE_FILENAME

#define NTFS_ATTR_TYPE_FILENAME   0x30

Definition at line 38 of file ntfs.h.

◆ NTFS_ATTR_TYPE_INDEX_ALLOCATION

#define NTFS_ATTR_TYPE_INDEX_ALLOCATION   0xa0

Definition at line 45 of file ntfs.h.

◆ NTFS_ATTR_TYPE_INDEX_ROOT

#define NTFS_ATTR_TYPE_INDEX_ROOT   0x90

Definition at line 44 of file ntfs.h.

◆ NTFS_ATTR_TYPE_OBJECT_ID

#define NTFS_ATTR_TYPE_OBJECT_ID   0x40

Definition at line 39 of file ntfs.h.

◆ NTFS_ATTR_TYPE_REPARSE_POINT

#define NTFS_ATTR_TYPE_REPARSE_POINT   0xc0

Definition at line 47 of file ntfs.h.

◆ NTFS_ATTR_TYPE_SECURITY_DESCRIPTOR

#define NTFS_ATTR_TYPE_SECURITY_DESCRIPTOR   0x50

Definition at line 40 of file ntfs.h.

◆ NTFS_ATTR_TYPE_STANDARD_INFORMATION

#define NTFS_ATTR_TYPE_STANDARD_INFORMATION   0x10

Definition at line 36 of file ntfs.h.

◆ NTFS_ATTR_TYPE_VOLUME_INFORMATION

#define NTFS_ATTR_TYPE_VOLUME_INFORMATION   0x70

Definition at line 42 of file ntfs.h.

◆ NTFS_ATTR_TYPE_VOLUME_NAME

#define NTFS_ATTR_TYPE_VOLUME_NAME   0x60

Definition at line 41 of file ntfs.h.

◆ NTFS_FILE_ATTRDEF

#define NTFS_FILE_ATTRDEF   4

Definition at line 27 of file ntfs.h.

◆ NTFS_FILE_BADCLUS

#define NTFS_FILE_BADCLUS   8

Definition at line 31 of file ntfs.h.

◆ NTFS_FILE_BITMAP

#define NTFS_FILE_BITMAP   6

Definition at line 29 of file ntfs.h.

◆ NTFS_FILE_BOOT

#define NTFS_FILE_BOOT   7

Definition at line 30 of file ntfs.h.

◆ NTFS_FILE_EXTEND

#define NTFS_FILE_EXTEND   11

Definition at line 34 of file ntfs.h.

◆ NTFS_FILE_LOGFILE

#define NTFS_FILE_LOGFILE   2

Definition at line 25 of file ntfs.h.

◆ NTFS_FILE_MFT

#define NTFS_FILE_MFT   0

Definition at line 23 of file ntfs.h.

◆ NTFS_FILE_MFTMIRR

#define NTFS_FILE_MFTMIRR   1

Definition at line 24 of file ntfs.h.

◆ NTFS_FILE_NAME_DOS

#define NTFS_FILE_NAME_DOS   2

Definition at line 65 of file ntfs.h.

◆ NTFS_FILE_NAME_POSIX

#define NTFS_FILE_NAME_POSIX   0

Definition at line 63 of file ntfs.h.

◆ NTFS_FILE_NAME_WIN32

#define NTFS_FILE_NAME_WIN32   1

Definition at line 64 of file ntfs.h.

◆ NTFS_FILE_NAME_WIN32_AND_DOS

#define NTFS_FILE_NAME_WIN32_AND_DOS   3

Definition at line 66 of file ntfs.h.

◆ NTFS_FILE_QUOTA

#define NTFS_FILE_QUOTA   9

Definition at line 32 of file ntfs.h.

◆ NTFS_FILE_ROOT

#define NTFS_FILE_ROOT   5

Definition at line 28 of file ntfs.h.

◆ NTFS_FILE_UPCASE

#define NTFS_FILE_UPCASE   10

Definition at line 33 of file ntfs.h.

◆ NTFS_FILE_VOLUME

#define NTFS_FILE_VOLUME   3

Definition at line 26 of file ntfs.h.

◆ NTFS_INDEX_ENTRY_END

#define NTFS_INDEX_ENTRY_END   2

Definition at line 61 of file ntfs.h.

◆ NTFS_INDEX_ENTRY_NODE

#define NTFS_INDEX_ENTRY_NODE   1

Definition at line 60 of file ntfs.h.

◆ NTFS_LARGE_INDEX

#define NTFS_LARGE_INDEX   1

Definition at line 58 of file ntfs.h.

◆ NTFS_SMALL_INDEX

#define NTFS_SMALL_INDEX   0

Definition at line 57 of file ntfs.h.

Typedef Documentation

◆ PNTFS_ATTR_CONTEXT

◆ PNTFS_ATTR_LIST_ATTR

◆ PNTFS_ATTR_RECORD

◆ PNTFS_BOOTSECTOR

◆ PNTFS_FILE_HANDLE

◆ PNTFS_FILE_NAME_ATTR

◆ PNTFS_INDEX_ENTRY

◆ PNTFS_INDEX_HEADER

◆ PNTFS_INDEX_ROOT

◆ PNTFS_MFT_RECORD

◆ PNTFS_RECORD

◆ PNTFS_VOLUME_INFO

Definition at line 237 of file ntfs.h.

Function Documentation

◆ NtfsMount()

const DEVVTBL* NtfsMount ( ULONG  DeviceId)

Definition at line 875 of file ntfs.c.

876 {
879  ULONG Count;
881 
882  //
883  // Allocate data for volume information
884  //
886  if (!Volume)
887  return NULL;
889 
890  //
891  // Read the BootSector
892  //
893  Position.HighPart = 0;
894  Position.LowPart = 0;
895  Status = ArcSeek(DeviceId, &Position, SeekAbsolute);
896  if (Status != ESUCCESS)
897  {
899  return NULL;
900  }
901  Status = ArcRead(DeviceId, &Volume->BootSector, sizeof(Volume->BootSector), &Count);
902  if (Status != ESUCCESS || Count != sizeof(Volume->BootSector))
903  {
905  return NULL;
906  }
907 
908  //
909  // Check if BootSector is valid. If no, return early
910  //
911  if (!RtlEqualMemory(Volume->BootSector.SystemId, "NTFS", 4))
912  {
914  return NULL;
915  }
916 
917  //
918  // Calculate cluster size and MFT record size
919  //
920  Volume->ClusterSize = Volume->BootSector.SectorsPerCluster * Volume->BootSector.BytesPerSector;
921  if (Volume->BootSector.ClustersPerMftRecord > 0)
922  Volume->MftRecordSize = Volume->BootSector.ClustersPerMftRecord * Volume->ClusterSize;
923  else
924  Volume->MftRecordSize = 1 << (-Volume->BootSector.ClustersPerMftRecord);
925  if (Volume->BootSector.ClustersPerIndexRecord > 0)
926  Volume->IndexRecordSize = Volume->BootSector.ClustersPerIndexRecord * Volume->ClusterSize;
927  else
928  Volume->IndexRecordSize = 1 << (-Volume->BootSector.ClustersPerIndexRecord);
929 
930  TRACE("ClusterSize: 0x%x\n", Volume->ClusterSize);
931  TRACE("ClustersPerMftRecord: %d\n", Volume->BootSector.ClustersPerMftRecord);
932  TRACE("ClustersPerIndexRecord: %d\n", Volume->BootSector.ClustersPerIndexRecord);
933  TRACE("MftRecordSize: 0x%x\n", Volume->MftRecordSize);
934  TRACE("IndexRecordSize: 0x%x\n", Volume->IndexRecordSize);
935 
936  //
937  // Read MFT index
938  //
939  TRACE("Reading MFT index...\n");
940  Volume->MasterFileTable = FrLdrTempAlloc(Volume->MftRecordSize, TAG_NTFS_MFT);
941  if (!Volume->MasterFileTable)
942  {
944  return NULL;
945  }
946  Position.QuadPart = Volume->BootSector.MftLocation * Volume->ClusterSize;
947  Status = ArcSeek(DeviceId, &Position, SeekAbsolute);
948  if (Status != ESUCCESS)
949  {
950  FileSystemError("Failed to seek to Master File Table record.");
951  FrLdrTempFree(Volume->MasterFileTable, TAG_NTFS_MFT);
953  return NULL;
954  }
955  Status = ArcRead(DeviceId, Volume->MasterFileTable, Volume->MftRecordSize, &Count);
956  if (Status != ESUCCESS || Count != Volume->MftRecordSize)
957  {
958  FileSystemError("Failed to read the Master File Table record.");
959  FrLdrTempFree(Volume->MasterFileTable, TAG_NTFS_MFT);
961  return NULL;
962  }
963 
964  //
965  // Keep room to read partial sectors
966  //
967  Volume->TemporarySector = FrLdrTempAlloc(Volume->BootSector.BytesPerSector, TAG_NTFS_DATA);
968  if (!Volume->TemporarySector)
969  {
970  FileSystemError("Failed to allocate memory.");
971  FrLdrTempFree(Volume->MasterFileTable, TAG_NTFS_MFT);
973  return NULL;
974  }
975 
976  //
977  // Keep device id
978  //
979  Volume->DeviceId = DeviceId;
980 
981  //
982  // Search DATA attribute
983  //
984  TRACE("Searching for DATA attribute...\n");
985  Volume->MFTContext = NtfsFindAttribute(Volume, Volume->MasterFileTable, NTFS_ATTR_TYPE_DATA, L"");
986  if (!Volume->MFTContext)
987  {
988  FileSystemError("Can't find data attribute for Master File Table.");
989  FrLdrTempFree(Volume->MasterFileTable, TAG_NTFS_MFT);
991  return NULL;
992  }
993 
994  //
995  // Remember NTFS volume information
996  //
997  NtfsVolumes[DeviceId] = Volume;
998 
999  //
1000  // Return success
1001  //
1002  return &NtfsFuncTable;
1003 }
Definition: arc.h:32
static COORD Position
Definition: mouse.c:34
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
ULONG ARC_STATUS
Definition: arc.h:4
#define NTFS_ATTR_TYPE_DATA
Definition: ntfs.h:43
VOID FileSystemError(PCSTR ErrorString)
Definition: fs.c:260
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:177
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
NTSYSAPI ULONG NTAPI RtlEqualMemory(CONST VOID *Source1, CONST VOID *Source2, ULONG Length)
static PNTFS_ATTR_CONTEXT NtfsFindAttribute(PNTFS_VOLUME_INFO Volume, PNTFS_MFT_RECORD MftRecord, ULONG Type, const WCHAR *Name)
Definition: ntfs.c:443
#define TAG_NTFS_VOLUME
Definition: ntfs.c:37
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:237
static const WCHAR L[]
Definition: oid.c:1250
PNTFS_VOLUME_INFO NtfsVolumes[MAX_FDS]
Definition: ntfs.c:55
ARC_STATUS ArcSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
Definition: fs.c:244
Status
Definition: gdiplustypes.h:24
#define TAG_NTFS_DATA
Definition: ntfs.c:38
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define TAG_NTFS_MFT
Definition: ntfs.c:33
const DEVVTBL NtfsFuncTable
Definition: ntfs.c:865
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:186

Referenced by ArcOpen().