ReactOS 0.4.15-dev-5672-gf73ac17
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 {
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 {
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}
unsigned char BOOLEAN
static BOOLEAN DiskReadBootRecord(IN UCHAR DriveNumber, IN ULONGLONG LogicalSectorNumber, OUT PMASTER_BOOT_RECORD BootRecord)
Definition: partition.c:52
#define FATX_DATA_PARTITION
Definition: partition.c:34
static BOOLEAN DiskGetBrfrPartitionEntry(IN UCHAR DriveNumber, IN ULONG PartitionNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
Definition: partition.c:285
static PARTITION_STYLE DiskPartitionType[MaxDriveNumber+1]
Definition: partition.c:27
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
#define PARTITION_GPT
Definition: disk.h:105
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
@ PARTITION_STYLE_GPT
Definition: imports.h:202
@ PARTITION_STYLE_MBR
Definition: imports.h:201
#define TRACE(s)
Definition: solgame.cpp:4
PARTITION_TABLE_ENTRY PartitionTable[4]
Definition: parttest.c:92
Definition: parttest.c:75
Definition: disk.h:54
UCHAR SystemIndicator
Definition: disk.h:60
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFCOLLECTION _In_ ULONG Index

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 {
375 {
376 return DiskGetActivePartitionEntry(DriveNumber, PartitionTableEntry, BootPartition);
377 }
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}
static BOOLEAN DiskGetActivePartitionEntry(IN UCHAR DriveNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry, OUT PULONG ActivePartition)
Definition: partition.c:134
#define FIXME(fmt,...)
Definition: debug.h:111
#define ERR(fmt,...)
Definition: debug.h:110
#define ASSERT(a)
Definition: mode.c:44

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 {
415 {
416 return DiskGetMbrPartitionEntry(DriveNumber, PartitionNumber, PartitionTableEntry);
417 }
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}
static BOOLEAN DiskGetMbrPartitionEntry(IN UCHAR DriveNumber, IN ULONG PartitionNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
Definition: partition.c:194
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2061

Referenced by DiskOpen(), and GetHarddiskInformation().

◆ LoadBootDeviceDriver()

ULONG LoadBootDeviceDriver ( VOID  )

Definition at line 1626 of file scsiport.c.

1627{
1628 PIMAGE_NT_HEADERS NtHeaders;
1630 PIMAGE_IMPORT_DESCRIPTOR ImportTable;
1631 ULONG ImportTableSize;
1632 PLDR_DATA_TABLE_ENTRY BootDdDTE, FreeldrDTE;
1633 CHAR NtBootDdPath[MAX_PATH];
1634 PVOID ImageBase = NULL;
1637
1638 // FIXME: Must be done *INSIDE* the HAL!
1639#ifdef _M_IX86
1642#endif
1643
1644 /* Initialize the loaded module list */
1646
1647 /* Create full ntbootdd.sys path */
1648 strcpy(NtBootDdPath, FrLdrBootPath);
1649 strcat(NtBootDdPath, "\\NTBOOTDD.SYS");
1650
1651 /* Load file */
1652 Success = PeLdrLoadImage(NtBootDdPath, LoaderBootDriver, &ImageBase);
1653 if (!Success)
1654 {
1655 /* That's OK, file simply doesn't exist */
1656 return ESUCCESS;
1657 }
1658
1659 /* Allocate a DTE for ntbootdd */
1661 "NTBOOTDD.SYS", ImageBase, &BootDdDTE);
1662 if (!Success)
1663 {
1664 /* Cleanup and bail out */
1665 MmFreeMemory(ImageBase);
1666 return EIO;
1667 }
1668
1669 /* Add the PE part of freeldr.sys to the list of loaded executables, it
1670 contains ScsiPort* exports, imported by ntbootdd.sys */
1672 "FREELDR.SYS", &__ImageBase, &FreeldrDTE);
1673 if (!Success)
1674 {
1675 /* Cleanup and bail out */
1676 PeLdrFreeDataTableEntry(BootDdDTE);
1677 MmFreeMemory(ImageBase);
1678 return EIO;
1679 }
1680
1681 /* Fix imports */
1683 if (!Success)
1684 {
1685 /* Cleanup and bail out */
1686 PeLdrFreeDataTableEntry(FreeldrDTE);
1687 PeLdrFreeDataTableEntry(BootDdDTE);
1688 MmFreeMemory(ImageBase);
1689 return EIO;
1690 }
1691
1692 /* Now unlink the DTEs, they won't be valid later */
1693 RemoveEntryList(&BootDdDTE->InLoadOrderLinks);
1694 RemoveEntryList(&FreeldrDTE->InLoadOrderLinks);
1695
1696 /* Change imports to PA */
1698 TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize);
1699 for (;(ImportTable->Name != 0) && (ImportTable->FirstThunk != 0);ImportTable++)
1700 {
1701 PIMAGE_THUNK_DATA ThunkData = (PIMAGE_THUNK_DATA)VaToPa(RVA(BootDdDTE->DllBase, ImportTable->FirstThunk));
1702
1703 while (((PIMAGE_THUNK_DATA)ThunkData)->u1.AddressOfData != 0)
1704 {
1705 ThunkData->u1.Function = (ULONG)VaToPa((PVOID)ThunkData->u1.Function);
1706 ThunkData++;
1707 }
1708 }
1709
1710 /* Relocate image to PA */
1711 NtHeaders = RtlImageNtHeader(VaToPa(BootDdDTE->DllBase));
1712 if (!NtHeaders)
1713 return EIO;
1715 NtHeaders->OptionalHeader.ImageBase - (ULONG_PTR)BootDdDTE->DllBase,
1716 "FreeLdr",
1717 TRUE,
1718 TRUE, /* In case of conflict still return success */
1719 FALSE);
1720 if (!Success)
1721 return EIO;
1722
1723 /* Call the entrypoint */
1724 EntryPoint = VaToPa(BootDdDTE->EntryPoint);
1725 (*EntryPoint)(NULL, NULL);
1726
1727 return ESUCCESS;
1728}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define EIO
Definition: acclib.h:81
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char __ImageBase
VOID MmFreeMemory(PVOID MemoryPointer)
Definition: mm.c:215
VOID NTAPI HalpInitBusHandler(VOID)
Definition: bushndlr.c:420
VOID NTAPI HalpInitializePciStubs(VOID)
Definition: pcibus.c:1190
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
#define NULL
Definition: types.h:112
#define RtlImageDirectoryEntryToData
Definition: compat.h:809
#define RtlImageNtHeader
Definition: compat.h:806
#define MAX_PATH
Definition: compat.h:34
#define ULONG_PTR
Definition: config.h:101
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
@ Success
Definition: eventcreate.c:712
CCHAR FrLdrBootPath[MAX_PATH]
Definition: freeldr.c:39
#define RVA(m, b)
Definition: freeldr.h:24
GLdouble u1
Definition: glext.h:8308
LIST_ENTRY * ModuleListHead
Definition: kdpacket.c:23
NTSYSAPI ULONG NTAPI LdrRelocateImageWithBias(_In_ PVOID NewAddress, _In_ LONGLONG AdditionalBias, _In_ PCCH LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid)
struct _IMAGE_IMPORT_DESCRIPTOR * PIMAGE_IMPORT_DESCRIPTOR
PIMAGE_THUNK_DATA32 PIMAGE_THUNK_DATA
Definition: ntimage.h:566
#define IMAGE_DIRECTORY_ENTRY_IMPORT
Definition: pedump.c:260
#define BOOLEAN
Definition: pedump.c:73
BOOLEAN PeLdrScanImportDescriptorTable(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH DirectoryPath, IN PLDR_DATA_TABLE_ENTRY ScanDTE)
Definition: peloader.c:522
VOID PeLdrFreeDataTableEntry(_In_ PLDR_DATA_TABLE_ENTRY Entry)
Definition: peloader.c:715
BOOLEAN PeLdrLoadImage(IN PCHAR FileName, IN TYPE_OF_MEMORY MemoryType, OUT PVOID *ImageBasePA)
Definition: peloader.c:736
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:598
@ ESUCCESS
Definition: arc.h:32
@ LoaderBootDriver
Definition: arc.h:138
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
union _IMAGE_THUNK_DATA32::@2107 u1
Definition: btrfs_drv.h:1876
PVOID EntryPoint
Definition: ntddk_ex.h:203
LIST_ENTRY InLoadOrderLinks
Definition: ldrtypes.h:138
PVOID DllBase
Definition: btrfs_drv.h:1880
Definition: typedefs.h:120
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
char CHAR
Definition: xmlstorage.h:175

Referenced by RunLoader().

Variable Documentation

◆ DiskReadBuffer

PVOID DiskReadBuffer
extern

◆ DiskReadBufferSize

SIZE_T DiskReadBufferSize
extern

Definition at line 47 of file hwdisk.c.

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

◆ FrLdrBootPath