DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
RtlZeroMemory(Information, sizeof(*Information));
- Information->EndingAddress.QuadPart = Context->SectorCount * Context->SectorSize;
- Information->CurrentAddress.QuadPart = Context->SectorNumber * Context->SectorSize;
+
+ /*
+ * The ARC specification mentions that for partitions, StartingAddress and
+ * EndingAddress are the start and end positions of the partition in terms
+ * of byte offsets from the start of the disk.
+ * CurrentAddress is the current offset into (i.e. relative to) the partition.
+ */
+ Information->StartingAddress.QuadPart = Context->SectorOffset * Context->SectorSize;
+ Information->EndingAddress.QuadPart = (Context->SectorOffset + Context->SectorCount) * Context->SectorSize;
+ Information->CurrentAddress.QuadPart = Context->SectorNumber * Context->SectorSize;
return ESUCCESS;
}
SectorOffset = PartitionTableEntry.SectorCountBeforePartition;
SectorCount = PartitionTableEntry.PartitionSectorCount;
}
-#if 0 // FIXME: Investigate
else
{
- SectorCount = 0; /* FIXME */
+ GEOMETRY Geometry;
+ if (!MachDiskGetDriveGeometry(DriveNumber, &Geometry))
+ return EINVAL;
+
+ if (SectorSize != Geometry.BytesPerSector)
+ {
+ ERR("SectorSize (%lu) != Geometry.BytesPerSector (%lu), expect problems!\n",
+ SectorSize, Geometry.BytesPerSector);
+ }
+
+ SectorOffset = 0;
+ SectorCount = (ULONGLONG)Geometry.Cylinders * Geometry.Heads * Geometry.Sectors;
}
-#endif
Context = FrLdrTempAlloc(sizeof(DISKCONTEXT), TAG_HW_DISK_CONTEXT);
if (!Context)
TotalSectors = (N + Context->SectorSize - 1) / Context->SectorSize;
MaxSectors = DiskReadBufferSize / Context->SectorSize;
- SectorOffset = Context->SectorNumber + Context->SectorOffset;
+ SectorOffset = Context->SectorOffset + Context->SectorNumber;
// If MaxSectors is 0, this will lead to infinite loop.
// In release builds assertions are disabled, however we also have sanity checks in DiskOpen()
DiskSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
{
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
+ ULONGLONG SectorNumber;
if (SeekMode != SeekAbsolute)
return EINVAL;
if (Position->LowPart & (Context->SectorSize - 1))
return EINVAL;
- Context->SectorNumber = Position->QuadPart / Context->SectorSize;
+ SectorNumber = Position->QuadPart / Context->SectorSize;
+ if (SectorNumber >= Context->SectorCount)
+ return EINVAL;
+
+ Context->SectorNumber = SectorNumber;
return ESUCCESS;
}
DiskGeometry->SectorsPerTrack = ExtGeometry.SectorsPerTrack;
DiskGeometry->NumberOfHeads = ExtGeometry.Heads;
}
- else if (MachDiskGetDriveGeometry(DriveNumber, &Geometry))
+ else if (PcDiskGetDriveGeometry(DriveNumber, &Geometry))
{
DiskGeometry->BytesPerSector = Geometry.BytesPerSector;
DiskGeometry->NumberOfCylinders = Geometry.Cylinders;
/* Get the disk geometry */
//ExtGeometry.Size = sizeof(EXTENDED_GEOMETRY);
- if (MachDiskGetDriveGeometry(DriveNumber, &Geometry))
+ if (XboxDiskGetDriveGeometry(DriveNumber, &Geometry))
{
DiskGeometry->BytesPerSector = Geometry.BytesPerSector;
DiskGeometry->NumberOfCylinders = Geometry.Cylinders;
TRACE("PcDiskReadLogicalSectorsCHS()\n");
/* Get the drive geometry */
- if (!MachDiskGetDriveGeometry(DriveNumber, &DriveGeometry) ||
- DriveGeometry.Sectors == 0 ||
- DriveGeometry.Heads == 0)
+ //
+ // TODO: Cache this information for the given drive.
+ //
+ if (!PcDiskGetDriveGeometry(DriveNumber, &DriveGeometry) ||
+ DriveGeometry.Sectors == 0 || DriveGeometry.Heads == 0)
{
return FALSE;
}
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
RtlZeroMemory(Information, sizeof(*Information));
- Information->EndingAddress.QuadPart = Context->SectorCount * Context->SectorSize;
- Information->CurrentAddress.QuadPart = Context->SectorNumber * Context->SectorSize;
+
+ /*
+ * The ARC specification mentions that for partitions, StartingAddress and
+ * EndingAddress are the start and end positions of the partition in terms
+ * of byte offsets from the start of the disk.
+ * CurrentAddress is the current offset into (i.e. relative to) the partition.
+ */
+ Information->StartingAddress.QuadPart = Context->SectorOffset * Context->SectorSize;
+ Information->EndingAddress.QuadPart = (Context->SectorOffset + Context->SectorCount) * Context->SectorSize;
+ Information->CurrentAddress.QuadPart = Context->SectorNumber * Context->SectorSize;
return ESUCCESS;
}
/* Read full sectors */
ASSERT(Context->SectorNumber < 0xFFFFFFFF);
- Lba = (ULONG)Context->SectorNumber;
+ Lba = (ULONG)(Context->SectorOffset + Context->SectorNumber);
if (FullSectors > 0)
{
Srb = ExAllocatePool(PagedPool, sizeof(SCSI_REQUEST_BLOCK));
static ARC_STATUS DiskSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
{
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
+ ULONGLONG SectorNumber;
if (SeekMode != SeekAbsolute)
return EINVAL;
if (Position->QuadPart & (Context->SectorSize - 1))
return EINVAL;
- Context->SectorNumber = Position->QuadPart / Context->SectorSize;
+ SectorNumber = Position->QuadPart / Context->SectorSize;
+ if (SectorNumber >= Context->SectorCount)
+ return EINVAL;
+
+ Context->SectorNumber = SectorNumber;
return ESUCCESS;
}
FrLdrTempFree(Volume, TAG_FAT_VOLUME);
return NULL;
}
- SectorCount.QuadPart = FileInformation.EndingAddress.QuadPart;
+ SectorCount.QuadPart = (FileInformation.EndingAddress.QuadPart - FileInformation.StartingAddress.QuadPart);
SectorCount.QuadPart /= SECTOR_SIZE;
//