ReactOS  0.4.13-dev-66-gc714b7f
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
 

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
 
typedef BOOLEAN(* DISK_GET_PARTITION_ENTRY) (UCHAR DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry)
 

Functions

VOID DiskReportError (BOOLEAN bError)
 
VOID DiskError (PCSTR ErrorString, ULONG ErrorCode)
 
PCSTR DiskGetErrorCodeString (ULONG ErrorCode)
 
BOOLEAN DiskIsDriveRemovable (UCHAR DriveNumber)
 
BOOLEAN DiskGetBootPath (OUT PCHAR BootPath, IN ULONG Size)
 
BOOLEAN DiskGetActivePartitionEntry (UCHAR DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry, ULONG *ActivePartition)
 
BOOLEAN DiskGetMbrPartitionEntry (UCHAR DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry)
 
BOOLEAN DiskGetFirstPartitionEntry (PMASTER_BOOT_RECORD MasterBootRecord, PPARTITION_TABLE_ENTRY PartitionTableEntry)
 
BOOLEAN DiskGetFirstExtendedPartitionEntry (PMASTER_BOOT_RECORD MasterBootRecord, PPARTITION_TABLE_ENTRY PartitionTableEntry)
 
BOOLEAN DiskReadBootRecord (UCHAR DriveNumber, ULONGLONG LogicalSectorNumber, PMASTER_BOOT_RECORD BootRecord)
 
ULONG LoadBootDeviceDriver (VOID)
 

Variables

UCHAR FrldrBootDrive
 
ULONG FrldrBootPartition
 
CHAR FrldrBootPath [MAX_PATH]
 
PVOID DiskReadBuffer
 
SIZE_T DiskReadBufferSize
 
DISK_GET_PARTITION_ENTRY DiskGetPartitionEntry
 

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_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

◆ DISK_GET_PARTITION_ENTRY

typedef BOOLEAN(* DISK_GET_PARTITION_ENTRY) (UCHAR DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry)

Definition at line 150 of file disk.h.

◆ EXTENDED_GEOMETRY

◆ GEOMETRY

◆ MASTER_BOOT_RECORD

◆ PARTITION_TABLE_ENTRY

◆ PEXTENDED_GEOMETRY

◆ PGEOMETRY

◆ PMASTER_BOOT_RECORD

◆ PPARTITION_TABLE_ENTRY

Function Documentation

◆ DiskError()

VOID DiskError ( PCSTR  ErrorString,
ULONG  ErrorCode 
)

Definition at line 38 of file disk.c.

