ReactOS 0.4.16-dev-250-g3ecd236
uefidisk.c File Reference
#include <uefildr.h>
#include <debug.h>
Include dependency graph for uefidisk.c:

Go to the source code of this file.

Classes

struct  tagDISKCONTEXT
 
struct  _INTERNAL_UEFI_DISK
 

Macros

#define TAG_HW_RESOURCE_LIST   'lRwH'
 
#define TAG_HW_DISK_CONTEXT   'cDwH'
 
#define FIRST_BIOS_DISK   0x80
 
#define FIRST_PARTITION   1
 

Typedefs

typedef struct tagDISKCONTEXT DISKCONTEXT
 
typedef struct _INTERNAL_UEFI_DISK INTERNAL_UEFI_DISK
 
typedef struct _INTERNAL_UEFI_DISKPINTERNAL_UEFI_DISK
 

Functions

 DBG_DEFAULT_CHANNEL (WARNING)
 
PCHAR GetHarddiskIdentifier (UCHAR DriveNumber)
 
LONG DiskReportError (BOOLEAN bShowError)
 
static BOOLEAN UefiGetBootPartitionEntry (IN UCHAR DriveNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry, OUT PULONG BootPartition)
 
static ARC_STATUS UefiDiskClose (ULONG FileId)
 
static ARC_STATUS UefiDiskGetFileInformation (ULONG FileId, FILEINFORMATION *Information)
 
