2017-05-28 21:01:17 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : ATA.cs
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2017-05-28 21:01:17 +01:00
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Core algorithms.
|
2017-05-28 21:01:17 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Creates reports from ATA devices.
|
2017-05-28 21:01:17 +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-28 21:01:17 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 03:50:57 +00:00
|
|
|
|
|
2017-05-28 21:01:17 +01:00
|
|
|
|
using System;
|
2018-06-25 19:08:16 +01:00
|
|
|
|
using DiscImageChef.CommonTypes.Metadata;
|
2017-05-28 21:01:17 +01:00
|
|
|
|
using DiscImageChef.Console;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.Decoders.ATA;
|
2017-05-28 21:01:17 +01:00
|
|
|
|
using DiscImageChef.Devices;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Core.Devices.Report
|
|
|
|
|
|
{
|
2018-11-25 19:13:21 +00:00
|
|
|
|
public partial class DeviceReport
|
2017-05-28 21:01:17 +01:00
|
|
|
|
{
|
2018-11-25 19:13:21 +00:00
|
|
|
|
public TestedMedia ReportAtaMedia()
|
2017-05-28 21:01:17 +01:00
|
|
|
|
{
|
2018-11-25 19:13:21 +00:00
|
|
|
|
TestedMedia mediaTest = new TestedMedia();
|
|
|
|
|
|
DicConsole.Write("Please write a description of the media type and press enter: ");
|
|
|
|
|
|
mediaTest.MediumTypeName = System.Console.ReadLine();
|
|
|
|
|
|
DicConsole.Write("Please write the media model and press enter: ");
|
|
|
|
|
|
mediaTest.Model = System.Console.ReadLine();
|
2017-05-28 21:01:17 +01:00
|
|
|
|
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.MediaIsRecognized = true;
|
2017-05-28 21:01:17 +01:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Querying ATA IDENTIFY...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
dev.AtaIdentify(out byte[] buffer, out _, dev.Timeout, out _);
|
2017-05-28 21:01:17 +01:00
|
|
|
|
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.IdentifyData = buffer;
|
|
|
|
|
|
mediaTest.IdentifyDevice = Identify.Decode(buffer);
|
2017-05-28 21:01:17 +01:00
|
|
|
|
|
2018-11-25 19:13:21 +00:00
|
|
|
|
if(mediaTest.IdentifyDevice.HasValue)
|
2017-12-23 01:46:08 +00:00
|
|
|
|
{
|
2018-11-25 19:13:21 +00:00
|
|
|
|
Identify.IdentifyDevice ataId = mediaTest.IdentifyDevice.Value;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
2018-11-25 19:13:21 +00:00
|
|
|
|
if(ataId.UnformattedBPT != 0) mediaTest.UnformattedBPT = ataId.UnformattedBPT;
|
2018-01-21 21:56:09 +00:00
|
|
|
|
|
2018-11-25 19:13:21 +00:00
|
|
|
|
if(ataId.UnformattedBPS != 0) mediaTest.UnformattedBPS = ataId.UnformattedBPS;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
2017-12-23 01:46:08 +00:00
|
|
|
|
if(ataId.Cylinders > 0 && ataId.Heads > 0 && ataId.SectorsPerTrack > 0)
|
|
|
|
|
|
{
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.CHS = new Chs
|
2017-12-21 17:10:37 +00:00
|
|
|
|
{
|
2018-11-25 17:47:14 +00:00
|
|
|
|
Cylinders = ataId.Cylinders, Heads = ataId.Heads, Sectors = ataId.SectorsPerTrack
|
2017-12-23 01:46:08 +00:00
|
|
|
|
};
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.Blocks = (ulong)(ataId.Cylinders * ataId.Heads * ataId.SectorsPerTrack);
|
2017-12-23 01:46:08 +00:00
|
|
|
|
}
|
2017-05-28 21:01:17 +01:00
|
|
|
|
|
2017-12-23 01:46:08 +00:00
|
|
|
|
if(ataId.CurrentCylinders > 0 && ataId.CurrentHeads > 0 && ataId.CurrentSectorsPerTrack > 0)
|
|
|
|
|
|
{
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.CurrentCHS = new Chs
|
2017-12-21 17:10:37 +00:00
|
|
|
|
{
|
2017-12-23 01:46:08 +00:00
|
|
|
|
Cylinders = ataId.CurrentCylinders,
|
2018-01-21 21:56:09 +00:00
|
|
|
|
Heads = ataId.CurrentHeads,
|
|
|
|
|
|
Sectors = ataId.CurrentSectorsPerTrack
|
2017-12-23 01:46:08 +00:00
|
|
|
|
};
|
2018-11-25 19:13:21 +00:00
|
|
|
|
if(mediaTest.Blocks == 0)
|
|
|
|
|
|
mediaTest.Blocks =
|
|
|
|
|
|
(ulong)(ataId.CurrentCylinders * ataId.CurrentHeads * ataId.CurrentSectorsPerTrack);
|
2017-12-23 01:46:08 +00:00
|
|
|
|
}
|
2017-05-28 21:01:17 +01:00
|
|
|
|
|
2017-12-23 01:46:08 +00:00
|
|
|
|
if(ataId.Capabilities.HasFlag(Identify.CapabilitiesBit.LBASupport))
|
|
|
|
|
|
{
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.LBASectors = ataId.LBASectors;
|
|
|
|
|
|
mediaTest.Blocks = ataId.LBASectors;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
}
|
2017-05-28 21:01:17 +01:00
|
|
|
|
|
2017-12-23 01:46:08 +00:00
|
|
|
|
if(ataId.CommandSet2.HasFlag(Identify.CommandSetBit2.LBA48))
|
|
|
|
|
|
{
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.LBA48Sectors = ataId.LBA48Sectors;
|
|
|
|
|
|
mediaTest.Blocks = ataId.LBA48Sectors;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
}
|
2017-05-28 21:01:17 +01:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
if(ataId.NominalRotationRate != 0x0000 && ataId.NominalRotationRate != 0xFFFF)
|
2017-12-23 01:46:08 +00:00
|
|
|
|
if(ataId.NominalRotationRate == 0x0001)
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.SolidStateDevice = true;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
else
|
2017-05-28 21:01:17 +01:00
|
|
|
|
{
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.SolidStateDevice = false;
|
|
|
|
|
|
mediaTest.NominalRotationRate = ataId.NominalRotationRate;
|
2017-05-28 21:01:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-23 01:46:08 +00:00
|
|
|
|
uint logicalsectorsize;
|
|
|
|
|
|
uint physicalsectorsize;
|
|
|
|
|
|
if((ataId.PhysLogSectorSize & 0x8000) == 0x0000 && (ataId.PhysLogSectorSize & 0x4000) == 0x4000)
|
|
|
|
|
|
{
|
|
|
|
|
|
if((ataId.PhysLogSectorSize & 0x1000) == 0x1000)
|
2018-06-22 08:08:38 +01:00
|
|
|
|
if(ataId.LogicalSectorWords <= 255 || ataId.LogicalAlignment == 0xFFFF)
|
2018-01-21 21:56:09 +00:00
|
|
|
|
logicalsectorsize = 512;
|
|
|
|
|
|
else
|
|
|
|
|
|
logicalsectorsize = ataId.LogicalSectorWords * 2;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
else logicalsectorsize = 512;
|
2017-05-28 21:01:17 +01:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
if((ataId.PhysLogSectorSize & 0x2000) == 0x2000)
|
2018-11-25 19:13:21 +00:00
|
|
|
|
physicalsectorsize = (uint)(logicalsectorsize * ((1 << ataId.PhysLogSectorSize) & 0xF));
|
2017-12-23 01:46:08 +00:00
|
|
|
|
else physicalsectorsize = logicalsectorsize;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-01-21 21:56:09 +00:00
|
|
|
|
logicalsectorsize = 512;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
physicalsectorsize = 512;
|
|
|
|
|
|
}
|
2017-06-04 05:06:49 +01:00
|
|
|
|
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.BlockSize = logicalsectorsize;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
if(physicalsectorsize != logicalsectorsize)
|
|
|
|
|
|
{
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.PhysicalBlockSize = physicalsectorsize;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
if((ataId.LogicalAlignment & 0x8000) == 0x0000 && (ataId.LogicalAlignment & 0x4000) == 0x4000)
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.LogicalAlignment = (ushort)(ataId.LogicalAlignment & 0x3FFF);
|
2017-12-23 01:46:08 +00:00
|
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
2017-12-23 01:46:08 +00:00
|
|
|
|
if(ataId.EccBytes != 0x0000 && ataId.EccBytes != 0xFFFF)
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.LongBlockSize = logicalsectorsize + ataId.EccBytes;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
if(ataId.UnformattedBPS > logicalsectorsize &&
|
2018-11-25 19:13:21 +00:00
|
|
|
|
(!(ataId.EccBytes != 0x0000 && ataId.EccBytes != 0xFFFF) || mediaTest.LongBlockSize == 516))
|
|
|
|
|
|
mediaTest.LongBlockSize = ataId.UnformattedBPS;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
2018-01-21 21:56:09 +00:00
|
|
|
|
if(ataId.CommandSet3.HasFlag(Identify.CommandSetBit3.MustBeSet) &&
|
2017-12-23 01:46:08 +00:00
|
|
|
|
!ataId.CommandSet3.HasFlag(Identify.CommandSetBit3.MustBeClear) &&
|
|
|
|
|
|
ataId.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.MediaSerial))
|
|
|
|
|
|
{
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.CanReadMediaSerial = true;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
if(!string.IsNullOrWhiteSpace(ataId.MediaManufacturer))
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.Manufacturer = ataId.MediaManufacturer;
|
2017-12-21 17:10:37 +00:00
|
|
|
|
}
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
ulong checkCorrectRead = BitConverter.ToUInt64(buffer, 0);
|
2018-01-21 21:56:09 +00:00
|
|
|
|
bool sense;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ SECTOR(S) in CHS mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.Read(out byte[] readBuf, out AtaErrorRegistersChs errorChs, false, 0, 0, 1, 1, dev.Timeout,
|
2017-12-23 17:41:23 +00:00
|
|
|
|
out _);
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.SupportsReadSectors = !sense && (errorChs.Status & 0x01) != 0x01 && errorChs.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report",
|
|
|
|
|
|
"Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense,
|
|
|
|
|
|
errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) mediaTest.ReadSectorsData = readBuf;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ SECTOR(S) RETRY in CHS mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.Read(out readBuf, out errorChs, true, 0, 0, 1, 1, dev.Timeout, out _);
|
|
|
|
|
|
mediaTest.SupportsReadRetry = !sense && (errorChs.Status & 0x01) != 0x01 && errorChs.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report",
|
|
|
|
|
|
"Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense,
|
|
|
|
|
|
errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) mediaTest.ReadSectorsRetryData = readBuf;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ DMA in CHS mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.ReadDma(out readBuf, out errorChs, false, 0, 0, 1, 1, dev.Timeout, out _);
|
|
|
|
|
|
mediaTest.SupportsReadDma = !sense && (errorChs.Status & 0x01) != 0x01 && errorChs.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report",
|
|
|
|
|
|
"Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense,
|
|
|
|
|
|
errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) mediaTest.ReadDmaData = readBuf;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ DMA RETRY in CHS mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.ReadDma(out readBuf, out errorChs, true, 0, 0, 1, 1, dev.Timeout, out _);
|
|
|
|
|
|
mediaTest.SupportsReadDmaRetry = !sense && (errorChs.Status & 0x01) != 0x01 && errorChs.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report",
|
|
|
|
|
|
"Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense,
|
|
|
|
|
|
errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) mediaTest.ReadDmaRetryData = readBuf;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying SEEK in CHS mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.Seek(out errorChs, 0, 0, 1, dev.Timeout, out _);
|
|
|
|
|
|
mediaTest.SupportsSeek = !sense && (errorChs.Status & 0x01) != 0x01 && errorChs.Error == 0;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}", sense,
|
|
|
|
|
|
errorChs.Status, errorChs.Error);
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ SECTOR(S) in LBA mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.Read(out readBuf, out AtaErrorRegistersLba28 errorLba, false, 0, 1, dev.Timeout, out _);
|
|
|
|
|
|
mediaTest.SupportsReadLba = !sense && (errorLba.Status & 0x01) != 0x01 && errorLba.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report",
|
|
|
|
|
|
"Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense,
|
2018-11-25 19:13:21 +00:00
|
|
|
|
errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) mediaTest.ReadLbaData = readBuf;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ SECTOR(S) RETRY in LBA mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.Read(out readBuf, out errorLba, true, 0, 1, dev.Timeout, out _);
|
|
|
|
|
|
mediaTest.SupportsReadRetryLba = !sense && (errorLba.Status & 0x01) != 0x01 && errorLba.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report",
|
|
|
|
|
|
"Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense,
|
2018-11-25 19:13:21 +00:00
|
|
|
|
errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) mediaTest.ReadRetryLbaData = readBuf;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ DMA in LBA mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.ReadDma(out readBuf, out errorLba, false, 0, 1, dev.Timeout, out _);
|
|
|
|
|
|
mediaTest.SupportsReadDmaLba = !sense && (errorLba.Status & 0x01) != 0x01 && errorLba.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report",
|
|
|
|
|
|
"Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense,
|
2018-11-25 19:13:21 +00:00
|
|
|
|
errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) mediaTest.ReadDmaLbaData = readBuf;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ DMA RETRY in LBA mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.ReadDma(out readBuf, out errorLba, true, 0, 1, dev.Timeout, out _);
|
|
|
|
|
|
mediaTest.SupportsReadDmaRetryLba = !sense && (errorLba.Status & 0x01) != 0x01 && errorLba.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report",
|
|
|
|
|
|
"Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense,
|
2018-11-25 19:13:21 +00:00
|
|
|
|
errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) mediaTest.ReadDmaRetryLbaData = readBuf;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying SEEK in LBA mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.Seek(out errorLba, 0, dev.Timeout, out _);
|
|
|
|
|
|
mediaTest.SupportsSeekLba = !sense && (errorLba.Status & 0x01) != 0x01 && errorLba.Error == 0;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}", sense,
|
2018-11-25 19:13:21 +00:00
|
|
|
|
errorChs.Status, errorChs.Error);
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ SECTOR(S) in LBA48 mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.Read(out readBuf, out AtaErrorRegistersLba48 errorLba48, 0, 1, dev.Timeout, out _);
|
|
|
|
|
|
mediaTest.SupportsReadLba48 = !sense && (errorLba48.Status & 0x01) != 0x01 && errorLba48.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report",
|
|
|
|
|
|
"Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense,
|
2018-11-25 19:13:21 +00:00
|
|
|
|
errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) mediaTest.ReadLba48Data = readBuf;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ DMA in LBA48 mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.ReadDma(out readBuf, out errorLba48, 0, 1, dev.Timeout, out _);
|
|
|
|
|
|
mediaTest.SupportsReadDmaLba48 = !sense && (errorLba48.Status & 0x01) != 0x01 &&
|
|
|
|
|
|
errorLba48.Error == 0 && readBuf.Length > 0;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report",
|
|
|
|
|
|
"Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense,
|
2018-11-25 19:13:21 +00:00
|
|
|
|
errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) mediaTest.ReadDmaLba48Data = readBuf;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
2018-01-21 21:56:09 +00:00
|
|
|
|
// Send SET FEATURES before sending READ LONG commands, retrieve IDENTIFY again and
|
|
|
|
|
|
// check if ECC size changed. Sector is set to 1 because without it most drives just return
|
|
|
|
|
|
// CORRECTABLE ERROR for this command.
|
2018-11-25 19:13:21 +00:00
|
|
|
|
dev.SetFeatures(out _, AtaFeatures.EnableReadLongVendorLength, 0, 0, 1, 0, dev.Timeout, out _);
|
2018-01-21 21:56:09 +00:00
|
|
|
|
|
2018-11-25 19:13:21 +00:00
|
|
|
|
dev.AtaIdentify(out buffer, out _, dev.Timeout, out _);
|
2018-01-21 21:56:09 +00:00
|
|
|
|
if(Identify.Decode(buffer).HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
ataId = Identify.Decode(buffer).Value;
|
|
|
|
|
|
if(ataId.EccBytes != 0x0000 && ataId.EccBytes != 0xFFFF)
|
2018-11-25 19:13:21 +00:00
|
|
|
|
mediaTest.LongBlockSize = logicalsectorsize + ataId.EccBytes;
|
2018-01-21 21:56:09 +00:00
|
|
|
|
|
|
|
|
|
|
if(ataId.UnformattedBPS > logicalsectorsize &&
|
2018-11-25 19:13:21 +00:00
|
|
|
|
(!(ataId.EccBytes != 0x0000 && ataId.EccBytes != 0xFFFF) || mediaTest.LongBlockSize == 516))
|
|
|
|
|
|
mediaTest.LongBlockSize = ataId.UnformattedBPS;
|
2018-01-21 21:56:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.WriteLine("Trying READ LONG in CHS mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.ReadLong(out readBuf, out errorChs, false, 0, 0, 1, mediaTest.LongBlockSize ?? 0,
|
|
|
|
|
|
dev.Timeout, out _);
|
|
|
|
|
|
mediaTest.SupportsReadLong = !sense && (errorChs.Status & 0x01) != 0x01 && errorChs.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0 &&
|
|
|
|
|
|
BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report",
|
|
|
|
|
|
"Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense,
|
|
|
|
|
|
errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) mediaTest.ReadLongData = readBuf;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ LONG RETRY in CHS mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.ReadLong(out readBuf, out errorChs, true, 0, 0, 1, mediaTest.LongBlockSize ?? 0,
|
|
|
|
|
|
dev.Timeout, out _);
|
|
|
|
|
|
mediaTest.SupportsReadLongRetry = !sense && (errorChs.Status & 0x01) != 0x01 && errorChs.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0 &&
|
|
|
|
|
|
BitConverter.ToUInt64(readBuf, 0) !=
|
|
|
|
|
|
checkCorrectRead;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report",
|
|
|
|
|
|
"Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense,
|
|
|
|
|
|
errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) mediaTest.ReadLongRetryData = readBuf;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ LONG in LBA mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.ReadLong(out readBuf, out errorLba, false, 0, mediaTest.LongBlockSize ?? 0, dev.Timeout,
|
|
|
|
|
|
out _);
|
|
|
|
|
|
mediaTest.SupportsReadLongLba = !sense && (errorLba.Status & 0x01) != 0x01 && errorLba.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0 &&
|
|
|
|
|
|
BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report",
|
|
|
|
|
|
"Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense,
|
2018-11-25 19:13:21 +00:00
|
|
|
|
errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) mediaTest.ReadLongLbaData = readBuf;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ LONG RETRY in LBA mode...");
|
2018-11-25 19:13:21 +00:00
|
|
|
|
sense = dev.ReadLong(out readBuf, out errorLba, true, 0, mediaTest.LongBlockSize ?? 0, dev.Timeout,
|
|
|
|
|
|
out _);
|
|
|
|
|
|
mediaTest.SupportsReadLongRetryLba = !sense && (errorLba.Status & 0x01) != 0x01 &&
|
|
|
|
|
|
errorLba.Error == 0 && readBuf.Length > 0 &&
|
|
|
|
|
|
BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead;
|
2017-12-23 01:46:08 +00:00
|
|
|
|
DicConsole.DebugWriteLine("ATA Report",
|
|
|
|
|
|
"Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense,
|
2018-11-25 19:13:21 +00:00
|
|
|
|
errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) mediaTest.ReadLongRetryLbaData = readBuf;
|
2017-05-28 21:01:17 +01:00
|
|
|
|
}
|
2018-11-25 19:13:21 +00:00
|
|
|
|
else mediaTest.MediaIsRecognized = false;
|
|
|
|
|
|
|
|
|
|
|
|
return mediaTest;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates a report of an ATA device
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public TestedMedia ReportAta(Identify.IdentifyDevice ataId)
|
|
|
|
|
|
{
|
|
|
|
|
|
TestedMedia capabilities = new TestedMedia();
|
|
|
|
|
|
|
|
|
|
|
|
if(ataId.UnformattedBPT != 0) capabilities.UnformattedBPT = ataId.UnformattedBPT;
|
|
|
|
|
|
|
|
|
|
|
|
if(ataId.UnformattedBPS != 0) capabilities.UnformattedBPS = ataId.UnformattedBPS;
|
|
|
|
|
|
|
|
|
|
|
|
if(ataId.Cylinders > 0 && ataId.Heads > 0 && ataId.SectorsPerTrack > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
capabilities.CHS = new Chs
|
|
|
|
|
|
{
|
|
|
|
|
|
Cylinders = ataId.Cylinders, Heads = ataId.Heads, Sectors = ataId.SectorsPerTrack
|
|
|
|
|
|
};
|
|
|
|
|
|
capabilities.Blocks = (ulong)(ataId.Cylinders * ataId.Heads * ataId.SectorsPerTrack);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(ataId.CurrentCylinders > 0 && ataId.CurrentHeads > 0 && ataId.CurrentSectorsPerTrack > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
capabilities.CurrentCHS = new Chs
|
|
|
|
|
|
{
|
|
|
|
|
|
Cylinders = ataId.CurrentCylinders,
|
|
|
|
|
|
Heads = ataId.CurrentHeads,
|
|
|
|
|
|
Sectors = ataId.CurrentSectorsPerTrack
|
|
|
|
|
|
};
|
|
|
|
|
|
capabilities.Blocks =
|
|
|
|
|
|
(ulong)(ataId.CurrentCylinders * ataId.CurrentHeads * ataId.CurrentSectorsPerTrack);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(ataId.Capabilities.HasFlag(Identify.CapabilitiesBit.LBASupport))
|
|
|
|
|
|
{
|
|
|
|
|
|
capabilities.LBASectors = ataId.LBASectors;
|
|
|
|
|
|
capabilities.Blocks = ataId.LBASectors;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(ataId.CommandSet2.HasFlag(Identify.CommandSetBit2.LBA48))
|
|
|
|
|
|
{
|
|
|
|
|
|
capabilities.LBA48Sectors = ataId.LBA48Sectors;
|
|
|
|
|
|
capabilities.Blocks = ataId.LBA48Sectors;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(ataId.NominalRotationRate != 0x0000 && ataId.NominalRotationRate != 0xFFFF)
|
|
|
|
|
|
if(ataId.NominalRotationRate == 0x0001)
|
|
|
|
|
|
capabilities.SolidStateDevice = true;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
capabilities.SolidStateDevice = false;
|
|
|
|
|
|
capabilities.NominalRotationRate = ataId.NominalRotationRate;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint logicalsectorsize;
|
|
|
|
|
|
uint physicalsectorsize;
|
|
|
|
|
|
if((ataId.PhysLogSectorSize & 0x8000) == 0x0000 && (ataId.PhysLogSectorSize & 0x4000) == 0x4000)
|
|
|
|
|
|
{
|
|
|
|
|
|
if((ataId.PhysLogSectorSize & 0x1000) == 0x1000)
|
|
|
|
|
|
if(ataId.LogicalSectorWords <= 255 || ataId.LogicalAlignment == 0xFFFF)
|
|
|
|
|
|
logicalsectorsize = 512;
|
|
|
|
|
|
else
|
|
|
|
|
|
logicalsectorsize = ataId.LogicalSectorWords * 2;
|
|
|
|
|
|
else logicalsectorsize = 512;
|
|
|
|
|
|
|
|
|
|
|
|
if((ataId.PhysLogSectorSize & 0x2000) == 0x2000)
|
|
|
|
|
|
physicalsectorsize = logicalsectorsize * (uint)Math.Pow(2, ataId.PhysLogSectorSize & 0xF);
|
|
|
|
|
|
else physicalsectorsize = logicalsectorsize;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
logicalsectorsize = 512;
|
|
|
|
|
|
physicalsectorsize = 512;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
capabilities.BlockSize = logicalsectorsize;
|
|
|
|
|
|
if(physicalsectorsize != logicalsectorsize)
|
|
|
|
|
|
{
|
|
|
|
|
|
capabilities.PhysicalBlockSize = physicalsectorsize;
|
|
|
|
|
|
|
|
|
|
|
|
if((ataId.LogicalAlignment & 0x8000) == 0x0000 && (ataId.LogicalAlignment & 0x4000) == 0x4000)
|
|
|
|
|
|
capabilities.LogicalAlignment = (ushort)(ataId.LogicalAlignment & 0x3FFF);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(ataId.EccBytes != 0x0000 && ataId.EccBytes != 0xFFFF)
|
|
|
|
|
|
capabilities.LongBlockSize = logicalsectorsize + ataId.EccBytes;
|
|
|
|
|
|
|
|
|
|
|
|
if(ataId.UnformattedBPS > logicalsectorsize &&
|
|
|
|
|
|
(!(ataId.EccBytes != 0x0000 && ataId.EccBytes != 0xFFFF) || capabilities.LongBlockSize == 516))
|
|
|
|
|
|
capabilities.LongBlockSize = ataId.UnformattedBPS;
|
|
|
|
|
|
|
|
|
|
|
|
if(ataId.CommandSet3.HasFlag(Identify.CommandSetBit3.MustBeSet) &&
|
|
|
|
|
|
!ataId.CommandSet3.HasFlag(Identify.CommandSetBit3.MustBeClear) &&
|
|
|
|
|
|
ataId.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.MediaSerial))
|
|
|
|
|
|
{
|
|
|
|
|
|
capabilities.CanReadMediaSerial = true;
|
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(ataId.MediaManufacturer))
|
|
|
|
|
|
capabilities.Manufacturer = ataId.MediaManufacturer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ulong checkCorrectRead = 0;
|
|
|
|
|
|
bool sense;
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ SECTOR(S) in CHS mode...");
|
|
|
|
|
|
sense = dev.Read(out byte[] readBuf, out AtaErrorRegistersChs errorChs, false, 0, 0, 1, 1, dev.Timeout,
|
|
|
|
|
|
out _);
|
|
|
|
|
|
capabilities.SupportsReadSectors = !sense && (errorChs.Status & 0x01) != 0x01 && errorChs.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}",
|
|
|
|
|
|
sense, errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) capabilities.ReadSectorsData = readBuf;
|
2018-11-25 19:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ SECTOR(S) RETRY in CHS mode...");
|
|
|
|
|
|
sense = dev.Read(out readBuf, out errorChs, true, 0, 0, 1, 1, dev.Timeout, out _);
|
|
|
|
|
|
capabilities.SupportsReadRetry =
|
|
|
|
|
|
!sense && (errorChs.Status & 0x01) != 0x01 && errorChs.Error == 0 && readBuf.Length > 0;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}",
|
|
|
|
|
|
sense, errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) capabilities.ReadSectorsRetryData = readBuf;
|
2018-11-25 19:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ DMA in CHS mode...");
|
|
|
|
|
|
sense = dev.ReadDma(out readBuf, out errorChs, false, 0, 0, 1, 1, dev.Timeout, out _);
|
|
|
|
|
|
capabilities.SupportsReadDma =
|
|
|
|
|
|
!sense && (errorChs.Status & 0x01) != 0x01 && errorChs.Error == 0 && readBuf.Length > 0;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}",
|
|
|
|
|
|
sense, errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) capabilities.ReadDmaData = readBuf;
|
2018-11-25 19:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ DMA RETRY in CHS mode...");
|
|
|
|
|
|
sense = dev.ReadDma(out readBuf, out errorChs, true, 0, 0, 1, 1, dev.Timeout, out _);
|
|
|
|
|
|
capabilities.SupportsReadDmaRetry = !sense && (errorChs.Status & 0x01) != 0x01 && errorChs.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}",
|
|
|
|
|
|
sense, errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) capabilities.ReadDmaRetryData = readBuf;
|
2018-11-25 19:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying SEEK in CHS mode...");
|
|
|
|
|
|
sense = dev.Seek(out errorChs, 0, 0, 1, dev.Timeout, out _);
|
|
|
|
|
|
capabilities.SupportsSeek = !sense && (errorChs.Status & 0x01) != 0x01 && errorChs.Error == 0;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}", sense,
|
|
|
|
|
|
errorChs.Status, errorChs.Error);
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ SECTOR(S) in LBA mode...");
|
|
|
|
|
|
sense = dev.Read(out readBuf, out AtaErrorRegistersLba28 errorLba, false, 0, 1, dev.Timeout, out _);
|
|
|
|
|
|
capabilities.SupportsReadLba =
|
|
|
|
|
|
!sense && (errorLba.Status & 0x01) != 0x01 && errorLba.Error == 0 && readBuf.Length > 0;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}",
|
|
|
|
|
|
sense, errorLba.Status, errorLba.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) capabilities.ReadLbaData = readBuf;
|
2018-11-25 19:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ SECTOR(S) RETRY in LBA mode...");
|
|
|
|
|
|
sense = dev.Read(out readBuf, out errorLba, true, 0, 1, dev.Timeout, out _);
|
|
|
|
|
|
capabilities.SupportsReadRetryLba = !sense && (errorLba.Status & 0x01) != 0x01 && errorLba.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}",
|
|
|
|
|
|
sense, errorLba.Status, errorLba.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) capabilities.ReadRetryLbaData = readBuf;
|
2018-11-25 19:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ DMA in LBA mode...");
|
|
|
|
|
|
sense = dev.ReadDma(out readBuf, out errorLba, false, 0, 1, dev.Timeout, out _);
|
|
|
|
|
|
capabilities.SupportsReadDmaLba = !sense && (errorLba.Status & 0x01) != 0x01 && errorLba.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}",
|
|
|
|
|
|
sense, errorLba.Status, errorLba.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) capabilities.ReadDmaLbaData = readBuf;
|
2018-11-25 19:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ DMA RETRY in LBA mode...");
|
|
|
|
|
|
sense = dev.ReadDma(out readBuf, out errorLba, true, 0, 1, dev.Timeout, out _);
|
|
|
|
|
|
capabilities.SupportsReadDmaRetryLba =
|
|
|
|
|
|
!sense && (errorLba.Status & 0x01) != 0x01 && errorLba.Error == 0 && readBuf.Length > 0;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}",
|
|
|
|
|
|
sense, errorLba.Status, errorLba.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) capabilities.ReadDmaRetryLbaData = readBuf;
|
2018-11-25 19:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying SEEK in LBA mode...");
|
|
|
|
|
|
sense = dev.Seek(out errorLba, 0, dev.Timeout, out _);
|
|
|
|
|
|
capabilities.SupportsSeekLba = !sense && (errorLba.Status & 0x01) != 0x01 && errorLba.Error == 0;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}", sense,
|
|
|
|
|
|
errorLba.Status, errorLba.Error);
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ SECTOR(S) in LBA48 mode...");
|
|
|
|
|
|
sense = dev.Read(out readBuf, out AtaErrorRegistersLba48 errorLba48, 0, 1, dev.Timeout, out _);
|
|
|
|
|
|
capabilities.SupportsReadLba48 = !sense && (errorLba48.Status & 0x01) != 0x01 && errorLba48.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}",
|
|
|
|
|
|
sense, errorLba48.Status, errorLba48.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) capabilities.ReadLba48Data = readBuf;
|
2018-11-25 19:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ DMA in LBA48 mode...");
|
|
|
|
|
|
sense = dev.ReadDma(out readBuf, out errorLba48, 0, 1, dev.Timeout, out _);
|
|
|
|
|
|
capabilities.SupportsReadDmaLba48 = !sense && (errorLba48.Status & 0x01) != 0x01 && errorLba48.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}",
|
|
|
|
|
|
sense, errorLba48.Status, errorLba48.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) capabilities.ReadDmaLba48Data = readBuf;
|
2018-11-25 19:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
// Send SET FEATURES before sending READ LONG commands, retrieve IDENTIFY again and
|
|
|
|
|
|
// check if ECC size changed. Sector is set to 1 because without it most drives just return
|
|
|
|
|
|
// CORRECTABLE ERROR for this command.
|
|
|
|
|
|
dev.SetFeatures(out _, AtaFeatures.EnableReadLongVendorLength, 0, 0, 1, 0, dev.Timeout, out _);
|
|
|
|
|
|
|
|
|
|
|
|
dev.AtaIdentify(out byte[] buffer, out _, dev.Timeout, out _);
|
|
|
|
|
|
if(Identify.Decode(buffer).HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
ataId = Identify.Decode(buffer).Value;
|
|
|
|
|
|
if(ataId.EccBytes != 0x0000 && ataId.EccBytes != 0xFFFF)
|
|
|
|
|
|
capabilities.LongBlockSize = logicalsectorsize + ataId.EccBytes;
|
|
|
|
|
|
|
|
|
|
|
|
if(ataId.UnformattedBPS > logicalsectorsize &&
|
|
|
|
|
|
(!(ataId.EccBytes != 0x0000 && ataId.EccBytes != 0xFFFF) || capabilities.LongBlockSize == 516))
|
|
|
|
|
|
capabilities.LongBlockSize = ataId.UnformattedBPS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ LONG in CHS mode...");
|
|
|
|
|
|
sense = dev.ReadLong(out readBuf, out errorChs, false, 0, 0, 1, capabilities.LongBlockSize ?? 0,
|
|
|
|
|
|
dev.Timeout, out _);
|
|
|
|
|
|
capabilities.SupportsReadLong = !sense && (errorChs.Status & 0x01) != 0x01 &&
|
|
|
|
|
|
errorChs.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0 &&
|
|
|
|
|
|
BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}",
|
|
|
|
|
|
sense, errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) capabilities.ReadLongData = readBuf;
|
2018-11-25 19:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ LONG RETRY in CHS mode...");
|
|
|
|
|
|
sense = dev.ReadLong(out readBuf, out errorChs, true, 0, 0, 1, capabilities.LongBlockSize ?? 0, dev.Timeout,
|
|
|
|
|
|
out _);
|
|
|
|
|
|
capabilities.SupportsReadLongRetry = !sense && (errorChs.Status & 0x01) != 0x01 && errorChs.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0 &&
|
|
|
|
|
|
BitConverter.ToUInt64(readBuf, 0) !=
|
|
|
|
|
|
checkCorrectRead;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}",
|
|
|
|
|
|
sense, errorChs.Status, errorChs.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) capabilities.ReadLongRetryData = readBuf;
|
2018-11-25 19:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ LONG in LBA mode...");
|
|
|
|
|
|
sense = dev.ReadLong(out readBuf, out errorLba, false, 0, capabilities.LongBlockSize ?? 0, dev.Timeout,
|
|
|
|
|
|
out _);
|
|
|
|
|
|
capabilities.SupportsReadLongLba = !sense && (errorLba.Status & 0x01) != 0x01 && errorLba.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0 &&
|
|
|
|
|
|
BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}",
|
|
|
|
|
|
sense, errorLba.Status, errorLba.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) capabilities.ReadLongLbaData = readBuf;
|
2018-11-25 19:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Trying READ LONG RETRY in LBA mode...");
|
|
|
|
|
|
sense = dev.ReadLong(out readBuf, out errorLba, true, 0, capabilities.LongBlockSize ?? 0, dev.Timeout,
|
|
|
|
|
|
out _);
|
|
|
|
|
|
capabilities.SupportsReadLongRetryLba = !sense && (errorLba.Status & 0x01) != 0x01 && errorLba.Error == 0 &&
|
|
|
|
|
|
readBuf.Length > 0 &&
|
|
|
|
|
|
BitConverter.ToUInt64(readBuf, 0) !=
|
|
|
|
|
|
checkCorrectRead;
|
|
|
|
|
|
DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}",
|
|
|
|
|
|
sense, errorLba.Status, errorLba.Error, readBuf.Length);
|
2018-12-26 01:15:30 +00:00
|
|
|
|
if(debug) capabilities.ReadLongRetryLbaData = readBuf;
|
2018-11-25 19:13:21 +00:00
|
|
|
|
|
|
|
|
|
|
return capabilities;
|
2017-05-28 21:01:17 +01:00
|
|
|
|
}
|
2018-12-25 14:46:02 +00:00
|
|
|
|
|
|
|
|
|
|
static byte[] ClearIdentify(byte[] buffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] empty = new byte[512];
|
|
|
|
|
|
|
|
|
|
|
|
Array.Copy(empty, 0, buffer, 20, 20);
|
|
|
|
|
|
Array.Copy(empty, 0, buffer, 216, 8);
|
|
|
|
|
|
Array.Copy(empty, 0, buffer, 224, 8);
|
|
|
|
|
|
Array.Copy(empty, 0, buffer, 352, 40);
|
|
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
|
}
|
2017-05-28 21:01:17 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|