Skip to content

Commit 246f2d2

Browse files
committed
[FREELDR] ArcGetFileInformation(): Set the Information->Type field for devices (reactos#8418)
CORE-9023 Some of this determination is platform-specific (e.g. BIOS-based PC vs. NEC PC-98 vs. Xbox), and is done in a per-platform `DiskGetConfigType()` routine. This routine is then invoked by `hwdisk.c!DiskOpen()` and `PcInitializeBootDevices()`.
1 parent e969fbe commit 246f2d2

File tree

9 files changed

+75
-30
lines changed

9 files changed

+75
-30
lines changed

boot/freeldr/freeldr/arch/i386/hwdisk.c

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ DBG_DEFAULT_CHANNEL(HWDETECT);
3434
typedef struct tagDISKCONTEXT
3535
{
3636
UCHAR DriveNumber;
37+
BOOLEAN IsFloppy;
3738
ULONG SectorSize;
3839
ULONGLONG SectorOffset;
3940
ULONGLONG SectorCount;
@@ -77,13 +78,16 @@ DiskGetFileInformation(ULONG FileId, FILEINFORMATION* Information)
7778
Information->EndingAddress.QuadPart = (Context->SectorOffset + Context->SectorCount) * Context->SectorSize;
7879
Information->CurrentAddress.QuadPart = Context->SectorNumber * Context->SectorSize;
7980

81+
Information->Type = (Context->IsFloppy ? FloppyDiskPeripheral : DiskPeripheral);
82+
8083
return ESUCCESS;
8184
}
8285

8386
static ARC_STATUS
8487
DiskOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
8588
{
8689
DISKCONTEXT* Context;
90+
CONFIGURATION_TYPE DriveType;
8791
UCHAR DriveNumber;
8892
ULONG DrivePartition, SectorSize;
8993
ULONGLONG SectorOffset = 0;
@@ -100,19 +104,16 @@ DiskOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
100104
if (!DissectArcPath(Path, NULL, &DriveNumber, &DrivePartition))
101105
return EINVAL;
102106

103-
if (DrivePartition == 0xff)
107+
DriveType = DiskGetConfigType(DriveNumber);
108+
if (DriveType == CdromController)
104109
{
105110
/* This is a CD-ROM device */
106111
SectorSize = 2048;
107112
}
108113
else
109114
{
110-
/*
111-
* This is either a floppy disk device (DrivePartition == 0) or
112-
* a hard disk device (DrivePartition != 0 && DrivePartition != 0xFF)
113-
* but it doesn't matter which one because they both have 512 bytes
114-
* per sector.
115-
*/
115+
/* This is either a floppy disk or a hard disk device, but it doesn't
116+
* matter which one because they both have 512 bytes per sector */
116117
SectorSize = 512;
117118
}
118119

@@ -145,6 +146,7 @@ DiskOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
145146
return ENOMEM;
146147

147148
Context->DriveNumber = DriveNumber;
149+
Context->IsFloppy = (DriveType == FloppyDiskPeripheral);
148150
Context->SectorSize = SectorSize;
149151
Context->SectorOffset = SectorOffset;
150152
Context->SectorCount = SectorCount;
@@ -399,23 +401,6 @@ EnumerateHarddisks(OUT PBOOLEAN BootDriveReported)
399401
return DiskCount;
400402
}
401403

402-
// FIXME: Copied from pcdisk.c
403-
// Actually this function is REALLY PC-specific!!
404-
static BOOLEAN
405-
DiskIsDriveRemovable(UCHAR DriveNumber)
406-
{
407-
/*
408-
* Hard disks use drive numbers >= 0x80 . So if the drive number
409-
* indicates a hard disk then return FALSE.
410-
* 0x49 is our magic ramdisk drive, so return FALSE for that too.
411-
*/
412-
if ((DriveNumber >= 0x80) || (DriveNumber == 0x49))
413-
return FALSE;
414-
415-
/* The drive is a floppy diskette so return TRUE */
416-
return TRUE;
417-
}
418-
419404
static BOOLEAN
420405
DiskGetBootPath(BOOLEAN IsPxe)
421406
{
@@ -474,23 +459,25 @@ PcInitializeBootDevices(VOID)
474459
{
475460
UCHAR DiskCount;
476461
BOOLEAN BootDriveReported = FALSE;
477-
ULONG i;
462+
CONFIGURATION_TYPE DriveType;
478463

479464
DiskCount = EnumerateHarddisks(&BootDriveReported);
480465

481466
/* Initialize FrLdrBootPath, the boot path we're booting from (the "SystemPartition") */
482467
DiskGetBootPath(PxeInit());
483468

484-
/* Add it, if it's a floppy or cdrom */
469+
/* Add it, if it's a floppy or CD-ROM */
470+
DriveType = DiskGetConfigType(FrldrBootDrive);
485471
if ((FrldrBootDrive >= FIRST_BIOS_DISK && !BootDriveReported) ||
486-
DiskIsDriveRemovable(FrldrBootDrive))
472+
(DriveType == FloppyDiskPeripheral || DriveType == CdromController))
487473
{
488-
/* TODO: Check if it's really a CDROM drive */
474+
/* TODO: Check if it's really a CD-ROM drive */
489475

490476
PMASTER_BOOT_RECORD Mbr;
491477
PULONG Buffer;
492478
ULONG Checksum = 0;
493479
ULONG Signature;
480+
ULONG i;
494481

495482
/* Read the MBR */
496483
if (!MachDiskReadLogicalSectors(FrldrBootDrive, 16ULL, 1, DiskReadBuffer))

boot/freeldr/freeldr/arch/i386/pc/pcdisk.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,18 @@ DiskGetExtendedDriveParameters(
398398
return TRUE;
399399
}
400400

401+
CONFIGURATION_TYPE
402+
DiskGetConfigType(
403+
_In_ UCHAR DriveNumber)
404+
{
405+
if ((DriveNumber == FrldrBootDrive)/* && DiskIsDriveRemovable(DriveNumber) */ && (FrldrBootPartition == 0xFF))
406+
return CdromController; /* This is our El Torito boot CD-ROM */
407+
else if (DiskIsDriveRemovable(DriveNumber))
408+
return FloppyDiskPeripheral;
409+
else
410+
return DiskPeripheral;
411+
}
412+
401413
static BOOLEAN
402414
InitDriveGeometry(
403415
IN UCHAR DriveNumber,

boot/freeldr/freeldr/arch/i386/pc98/pc98disk.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,24 @@ Pc98DiskDriveNumberToDrive(IN UCHAR DriveNumber)
149149
return NULL;
150150
}
151151

152+
CONFIGURATION_TYPE
153+
DiskGetConfigType(
154+
_In_ UCHAR DriveNumber)
155+
{
156+
PPC98_DISK_DRIVE DiskDrive;
157+
158+
DiskDrive = Pc98DiskDriveNumberToDrive(DriveNumber);
159+
if (!DiskDrive)
160+
return -1; // MaximumType;
161+
162+
if (DiskDrive->Type & DRIVE_CDROM || DiskDrive->Type & DRIVE_MO)
163+
return CdromController;
164+
else if (DiskDrive->Type & DRIVE_FDD)
165+
return FloppyDiskPeripheral;
166+
else
167+
return DiskPeripheral;
168+
}
169+
152170
static inline
153171
UCHAR
154172
BytesPerSectorToSectorLengthCode(IN ULONG BytesPerSector)

boot/freeldr/freeldr/arch/i386/xbox/xboxdisk.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ XboxDiskDriveNumberToDeviceUnit(UCHAR DriveNumber)
7777
return NULL;
7878
}
7979

80+
CONFIGURATION_TYPE
81+
DiskGetConfigType(
82+
_In_ UCHAR DriveNumber)
83+
{
84+
PDEVICE_UNIT DeviceUnit;
85+
86+
DeviceUnit = XboxDiskDriveNumberToDeviceUnit(DriveNumber);
87+
if (!DeviceUnit)
88+
return -1; // MaximumType;
89+
90+
if (DeviceUnit == CdDrive) // (DeviceUnit->Flags & ATA_DEVICE_ATAPI)
91+
return CdromController;
92+
else // if (DeviceUnit == HardDrive)
93+
return DiskPeripheral;
94+
}
95+
8096
BOOLEAN
8197
XboxDiskReadLogicalSectors(
8298
IN UCHAR DriveNumber,

boot/freeldr/freeldr/arch/uefi/uefidisk.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ UefiDiskGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
132132
Information->EndingAddress.QuadPart = (Context->SectorOffset + Context->SectorCount) * Context->SectorSize;
133133
Information->CurrentAddress.QuadPart = Context->SectorNumber * Context->SectorSize;
134134

135+
Information->Type = DiskPeripheral; /* No floppy for you for now... */
136+
135137
return ESUCCESS;
136138
}
137139

@@ -491,8 +493,6 @@ UefiSetBootpath(VOID)
491493
BOOLEAN
492494
UefiInitializeBootDevices(VOID)
493495
{
494-
ULONG i = 0;
495-
496496
DiskReadBufferSize = EFI_PAGE_SIZE;
497497
DiskReadBuffer = MmAllocateMemoryWithType(DiskReadBufferSize, LoaderFirmwareTemporary);
498498
UefiSetupBlockDevices();
@@ -506,6 +506,7 @@ UefiInitializeBootDevices(VOID)
506506
PULONG Buffer;
507507
ULONG Checksum = 0;
508508
ULONG Signature;
509+
ULONG i;
509510

510511
/* Read the MBR */
511512
if (!MachDiskReadLogicalSectors(FrldrBootDrive, 16ULL, 1, DiskReadBuffer))

boot/freeldr/freeldr/disk/ramdisk.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static ARC_STATUS RamDiskGetFileInformation(ULONG FileId, FILEINFORMATION* Infor
4040
RtlZeroMemory(Information, sizeof(*Information));
4141
Information->EndingAddress.QuadPart = RamDiskImageLength;
4242
Information->CurrentAddress.QuadPart = RamDiskOffset;
43+
Information->Type = DiskPeripheral;
4344

4445
return ESUCCESS;
4546
}

boot/freeldr/freeldr/include/arch/i386/machpc98.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ typedef struct _PC98_DISK_DRIVE
141141
extern UCHAR FrldrBootDrive;
142142
extern ULONG FrldrBootPartition;
143143

144+
CONFIGURATION_TYPE
145+
DiskGetConfigType(
146+
_In_ UCHAR DriveNumber);
147+
144148
LONG DiskReportError(BOOLEAN bShowError);
145149
BOOLEAN DiskResetController(IN PPC98_DISK_DRIVE DiskDrive);
146150

boot/freeldr/freeldr/include/arch/pc/machpc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ BOOLEAN PcFindPciBios(PPCI_REGISTRY_INFO BusData);
5656
extern UCHAR FrldrBootDrive;
5757
extern ULONG FrldrBootPartition;
5858

59+
CONFIGURATION_TYPE
60+
DiskGetConfigType(
61+
_In_ UCHAR DriveNumber);
62+
5963
LONG DiskReportError(BOOLEAN bShowError);
6064
BOOLEAN DiskResetController(UCHAR DriveNumber);
6165

boot/freeldr/freeldr/lib/fs/pxe.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ static ARC_STATUS PxeGetFileInformation(ULONG FileId, FILEINFORMATION* Informati
138138
Information->EndingAddress.LowPart = _FileSize;
139139
Information->CurrentAddress.LowPart = _FilePosition;
140140

141+
Information->Type = NetworkPeripheral;
142+
141143
TRACE("PxeGetFileInformation(%lu) -> FileSize = %lu, FilePointer = 0x%lx\n",
142144
FileId, Information->EndingAddress.LowPart, Information->CurrentAddress.LowPart);
143145

0 commit comments

Comments
 (0)