static ARC_STATUS UefiDiskOpen (CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
 
static ARC_STATUS UefiDiskRead (ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
 
static ARC_STATUS UefiDiskSeek (ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
 
static VOID GetHarddiskInformation (UCHAR DriveNumber)
 
static VOID UefiSetupBlockDevices (VOID)
 
static BOOLEAN UefiSetBootpath (VOID)
 
BOOLEAN UefiInitializeBootDevices (VOID)
 
UCHAR UefiGetFloppyCount (VOID)
 
BOOLEAN UefiDiskReadLogicalSectors (IN UCHAR DriveNumber, IN ULONGLONG SectorNumber, IN ULONG SectorCount, OUT PVOID Buffer)
 
BOOLEAN UefiDiskGetDriveGeometry (UCHAR DriveNumber, PGEOMETRY Geometry)
 
ULONG UefiDiskGetCacheableBlockCount (UCHAR DriveNumber)
 

Variables

EFI_SYSTEM_TABLEGlobalSystemTable
 
EFI_HANDLE GlobalImageHandle
 
EFI_HANDLE PublicBootHandle
 
PVOID DiskReadBuffer
 
UCHAR PcBiosDiskCount
 
UCHAR FrldrBootDrive
 
ULONG FrldrBootPartition
 
SIZE_T DiskReadBufferSize
 
PVOID Buffer
 
static const CHAR Hex [] = "0123456789abcdef"
 
static CHAR PcDiskIdentifier [32][20]
 
static ULONG UefiBootRootIdentifier
 
static ULONG OffsetToBoot
 
static ULONG PublicBootArcDisk
 
static INTERNAL_UEFI_DISKInternalUefiDisk = NULL
 
static EFI_GUID bioGuid = BLOCK_IO_PROTOCOL
 
static EFI_BLOCK_IObio
 
static EFI_HANDLEhandles = NULL
 
static LONG lReportError = 0
 
static const DEVVTBL UefiDiskVtbl
 

Macro Definition Documentation

◆ FIRST_BIOS_DISK

#define FIRST_BIOS_DISK   0x80

Definition at line 17 of file uefidisk.c.

◆ FIRST_PARTITION

#define FIRST_PARTITION   1

Definition at line 18 of file uefidisk.c.

◆ TAG_HW_DISK_CONTEXT

#define TAG_HW_DISK_CONTEXT   'cDwH'

Definition at line 16 of file uefidisk.c.

◆ TAG_HW_RESOURCE_LIST

#define TAG_HW_RESOURCE_LIST   'lRwH'

Definition at line 15 of file uefidisk.c.

Typedef Documentation

◆ DISKCONTEXT

◆ INTERNAL_UEFI_DISK

◆ PINTERNAL_UEFI_DISK

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( WARNING  )

◆ DiskReportError()

LONG DiskReportError ( BOOLEAN  bShowError)

Definition at line 76 of file uefidisk.c.

77{
78 /* Set the reference count */
79 if (bShowError) ++lReportError;
80 else --lReportError;
81 return lReportError;
82}
static LONG lReportError
Definition: uefidisk.c:73

Referenced by GetHarddiskInformation().

◆ GetHarddiskIdentifier()

PCHAR GetHarddiskIdentifier ( UCHAR  DriveNumber)

Definition at line 67 of file uefidisk.c.

68{
69 TRACE("GetHarddiskIdentifier: DriveNumber: %d\n", DriveNumber);
70 return PcDiskIdentifier[DriveNumber - FIRST_BIOS_DISK];
71}
#define TRACE(s)
Definition: solgame.cpp:4
static CHAR PcDiskIdentifier[32][20]
Definition: uefidisk.c:53
#define FIRST_BIOS_DISK
Definition: uefidisk.c:17

Referenced by DetectBiosDisks().

◆ GetHarddiskInformation()

static VOID GetHarddiskInformation ( UCHAR  DriveNumber)
static

Definition at line 298 of file uefidisk.c.

299{
302 ULONG i;
303 ULONG Checksum;
305 BOOLEAN ValidPartitionTable;
306 CHAR ArcName[MAX_PATH];
307 PARTITION_TABLE_ENTRY PartitionTableEntry;
309
310 /* Detect disk partition type */
311 DiskDetectPartitionType(DriveNumber);
312
313 /* Read the MBR */
314 if (!MachDiskReadLogicalSectors(DriveNumber, 0ULL, 1, DiskReadBuffer))
315 {
316 ERR("Reading MBR failed\n");
317 /* We failed, use a default identifier */
318 sprintf(Identifier, "BIOSDISK%d", DriveNumber - FIRST_BIOS_DISK);
319 return;
320 }
321
324
325 Signature = Mbr->Signature;
326 TRACE("Signature: %x\n", Signature);
327
328 /* Calculate the MBR checksum */
329 Checksum = 0;
330 for (i = 0; i < 512 / sizeof(ULONG); i++)
331 {
332 Checksum += Buffer[i];
333 }
334 Checksum = ~Checksum + 1;
335 TRACE("Checksum: %x\n", Checksum);
336
337 ValidPartitionTable = (Mbr->MasterBootRecordMagic == 0xAA55);
338
339 /* Fill out the ARC disk block */
340 sprintf(ArcName, "multi(0)disk(0)rdisk(%u)", DriveNumber - FIRST_BIOS_DISK);
341 AddReactOSArcDiskInfo(ArcName, Signature, Checksum, ValidPartitionTable);
342
343 sprintf(ArcName, "multi(0)disk(0)rdisk(%u)partition(0)", DriveNumber - FIRST_BIOS_DISK);
345
346 /* Add partitions */
349 while (DiskGetPartitionEntry(DriveNumber, i, &PartitionTableEntry))
350 {
351 if (PartitionTableEntry.SystemIndicator != PARTITION_ENTRY_UNUSED)
352 {
353 sprintf(ArcName, "multi(0)disk(0)rdisk(%u)partition(%lu)", DriveNumber - FIRST_BIOS_DISK, i);
355 }
356 i++;
357 }
359
360 InternalUefiDisk[DriveNumber].NumOfPartitions = i;
361 /* Convert checksum and signature to identifier string */
362 Identifier[0] = Hex[(Checksum >> 28) & 0x0F];
363 Identifier[1] = Hex[(Checksum >> 24) & 0x0F];
364 Identifier[2] = Hex[(Checksum >> 20) & 0x0F];
365 Identifier[3] = Hex[(Checksum >> 16) & 0x0F];
366 Identifier[4] = Hex[(Checksum >> 12) & 0x0F];
367 Identifier[5] = Hex[(Checksum >> 8) & 0x0F];
368 Identifier[6] = Hex[(Checksum >> 4) & 0x0F];
369 Identifier[7] = Hex[Checksum & 0x0F];
370 Identifier[8] = '-';
371 Identifier[9] = Hex[(Signature >> 28) & 0x0F];
372 Identifier[10] = Hex[(Signature >> 24) & 0x0F];
373 Identifier[11] = Hex[(Signature >> 20) & 0x0F];
374 Identifier[12] = Hex[(Signature >> 16) & 0x0F];
375 Identifier[13] = Hex[(Signature >> 12) & 0x0F];
376 Identifier[14] = Hex[(Signature >> 8) & 0x0F];
377 Identifier[15] = Hex[(Signature >> 4) & 0x0F];
378 Identifier[16] = Hex[Signature & 0x0F];
379 Identifier[17] = '-';
380 Identifier[18] = (ValidPartitionTable ? 'A' : 'X');
381 Identifier[19] = 0;
382 TRACE("Identifier: %s\n", Identifier);
383}
unsigned char BOOLEAN
VOID AddReactOSArcDiskInfo(IN PSTR ArcName, IN ULONG Signature, IN ULONG Checksum, IN BOOLEAN ValidPartitionTable)
Definition: archwsup.c:77
@ Identifier
Definition: asmpp.cpp:95
#define ERR(fmt,...)
Definition: precomp.h:57
BOOLEAN DiskGetPartitionEntry(IN UCHAR DriveNumber, IN ULONG PartitionNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry)
Definition: partition.c:407
VOID DiskDetectPartitionType(IN UCHAR DriveNumber)
Definition: partition.c:314
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:87
struct _MASTER_BOOT_RECORD * PMASTER_BOOT_RECORD
VOID FsRegisterDevice(_In_ PCSTR DeviceName, _In_ const DEVVTBL *FuncTable)
Definition: fs.c:596
#define MachDiskReadLogicalSectors(Drive, Start, Count, Buf)
Definition: machine.h:126
Definition: bufpool.h:45
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define MAX_PATH
Definition: compat.h:34
static const WCHAR Signature[]
Definition: parser.c:141
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
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define ULL(a, b)
Definition: format_msg.c:27
Definition: parttest.c:75
UCHAR SystemIndicator
Definition: parttest.c:80
UCHAR NumOfPartitions
Definition: uefidisk.c:32
USHORT MasterBootRecordMagic
Definition: disk.h:79
ULONG Signature
Definition: disk.h:76
uint32_t * PULONG
Definition: typedefs.h:59
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
PVOID Buffer
Definition: uefidisk.c:50
PVOID DiskReadBuffer
Definition: uefidisk.c:44
LONG DiskReportError(BOOLEAN bShowError)
Definition: uefidisk.c:76
static const DEVVTBL UefiDiskVtbl
Definition: uefidisk.c:287
static const CHAR Hex[]
Definition: uefidisk.c:52
static INTERNAL_UEFI_DISK * InternalUefiDisk
Definition: uefidisk.c:59
#define FIRST_PARTITION
Definition: uefidisk.c:18
char CHAR
Definition: xmlstorage.h:175

Referenced by UefiSetupBlockDevices().

◆ UefiDiskClose()

static ARC_STATUS UefiDiskClose ( ULONG  FileId)
static

Definition at line 111 of file uefidisk.c.

112{
115 return ESUCCESS;
116}
PVOID FsGetDeviceSpecific(ULONG FileId)
Definition: fs.c:632
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:197
@ ESUCCESS
Definition: arc.h:32
#define TAG_HW_DISK_CONTEXT
Definition: uefidisk.c:16

◆ UefiDiskGetCacheableBlockCount()

ULONG UefiDiskGetCacheableBlockCount ( UCHAR  DriveNumber)

Definition at line 590 of file uefidisk.c.

591{
592 ULONG UefiDriveNumber = InternalUefiDisk[DriveNumber - FIRST_BIOS_DISK].UefiRootNumber;
593 TRACE("UefiDiskGetCacheableBlockCount: DriveNumber: %d\n", UefiDriveNumber);
594
595 GlobalSystemTable->BootServices->HandleProtocol(handles[UefiDriveNumber], &bioGuid, (void**)&bio);
596 return (bio->Media->LastBlock + 1);
597}
EFI_LBA LastBlock
Definition: BlockIo.h:184
EFI_HANDLE_PROTOCOL HandleProtocol
Definition: UefiSpec.h:1832
EFI_BOOT_SERVICES * BootServices
Definition: UefiSpec.h:1959
EFI_BLOCK_IO_MEDIA * Media
Definition: BlockIo.h:230
UCHAR UefiRootNumber
Definition: uefidisk.c:33
static EFI_GUID bioGuid
Definition: uefidisk.c:60
static EFI_BLOCK_IO * bio
Definition: uefidisk.c:61
EFI_SYSTEM_TABLE * GlobalSystemTable
Definition: uefildr.c:16
static EFI_HANDLE * handles
Definition: uefidisk.c:62

Referenced by MachInit().

◆ UefiDiskGetDriveGeometry()

BOOLEAN UefiDiskGetDriveGeometry ( UCHAR  DriveNumber,
PGEOMETRY  Geometry 
)

Definition at line 574 of file uefidisk.c.

575{
576 ULONG UefiDriveNumber;
577
578 UefiDriveNumber = InternalUefiDisk[DriveNumber - FIRST_BIOS_DISK].UefiRootNumber;
579 GlobalSystemTable->BootServices->HandleProtocol(handles[UefiDriveNumber], &bioGuid, (void**)&bio);
580 Geometry->Cylinders = 1; // Not relevant for the UEFI BIO protocol
581 Geometry->Heads = 1; // Not relevant for the UEFI BIO protocol
582 Geometry->SectorsPerTrack = (bio->Media->LastBlock + 1);
583 Geometry->BytesPerSector = bio->Media->BlockSize;
584 Geometry->Sectors = (bio->Media->LastBlock + 1);
585
586 return TRUE;
587}
UINT32 BlockSize
Definition: BlockIo.h:173
ULONG BytesPerSector
Number of bytes per sector.
Definition: disk.h:30
ULONG Cylinders
Number of cylinders on the disk.
Definition: disk.h:27
ULONGLONG Sectors
Total number of disk sectors/LBA blocks.
Definition: disk.h:31
ULONG SectorsPerTrack
Number of sectors per track.
Definition: disk.h:29
ULONG Heads
Number of heads on the disk.
Definition: disk.h:28

Referenced by MachInit().

◆ UefiDiskGetFileInformation()

static ARC_STATUS UefiDiskGetFileInformation ( ULONG  FileId,
FILEINFORMATION Information 
)
static

Definition at line 120 of file uefidisk.c.

121{
124
125 /*
126 * The ARC specification mentions that for partitions, StartingAddress and
127 * EndingAddress are the start and end positions of the partition in terms
128 * of byte offsets from the start of the disk.
129 * CurrentAddress is the current offset into (i.e. relative to) the partition.
130 */
131 Information->StartingAddress.QuadPart = Context->SectorOffset * Context->SectorSize;
132 Information->EndingAddress.QuadPart = (Context->SectorOffset + Context->SectorCount) * Context->SectorSize;
133 Information->CurrentAddress.QuadPart = Context->SectorNumber * Context->SectorSize;
134
135 return ESUCCESS;
136}
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049

◆ UefiDiskOpen()

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

Definition at line 140 of file uefidisk.c.

141{
143 UCHAR DriveNumber;
144 ULONG DrivePartition, SectorSize;
147 ULONG UefiDriveNumber = 0;
148 PARTITION_TABLE_ENTRY PartitionTableEntry;
149
150 TRACE("UefiDiskOpen: File ID: %d, Path: %s\n", FileId, Path);
151
152 if (DiskReadBufferSize == 0)
153 {
154 ERR("DiskOpen(): DiskReadBufferSize is 0, something is wrong.\n");
155 ASSERT(FALSE);
156 return ENOMEM;
157 }
158
159 if (!DissectArcPath(Path, NULL, &DriveNumber, &DrivePartition))
160 return EINVAL;
161
162 TRACE("Opening disk: DriveNumber: %d, DrivePartition: %d\n", DriveNumber, DrivePartition);
163 UefiDriveNumber = DriveNumber - FIRST_BIOS_DISK;
164 GlobalSystemTable->BootServices->HandleProtocol(handles[UefiDriveNumber], &bioGuid, (void**)&bio);
166
167 if (DrivePartition != 0xff && DrivePartition != 0)
168 {
169 if (!DiskGetPartitionEntry(DriveNumber, DrivePartition, &PartitionTableEntry))
170 return EINVAL;
171
172 SectorOffset = PartitionTableEntry.SectorCountBeforePartition;
173 SectorCount = PartitionTableEntry.PartitionSectorCount;
174 }
175 else
176 {
177 GEOMETRY Geometry;
178 if (!MachDiskGetDriveGeometry(DriveNumber, &Geometry))
179 return EINVAL;
180
181 if (SectorSize != Geometry.BytesPerSector)
182 {
183 ERR("SectorSize (%lu) != Geometry.BytesPerSector (%lu), expect problems!\n",
184 SectorSize, Geometry.BytesPerSector);
185 }
186
187 SectorOffset = 0;
188 SectorCount = Geometry.Sectors;
189 }
190
192 if (!Context)
193 return ENOMEM;
194
195 Context->DriveNumber = DriveNumber;
196 Context->SectorSize = SectorSize;
197 Context->SectorOffset = SectorOffset;
198 Context->SectorCount = SectorCount;
199 Context->SectorNumber = 0;
201 return ESUCCESS;
202}
PRTL_UNICODE_STRING_BUFFER Path
#define EINVAL
Definition: acclib.h:90
#define ENOMEM
Definition: acclib.h:84
BOOLEAN DissectArcPath(IN PCSTR ArcPath, OUT PCSTR *Path OPTIONAL, OUT PUCHAR DriveNumber, OUT PULONG PartitionNumber)
Definition: arcname.c:25
VOID FsSetDeviceSpecific(ULONG FileId, PVOID Specific)
Definition: fs.c:625
#define MachDiskGetDriveGeometry(Drive, Geom)
Definition: machine.h:128
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:188
#define SectorOffset(L)
Definition: cdprocs.h:1622
#define NULL
Definition: types.h:112
#define ASSERT(a)
Definition: mode.c:44
ULONG SectorCount
Definition: part_xbox.c:31
ULONG PartitionSectorCount
Definition: parttest.c:85
ULONG SectorCountBeforePartition
Definition: parttest.c:84
Definition: disk.h:26
uint64_t ULONGLONG
Definition: typedefs.h:67
SIZE_T DiskReadBufferSize
Definition: uefidisk.c:49
_In_ ULONG SectorSize
Definition: halfuncs.h:291
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ UefiDiskRead()

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

Definition at line 206 of file uefidisk.c.

207{
209 UCHAR* Ptr = (UCHAR*)Buffer;
210 ULONG Length, TotalSectors, MaxSectors, ReadSectors;
212 BOOLEAN ret;
213
215
216 TotalSectors = (N + Context->SectorSize - 1) / Context->SectorSize;
217 MaxSectors = DiskReadBufferSize / Context->SectorSize;
218 SectorOffset = Context->SectorOffset + Context->SectorNumber;
219
220 // If MaxSectors is 0, this will lead to infinite loop.
221 // In release builds assertions are disabled, however we also have sanity checks in DiskOpen()
222 ASSERT(MaxSectors > 0);
223
224 ret = TRUE;
225
226 while (TotalSectors)
227 {
228 ReadSectors = min(TotalSectors, MaxSectors);
229
232 ReadSectors,
234 if (!ret)
235 break;
236
237 Length = ReadSectors * Context->SectorSize;
238 Length = min(Length, N);
239
241
242 Ptr += Length;
243 N -= Length;
244 SectorOffset += ReadSectors;
245 TotalSectors -= ReadSectors;
246 }
247
249 Context->SectorNumber = SectorOffset - Context->SectorOffset;
250
251 return (ret ? ESUCCESS : EIO);
252}
#define N
Definition: crc32.c:57
#define EIO
Definition: acclib.h:81
#define ULONG_PTR
Definition: config.h:101
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
#define min(a, b)
Definition: monoChain.cc:55
int Count
Definition: noreturn.cpp:7
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
int ret

◆ UefiDiskReadLogicalSectors()

BOOLEAN UefiDiskReadLogicalSectors ( IN UCHAR  DriveNumber,
IN ULONGLONG  SectorNumber,
IN ULONG  SectorCount,
OUT PVOID  Buffer 
)

Definition at line 556 of file uefidisk.c.

561{
562 ULONG UefiDriveNumber;
563
564 UefiDriveNumber = InternalUefiDisk[DriveNumber - FIRST_BIOS_DISK].UefiRootNumber;
565 TRACE("UefiDiskReadLogicalSectors: DriveNumber: %d\n", UefiDriveNumber);
566 GlobalSystemTable->BootServices->HandleProtocol(handles[UefiDriveNumber], &bioGuid, (void**)&bio);
567
568 /* Devices setup */
570 return TRUE;
571}
EFI_BLOCK_READ ReadBlocks
Definition: BlockIo.h:233

Referenced by MachInit().

◆ UefiDiskSeek()

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

Definition at line 256 of file uefidisk.c.

257{
259 LARGE_INTEGER NewPosition = *Position;
260
261 switch (SeekMode)
262 {
263 case SeekAbsolute:
264 break;
265 case SeekRelative:
266 NewPosition.QuadPart += (Context->SectorNumber * Context->SectorSize);
267 break;
268 default:
269 ASSERT(FALSE);
270 return EINVAL;
271 }
272
273 if (NewPosition.QuadPart & (Context->SectorSize - 1))
274 return EINVAL;
275
276 /* Convert in number of sectors */
277 NewPosition.QuadPart /= Context->SectorSize;
278
279 /* HACK: CDROMs may have a SectorCount of 0 */
280 if (Context->SectorCount != 0 && NewPosition.QuadPart >= Context->SectorCount)
281 return EINVAL;
282
283 Context->SectorNumber = NewPosition.QuadPart;
284 return ESUCCESS;
285}
@ SeekRelative
Definition: arc.h:60
@ SeekAbsolute
Definition: arc.h:59
static COORD Position
Definition: mouse.c:34
LONGLONG QuadPart
Definition: typedefs.h:114

◆ UefiGetBootPartitionEntry()

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

Definition at line 86 of file uefidisk.c.

90{
91 ULONG PartitionNum;
92
93 TRACE("UefiGetBootPartitionEntry: DriveNumber: %d\n", DriveNumber - FIRST_BIOS_DISK);
94 /* UefiBootRoot is the offset into the array of handles where the raw disk of the boot drive is.
95 * Partitions start with 1 in ARC, but UEFI root drive identitfier is also first partition. */
96 PartitionNum = (OffsetToBoot - UefiBootRootIdentifier);
97 if (PartitionNum == 0)
98 {
99 TRACE("Boot PartitionNumber is 0\n");
100 /* The OffsetToBoot is equal to the RootIdentifier */
101 PartitionNum = FIRST_PARTITION;
102 }
103
104 *BootPartition = PartitionNum;
105 TRACE("UefiGetBootPartitionEntry: Boot Partition is: %d\n", PartitionNum);
106 return TRUE;
107}
static ULONG UefiBootRootIdentifier
Definition: uefidisk.c:56
static ULONG OffsetToBoot
Definition: uefidisk.c:57

Referenced by UefiSetBootpath().

◆ UefiGetFloppyCount()

UCHAR UefiGetFloppyCount ( VOID  )

Definition at line 549 of file uefidisk.c.

550{
551 /* No floppy for you for now... */
552 return 0;
553}

Referenced by MachInit().

◆ UefiInitializeBootDevices()

BOOLEAN UefiInitializeBootDevices ( VOID  )

Definition at line 499 of file uefidisk.c.

500{
501 ULONG i = 0;
502
507
508 /* Add it, if it's a cdrom */
510 if (bio->Media->RemovableMedia == TRUE && bio->Media->BlockSize == 2048)
511 {
514 ULONG Checksum = 0;
516
517 /* Read the MBR */
519 {
520 ERR("Reading MBR failed\n");
521 return FALSE;
522 }
523
526
527 Signature = Mbr->Signature;
528 TRACE("Signature: %x\n", Signature);
529
530 /* Calculate the MBR checksum */
531 for (i = 0; i < 2048 / sizeof(ULONG); i++)
532 {
533 Checksum += Buffer[i];
534 }
535 Checksum = ~Checksum + 1;
536 TRACE("Checksum: %x\n", Checksum);
537
538 /* Fill out the ARC disk block */
540
542 PcBiosDiskCount++; // This is not accounted for in the number of pre-enumerated BIOS drives!
543 TRACE("Additional boot drive detected: 0x%02X\n", (int)FrldrBootDrive);
544 }
545 return TRUE;
546}
#define EFI_PAGE_SIZE
Definition: UefiBaseType.h:189
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
CCHAR FrLdrBootPath[MAX_PATH]
Definition: freeldr.c:29
@ LoaderFirmwareTemporary
Definition: arc.h:179
BOOLEAN RemovableMedia
Definition: BlockIo.h:143
static VOID UefiSetupBlockDevices(VOID)
Definition: uefidisk.c:387
UCHAR PcBiosDiskCount
Definition: uefidisk.c:45
UCHAR FrldrBootDrive
Definition: uefidisk.c:47
static BOOLEAN UefiSetBootpath(VOID)
Definition: uefidisk.c:466

Referenced by MachInit().

◆ UefiSetBootpath()

static BOOLEAN UefiSetBootpath ( VOID  )
static

Definition at line 466 of file uefidisk.c.

467{
468 TRACE("UefiSetBootpath: Setting up boot path\n");
471 if (bio->Media->RemovableMedia == TRUE && bio->Media->BlockSize == 2048)
472 {
473 /* Boot Partition 0xFF is the magic value that indicates booting from CD-ROM (see isoboot.S) */
474 FrldrBootPartition = 0xFF;
476 "multi(0)disk(0)cdrom(%u)", PublicBootArcDisk);
477 }
478 else
479 {
480 ULONG BootPartition;
481 PARTITION_TABLE_ENTRY PartitionEntry;
482
483 /* This is a hard disk */
484 if (!UefiGetBootPartitionEntry(FrldrBootDrive, &PartitionEntry, &BootPartition))
485 {
486 ERR("Failed to get boot partition entry\n");
487 return FALSE;
488 }
489
491 "multi(0)disk(0)rdisk(%u)partition(%lu)",
492 PublicBootArcDisk, BootPartition);
493 }
494
495 return TRUE;
496}
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
static ULONG PublicBootArcDisk
Definition: uefidisk.c:58
static BOOLEAN UefiGetBootPartitionEntry(IN UCHAR DriveNumber, OUT PPARTITION_TABLE_ENTRY PartitionTableEntry, OUT PULONG BootPartition)
Definition: uefidisk.c:86
ULONG FrldrBootPartition
Definition: uefidisk.c:48

Referenced by UefiInitializeBootDevices().

◆ UefiSetupBlockDevices()

static VOID UefiSetupBlockDevices ( VOID  )
static

Definition at line 387 of file uefidisk.c.

388{
389 ULONG BlockDeviceIndex;
390 ULONG SystemHandleCount;
392 ULONG i;
393
394 UINTN handle_size = 0;
395 PcBiosDiskCount = 0;
397
398 /* 1) Setup a list of boot handles by using the LocateHandle protocol */
402 SystemHandleCount = handle_size / sizeof(EFI_HANDLE);
404
405 BlockDeviceIndex = 0;
406 /* 2) Parse the handle list */
407 for (i = 0; i < SystemHandleCount; ++i)
408 {
410 if (handles[i] == PublicBootHandle)
411 {
412 OffsetToBoot = i; /* Drive offset in the handles list */
413 }
414
415 if (EFI_ERROR(Status) ||
416 bio == NULL ||
417 bio->Media->BlockSize == 0 ||
418 bio->Media->BlockSize > 4096)
419 {
420 TRACE("UefiSetupBlockDevices: UEFI has found a block device that failed, skipping\n");
421 continue;
422 }
424 {
425 TRACE("Found root of a HDD\n");
427 InternalUefiDisk[BlockDeviceIndex].ArcDriveNumber = BlockDeviceIndex;
428 InternalUefiDisk[BlockDeviceIndex].UefiRootNumber = i;
429 GetHarddiskInformation(BlockDeviceIndex + FIRST_BIOS_DISK);
430 BlockDeviceIndex++;
431 }
432 else if (handles[i] == PublicBootHandle)
433 {
434 ULONG increment = 0;
435 ULONG i;
436
437 /* 3) Grab the offset into the array of handles and decrement per volume (valid partition) */
438 for (increment = OffsetToBoot; increment > 0; increment--)
439 {
442 {
443 TRACE("Found root at increment %u\n", increment);
444 UefiBootRootIdentifier = increment;
445
446 for (i = 0; i <= PcBiosDiskCount; ++i)
447 {
448 /* Now only of the root drive number is equal to this drive we found above */
449 if (InternalUefiDisk[i].UefiRootNumber == UefiBootRootIdentifier)
450 {
453 TRACE("Found Boot drive\n");
454 }
455 }
456
457 break;
458 }
459 }
460 }
461 }
462}
UINT32 UINTN
#define EFI_ERROR(A)
Definition: UefiBaseType.h:165
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:31
VOID * EFI_HANDLE
Definition: UefiBaseType.h:35
@ ByProtocol
Definition: UefiSpec.h:1428
Status
Definition: gdiplustypes.h:25
BOOLEAN LogicalPartition
Definition: BlockIo.h:156
EFI_LOCATE_HANDLE LocateHandle
Definition: UefiSpec.h:1835
BOOLEAN IsThisTheBootDrive
Definition: uefidisk.c:34
UCHAR ArcDriveNumber
Definition: uefidisk.c:31
EFI_HANDLE PublicBootHandle
Definition: uefimem.c:39
static VOID GetHarddiskInformation(UCHAR DriveNumber)
Definition: uefidisk.c:298

Referenced by UefiInitializeBootDevices().

Variable Documentation

◆ bio

◆ bioGuid

◆ Buffer

Definition at line 50 of file uefidisk.c.

Referenced by GetHarddiskInformation(), and UefiInitializeBootDevices().

◆ DiskReadBuffer

PVOID DiskReadBuffer

Definition at line 44 of file uefidisk.c.

Referenced by GetHarddiskInformation(), UefiDiskRead(), and UefiInitializeBootDevices().

◆ DiskReadBufferSize

SIZE_T DiskReadBufferSize

Definition at line 49 of file uefidisk.c.

Referenced by UefiDiskOpen(), UefiDiskRead(), and UefiInitializeBootDevices().

◆ FrldrBootDrive

◆ FrldrBootPartition

ULONG FrldrBootPartition

◆ GlobalImageHandle

EFI_HANDLE GlobalImageHandle
extern

Definition at line 15 of file uefildr.c.

◆ GlobalSystemTable

◆ handles

◆ Hex

const CHAR Hex[] = "0123456789abcdef"
static

Definition at line 52 of file uefidisk.c.

Referenced by GetHarddiskInformation().

◆ InternalUefiDisk

◆ lReportError

LONG lReportError = 0
static

Definition at line 73 of file uefidisk.c.

Referenced by DiskReportError().

◆ OffsetToBoot

ULONG OffsetToBoot
static

Definition at line 57 of file uefidisk.c.

Referenced by UefiGetBootPartitionEntry(), and UefiSetupBlockDevices().

◆ PcBiosDiskCount

UCHAR PcBiosDiskCount

Definition at line 45 of file uefidisk.c.

Referenced by DetectBiosDisks(), UefiInitializeBootDevices(), and UefiSetupBlockDevices().

◆ PcDiskIdentifier

CHAR PcDiskIdentifier[32][20]
static

Definition at line 53 of file uefidisk.c.

Referenced by GetHarddiskIdentifier(), and GetHarddiskInformation().

◆ PublicBootArcDisk

ULONG PublicBootArcDisk
static

Definition at line 58 of file uefidisk.c.

Referenced by UefiSetBootpath(), and UefiSetupBlockDevices().

◆ PublicBootHandle

EFI_HANDLE PublicBootHandle
extern

Definition at line 39 of file uefimem.c.

Referenced by UefiMemGetMemoryMap(), and UefiSetupBlockDevices().

◆ UefiBootRootIdentifier

ULONG UefiBootRootIdentifier
static

◆ UefiDiskVtbl

const DEVVTBL UefiDiskVtbl
static
Initial value:
=
{
}
static ARC_STATUS UefiDiskGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: uefidisk.c:120
static ARC_STATUS UefiDiskOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: uefidisk.c:140
static ARC_STATUS UefiDiskSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
Definition: uefidisk.c:256
static ARC_STATUS UefiDiskClose(ULONG FileId)
Definition: uefidisk.c:111
static ARC_STATUS UefiDiskRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: uefidisk.c:206

Definition at line 287 of file uefidisk.c.

Referenced by GetHarddiskInformation(), and UefiInitializeBootDevices().