cdvdgigaherz: Fix last resort DVD size calculations

The calculated size values were off by one for single layer DVDs, off by
two for dual layer PTP DVDs, and just wrong for OTP DVDs.

Usually the IOCTL_DISK_GET_LENGTH_INFO ioctl will have succeeded already.
This commit is contained in:
Jonathan Li 2016-03-15 17:54:43 +00:00
parent 41986f4307
commit 643db78cc4
1 changed files with 12 additions and 21 deletions

View File

@ -395,37 +395,28 @@ s32 IOCtlSrc::GetSectorCount()
}
}
int sectors1=-1;
dvdrs.BlockByteOffset.QuadPart=0;
dvdrs.Format=DvdPhysicalDescriptor;
dvdrs.SessionId=sessID;
dvdrs.LayerNumber=0;
if(DeviceIoControl(device,IOCTL_DVD_READ_STRUCTURE,&dvdrs,sizeof(dvdrs),&dld, sizeof(dld), &size, NULL)!=0)
{
if(dld.ld.EndLayerZeroSector>0) // OTP?
s32 sectors1 = _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector) + 1;
if (dld.ld.NumberOfLayers == 1) // PTP, OTP
{
sectors1 = _byteswap_ulong(dld.ld.EndLayerZeroSector) - _byteswap_ulong(dld.ld.StartingDataSector);
}
else //PTP or single layer
if (dld.ld.TrackPath == 0) // PTP
{
sectors1 = _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector);
}
dvdrs.BlockByteOffset.QuadPart=0;
dvdrs.Format=DvdPhysicalDescriptor;
dvdrs.SessionId=sessID;
dvdrs.LayerNumber = 1;
if(DeviceIoControl(device,IOCTL_DVD_READ_STRUCTURE,&dvdrs,sizeof(dvdrs),&dld, sizeof(dld), &size, NULL)!=0)
if (DeviceIoControl(device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs), &dld, sizeof(dld), &size, nullptr) != 0)
{
// PTP second layer
//sectors1 += dld.ld.EndDataSector - dld.ld.StartingDataSector;
if(dld.ld.EndLayerZeroSector>0) // OTP?
{
sectors1 += _byteswap_ulong(dld.ld.EndLayerZeroSector) - _byteswap_ulong(dld.ld.StartingDataSector);
sectors1 += _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector) + 1;
}
else //PTP
}
else // OTP
{
sectors1 += _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector);
// sectors = end_sector - (~end_sector_l0 & 0xFFFFFF) + end_sector_l0 - start_sector
dld.ld.EndLayerZeroSector = _byteswap_ulong(dld.ld.EndLayerZeroSector);
sectors1 += dld.ld.EndLayerZeroSector - (~dld.ld.EndLayerZeroSector & 0x00FFFFFF) + 1;
}
}