ReactOS  0.4.14-dev-593-g1793dcc
disk.h File Reference
#include <reactos/rosioctl.h>
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for disk.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _GEOMETRY
 
struct  _EXTENDED_GEOMETRY
 
struct  _PARTITION_TABLE_ENTRY
 
struct  _MASTER_BOOT_RECORD
 

Macros

#define PARTITION_ENTRY_UNUSED   0x00
 
#define PARTITION_FAT_12   0x01
 
#define PARTITION_XENIX_1   0x02
 
#define PARTITION_XENIX_2   0x03
 
#define PARTITION_FAT_16   0x04
 
#define PARTITION_EXTENDED   0x05
 
#define PARTITION_HUGE   0x06
 
#define PARTITION_IFS   0x07
 
#define PARTITION_OS2BOOTMGR   0x0A
 
#define PARTITION_FAT32   0x0B
 
#define PARTITION_FAT32_XINT13   0x0C
 
#define PARTITION_XINT13   0x0E
 
#define PARTITION_XINT13_EXTENDED   0x0F
 
#define PARTITION_NTFS   0x17
 
#define PARTITION_PREP   0x41
 
#define PARTITION_LDM   0x42
 
#define PARTITION_UNIX   0x63
 
#define VALID_NTFT   0xC0
 
#define PARTITION_NTFT   0x80
 
#define PARTITION_GPT   0xEE
 

Typedefs

typedef struct _GEOMETRY GEOMETRY
 
typedef struct _GEOMETRYPGEOMETRY
 
typedef struct _EXTENDED_GEOMETRY EXTENDED_GEOMETRY
 
typedef struct _EXTENDED_GEOMETRYPEXTENDED_GEOMETRY
 
typedef struct _PARTITION_TABLE_ENTRY PARTITION_TABLE_ENTRY
 
typedef struct _PARTITION_TABLE_ENTRYPPARTITION_TABLE_ENTRY
 
typedef struct _MASTER_BOOT_RECORD MASTER_BOOT_RECORD
 
typedef struct _MASTER_BOOT_RECORDPMASTER_BOOT_RECORD
 

Functions

VOID DiskDetectPartitionType (IN UCHAR DriveNumber)
 
BOOLEAN DiskGetBootPartitionEntry (IN UCHAR DriveNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry, OUT PULONG BootPartition)
 
