Files
Aaru/Aaru.Core/Devices/Scanning/MediaScan.cs

119 lines
5.1 KiB
C#
Raw Normal View History

2020-03-11 21:56:55 +00:00
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : MediaScan.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Core algorithms.
//
// --[ Description ] ----------------------------------------------------------
//
// Scans media from devices.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
2022-12-03 16:07:10 +00:00
// Copyright © 2011-2023 Natalia Portillo
2020-03-11 21:56:55 +00:00
// ****************************************************************************/
2019-04-21 00:11:27 +01:00
using System;
using System.Diagnostics;
2020-12-31 19:28:47 +00:00
using Aaru.CommonTypes;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes.Enums;
using Aaru.Devices;
2023-09-26 02:40:11 +01:00
using Humanizer;
2019-04-21 00:11:27 +01:00
namespace Aaru.Core.Devices.Scanning;
2022-03-06 13:29:38 +00:00
public sealed partial class MediaScan
2019-04-21 00:11:27 +01:00
{
readonly Device _dev;
readonly string _devicePath;
readonly string _ibgLogPath;
readonly string _mhddLogPath;
readonly bool _seekTest;
readonly bool _useBufferedReads;
bool _aborted;
static readonly TimeSpan _oneSecond = 1.Seconds();
readonly Stopwatch _scanStopwatch;
readonly Stopwatch _speedStopwatch;
const string MODULE_NAME = "Media scanning";
2019-04-21 00:11:27 +01:00
2022-03-06 13:29:38 +00:00
/// <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>
/// <param name="seekTest">Enable seek test</param>
/// <param name="useBufferedReads">
/// If MMC/SD does not support CMD23, use OS buffered reads instead of multiple single block
/// commands
/// </param>
public MediaScan(string mhddLogPath, string ibgLogPath, string devicePath, Device dev, bool useBufferedReads,
bool seekTest = true)
{
_mhddLogPath = mhddLogPath;
_ibgLogPath = ibgLogPath;
_devicePath = devicePath;
_dev = dev;
_aborted = false;
_seekTest = seekTest;
_useBufferedReads = useBufferedReads;
_scanStopwatch = new Stopwatch();
_speedStopwatch = new Stopwatch();
2022-03-06 13:29:38 +00:00
}
2019-04-21 00:11:27 +01:00
2022-03-06 13:29:38 +00:00
/// <summary>Starts a media scan</summary>
/// <returns>Media scan results</returns>
/// <exception cref="NotSupportedException">Unknown device type</exception>
public ScanResults Scan()
{
switch(_dev.Type)
2019-04-21 00:11:27 +01:00
{
2022-03-06 13:29:38 +00:00
case DeviceType.ATA: return Ata();
case DeviceType.MMC:
case DeviceType.SecureDigital: return SecureDigital();
case DeviceType.NVMe: return Nvme();
case DeviceType.ATAPI:
case DeviceType.SCSI: return Scsi();
default: throw new NotSupportedException(Localization.Core.Unknown_device_type);
2019-04-21 00:11:27 +01:00
}
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
/// <summary>Aborts the running media scan</summary>
public void Abort() => _aborted = true;
2019-04-21 00:59:01 +01:00
2022-03-06 13:29:38 +00:00
/// <summary>Event raised when the progress bar is not longer needed</summary>
public event EndProgressHandler EndProgress;
/// <summary>Event raised when a progress bar is needed</summary>
public event InitProgressHandler InitProgress;
/// <summary>Event raised to report status updates</summary>
public event UpdateStatusHandler UpdateStatus;
/// <summary>Event raised to report a fatal error that stops the dumping operation and should call user's attention</summary>
public event ErrorMessageHandler StoppingErrorMessage;
/// <summary>Event raised to update the values of a determinate progress bar</summary>
public event UpdateProgressHandler UpdateProgress;
/// <summary>Event raised to update the status of an indeterminate progress bar</summary>
public event PulseProgressHandler PulseProgress;
/// <summary>Updates lists of time taken on scanning from the specified sector</summary>
public event ScanTimeHandler ScanTime;
/// <summary>Specified a number of blocks could not be read on scan</summary>
public event ScanUnreadableHandler ScanUnreadable;
/// <summary>Initializes a block map that's going to be filled with a media scan</summary>
public event InitBlockMapHandler InitBlockMap;
/// <summary>Sends the speed of scanning a specific sector</summary>
public event ScanSpeedHandler ScanSpeed;
2019-04-21 00:11:27 +01:00
}