2014-07-03 18:34:19 +01:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
|
The Disc Image Chef
|
|
|
|
|
|
----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
Filename : Verify.cs
|
|
|
|
|
|
Version : 1.0
|
|
|
|
|
|
Author(s) : Natalia Portillo
|
|
|
|
|
|
|
|
|
|
|
|
Component : Verbs.
|
|
|
|
|
|
|
|
|
|
|
|
Revision : $Revision$
|
|
|
|
|
|
Last change by : $Author$
|
|
|
|
|
|
Date : $Date$
|
|
|
|
|
|
|
|
|
|
|
|
--[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
Implements the 'verify' verb.
|
|
|
|
|
|
|
|
|
|
|
|
--[ 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/>.
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------
|
|
|
|
|
|
Copyright (C) 2011-2014 Claunia.com
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
//$Id$
|
|
|
|
|
|
using System;
|
2014-08-25 05:00:25 +01:00
|
|
|
|
using DiscImageChef.ImagePlugins;
|
|
|
|
|
|
using System.Collections.Generic;
|
2015-10-18 22:04:03 +01:00
|
|
|
|
using DiscImageChef.Console;
|
2014-06-16 01:45:04 +01:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Commands
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class Verify
|
|
|
|
|
|
{
|
|
|
|
|
|
public static void doVerify(VerifySubOptions options)
|
|
|
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Verify command", "--debug={0}", options.Debug);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Verify command", "--verbose={0}", options.Verbose);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Verify command", "--input={0}", options.InputFile);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Verify command", "--verify-disc={0}", options.VerifyDisc);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Verify command", "--verify-sectors={0}", options.VerifySectors);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
|
|
|
|
|
|
ImagePlugin inputFormat = ImageFormat.Detect(options.InputFile);
|
|
|
|
|
|
|
|
|
|
|
|
if (inputFormat == null)
|
|
|
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.ErrorWriteLine("Unable to recognize image format, not verifying");
|
2014-08-25 05:00:25 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inputFormat.OpenImage(options.InputFile);
|
|
|
|
|
|
|
|
|
|
|
|
if (options.VerifyDisc)
|
|
|
|
|
|
{
|
|
|
|
|
|
DateTime StartCheck = DateTime.UtcNow;
|
2016-01-16 03:54:55 +00:00
|
|
|
|
bool? discCheckStatus = inputFormat.VerifyMediaImage();
|
2014-08-25 05:00:25 +01:00
|
|
|
|
DateTime EndCheck = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
|
|
TimeSpan CheckTime = EndCheck - StartCheck;
|
|
|
|
|
|
|
|
|
|
|
|
switch (discCheckStatus)
|
|
|
|
|
|
{
|
|
|
|
|
|
case true:
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.WriteLine("Disc image checksums are correct");
|
2014-08-25 05:00:25 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case false:
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.WriteLine("Disc image checksums are incorrect");
|
2014-08-25 05:00:25 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case null:
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.WriteLine("Disc image does not contain checksums");
|
2014-08-25 05:00:25 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.VerboseWriteLine("Checking disc image checksums took {0} seconds", CheckTime.TotalSeconds);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (options.VerifySectors)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool formatHasTracks;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
List<Track> inputTracks = inputFormat.GetTracks();
|
|
|
|
|
|
if (inputTracks.Count > 0)
|
|
|
|
|
|
formatHasTracks = true;
|
|
|
|
|
|
else
|
|
|
|
|
|
formatHasTracks = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
formatHasTracks = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DateTime StartCheck;
|
|
|
|
|
|
DateTime EndCheck;
|
|
|
|
|
|
List<UInt64> FailingLBAs = new List<UInt64>();
|
|
|
|
|
|
List<UInt64> UnknownLBAs = new List<UInt64>();
|
|
|
|
|
|
bool? checkStatus = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (formatHasTracks)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<Track> inputTracks = inputFormat.GetTracks();
|
|
|
|
|
|
UInt64 currentSectorAll = 0;
|
|
|
|
|
|
|
|
|
|
|
|
StartCheck = DateTime.UtcNow;
|
|
|
|
|
|
foreach (Track currentTrack in inputTracks)
|
|
|
|
|
|
{
|
|
|
|
|
|
UInt64 remainingSectors = currentTrack.TrackEndSector - currentTrack.TrackStartSector;
|
|
|
|
|
|
UInt64 currentSector = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while (remainingSectors > 0)
|
|
|
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.Write("\rChecking sector {0} of {1}, on track {2}", currentSectorAll, inputFormat.GetSectors(), currentTrack.TrackSequence);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
|
|
|
|
|
|
List<UInt64> tempFailingLBAs;
|
|
|
|
|
|
List<UInt64> tempUnknownLBAs;
|
|
|
|
|
|
bool? tempStatus;
|
|
|
|
|
|
|
|
|
|
|
|
if (remainingSectors < 512)
|
|
|
|
|
|
tempStatus = inputFormat.VerifySectors(currentSector, (uint)remainingSectors, currentTrack.TrackSequence, out tempFailingLBAs, out tempUnknownLBAs);
|
|
|
|
|
|
else
|
|
|
|
|
|
tempStatus = inputFormat.VerifySectors(currentSector, 512, currentTrack.TrackSequence, out tempFailingLBAs, out tempUnknownLBAs);
|
|
|
|
|
|
|
|
|
|
|
|
if (checkStatus == null || tempStatus == null)
|
|
|
|
|
|
checkStatus = null;
|
|
|
|
|
|
else if (checkStatus == false || tempStatus == false)
|
|
|
|
|
|
checkStatus = false;
|
|
|
|
|
|
else if (checkStatus == true && tempStatus == true)
|
|
|
|
|
|
checkStatus = true;
|
|
|
|
|
|
else
|
|
|
|
|
|
checkStatus = null;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (UInt64 failLBA in tempFailingLBAs)
|
|
|
|
|
|
FailingLBAs.Add(failLBA);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (UInt64 unknownLBA in tempUnknownLBAs)
|
|
|
|
|
|
UnknownLBAs.Add(unknownLBA);
|
|
|
|
|
|
|
|
|
|
|
|
if (remainingSectors < 512)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentSector += remainingSectors;
|
|
|
|
|
|
currentSectorAll += remainingSectors;
|
|
|
|
|
|
remainingSectors = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
currentSector += 512;
|
|
|
|
|
|
currentSectorAll += 512;
|
|
|
|
|
|
remainingSectors -= 512;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
EndCheck = DateTime.UtcNow;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
UInt64 remainingSectors = inputFormat.GetSectors();
|
|
|
|
|
|
UInt64 currentSector = 0;
|
|
|
|
|
|
|
|
|
|
|
|
StartCheck = DateTime.UtcNow;
|
|
|
|
|
|
while (remainingSectors > 0)
|
|
|
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.Write("\rChecking sector {0} of {1}", currentSector, inputFormat.GetSectors());
|
2014-08-25 05:00:25 +01:00
|
|
|
|
|
|
|
|
|
|
List<UInt64> tempFailingLBAs;
|
|
|
|
|
|
List<UInt64> tempUnknownLBAs;
|
|
|
|
|
|
bool? tempStatus;
|
|
|
|
|
|
|
|
|
|
|
|
if (remainingSectors < 512)
|
|
|
|
|
|
tempStatus = inputFormat.VerifySectors(currentSector, (uint)remainingSectors, out tempFailingLBAs, out tempUnknownLBAs);
|
|
|
|
|
|
else
|
|
|
|
|
|
tempStatus = inputFormat.VerifySectors(currentSector, 512, out tempFailingLBAs, out tempUnknownLBAs);
|
|
|
|
|
|
|
|
|
|
|
|
if (checkStatus == null || tempStatus == null)
|
|
|
|
|
|
checkStatus = null;
|
|
|
|
|
|
else if (checkStatus == false || tempStatus == false)
|
|
|
|
|
|
checkStatus = false;
|
|
|
|
|
|
else if (checkStatus == true && tempStatus == true)
|
|
|
|
|
|
checkStatus = true;
|
|
|
|
|
|
else
|
|
|
|
|
|
checkStatus = null;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (UInt64 failLBA in tempFailingLBAs)
|
|
|
|
|
|
FailingLBAs.Add(failLBA);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (UInt64 unknownLBA in tempUnknownLBAs)
|
|
|
|
|
|
UnknownLBAs.Add(unknownLBA);
|
|
|
|
|
|
|
|
|
|
|
|
if (remainingSectors < 512)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentSector += remainingSectors;
|
|
|
|
|
|
remainingSectors = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
currentSector += 512;
|
|
|
|
|
|
remainingSectors -= 512;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
EndCheck = DateTime.UtcNow;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TimeSpan CheckTime = EndCheck - StartCheck;
|
|
|
|
|
|
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.Write("\r");
|
2014-08-25 05:00:25 +01:00
|
|
|
|
|
|
|
|
|
|
switch (checkStatus)
|
|
|
|
|
|
{
|
|
|
|
|
|
case true:
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.WriteLine("All sector checksums are correct");
|
2014-08-25 05:00:25 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case false:
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.WriteLine("There is at least one sector with incorrect checksum or errors");
|
2014-08-25 05:00:25 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case null:
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.WriteLine("There is at least one sector that does not contain a checksum");
|
2014-08-25 05:00:25 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.VerboseWriteLine("Checking sector checksums took {0} seconds", CheckTime.TotalSeconds);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
|
2015-10-18 22:04:03 +01:00
|
|
|
|
if (options.Verbose)
|
2014-08-25 05:00:25 +01:00
|
|
|
|
{
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.VerboseWriteLine("LBAs with error:");
|
2014-08-25 05:00:25 +01:00
|
|
|
|
if (FailingLBAs.Count == (int)inputFormat.GetSectors())
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.VerboseWriteLine("\tall sectors.");
|
2014-08-25 05:00:25 +01:00
|
|
|
|
else
|
|
|
|
|
|
for (int i = 0; i < FailingLBAs.Count; i++)
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.VerboseWriteLine("\t{0}", FailingLBAs[i]);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.WriteLine("LBAs without checksum:");
|
2014-08-25 05:00:25 +01:00
|
|
|
|
if (UnknownLBAs.Count == (int)inputFormat.GetSectors())
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.VerboseWriteLine("\tall sectors.");
|
2014-08-25 05:00:25 +01:00
|
|
|
|
else
|
|
|
|
|
|
for (int i = 0; i < UnknownLBAs.Count; i++)
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.VerboseWriteLine("\t{0}", UnknownLBAs[i]);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-18 22:04:03 +01:00
|
|
|
|
DicConsole.WriteLine("Total sectors........... {0}", inputFormat.GetSectors());
|
|
|
|
|
|
DicConsole.WriteLine("Total errors............ {0}", FailingLBAs.Count);
|
|
|
|
|
|
DicConsole.WriteLine("Total unknowns.......... {0}", UnknownLBAs.Count);
|
|
|
|
|
|
DicConsole.WriteLine("Total errors+unknowns... {0}", FailingLBAs.Count + UnknownLBAs.Count);
|
2014-08-25 05:00:25 +01:00
|
|
|
|
}
|
2014-06-16 01:45:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|