BOOLEAN DiskGetPartitionEntry (IN UCHAR DriveNumber, IN ULONG PartitionNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
 
ULONG LoadBootDeviceDriver (VOID)
 

Variables

PVOID DiskReadBuffer
 
SIZE_T DiskReadBufferSize
 
CCHAR FrLdrBootPath [MAX_PATH]
 

Macro Definition Documentation

◆ PARTITION_ENTRY_UNUSED

#define PARTITION_ENTRY_UNUSED   0x00

Definition at line 86 of file disk.h.

◆ PARTITION_EXTENDED

#define PARTITION_EXTENDED   0x05

Definition at line 91 of file disk.h.

◆ PARTITION_FAT32

#define PARTITION_FAT32   0x0B

Definition at line 95 of file disk.h.

◆ PARTITION_FAT32_XINT13

#define PARTITION_FAT32_XINT13   0x0C

Definition at line 96 of file disk.h.

◆ PARTITION_FAT_12

#define PARTITION_FAT_12   0x01

Definition at line 87 of file disk.h.

◆ PARTITION_FAT_16

#define PARTITION_FAT_16   0x04

Definition at line 90 of file disk.h.

◆ PARTITION_GPT

#define PARTITION_GPT   0xEE

Definition at line 105 of file disk.h.

◆ PARTITION_HUGE

#define PARTITION_HUGE   0x06

Definition at line 92 of file disk.h.

◆ PARTITION_IFS

#define PARTITION_IFS   0x07

Definition at line 93 of file disk.h.

◆ PARTITION_LDM

#define PARTITION_LDM   0x42

Definition at line 101 of file disk.h.

◆ PARTITION_NTFS

#define PARTITION_NTFS   0x17

Definition at line 99 of file disk.h.

◆ PARTITION_NTFT

#define PARTITION_NTFT   0x80

Definition at line 104 of file disk.h.

◆ PARTITION_OS2BOOTMGR

#define PARTITION_OS2BOOTMGR   0x0A

Definition at line 94 of file disk.h.

◆ PARTITION_PREP

#define PARTITION_PREP   0x41

Definition at line 100 of file disk.h.

◆ PARTITION_UNIX

#define PARTITION_UNIX   0x63

Definition at line 102 of file disk.h.

◆ PARTITION_XENIX_1

#define PARTITION_XENIX_1   0x02

Definition at line 88 of file disk.h.

◆ PARTITION_XENIX_2

#define PARTITION_XENIX_2   0x03

Definition at line 89 of file disk.h.

◆ PARTITION_XINT13

#define PARTITION_XINT13   0x0E

Definition at line 97 of file disk.h.

◆ PARTITION_XINT13_EXTENDED

#define PARTITION_XINT13_EXTENDED   0x0F

Definition at line 98 of file disk.h.

◆ VALID_NTFT

#define VALID_NTFT   0xC0

Definition at line 103 of file disk.h.

Typedef Documentation

◆ EXTENDED_GEOMETRY

◆ GEOMETRY

◆ MASTER_BOOT_RECORD

◆ PARTITION_TABLE_ENTRY

◆ PEXTENDED_GEOMETRY

◆ PGEOMETRY

◆ PMASTER_BOOT_RECORD

◆ PPARTITION_TABLE_ENTRY

Function Documentation

◆ DiskDetectPartitionType()

VOID DiskDetectPartitionType ( IN UCHAR  DriveNumber)

Definition at line 314 of file partition.c.

316 {
317  MASTER_BOOT_RECORD MasterBootRecord;
318  ULONG Index;
319  ULONG PartitionCount = 0;
320  PPARTITION_TABLE_ENTRY ThisPartitionTableEntry;
321  BOOLEAN GPTProtect = FALSE;
322  PARTITION_TABLE_ENTRY PartitionTableEntry;
323 
324  /* Probe for Master Boot Record */
325  if (DiskReadBootRecord(DriveNumber, 0, &MasterBootRecord))
326  {
327  DiskPartitionType[DriveNumber] = PARTITION_STYLE_MBR;
328 
329  /* Check for GUID Partition Table */
330  for (Index = 0; Index < 4; Index++)
331  {
332  ThisPartitionTableEntry = &MasterBootRecord.PartitionTable[Index];
333 
334  if (ThisPartitionTableEntry->SystemIndicator != PARTITION_ENTRY_UNUSED)
335  {
336  PartitionCount++;
337 
338  if (Index == 0 && ThisPartitionTableEntry->SystemIndicator == PARTITION_GPT)
339  {
340  GPTProtect = TRUE;
341  }
342  }
343  }
344 
345  if (PartitionCount == 1 && GPTProtect)
346  {
347  DiskPartitionType[DriveNumber] = PARTITION_STYLE_GPT;
348  }
349  TRACE("Drive 0x%X partition type %s\n", DriveNumber, DiskPartitionType[DriveNumber] == PARTITION_STYLE_MBR ? "MBR" : "GPT");
350  return;
351  }
352 
353  /* Probe for Xbox-BRFR partitioning */
354  if (DiskGetBrfrPartitionEntry(DriveNumber, FATX_DATA_PARTITION, &PartitionTableEntry))
355  {
356  DiskPartitionType[DriveNumber] = PARTITION_STYLE_BRFR;
357  TRACE("Drive 0x%X partition type Xbox-BRFR\n", DriveNumber);
358  return;
359  }
360 
361  /* Failed to detect partitions, assume partitionless disk */
362  DiskPartitionType[DriveNumber] = PARTITION_STYLE_RAW;
363  TRACE("Drive 0x%X partition type unknown\n", DriveNumber);
364 }
Definition: disk.h:53
#define TRUE
Definition: types.h:120
UCHAR SystemIndicator
Definition: disk.h:60
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
unsigned char BOOLEAN
static PARTITION_STYLE DiskPartitionType[MaxDriveNumber+1]
Definition: partition.c:27
static BOOLEAN DiskReadBootRecord(IN UCHAR DriveNumber, IN ULONGLONG LogicalSectorNumber, OUT PMASTER_BOOT_RECORD BootRecord)
Definition: partition.c:52
#define TRACE(s)
Definition: solgame.cpp:4
static const UCHAR Index[8]
Definition: usbohci.c:18
Definition: parttest.c:75
static BOOLEAN DiskGetBrfrPartitionEntry(IN UCHAR DriveNumber, IN ULONG PartitionNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
Definition: partition.c:285
#define FATX_DATA_PARTITION
Definition: partition.c:34
unsigned int ULONG
Definition: retypes.h:1
PARTITION_TABLE_ENTRY PartitionTable[4]
Definition: parttest.c:92
#define PARTITION_GPT
Definition: disk.h:105

Referenced by GetHarddiskInformation().

◆ DiskGetBootPartitionEntry()

BOOLEAN DiskGetBootPartitionEntry ( IN UCHAR  DriveNumber,
OUT PPARTITION_TABLE_ENTRY  PartitionTableEntry,
OUT PULONG  BootPartition 
)

Definition at line 367 of file partition.c.

371 {
372  switch (DiskPartitionType[DriveNumber])
373  {
374  case PARTITION_STYLE_MBR:
375  {
376  return DiskGetActivePartitionEntry(DriveNumber, PartitionTableEntry, BootPartition);
377  }
378  case PARTITION_STYLE_GPT:
379  {
380  FIXME("DiskGetBootPartitionEntry() unimplemented for GPT\n");
381  return FALSE;
382  }
383  case PARTITION_STYLE_RAW:
384  {
385  FIXME("DiskGetBootPartitionEntry() unimplemented for RAW\n");
386  return FALSE;
387  }
388  case PARTITION_STYLE_BRFR:
389  {
390  if (DiskGetBrfrPartitionEntry(DriveNumber, FATX_DATA_PARTITION, PartitionTableEntry))
391  {
392  *BootPartition = FATX_DATA_PARTITION;
393  return TRUE;
394  }
395  return FALSE;
396  }
397  default:
398  {
399  ERR("Drive 0x%X partition type = %d, should not happen!\n", DriveNumber, DiskPartitionType[DriveNumber]);
400  ASSERT(FALSE);
401  }
402  }
403  return FALSE;
404 }
#define TRUE
Definition: types.h:120
#define FIXME(fmt,...)
Definition: debug.h:110
static PARTITION_STYLE DiskPartitionType[MaxDriveNumber+1]
Definition: partition.c:27
static BOOLEAN DiskGetBrfrPartitionEntry(IN UCHAR DriveNumber, IN ULONG PartitionNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
Definition: partition.c:285
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define FATX_DATA_PARTITION
Definition: partition.c:34
static BOOLEAN DiskGetActivePartitionEntry(IN UCHAR DriveNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry, OUT PULONG ActivePartition)
Definition: partition.c:134
#define ERR(fmt,...)
Definition: debug.h:109

Referenced by DiskGetBootPath().

◆ DiskGetPartitionEntry()

BOOLEAN DiskGetPartitionEntry ( IN UCHAR  DriveNumber,
IN ULONG  PartitionNumber,
OUT PPARTITION_TABLE_ENTRY  PartitionTableEntry 
)

Definition at line 407 of file partition.c.

411 {
412  switch (DiskPartitionType[DriveNumber])
413  {
414  case PARTITION_STYLE_MBR:
415  {
416  return DiskGetMbrPartitionEntry(DriveNumber, PartitionNumber, PartitionTableEntry);
417  }
418  case PARTITION_STYLE_GPT:
419  {
420  FIXME("DiskGetPartitionEntry() unimplemented for GPT\n");
421  return FALSE;
422  }
423  case PARTITION_STYLE_RAW:
424  {
425  FIXME("DiskGetPartitionEntry() unimplemented for RAW\n");
426  return FALSE;
427  }
428  case PARTITION_STYLE_BRFR:
429  {
430  return DiskGetBrfrPartitionEntry(DriveNumber, PartitionNumber, PartitionTableEntry);
431  }
432  default:
433  {
434  ERR("Drive 0x%X partition type = %d, should not happen!\n", DriveNumber, DiskPartitionType[DriveNumber]);
435  ASSERT(FALSE);
436  }
437  }
438  return FALSE;
439 }
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
static BOOLEAN DiskGetMbrPartitionEntry(IN UCHAR DriveNumber, IN ULONG PartitionNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
Definition: partition.c:194
#define FIXME(fmt,...)
Definition: debug.h:110
static PARTITION_STYLE DiskPartitionType[MaxDriveNumber+1]
Definition: partition.c:27
static BOOLEAN DiskGetBrfrPartitionEntry(IN UCHAR DriveNumber, IN ULONG PartitionNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
Definition: partition.c:285
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ERR(fmt,...)
Definition: debug.h:109

Referenced by DiskOpen(), and GetHarddiskInformation().

◆ LoadBootDeviceDriver()

ULONG LoadBootDeviceDriver ( VOID  )

Definition at line 1619 of file scsiport.c.

1620 {
1621  PIMAGE_NT_HEADERS NtHeaders;
1623  PIMAGE_IMPORT_DESCRIPTOR ImportTable;
1624  ULONG ImportTableSize;
1625  PLDR_DATA_TABLE_ENTRY BootDdDTE, FreeldrDTE;
1626  CHAR NtBootDdPath[MAX_PATH];
1627  PVOID ImageBase = NULL;
1628  ULONG (NTAPI *EntryPoint)(IN PVOID DriverObject, IN PVOID RegistryPath);
1629  BOOLEAN Success;
1630 
1631  // FIXME: Must be done *INSIDE* the HAL!
1632 #ifdef _M_IX86
1635 #endif
1636 
1637  /* Initialize the loaded module list */
1639 
1640  /* Create full ntbootdd.sys path */
1641  strcpy(NtBootDdPath, FrLdrBootPath);
1642  strcat(NtBootDdPath, "\\NTBOOTDD.SYS");
1643 
1644  /* Load file */
1645  Success = PeLdrLoadImage(NtBootDdPath, LoaderBootDriver, &ImageBase);
1646  if (!Success)
1647  {
1648  /* That's OK. File simply doesn't exist */
1649  return ESUCCESS;
1650  }
1651 
1652  /* Allocate a DTE for ntbootdd */
1654  "NTBOOTDD.SYS", ImageBase, &BootDdDTE);
1655  if (!Success)
1656  return EIO;
1657 
1658  /* Add the PE part of freeldr.sys to the list of loaded executables, it
1659  contains ScsiPort* exports, imported by ntbootdd.sys */
1661  "FREELDR.SYS", &__ImageBase, &FreeldrDTE);
1662  if (!Success)
1663  {
1664  RemoveEntryList(&BootDdDTE->InLoadOrderLinks);
1665  return EIO;
1666  }
1667 
1668  /* Fix imports */
1670 
1671  /* Now unlinkt the DTEs, they won't be valid later */
1672  RemoveEntryList(&BootDdDTE->InLoadOrderLinks);
1673  RemoveEntryList(&FreeldrDTE->InLoadOrderLinks);
1674 
1675  if (!Success)
1676  return EIO;
1677 
1678  /* Change imports to PA */
1680  TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize);
1681  for (;(ImportTable->Name != 0) && (ImportTable->FirstThunk != 0);ImportTable++)
1682  {
1683  PIMAGE_THUNK_DATA ThunkData = (PIMAGE_THUNK_DATA)VaToPa(RVA(BootDdDTE->DllBase, ImportTable->FirstThunk));
1684 
1685  while (((PIMAGE_THUNK_DATA)ThunkData)->u1.AddressOfData != 0)
1686  {
1687  ThunkData->u1.Function = (ULONG)VaToPa((PVOID)ThunkData->u1.Function);
1688  ThunkData++;
1689  }
1690  }
1691 
1692  /* Relocate image to PA */
1693  NtHeaders = RtlImageNtHeader(VaToPa(BootDdDTE->DllBase));
1694  if (!NtHeaders)
1695  return EIO;
1697  NtHeaders->OptionalHeader.ImageBase - (ULONG_PTR)BootDdDTE->DllBase,
1698  "FreeLdr",
1699  TRUE,
1700  TRUE, /* in case of conflict still return success */
1701  FALSE);
1702  if (!Success)
1703  return EIO;
1704 
1705  /* Call the entrypoint */
1706  EntryPoint = VaToPa(BootDdDTE->EntryPoint);
1707  (*EntryPoint)(NULL, NULL);
1708 
1709  return ESUCCESS;
1710 }
BOOLEAN PeLdrScanImportDescriptorTable(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH DirectoryPath, IN PLDR_DATA_TABLE_ENTRY ScanDTE)
Definition: peloader.c:509
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
BOOLEAN PeLdrLoadImage(IN PCHAR FileName, IN TYPE_OF_MEMORY MemoryType, OUT PVOID *ImageBasePA)
Definition: peloader.c:701
VOID NTAPI HalpInitBusHandler(VOID)
Definition: bushndlr.c:420
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
Definition: arc.h:32
char CHAR
Definition: xmlstorage.h:175
struct _IMAGE_IMPORT_DESCRIPTOR * PIMAGE_IMPORT_DESCRIPTOR
GLdouble u1
Definition: glext.h:8308
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
PVOID DllBase
Definition: btrfs_drv.h:1857
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PVOID EntryPoint
Definition: ntddk_ex.h:203
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define MAX_PATH
Definition: compat.h:26
#define RtlImageDirectoryEntryToData
Definition: compat.h:468
union _IMAGE_THUNK_DATA32::@2074 u1
Definition: btrfs_drv.h:1853
Definition: typedefs.h:117
LIST_ENTRY InLoadOrderLinks
Definition: ldrtypes.h:138
#define RVA(m, b)
Definition: freeldr.h:24
NTSYSAPI ULONG NTAPI LdrRelocateImageWithBias(_In_ PVOID NewAddress, _In_ LONGLONG AdditionalBias, _In_ PCCH LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid)
VOID NTAPI HalpInitializePciStubs(VOID)
Definition: pci.c:674
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
Definition: arc.h:40
#define RtlImageNtHeader
Definition: compat.h:465
#define IMAGE_DIRECTORY_ENTRY_IMPORT
Definition: pedump.c:260
char __ImageBase
Definition: mstscax.cpp:17
#define BOOLEAN
Definition: pedump.c:73
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
CHAR FrLdrBootPath[MAX_PATH]
Definition: mach.c:34
BOOLEAN PeLdrAllocateDataTableEntry(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH BaseDllName, IN PCCH FullDllName, IN PVOID BasePA, OUT PLDR_DATA_TABLE_ENTRY *NewEntry)
Definition: peloader.c:585
LIST_ENTRY * ModuleListHead
Definition: kdpacket.c:23
PIMAGE_THUNK_DATA32 PIMAGE_THUNK_DATA
Definition: ntimage.h:566

Referenced by RunLoader().

Variable Documentation

◆ DiskReadBuffer

PVOID DiskReadBuffer

◆ DiskReadBufferSize

SIZE_T DiskReadBufferSize

Definition at line 47 of file hwdisk.c.

Referenced by DiskOpen(), DiskRead(), EnumerateHarddisks(), and PcMemFinalizeMemoryMap().

◆ FrLdrBootPath