Skip to content

Commit b51789c

Browse files
committed
[FREELDR] scsiport.c: Set the Information->Type field (reactos#8418)
CORE-9023 And more accurately detect and report disks: using `InquiryBuffer.DeviceType`, differentiate between "rigid" disks, floppy disks, and CD-ROM drives.
1 parent 246f2d2 commit b51789c

File tree

1 file changed

+45
-24
lines changed

1 file changed

+45
-24
lines changed

boot/freeldr/freeldr/disk/scsiport.c

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ typedef struct
6767
PVOID NonCachedExtension;
6868

6969
ULONG BusNum;
70-
ULONG MaxTargedIds;
70+
ULONG MaxTargetIds;
7171

7272
ULONG InterruptFlags;
7373

@@ -99,6 +99,7 @@ typedef struct tagDISKCONTEXT
9999
UCHAR Lun;
100100

101101
/* Device characteristics */
102+
BOOLEAN IsFloppy;
102103
ULONG SectorSize;
103104
ULONGLONG SectorOffset;
104105
ULONGLONG SectorCount;
@@ -196,6 +197,8 @@ static ARC_STATUS DiskGetFileInformation(ULONG FileId, FILEINFORMATION* Informat
196197
Information->EndingAddress.QuadPart = (Context->SectorOffset + Context->SectorCount) * Context->SectorSize;
197198
Information->CurrentAddress.QuadPart = Context->SectorNumber * Context->SectorSize;
198199

200+
Information->Type = (Context->IsFloppy ? FloppyDiskPeripheral : DiskPeripheral);
201+
199202
return ESUCCESS;
200203
}
201204

@@ -260,6 +263,7 @@ static ARC_STATUS DiskOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
260263
Context->PathId = (UCHAR)PathId;
261264
Context->TargetId = (UCHAR)TargetId;
262265
Context->Lun = (UCHAR)Lun;
266+
Context->IsFloppy = (!strstr(Path, ")cdrom(") && strstr(Path, ")fdisk("));
263267
Context->SectorSize = SectorSize;
264268
Context->SectorOffset = SectorOffset;
265269
Context->SectorCount = SectorCount;
@@ -894,13 +898,11 @@ SpiScanAdapter(
894898
/* Remember the extension */
895899
ScsiDeviceExtensions[ScsiBus] = DeviceExtension;
896900

897-
for (TargetId = 0; TargetId < DeviceExtension->MaxTargedIds; TargetId++)
901+
for (TargetId = 0; TargetId < DeviceExtension->MaxTargetIds; TargetId++)
898902
{
899-
Lun = 0;
900-
do
903+
for (Lun = 0; Lun < SCSI_MAXIMUM_LOGICAL_UNITS; Lun++)
901904
{
902-
TRACE("Scanning SCSI device %d.%d.%d\n",
903-
ScsiBus, TargetId, Lun);
905+
TRACE("Scanning SCSI device %lu.%u.%u\n", ScsiBus, TargetId, Lun);
904906

905907
Srb = ExAllocatePool(PagedPool, sizeof(SCSI_REQUEST_BLOCK));
906908
if (!Srb)
@@ -926,24 +928,43 @@ SpiScanAdapter(
926928
break;
927929
}
928930

929-
/* Device exists, create its ARC name */
930-
if (InquiryBuffer.RemovableMedia)
931+
/*
932+
* Device exists, create its ARC name.
933+
* NOTE: Other devices are not supported:
934+
* - SEQUENTIAL_ACCESS_DEVICE i.e. Tape,
935+
* - WRITE_ONCE_READ_MULTIPLE_DEVICE i.e. Worm.
936+
*/
937+
if ((InquiryBuffer.DeviceType == DIRECT_ACCESS_DEVICE) ||
938+
(InquiryBuffer.DeviceType == OPTICAL_DEVICE))
931939
{
932-
sprintf(ArcName, "scsi(%ld)cdrom(%d)fdisk(%d)",
933-
ScsiBus, TargetId, Lun);
934-
FsRegisterDevice(ArcName, &DiskVtbl);
940+
if ((InquiryBuffer.DeviceType == DIRECT_ACCESS_DEVICE) &&
941+
InquiryBuffer.RemovableMedia)
942+
{
943+
/* Floppy disk */
944+
RtlStringCbPrintfA(ArcName, sizeof(ArcName),
945+
"scsi(%lu)disk(%u)fdisk(%u)",
946+
ScsiBus, TargetId, Lun);
947+
FsRegisterDevice(ArcName, &DiskVtbl);
948+
}
949+
else
950+
{
951+
/* Other rigid disk */
952+
RtlStringCbPrintfA(ArcName, sizeof(ArcName),
953+
"scsi(%lu)disk(%u)rdisk(%u)",
954+
ScsiBus, TargetId, Lun);
955+
/* Now, check if it has partitions */
956+
SpiScanDevice(DeviceExtension, ArcName, PathId, TargetId, Lun);
957+
}
935958
}
936-
else
959+
else if (InquiryBuffer.DeviceType == READ_ONLY_DIRECT_ACCESS_DEVICE)
937960
{
938-
sprintf(ArcName, "scsi(%ld)disk(%d)rdisk(%d)",
939-
ScsiBus, TargetId, Lun);
940-
/* Now, check if it has partitions */
941-
SpiScanDevice(DeviceExtension, ArcName, PathId, TargetId, Lun);
961+
/* CD-ROM; note that the RemovableMedia bit may or may not be set */
962+
RtlStringCbPrintfA(ArcName, sizeof(ArcName),
963+
"scsi(%lu)cdrom(%u)fdisk(%u)",
964+
ScsiBus, TargetId, Lun);
965+
FsRegisterDevice(ArcName, &DiskVtbl);
942966
}
943-
944-
/* Check next LUN */
945-
Lun++;
946-
} while (Lun < SCSI_MAXIMUM_LOGICAL_UNITS);
967+
}
947968
}
948969
}
949970

@@ -1249,14 +1270,14 @@ ScsiPortInitialize(
12491270

12501271
/* Copy all stuff which we ever need from PortConfig to the DeviceExtension */
12511272
if (PortConfig.MaximumNumberOfTargets > SCSI_MAXIMUM_TARGETS_PER_BUS)
1252-
DeviceExtension->MaxTargedIds = SCSI_MAXIMUM_TARGETS_PER_BUS;
1273+
DeviceExtension->MaxTargetIds = SCSI_MAXIMUM_TARGETS_PER_BUS;
12531274
else
1254-
DeviceExtension->MaxTargedIds = PortConfig.MaximumNumberOfTargets;
1275+
DeviceExtension->MaxTargetIds = PortConfig.MaximumNumberOfTargets;
12551276

12561277
DeviceExtension->BusNum = PortConfig.SystemIoBusNumber;
12571278

1258-
TRACE("Adapter found: buses = %d, targets = %d\n",
1259-
PortConfig.NumberOfBuses, DeviceExtension->MaxTargedIds);
1279+
TRACE("Adapter found: buses = %u, targets = %u\n",
1280+
PortConfig.NumberOfBuses, DeviceExtension->MaxTargetIds);
12601281

12611282
/* Initialize adapter */
12621283
if (!DeviceExtension->HwInitialize(DeviceExtension->MiniPortDeviceExtension))

0 commit comments

Comments
 (0)