mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
REFACTOR: Convert variables to auto setters.
This commit is contained in:
@@ -40,42 +40,14 @@ namespace DiscImageChef.Core.Devices
|
||||
{
|
||||
Device dev;
|
||||
uint timeout;
|
||||
ulong blocks;
|
||||
uint blocksToRead;
|
||||
string errorMessage;
|
||||
bool readRaw;
|
||||
uint blockSize;
|
||||
uint physicalsectorsize;
|
||||
uint longBlockSize;
|
||||
|
||||
internal string ErrorMessage
|
||||
{
|
||||
get { return errorMessage; }
|
||||
}
|
||||
internal ulong Blocks
|
||||
{
|
||||
get { return blocks; }
|
||||
}
|
||||
internal uint BlocksToRead
|
||||
{
|
||||
get { return blocksToRead; }
|
||||
}
|
||||
internal uint LogicalBlockSize
|
||||
{
|
||||
get { return blockSize; }
|
||||
}
|
||||
internal uint PhysicalBlockSize
|
||||
{
|
||||
get { return physicalsectorsize; }
|
||||
}
|
||||
internal uint LongBlockSize
|
||||
{
|
||||
get { return longBlockSize; }
|
||||
}
|
||||
internal bool CanReadRaw
|
||||
{
|
||||
get { return readRaw; }
|
||||
}
|
||||
internal string ErrorMessage { get; private set; }
|
||||
internal ulong Blocks { get; set; }
|
||||
internal uint BlocksToRead { get; private set; }
|
||||
internal uint LogicalBlockSize { get; private set; }
|
||||
internal uint PhysicalBlockSize { get; private set; }
|
||||
internal uint LongBlockSize { get; private set; }
|
||||
internal bool CanReadRaw { get; private set; }
|
||||
internal bool CanSeek
|
||||
{
|
||||
get { return ataSeek || seek6 || seek10; }
|
||||
@@ -89,8 +61,8 @@ namespace DiscImageChef.Core.Devices
|
||||
{
|
||||
this.dev = dev;
|
||||
this.timeout = timeout;
|
||||
blocksToRead = 64;
|
||||
readRaw = raw;
|
||||
BlocksToRead = 64;
|
||||
CanReadRaw = raw;
|
||||
|
||||
switch(dev.Type)
|
||||
{
|
||||
@@ -109,7 +81,7 @@ namespace DiscImageChef.Core.Devices
|
||||
case DeviceType.ATAPI:
|
||||
case DeviceType.SCSI: return ScsiGetBlocks();
|
||||
default:
|
||||
errorMessage = string.Format("Unknown device type {0}.", dev.Type);
|
||||
ErrorMessage = string.Format("Unknown device type {0}.", dev.Type);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -122,7 +94,7 @@ namespace DiscImageChef.Core.Devices
|
||||
case DeviceType.ATAPI:
|
||||
case DeviceType.SCSI: return ScsiFindReadCommand();
|
||||
default:
|
||||
errorMessage = string.Format("Unknown device type {0}.", dev.Type);
|
||||
ErrorMessage = string.Format("Unknown device type {0}.", dev.Type);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -135,7 +107,7 @@ namespace DiscImageChef.Core.Devices
|
||||
case DeviceType.ATAPI:
|
||||
case DeviceType.SCSI: return ScsiGetBlockSize();
|
||||
default:
|
||||
errorMessage = string.Format("Unknown device type {0}.", dev.Type);
|
||||
ErrorMessage = string.Format("Unknown device type {0}.", dev.Type);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -148,7 +120,7 @@ namespace DiscImageChef.Core.Devices
|
||||
case DeviceType.ATAPI:
|
||||
case DeviceType.SCSI: return ScsiGetBlocksToRead(startWithBlocks);
|
||||
default:
|
||||
errorMessage = string.Format("Unknown device type {0}.", dev.Type);
|
||||
ErrorMessage = string.Format("Unknown device type {0}.", dev.Type);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -160,7 +132,7 @@ namespace DiscImageChef.Core.Devices
|
||||
|
||||
internal bool ReadBlocks(out byte[] buffer, ulong block, out double duration)
|
||||
{
|
||||
return ReadBlocks(out buffer, block, blocksToRead, out duration);
|
||||
return ReadBlocks(out buffer, block, BlocksToRead, out duration);
|
||||
}
|
||||
|
||||
internal bool ReadBlocks(out byte[] buffer, ulong block, uint count, out double duration)
|
||||
|
||||
@@ -49,30 +49,15 @@ namespace DiscImageChef.Core.Devices
|
||||
bool ataReadRetry;
|
||||
bool ataReadDma;
|
||||
bool ataReadDmaRetry;
|
||||
bool lbaMode;
|
||||
ushort cylinders;
|
||||
byte heads, sectors;
|
||||
bool ataSeek;
|
||||
bool ataSeekLba;
|
||||
|
||||
Identify.IdentifyDevice ataId;
|
||||
|
||||
internal bool IsLba
|
||||
{
|
||||
get { return lbaMode; }
|
||||
}
|
||||
internal ushort Cylinders
|
||||
{
|
||||
get { return cylinders; }
|
||||
}
|
||||
internal byte Heads
|
||||
{
|
||||
get { return heads; }
|
||||
}
|
||||
internal byte Sectors
|
||||
{
|
||||
get { return sectors; }
|
||||
}
|
||||
internal bool IsLba { get; private set; }
|
||||
internal ushort Cylinders { get; private set; }
|
||||
internal byte Heads { get; private set; }
|
||||
internal byte Sectors { get; private set; }
|
||||
|
||||
(uint, byte, byte) GetDeviceChs()
|
||||
{
|
||||
@@ -80,22 +65,22 @@ namespace DiscImageChef.Core.Devices
|
||||
|
||||
if(ataId.CurrentCylinders > 0 && ataId.CurrentHeads > 0 && ataId.CurrentSectorsPerTrack > 0)
|
||||
{
|
||||
cylinders = ataId.CurrentCylinders;
|
||||
heads = (byte)ataId.CurrentHeads;
|
||||
sectors = (byte)ataId.CurrentSectorsPerTrack;
|
||||
blocks = (ulong)(cylinders * heads * sectors);
|
||||
Cylinders = ataId.CurrentCylinders;
|
||||
Heads = (byte)ataId.CurrentHeads;
|
||||
Sectors = (byte)ataId.CurrentSectorsPerTrack;
|
||||
Blocks = (ulong)(Cylinders * Heads * Sectors);
|
||||
}
|
||||
|
||||
if((ataId.CurrentCylinders != 0 && ataId.CurrentHeads != 0 && ataId.CurrentSectorsPerTrack != 0) ||
|
||||
ataId.Cylinders <= 0 || ataId.Heads <= 0 ||
|
||||
ataId.SectorsPerTrack <= 0) return (cylinders, heads, sectors);
|
||||
ataId.SectorsPerTrack <= 0) return (Cylinders, Heads, Sectors);
|
||||
|
||||
cylinders = ataId.Cylinders;
|
||||
heads = (byte)ataId.Heads;
|
||||
sectors = (byte)ataId.SectorsPerTrack;
|
||||
blocks = (ulong)(cylinders * heads * sectors);
|
||||
Cylinders = ataId.Cylinders;
|
||||
Heads = (byte)ataId.Heads;
|
||||
Sectors = (byte)ataId.SectorsPerTrack;
|
||||
Blocks = (ulong)(Cylinders * Heads * Sectors);
|
||||
|
||||
return (cylinders, heads, sectors);
|
||||
return (Cylinders, Heads, Sectors);
|
||||
}
|
||||
|
||||
ulong AtaGetBlocks()
|
||||
@@ -104,16 +89,16 @@ namespace DiscImageChef.Core.Devices
|
||||
|
||||
if(ataId.Capabilities.HasFlag(Identify.CapabilitiesBit.LBASupport))
|
||||
{
|
||||
blocks = ataId.LBASectors;
|
||||
lbaMode = true;
|
||||
Blocks = ataId.LBASectors;
|
||||
IsLba = true;
|
||||
}
|
||||
|
||||
if(!ataId.CommandSet2.HasFlag(Identify.CommandSetBit2.LBA48)) return blocks;
|
||||
if(!ataId.CommandSet2.HasFlag(Identify.CommandSetBit2.LBA48)) return Blocks;
|
||||
|
||||
blocks = ataId.LBA48Sectors;
|
||||
lbaMode = true;
|
||||
Blocks = ataId.LBA48Sectors;
|
||||
IsLba = true;
|
||||
|
||||
return blocks;
|
||||
return Blocks;
|
||||
}
|
||||
|
||||
bool AtaFindReadCommand()
|
||||
@@ -153,17 +138,17 @@ namespace DiscImageChef.Core.Devices
|
||||
sense = dev.Seek(out errorLba, 0, timeout, out duration);
|
||||
ataSeekLba = !sense && (errorLba.status & 0x27) == 0 && errorChs.error == 0;
|
||||
|
||||
if(lbaMode)
|
||||
if(IsLba)
|
||||
{
|
||||
if(blocks > 0xFFFFFFF && !ataReadLba48 && !ataReadDmaLba48)
|
||||
if(Blocks > 0xFFFFFFF && !ataReadLba48 && !ataReadDmaLba48)
|
||||
{
|
||||
errorMessage = "Device needs 48-bit LBA commands but I can't issue them... Aborting.";
|
||||
ErrorMessage = "Device needs 48-bit LBA commands but I can't issue them... Aborting.";
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!ataReadLba && !ataReadRetryLba && !ataReadDmaLba && !ataReadDmaRetryLba)
|
||||
{
|
||||
errorMessage = "Device needs 28-bit LBA commands but I can't issue them... Aborting.";
|
||||
ErrorMessage = "Device needs 28-bit LBA commands but I can't issue them... Aborting.";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -171,7 +156,7 @@ namespace DiscImageChef.Core.Devices
|
||||
{
|
||||
if(!ataRead && !ataReadRetry && !ataReadDma && !ataReadDmaRetry)
|
||||
{
|
||||
errorMessage = "Device needs CHS commands but I can't issue them... Aborting.";
|
||||
ErrorMessage = "Device needs CHS commands but I can't issue them... Aborting.";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -188,7 +173,7 @@ namespace DiscImageChef.Core.Devices
|
||||
else if(ataRead) DicConsole.WriteLine("Using ATA READ command (CHS).");
|
||||
else
|
||||
{
|
||||
errorMessage = "Could not get a working read command!";
|
||||
ErrorMessage = "Could not get a working read command!";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -200,37 +185,37 @@ namespace DiscImageChef.Core.Devices
|
||||
if((ataId.PhysLogSectorSize & 0x8000) == 0x0000 && (ataId.PhysLogSectorSize & 0x4000) == 0x4000)
|
||||
{
|
||||
if((ataId.PhysLogSectorSize & 0x1000) == 0x1000)
|
||||
if(ataId.LogicalSectorWords <= 255 || ataId.LogicalAlignment == 0xFFFF) blockSize = 512;
|
||||
else blockSize = ataId.LogicalSectorWords * 2;
|
||||
else blockSize = 512;
|
||||
if(ataId.LogicalSectorWords <= 255 || ataId.LogicalAlignment == 0xFFFF) LogicalBlockSize = 512;
|
||||
else LogicalBlockSize = ataId.LogicalSectorWords * 2;
|
||||
else LogicalBlockSize = 512;
|
||||
|
||||
if((ataId.PhysLogSectorSize & 0x2000) == 0x2000)
|
||||
{
|
||||
#pragma warning disable IDE0004 // Cast is necessary, otherwise incorrect value is created
|
||||
physicalsectorsize = blockSize * (uint)Math.Pow(2, (double)(ataId.PhysLogSectorSize & 0xF));
|
||||
PhysicalBlockSize = LogicalBlockSize * (uint)Math.Pow(2, (double)(ataId.PhysLogSectorSize & 0xF));
|
||||
#pragma warning restore IDE0004 // Cast is necessary, otherwise incorrect value is created
|
||||
}
|
||||
else physicalsectorsize = blockSize;
|
||||
else PhysicalBlockSize = LogicalBlockSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
blockSize = 512;
|
||||
physicalsectorsize = 512;
|
||||
LogicalBlockSize = 512;
|
||||
PhysicalBlockSize = 512;
|
||||
}
|
||||
|
||||
// TODO: ATA READ LONG
|
||||
longBlockSize = 0;
|
||||
LongBlockSize = 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AtaGetBlocksToRead(uint startWithBlocks)
|
||||
{
|
||||
blocksToRead = startWithBlocks;
|
||||
BlocksToRead = startWithBlocks;
|
||||
|
||||
if(!lbaMode)
|
||||
if(!IsLba)
|
||||
{
|
||||
blocksToRead = 1;
|
||||
BlocksToRead = 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -241,48 +226,48 @@ namespace DiscImageChef.Core.Devices
|
||||
double duration;
|
||||
bool error = true;
|
||||
|
||||
while(lbaMode)
|
||||
while(IsLba)
|
||||
{
|
||||
if(ataReadDmaLba48)
|
||||
{
|
||||
sense = dev.ReadDma(out cmdBuf, out errorLba48, 0, (byte)blocksToRead, timeout, out duration);
|
||||
sense = dev.ReadDma(out cmdBuf, out errorLba48, 0, (byte)BlocksToRead, timeout, out duration);
|
||||
error = !(!sense && (errorLba48.status & 0x27) == 0 && errorLba48.error == 0 && cmdBuf.Length > 0);
|
||||
}
|
||||
else if(ataReadLba48)
|
||||
{
|
||||
sense = dev.Read(out cmdBuf, out errorLba48, 0, (byte)blocksToRead, timeout, out duration);
|
||||
sense = dev.Read(out cmdBuf, out errorLba48, 0, (byte)BlocksToRead, timeout, out duration);
|
||||
error = !(!sense && (errorLba48.status & 0x27) == 0 && errorLba48.error == 0 && cmdBuf.Length > 0);
|
||||
}
|
||||
else if(ataReadDmaRetryLba)
|
||||
{
|
||||
sense = dev.ReadDma(out cmdBuf, out errorLba, true, 0, (byte)blocksToRead, timeout, out duration);
|
||||
sense = dev.ReadDma(out cmdBuf, out errorLba, true, 0, (byte)BlocksToRead, timeout, out duration);
|
||||
error = !(!sense && (errorLba.status & 0x27) == 0 && errorLba.error == 0 && cmdBuf.Length > 0);
|
||||
}
|
||||
else if(ataReadDmaLba)
|
||||
{
|
||||
sense = dev.ReadDma(out cmdBuf, out errorLba, false, 0, (byte)blocksToRead, timeout, out duration);
|
||||
sense = dev.ReadDma(out cmdBuf, out errorLba, false, 0, (byte)BlocksToRead, timeout, out duration);
|
||||
error = !(!sense && (errorLba.status & 0x27) == 0 && errorLba.error == 0 && cmdBuf.Length > 0);
|
||||
}
|
||||
else if(ataReadRetryLba)
|
||||
{
|
||||
sense = dev.Read(out cmdBuf, out errorLba, true, 0, (byte)blocksToRead, timeout, out duration);
|
||||
sense = dev.Read(out cmdBuf, out errorLba, true, 0, (byte)BlocksToRead, timeout, out duration);
|
||||
error = !(!sense && (errorLba.status & 0x27) == 0 && errorLba.error == 0 && cmdBuf.Length > 0);
|
||||
}
|
||||
else if(ataReadLba)
|
||||
{
|
||||
sense = dev.Read(out cmdBuf, out errorLba, false, 0, (byte)blocksToRead, timeout, out duration);
|
||||
sense = dev.Read(out cmdBuf, out errorLba, false, 0, (byte)BlocksToRead, timeout, out duration);
|
||||
error = !(!sense && (errorLba.status & 0x27) == 0 && errorLba.error == 0 && cmdBuf.Length > 0);
|
||||
}
|
||||
|
||||
if(error) blocksToRead /= 2;
|
||||
if(error) BlocksToRead /= 2;
|
||||
|
||||
if(!error || blocksToRead == 1) break;
|
||||
if(!error || BlocksToRead == 1) break;
|
||||
}
|
||||
|
||||
if(!error || !lbaMode) return false;
|
||||
if(!error || !IsLba) return false;
|
||||
|
||||
blocksToRead = 1;
|
||||
errorMessage = string.Format("Device error {0} trying to guess ideal transfer length.", dev.LastError);
|
||||
BlocksToRead = 1;
|
||||
ErrorMessage = string.Format("Device error {0} trying to guess ideal transfer length.", dev.LastError);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace DiscImageChef.Core.Devices
|
||||
|
||||
ulong ScsiGetBlocks()
|
||||
{
|
||||
return ScsiGetBlockSize() ? 0 : blocks;
|
||||
return ScsiGetBlockSize() ? 0 : Blocks;
|
||||
}
|
||||
|
||||
bool ScsiFindReadCommand()
|
||||
@@ -63,15 +63,15 @@ namespace DiscImageChef.Core.Devices
|
||||
byte[] senseBuf;
|
||||
double duration;
|
||||
|
||||
read6 = !dev.Read6(out readBuffer, out senseBuf, 0, blockSize, timeout, out duration);
|
||||
read6 = !dev.Read6(out readBuffer, out senseBuf, 0, LogicalBlockSize, timeout, out duration);
|
||||
|
||||
read10 = !dev.Read10(out readBuffer, out senseBuf, 0, false, true, false, false, 0, blockSize, 0, 1,
|
||||
read10 = !dev.Read10(out readBuffer, out senseBuf, 0, false, true, false, false, 0, LogicalBlockSize, 0, 1,
|
||||
timeout, out duration);
|
||||
|
||||
read12 = !dev.Read12(out readBuffer, out senseBuf, 0, false, true, false, false, 0, blockSize, 0, 1, false,
|
||||
read12 = !dev.Read12(out readBuffer, out senseBuf, 0, false, true, false, false, 0, LogicalBlockSize, 0, 1, false,
|
||||
timeout, out duration);
|
||||
|
||||
read16 = !dev.Read16(out readBuffer, out senseBuf, 0, false, true, false, 0, blockSize, 0, 1, false,
|
||||
read16 = !dev.Read16(out readBuffer, out senseBuf, 0, false, true, false, 0, LogicalBlockSize, 0, 1, false,
|
||||
timeout, out duration);
|
||||
|
||||
seek6 = !dev.Seek6(out senseBuf, 0, timeout, out duration);
|
||||
@@ -80,35 +80,35 @@ namespace DiscImageChef.Core.Devices
|
||||
|
||||
if(!read6 && !read10 && !read12 && !read16)
|
||||
{
|
||||
errorMessage = "Cannot read medium, aborting scan...";
|
||||
ErrorMessage = "Cannot read medium, aborting scan...";
|
||||
return true;
|
||||
}
|
||||
|
||||
if(read6 && !read10 && !read12 && !read16 && blocks > 0x001FFFFF + 1)
|
||||
if(read6 && !read10 && !read12 && !read16 && Blocks > 0x001FFFFF + 1)
|
||||
{
|
||||
errorMessage =
|
||||
ErrorMessage =
|
||||
string.Format("Device only supports SCSI READ (6) but has more than {0} blocks ({1} blocks total)",
|
||||
0x001FFFFF + 1, blocks);
|
||||
0x001FFFFF + 1, Blocks);
|
||||
return true;
|
||||
}
|
||||
|
||||
#pragma warning disable IDE0004 // Remove Unnecessary Cast
|
||||
if(!read16 && blocks > (long)0xFFFFFFFF + (long)1)
|
||||
if(!read16 && Blocks > (long)0xFFFFFFFF + (long)1)
|
||||
#pragma warning restore IDE0004 // Remove Unnecessary Cast
|
||||
{
|
||||
#pragma warning disable IDE0004 // Remove Unnecessary Cast
|
||||
errorMessage =
|
||||
ErrorMessage =
|
||||
string.Format("Device only supports SCSI READ (10) but has more than {0} blocks ({1} blocks total)",
|
||||
(long)0xFFFFFFFF + (long)1, blocks);
|
||||
(long)0xFFFFFFFF + (long)1, Blocks);
|
||||
#pragma warning restore IDE0004 // Remove Unnecessary Cast
|
||||
return true;
|
||||
}
|
||||
|
||||
if(readRaw)
|
||||
if(CanReadRaw)
|
||||
{
|
||||
bool testSense;
|
||||
Decoders.SCSI.FixedSense? decSense;
|
||||
readRaw = false;
|
||||
CanReadRaw = false;
|
||||
|
||||
if(dev.ScsiType != Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice)
|
||||
{
|
||||
@@ -140,18 +140,18 @@ namespace DiscImageChef.Core.Devices
|
||||
if(decSense.Value.SenseKey == Decoders.SCSI.SenseKeys.IllegalRequest &&
|
||||
decSense.Value.ASC == 0x24 && decSense.Value.ASCQ == 0x00)
|
||||
{
|
||||
readRaw = true;
|
||||
CanReadRaw = true;
|
||||
if(decSense.Value.InformationValid && decSense.Value.ILI)
|
||||
{
|
||||
longBlockSize = 0xFFFF - (decSense.Value.Information & 0xFFFF);
|
||||
LongBlockSize = 0xFFFF - (decSense.Value.Information & 0xFFFF);
|
||||
readLong10 = !dev.ReadLong10(out readBuffer, out senseBuf, false, false, 0,
|
||||
(ushort)longBlockSize, timeout, out duration);
|
||||
(ushort)LongBlockSize, timeout, out duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(readRaw && longBlockSize == blockSize)
|
||||
if(blockSize == 512)
|
||||
if(CanReadRaw && LongBlockSize == LogicalBlockSize)
|
||||
if(LogicalBlockSize == 512)
|
||||
foreach(ushort testSize in new[]
|
||||
{
|
||||
// Long sector sizes for floppies
|
||||
@@ -167,8 +167,8 @@ namespace DiscImageChef.Core.Devices
|
||||
if(!testSense && !dev.Error)
|
||||
{
|
||||
readLong16 = true;
|
||||
longBlockSize = testSize;
|
||||
readRaw = true;
|
||||
LongBlockSize = testSize;
|
||||
CanReadRaw = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -177,11 +177,11 @@ namespace DiscImageChef.Core.Devices
|
||||
if(testSense || dev.Error) continue;
|
||||
|
||||
readLong10 = true;
|
||||
longBlockSize = testSize;
|
||||
readRaw = true;
|
||||
LongBlockSize = testSize;
|
||||
CanReadRaw = true;
|
||||
break;
|
||||
}
|
||||
else if(blockSize == 1024)
|
||||
else if(LogicalBlockSize == 1024)
|
||||
foreach(ushort testSize in new[]
|
||||
{
|
||||
// Long sector sizes for floppies
|
||||
@@ -195,8 +195,8 @@ namespace DiscImageChef.Core.Devices
|
||||
if(!testSense && !dev.Error)
|
||||
{
|
||||
readLong16 = true;
|
||||
longBlockSize = testSize;
|
||||
readRaw = true;
|
||||
LongBlockSize = testSize;
|
||||
CanReadRaw = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -205,19 +205,19 @@ namespace DiscImageChef.Core.Devices
|
||||
if(testSense || dev.Error) continue;
|
||||
|
||||
readLong10 = true;
|
||||
longBlockSize = testSize;
|
||||
readRaw = true;
|
||||
LongBlockSize = testSize;
|
||||
CanReadRaw = true;
|
||||
break;
|
||||
}
|
||||
else if(blockSize == 2048)
|
||||
else if(LogicalBlockSize == 2048)
|
||||
{
|
||||
testSense = dev.ReadLong16(out readBuffer, out senseBuf, false, 0, 2380, timeout,
|
||||
out duration);
|
||||
if(!testSense && !dev.Error)
|
||||
{
|
||||
readLong16 = true;
|
||||
longBlockSize = 2380;
|
||||
readRaw = true;
|
||||
LongBlockSize = 2380;
|
||||
CanReadRaw = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -226,20 +226,20 @@ namespace DiscImageChef.Core.Devices
|
||||
if(!testSense && !dev.Error)
|
||||
{
|
||||
readLong10 = true;
|
||||
longBlockSize = 2380;
|
||||
readRaw = true;
|
||||
LongBlockSize = 2380;
|
||||
CanReadRaw = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(blockSize == 4096)
|
||||
else if(LogicalBlockSize == 4096)
|
||||
{
|
||||
testSense = dev.ReadLong16(out readBuffer, out senseBuf, false, 0, 4760, timeout,
|
||||
out duration);
|
||||
if(!testSense && !dev.Error)
|
||||
{
|
||||
readLong16 = true;
|
||||
longBlockSize = 4760;
|
||||
readRaw = true;
|
||||
LongBlockSize = 4760;
|
||||
CanReadRaw = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -248,20 +248,20 @@ namespace DiscImageChef.Core.Devices
|
||||
if(!testSense && !dev.Error)
|
||||
{
|
||||
readLong10 = true;
|
||||
longBlockSize = 4760;
|
||||
readRaw = true;
|
||||
LongBlockSize = 4760;
|
||||
CanReadRaw = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(blockSize == 8192)
|
||||
else if(LogicalBlockSize == 8192)
|
||||
{
|
||||
testSense = dev.ReadLong16(out readBuffer, out senseBuf, false, 0, 9424, timeout,
|
||||
out duration);
|
||||
if(!testSense && !dev.Error)
|
||||
{
|
||||
readLong16 = true;
|
||||
longBlockSize = 9424;
|
||||
readRaw = true;
|
||||
LongBlockSize = 9424;
|
||||
CanReadRaw = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -270,13 +270,13 @@ namespace DiscImageChef.Core.Devices
|
||||
if(!testSense && !dev.Error)
|
||||
{
|
||||
readLong10 = true;
|
||||
longBlockSize = 9424;
|
||||
readRaw = true;
|
||||
LongBlockSize = 9424;
|
||||
CanReadRaw = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!readRaw && dev.Manufacturer == "SYQUEST")
|
||||
if(!CanReadRaw && dev.Manufacturer == "SYQUEST")
|
||||
{
|
||||
testSense = dev.SyQuestReadLong10(out readBuffer, out senseBuf, 0, 0xFFFF, timeout,
|
||||
out duration);
|
||||
@@ -287,12 +287,12 @@ namespace DiscImageChef.Core.Devices
|
||||
if(decSense.Value.SenseKey == Decoders.SCSI.SenseKeys.IllegalRequest &&
|
||||
decSense.Value.ASC == 0x24 && decSense.Value.ASCQ == 0x00)
|
||||
{
|
||||
readRaw = true;
|
||||
CanReadRaw = true;
|
||||
if(decSense.Value.InformationValid && decSense.Value.ILI)
|
||||
{
|
||||
longBlockSize = 0xFFFF - (decSense.Value.Information & 0xFFFF);
|
||||
LongBlockSize = 0xFFFF - (decSense.Value.Information & 0xFFFF);
|
||||
syqReadLong10 =
|
||||
!dev.SyQuestReadLong10(out readBuffer, out senseBuf, 0, longBlockSize,
|
||||
!dev.SyQuestReadLong10(out readBuffer, out senseBuf, 0, LongBlockSize,
|
||||
timeout, out duration);
|
||||
}
|
||||
}
|
||||
@@ -307,28 +307,28 @@ namespace DiscImageChef.Core.Devices
|
||||
if(decSense.Value.SenseKey == Decoders.SCSI.SenseKeys.IllegalRequest &&
|
||||
decSense.Value.ASC == 0x24 && decSense.Value.ASCQ == 0x00)
|
||||
{
|
||||
readRaw = true;
|
||||
CanReadRaw = true;
|
||||
if(decSense.Value.InformationValid && decSense.Value.ILI)
|
||||
{
|
||||
longBlockSize = 0xFFFF - (decSense.Value.Information & 0xFFFF);
|
||||
LongBlockSize = 0xFFFF - (decSense.Value.Information & 0xFFFF);
|
||||
syqReadLong6 =
|
||||
!dev.SyQuestReadLong6(out readBuffer, out senseBuf, 0,
|
||||
longBlockSize, timeout, out duration);
|
||||
LongBlockSize, timeout, out duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!readRaw && blockSize == 256)
|
||||
if(!CanReadRaw && LogicalBlockSize == 256)
|
||||
{
|
||||
testSense = dev.SyQuestReadLong6(out readBuffer, out senseBuf, 0, 262, timeout,
|
||||
out duration);
|
||||
if(!testSense && !dev.Error)
|
||||
{
|
||||
syqReadLong6 = true;
|
||||
longBlockSize = 262;
|
||||
readRaw = true;
|
||||
LongBlockSize = 262;
|
||||
CanReadRaw = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -348,26 +348,26 @@ namespace DiscImageChef.Core.Devices
|
||||
|
||||
if(hldtstReadRaw || plextorReadRaw)
|
||||
{
|
||||
readRaw = true;
|
||||
longBlockSize = 2064;
|
||||
CanReadRaw = true;
|
||||
LongBlockSize = 2064;
|
||||
}
|
||||
|
||||
// READ LONG (10) for some DVD drives
|
||||
if(!readRaw && dev.Manufacturer == "MATSHITA")
|
||||
if(!CanReadRaw && dev.Manufacturer == "MATSHITA")
|
||||
{
|
||||
testSense = dev.ReadLong10(out readBuffer, out senseBuf, false, false, 0, 37856, timeout,
|
||||
out duration);
|
||||
if(!testSense && !dev.Error)
|
||||
{
|
||||
readLongDvd = true;
|
||||
longBlockSize = 37856;
|
||||
readRaw = true;
|
||||
LongBlockSize = 37856;
|
||||
CanReadRaw = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(readRaw)
|
||||
if(CanReadRaw)
|
||||
{
|
||||
if(readLong16) DicConsole.WriteLine("Using SCSI READ LONG (16) command.");
|
||||
else if(readLong10 || readLongDvd) DicConsole.WriteLine("Using SCSI READ LONG (10) command.");
|
||||
@@ -390,23 +390,23 @@ namespace DiscImageChef.Core.Devices
|
||||
byte[] cmdBuf;
|
||||
byte[] senseBuf;
|
||||
double duration;
|
||||
blocks = 0;
|
||||
Blocks = 0;
|
||||
|
||||
sense = dev.ReadCapacity(out cmdBuf, out senseBuf, timeout, out duration);
|
||||
if(!sense)
|
||||
{
|
||||
blocks = (ulong)((cmdBuf[0] << 24) + (cmdBuf[1] << 16) + (cmdBuf[2] << 8) + cmdBuf[3]);
|
||||
blockSize = (uint)((cmdBuf[5] << 24) + (cmdBuf[5] << 16) + (cmdBuf[6] << 8) + cmdBuf[7]);
|
||||
Blocks = (ulong)((cmdBuf[0] << 24) + (cmdBuf[1] << 16) + (cmdBuf[2] << 8) + cmdBuf[3]);
|
||||
LogicalBlockSize = (uint)((cmdBuf[5] << 24) + (cmdBuf[5] << 16) + (cmdBuf[6] << 8) + cmdBuf[7]);
|
||||
}
|
||||
|
||||
if(sense || blocks == 0xFFFFFFFF)
|
||||
if(sense || Blocks == 0xFFFFFFFF)
|
||||
{
|
||||
sense = dev.ReadCapacity16(out cmdBuf, out senseBuf, timeout, out duration);
|
||||
|
||||
if(sense && blocks == 0)
|
||||
if(sense && Blocks == 0)
|
||||
if(dev.ScsiType != Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice)
|
||||
{
|
||||
errorMessage = string.Format("Unable to get media capacity\n" + "{0}",
|
||||
ErrorMessage = string.Format("Unable to get media capacity\n" + "{0}",
|
||||
Decoders.SCSI.Sense.PrettifySense(senseBuf));
|
||||
|
||||
return true;
|
||||
@@ -418,13 +418,13 @@ namespace DiscImageChef.Core.Devices
|
||||
|
||||
Array.Copy(cmdBuf, 0, temp, 0, 8);
|
||||
Array.Reverse(temp);
|
||||
blocks = BitConverter.ToUInt64(temp, 0);
|
||||
blockSize = (uint)((cmdBuf[5] << 24) + (cmdBuf[5] << 16) + (cmdBuf[6] << 8) + cmdBuf[7]);
|
||||
Blocks = BitConverter.ToUInt64(temp, 0);
|
||||
LogicalBlockSize = (uint)((cmdBuf[5] << 24) + (cmdBuf[5] << 16) + (cmdBuf[6] << 8) + cmdBuf[7]);
|
||||
}
|
||||
}
|
||||
|
||||
physicalsectorsize = blockSize;
|
||||
longBlockSize = blockSize;
|
||||
PhysicalBlockSize = LogicalBlockSize;
|
||||
LongBlockSize = LogicalBlockSize;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -434,42 +434,42 @@ namespace DiscImageChef.Core.Devices
|
||||
byte[] readBuffer;
|
||||
byte[] senseBuf;
|
||||
double duration;
|
||||
blocksToRead = startWithBlocks;
|
||||
BlocksToRead = startWithBlocks;
|
||||
|
||||
while(true)
|
||||
{
|
||||
if(read16)
|
||||
{
|
||||
sense = dev.Read16(out readBuffer, out senseBuf, 0, false, true, false, 0, blockSize, 0,
|
||||
blocksToRead, false, timeout, out duration);
|
||||
if(dev.Error) blocksToRead /= 2;
|
||||
sense = dev.Read16(out readBuffer, out senseBuf, 0, false, true, false, 0, LogicalBlockSize, 0,
|
||||
BlocksToRead, false, timeout, out duration);
|
||||
if(dev.Error) BlocksToRead /= 2;
|
||||
}
|
||||
else if(read12)
|
||||
{
|
||||
sense = dev.Read12(out readBuffer, out senseBuf, 0, false, false, false, false, 0, blockSize, 0,
|
||||
blocksToRead, false, timeout, out duration);
|
||||
if(dev.Error) blocksToRead /= 2;
|
||||
sense = dev.Read12(out readBuffer, out senseBuf, 0, false, false, false, false, 0, LogicalBlockSize, 0,
|
||||
BlocksToRead, false, timeout, out duration);
|
||||
if(dev.Error) BlocksToRead /= 2;
|
||||
}
|
||||
else if(read10)
|
||||
{
|
||||
sense = dev.Read10(out readBuffer, out senseBuf, 0, false, true, false, false, 0, blockSize, 0,
|
||||
(ushort)blocksToRead, timeout, out duration);
|
||||
if(dev.Error) blocksToRead /= 2;
|
||||
sense = dev.Read10(out readBuffer, out senseBuf, 0, false, true, false, false, 0, LogicalBlockSize, 0,
|
||||
(ushort)BlocksToRead, timeout, out duration);
|
||||
if(dev.Error) BlocksToRead /= 2;
|
||||
}
|
||||
else if(read6)
|
||||
{
|
||||
sense = dev.Read6(out readBuffer, out senseBuf, 0, blockSize, (byte)blocksToRead, timeout,
|
||||
sense = dev.Read6(out readBuffer, out senseBuf, 0, LogicalBlockSize, (byte)BlocksToRead, timeout,
|
||||
out duration);
|
||||
if(dev.Error) blocksToRead /= 2;
|
||||
if(dev.Error) BlocksToRead /= 2;
|
||||
}
|
||||
|
||||
if(!dev.Error || blocksToRead == 1) break;
|
||||
if(!dev.Error || BlocksToRead == 1) break;
|
||||
}
|
||||
|
||||
if(!dev.Error) return false;
|
||||
|
||||
blocksToRead = 1;
|
||||
errorMessage = string.Format("Device error {0} trying to guess ideal transfer length.", dev.LastError);
|
||||
BlocksToRead = 1;
|
||||
ErrorMessage = string.Format("Device error {0} trying to guess ideal transfer length.", dev.LastError);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -480,39 +480,39 @@ namespace DiscImageChef.Core.Devices
|
||||
buffer = null;
|
||||
duration = 0;
|
||||
|
||||
if(readRaw)
|
||||
if(CanReadRaw)
|
||||
if(readLong16)
|
||||
sense = dev.ReadLong16(out buffer, out senseBuf, false, block, longBlockSize, timeout,
|
||||
sense = dev.ReadLong16(out buffer, out senseBuf, false, block, LongBlockSize, timeout,
|
||||
out duration);
|
||||
else if(readLong10)
|
||||
sense = dev.ReadLong10(out buffer, out senseBuf, false, false, (uint)block, (ushort)longBlockSize,
|
||||
sense = dev.ReadLong10(out buffer, out senseBuf, false, false, (uint)block, (ushort)LongBlockSize,
|
||||
timeout, out duration);
|
||||
else if(syqReadLong10)
|
||||
sense = dev.SyQuestReadLong10(out buffer, out senseBuf, (uint)block, longBlockSize, timeout,
|
||||
sense = dev.SyQuestReadLong10(out buffer, out senseBuf, (uint)block, LongBlockSize, timeout,
|
||||
out duration);
|
||||
else if(syqReadLong6)
|
||||
sense = dev.SyQuestReadLong6(out buffer, out senseBuf, (uint)block, longBlockSize, timeout,
|
||||
sense = dev.SyQuestReadLong6(out buffer, out senseBuf, (uint)block, LongBlockSize, timeout,
|
||||
out duration);
|
||||
else if(hldtstReadRaw)
|
||||
sense = dev.HlDtStReadRawDvd(out buffer, out senseBuf, (uint)block, longBlockSize, timeout,
|
||||
sense = dev.HlDtStReadRawDvd(out buffer, out senseBuf, (uint)block, LongBlockSize, timeout,
|
||||
out duration);
|
||||
else if(plextorReadRaw)
|
||||
sense = dev.PlextorReadRawDvd(out buffer, out senseBuf, (uint)block, longBlockSize, timeout,
|
||||
sense = dev.PlextorReadRawDvd(out buffer, out senseBuf, (uint)block, LongBlockSize, timeout,
|
||||
out duration);
|
||||
else return true;
|
||||
else
|
||||
{
|
||||
if(read16)
|
||||
sense = dev.Read16(out buffer, out senseBuf, 0, false, true, false, block, blockSize, 0, count,
|
||||
sense = dev.Read16(out buffer, out senseBuf, 0, false, true, false, block, LogicalBlockSize, 0, count,
|
||||
false, timeout, out duration);
|
||||
else if(read12)
|
||||
sense = dev.Read12(out buffer, out senseBuf, 0, false, false, false, false, (uint)block, blockSize,
|
||||
sense = dev.Read12(out buffer, out senseBuf, 0, false, false, false, false, (uint)block, LogicalBlockSize,
|
||||
0, count, false, timeout, out duration);
|
||||
else if(read10)
|
||||
sense = dev.Read10(out buffer, out senseBuf, 0, false, true, false, false, (uint)block, blockSize,
|
||||
sense = dev.Read10(out buffer, out senseBuf, 0, false, true, false, false, (uint)block, LogicalBlockSize,
|
||||
0, (ushort)count, timeout, out duration);
|
||||
else if(read6)
|
||||
sense = dev.Read6(out buffer, out senseBuf, (uint)block, blockSize, (byte)count, timeout,
|
||||
sense = dev.Read6(out buffer, out senseBuf, (uint)block, LogicalBlockSize, (byte)count, timeout,
|
||||
out duration);
|
||||
else return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user