Allow to disable seek in medium scan for GUI.

This commit is contained in:
2020-04-17 19:54:11 +01:00
parent 0072c5e1d1
commit 55c6f15b42
5 changed files with 82 additions and 81 deletions

View File

@@ -50,13 +50,13 @@ namespace Aaru.Core.Devices.Scanning
const ushort ATA_PROFILE = 0x0001;
const uint TIMEOUT = 5;
sense = dev.AtaIdentify(out byte[] cmdBuf, out _);
sense = _dev.AtaIdentify(out byte[] cmdBuf, out _);
if(!sense &&
Identify.Decode(cmdBuf).HasValue)
{
// Initializate reader
var ataReader = new Reader(dev, TIMEOUT, cmdBuf);
var ataReader = new Reader(_dev, TIMEOUT, cmdBuf);
// Fill reader blocks
results.Blocks = ataReader.GetDeviceBlocks();
@@ -123,8 +123,8 @@ namespace Aaru.Core.Devices.Scanning
UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time.");
InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead, ATA_PROFILE);
mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead, false);
ibgLog = new IbgLog(ibgLogPath, ATA_PROFILE);
mhddLog = new MhddLog(_mhddLogPath, _dev, results.Blocks, blockSize, blocksToRead, false);
ibgLog = new IbgLog(_ibgLogPath, ATA_PROFILE);
start = DateTime.UtcNow;
DateTime timeSpeedStart = DateTime.UtcNow;
@@ -133,7 +133,7 @@ namespace Aaru.Core.Devices.Scanning
for(ulong i = 0; i < results.Blocks; i += blocksToRead)
{
if(aborted)
if(_aborted)
break;
if(results.Blocks - i < blocksToRead)
@@ -203,17 +203,17 @@ namespace Aaru.Core.Devices.Scanning
EndProgress?.Invoke();
mhddLog.Close();
ibgLog.Close(dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
ibgLog.Close(_dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
(blockSize * (double)(results.Blocks + 1)) / 1024 /
(results.ProcessingTime / 1000),
devicePath);
_devicePath);
InitProgress?.Invoke();
if(ataReader.CanSeekLba)
if(ataReader.CanSeekLba && _seekTest)
for(int i = 0; i < SEEK_TIMES; i++)
{
if(aborted)
if(_aborted)
break;
uint seekPos = (uint)rnd.Next((int)results.Blocks);
@@ -241,8 +241,8 @@ namespace Aaru.Core.Devices.Scanning
else
{
InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead, ATA_PROFILE);
mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead, false);
ibgLog = new IbgLog(ibgLogPath, ATA_PROFILE);
mhddLog = new MhddLog(_mhddLogPath, _dev, results.Blocks, blockSize, blocksToRead, false);
ibgLog = new IbgLog(_ibgLogPath, ATA_PROFILE);
ulong currentBlock = 0;
results.Blocks = (ulong)(cylinders * heads * sectors);
@@ -257,7 +257,7 @@ namespace Aaru.Core.Devices.Scanning
{
for(byte sc = 1; sc < sectors; sc++)
{
if(aborted)
if(_aborted)
break;
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
@@ -324,17 +324,17 @@ namespace Aaru.Core.Devices.Scanning
EndProgress?.Invoke();
mhddLog.Close();
ibgLog.Close(dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
ibgLog.Close(_dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
(blockSize * (double)(results.Blocks + 1)) / 1024 /
(results.ProcessingTime / 1000),
devicePath);
_devicePath);
InitProgress?.Invoke();
if(ataReader.CanSeek)
for(int i = 0; i < SEEK_TIMES; i++)
{
if(aborted)
if(_aborted)
break;
ushort seekCy = (ushort)rnd.Next(cylinders);

View File

@@ -38,28 +38,30 @@ namespace Aaru.Core.Devices.Scanning
{
public partial class MediaScan
{
readonly Device dev;
readonly string devicePath;
readonly string ibgLogPath;
readonly string mhddLogPath;
bool aborted;
readonly Device _dev;
readonly string _devicePath;
readonly string _ibgLogPath;
readonly string _mhddLogPath;
readonly bool _seekTest;
bool _aborted;
/// <param name="mhddLogPath">Path to a MHDD log file</param>
/// <param name="ibgLogPath">Path to a IMGBurn log file</param>
/// <param name="devicePath">Device path</param>
/// <param name="dev">Device</param>
public MediaScan(string mhddLogPath, string ibgLogPath, string devicePath, Device dev)
public MediaScan(string mhddLogPath, string ibgLogPath, string devicePath, Device dev, bool seekTest = true)
{
this.mhddLogPath = mhddLogPath;
this.ibgLogPath = ibgLogPath;
this.devicePath = devicePath;
this.dev = dev;
aborted = false;
_mhddLogPath = mhddLogPath;
_ibgLogPath = ibgLogPath;
_devicePath = devicePath;
_dev = dev;
_aborted = false;
_seekTest = seekTest;
}
public ScanResults Scan()
{
switch(dev.Type)
switch(_dev.Type)
{
case DeviceType.ATA: return Ata();
case DeviceType.MMC:
@@ -71,7 +73,7 @@ namespace Aaru.Core.Devices.Scanning
}
}
public void Abort() => aborted = true;
public void Abort() => _aborted = true;
/// <summary>Event raised when the progress bar is not longer needed</summary>
public event EndProgressHandler EndProgress;

View File

@@ -57,9 +57,9 @@ namespace Aaru.Core.Devices.Scanning
uint blockSize = 0;
ushort currentProfile = 0x0001;
if(dev.IsRemovable)
if(_dev.IsRemovable)
{
sense = dev.ScsiTestUnitReady(out senseBuf, dev.Timeout, out _);
sense = _dev.ScsiTestUnitReady(out senseBuf, _dev.Timeout, out _);
if(sense)
{
@@ -75,7 +75,7 @@ namespace Aaru.Core.Devices.Scanning
{
PulseProgress?.Invoke("Waiting for drive to become ready");
Thread.Sleep(2000);
sense = dev.ScsiTestUnitReady(out senseBuf, dev.Timeout, out _);
sense = _dev.ScsiTestUnitReady(out senseBuf, _dev.Timeout, out _);
if(!sense)
break;
@@ -99,7 +99,7 @@ namespace Aaru.Core.Devices.Scanning
{
PulseProgress?.Invoke("Waiting for drive to become ready");
Thread.Sleep(2000);
sense = dev.ScsiTestUnitReady(out senseBuf, dev.Timeout, out _);
sense = _dev.ScsiTestUnitReady(out senseBuf, _dev.Timeout, out _);
if(!sense)
break;
@@ -125,7 +125,7 @@ namespace Aaru.Core.Devices.Scanning
{
PulseProgress?.Invoke("Waiting for drive to become ready");
Thread.Sleep(2000);
sense = dev.ScsiTestUnitReady(out senseBuf, dev.Timeout, out _);
sense = _dev.ScsiTestUnitReady(out senseBuf, _dev.Timeout, out _);
if(!sense)
break;
@@ -161,7 +161,7 @@ namespace Aaru.Core.Devices.Scanning
Reader scsiReader = null;
switch(dev.ScsiType)
switch(_dev.ScsiType)
{
case PeripheralDeviceTypes.DirectAccess:
case PeripheralDeviceTypes.MultiMediaDevice:
@@ -169,7 +169,7 @@ namespace Aaru.Core.Devices.Scanning
case PeripheralDeviceTypes.OpticalDevice:
case PeripheralDeviceTypes.SimplifiedDevice:
case PeripheralDeviceTypes.WriteOnceDevice:
scsiReader = new Reader(dev, dev.Timeout, null);
scsiReader = new Reader(_dev, _dev.Timeout, null);
results.Blocks = scsiReader.GetDeviceBlocks();
if(scsiReader.FindReadCommand())
@@ -209,10 +209,10 @@ namespace Aaru.Core.Devices.Scanning
bool compactDisc = true;
FullTOC.CDFullTOC? toc = null;
if(dev.ScsiType == PeripheralDeviceTypes.MultiMediaDevice)
if(_dev.ScsiType == PeripheralDeviceTypes.MultiMediaDevice)
{
sense = dev.GetConfiguration(out byte[] cmdBuf, out senseBuf, 0, MmcGetConfigurationRt.Current,
dev.Timeout, out _);
sense = _dev.GetConfiguration(out byte[] cmdBuf, out senseBuf, 0, MmcGetConfigurationRt.Current,
_dev.Timeout, out _);
if(!sense)
{
@@ -242,7 +242,7 @@ namespace Aaru.Core.Devices.Scanning
// We discarded all discs that falsify a TOC before requesting a real TOC
// No TOC, no CD (or an empty one)
bool tocSense = dev.ReadRawToc(out cmdBuf, out senseBuf, 1, dev.Timeout, out _);
bool tocSense = _dev.ReadRawToc(out cmdBuf, out senseBuf, 1, _dev.Timeout, out _);
if(!tocSense)
toc = FullTOC.Decode(cmdBuf);
@@ -278,9 +278,9 @@ namespace Aaru.Core.Devices.Scanning
return results;
}
bool readcd = !dev.ReadCd(out _, out senseBuf, 0, 2352, 1, MmcSectorTypes.AllTypes, false, false, true,
MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None,
dev.Timeout, out _);
bool readcd = !_dev.ReadCd(out _, out senseBuf, 0, 2352, 1, MmcSectorTypes.AllTypes, false, false, true,
MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None,
MmcSubchannel.None, _dev.Timeout, out _);
if(readcd)
UpdateStatus?.Invoke("Using MMC READ CD command.");
@@ -291,23 +291,23 @@ namespace Aaru.Core.Devices.Scanning
{
if(readcd)
{
sense = dev.ReadCd(out _, out senseBuf, 0, 2352, blocksToRead, MmcSectorTypes.AllTypes, false,
false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None,
MmcSubchannel.None, dev.Timeout, out _);
sense = _dev.ReadCd(out _, out senseBuf, 0, 2352, blocksToRead, MmcSectorTypes.AllTypes, false,
false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None,
MmcSubchannel.None, _dev.Timeout, out _);
if(dev.Error)
if(_dev.Error)
blocksToRead /= 2;
}
if(!dev.Error ||
if(!_dev.Error ||
blocksToRead == 1)
break;
}
if(dev.Error)
if(_dev.Error)
{
StoppingErrorMessage?.
Invoke($"Device error {dev.LastError} trying to guess ideal transfer length.");
Invoke($"Device error {_dev.LastError} trying to guess ideal transfer length.");
return results;
}
@@ -315,8 +315,8 @@ namespace Aaru.Core.Devices.Scanning
UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time.");
InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead, currentProfile);
mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead, false);
ibgLog = new IbgLog(ibgLogPath, currentProfile);
mhddLog = new MhddLog(_mhddLogPath, _dev, results.Blocks, blockSize, blocksToRead, false);
ibgLog = new IbgLog(_ibgLogPath, currentProfile);
DateTime timeSpeedStart = DateTime.UtcNow;
ulong sectorSpeedStart = 0;
@@ -324,7 +324,7 @@ namespace Aaru.Core.Devices.Scanning
for(ulong i = 0; i < results.Blocks; i += blocksToRead)
{
if(aborted)
if(_aborted)
break;
double cmdDuration = 0;
@@ -347,9 +347,9 @@ namespace Aaru.Core.Devices.Scanning
if(readcd)
{
sense = dev.ReadCd(out _, out senseBuf, (uint)i, 2352, blocksToRead, MmcSectorTypes.AllTypes,
false, false, true, MmcHeaderCodes.AllHeaders, true, true,
MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out cmdDuration);
sense = _dev.ReadCd(out _, out senseBuf, (uint)i, 2352, blocksToRead, MmcSectorTypes.AllTypes,
false, false, true, MmcHeaderCodes.AllHeaders, true, true,
MmcErrorField.None, MmcSubchannel.None, _dev.Timeout, out cmdDuration);
results.ProcessingTime += cmdDuration;
}
@@ -431,10 +431,10 @@ namespace Aaru.Core.Devices.Scanning
EndProgress?.Invoke();
mhddLog.Close();
ibgLog.Close(dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
ibgLog.Close(_dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
(blockSize * (double)(results.Blocks + 1)) / 1024 /
(results.ProcessingTime / 1000),
devicePath);
_devicePath);
}
else
{
@@ -443,8 +443,8 @@ namespace Aaru.Core.Devices.Scanning
UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time.");
InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead, currentProfile);
mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead, false);
ibgLog = new IbgLog(ibgLogPath, currentProfile);
mhddLog = new MhddLog(_mhddLogPath, _dev, results.Blocks, blockSize, blocksToRead, false);
ibgLog = new IbgLog(_ibgLogPath, currentProfile);
DateTime timeSpeedStart = DateTime.UtcNow;
ulong sectorSpeedStart = 0;
@@ -452,7 +452,7 @@ namespace Aaru.Core.Devices.Scanning
for(ulong i = 0; i < results.Blocks; i += blocksToRead)
{
if(aborted)
if(_aborted)
break;
if(results.Blocks - i < blocksToRead)
@@ -475,7 +475,7 @@ namespace Aaru.Core.Devices.Scanning
results.ProcessingTime += cmdDuration;
if(!sense &&
!dev.Error)
!_dev.Error)
{
if(cmdDuration >= 500)
results.F += blocksToRead;
@@ -525,10 +525,10 @@ namespace Aaru.Core.Devices.Scanning
EndProgress?.Invoke();
mhddLog.Close();
ibgLog.Close(dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
ibgLog.Close(_dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
(blockSize * (double)(results.Blocks + 1)) / 1024 /
(results.ProcessingTime / 1000),
devicePath);
_devicePath);
}
results.SeekMax = double.MinValue;
@@ -542,7 +542,7 @@ namespace Aaru.Core.Devices.Scanning
for(int i = 0; i < SEEK_TIMES; i++)
{
if(aborted)
if(_aborted || !_seekTest)
break;
uint seekPos = (uint)rnd.Next((int)results.Blocks);

View File

@@ -54,11 +54,11 @@ namespace Aaru.Core.Devices.Scanning
uint blockSize = 512;
bool byteAddressed = true;
switch(dev.Type)
switch(_dev.Type)
{
case DeviceType.MMC:
{
sense = dev.ReadExtendedCsd(out cmdBuf, out _, TIMEOUT, out _);
sense = _dev.ReadExtendedCsd(out cmdBuf, out _, TIMEOUT, out _);
if(!sense)
{
@@ -73,7 +73,7 @@ namespace Aaru.Core.Devices.Scanning
if(sense || results.Blocks == 0)
{
sense = dev.ReadCsd(out cmdBuf, out _, TIMEOUT, out _);
sense = _dev.ReadCsd(out cmdBuf, out _, TIMEOUT, out _);
if(!sense)
{
@@ -88,7 +88,7 @@ namespace Aaru.Core.Devices.Scanning
case DeviceType.SecureDigital:
{
sense = dev.ReadCsd(out cmdBuf, out _, TIMEOUT, out _);
sense = _dev.ReadCsd(out cmdBuf, out _, TIMEOUT, out _);
if(!sense)
{
@@ -117,7 +117,7 @@ namespace Aaru.Core.Devices.Scanning
while(true)
{
sense = dev.Read(out cmdBuf, out _, 0, blockSize, blocksToRead, byteAddressed, TIMEOUT, out duration);
sense = _dev.Read(out cmdBuf, out _, 0, blockSize, blocksToRead, byteAddressed, TIMEOUT, out duration);
if(sense)
blocksToRead /= 2;
@@ -129,7 +129,7 @@ namespace Aaru.Core.Devices.Scanning
if(sense)
{
StoppingErrorMessage?.Invoke($"Device error {dev.LastError} trying to guess ideal transfer length.");
StoppingErrorMessage?.Invoke($"Device error {_dev.LastError} trying to guess ideal transfer length.");
return results;
}
@@ -158,8 +158,8 @@ namespace Aaru.Core.Devices.Scanning
UpdateStatus?.Invoke($"Reading {blocksToRead} sectors at a time.");
InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead, SD_PROFILE);
var mhddLog = new MhddLog(mhddLogPath, dev, results.Blocks, blockSize, blocksToRead, false);
var ibgLog = new IbgLog(ibgLogPath, SD_PROFILE);
var mhddLog = new MhddLog(_mhddLogPath, _dev, results.Blocks, blockSize, blocksToRead, false);
var ibgLog = new IbgLog(_ibgLogPath, SD_PROFILE);
start = DateTime.UtcNow;
DateTime timeSpeedStart = DateTime.UtcNow;
@@ -168,7 +168,7 @@ namespace Aaru.Core.Devices.Scanning
for(ulong i = 0; i < results.Blocks; i += blocksToRead)
{
if(aborted)
if(_aborted)
break;
if(results.Blocks - i < blocksToRead)
@@ -187,8 +187,8 @@ namespace Aaru.Core.Devices.Scanning
UpdateProgress?.Invoke($"Reading sector {i} of {results.Blocks} ({currentSpeed:F3} MiB/sec.)", (long)i,
(long)results.Blocks);
bool error = dev.Read(out cmdBuf, out _, (uint)i, blockSize, blocksToRead, byteAddressed, TIMEOUT,
out duration);
bool error = _dev.Read(out cmdBuf, out _, (uint)i, blockSize, blocksToRead, byteAddressed, TIMEOUT,
out duration);
if(!error)
{
@@ -239,24 +239,24 @@ namespace Aaru.Core.Devices.Scanning
EndProgress?.Invoke();
mhddLog.Close();
ibgLog.Close(dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
ibgLog.Close(_dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
(blockSize * (double)(results.Blocks + 1)) / 1024 /
(results.ProcessingTime / 1000),
devicePath);
_devicePath);
InitProgress?.Invoke();
for(int i = 0; i < SEEK_TIMES; i++)
{
if(aborted)
if(_aborted || !_seekTest)
break;
uint seekPos = (uint)rnd.Next((int)results.Blocks);
PulseProgress?.Invoke($"Seeking to sector {seekPos}...\t\t");
dev.Read(out cmdBuf, out _, seekPos, blockSize, blocksToRead, byteAddressed, TIMEOUT,
out double seekCur);
_dev.Read(out cmdBuf, out _, seekPos, blockSize, blocksToRead, byteAddressed, TIMEOUT,
out double seekCur);
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
if(seekCur > results.SeekMax &&