39 {
40  CHAR ErrorCodeString[200];
41 
42  if (bReportError == FALSE)
43  return;
44 
45  sprintf(ErrorCodeString, "%s\n\nError Code: 0x%lx\nError: %s",
47 
48  TRACE("%s\n", ErrorCodeString);
49 
50  UiMessageBox(ErrorCodeString);
51 }
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4418
char CHAR
Definition: xmlstorage.h:175
PCSTR DiskGetErrorCodeString(ULONG ErrorCode)
Definition: disk.c:53
#define sprintf(buf, format,...)
Definition: sprintf.c:55
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:347
#define TRACE(s)
Definition: solgame.cpp:4
static BOOLEAN bReportError
Definition: disk.c:29

Referenced by PcDiskReadLogicalSectorsCHS().

◆ DiskGetActivePartitionEntry()

BOOLEAN DiskGetActivePartitionEntry ( UCHAR  DriveNumber,
PPARTITION_TABLE_ENTRY  PartitionTableEntry,
ULONG ActivePartition 
)

Definition at line 35 of file partition.c.

38 {
39  ULONG BootablePartitionCount = 0;
40  ULONG CurrentPartitionNumber;
41  ULONG Index;
42  MASTER_BOOT_RECORD MasterBootRecord;
43  PPARTITION_TABLE_ENTRY ThisPartitionTableEntry;
44 
45  *ActivePartition = 0;
46 
47  // Read master boot record
48  if (!DiskReadBootRecord(DriveNumber, 0, &MasterBootRecord))
49  {
50  return FALSE;
51  }
52 
53  CurrentPartitionNumber = 0;
54  for (Index=0; Index<4; Index++)
55  {
56  ThisPartitionTableEntry = &MasterBootRecord.PartitionTable[Index];
57 
58  if (ThisPartitionTableEntry->SystemIndicator != PARTITION_ENTRY_UNUSED &&
59  ThisPartitionTableEntry->SystemIndicator != PARTITION_EXTENDED &&
60  ThisPartitionTableEntry->SystemIndicator != PARTITION_XINT13_EXTENDED)
61  {
62  CurrentPartitionNumber++;
63 
64  // Test if this is the bootable partition
65  if (ThisPartitionTableEntry->BootIndicator == 0x80)
66  {
67  BootablePartitionCount++;
68  *ActivePartition = CurrentPartitionNumber;
69 
70  // Copy the partition table entry
71  RtlCopyMemory(PartitionTableEntry,
72  ThisPartitionTableEntry,
73  sizeof(PARTITION_TABLE_ENTRY));
74  }
75  }
76  }
77 
78  // Make sure there was only one bootable partition
79  if (BootablePartitionCount == 0)
80  {
81  ERR("No bootable (active) partitions found.\n");
82  return FALSE;
83  }
84  else if (BootablePartitionCount != 1)
85  {
86  ERR("Too many bootable (active) partitions found.\n");
87  return FALSE;
88  }
89 
90  return TRUE;
91 }
Definition: disk.h:53
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
UCHAR SystemIndicator
Definition: disk.h:60
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
#define PARTITION_EXTENDED
Definition: disk.h:91
static const UCHAR Index[8]
Definition: usbohci.c:18
Definition: parttest.c:75
UCHAR BootIndicator
Definition: disk.h:55
#define PARTITION_XINT13_EXTENDED
Definition: disk.h:98
#define ERR(fmt,...)
Definition: debug.h:109
BOOLEAN DiskReadBootRecord(UCHAR DriveNumber, ULONGLONG LogicalSectorNumber, PMASTER_BOOT_RECORD BootRecord)
Definition: partition.c:216
unsigned int ULONG
Definition: retypes.h:1
PARTITION_TABLE_ENTRY PartitionTable[4]
Definition: parttest.c:92

Referenced by DiskGetBootPath().

◆ DiskGetBootPath()

BOOLEAN DiskGetBootPath ( OUT PCHAR  BootPath,
IN ULONG  Size 
)

Definition at line 102 of file disk.c.

103 {
104  if (*FrldrBootPath)
105  goto Done;
106 
107  /* 0x49 is our magic ramdisk drive, so try to detect it first */
108  if (FrldrBootDrive == 0x49)
109  {
110  /* This is the ramdisk. See ArmDiskGetBootPath too... */
111  // sprintf(FrldrBootPath, "ramdisk(%u)", 0);
112  strcpy(FrldrBootPath, "ramdisk(0)");
113  }
114  else if (FrldrBootDrive < 0x80)
115  {
116  /* This is a floppy */
117  sprintf(FrldrBootPath, "multi(0)disk(0)fdisk(%u)", FrldrBootDrive);
118  }
119  else if (FrldrBootPartition == 0xFF)
120  {
121  /* Boot Partition 0xFF is the magic value that indicates booting from CD-ROM (see isoboot.S) */
122  sprintf(FrldrBootPath, "multi(0)disk(0)cdrom(%u)", FrldrBootDrive - 0x80);
123  }
124  else
125  {
126  ULONG BootPartition;
128 
129  /* This is a hard disk */
131  {
132  ERR("Invalid active partition information\n");
133  return FALSE;
134  }
135 
136  FrldrBootPartition = BootPartition;
137 
138  sprintf(FrldrBootPath, "multi(0)disk(0)rdisk(%u)partition(%lu)",
140  }
141 
142 Done:
143  /* Copy back the buffer */
144  if (Size < strlen(FrldrBootPath) + 1)
145  return FALSE;
147  return TRUE;
148 }
#define TRUE
Definition: types.h:120
BOOLEAN DiskGetActivePartitionEntry(UCHAR DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry, ULONG *ActivePartition)
Definition: partition.c:35
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define sprintf(buf, format,...)
Definition: sprintf.c:55
PARTITION_INFORMATION PartitionEntry[1]
Definition: ntdddisk.h:467
CHAR FrldrBootPath[MAX_PATH]
Definition: disk.c:27
Definition: parttest.c:75
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ULONG FrldrBootPartition
#define ERR(fmt,...)
Definition: debug.h:109
UCHAR FrldrBootDrive
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
char BootPath[0x100]
Definition: mach.c:35

Referenced by PcDiskGetBootPath(), and XboxMachInit().

◆ DiskGetErrorCodeString()

PCSTR DiskGetErrorCodeString ( ULONG  ErrorCode)

Definition at line 53 of file disk.c.

54 {
55  switch (ErrorCode)
56  {
57  case 0x00: return "no error";
58  case 0x01: return "bad command passed to driver";
59  case 0x02: return "address mark not found or bad sector";
60  case 0x03: return "diskette write protect error";
61  case 0x04: return "sector not found";
62  case 0x05: return "fixed disk reset failed";
63  case 0x06: return "diskette changed or removed";
64  case 0x07: return "bad fixed disk parameter table";
65  case 0x08: return "DMA overrun";
66  case 0x09: return "DMA access across 64k boundary";
67  case 0x0A: return "bad fixed disk sector flag";
68  case 0x0B: return "bad fixed disk cylinder";
69  case 0x0C: return "unsupported track/invalid media";
70  case 0x0D: return "invalid number of sectors on fixed disk format";
71  case 0x0E: return "fixed disk controlled data address mark detected";
72  case 0x0F: return "fixed disk DMA arbitration level out of range";
73  case 0x10: return "ECC/CRC error on disk read";
74  case 0x11: return "recoverable fixed disk data error, data fixed by ECC";
75  case 0x20: return "controller error (NEC for floppies)";
76  case 0x40: return "seek failure";
77  case 0x80: return "time out, drive not ready";
78  case 0xAA: return "fixed disk drive not ready";
79  case 0xBB: return "fixed disk undefined error";
80  case 0xCC: return "fixed disk write fault on selected drive";
81  case 0xE0: return "fixed disk status error/Error reg = 0";
82  case 0xFF: return "sense operation failed";
83 
84  default: return "unknown error code";
85  }
86 }
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4418

Referenced by DiskError().

◆ DiskGetFirstExtendedPartitionEntry()

BOOLEAN DiskGetFirstExtendedPartitionEntry ( PMASTER_BOOT_RECORD  MasterBootRecord,
PPARTITION_TABLE_ENTRY  PartitionTableEntry 
)

Definition at line 197 of file partition.c.

198 {
199  ULONG Index;
200 
201  for (Index=0; Index<4; Index++)
202  {
203  // Check the system indicator
204  // If it an extended partition then we're done
205  if ((MasterBootRecord->PartitionTable[Index].SystemIndicator == PARTITION_EXTENDED) ||
207  {
208  RtlCopyMemory(PartitionTableEntry, &MasterBootRecord->PartitionTable[Index], sizeof(PARTITION_TABLE_ENTRY));
209  return TRUE;
210  }
211  }
212 
213  return FALSE;
214 }
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
UCHAR SystemIndicator
Definition: parttest.c:80
#define PARTITION_EXTENDED
Definition: disk.h:91
static const UCHAR Index[8]
Definition: usbohci.c:18
Definition: parttest.c:75
PARTITION_TABLE_ENTRY PartitionTable[4]
Definition: disk.h:77
#define PARTITION_XINT13_EXTENDED
Definition: disk.h:98
unsigned int ULONG
Definition: retypes.h:1

Referenced by DiskGetMbrPartitionEntry().

◆ DiskGetFirstPartitionEntry()

BOOLEAN DiskGetFirstPartitionEntry ( PMASTER_BOOT_RECORD  MasterBootRecord,
PPARTITION_TABLE_ENTRY  PartitionTableEntry 
)

Definition at line 176 of file partition.c.

177 {
178  ULONG Index;
179 
180  for (Index=0; Index<4; Index++)
181  {
182  // Check the system indicator
183  // If it's not an extended or unused partition
184  // then we're done
185  if ((MasterBootRecord->PartitionTable[Index].SystemIndicator != PARTITION_ENTRY_UNUSED) &&
186  (MasterBootRecord->PartitionTable[Index].SystemIndicator != PARTITION_EXTENDED) &&
188  {
189  RtlCopyMemory(PartitionTableEntry, &MasterBootRecord->PartitionTable[Index], sizeof(PARTITION_TABLE_ENTRY));
190  return TRUE;
191  }
192  }
193 
194  return FALSE;
195 }
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
UCHAR SystemIndicator
Definition: parttest.c:80
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
#define PARTITION_EXTENDED
Definition: disk.h:91
static const UCHAR Index[8]
Definition: usbohci.c:18
Definition: parttest.c:75
PARTITION_TABLE_ENTRY PartitionTable[4]
Definition: disk.h:77
#define PARTITION_XINT13_EXTENDED
Definition: disk.h:98
unsigned int ULONG
Definition: retypes.h:1

Referenced by DiskGetMbrPartitionEntry().

◆ DiskGetMbrPartitionEntry()

BOOLEAN DiskGetMbrPartitionEntry ( UCHAR  DriveNumber,
ULONG  PartitionNumber,
PPARTITION_TABLE_ENTRY  PartitionTableEntry 
)

Definition at line 93 of file partition.c.

94 {
95  MASTER_BOOT_RECORD MasterBootRecord;
96  PARTITION_TABLE_ENTRY ExtendedPartitionTableEntry;
97  ULONG ExtendedPartitionNumber;
98  ULONG ExtendedPartitionOffset;
99  ULONG Index;
100  ULONG CurrentPartitionNumber;
101  PPARTITION_TABLE_ENTRY ThisPartitionTableEntry;
102 
103  // Read master boot record
104  if (!DiskReadBootRecord(DriveNumber, 0, &MasterBootRecord))
105  {
106  return FALSE;
107  }
108 
109  CurrentPartitionNumber = 0;
110  for (Index=0; Index<4; Index++)
111  {
112  ThisPartitionTableEntry = &MasterBootRecord.PartitionTable[Index];
113 
114  if (ThisPartitionTableEntry->SystemIndicator != PARTITION_ENTRY_UNUSED &&
115  ThisPartitionTableEntry->SystemIndicator != PARTITION_EXTENDED &&
116  ThisPartitionTableEntry->SystemIndicator != PARTITION_XINT13_EXTENDED)
117  {
118  CurrentPartitionNumber++;
119  }
120 
121  if (PartitionNumber == CurrentPartitionNumber)
122  {
123  RtlCopyMemory(PartitionTableEntry, ThisPartitionTableEntry, sizeof(PARTITION_TABLE_ENTRY));
124  return TRUE;
125  }
126  }
127 
128  // They want an extended partition entry so we will need
129  // to loop through all the extended partitions on the disk
130  // and return the one they want.
131 
132  ExtendedPartitionNumber = PartitionNumber - CurrentPartitionNumber - 1;
133 
134  // Set the initial relative starting sector to 0
135  // This is because extended partition starting
136  // sectors a numbered relative to their parent
137  ExtendedPartitionOffset = 0;
138 
139  for (Index=0; Index<=ExtendedPartitionNumber; Index++)
140  {
141  // Get the extended partition table entry
142  if (!DiskGetFirstExtendedPartitionEntry(&MasterBootRecord, &ExtendedPartitionTableEntry))
143  {
144  return FALSE;
145  }
146 
147  // Adjust the relative starting sector of the partition
148  ExtendedPartitionTableEntry.SectorCountBeforePartition += ExtendedPartitionOffset;
149  if (ExtendedPartitionOffset == 0)
150  {
151  // Set the start of the parrent extended partition
152  ExtendedPartitionOffset = ExtendedPartitionTableEntry.SectorCountBeforePartition;
153  }
154  // Read the partition boot record
155  if (!DiskReadBootRecord(DriveNumber, ExtendedPartitionTableEntry.SectorCountBeforePartition, &MasterBootRecord))
156  {
157  return FALSE;
158  }
159 
160  // Get the first real partition table entry
161  if (!DiskGetFirstPartitionEntry(&MasterBootRecord, PartitionTableEntry))
162  {
163  return FALSE;
164  }
165 
166  // Now correct the start sector of the partition
167  PartitionTableEntry->SectorCountBeforePartition += ExtendedPartitionTableEntry.SectorCountBeforePartition;
168  }
169 
170  // When we get here we should have the correct entry
171  // already stored in PartitionTableEntry
172  // so just return TRUE
173  return TRUE;
174 }
Definition: disk.h:53
BOOLEAN DiskGetFirstExtendedPartitionEntry(PMASTER_BOOT_RECORD MasterBootRecord, PPARTITION_TABLE_ENTRY PartitionTableEntry)
Definition: partition.c:197
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
UCHAR SystemIndicator
Definition: disk.h:60
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
ULONG SectorCountBeforePartition
Definition: parttest.c:84
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
BOOLEAN DiskGetFirstPartitionEntry(PMASTER_BOOT_RECORD MasterBootRecord, PPARTITION_TABLE_ENTRY PartitionTableEntry)
Definition: partition.c:176
ULONG SectorCountBeforePartition
Definition: disk.h:64
#define PARTITION_EXTENDED
Definition: disk.h:91
static const UCHAR Index[8]
Definition: usbohci.c:18
Definition: parttest.c:75
#define PARTITION_XINT13_EXTENDED
Definition: disk.h:98
BOOLEAN DiskReadBootRecord(UCHAR DriveNumber, ULONGLONG LogicalSectorNumber, PMASTER_BOOT_RECORD BootRecord)
Definition: partition.c:216
unsigned int ULONG
Definition: retypes.h:1
PARTITION_TABLE_ENTRY PartitionTable[4]
Definition: parttest.c:92

Referenced by XboxDiskGetPartitionEntry().

◆ DiskIsDriveRemovable()

BOOLEAN DiskIsDriveRemovable ( UCHAR  DriveNumber)

Definition at line 88 of file disk.c.

89 {
90  /*
91  * Hard disks use drive numbers >= 0x80 . So if the drive number
92  * indicates a hard disk then return FALSE.
93  * 0x49 is our magic ramdisk drive, so return FALSE for that too.
94  */
95  if ((DriveNumber >= 0x80) || (DriveNumber == 0x49))
96  return FALSE;
97 
98  /* The drive is a floppy diskette so return TRUE */
99  return TRUE;
100 }
#define TRUE
Definition: types.h:120

Referenced by PcInitializeBootDevices().

◆ DiskReadBootRecord()

BOOLEAN DiskReadBootRecord ( UCHAR  DriveNumber,
ULONGLONG  LogicalSectorNumber,
PMASTER_BOOT_RECORD  BootRecord 
)

Definition at line 216 of file partition.c.

217 {
218  ULONG Index;
219 
220  // Read master boot record
221  if (!MachDiskReadLogicalSectors(DriveNumber, LogicalSectorNumber, 1, DiskReadBuffer))
222  {
223  return FALSE;
224  }
225  RtlCopyMemory(BootRecord, DiskReadBuffer, sizeof(MASTER_BOOT_RECORD));
226 
227  TRACE("Dumping partition table for drive 0x%x:\n", DriveNumber);
228  TRACE("Boot record logical start sector = %d\n", LogicalSectorNumber);
229  TRACE("sizeof(MASTER_BOOT_RECORD) = 0x%x.\n", sizeof(MASTER_BOOT_RECORD));
230 
231  for (Index=0; Index<4; Index++)
232  {
233  TRACE("-------------------------------------------\n");
234  TRACE("Partition %d\n", (Index + 1));
235  TRACE("BootIndicator: 0x%x\n", BootRecord->PartitionTable[Index].BootIndicator);
236  TRACE("StartHead: 0x%x\n", BootRecord->PartitionTable[Index].StartHead);
237  TRACE("StartSector (Plus 2 cylinder bits): 0x%x\n", BootRecord->PartitionTable[Index].StartSector);
238  TRACE("StartCylinder: 0x%x\n", BootRecord->PartitionTable[Index].StartCylinder);
239  TRACE("SystemIndicator: 0x%x\n", BootRecord->PartitionTable[Index].SystemIndicator);
240  TRACE("EndHead: 0x%x\n", BootRecord->PartitionTable[Index].EndHead);
241  TRACE("EndSector (Plus 2 cylinder bits): 0x%x\n", BootRecord->PartitionTable[Index].EndSector);
242  TRACE("EndCylinder: 0x%x\n", BootRecord->PartitionTable[Index].EndCylinder);
243  TRACE("SectorCountBeforePartition: 0x%x\n", BootRecord->PartitionTable[Index].SectorCountBeforePartition);
244  TRACE("PartitionSectorCount: 0x%x\n", BootRecord->PartitionTable[Index].PartitionSectorCount);
245  }
246 
247  // Check the partition table magic value
248  if (BootRecord->MasterBootRecordMagic != 0xaa55)
249  {
250  return FALSE;
251  }
252 
253  return TRUE;
254 }
#define MachDiskReadLogicalSectors(Drive, Start, Count, Buf)
Definition: machine.h:120
USHORT MasterBootRecordMagic
Definition: disk.h:78
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
UCHAR StartCylinder
Definition: parttest.c:79
UCHAR StartSector
Definition: parttest.c:78
UCHAR EndHead
Definition: parttest.c:81
ULONG PartitionSectorCount
Definition: parttest.c:85
#define DiskReadBuffer
Definition: hardware.h:33
ULONG SectorCountBeforePartition
Definition: parttest.c:84
UCHAR SystemIndicator
Definition: parttest.c:80
#define TRACE(s)
Definition: solgame.cpp:4
UCHAR BootIndicator
Definition: parttest.c:76
UCHAR StartHead
Definition: parttest.c:77
static const UCHAR Index[8]
Definition: usbohci.c:18
UCHAR EndCylinder
Definition: parttest.c:83
PARTITION_TABLE_ENTRY PartitionTable[4]
Definition: disk.h:77
unsigned int ULONG
Definition: retypes.h:1
UCHAR EndSector
Definition: parttest.c:82

Referenced by DiskGetActivePartitionEntry(), and DiskGetMbrPartitionEntry().

◆ DiskReportError()

VOID DiskReportError ( BOOLEAN  bError)

Definition at line 33 of file disk.c.

34 {
35  bReportError = bError;
36 }
static BOOLEAN bReportError
Definition: disk.c:29

Referenced by EnumerateHarddisks(), and GetHarddiskInformation().

◆ LoadBootDeviceDriver()

ULONG LoadBootDeviceDriver ( VOID  )

Definition at line 1591 of file scsiport.c.

1592 {
1593  PIMAGE_NT_HEADERS NtHeaders;
1595  PIMAGE_IMPORT_DESCRIPTOR ImportTable;
1596  ULONG ImportTableSize;
1597  PLDR_DATA_TABLE_ENTRY BootDdDTE, FreeldrDTE;
1598  CHAR NtBootDdPath[MAX_PATH];
1599  PVOID ImageBase = NULL;
1600  ULONG (NTAPI *EntryPoint)(IN PVOID DriverObject, IN PVOID RegistryPath);
1601  BOOLEAN Success;
1602 
1603  // FIXME: Must be done *INSIDE* the HAL!
1604 #ifdef _M_IX86
1607 #endif
1608 
1609  /* Initialize the loaded module list */
1611 
1612  /* Create full ntbootdd.sys path */
1613  MachDiskGetBootPath(NtBootDdPath, sizeof(NtBootDdPath));
1614  strcat(NtBootDdPath, "\\NTBOOTDD.SYS");
1615 
1616  /* Load file */
1617  Success = WinLdrLoadImage(NtBootDdPath, LoaderBootDriver, &ImageBase);
1618  if (!Success)
1619  {
1620  /* That's OK. File simply doesn't exist */
1621  return ESUCCESS;
1622  }
1623 
1624  /* Allocate a DTE for ntbootdd */
1626  "NTBOOTDD.SYS", ImageBase, &BootDdDTE);
1627  if (!Success)
1628  return EIO;
1629 
1630  /* Add the PE part of freeldr.sys to the list of loaded executables, it
1631  contains Scsiport* exports, imported by ntbootdd.sys */
1633  "FREELDR.SYS", &__ImageBase, &FreeldrDTE);
1634  if (!Success)
1635  {
1636  RemoveEntryList(&BootDdDTE->InLoadOrderLinks);
1637  return EIO;
1638  }
1639 
1640  /* Fix imports */
1642 
1643  /* Now unlinkt the DTEs, they won't be valid later */
1644  RemoveEntryList(&BootDdDTE->InLoadOrderLinks);
1645  RemoveEntryList(&FreeldrDTE->InLoadOrderLinks);
1646 
1647  if (!Success)
1648  return EIO;
1649 
1650  /* Change imports to PA */
1652  TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize);
1653  for (;(ImportTable->Name != 0) && (ImportTable->FirstThunk != 0);ImportTable++)
1654  {
1655  PIMAGE_THUNK_DATA ThunkData = (PIMAGE_THUNK_DATA)VaToPa(RVA(BootDdDTE->DllBase, ImportTable->FirstThunk));
1656 
1657  while (((PIMAGE_THUNK_DATA)ThunkData)->u1.AddressOfData != 0)
1658  {
1659  ThunkData->u1.Function = (ULONG)VaToPa((PVOID)ThunkData->u1.Function);
1660  ThunkData++;
1661  }
1662  }
1663 
1664  /* Relocate image to PA */
1665  NtHeaders = RtlImageNtHeader(VaToPa(BootDdDTE->DllBase));
1666  if (!NtHeaders)
1667  return EIO;
1669  NtHeaders->OptionalHeader.ImageBase - (ULONG_PTR)BootDdDTE->DllBase,
1670  "FreeLdr",
1671  TRUE,
1672  TRUE, /* in case of conflict still return success */
1673  FALSE);
1674  if (!Success)
1675  return EIO;
1676 
1677  /* Call the entrypoint */
1678  EntryPoint = VaToPa(BootDdDTE->EntryPoint);
1679  (*EntryPoint)(NULL, NULL);
1680 
1681  return ESUCCESS;
1682 }
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
VOID NTAPI HalpInitBusHandler(VOID)
Definition: bushndlr.c:420
BOOLEAN WinLdrAllocateDataTableEntry(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH BaseDllName, IN PCCH FullDllName, IN PVOID BasePA, OUT PLDR_DATA_TABLE_ENTRY *NewEntry)
Definition: peloader.c:172
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:1805
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
BOOLEAN WinLdrScanImportDescriptorTable(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH DirectoryPath, IN PLDR_DATA_TABLE_ENTRY ScanDTE)
Definition: peloader.c:101
#define RtlImageDirectoryEntryToData
Definition: compat.h:460
Definition: btrfs_drv.h:1801
Definition: typedefs.h:117
LIST_ENTRY InLoadOrderLinks
Definition: ldrtypes.h:137
#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
#define MachDiskGetBootPath(Path, Size)
Definition: machine.h:118
BOOLEAN WinLdrLoadImage(IN PCHAR FileName, TYPE_OF_MEMORY MemoryType, OUT PVOID *ImageBasePA)
Definition: peloader.c:268
Definition: arc.h:40
#define RtlImageNtHeader
Definition: compat.h:457
#define IMAGE_DIRECTORY_ENTRY_IMPORT
Definition: pedump.c:260
char __ImageBase
Definition: mstscax.cpp:17
#define BOOLEAN
Definition: pedump.c:73
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
LIST_ENTRY * ModuleListHead
Definition: kdpacket.c:23
PIMAGE_THUNK_DATA32 PIMAGE_THUNK_DATA
Definition: ntimage.h:566
union _IMAGE_THUNK_DATA32::@2046 u1

Referenced by RunLoader().

Variable Documentation

◆ DiskGetPartitionEntry

DISK_GET_PARTITION_ENTRY DiskGetPartitionEntry

Definition at line 33 of file partition.c.

Referenced by DiskOpen(), GetHarddiskInformation(), and XboxMachInit().

◆ DiskReadBuffer

PVOID DiskReadBuffer

◆ DiskReadBufferSize

SIZE_T DiskReadBufferSize

Definition at line 48 of file hwdisk.c.

Referenced by DiskRead(), EnumerateHarddisks(), and PcMemGetMemoryMap().

◆ FrldrBootDrive

◆ FrldrBootPartition

ULONG FrldrBootPartition

Referenced by DiskGetBootPath().

◆ FrldrBootPath

CHAR FrldrBootPath[MAX_PATH]

Definition at line 27 of file disk.c.

Referenced by DiskGetBootPath(), and PcDiskGetBootPath().