ReactOS 0.4.15-dev-7788-g1ad9096
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(), GetHarddiskInformation(), and UefiDiskOpen().

◆ LoadBootDeviceDriver()

ULONG LoadBootDeviceDriver ( VOID  )

Definition at line 1635 of file scsiport.c.

1636{
1637 PIMAGE_NT_HEADERS NtHeaders;
1639 PIMAGE_IMPORT_DESCRIPTOR ImportTable;
1640 ULONG ImportTableSize;
1641 PLDR_DATA_TABLE_ENTRY BootDdDTE, FreeldrDTE;
1642 CHAR NtBootDdPath[MAX_PATH];
1643 PVOID ImageBase = NULL;
1646
1647 // FIXME: Must be done *INSIDE* the HAL!
1648#ifdef _M_IX86
1651#endif
1652
1653 /* Initialize the loaded module list */
1655
1656 /* Create full ntbootdd.sys path */
1657 strcpy(NtBootDdPath, FrLdrBootPath);
1658 strcat(NtBootDdPath, "\\NTBOOTDD.SYS");
1659
1660 /* Load file */
1661 Success = PeLdrLoadImage(NtBootDdPath, LoaderBootDriver, &ImageBase);
1662 if (!Success)
1663 {
1664 /* That's OK, file simply doesn't exist */
1665 return ESUCCESS;
1666 }
1667
1668 /* Allocate a DTE for ntbootdd */
1670 "NTBOOTDD.SYS", ImageBase, &BootDdDTE);
1671 if (!Success)
1672 {
1673 /* Cleanup and bail out */
1674 MmFreeMemory(ImageBase);
1675 return EIO;
1676 }
1677
1678 /* Add the PE part of freeldr.sys to the list of loaded executables, it
1679 contains ScsiPort* exports, imported by ntbootdd.sys */
1681 "FREELDR.SYS", &__ImageBase, &FreeldrDTE);
1682 if (!Success)
1683 {
1684 /* Cleanup and bail out */
1685 PeLdrFreeDataTableEntry(BootDdDTE);
1686 MmFreeMemory(ImageBase);
1687 return EIO;
1688 }
1689
1690 /* Fix imports */
1692 if (!Success)
1693 {
1694 /* Cleanup and bail out */
1695 PeLdrFreeDataTableEntry(FreeldrDTE);
1696 PeLdrFreeDataTableEntry(BootDdDTE);
1697 MmFreeMemory(ImageBase);
1698 return EIO;
1699 }
1700
1701 /* Now unlink the DTEs, they won't be valid later */
1702 RemoveEntryList(&BootDdDTE->InLoadOrderLinks);
1703 RemoveEntryList(&FreeldrDTE->InLoadOrderLinks);
1704
1705 /* Change imports to PA */
1707 TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize);
1708 for (;(ImportTable->Name != 0) && (ImportTable->FirstThunk != 0);ImportTable++)
1709 {
1710 PIMAGE_THUNK_DATA ThunkData = (PIMAGE_THUNK_DATA)VaToPa(RVA(BootDdDTE->DllBase, ImportTable->FirstThunk));
1711
1712 while (((PIMAGE_THUNK_DATA)ThunkData)->u1.AddressOfData != 0)
1713 {
1714 ThunkData->u1.Function = (ULONG_PTR)VaToPa((PVOID)ThunkData->u1.Function);
1715 ThunkData++;
1716 }
1717 }
1718
1719 /* Relocate image to PA */
1720 NtHeaders = RtlImageNtHeader(VaToPa(BootDdDTE->DllBase));
1721 if (!NtHeaders)
1722 return EIO;
1724 NtHeaders->OptionalHeader.ImageBase - (ULONG_PTR)BootDdDTE->DllBase,
1725 "FreeLdr",
1726 TRUE,
1727 TRUE, /* In case of conflict still return success */
1728 FALSE);
1729 if (!Success)
1730 return EIO;
1731
1732 /* Call the entrypoint */
1733 EntryPoint = VaToPa(BootDdDTE->EntryPoint);
1734 (*EntryPoint)(NULL, NULL);
1735
1736 return ESUCCESS;
1737}
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:444
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
ULONG NTAPI LdrRelocateImageWithBias(_In_ PVOID BaseAddress, _In_ LONGLONG AdditionalBias, _In_opt_ PCSTR LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid)
Definition: image.c:474
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 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
BOOLEAN PeLdrLoadImage(_In_ PCSTR FilePath, _In_ TYPE_OF_MEMORY MemoryType, _Out_ PVOID *ImageBasePA)
Loads the specified image from the file.
Definition: peloader.c:740
@ ESUCCESS
Definition: arc.h:32
@ LoaderBootDriver
Definition: arc.h:185
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
union _IMAGE_THUNK_DATA32::@2129 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

◆ DiskReadBufferSize

SIZE_T DiskReadBufferSize
extern

◆ FrLdrBootPath