ReactOS  0.4.14-dev-49-gfb4591c
hwdisk.c File Reference
#include <freeldr.h>
#include <debug.h>
Include dependency graph for hwdisk.c:

Go to the source code of this file.

Classes

struct  tagDISKCONTEXT
 

Typedefs

typedef struct tagDISKCONTEXT DISKCONTEXT
 

Functions

 DBG_DEFAULT_CHANNEL (HWDETECT)
 
static ARC_STATUS DiskClose (ULONG FileId)
 
static ARC_STATUS DiskGetFileInformation (ULONG FileId, FILEINFORMATION *Information)
 
static ARC_STATUS DiskOpen (CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
 
static ARC_STATUS DiskRead (ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
 
static ARC_STATUS DiskSeek (ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
 
PCHAR GetHarddiskIdentifier (UCHAR DriveNumber)
 
static VOID GetHarddiskInformation (UCHAR DriveNumber)
 
static UCHAR EnumerateHarddisks (OUT PBOOLEAN BootDriveReported)
 
static BOOLEAN DiskIsDriveRemovable (UCHAR DriveNumber)
 
static BOOLEAN DiskGetBootPath (BOOLEAN IsPxe)
 
BOOLEAN PcInitializeBootDevices (VOID)
 

Variables

static const CHAR Hex [] = "0123456789abcdef"
 
UCHAR PcBiosDiskCount = 0
 
static CHAR PcDiskIdentifier [32][20]
 
PVOID DiskReadBuffer
 
SIZE_T DiskReadBufferSize
 
static const DEVVTBL DiskVtbl
 

Typedef Documentation

◆ DISKCONTEXT

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( HWDETECT  )

◆ DiskClose()

static ARC_STATUS DiskClose ( ULONG  FileId)
static

Definition at line 53 of file hwdisk.c.

54 {
57  return ESUCCESS;
58 }
Definition: arc.h:32
VOID * FsGetDeviceSpecific(ULONG FileId)
Definition: fs.c:416
#define TAG_HW_DISK_CONTEXT
Definition: hardware.h:27
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:186

◆ DiskGetBootPath()

static BOOLEAN DiskGetBootPath ( BOOLEAN  IsPxe)
static

Definition at line 415 of file hwdisk.c.

416 {
417  if (*FrLdrBootPath)
418  return TRUE;
419 
420  // FIXME! FIXME! Do this in some drive recognition procedure!!!!
421  if (IsPxe)
422  {
423  RtlStringCbCopyA(FrLdrBootPath, sizeof(FrLdrBootPath), "net(0)");
424  }
425  else
426  /* 0x49 is our magic ramdisk drive, so try to detect it first */
427  if (FrldrBootDrive == 0x49)
428  {
429  /* This is the ramdisk. See ArmInitializeBootDevices() too... */
430  // RtlStringCbPrintfA(FrLdrBootPath, sizeof(FrLdrBootPath), "ramdisk(%u)", 0);
431  RtlStringCbCopyA(FrLdrBootPath, sizeof(FrLdrBootPath), "ramdisk(0)");
432  }
433  else if (FrldrBootDrive < 0x80)
434  {
435  /* This is a floppy */
437  "multi(0)disk(0)fdisk(%u)", FrldrBootDrive);
438  }
439  else if (FrldrBootPartition == 0xFF)
440  {
441  /* Boot Partition 0xFF is the magic value that indicates booting from CD-ROM (see isoboot.S) */
443  "multi(0)disk(0)cdrom(%u)", FrldrBootDrive - 0x80);
444  }
445  else
446  {
447  ULONG BootPartition;
448  PARTITION_TABLE_ENTRY PartitionEntry;
449 
450  /* This is a hard disk */
451  if (!DiskGetBootPartitionEntry(FrldrBootDrive, &PartitionEntry, &BootPartition))
452  {
453  ERR("Failed to get boot partition entry\n");
454  return FALSE;
455  }
456 
457  FrldrBootPartition = BootPartition;
458 
460  "multi(0)disk(0)rdisk(%u)partition(%lu)",
462  }
463 
464  return TRUE;
465 }
ULONG FrldrBootPartition
#define TRUE
Definition: types.h:120
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
NTSTRSAFEVAPI RtlStringCbPrintfA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
Definition: ntstrsafe.h:1148
UCHAR FrldrBootDrive
Definition: parttest.c:75
BOOLEAN DiskGetBootPartitionEntry(IN UCHAR DriveNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry, OUT PULONG BootPartition)
Definition: partition.c:367
#define ERR(fmt,...)
Definition: debug.h:109
unsigned int ULONG
Definition: retypes.h:1
CHAR FrLdrBootPath[MAX_PATH]
Definition: mach.c:34

Referenced by PcInitializeBootDevices().

◆ DiskGetFileInformation()

static ARC_STATUS DiskGetFileInformation ( ULONG  FileId,
FILEINFORMATION Information 
)
static

Definition at line 61 of file hwdisk.c.

62 {
64 
66 
67  /*
68  * The ARC specification mentions that for partitions, StartingAddress and
69  * EndingAddress are the start and end positions of the partition in terms
70  * of byte offsets from the start of the disk.
71  * CurrentAddress is the current offset into (i.e. relative to) the partition.
72  */
73  Information->StartingAddress.QuadPart = Context->SectorOffset * Context->SectorSize;
74  Information->EndingAddress.QuadPart = (Context->SectorOffset + Context->SectorCount) * Context->SectorSize;
75  Information->CurrentAddress.QuadPart = Context->SectorNumber * Context->SectorSize;
76 
77  return ESUCCESS;
78 }
Definition: arc.h:32
VOID * FsGetDeviceSpecific(ULONG FileId)
Definition: fs.c:416
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
Iosb Information
Definition: create.c:4377

◆ DiskIsDriveRemovable()

static BOOLEAN DiskIsDriveRemovable ( UCHAR  DriveNumber)
static

Definition at line 400 of file hwdisk.c.

401 {
402  /*
403  * Hard disks use drive numbers >= 0x80 . So if the drive number
404  * indicates a hard disk then return FALSE.
405  * 0x49 is our magic ramdisk drive, so return FALSE for that too.
406  */
407  if ((DriveNumber >= 0x80) || (DriveNumber == 0x49))
408  return FALSE;
409 
410  /* The drive is a floppy diskette so return TRUE */
411  return TRUE;
412 }
#define TRUE
Definition: types.h:120

Referenced by PcInitializeBootDevices().

◆ DiskOpen()

static ARC_STATUS DiskOpen ( CHAR Path,
OPENMODE  OpenMode,
ULONG FileId 
)
static

Definition at line 81 of file hwdisk.c.

82 {
84  UCHAR DriveNumber;
85  ULONG DrivePartition, SectorSize;
88  PARTITION_TABLE_ENTRY PartitionTableEntry;
89 
90  if (DiskReadBufferSize == 0)
91  {
92  ERR("DiskOpen(): DiskReadBufferSize is 0, something is wrong.\n");
93  ASSERT(FALSE);
94  return ENOMEM;
95  }
96 
97  if (!DissectArcPath(Path, NULL, &DriveNumber, &DrivePartition))
98  return EINVAL;
99 
100  if (DrivePartition == 0xff)
101  {
102  /* This is a CD-ROM device */
103  SectorSize = 2048;
104  }
105  else
106  {
107  /*
108  * This is either a floppy disk device (DrivePartition == 0) or
109  * a hard disk device (DrivePartition != 0 && DrivePartition != 0xFF)
110  * but it doesn't matter which one because they both have 512 bytes
111  * per sector.
112  */
113  SectorSize = 512;
114  }
115 
116  if (DrivePartition != 0xff && DrivePartition != 0)
117  {
118  if (!DiskGetPartitionEntry(DriveNumber, DrivePartition, &PartitionTableEntry))
119  return EINVAL;
120 
121  SectorOffset = PartitionTableEntry.SectorCountBeforePartition;
122  SectorCount = PartitionTableEntry.PartitionSectorCount;
123  }
124  else
125  {
126  GEOMETRY Geometry;
127  if (!MachDiskGetDriveGeometry(DriveNumber, &Geometry))
128  return EINVAL;
129 
130  if (SectorSize != Geometry.BytesPerSector)
131  {
132  ERR("SectorSize (%lu) != Geometry.BytesPerSector (%lu), expect problems!\n",
133  SectorSize, Geometry.BytesPerSector);
134  }
135 
136  SectorOffset = 0;
137  SectorCount = (ULONGLONG)Geometry.Cylinders * Geometry.Heads * Geometry.Sectors;
138  }
139 
141  if (!Context)
142  return ENOMEM;
143 
144  Context->DriveNumber = DriveNumber;
145  Context->SectorSize = SectorSize;
146  Context->SectorOffset = SectorOffset;
147  Context->SectorCount = SectorCount;
148  Context->SectorNumber = 0;
149  FsSetDeviceSpecific(*FileId, Context);
150 
151  return ESUCCESS;
152 }
BOOLEAN DissectArcPath(IN PCSTR ArcPath, OUT PCSTR *Path OPTIONAL, OUT PUCHAR DriveNumber, OUT PULONG PartitionNumber)
Definition: arcname.c:25
Definition: arc.h:32
ULONG Cylinders
Definition: disk.h:26
ULONG PartitionSectorCount
Definition: parttest.c:85
Definition: arc.h:39
ULONG SectorCountBeforePartition
Definition: parttest.c:84
Definition: arc.h:48
BOOLEAN DiskGetPartitionEntry(IN UCHAR DriveNumber, IN ULONG PartitionNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
Definition: partition.c:407
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:177
#define SectorOffset(L)
Definition: cdprocs.h:1632
smooth NULL
Definition: ftsmooth.c:416
#define MachDiskGetDriveGeometry(Drive, Geom)
Definition: machine.h:128
ULONG Sectors
Definition: disk.h:28
uint64_t ULONGLONG
Definition: typedefs.h:65
Definition: parttest.c:75
VOID FsSetDeviceSpecific(ULONG FileId, VOID *Specific)
Definition: fs.c:409
SIZE_T DiskReadBufferSize
Definition: hwdisk.c:47
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG SectorCount
Definition: part_xbox.c:32
#define ERR(fmt,...)
Definition: debug.h:109
ULONG BytesPerSector
Definition: disk.h:29
PRTL_UNICODE_STRING_BUFFER Path
Definition: disk.h:24
#define TAG_HW_DISK_CONTEXT
Definition: hardware.h:27
struct tagContext Context
Definition: acpixf.h:1024
unsigned int ULONG
Definition: retypes.h:1
_In_ ULONG SectorSize
Definition: halfuncs.h:291
ULONG Heads
Definition: disk.h:27

◆ DiskRead()

static ARC_STATUS DiskRead ( ULONG  FileId,
VOID Buffer,
ULONG  N,
ULONG Count 
)
static

Definition at line 155 of file hwdisk.c.

156 {
158  UCHAR* Ptr = (UCHAR*)Buffer;
159  ULONG Length, TotalSectors, MaxSectors, ReadSectors;
161  BOOLEAN ret;
162 
164 
165  TotalSectors = (N + Context->SectorSize - 1) / Context->SectorSize;
166  MaxSectors = DiskReadBufferSize / Context->SectorSize;
167  SectorOffset = Context->SectorOffset + Context->SectorNumber;
168 
169  // If MaxSectors is 0, this will lead to infinite loop.
170  // In release builds assertions are disabled, however we also have sanity checks in DiskOpen()
171  ASSERT(MaxSectors > 0);
172 
173  ret = TRUE;
174 
175  while (TotalSectors)
176  {
177  ReadSectors = TotalSectors;
178  if (ReadSectors > MaxSectors)
179  ReadSectors = MaxSectors;
180 
181  ret = MachDiskReadLogicalSectors(Context->DriveNumber,
182  SectorOffset,
183  ReadSectors,
185  if (!ret)
186  break;
187 
188  Length = ReadSectors * Context->SectorSize;
189  if (Length > N)
190  Length = N;
191 
193 
194  Ptr += Length;
195  N -= Length;
196  SectorOffset += ReadSectors;
197  TotalSectors -= ReadSectors;
198  }
199 
201  Context->SectorNumber = SectorOffset - Context->SectorOffset;
202 
203  return (!ret) ? EIO : ESUCCESS;
204 }
#define MachDiskReadLogicalSectors(Drive, Start, Count, Buf)
Definition: machine.h:126
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
Definition: arc.h:32
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
VOID * FsGetDeviceSpecific(ULONG FileId)
Definition: fs.c:416
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define SectorOffset(L)
Definition: cdprocs.h:1632
unsigned char BOOLEAN
Definition: bufpool.h:45
uint64_t ULONGLONG
Definition: typedefs.h:65
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
SIZE_T DiskReadBufferSize
Definition: hwdisk.c:47
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
int ret
PVOID DiskReadBuffer
Definition: hwdisk.c:46
Definition: arc.h:40
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101

◆ DiskSeek()

static ARC_STATUS DiskSeek ( ULONG  FileId,
LARGE_INTEGER Position,
SEEKMODE  SeekMode 
)
static

Definition at line 207 of file hwdisk.c.

208 {
210  LARGE_INTEGER NewPosition = *Position;
211 
212  switch (SeekMode)
213  {
214  case SeekAbsolute:
215  break;
216  case SeekRelative:
217  NewPosition.QuadPart += (Context->SectorNumber * Context->SectorSize);
218  break;
219  default:
220  ASSERT(FALSE);
221  return EINVAL;
222  }
223 
224  if (NewPosition.QuadPart & (Context->SectorSize - 1))
225  return EINVAL;
226 
227  /* Convert in number of sectors */
228  NewPosition.QuadPart /= Context->SectorSize;
229 
230  /* HACK: CDROMs may have a SectorCount of 0 */
231  if (Context->SectorCount != 0 && NewPosition.QuadPart >= Context->SectorCount)
232  return EINVAL;
233 
234  Context->SectorNumber = NewPosition.QuadPart;
235  return ESUCCESS;
236 }
Definition: arc.h:32
Definition: arc.h:39
static COORD Position
Definition: mouse.c:34
VOID * FsGetDeviceSpecific(ULONG FileId)
Definition: fs.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
LONGLONG QuadPart
Definition: typedefs.h:112

◆ EnumerateHarddisks()

static UCHAR EnumerateHarddisks ( OUT PBOOLEAN  BootDriveReported)
static

Definition at line 342 of file hwdisk.c.

343 {
344  UCHAR DiskCount, DriveNumber;
345  ULONG i;
346  BOOLEAN Changed;
347 
348  *BootDriveReported = FALSE;
349 
350  /* Count the number of visible harddisk drives */
352  DiskCount = 0;
353  DriveNumber = 0x80;
354 
356 
357  /*
358  * There are some really broken BIOSes out there. There are even BIOSes
359  * that happily report success when you ask them to read from non-existent
360  * harddisks. So, we set the buffer to known contents first, then try to
361  * read. If the BIOS reports success but the buffer contents haven't
362  * changed then we fail anyway.
363  */
365  while (MachDiskReadLogicalSectors(DriveNumber, 0ULL, 1, DiskReadBuffer))
366  {
367  Changed = FALSE;
368  for (i = 0; !Changed && i < DiskReadBufferSize; i++)
369  {
370  Changed = ((PUCHAR)DiskReadBuffer)[i] != 0xcd;
371  }
372  if (!Changed)
373  {
374  TRACE("BIOS reports success for disk %d (0x%02X) but data didn't change\n",
375  (int)DiskCount, DriveNumber);
376  break;
377  }
378 
379  /* Cache the BIOS hard disk information for later use */
380  GetHarddiskInformation(DriveNumber);
381 
382  /* Check if we have seen the boot drive */
383  if (FrldrBootDrive == DriveNumber)
384  *BootDriveReported = TRUE;
385 
386  DiskCount++;
387  DriveNumber++;
389  }
391 
392  PcBiosDiskCount = DiskCount;
393  TRACE("BIOS reports %d harddisk%s\n",
394  (int)DiskCount, (DiskCount == 1) ? "" : "s");
395 
396  return DiskCount;
397 }
#define MachDiskReadLogicalSectors(Drive, Start, Count, Buf)
Definition: machine.h:126
#define TRUE
Definition: types.h:120
unsigned char * PUCHAR
Definition: retypes.h:3
static VOID GetHarddiskInformation(UCHAR DriveNumber)
Definition: hwdisk.c:255
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char BOOLEAN
#define ULL(a, b)
Definition: format_msg.c:27
#define TRACE(s)
Definition: solgame.cpp:4
UCHAR FrldrBootDrive
SIZE_T DiskReadBufferSize
Definition: hwdisk.c:47
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
PVOID DiskReadBuffer
Definition: hwdisk.c:46
LONG DiskReportError(BOOLEAN bShowError)
Definition: pcdisk.c:80
UCHAR PcBiosDiskCount
Definition: hwdisk.c:43
unsigned int ULONG
Definition: retypes.h:1
#define memset(x, y, z)
Definition: compat.h:39

Referenced by PcInitializeBootDevices().

◆ GetHarddiskIdentifier()

PCHAR GetHarddiskIdentifier ( UCHAR  DriveNumber)

Definition at line 249 of file hwdisk.c.

250 {
251  return PcDiskIdentifier[DriveNumber - 0x80];
252 }
static CHAR PcDiskIdentifier[32][20]
Definition: hwdisk.c:44

Referenced by DetectBiosDisks().

◆ GetHarddiskInformation()

static VOID GetHarddiskInformation ( UCHAR  DriveNumber)
static

Definition at line 255 of file hwdisk.c.

256 {
258  PULONG Buffer;
259  ULONG i;
260  ULONG Checksum;
262  BOOLEAN ValidPartitionTable;
263  CHAR ArcName[MAX_PATH];
264  PARTITION_TABLE_ENTRY PartitionTableEntry;
265  PCHAR Identifier = PcDiskIdentifier[DriveNumber - 0x80];
266 
267  /* Detect disk partition type */
268  DiskDetectPartitionType(DriveNumber);
269 
270  /* Read the MBR */
271  if (!MachDiskReadLogicalSectors(DriveNumber, 0ULL, 1, DiskReadBuffer))
272  {
273  ERR("Reading MBR failed\n");
274  /* We failed, use a default identifier */
275  sprintf(Identifier, "BIOSDISK%d", DriveNumber - 0x80 + 1);
276  return;
277  }
278 
281 
282  Signature = Mbr->Signature;
283  TRACE("Signature: %x\n", Signature);
284 
285  /* Calculate the MBR checksum */
286  Checksum = 0;
287  for (i = 0; i < 512 / sizeof(ULONG); i++)
288  {
289  Checksum += Buffer[i];
290  }
291  Checksum = ~Checksum + 1;
292  TRACE("Checksum: %x\n", Checksum);
293 
294  ValidPartitionTable = (Mbr->MasterBootRecordMagic == 0xAA55);
295 
296  /* Fill out the ARC disk block */
297  sprintf(ArcName, "multi(0)disk(0)rdisk(%u)", DriveNumber - 0x80);
298  AddReactOSArcDiskInfo(ArcName, Signature, Checksum, ValidPartitionTable);
299 
300  sprintf(ArcName, "multi(0)disk(0)rdisk(%u)partition(0)", DriveNumber - 0x80);
301  FsRegisterDevice(ArcName, &DiskVtbl);
302 
303  /* Add partitions */
304  i = 1;
306  while (DiskGetPartitionEntry(DriveNumber, i, &PartitionTableEntry))
307  {
308  if (PartitionTableEntry.SystemIndicator != PARTITION_ENTRY_UNUSED)
309  {
310  sprintf(ArcName, "multi(0)disk(0)rdisk(%u)partition(%lu)", DriveNumber - 0x80, i);
311  FsRegisterDevice(ArcName, &DiskVtbl);
312  }
313  i++;
314  }
316 
317  /* Convert checksum and signature to identifier string */
318  Identifier[0] = Hex[(Checksum >> 28) & 0x0F];
319  Identifier[1] = Hex[(Checksum >> 24) & 0x0F];
320  Identifier[2] = Hex[(Checksum >> 20) & 0x0F];
321  Identifier[3] = Hex[(Checksum >> 16) & 0x0F];
322  Identifier[4] = Hex[(Checksum >> 12) & 0x0F];
323  Identifier[5] = Hex[(Checksum >> 8) & 0x0F];
324  Identifier[6] = Hex[(Checksum >> 4) & 0x0F];
325  Identifier[7] = Hex[Checksum & 0x0F];
326  Identifier[8] = '-';
327  Identifier[9] = Hex[(Signature >> 28) & 0x0F];
328  Identifier[10] = Hex[(Signature >> 24) & 0x0F];
329  Identifier[11] = Hex[(Signature >> 20) & 0x0F];
330  Identifier[12] = Hex[(Signature >> 16) & 0x0F];
331  Identifier[13] = Hex[(Signature >> 12) & 0x0F];
332  Identifier[14] = Hex[(Signature >> 8) & 0x0F];
333  Identifier[15] = Hex[(Signature >> 4) & 0x0F];
334  Identifier[16] = Hex[Signature & 0x0F];
335  Identifier[17] = '-';
336  Identifier[18] = (ValidPartitionTable ? 'A' : 'X');
337  Identifier[19] = 0;
338  TRACE("Identifier: %s\n", Identifier);
339 }
signed char * PCHAR
Definition: retypes.h:7
ULONG Signature
Definition: disk.h:75
#define MachDiskReadLogicalSectors(Drive, Start, Count, Buf)
Definition: machine.h:126
USHORT MasterBootRecordMagic
Definition: disk.h:78
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
VOID DiskDetectPartitionType(IN UCHAR DriveNumber)
Definition: partition.c:314
static const CHAR Hex[]
Definition: hwdisk.c:40
UCHAR SystemIndicator
Definition: parttest.c:80
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
#define sprintf(buf, format,...)
Definition: sprintf.c:55
BOOLEAN DiskGetPartitionEntry(IN UCHAR DriveNumber, IN ULONG PartitionNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
Definition: partition.c:407
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char BOOLEAN
Definition: bufpool.h:45
#define ULL(a, b)
Definition: format_msg.c:27
#define TRACE(s)
Definition: solgame.cpp:4
#define MAX_PATH
Definition: compat.h:26
Definition: parttest.c:75
static CHAR PcDiskIdentifier[32][20]
Definition: hwdisk.c:44
VOID FsRegisterDevice(CHAR *Prefix, const DEVVTBL *FuncTable)
Definition: fs.c:383
PVOID DiskReadBuffer
Definition: hwdisk.c:46
VOID AddReactOSArcDiskInfo(IN PSTR ArcName, IN ULONG Signature, IN ULONG Checksum, IN BOOLEAN ValidPartitionTable)
Definition: archwsup.c:29
#define ERR(fmt,...)
Definition: debug.h:109
LONG DiskReportError(BOOLEAN bShowError)
Definition: pcdisk.c:80
unsigned int * PULONG
Definition: retypes.h:1
struct _MASTER_BOOT_RECORD * PMASTER_BOOT_RECORD
unsigned int ULONG
Definition: retypes.h:1
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
static const WCHAR Signature[]
Definition: parser.c:141
static const DEVVTBL DiskVtbl
Definition: hwdisk.c:238

Referenced by EnumerateHarddisks().

◆ PcInitializeBootDevices()

BOOLEAN PcInitializeBootDevices ( VOID  )

Definition at line 468 of file hwdisk.c.

469 {
470  UCHAR DiskCount;
471  BOOLEAN BootDriveReported = FALSE;
472  ULONG i;
473 
474  DiskCount = EnumerateHarddisks(&BootDriveReported);
475 
476  /* Initialize FrLdrBootPath, the boot path we're booting from (the "SystemPartition") */
478 
479  /* Add it, if it's a floppy or cdrom */
480  if ((FrldrBootDrive >= 0x80 && !BootDriveReported) ||
482  {
483  /* TODO: Check if it's really a CDROM drive */
484 
486  PULONG Buffer;
487  ULONG Checksum = 0;
489 
490  /* Read the MBR */
492  {
493  ERR("Reading MBR failed\n");
494  return FALSE;
495  }
496 
499 
500  Signature = Mbr->Signature;
501  TRACE("Signature: %x\n", Signature);
502 
503  /* Calculate the MBR checksum */
504  for (i = 0; i < 2048 / sizeof(ULONG); i++)
505  {
506  Checksum += Buffer[i];
507  }
508  Checksum = ~Checksum + 1;
509  TRACE("Checksum: %x\n", Checksum);
510 
511  /* Fill out the ARC disk block */
513 
515  DiskCount++; // This is not accounted for in the number of pre-enumerated BIOS drives!
516  TRACE("Additional boot drive detected: 0x%02X\n", (int)FrldrBootDrive);
517  }
518 
519  return (DiskCount != 0);
520 }
ULONG Signature
Definition: disk.h:75
#define MachDiskReadLogicalSectors(Drive, Start, Count, Buf)
Definition: machine.h:126
#define TRUE
Definition: types.h:120
BOOLEAN PxeInit(VOID)
Definition: pxe.c:373
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char BOOLEAN
Definition: bufpool.h:45
#define ULL(a, b)
Definition: format_msg.c:27
static BOOLEAN DiskGetBootPath(BOOLEAN IsPxe)
Definition: hwdisk.c:415
static BOOLEAN DiskIsDriveRemovable(UCHAR DriveNumber)
Definition: hwdisk.c:400
#define TRACE(s)
Definition: solgame.cpp:4
UCHAR FrldrBootDrive
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID FsRegisterDevice(CHAR *Prefix, const DEVVTBL *FuncTable)
Definition: fs.c:383
PVOID DiskReadBuffer
Definition: hwdisk.c:46
VOID AddReactOSArcDiskInfo(IN PSTR ArcName, IN ULONG Signature, IN ULONG Checksum, IN BOOLEAN ValidPartitionTable)
Definition: archwsup.c:29
#define ERR(fmt,...)
Definition: debug.h:109
unsigned int * PULONG
Definition: retypes.h:1
struct _MASTER_BOOT_RECORD * PMASTER_BOOT_RECORD
unsigned int ULONG
Definition: retypes.h:1
CHAR FrLdrBootPath[MAX_PATH]
Definition: mach.c:34
static UCHAR EnumerateHarddisks(OUT PBOOLEAN BootDriveReported)
Definition: hwdisk.c:342
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
static const WCHAR Signature[]
Definition: parser.c:141
static const DEVVTBL DiskVtbl
Definition: hwdisk.c:238

Referenced by PcMachInit(), and XboxMachInit().

Variable Documentation

◆ DiskReadBuffer

PVOID DiskReadBuffer

◆ DiskReadBufferSize

SIZE_T DiskReadBufferSize

Definition at line 47 of file hwdisk.c.

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

◆ DiskVtbl

const DEVVTBL DiskVtbl
static
Initial value:
=
{
}
static ARC_STATUS DiskSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
Definition: hwdisk.c:207
static ARC_STATUS DiskOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: hwdisk.c:81
static ARC_STATUS DiskGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: hwdisk.c:61
static ARC_STATUS DiskClose(ULONG FileId)
Definition: hwdisk.c:53
static ARC_STATUS DiskRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: hwdisk.c:155

Definition at line 238 of file hwdisk.c.

Referenced by GetHarddiskInformation(), and PcInitializeBootDevices().

◆ Hex

const CHAR Hex[] = "0123456789abcdef"
static

Definition at line 40 of file hwdisk.c.

Referenced by GetHarddiskInformation(), and GspHex2Long().

◆ PcBiosDiskCount

UCHAR PcBiosDiskCount = 0

Definition at line 43 of file hwdisk.c.

Referenced by DetectBiosDisks(), and EnumerateHarddisks().

◆ PcDiskIdentifier

CHAR PcDiskIdentifier[32][20]
static

Definition at line 44 of file hwdisk.c.

Referenced by GetHarddiskIdentifier(), and GetHarddiskInformation().