mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Refactor IMediaImage.ReadSector(s)Long to return error status instead of buffer.
This commit is contained in:
Submodule Aaru.CommonTypes updated: 5bc77788ec...95525cff74
@@ -139,8 +139,11 @@ namespace Aaru.Filesystems
|
||||
if((size + offsetInSector) % 2352 > 0)
|
||||
sizeInSectors++;
|
||||
|
||||
byte[] buffer =
|
||||
_image.ReadSectorsLong((ulong)(entry.Extents[0].extent + firstSector), (uint)sizeInSectors);
|
||||
ErrorNumber errno = _image.ReadSectorsLong((ulong)(entry.Extents[0].extent + firstSector),
|
||||
(uint)sizeInSectors, out byte[] buffer);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return errno;
|
||||
|
||||
buf = new byte[size];
|
||||
Array.Copy(buffer, offsetInSector, buf, 0, size);
|
||||
@@ -152,7 +155,7 @@ namespace Aaru.Filesystems
|
||||
AaruConsole.DebugWriteLine("ISO9660 plugin", "Exception reading CD-i audio file");
|
||||
AaruConsole.DebugWriteLine("ISO9660 plugin", "{0}", e);
|
||||
|
||||
return ErrorNumber.InOutError;
|
||||
return ErrorNumber.UnexpectedException;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,8 @@ namespace Aaru.Filesystems
|
||||
{
|
||||
ulong realSector;
|
||||
uint sectorCount;
|
||||
ErrorNumber errno = ErrorNumber.NoError;
|
||||
ErrorNumber errno;
|
||||
buffer = null;
|
||||
|
||||
sectorCount = (uint)_blockSize / 2048;
|
||||
|
||||
@@ -60,15 +61,13 @@ namespace Aaru.Filesystems
|
||||
|
||||
if(sectorCount == 1)
|
||||
{
|
||||
// TODO: No more exceptions
|
||||
try
|
||||
{
|
||||
data = _image.ReadSectorLong(realSector);
|
||||
}
|
||||
catch
|
||||
{
|
||||
errno = _image.ReadSectorLong(realSector, out data);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
errno = _image.ReadSector(realSector, out data);
|
||||
}
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return errno;
|
||||
|
||||
if(_debug)
|
||||
{
|
||||
@@ -137,15 +136,13 @@ namespace Aaru.Filesystems
|
||||
{
|
||||
ulong dstSector = realSector + 1;
|
||||
|
||||
// TODO: No more exceptions
|
||||
try
|
||||
{
|
||||
data = _image.ReadSectorLong(dstSector);
|
||||
}
|
||||
catch
|
||||
{
|
||||
errno = _image.ReadSectorLong(dstSector, out data);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
errno = _image.ReadSector(dstSector, out data);
|
||||
}
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return errno;
|
||||
|
||||
if(_debug)
|
||||
{
|
||||
@@ -201,7 +198,7 @@ namespace Aaru.Filesystems
|
||||
Array.Copy(Sector.GetUserData(ms.ToArray(), interleaved, fileNumber), 0, tmp, 0, _blockSize);
|
||||
buffer = tmp;
|
||||
|
||||
return errno;
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,18 +84,13 @@ namespace Aaru.Filesystems
|
||||
entry.Extents.Count == 0)
|
||||
return ErrorNumber.NoError;
|
||||
|
||||
// TODO: No more exceptions
|
||||
try
|
||||
{
|
||||
byte[] sector = _image.ReadSectorLong(entry.Extents[0].extent * _blockSize / 2048);
|
||||
ErrorNumber errno = _image.ReadSectorLong(entry.Extents[0].extent * _blockSize / 2048, out byte[] sector);
|
||||
|
||||
if(sector[15] != 2)
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return errno;
|
||||
|
||||
if(sector[15] != 2)
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
xattrs.Add("org.iso.mode2.subheader");
|
||||
xattrs.Add("org.iso.mode2.subheader.copy");
|
||||
|
||||
@@ -961,16 +961,39 @@ namespace Aaru.Gui.ViewModels.Windows
|
||||
bool result;
|
||||
|
||||
if(useLong)
|
||||
if(sectorsToDo == 1)
|
||||
{
|
||||
sector = _inputFormat.ReadSectorLong(doneSectors);
|
||||
result = outputFormat.WriteSectorLong(sector, doneSectors);
|
||||
}
|
||||
{
|
||||
errno = sectorsToDo == 1 ? _inputFormat.ReadSectorLong(doneSectors, out sector)
|
||||
: _inputFormat.ReadSectorsLong(doneSectors, sectorsToDo, out sector);
|
||||
|
||||
if(errno == ErrorNumber.NoError)
|
||||
result = sectorsToDo == 1 ? outputFormat.WriteSectorLong(sector, doneSectors)
|
||||
: outputFormat.WriteSectorsLong(sector, doneSectors, sectorsToDo);
|
||||
else
|
||||
{
|
||||
sector = _inputFormat.ReadSectorsLong(doneSectors, sectorsToDo);
|
||||
result = outputFormat.WriteSectorsLong(sector, doneSectors, sectorsToDo);
|
||||
result = true;
|
||||
|
||||
if(ForceChecked)
|
||||
{
|
||||
warning = true;
|
||||
|
||||
AaruConsole.ErrorWriteLine("Error {0} reading sector {1}, continuing...", errno,
|
||||
doneSectors);
|
||||
}
|
||||
else
|
||||
{
|
||||
await Dispatcher.UIThread.InvokeAsync(action: async () => await MessageBoxManager.
|
||||
GetMessageBoxStandardWindow("Error",
|
||||
$"Error {errno} reading sector {doneSectors}, not continuing...",
|
||||
icon: Icon.Error).
|
||||
ShowDialog(_view));
|
||||
|
||||
AaruConsole.ErrorWriteLine("Error {0} reading sector {1}, not continuing...", errno,
|
||||
doneSectors);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = sectorsToDo == 1 ? _inputFormat.ReadSector(doneSectors, out sector)
|
||||
@@ -1272,18 +1295,40 @@ namespace Aaru.Gui.ViewModels.Windows
|
||||
bool result;
|
||||
|
||||
if(useLong)
|
||||
if(sectorsToDo == 1)
|
||||
{
|
||||
sector = _inputFormat.ReadSectorLong(doneSectors + track.StartSector);
|
||||
result = outputFormat.WriteSectorLong(sector, doneSectors + track.StartSector);
|
||||
}
|
||||
{
|
||||
errno = sectorsToDo == 1
|
||||
? _inputFormat.ReadSectorLong(doneSectors + track.StartSector, out sector)
|
||||
: _inputFormat.ReadSectorsLong(doneSectors + track.StartSector, sectorsToDo,
|
||||
out sector);
|
||||
|
||||
if(errno == ErrorNumber.NoError)
|
||||
result = sectorsToDo == 1
|
||||
? outputFormat.WriteSectorLong(sector, doneSectors + track.StartSector)
|
||||
: outputFormat.WriteSectorsLong(sector, doneSectors + track.StartSector,
|
||||
sectorsToDo);
|
||||
else
|
||||
{
|
||||
sector = _inputFormat.ReadSectorsLong(doneSectors + track.StartSector, sectorsToDo);
|
||||
result = true;
|
||||
|
||||
result = outputFormat.WriteSectorsLong(sector, doneSectors + track.StartSector,
|
||||
sectorsToDo);
|
||||
if(ForceChecked)
|
||||
{
|
||||
warning = true;
|
||||
|
||||
AaruConsole.ErrorWriteLine("Error {0} reading sector {1}, continuing...", errno,
|
||||
doneSectors);
|
||||
}
|
||||
else
|
||||
{
|
||||
await Dispatcher.UIThread.InvokeAsync(action: async () => await MessageBoxManager.
|
||||
GetMessageBoxStandardWindow("Error",
|
||||
$"Error {errno} reading sector {doneSectors}, not continuing...",
|
||||
icon: Icon.Error).
|
||||
ShowDialog(_view));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = sectorsToDo == 1
|
||||
|
||||
@@ -53,15 +53,12 @@ namespace Aaru.Gui.ViewModels.Windows
|
||||
{
|
||||
_inputFormat = inputFormat;
|
||||
|
||||
try
|
||||
{
|
||||
inputFormat.ReadSectorLong(0);
|
||||
ErrorNumber errno = inputFormat.ReadSectorLong(0, out _);
|
||||
|
||||
if(errno == ErrorNumber.NoError)
|
||||
LongSectorChecked = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
else
|
||||
LongSectorVisible = false;
|
||||
}
|
||||
|
||||
TotalSectorsText = $"of {inputFormat.Info.Sectors}";
|
||||
SectorNumber = 0;
|
||||
@@ -81,12 +78,10 @@ namespace Aaru.Gui.ViewModels.Windows
|
||||
this.RaiseAndSetIfChanged(ref _sectorNumber, value);
|
||||
|
||||
byte[] sector;
|
||||
ErrorNumber errno = ErrorNumber.NoError;
|
||||
ErrorNumber errno;
|
||||
|
||||
if(LongSectorChecked)
|
||||
sector = _inputFormat.ReadSectorLong((ulong)SectorNumber);
|
||||
else
|
||||
errno = _inputFormat.ReadSector((ulong)SectorNumber, out sector);
|
||||
errno = LongSectorChecked ? _inputFormat.ReadSectorLong((ulong)SectorNumber, out sector)
|
||||
: _inputFormat.ReadSector((ulong)SectorNumber, out sector);
|
||||
|
||||
if(errno == ErrorNumber.NoError)
|
||||
PrintHexText = PrintHex.ByteArrayToHexArrayString(sector, HEX_COLUMNS);
|
||||
|
||||
@@ -1980,9 +1980,10 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress)
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
ErrorNumber errno;
|
||||
buffer = null;
|
||||
|
||||
switch(_imageInfo.XmlMediaType)
|
||||
{
|
||||
@@ -1991,39 +1992,39 @@ namespace Aaru.DiscImages
|
||||
sectorAddress <= t.EndSector);
|
||||
|
||||
if(trk is null)
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
|
||||
"Can't found track containing requested sector");
|
||||
return ErrorNumber.SectorNotFound;
|
||||
|
||||
if(trk.Sequence == 0 &&
|
||||
trk.StartSector == 0 &&
|
||||
trk.EndSector == 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
|
||||
"Can't found track containing requested sector");
|
||||
return ErrorNumber.SectorNotFound;
|
||||
|
||||
if((_sectorSuffix == null || _sectorPrefix == null) &&
|
||||
(_sectorSuffixMs == null || _sectorPrefixMs == null))
|
||||
{
|
||||
errno = ReadSector(sectorAddress, out byte[] buffer);
|
||||
return ReadSector(sectorAddress, out buffer);
|
||||
|
||||
return errno != ErrorNumber.NoError ? null : buffer;
|
||||
}
|
||||
buffer = new byte[2352];
|
||||
errno = ReadSector(sectorAddress, out byte[] data);
|
||||
|
||||
byte[] sector = new byte[2352];
|
||||
errno = ReadSector(sectorAddress, out byte[] data);
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return errno;
|
||||
|
||||
switch(trk.Type)
|
||||
{
|
||||
case TrackType.Audio:
|
||||
case TrackType.Data: return data;
|
||||
case TrackType.Data:
|
||||
buffer = data;
|
||||
|
||||
return ErrorNumber.NoError;
|
||||
case TrackType.CdMode1:
|
||||
Array.Copy(data, 0, sector, 16, 2048);
|
||||
Array.Copy(data, 0, buffer, 16, 2048);
|
||||
|
||||
if(_sectorPrefix != null)
|
||||
Array.Copy(_sectorPrefix, (int)sectorAddress * 16, sector, 0, 16);
|
||||
Array.Copy(_sectorPrefix, (int)sectorAddress * 16, buffer, 0, 16);
|
||||
else if(_sectorPrefixDdt != null)
|
||||
{
|
||||
if((_sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == (uint)CdFixFlags.Correct)
|
||||
ReconstructPrefix(ref sector, trk.Type, (long)sectorAddress);
|
||||
ReconstructPrefix(ref buffer, trk.Type, (long)sectorAddress);
|
||||
else if((_sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) ==
|
||||
(uint)CdFixFlags.NotDumped ||
|
||||
_sectorPrefixDdt[sectorAddress] == 0)
|
||||
@@ -2035,23 +2036,22 @@ namespace Aaru.DiscImages
|
||||
uint prefixPosition = ((_sectorPrefixDdt[sectorAddress] & CD_DFIX_MASK) - 1) * 16;
|
||||
|
||||
if(prefixPosition > _sectorPrefixMs.Length)
|
||||
throw new
|
||||
InvalidProgramException("Incorrect data found in image, please re-dump. If issue persists, please open a bug report.");
|
||||
return ErrorNumber.InvalidArgument;
|
||||
|
||||
_sectorPrefixMs.Position = prefixPosition;
|
||||
|
||||
_sectorPrefixMs.Read(sector, 0, 16);
|
||||
_sectorPrefixMs.Read(buffer, 0, 16);
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new InvalidProgramException("Should not have arrived here");
|
||||
return ErrorNumber.InvalidArgument;
|
||||
|
||||
if(_sectorSuffix != null)
|
||||
Array.Copy(_sectorSuffix, (int)sectorAddress * 288, sector, 2064, 288);
|
||||
Array.Copy(_sectorSuffix, (int)sectorAddress * 288, buffer, 2064, 288);
|
||||
else if(_sectorSuffixDdt != null)
|
||||
{
|
||||
if((_sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == (uint)CdFixFlags.Correct)
|
||||
ReconstructEcc(ref sector, trk.Type);
|
||||
ReconstructEcc(ref buffer, trk.Type);
|
||||
else if((_sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) ==
|
||||
(uint)CdFixFlags.NotDumped ||
|
||||
_sectorSuffixDdt[sectorAddress] == 0)
|
||||
@@ -2063,27 +2063,26 @@ namespace Aaru.DiscImages
|
||||
uint suffixPosition = ((_sectorSuffixDdt[sectorAddress] & CD_DFIX_MASK) - 1) * 288;
|
||||
|
||||
if(suffixPosition > _sectorSuffixMs.Length)
|
||||
throw new
|
||||
InvalidProgramException("Incorrect data found in image, please re-dump. If issue persists, please open a bug report.");
|
||||
return ErrorNumber.InvalidArgument;
|
||||
|
||||
_sectorSuffixMs.Position = suffixPosition;
|
||||
|
||||
_sectorSuffixMs.Read(sector, 2064, 288);
|
||||
_sectorSuffixMs.Read(buffer, 2064, 288);
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new InvalidProgramException("Should not have arrived here");
|
||||
return ErrorNumber.InvalidArgument;
|
||||
|
||||
return sector;
|
||||
return ErrorNumber.NoError;
|
||||
case TrackType.CdMode2Formless:
|
||||
case TrackType.CdMode2Form1:
|
||||
case TrackType.CdMode2Form2:
|
||||
if(_sectorPrefix != null)
|
||||
Array.Copy(_sectorPrefix, (int)sectorAddress * 16, sector, 0, 16);
|
||||
Array.Copy(_sectorPrefix, (int)sectorAddress * 16, buffer, 0, 16);
|
||||
else if(_sectorPrefixMs != null)
|
||||
{
|
||||
if((_sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == (uint)CdFixFlags.Correct)
|
||||
ReconstructPrefix(ref sector, trk.Type, (long)sectorAddress);
|
||||
ReconstructPrefix(ref buffer, trk.Type, (long)sectorAddress);
|
||||
else if((_sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) ==
|
||||
(uint)CdFixFlags.NotDumped ||
|
||||
_sectorPrefixDdt[sectorAddress] == 0)
|
||||
@@ -2095,78 +2094,84 @@ namespace Aaru.DiscImages
|
||||
uint prefixPosition = ((_sectorPrefixDdt[sectorAddress] & CD_DFIX_MASK) - 1) * 16;
|
||||
|
||||
if(prefixPosition > _sectorPrefixMs.Length)
|
||||
throw new
|
||||
InvalidProgramException("Incorrect data found in image, please re-dump. If issue persists, please open a bug report.");
|
||||
return ErrorNumber.InvalidArgument;
|
||||
|
||||
_sectorPrefixMs.Position = prefixPosition;
|
||||
|
||||
_sectorPrefixMs.Read(sector, 0, 16);
|
||||
_sectorPrefixMs.Read(buffer, 0, 16);
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new InvalidProgramException("Should not have arrived here");
|
||||
return ErrorNumber.InvalidArgument;
|
||||
|
||||
if(_mode2Subheaders != null &&
|
||||
_sectorSuffixDdt != null)
|
||||
{
|
||||
Array.Copy(_mode2Subheaders, (int)sectorAddress * 8, sector, 16, 8);
|
||||
Array.Copy(_mode2Subheaders, (int)sectorAddress * 8, buffer, 16, 8);
|
||||
|
||||
if((_sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == (uint)CdFixFlags.Mode2Form1Ok)
|
||||
switch(_sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK)
|
||||
{
|
||||
Array.Copy(data, 0, sector, 24, 2048);
|
||||
ReconstructEcc(ref sector, TrackType.CdMode2Form1);
|
||||
}
|
||||
else if((_sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) ==
|
||||
(uint)CdFixFlags.Mode2Form2Ok ||
|
||||
(_sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) ==
|
||||
(uint)CdFixFlags.Mode2Form2NoCrc)
|
||||
{
|
||||
Array.Copy(data, 0, sector, 24, 2324);
|
||||
case (uint)CdFixFlags.Mode2Form1Ok:
|
||||
Array.Copy(data, 0, buffer, 24, 2048);
|
||||
ReconstructEcc(ref buffer, TrackType.CdMode2Form1);
|
||||
|
||||
if((_sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) ==
|
||||
(uint)CdFixFlags.Mode2Form2Ok)
|
||||
ReconstructEcc(ref sector, TrackType.CdMode2Form2);
|
||||
}
|
||||
else if((_sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) ==
|
||||
(uint)CdFixFlags.NotDumped ||
|
||||
_sectorSuffixDdt[sectorAddress] == 0)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
else // Mode 2 where EDC failed
|
||||
{
|
||||
// Incorrectly written images
|
||||
if(data.Length == 2328)
|
||||
break;
|
||||
case (uint)CdFixFlags.Mode2Form2Ok:
|
||||
case (uint)CdFixFlags.Mode2Form2NoCrc:
|
||||
{
|
||||
Array.Copy(data, 0, sector, 24, 2328);
|
||||
Array.Copy(data, 0, buffer, 24, 2324);
|
||||
|
||||
if((_sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) ==
|
||||
(uint)CdFixFlags.Mode2Form2Ok)
|
||||
ReconstructEcc(ref buffer, TrackType.CdMode2Form2);
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
default:
|
||||
{
|
||||
bool form2 = (sector[18] & 0x20) == 0x20 || (sector[22] & 0x20) == 0x20;
|
||||
if((_sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) ==
|
||||
(uint)CdFixFlags.NotDumped ||
|
||||
_sectorSuffixDdt[sectorAddress] == 0)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
else // Mode 2 where EDC failed
|
||||
{
|
||||
// Incorrectly written images
|
||||
if(data.Length == 2328)
|
||||
{
|
||||
Array.Copy(data, 0, buffer, 24, 2328);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool form2 = (buffer[18] & 0x20) == 0x20 || (buffer[22] & 0x20) == 0x20;
|
||||
|
||||
uint suffixPosition =
|
||||
((_sectorSuffixDdt[sectorAddress] & CD_DFIX_MASK) - 1) * 288;
|
||||
uint suffixPosition =
|
||||
((_sectorSuffixDdt[sectorAddress] & CD_DFIX_MASK) - 1) * 288;
|
||||
|
||||
if(suffixPosition > _sectorSuffixMs.Length)
|
||||
throw new
|
||||
InvalidProgramException("Incorrect data found in image, please re-dump. If issue persists, please open a bug report.");
|
||||
if(suffixPosition > _sectorSuffixMs.Length)
|
||||
return ErrorNumber.InvalidArgument;
|
||||
|
||||
_sectorSuffixMs.Position = suffixPosition;
|
||||
_sectorSuffixMs.Position = suffixPosition;
|
||||
|
||||
_sectorSuffixMs.Read(sector, form2 ? 2348 : 2072, form2 ? 4 : 280);
|
||||
Array.Copy(data, 0, sector, 24, form2 ? 2324 : 2048);
|
||||
_sectorSuffixMs.Read(buffer, form2 ? 2348 : 2072, form2 ? 4 : 280);
|
||||
Array.Copy(data, 0, buffer, 24, form2 ? 2324 : 2048);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(_mode2Subheaders != null)
|
||||
{
|
||||
Array.Copy(_mode2Subheaders, (int)sectorAddress * 8, sector, 16, 8);
|
||||
Array.Copy(data, 0, sector, 24, 2328);
|
||||
Array.Copy(_mode2Subheaders, (int)sectorAddress * 8, buffer, 16, 8);
|
||||
Array.Copy(data, 0, buffer, 24, 2328);
|
||||
}
|
||||
else
|
||||
Array.Copy(data, 0, sector, 16, 2336);
|
||||
Array.Copy(data, 0, buffer, 16, 2336);
|
||||
|
||||
return sector;
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -2178,13 +2183,13 @@ namespace Aaru.DiscImages
|
||||
case MediaType.AppleSonySS:
|
||||
case MediaType.AppleSonyDS:
|
||||
case MediaType.AppleWidget:
|
||||
case MediaType.PriamDataTower: return ReadSectorsLong(sectorAddress, 1);
|
||||
case MediaType.PriamDataTower: return ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
throw new FeatureNotPresentImageException("Feature not present in image");
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -2198,15 +2203,17 @@ namespace Aaru.DiscImages
|
||||
if(trk?.Sequence != track)
|
||||
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
||||
|
||||
return ReadSectorLong(trk.StartSector + sectorAddress);
|
||||
ErrorNumber errno = ReadSectorLong(trk.StartSector + sectorAddress, out byte[] buffer);
|
||||
|
||||
return errno != ErrorNumber.NoError ? null : buffer;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
byte[] sectors;
|
||||
byte[] data;
|
||||
ErrorNumber errno;
|
||||
buffer = null;
|
||||
|
||||
switch(_imageInfo.XmlMediaType)
|
||||
{
|
||||
@@ -2215,71 +2222,65 @@ namespace Aaru.DiscImages
|
||||
sectorAddress <= t.EndSector);
|
||||
|
||||
if(trk is null)
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
|
||||
"Can't found track containing requested sector");
|
||||
return ErrorNumber.SectorNotFound;
|
||||
|
||||
if(trk.Sequence == 0 &&
|
||||
trk.StartSector == 0 &&
|
||||
trk.EndSector == 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
|
||||
"Can't found track containing requested sector");
|
||||
return ErrorNumber.SectorNotFound;
|
||||
|
||||
if(sectorAddress + length > trk.EndSector + 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(length),
|
||||
$"Requested more sectors ({length + sectorAddress}) than present in track ({trk.EndSector - trk.StartSector + 1}), won't cross tracks");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
switch(trk.Type)
|
||||
{
|
||||
// These types only contain user data
|
||||
case TrackType.Audio:
|
||||
case TrackType.Data:
|
||||
errno = ReadSectors(sectorAddress, length, out data);
|
||||
|
||||
return errno == ErrorNumber.NoError ? data : null;
|
||||
case TrackType.Data: return ReadSectors(sectorAddress, length, out buffer);
|
||||
|
||||
// Join prefix (sync, header) with user data with suffix (edc, ecc p, ecc q)
|
||||
case TrackType.CdMode1:
|
||||
if(_sectorPrefix != null &&
|
||||
_sectorSuffix != null)
|
||||
{
|
||||
sectors = new byte[2352 * length];
|
||||
errno = ReadSectors(sectorAddress, length, out data);
|
||||
buffer = new byte[2352 * length];
|
||||
errno = ReadSectors(sectorAddress, length, out data);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
return errno;
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
Array.Copy(_sectorPrefix, (int)((sectorAddress + i) * 16), sectors, (int)(i * 2352),
|
||||
Array.Copy(_sectorPrefix, (int)((sectorAddress + i) * 16), buffer, (int)(i * 2352),
|
||||
16);
|
||||
|
||||
Array.Copy(data, (int)(i * 2048), sectors, (int)(i * 2352) + 16, 2048);
|
||||
Array.Copy(data, (int)(i * 2048), buffer, (int)(i * 2352) + 16, 2048);
|
||||
|
||||
Array.Copy(_sectorSuffix, (int)((sectorAddress + i) * 288), sectors,
|
||||
Array.Copy(_sectorSuffix, (int)((sectorAddress + i) * 288), buffer,
|
||||
(int)(i * 2352) + 2064, 288);
|
||||
}
|
||||
|
||||
return sectors;
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
else if(_sectorPrefixDdt != null &&
|
||||
_sectorSuffixDdt != null)
|
||||
{
|
||||
sectors = new byte[2352 * length];
|
||||
buffer = new byte[2352 * length];
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
byte[] temp = ReadSectorLong(sectorAddress + i);
|
||||
Array.Copy(temp, 0, sectors, 2352 * i, 2352);
|
||||
errno = ReadSectorLong(sectorAddress + i, out byte[] temp);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return errno;
|
||||
|
||||
Array.Copy(temp, 0, buffer, 2352 * i, 2352);
|
||||
}
|
||||
|
||||
return sectors;
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = ReadSectors(sectorAddress, length, out data);
|
||||
|
||||
return errno == ErrorNumber.NoError ? data : null;
|
||||
}
|
||||
return ReadSectors(sectorAddress, length, out buffer);
|
||||
|
||||
// Join prefix (sync, header) with user data
|
||||
case TrackType.CdMode2Formless:
|
||||
@@ -2288,39 +2289,41 @@ namespace Aaru.DiscImages
|
||||
if(_sectorPrefix != null &&
|
||||
_sectorSuffix != null)
|
||||
{
|
||||
sectors = new byte[2352 * length];
|
||||
errno = ReadSectors(sectorAddress, length, out data);
|
||||
buffer = new byte[2352 * length];
|
||||
errno = ReadSectors(sectorAddress, length, out data);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
return errno;
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
Array.Copy(_sectorPrefix, (int)((sectorAddress + i) * 16), sectors, (int)(i * 2352),
|
||||
Array.Copy(_sectorPrefix, (int)((sectorAddress + i) * 16), buffer, (int)(i * 2352),
|
||||
16);
|
||||
|
||||
Array.Copy(data, (int)(i * 2336), sectors, (int)(i * 2352) + 16, 2336);
|
||||
Array.Copy(data, (int)(i * 2336), buffer, (int)(i * 2352) + 16, 2336);
|
||||
}
|
||||
|
||||
return sectors;
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
else if(_sectorPrefixDdt != null &&
|
||||
_sectorSuffixDdt != null)
|
||||
{
|
||||
sectors = new byte[2352 * length];
|
||||
buffer = new byte[2352 * length];
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
byte[] temp = ReadSectorLong(sectorAddress + i);
|
||||
Array.Copy(temp, 0, sectors, 2352 * i, 2352);
|
||||
errno = ReadSectorLong(sectorAddress + i, out byte[] temp);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return errno;
|
||||
|
||||
Array.Copy(temp, 0, buffer, 2352 * i, 2352);
|
||||
}
|
||||
|
||||
return sectors;
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
errno = ReadSectors(sectorAddress, length, out data);
|
||||
|
||||
return errno == ErrorNumber.NoError ? data : null;
|
||||
return ReadSectors(sectorAddress, length, out buffer);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -2335,11 +2338,7 @@ namespace Aaru.DiscImages
|
||||
case MediaType.AppleWidget:
|
||||
case MediaType.PriamDataTower:
|
||||
if(_sectorSubchannel == null)
|
||||
{
|
||||
errno = ReadSector(sectorAddress, out data);
|
||||
|
||||
return errno == ErrorNumber.NoError ? data : null;
|
||||
}
|
||||
return ReadSector(sectorAddress, out buffer);
|
||||
|
||||
uint tagSize = 0;
|
||||
|
||||
@@ -2366,25 +2365,25 @@ namespace Aaru.DiscImages
|
||||
errno = ReadSectors(sectorAddress, length, out data);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
return errno;
|
||||
|
||||
sectors = new byte[(sectorSize + 512) * length];
|
||||
buffer = new byte[(sectorSize + 512) * length];
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
Array.Copy(_sectorSubchannel, (int)((sectorAddress + i) * tagSize), sectors,
|
||||
Array.Copy(_sectorSubchannel, (int)((sectorAddress + i) * tagSize), buffer,
|
||||
(int)((i * sectorSize) + 512), tagSize);
|
||||
|
||||
Array.Copy(data, (int)((sectorAddress + i) * 512), sectors, (int)(i * 512), 512);
|
||||
Array.Copy(data, (int)((sectorAddress + i) * 512), buffer, (int)(i * 512), 512);
|
||||
}
|
||||
|
||||
return sectors;
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
throw new FeatureNotPresentImageException("Feature not present in image");
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -2402,7 +2401,9 @@ namespace Aaru.DiscImages
|
||||
throw new ArgumentOutOfRangeException(nameof(length),
|
||||
$"Requested more sectors ({length + sectorAddress}) than present in track ({trk.EndSector - trk.StartSector + 1}), won't cross tracks");
|
||||
|
||||
return ReadSectorsLong(trk.StartSector + sectorAddress, length);
|
||||
ErrorNumber errno = ReadSectorsLong(trk.StartSector + sectorAddress, length, out byte[] buffer);
|
||||
|
||||
return errno == ErrorNumber.NoError ? buffer : null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Aaru.DiscImages
|
||||
|
||||
_imageStream.Position -= _structureBytes.Length;
|
||||
|
||||
List<IndexEntry> vrIndex = new List<IndexEntry>();
|
||||
List<IndexEntry> vrIndex = new();
|
||||
|
||||
for(ushort i = 0; i < idxHeader.entries; i++)
|
||||
{
|
||||
@@ -212,9 +212,9 @@ namespace Aaru.DiscImages
|
||||
if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc)
|
||||
return null;
|
||||
|
||||
byte[] buffer = ReadSectorLong(sectorAddress);
|
||||
ErrorNumber errno = ReadSectorLong(sectorAddress, out byte[] buffer);
|
||||
|
||||
return CdChecksums.CheckCdSector(buffer);
|
||||
return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -233,7 +233,11 @@ namespace Aaru.DiscImages
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
failingLbas = new List<ulong>();
|
||||
|
||||
@@ -1373,14 +1373,17 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
foreach(KeyValuePair<uint, ulong> kvp in _offsetMap)
|
||||
if(sectorAddress >= kvp.Value)
|
||||
foreach(Track alcTrack in _alcTracks.Values)
|
||||
@@ -1389,11 +1392,15 @@ namespace Aaru.DiscImages
|
||||
!_alcTrackExtras.TryGetValue(alcTrack.point, out TrackExtra alcExtra))
|
||||
continue;
|
||||
|
||||
if(sectorAddress - kvp.Value < alcExtra.sectors + alcExtra.pregap)
|
||||
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
if(sectorAddress - kvp.Value >= alcExtra.sectors + alcExtra.pregap)
|
||||
continue;
|
||||
|
||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
|
||||
return buffer == null ? ErrorNumber.NoData : ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
||||
return ErrorNumber.SectorNotFound;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
namespace Aaru.DiscImages
|
||||
{
|
||||
@@ -41,20 +42,24 @@ namespace Aaru.DiscImages
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySector(ulong sectorAddress)
|
||||
{
|
||||
byte[] buffer = ReadSectorLong(sectorAddress);
|
||||
ErrorNumber errno = ReadSectorLong(sectorAddress, out byte[] buffer);
|
||||
|
||||
return CdChecksums.CheckCdSector(buffer);
|
||||
return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
||||
out List<ulong> unknownLbas)
|
||||
{
|
||||
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
failingLbas = new List<ulong>();
|
||||
unknownLbas = new List<ulong>();
|
||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,12 +46,20 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer)
|
||||
|
||||
@@ -246,36 +246,43 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress)
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
if(sectorAddress > _imageInfo.Sectors - 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
|
||||
$"Sector address {sectorAddress} not found");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
_longSectors.TryGetValue(sectorAddress, out byte[] temp);
|
||||
|
||||
return temp;
|
||||
return _longSectors.TryGetValue(sectorAddress, out buffer) ? ErrorNumber.NoError
|
||||
: ErrorNumber.SectorNotFound;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
if(sectorAddress > _imageInfo.Sectors - 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
|
||||
$"Sector address {sectorAddress} not found");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
if(sectorAddress + length > _imageInfo.Sectors)
|
||||
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
var ms = new MemoryStream();
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
byte[] sector = ReadSectorLong(sectorAddress + i);
|
||||
ErrorNumber errno = ReadSectorLong(sectorAddress + i, out byte[] sector);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return errno;
|
||||
|
||||
ms.Write(sector, 0, sector.Length);
|
||||
}
|
||||
|
||||
return ms.ToArray();
|
||||
buffer = ms.ToArray();
|
||||
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,23 +228,26 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
if(sectorAddress > _imageInfo.Sectors - 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
if(sectorAddress + length > _imageInfo.Sectors)
|
||||
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
byte[] buffer = new byte[length * _imageHeader.BytesPerBlock];
|
||||
buffer = new byte[length * _imageHeader.BytesPerBlock];
|
||||
Stream stream = _bluImageFilter.GetDataForkStream();
|
||||
stream.Seek((long)((sectorAddress + 1) * _imageHeader.BytesPerBlock), SeekOrigin.Begin);
|
||||
stream.Read(buffer, 0, buffer.Length);
|
||||
|
||||
return buffer;
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1184,21 +1184,28 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetMap where sectorAddress >= kvp.Value
|
||||
from track in Tracks where track.Sequence == kvp.Key
|
||||
where sectorAddress - kvp.Value <
|
||||
track.EndSector - track.StartSector + 1 select kvp)
|
||||
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
{
|
||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
||||
return buffer is null ? ErrorNumber.SectorNotFound : ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
return ErrorNumber.SectorNotFound;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
namespace Aaru.DiscImages
|
||||
{
|
||||
@@ -41,20 +42,24 @@ namespace Aaru.DiscImages
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySector(ulong sectorAddress)
|
||||
{
|
||||
byte[] buffer = ReadSectorLong(sectorAddress);
|
||||
ErrorNumber errno = ReadSectorLong(sectorAddress, out byte[] buffer);
|
||||
|
||||
return CdChecksums.CheckCdSector(buffer);
|
||||
return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
||||
out List<ulong> unknownLbas)
|
||||
{
|
||||
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
failingLbas = new List<ulong>();
|
||||
unknownLbas = new List<ulong>();
|
||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
|
||||
@@ -2103,21 +2103,28 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetMap where sectorAddress >= kvp.Value
|
||||
from track in Tracks where track.Sequence == kvp.Key
|
||||
where sectorAddress - kvp.Value <
|
||||
track.EndSector - track.StartSector + 1 select kvp)
|
||||
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
{
|
||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
||||
return buffer is null ? ErrorNumber.SectorNotFound : ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
return ErrorNumber.SectorNotFound;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
namespace Aaru.DiscImages
|
||||
{
|
||||
@@ -41,20 +42,24 @@ namespace Aaru.DiscImages
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySector(ulong sectorAddress)
|
||||
{
|
||||
byte[] buffer = ReadSectorLong(sectorAddress);
|
||||
ErrorNumber errno = ReadSectorLong(sectorAddress, out byte[] buffer);
|
||||
|
||||
return CdChecksums.CheckCdSector(buffer);
|
||||
return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
||||
out List<ulong> unknownLbas)
|
||||
{
|
||||
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
failingLbas = new List<ulong>();
|
||||
unknownLbas = new List<ulong>();
|
||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
|
||||
@@ -913,7 +913,8 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer) => ReadSectors(sectorAddress, 1, out buffer);
|
||||
public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectors(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) => ReadSectorsTag(sectorAddress, 1, tag);
|
||||
@@ -929,12 +930,13 @@ namespace Aaru.DiscImages
|
||||
public ErrorNumber ReadSectors(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetmap where sectorAddress >= kvp.Value
|
||||
from cdrdaoTrack in _discimage.Tracks
|
||||
where cdrdaoTrack.Sequence == kvp.Key
|
||||
where sectorAddress - kvp.Value < cdrdaoTrack.Sectors select kvp)
|
||||
{
|
||||
buffer= ReadSectors(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
buffer = ReadSectors(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
@@ -1296,21 +1298,28 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetmap where sectorAddress >= kvp.Value
|
||||
from cdrdaoTrack in _discimage.Tracks
|
||||
where cdrdaoTrack.Sequence == kvp.Key
|
||||
where sectorAddress - kvp.Value < cdrdaoTrack.Sectors select kvp)
|
||||
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
{
|
||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
||||
return buffer is null ? ErrorNumber.SectorNotFound : ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
return ErrorNumber.SectorNotFound;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
namespace Aaru.DiscImages
|
||||
{
|
||||
@@ -41,20 +42,24 @@ namespace Aaru.DiscImages
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySector(ulong sectorAddress)
|
||||
{
|
||||
byte[] buffer = ReadSectorLong(sectorAddress);
|
||||
ErrorNumber errno = ReadSectorLong(sectorAddress, out byte[] buffer);
|
||||
|
||||
return CdChecksums.CheckCdSector(buffer);
|
||||
return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
||||
out List<ulong> unknownLbas)
|
||||
{
|
||||
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
failingLbas = new List<ulong>();
|
||||
unknownLbas = new List<ulong>();
|
||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
|
||||
@@ -2030,21 +2030,28 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetMap where sectorAddress >= kvp.Value
|
||||
from cdrwinTrack in _discImage.Tracks
|
||||
where cdrwinTrack.Sequence == kvp.Key
|
||||
where sectorAddress - kvp.Value < cdrwinTrack.Sectors select kvp)
|
||||
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
{
|
||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
||||
return buffer is null ? ErrorNumber.SectorNotFound : ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
return ErrorNumber.SectorNotFound;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -35,6 +35,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.Console;
|
||||
|
||||
@@ -149,20 +150,24 @@ namespace Aaru.DiscImages
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySector(ulong sectorAddress)
|
||||
{
|
||||
byte[] buffer = ReadSectorLong(sectorAddress);
|
||||
ErrorNumber errno = ReadSectorLong(sectorAddress, out byte[] buffer);
|
||||
|
||||
return CdChecksums.CheckCdSector(buffer);
|
||||
return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
||||
out List<ulong> unknownLbas)
|
||||
{
|
||||
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
failingLbas = new List<ulong>();
|
||||
unknownLbas = new List<ulong>();
|
||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
|
||||
@@ -1774,20 +1774,15 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress)
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
byte[] buffer;
|
||||
buffer = null;
|
||||
|
||||
if(_isHdd)
|
||||
{
|
||||
ErrorNumber errno = ReadSector(sectorAddress, out buffer);
|
||||
|
||||
return errno == ErrorNumber.NoError ? buffer : null;
|
||||
}
|
||||
return ReadSector(sectorAddress, out buffer);
|
||||
|
||||
if(sectorAddress > _imageInfo.Sectors - 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
|
||||
$"Sector address {sectorAddress} not found");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
var track = new Track();
|
||||
|
||||
@@ -1872,29 +1867,35 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
if(sectorAddress > _imageInfo.Sectors - 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
|
||||
$"Sector address {sectorAddress} not found");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
if(sectorAddress + length > _imageInfo.Sectors)
|
||||
throw new ArgumentOutOfRangeException(nameof(length),
|
||||
$"Requested more sectors ({sectorAddress + length}) than available ({_imageInfo.Sectors})");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
var ms = new MemoryStream();
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
byte[] sector = ReadSectorLong(sectorAddress + i);
|
||||
ErrorNumber errno = ReadSectorLong(sectorAddress + i, out byte[] sector);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return errno;
|
||||
|
||||
ms.Write(sector, 0, sector.Length);
|
||||
}
|
||||
|
||||
return ms.ToArray();
|
||||
buffer = ms.ToArray();
|
||||
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -1982,7 +1983,9 @@ namespace Aaru.DiscImages
|
||||
if(_isHdd)
|
||||
throw new FeaturedNotSupportedByDiscImageException("Cannot access optical tracks on a hard disk image");
|
||||
|
||||
return ReadSectorLong(GetAbsoluteSector(sectorAddress, track));
|
||||
ErrorNumber errno = ReadSectorLong(GetAbsoluteSector(sectorAddress, track), out byte[] buffer);
|
||||
|
||||
return errno == ErrorNumber.NoError ? buffer : null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -34,6 +34,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
namespace Aaru.DiscImages
|
||||
{
|
||||
@@ -45,9 +46,9 @@ namespace Aaru.DiscImages
|
||||
if(_isHdd)
|
||||
return null;
|
||||
|
||||
byte[] buffer = ReadSectorLong(sectorAddress);
|
||||
ErrorNumber errno = ReadSectorLong(sectorAddress, out byte[] buffer);
|
||||
|
||||
return CdChecksums.CheckCdSector(buffer);
|
||||
return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -60,7 +61,11 @@ namespace Aaru.DiscImages
|
||||
if(_isHdd)
|
||||
return null;
|
||||
|
||||
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.CommonTypes.Exceptions;
|
||||
|
||||
namespace Aaru.DiscImages
|
||||
{
|
||||
@@ -46,11 +45,19 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,12 +46,20 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer)
|
||||
|
||||
@@ -1352,21 +1352,28 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetMap where sectorAddress >= kvp.Value
|
||||
from track in Tracks where track.Sequence == kvp.Key
|
||||
where sectorAddress - kvp.Value <
|
||||
track.EndSector - track.StartSector + 1 select kvp)
|
||||
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
{
|
||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress), $"Sector address {sectorAddress} not found");
|
||||
return buffer is null ? ErrorNumber.NoData : ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
return ErrorNumber.SectorNotFound;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
namespace Aaru.DiscImages
|
||||
{
|
||||
@@ -41,20 +42,24 @@ namespace Aaru.DiscImages
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySector(ulong sectorAddress)
|
||||
{
|
||||
byte[] buffer = ReadSectorLong(sectorAddress);
|
||||
ErrorNumber errno = ReadSectorLong(sectorAddress, out byte[] buffer);
|
||||
|
||||
return CdChecksums.CheckCdSector(buffer);
|
||||
return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
||||
out List<ulong> unknownLbas)
|
||||
{
|
||||
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
failingLbas = new List<ulong>();
|
||||
unknownLbas = new List<ulong>();
|
||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
|
||||
@@ -46,12 +46,20 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer)
|
||||
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,24 +373,27 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
if(sectorAddress > _imageInfo.Sectors - 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
if(sectorAddress + length > _imageInfo.Sectors)
|
||||
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
ErrorNumber errno = ReadSectors(sectorAddress, length, out byte[] data);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
return errno;
|
||||
|
||||
byte[] tags = ReadSectorsTag(sectorAddress, length, SectorTagType.AppleSectorTag);
|
||||
byte[] buffer = new byte[data.Length + tags.Length];
|
||||
byte[] tags = ReadSectorsTag(sectorAddress, length, SectorTagType.AppleSectorTag);
|
||||
buffer = new byte[data.Length + tags.Length];
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
@@ -401,7 +404,7 @@ namespace Aaru.DiscImages
|
||||
(i * (_imageInfo.SectorSize + TAG_SECTOR_SIZE)) + _imageInfo.SectorSize, TAG_SECTOR_SIZE);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,8 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer) => ReadSectors(sectorAddress, 1, out buffer);
|
||||
public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectors(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) =>
|
||||
@@ -154,11 +155,15 @@ namespace Aaru.DiscImages
|
||||
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotImplemented;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1238,21 +1238,28 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetMap where sectorAddress >= kvp.Value
|
||||
from track in Tracks where track.Sequence == kvp.Key
|
||||
where sectorAddress - kvp.Value <
|
||||
track.EndSector - track.StartSector + 1 select kvp)
|
||||
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
{
|
||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress), $"Sector address {sectorAddress} not found");
|
||||
return buffer is null ? ErrorNumber.NoData : ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
return ErrorNumber.SectorNotFound;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
namespace Aaru.DiscImages
|
||||
{
|
||||
@@ -41,20 +42,24 @@ namespace Aaru.DiscImages
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySector(ulong sectorAddress)
|
||||
{
|
||||
byte[] buffer = ReadSectorLong(sectorAddress);
|
||||
ErrorNumber errno = ReadSectorLong(sectorAddress, out byte[] buffer);
|
||||
|
||||
return CdChecksums.CheckCdSector(buffer);
|
||||
return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
||||
out List<ulong> unknownLbas)
|
||||
{
|
||||
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
failingLbas = new List<ulong>();
|
||||
unknownLbas = new List<ulong>();
|
||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
|
||||
@@ -530,24 +530,27 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
if(sectorAddress > imageInfo.Sectors - 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
if(sectorAddress + length > imageInfo.Sectors)
|
||||
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
ErrorNumber errno = ReadSectors(sectorAddress, length, out byte[] data);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
return errno;
|
||||
|
||||
byte[] tags = ReadSectorsTag(sectorAddress, length, SectorTagType.AppleSectorTag);
|
||||
byte[] buffer = new byte[data.Length + tags.Length];
|
||||
byte[] tags = ReadSectorsTag(sectorAddress, length, SectorTagType.AppleSectorTag);
|
||||
buffer = new byte[data.Length + tags.Length];
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
@@ -557,7 +560,7 @@ namespace Aaru.DiscImages
|
||||
Array.Copy(tags, i * bptag, buffer, (i * (imageInfo.SectorSize + bptag)) + imageInfo.SectorSize, bptag);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,11 +55,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,12 +46,20 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer)
|
||||
|
||||
@@ -689,21 +689,28 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetMap where sectorAddress >= kvp.Value
|
||||
from gdiTrack in _discImage.Tracks
|
||||
where gdiTrack.Sequence == kvp.Key
|
||||
where sectorAddress - kvp.Value < gdiTrack.Sectors select kvp)
|
||||
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
{
|
||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
||||
return buffer is null ? ErrorNumber.SectorNotFound : ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
return ErrorNumber.SectorNotFound;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
namespace Aaru.DiscImages
|
||||
{
|
||||
@@ -41,20 +42,24 @@ namespace Aaru.DiscImages
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySector(ulong sectorAddress)
|
||||
{
|
||||
byte[] buffer = ReadSectorLong(sectorAddress);
|
||||
ErrorNumber errno = ReadSectorLong(sectorAddress, out byte[] buffer);
|
||||
|
||||
return CdChecksums.CheckCdSector(buffer);
|
||||
return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
||||
out List<ulong> unknownLbas)
|
||||
{
|
||||
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
failingLbas = new List<ulong>();
|
||||
unknownLbas = new List<ulong>();
|
||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
|
||||
@@ -55,11 +55,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,12 +46,20 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer)
|
||||
|
||||
@@ -284,11 +284,15 @@ namespace Aaru.DiscImages
|
||||
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotImplemented;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,12 +46,20 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer)
|
||||
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2082,21 +2082,28 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetmap where sectorAddress >= kvp.Value
|
||||
from track in Tracks where track.Sequence == kvp.Key
|
||||
where sectorAddress - kvp.Value <=
|
||||
track.EndSector - track.StartSector select kvp)
|
||||
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
{
|
||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress), $"Sector address {sectorAddress} not found");
|
||||
return buffer is null ? ErrorNumber.NoData : ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
return ErrorNumber.SectorNotFound;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
namespace Aaru.DiscImages
|
||||
{
|
||||
@@ -41,20 +42,24 @@ namespace Aaru.DiscImages
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySector(ulong sectorAddress)
|
||||
{
|
||||
byte[] buffer = ReadSectorLong(sectorAddress);
|
||||
ErrorNumber errno = ReadSectorLong(sectorAddress, out byte[] buffer);
|
||||
|
||||
return CdChecksums.CheckCdSector(buffer);
|
||||
return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
||||
out List<ulong> unknownLbas)
|
||||
{
|
||||
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
failingLbas = new List<ulong>();
|
||||
unknownLbas = new List<ulong>();
|
||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,12 +46,20 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer)
|
||||
|
||||
@@ -46,11 +46,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,12 +46,20 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer)
|
||||
|
||||
@@ -285,11 +285,15 @@ namespace Aaru.DiscImages
|
||||
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -578,20 +578,12 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress)
|
||||
{
|
||||
ErrorNumber errno = ReadSectors(sectorAddress, 1, out byte[] buffer);
|
||||
|
||||
return errno == ErrorNumber.NoError ? buffer : null;
|
||||
}
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectors(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
{
|
||||
ErrorNumber errno = ReadSectors(sectorAddress, 1, out byte[] buffer);
|
||||
|
||||
return errno == ErrorNumber.NoError ? buffer : null;
|
||||
}
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer) =>
|
||||
ReadSectors(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer)
|
||||
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,19 @@ namespace Aaru.DiscImages
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1380,7 +1380,9 @@ namespace Aaru.DiscImages
|
||||
if(track != 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(track), "Only a single track is supported");
|
||||
|
||||
return ReadSectorsLong(sectorAddress, 1);
|
||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, 1, out byte[] buffer);
|
||||
|
||||
return errno != ErrorNumber.NoError ? null : buffer;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -1392,7 +1394,9 @@ namespace Aaru.DiscImages
|
||||
if(track != 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(track), "Only a single track is supported");
|
||||
|
||||
return ReadSectorsLong(sectorAddress, length);
|
||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
|
||||
|
||||
return errno != ErrorNumber.NoError ? null : buffer;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -1535,20 +1539,23 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
|
||||
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc ||
|
||||
!_rawCompactDisc)
|
||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
||||
return ErrorNumber.NotSupported;
|
||||
|
||||
if(sectorAddress > _imageInfo.Sectors - 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
if(sectorAddress + length > _imageInfo.Sectors)
|
||||
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
||||
return ErrorNumber.OutOfRange;
|
||||
|
||||
const uint sectorSize = 2352;
|
||||
uint sectorSkip = 0;
|
||||
@@ -1556,7 +1563,7 @@ namespace Aaru.DiscImages
|
||||
if(_hasSubchannel)
|
||||
sectorSkip += 96;
|
||||
|
||||
byte[] buffer = new byte[sectorSize * length];
|
||||
buffer = new byte[sectorSize * length];
|
||||
|
||||
Stream stream = _rawImageFilter.GetDataForkStream();
|
||||
var br = new BinaryReader(stream);
|
||||
@@ -1574,7 +1581,7 @@ namespace Aaru.DiscImages
|
||||
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
namespace Aaru.DiscImages
|
||||
{
|
||||
@@ -44,9 +45,9 @@ namespace Aaru.DiscImages
|
||||
if(!_rawCompactDisc)
|
||||
return null;
|
||||
|
||||
byte[] buffer = ReadSectorLong(sectorAddress);
|
||||
ErrorNumber errno = ReadSectorLong(sectorAddress, out byte[] buffer);
|
||||
|
||||
return CdChecksums.CheckCdSector(buffer);
|
||||
return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -64,11 +65,15 @@ namespace Aaru.DiscImages
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] buffer = ReadSectorsLong(sectorAddress, length);
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
failingLbas = new List<ulong>();
|
||||
unknownLbas = new List<ulong>();
|
||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
|
||||
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return null;
|
||||
|
||||
int bps = (int)(buffer.Length / length);
|
||||
byte[] sector = new byte[bps];
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
|
||||
@@ -142,18 +142,15 @@ namespace Aaru.Tests.Issues
|
||||
|
||||
if(UseLong)
|
||||
{
|
||||
if(sectorsToDo == 1)
|
||||
{
|
||||
sector = inputFormat.ReadSectorLong(doneSectors + track.StartSector);
|
||||
result = outputOptical.WriteSectorLong(sector, doneSectors + track.StartSector);
|
||||
}
|
||||
else
|
||||
{
|
||||
sector = inputFormat.ReadSectorsLong(doneSectors + track.StartSector, sectorsToDo);
|
||||
errno = sectorsToDo == 1 ? inputFormat.ReadSectorLong(doneSectors + track.StartSector, out sector) : inputFormat.ReadSectorsLong(doneSectors + track.StartSector, sectorsToDo, out sector);
|
||||
|
||||
result = outputOptical.WriteSectorsLong(sector, doneSectors + track.StartSector,
|
||||
sectorsToDo);
|
||||
}
|
||||
if(errno == ErrorNumber.NoError)
|
||||
result = sectorsToDo == 1
|
||||
? outputOptical.WriteSectorLong(sector, doneSectors + track.StartSector)
|
||||
: outputOptical.WriteSectorsLong(sector, doneSectors + track.StartSector,
|
||||
sectorsToDo);
|
||||
else
|
||||
result = false;
|
||||
|
||||
if(!result &&
|
||||
sector.Length % 2352 != 0)
|
||||
|
||||
@@ -199,18 +199,15 @@ namespace Aaru.Tests.WritableImages
|
||||
|
||||
if(useLong)
|
||||
{
|
||||
if(sectorsToDo == 1)
|
||||
{
|
||||
sector = inputFormat.ReadSectorLong(doneSectors + track.StartSector);
|
||||
result = outputFormat.WriteSectorLong(sector, doneSectors + track.StartSector);
|
||||
}
|
||||
else
|
||||
{
|
||||
sector = inputFormat.ReadSectorsLong(doneSectors + track.StartSector, sectorsToDo);
|
||||
errno = sectorsToDo == 1 ? inputFormat.ReadSectorLong(doneSectors + track.StartSector, out sector) : inputFormat.ReadSectorsLong(doneSectors + track.StartSector, sectorsToDo, out sector);
|
||||
|
||||
result = outputFormat.WriteSectorsLong(sector, doneSectors + track.StartSector,
|
||||
sectorsToDo);
|
||||
}
|
||||
if(errno == ErrorNumber.NoError)
|
||||
result = sectorsToDo == 1
|
||||
? outputFormat.WriteSectorLong(sector, doneSectors + track.StartSector)
|
||||
: outputFormat.WriteSectorsLong(sector,
|
||||
doneSectors + track.StartSector, sectorsToDo);
|
||||
else
|
||||
result = false;
|
||||
|
||||
if(!result &&
|
||||
sector.Length % 2352 != 0)
|
||||
|
||||
@@ -826,22 +826,36 @@ namespace Aaru.Commands.Image
|
||||
|
||||
if(useLong)
|
||||
{
|
||||
if(sectorsToDo == 1)
|
||||
{
|
||||
sector = inputFormat.ReadSectorLong(doneSectors + track.StartSector);
|
||||
errno = sectorsToDo == 1
|
||||
? inputFormat.ReadSectorLong(doneSectors + track.StartSector,
|
||||
out sector)
|
||||
: inputFormat.ReadSectorsLong(doneSectors + track.StartSector,
|
||||
sectorsToDo, out sector);
|
||||
|
||||
result =
|
||||
outputFormat.WriteSectorLong(sector,
|
||||
doneSectors + track.StartSector);
|
||||
}
|
||||
if(errno == ErrorNumber.NoError)
|
||||
result = sectorsToDo == 1
|
||||
? outputFormat.WriteSectorLong(sector,
|
||||
doneSectors + track.StartSector)
|
||||
: outputFormat.WriteSectorsLong(sector,
|
||||
doneSectors + track.StartSector, sectorsToDo);
|
||||
else
|
||||
{
|
||||
sector = inputFormat.ReadSectorsLong(doneSectors + track.StartSector,
|
||||
sectorsToDo);
|
||||
result = true;
|
||||
|
||||
result =
|
||||
outputFormat.WriteSectorsLong(sector,
|
||||
doneSectors + track.StartSector, sectorsToDo);
|
||||
if(force)
|
||||
AaruConsole.
|
||||
ErrorWriteLine("Error {0} reading sector {1}, continuing...",
|
||||
errno, doneSectors + track.StartSector);
|
||||
else
|
||||
{
|
||||
AaruConsole.
|
||||
ErrorWriteLine("Error {0} reading sector {1}, not continuing...",
|
||||
errno, doneSectors + track.StartSector);
|
||||
|
||||
errno = ErrorNumber.WriteError;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(!result &&
|
||||
@@ -1256,16 +1270,33 @@ namespace Aaru.Commands.Image
|
||||
bool result;
|
||||
|
||||
if(useLong)
|
||||
if(sectorsToDo == 1)
|
||||
{
|
||||
sector = inputFormat.ReadSectorLong(doneSectors);
|
||||
result = outputFormat.WriteSectorLong(sector, doneSectors);
|
||||
}
|
||||
{
|
||||
errno = sectorsToDo == 1 ? inputFormat.ReadSectorLong(doneSectors, out sector)
|
||||
: inputFormat.ReadSectorsLong(doneSectors, sectorsToDo, out sector);
|
||||
|
||||
if(errno == ErrorNumber.NoError)
|
||||
result = sectorsToDo == 1
|
||||
? outputFormat.WriteSectorLong(sector, doneSectors)
|
||||
: outputFormat.WriteSectorsLong(sector, doneSectors,
|
||||
sectorsToDo);
|
||||
else
|
||||
{
|
||||
sector = inputFormat.ReadSectorsLong(doneSectors, sectorsToDo);
|
||||
result = outputFormat.WriteSectorsLong(sector, doneSectors, sectorsToDo);
|
||||
result = true;
|
||||
|
||||
if(force)
|
||||
AaruConsole.
|
||||
ErrorWriteLine("Error {0} reading sector {1}, continuing...", errno,
|
||||
doneSectors);
|
||||
else
|
||||
{
|
||||
AaruConsole.
|
||||
ErrorWriteLine("Error {0} reading sector {1}, not continuing...",
|
||||
errno, doneSectors);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = sectorsToDo == 1 ? inputFormat.ReadSector(doneSectors, out sector)
|
||||
|
||||
@@ -209,10 +209,8 @@ namespace Aaru.Commands.Image
|
||||
{
|
||||
ctx.AddTask("Reading sector...").IsIndeterminate();
|
||||
|
||||
if(longSectors)
|
||||
sector = inputFormat.ReadSectorLong(start + i);
|
||||
else
|
||||
errno = inputFormat.ReadSector(start + i, out sector);
|
||||
errno = longSectors ? inputFormat.ReadSectorLong(start + i, out sector)
|
||||
: inputFormat.ReadSector(start + i, out sector);
|
||||
});
|
||||
|
||||
if(errno == ErrorNumber.NoError)
|
||||
|
||||
Reference in New Issue
Block a user