2017-05-30 02:00:55 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : ReaderSCSI.cs
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2017-05-30 02:00:55 +01:00
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Core algorithms.
|
2017-05-30 02:00:55 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Contains common code for reading SCSI devices.
|
2017-05-30 02:00:55 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2017-05-30 02:00:55 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 03:50:57 +00:00
|
|
|
|
|
2017-05-30 02:00:55 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using DiscImageChef.Console;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Core.Devices
|
|
|
|
|
|
{
|
2017-12-20 02:08:37 +00:00
|
|
|
|
partial class Reader
|
2017-05-30 02:00:55 +01:00
|
|
|
|
{
|
|
|
|
|
|
// TODO: Raw reading
|
|
|
|
|
|
bool read6;
|
|
|
|
|
|
bool read10;
|
|
|
|
|
|
bool read12;
|
|
|
|
|
|
bool read16;
|
|
|
|
|
|
bool readLong10;
|
|
|
|
|
|
bool readLong16;
|
|
|
|
|
|
bool hldtstReadRaw;
|
|
|
|
|
|
bool readLongDvd;
|
|
|
|
|
|
bool plextorReadRaw;
|
|
|
|
|
|
bool syqReadLong6;
|
|
|
|
|
|
bool syqReadLong10;
|
|
|
|
|
|
bool seek6;
|
|
|
|
|
|
bool seek10;
|
|
|
|
|
|
|
|
|
|
|
|
ulong ScsiGetBlocks()
|
|
|
|
|
|
{
|
|
|
|
|
|
return ScsiGetBlockSize() ? 0 : blocks;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ScsiFindReadCommand()
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] readBuffer;
|
|
|
|
|
|
byte[] senseBuf;
|
|
|
|
|
|
double duration;
|
|
|
|
|
|
|
|
|
|
|
|
read6 = !dev.Read6(out readBuffer, out senseBuf, 0, blockSize, timeout, out duration);
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
read10 = !dev.Read10(out readBuffer, out senseBuf, 0, false, true, false, false, 0, blockSize, 0, 1,
|
|
|
|
|
|
timeout, out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
read12 = !dev.Read12(out readBuffer, out senseBuf, 0, false, true, false, false, 0, blockSize, 0, 1, false,
|
|
|
|
|
|
timeout, out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
read16 = !dev.Read16(out readBuffer, out senseBuf, 0, false, true, false, 0, blockSize, 0, 1, false,
|
|
|
|
|
|
timeout, out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
|
|
|
|
|
|
seek6 = !dev.Seek6(out senseBuf, 0, timeout, out duration);
|
|
|
|
|
|
|
|
|
|
|
|
seek10 = !dev.Seek10(out senseBuf, 0, timeout, out duration);
|
|
|
|
|
|
|
|
|
|
|
|
if(!read6 && !read10 && !read12 && !read16)
|
|
|
|
|
|
{
|
|
|
|
|
|
errorMessage = "Cannot read medium, aborting scan...";
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
|
if(read6 && !read10 && !read12 && !read16 && blocks > 0x001FFFFF + 1)
|
2017-05-30 02:00:55 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
errorMessage =
|
|
|
|
|
|
string.Format("Device only supports SCSI READ (6) but has more than {0} blocks ({1} blocks total)",
|
|
|
|
|
|
0x001FFFFF + 1, blocks);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma warning disable IDE0004 // Remove Unnecessary Cast
|
2017-12-20 17:26:28 +00:00
|
|
|
|
if(!read16 && blocks > (long)0xFFFFFFFF + (long)1)
|
2017-05-30 02:00:55 +01:00
|
|
|
|
#pragma warning restore IDE0004 // Remove Unnecessary Cast
|
|
|
|
|
|
{
|
|
|
|
|
|
#pragma warning disable IDE0004 // Remove Unnecessary Cast
|
2017-12-19 20:33:03 +00:00
|
|
|
|
errorMessage =
|
|
|
|
|
|
string.Format("Device only supports SCSI READ (10) but has more than {0} blocks ({1} blocks total)",
|
|
|
|
|
|
(long)0xFFFFFFFF + (long)1, blocks);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
#pragma warning restore IDE0004 // Remove Unnecessary Cast
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(readRaw)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool testSense;
|
|
|
|
|
|
Decoders.SCSI.FixedSense? decSense;
|
|
|
|
|
|
readRaw = false;
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(dev.ScsiType != Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice)
|
2017-05-30 02:00:55 +01:00
|
|
|
|
{
|
|
|
|
|
|
/*testSense = dev.ReadLong16(out readBuffer, out senseBuf, false, 0, 0xFFFF, timeout, out duration);
|
|
|
|
|
|
if (testSense && !dev.Error)
|
|
|
|
|
|
{
|
|
|
|
|
|
decSense = Decoders.SCSI.Sense.DecodeFixed(senseBuf);
|
|
|
|
|
|
if (decSense.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (decSense.Value.SenseKey == DiscImageChef.Decoders.SCSI.SenseKeys.IllegalRequest &&
|
|
|
|
|
|
decSense.Value.ASC == 0x24 && decSense.Value.ASCQ == 0x00)
|
|
|
|
|
|
{
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
if (decSense.Value.InformationValid && decSense.Value.ILI)
|
|
|
|
|
|
{
|
|
|
|
|
|
longBlockSize = 0xFFFF - (decSense.Value.Information & 0xFFFF);
|
|
|
|
|
|
readLong16 = !dev.ReadLong16(out readBuffer, out senseBuf, false, 0, longBlockSize, timeout, out duration);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.ReadLong10(out readBuffer, out senseBuf, false, false, 0, 0xFFFF, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
if(testSense && !dev.Error)
|
|
|
|
|
|
{
|
|
|
|
|
|
decSense = Decoders.SCSI.Sense.DecodeFixed(senseBuf);
|
|
|
|
|
|
if(decSense.HasValue)
|
|
|
|
|
|
if(decSense.Value.SenseKey == Decoders.SCSI.SenseKeys.IllegalRequest &&
|
2017-12-19 20:33:03 +00:00
|
|
|
|
decSense.Value.ASC == 0x24 && decSense.Value.ASCQ == 0x00)
|
2017-05-30 02:00:55 +01:00
|
|
|
|
{
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
if(decSense.Value.InformationValid && decSense.Value.ILI)
|
|
|
|
|
|
{
|
|
|
|
|
|
longBlockSize = 0xFFFF - (decSense.Value.Information & 0xFFFF);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
readLong10 = !dev.ReadLong10(out readBuffer, out senseBuf, false, false, 0,
|
|
|
|
|
|
(ushort)longBlockSize, timeout, out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(readRaw && longBlockSize == blockSize)
|
|
|
|
|
|
if(blockSize == 512)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
foreach(ushort testSize in new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
// Long sector sizes for floppies
|
|
|
|
|
|
514,
|
|
|
|
|
|
// Long sector sizes for SuperDisk
|
|
|
|
|
|
536, 558,
|
|
|
|
|
|
// Long sector sizes for 512-byte magneto-opticals
|
|
|
|
|
|
600, 610, 630
|
|
|
|
|
|
})
|
2017-05-30 02:00:55 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.ReadLong16(out readBuffer, out senseBuf, false, 0, testSize, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
if(!testSense && !dev.Error)
|
|
|
|
|
|
{
|
|
|
|
|
|
readLong16 = true;
|
|
|
|
|
|
longBlockSize = testSize;
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.ReadLong10(out readBuffer, out senseBuf, false, false, 0, testSize,
|
|
|
|
|
|
timeout, out duration);
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(testSense || dev.Error) continue;
|
|
|
|
|
|
|
|
|
|
|
|
readLong10 = true;
|
|
|
|
|
|
longBlockSize = testSize;
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
break;
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
else if(blockSize == 1024)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
foreach(ushort testSize in new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
// Long sector sizes for floppies
|
|
|
|
|
|
1026,
|
|
|
|
|
|
// Long sector sizes for 1024-byte magneto-opticals
|
|
|
|
|
|
1200
|
|
|
|
|
|
})
|
2017-05-30 02:00:55 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.ReadLong16(out readBuffer, out senseBuf, false, 0, testSize, timeout,
|
|
|
|
|
|
out duration);
|
2017-11-29 15:19:04 +00:00
|
|
|
|
if(!testSense && !dev.Error)
|
|
|
|
|
|
{
|
|
|
|
|
|
readLong16 = true;
|
|
|
|
|
|
longBlockSize = testSize;
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.ReadLong10(out readBuffer, out senseBuf, false, false, 0, testSize,
|
|
|
|
|
|
timeout, out duration);
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(testSense || dev.Error) continue;
|
|
|
|
|
|
|
|
|
|
|
|
readLong10 = true;
|
|
|
|
|
|
longBlockSize = testSize;
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
break;
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
else if(blockSize == 2048)
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.ReadLong16(out readBuffer, out senseBuf, false, 0, 2380, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
if(!testSense && !dev.Error)
|
|
|
|
|
|
{
|
|
|
|
|
|
readLong16 = true;
|
|
|
|
|
|
longBlockSize = 2380;
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.ReadLong10(out readBuffer, out senseBuf, false, false, 0, 2380, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
if(!testSense && !dev.Error)
|
|
|
|
|
|
{
|
|
|
|
|
|
readLong10 = true;
|
|
|
|
|
|
longBlockSize = 2380;
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(blockSize == 4096)
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.ReadLong16(out readBuffer, out senseBuf, false, 0, 4760, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
if(!testSense && !dev.Error)
|
|
|
|
|
|
{
|
|
|
|
|
|
readLong16 = true;
|
|
|
|
|
|
longBlockSize = 4760;
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.ReadLong10(out readBuffer, out senseBuf, false, false, 0, 4760, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
if(!testSense && !dev.Error)
|
|
|
|
|
|
{
|
|
|
|
|
|
readLong10 = true;
|
|
|
|
|
|
longBlockSize = 4760;
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(blockSize == 8192)
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.ReadLong16(out readBuffer, out senseBuf, false, 0, 9424, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
if(!testSense && !dev.Error)
|
|
|
|
|
|
{
|
|
|
|
|
|
readLong16 = true;
|
|
|
|
|
|
longBlockSize = 9424;
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.ReadLong10(out readBuffer, out senseBuf, false, false, 0, 9424, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
if(!testSense && !dev.Error)
|
|
|
|
|
|
{
|
|
|
|
|
|
readLong10 = true;
|
|
|
|
|
|
longBlockSize = 9424;
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!readRaw && dev.Manufacturer == "SYQUEST")
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.SyQuestReadLong10(out readBuffer, out senseBuf, 0, 0xFFFF, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
if(testSense)
|
|
|
|
|
|
{
|
|
|
|
|
|
decSense = Decoders.SCSI.Sense.DecodeFixed(senseBuf);
|
|
|
|
|
|
if(decSense.HasValue)
|
|
|
|
|
|
if(decSense.Value.SenseKey == Decoders.SCSI.SenseKeys.IllegalRequest &&
|
2017-12-19 20:33:03 +00:00
|
|
|
|
decSense.Value.ASC == 0x24 && decSense.Value.ASCQ == 0x00)
|
2017-05-30 02:00:55 +01:00
|
|
|
|
{
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
if(decSense.Value.InformationValid && decSense.Value.ILI)
|
|
|
|
|
|
{
|
|
|
|
|
|
longBlockSize = 0xFFFF - (decSense.Value.Information & 0xFFFF);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
syqReadLong10 =
|
|
|
|
|
|
!dev.SyQuestReadLong10(out readBuffer, out senseBuf, 0, longBlockSize,
|
|
|
|
|
|
timeout, out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.SyQuestReadLong6(out readBuffer, out senseBuf, 0, 0xFFFF, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
if(testSense)
|
|
|
|
|
|
{
|
|
|
|
|
|
decSense = Decoders.SCSI.Sense.DecodeFixed(senseBuf);
|
|
|
|
|
|
if(decSense.HasValue)
|
|
|
|
|
|
if(decSense.Value.SenseKey == Decoders.SCSI.SenseKeys.IllegalRequest &&
|
2017-12-19 20:33:03 +00:00
|
|
|
|
decSense.Value.ASC == 0x24 && decSense.Value.ASCQ == 0x00)
|
2017-05-30 02:00:55 +01:00
|
|
|
|
{
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
if(decSense.Value.InformationValid && decSense.Value.ILI)
|
|
|
|
|
|
{
|
|
|
|
|
|
longBlockSize = 0xFFFF - (decSense.Value.Information & 0xFFFF);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
syqReadLong6 =
|
|
|
|
|
|
!dev.SyQuestReadLong6(out readBuffer, out senseBuf, 0,
|
|
|
|
|
|
longBlockSize, timeout, out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!readRaw && blockSize == 256)
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.SyQuestReadLong6(out readBuffer, out senseBuf, 0, 262, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
if(!testSense && !dev.Error)
|
|
|
|
|
|
{
|
|
|
|
|
|
syqReadLong6 = true;
|
|
|
|
|
|
longBlockSize = 262;
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-12-21 04:43:29 +00:00
|
|
|
|
switch(dev.Manufacturer) {
|
|
|
|
|
|
case "HL-DT-ST":
|
|
|
|
|
|
hldtstReadRaw =
|
|
|
|
|
|
!dev.HlDtStReadRawDvd(out readBuffer, out senseBuf, 0, 1, timeout, out duration);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "PLEXTOR":
|
|
|
|
|
|
plextorReadRaw =
|
|
|
|
|
|
!dev.PlextorReadRawDvd(out readBuffer, out senseBuf, 0, 1, timeout, out duration);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-05-30 02:00:55 +01:00
|
|
|
|
|
|
|
|
|
|
if(hldtstReadRaw || plextorReadRaw)
|
|
|
|
|
|
{
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
longBlockSize = 2064;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// READ LONG (10) for some DVD drives
|
|
|
|
|
|
if(!readRaw && dev.Manufacturer == "MATSHITA")
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
testSense = dev.ReadLong10(out readBuffer, out senseBuf, false, false, 0, 37856, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
if(!testSense && !dev.Error)
|
|
|
|
|
|
{
|
|
|
|
|
|
readLongDvd = true;
|
|
|
|
|
|
longBlockSize = 37856;
|
|
|
|
|
|
readRaw = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(readRaw)
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(readLong16) DicConsole.WriteLine("Using SCSI READ LONG (16) command.");
|
|
|
|
|
|
else if(readLong10 || readLongDvd) DicConsole.WriteLine("Using SCSI READ LONG (10) command.");
|
|
|
|
|
|
else if(syqReadLong10) DicConsole.WriteLine("Using SyQuest READ LONG (10) command.");
|
|
|
|
|
|
else if(syqReadLong6) DicConsole.WriteLine("Using SyQuest READ LONG (6) command.");
|
|
|
|
|
|
else if(hldtstReadRaw) DicConsole.WriteLine("Using HL-DT-ST raw DVD reading.");
|
|
|
|
|
|
else if(plextorReadRaw) DicConsole.WriteLine("Using Plextor raw DVD reading.");
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
else if(read16) DicConsole.WriteLine("Using SCSI READ (16) command.");
|
|
|
|
|
|
else if(read12) DicConsole.WriteLine("Using SCSI READ (12) command.");
|
|
|
|
|
|
else if(read10) DicConsole.WriteLine("Using SCSI READ (10) command.");
|
|
|
|
|
|
else if(read6) DicConsole.WriteLine("Using SCSI READ (6) command.");
|
2017-05-30 02:00:55 +01:00
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ScsiGetBlockSize()
|
|
|
|
|
|
{
|
|
|
|
|
|
bool sense;
|
|
|
|
|
|
byte[] cmdBuf;
|
|
|
|
|
|
byte[] senseBuf;
|
|
|
|
|
|
double duration;
|
|
|
|
|
|
blocks = 0;
|
|
|
|
|
|
|
|
|
|
|
|
sense = dev.ReadCapacity(out cmdBuf, out senseBuf, timeout, out duration);
|
|
|
|
|
|
if(!sense)
|
|
|
|
|
|
{
|
2017-12-20 17:26:28 +00:00
|
|
|
|
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]);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(sense || blocks == 0xFFFFFFFF)
|
|
|
|
|
|
{
|
|
|
|
|
|
sense = dev.ReadCapacity16(out cmdBuf, out senseBuf, timeout, out duration);
|
|
|
|
|
|
|
|
|
|
|
|
if(sense && blocks == 0)
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(dev.ScsiType != Decoders.SCSI.PeripheralDeviceTypes.MultiMediaDevice)
|
2017-05-30 02:00:55 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
errorMessage = string.Format("Unable to get media capacity\n" + "{0}",
|
|
|
|
|
|
Decoders.SCSI.Sense.PrettifySense(senseBuf));
|
2017-05-30 02:00:55 +01:00
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!sense)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] temp = new byte[8];
|
|
|
|
|
|
|
|
|
|
|
|
Array.Copy(cmdBuf, 0, temp, 0, 8);
|
|
|
|
|
|
Array.Reverse(temp);
|
|
|
|
|
|
blocks = BitConverter.ToUInt64(temp, 0);
|
2017-12-20 17:26:28 +00:00
|
|
|
|
blockSize = (uint)((cmdBuf[5] << 24) + (cmdBuf[5] << 16) + (cmdBuf[6] << 8) + cmdBuf[7]);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
physicalsectorsize = blockSize;
|
|
|
|
|
|
longBlockSize = blockSize;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ScsiGetBlocksToRead(uint startWithBlocks)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool sense;
|
|
|
|
|
|
byte[] readBuffer;
|
|
|
|
|
|
byte[] senseBuf;
|
|
|
|
|
|
double duration;
|
|
|
|
|
|
blocksToRead = startWithBlocks;
|
|
|
|
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(read16)
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sense = dev.Read16(out readBuffer, out senseBuf, 0, false, true, false, 0, blockSize, 0,
|
|
|
|
|
|
blocksToRead, false, timeout, out duration);
|
|
|
|
|
|
if(dev.Error) blocksToRead /= 2;
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
else if(read12)
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
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;
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
else if(read10)
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
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;
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
else if(read6)
|
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sense = dev.Read6(out readBuffer, out senseBuf, 0, blockSize, (byte)blocksToRead, timeout,
|
|
|
|
|
|
out duration);
|
|
|
|
|
|
if(dev.Error) blocksToRead /= 2;
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(!dev.Error || blocksToRead == 1) break;
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(!dev.Error) return false;
|
2017-05-30 02:00:55 +01:00
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
blocksToRead = 1;
|
|
|
|
|
|
errorMessage = string.Format("Device error {0} trying to guess ideal transfer length.", dev.LastError);
|
|
|
|
|
|
return true;
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ScsiReadBlocks(out byte[] buffer, ulong block, uint count, out double duration)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool sense = false;
|
|
|
|
|
|
byte[] senseBuf = null;
|
|
|
|
|
|
buffer = null;
|
|
|
|
|
|
duration = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if(readRaw)
|
|
|
|
|
|
if(readLong16)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sense = dev.ReadLong16(out buffer, out senseBuf, false, block, longBlockSize, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
else if(readLong10)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sense = dev.ReadLong10(out buffer, out senseBuf, false, false, (uint)block, (ushort)longBlockSize,
|
|
|
|
|
|
timeout, out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
else if(syqReadLong10)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sense = dev.SyQuestReadLong10(out buffer, out senseBuf, (uint)block, longBlockSize, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
else if(syqReadLong6)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sense = dev.SyQuestReadLong6(out buffer, out senseBuf, (uint)block, longBlockSize, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
else if(hldtstReadRaw)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sense = dev.HlDtStReadRawDvd(out buffer, out senseBuf, (uint)block, longBlockSize, timeout,
|
|
|
|
|
|
out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
else if(plextorReadRaw)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sense = dev.PlextorReadRawDvd(out buffer, out senseBuf, (uint)block, longBlockSize, timeout,
|
|
|
|
|
|
out duration);
|
|
|
|
|
|
else return true;
|
2017-05-30 02:00:55 +01:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if(read16)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sense = dev.Read16(out buffer, out senseBuf, 0, false, true, false, block, blockSize, 0, count,
|
|
|
|
|
|
false, timeout, out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
else if(read12)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sense = dev.Read12(out buffer, out senseBuf, 0, false, false, false, false, (uint)block, blockSize,
|
|
|
|
|
|
0, count, false, timeout, out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
else if(read10)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sense = dev.Read10(out buffer, out senseBuf, 0, false, true, false, false, (uint)block, blockSize,
|
|
|
|
|
|
0, (ushort)count, timeout, out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
else if(read6)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sense = dev.Read6(out buffer, out senseBuf, (uint)block, blockSize, (byte)count, timeout,
|
|
|
|
|
|
out duration);
|
|
|
|
|
|
else return true;
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(!sense && !dev.Error) return false;
|
2017-05-30 02:00:55 +01:00
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SCSI Reader", "READ error:\n{0}",
|
|
|
|
|
|
Decoders.SCSI.Sense.PrettifySense(senseBuf));
|
|
|
|
|
|
return true;
|
2017-05-30 02:00:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ScsiSeek(ulong block, out double duration)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] senseBuf;
|
|
|
|
|
|
bool sense = true;
|
|
|
|
|
|
duration = 0;
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(seek6) sense = dev.Seek6(out senseBuf, (uint)block, timeout, out duration);
|
|
|
|
|
|
else if(seek10) sense = dev.Seek10(out senseBuf, (uint)block, timeout, out duration);
|
2017-05-30 02:00:55 +01:00
|
|
|
|
|
|
|
|
|
|
return sense;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|