From a6690aa121d46e829559e9eea0ecd80e1b22a31e Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 20 Sep 2021 14:22:22 +0100 Subject: [PATCH] Refactor IMediaImage.ReadSector(s)Long to return error status instead of buffer. --- Aaru.CommonTypes | 2 +- Aaru.Filesystems/ISO9660/File.cs | 9 +- Aaru.Filesystems/ISO9660/Mode2.cs | 33 +-- Aaru.Filesystems/ISO9660/Xattr.cs | 15 +- .../Windows/ImageConvertViewModel.cs | 75 ++++- .../ViewModels/Windows/ViewSectorViewModel.cs | 19 +- Aaru.Images/AaruFormat/Read.cs | 257 +++++++++--------- Aaru.Images/AaruFormat/Verify.cs | 12 +- Aaru.Images/Alcohol120/Read.cs | 17 +- Aaru.Images/Alcohol120/Verify.cs | 15 +- Aaru.Images/Anex86/Unsupported.cs | 16 +- Aaru.Images/Apple2MG/Unsupported.cs | 16 +- Aaru.Images/AppleDOS/Unsupported.cs | 16 +- Aaru.Images/AppleNIB/Read.cs | 31 ++- Aaru.Images/Apridisk/Unsupported.cs | 16 +- Aaru.Images/BLU/Read.cs | 15 +- Aaru.Images/BlindWrite4/Read.cs | 15 +- Aaru.Images/BlindWrite4/Verify.cs | 15 +- Aaru.Images/BlindWrite5/Read.cs | 15 +- Aaru.Images/BlindWrite5/Verify.cs | 15 +- Aaru.Images/CDRDAO/Read.cs | 21 +- Aaru.Images/CDRDAO/Verify.cs | 15 +- Aaru.Images/CDRWin/Read.cs | 15 +- Aaru.Images/CDRWin/Verify.cs | 15 +- Aaru.Images/CHD/Read.cs | 39 +-- Aaru.Images/CHD/Verify.cs | 11 +- Aaru.Images/CPCDSK/Unsupported.cs | 17 +- Aaru.Images/CisCopy/Unsupported.cs | 16 +- Aaru.Images/CloneCD/Read.cs | 15 +- Aaru.Images/CloneCD/Verify.cs | 15 +- Aaru.Images/CopyQM/Unsupported.cs | 16 +- Aaru.Images/CopyTape/Unsupported.cs | 16 +- Aaru.Images/D88/Unsupported.cs | 16 +- Aaru.Images/DART/Read.cs | 19 +- Aaru.Images/DIM/Unsupported.cs | 16 +- Aaru.Images/DiscFerret/Read.cs | 15 +- Aaru.Images/DiscJuggler/Read.cs | 15 +- Aaru.Images/DiscJuggler/Verify.cs | 15 +- Aaru.Images/DiskCopy42/Read.cs | 19 +- Aaru.Images/DiskDupe/Unsupported.cs | 16 +- Aaru.Images/DriDiskCopy/Unsupported.cs | 16 +- Aaru.Images/GDI/Read.cs | 15 +- Aaru.Images/GDI/Verify.cs | 15 +- Aaru.Images/HDCopy/Unsupported.cs | 16 +- Aaru.Images/IMD/Unsupported.cs | 16 +- Aaru.Images/KryoFlux/Read.cs | 12 +- Aaru.Images/MaxiDisk/Unsupported.cs | 16 +- Aaru.Images/NDIF/Unsupported.cs | 16 +- Aaru.Images/NHDr0/Unsupported.cs | 16 +- Aaru.Images/Nero/Read.cs | 15 +- Aaru.Images/Nero/Verify.cs | 15 +- Aaru.Images/Parallels/Unsupported.cs | 16 +- Aaru.Images/PartClone/Unsupported.cs | 16 +- Aaru.Images/Partimage/Unsupported.cs | 16 +- Aaru.Images/QCOW/Unsupported.cs | 16 +- Aaru.Images/QCOW2/Unsupported.cs | 16 +- Aaru.Images/QED/Unsupported.cs | 16 +- Aaru.Images/RayDIM/Unsupported.cs | 16 +- Aaru.Images/RsIde/Unsupported.cs | 16 +- Aaru.Images/SaveDskF/Unsupported.cs | 16 +- Aaru.Images/SuperCardPro/Read.cs | 12 +- Aaru.Images/T98/Unsupported.cs | 16 +- Aaru.Images/TeleDisk/Read.cs | 16 +- Aaru.Images/UDIF/Unsupported.cs | 16 +- Aaru.Images/UkvFdi/Unsupported.cs | 16 +- Aaru.Images/VDI/Unsupported.cs | 16 +- Aaru.Images/VHD/Unsupported.cs | 16 +- Aaru.Images/VHDX/Unsupported.cs | 16 +- Aaru.Images/VMware/Unsupported.cs | 16 +- Aaru.Images/Virtual98/Unsupported.cs | 16 +- Aaru.Images/WCDiskImage/Unsupported.cs | 16 +- Aaru.Images/ZZZRawImage/Read.cs | 25 +- Aaru.Images/ZZZRawImage/Verify.cs | 15 +- .../Issues/OpticalImageConvertIssueTest.cs | 19 +- .../WritableOpticalMediaImageTest.cs | 19 +- Aaru/Commands/Image/Convert.cs | 69 +++-- Aaru/Commands/Image/Print.cs | 6 +- 77 files changed, 1048 insertions(+), 555 deletions(-) diff --git a/Aaru.CommonTypes b/Aaru.CommonTypes index 5bc77788e..95525cff7 160000 --- a/Aaru.CommonTypes +++ b/Aaru.CommonTypes @@ -1 +1 @@ -Subproject commit 5bc77788ece229aac83b0605b6652f1e56db3d5c +Subproject commit 95525cff74eb1ac3639e61276e5294cb34af3886 diff --git a/Aaru.Filesystems/ISO9660/File.cs b/Aaru.Filesystems/ISO9660/File.cs index 14067beba..8bf766aad 100644 --- a/Aaru.Filesystems/ISO9660/File.cs +++ b/Aaru.Filesystems/ISO9660/File.cs @@ -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; } } diff --git a/Aaru.Filesystems/ISO9660/Mode2.cs b/Aaru.Filesystems/ISO9660/Mode2.cs index 7c73fd59d..51a996ebb 100644 --- a/Aaru.Filesystems/ISO9660/Mode2.cs +++ b/Aaru.Filesystems/ISO9660/Mode2.cs @@ -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; } } } diff --git a/Aaru.Filesystems/ISO9660/Xattr.cs b/Aaru.Filesystems/ISO9660/Xattr.cs index 12c1b91e0..4b2200d9d 100644 --- a/Aaru.Filesystems/ISO9660/Xattr.cs +++ b/Aaru.Filesystems/ISO9660/Xattr.cs @@ -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"); diff --git a/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs b/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs index dab5eb744..0d84d4330 100644 --- a/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs @@ -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 diff --git a/Aaru.Gui/ViewModels/Windows/ViewSectorViewModel.cs b/Aaru.Gui/ViewModels/Windows/ViewSectorViewModel.cs index 6c348aac6..e5db689c8 100644 --- a/Aaru.Gui/ViewModels/Windows/ViewSectorViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/ViewSectorViewModel.cs @@ -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); diff --git a/Aaru.Images/AaruFormat/Read.cs b/Aaru.Images/AaruFormat/Read.cs index ce9fb9d3f..c0b307cea 100644 --- a/Aaru.Images/AaruFormat/Read.cs +++ b/Aaru.Images/AaruFormat/Read.cs @@ -1980,9 +1980,10 @@ namespace Aaru.DiscImages } /// - 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; } /// @@ -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; } /// - 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; } /// @@ -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; } /// diff --git a/Aaru.Images/AaruFormat/Verify.cs b/Aaru.Images/AaruFormat/Verify.cs index 4a40c8448..3add3caaa 100644 --- a/Aaru.Images/AaruFormat/Verify.cs +++ b/Aaru.Images/AaruFormat/Verify.cs @@ -76,7 +76,7 @@ namespace Aaru.DiscImages _imageStream.Position -= _structureBytes.Length; - List vrIndex = new List(); + List 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); } /// @@ -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(); diff --git a/Aaru.Images/Alcohol120/Read.cs b/Aaru.Images/Alcohol120/Read.cs index 8aa8482f2..8b274273c 100644 --- a/Aaru.Images/Alcohol120/Read.cs +++ b/Aaru.Images/Alcohol120/Read.cs @@ -1373,14 +1373,17 @@ namespace Aaru.DiscImages } /// - public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1); + public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) => + ReadSectorsLong(sectorAddress, 1, out buffer); /// public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track); /// - public byte[] ReadSectorsLong(ulong sectorAddress, uint length) + public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer) { + buffer = null; + foreach(KeyValuePair 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; } /// diff --git a/Aaru.Images/Alcohol120/Verify.cs b/Aaru.Images/Alcohol120/Verify.cs index 1ca633518..575706d1b 100644 --- a/Aaru.Images/Alcohol120/Verify.cs +++ b/Aaru.Images/Alcohol120/Verify.cs @@ -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 /// 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); } /// public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, out List unknownLbas) { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; failingLbas = new List(); unknownLbas = new List(); + 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++) { diff --git a/Aaru.Images/Anex86/Unsupported.cs b/Aaru.Images/Anex86/Unsupported.cs index 42dfe7abb..2272b2e11 100644 --- a/Aaru.Images/Anex86/Unsupported.cs +++ b/Aaru.Images/Anex86/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/Apple2MG/Unsupported.cs b/Aaru.Images/Apple2MG/Unsupported.cs index 69f67979d..a779994e7 100644 --- a/Aaru.Images/Apple2MG/Unsupported.cs +++ b/Aaru.Images/Apple2MG/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/AppleDOS/Unsupported.cs b/Aaru.Images/AppleDOS/Unsupported.cs index e689d840d..37cedf7a9 100644 --- a/Aaru.Images/AppleDOS/Unsupported.cs +++ b/Aaru.Images/AppleDOS/Unsupported.cs @@ -46,12 +46,20 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } /// public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer) diff --git a/Aaru.Images/AppleNIB/Read.cs b/Aaru.Images/AppleNIB/Read.cs index fdd08117e..c821a102e 100644 --- a/Aaru.Images/AppleNIB/Read.cs +++ b/Aaru.Images/AppleNIB/Read.cs @@ -246,36 +246,43 @@ namespace Aaru.DiscImages } /// - 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; } /// - 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; } } } \ No newline at end of file diff --git a/Aaru.Images/Apridisk/Unsupported.cs b/Aaru.Images/Apridisk/Unsupported.cs index 48066ddf0..5764683fa 100644 --- a/Aaru.Images/Apridisk/Unsupported.cs +++ b/Aaru.Images/Apridisk/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/BLU/Read.cs b/Aaru.Images/BLU/Read.cs index ecbae6019..8cc7986ea 100644 --- a/Aaru.Images/BLU/Read.cs +++ b/Aaru.Images/BLU/Read.cs @@ -228,23 +228,26 @@ namespace Aaru.DiscImages } /// - public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1); + public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) => + ReadSectorsLong(sectorAddress, 1, out buffer); /// - 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; } } } \ No newline at end of file diff --git a/Aaru.Images/BlindWrite4/Read.cs b/Aaru.Images/BlindWrite4/Read.cs index 1c183ec99..96b202126 100644 --- a/Aaru.Images/BlindWrite4/Read.cs +++ b/Aaru.Images/BlindWrite4/Read.cs @@ -1184,21 +1184,28 @@ namespace Aaru.DiscImages } /// - public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1); + public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) => + ReadSectorsLong(sectorAddress, 1, out buffer); /// public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track); /// - public byte[] ReadSectorsLong(ulong sectorAddress, uint length) + public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer) { + buffer = null; + foreach(KeyValuePair 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; } /// diff --git a/Aaru.Images/BlindWrite4/Verify.cs b/Aaru.Images/BlindWrite4/Verify.cs index 1dd091a12..6591eb86c 100644 --- a/Aaru.Images/BlindWrite4/Verify.cs +++ b/Aaru.Images/BlindWrite4/Verify.cs @@ -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 /// 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); } /// public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, out List unknownLbas) { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; failingLbas = new List(); unknownLbas = new List(); + 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++) { diff --git a/Aaru.Images/BlindWrite5/Read.cs b/Aaru.Images/BlindWrite5/Read.cs index 325303e4b..70d30b464 100644 --- a/Aaru.Images/BlindWrite5/Read.cs +++ b/Aaru.Images/BlindWrite5/Read.cs @@ -2103,21 +2103,28 @@ namespace Aaru.DiscImages } /// - public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1); + public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) => + ReadSectorsLong(sectorAddress, 1, out buffer); /// public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track); /// - public byte[] ReadSectorsLong(ulong sectorAddress, uint length) + public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer) { + buffer = null; + foreach(KeyValuePair 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; } /// diff --git a/Aaru.Images/BlindWrite5/Verify.cs b/Aaru.Images/BlindWrite5/Verify.cs index 712361d54..5ef8939fd 100644 --- a/Aaru.Images/BlindWrite5/Verify.cs +++ b/Aaru.Images/BlindWrite5/Verify.cs @@ -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 /// 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); } /// public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, out List unknownLbas) { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; failingLbas = new List(); unknownLbas = new List(); + 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++) { diff --git a/Aaru.Images/CDRDAO/Read.cs b/Aaru.Images/CDRDAO/Read.cs index 0aab46435..3122e4302 100644 --- a/Aaru.Images/CDRDAO/Read.cs +++ b/Aaru.Images/CDRDAO/Read.cs @@ -913,7 +913,8 @@ namespace Aaru.DiscImages } /// - 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); /// 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 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 } /// - public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1); + public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) => + ReadSectorsLong(sectorAddress, 1, out buffer); /// public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track); /// - public byte[] ReadSectorsLong(ulong sectorAddress, uint length) + public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer) { + buffer = null; + foreach(KeyValuePair 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; } /// diff --git a/Aaru.Images/CDRDAO/Verify.cs b/Aaru.Images/CDRDAO/Verify.cs index 304d7f2b1..d2e5f93ea 100644 --- a/Aaru.Images/CDRDAO/Verify.cs +++ b/Aaru.Images/CDRDAO/Verify.cs @@ -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 /// 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); } /// public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, out List unknownLbas) { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; failingLbas = new List(); unknownLbas = new List(); + 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++) { diff --git a/Aaru.Images/CDRWin/Read.cs b/Aaru.Images/CDRWin/Read.cs index 9ec162807..0d614b967 100644 --- a/Aaru.Images/CDRWin/Read.cs +++ b/Aaru.Images/CDRWin/Read.cs @@ -2030,21 +2030,28 @@ namespace Aaru.DiscImages } /// - public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1); + public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) => + ReadSectorsLong(sectorAddress, 1, out buffer); /// public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track); /// - public byte[] ReadSectorsLong(ulong sectorAddress, uint length) + public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer) { + buffer = null; + foreach(KeyValuePair 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; } /// diff --git a/Aaru.Images/CDRWin/Verify.cs b/Aaru.Images/CDRWin/Verify.cs index 79bad595d..27d88f13a 100644 --- a/Aaru.Images/CDRWin/Verify.cs +++ b/Aaru.Images/CDRWin/Verify.cs @@ -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 /// 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); } /// public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, out List unknownLbas) { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; failingLbas = new List(); unknownLbas = new List(); + 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++) { diff --git a/Aaru.Images/CHD/Read.cs b/Aaru.Images/CHD/Read.cs index d80c495e4..924748500 100644 --- a/Aaru.Images/CHD/Read.cs +++ b/Aaru.Images/CHD/Read.cs @@ -1774,20 +1774,15 @@ namespace Aaru.DiscImages } /// - 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; } /// - 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; } /// @@ -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; } /// diff --git a/Aaru.Images/CHD/Verify.cs b/Aaru.Images/CHD/Verify.cs index 77bae4482..648300d94 100644 --- a/Aaru.Images/CHD/Verify.cs +++ b/Aaru.Images/CHD/Verify.cs @@ -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); } /// @@ -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]; diff --git a/Aaru.Images/CPCDSK/Unsupported.cs b/Aaru.Images/CPCDSK/Unsupported.cs index 2db9f7a41..5754ae3cb 100644 --- a/Aaru.Images/CPCDSK/Unsupported.cs +++ b/Aaru.Images/CPCDSK/Unsupported.cs @@ -31,7 +31,6 @@ // ****************************************************************************/ using Aaru.CommonTypes.Enums; -using Aaru.CommonTypes.Exceptions; namespace Aaru.DiscImages { @@ -46,11 +45,19 @@ namespace Aaru.DiscImages } /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/CisCopy/Unsupported.cs b/Aaru.Images/CisCopy/Unsupported.cs index 2982cc57d..781a3b1a5 100644 --- a/Aaru.Images/CisCopy/Unsupported.cs +++ b/Aaru.Images/CisCopy/Unsupported.cs @@ -46,12 +46,20 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } /// public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer) diff --git a/Aaru.Images/CloneCD/Read.cs b/Aaru.Images/CloneCD/Read.cs index d869b8e99..33672df5f 100644 --- a/Aaru.Images/CloneCD/Read.cs +++ b/Aaru.Images/CloneCD/Read.cs @@ -1352,21 +1352,28 @@ namespace Aaru.DiscImages } /// - public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1); + public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) => + ReadSectorsLong(sectorAddress, 1, out buffer); /// public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track); /// - public byte[] ReadSectorsLong(ulong sectorAddress, uint length) + public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer) { + buffer = null; + foreach(KeyValuePair 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; } /// diff --git a/Aaru.Images/CloneCD/Verify.cs b/Aaru.Images/CloneCD/Verify.cs index 0c3d18246..02c841fdb 100644 --- a/Aaru.Images/CloneCD/Verify.cs +++ b/Aaru.Images/CloneCD/Verify.cs @@ -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 /// 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); } /// public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, out List unknownLbas) { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; failingLbas = new List(); unknownLbas = new List(); + 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++) { diff --git a/Aaru.Images/CopyQM/Unsupported.cs b/Aaru.Images/CopyQM/Unsupported.cs index bba0425bc..6e7c99706 100644 --- a/Aaru.Images/CopyQM/Unsupported.cs +++ b/Aaru.Images/CopyQM/Unsupported.cs @@ -46,12 +46,20 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } /// public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer) diff --git a/Aaru.Images/CopyTape/Unsupported.cs b/Aaru.Images/CopyTape/Unsupported.cs index 3643b05e4..a9789c8be 100644 --- a/Aaru.Images/CopyTape/Unsupported.cs +++ b/Aaru.Images/CopyTape/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/D88/Unsupported.cs b/Aaru.Images/D88/Unsupported.cs index d271f305f..46cc5d804 100644 --- a/Aaru.Images/D88/Unsupported.cs +++ b/Aaru.Images/D88/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/DART/Read.cs b/Aaru.Images/DART/Read.cs index 65189d4b3..384c87486 100644 --- a/Aaru.Images/DART/Read.cs +++ b/Aaru.Images/DART/Read.cs @@ -373,24 +373,27 @@ namespace Aaru.DiscImages } /// - public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1); + public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) => + ReadSectorsLong(sectorAddress, 1, out buffer); /// - 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; } } } \ No newline at end of file diff --git a/Aaru.Images/DIM/Unsupported.cs b/Aaru.Images/DIM/Unsupported.cs index 5a7913e6b..425777533 100644 --- a/Aaru.Images/DIM/Unsupported.cs +++ b/Aaru.Images/DIM/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/DiscFerret/Read.cs b/Aaru.Images/DiscFerret/Read.cs index 9d7a0a3fc..7d1193611 100644 --- a/Aaru.Images/DiscFerret/Read.cs +++ b/Aaru.Images/DiscFerret/Read.cs @@ -135,7 +135,8 @@ namespace Aaru.DiscImages } /// - 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); /// public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) => @@ -154,11 +155,15 @@ namespace Aaru.DiscImages throw new NotImplementedException("Flux decoding is not yet implemented."); /// - 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); /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/DiscJuggler/Read.cs b/Aaru.Images/DiscJuggler/Read.cs index cdc14943b..c95c3981e 100644 --- a/Aaru.Images/DiscJuggler/Read.cs +++ b/Aaru.Images/DiscJuggler/Read.cs @@ -1238,21 +1238,28 @@ namespace Aaru.DiscImages } /// - public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1); + public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) => + ReadSectorsLong(sectorAddress, 1, out buffer); /// public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track); /// - public byte[] ReadSectorsLong(ulong sectorAddress, uint length) + public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer) { + buffer = null; + foreach(KeyValuePair 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; } /// diff --git a/Aaru.Images/DiscJuggler/Verify.cs b/Aaru.Images/DiscJuggler/Verify.cs index e6d0413d0..bacf48749 100644 --- a/Aaru.Images/DiscJuggler/Verify.cs +++ b/Aaru.Images/DiscJuggler/Verify.cs @@ -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 /// 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); } /// public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, out List unknownLbas) { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; failingLbas = new List(); unknownLbas = new List(); + 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++) { diff --git a/Aaru.Images/DiskCopy42/Read.cs b/Aaru.Images/DiskCopy42/Read.cs index 30e083bb8..56835f8e0 100644 --- a/Aaru.Images/DiskCopy42/Read.cs +++ b/Aaru.Images/DiskCopy42/Read.cs @@ -530,24 +530,27 @@ namespace Aaru.DiscImages } /// - public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1); + public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) => + ReadSectorsLong(sectorAddress, 1, out buffer); /// - 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; } } } \ No newline at end of file diff --git a/Aaru.Images/DiskDupe/Unsupported.cs b/Aaru.Images/DiskDupe/Unsupported.cs index e35feb271..be5c7093a 100644 --- a/Aaru.Images/DiskDupe/Unsupported.cs +++ b/Aaru.Images/DiskDupe/Unsupported.cs @@ -55,11 +55,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/DriDiskCopy/Unsupported.cs b/Aaru.Images/DriDiskCopy/Unsupported.cs index 82dbc05c3..d5b7bd6eb 100644 --- a/Aaru.Images/DriDiskCopy/Unsupported.cs +++ b/Aaru.Images/DriDiskCopy/Unsupported.cs @@ -46,12 +46,20 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } /// public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer) diff --git a/Aaru.Images/GDI/Read.cs b/Aaru.Images/GDI/Read.cs index 3f9260587..e85597bb8 100644 --- a/Aaru.Images/GDI/Read.cs +++ b/Aaru.Images/GDI/Read.cs @@ -689,21 +689,28 @@ namespace Aaru.DiscImages } /// - public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1); + public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) => + ReadSectorsLong(sectorAddress, 1, out buffer); /// public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track); /// - public byte[] ReadSectorsLong(ulong sectorAddress, uint length) + public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer) { + buffer = null; + foreach(KeyValuePair 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; } /// diff --git a/Aaru.Images/GDI/Verify.cs b/Aaru.Images/GDI/Verify.cs index 8477b3af3..7eef5133d 100644 --- a/Aaru.Images/GDI/Verify.cs +++ b/Aaru.Images/GDI/Verify.cs @@ -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 /// 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); } /// public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, out List unknownLbas) { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; failingLbas = new List(); unknownLbas = new List(); + 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++) { diff --git a/Aaru.Images/HDCopy/Unsupported.cs b/Aaru.Images/HDCopy/Unsupported.cs index 31d221b5b..8a4d8560e 100644 --- a/Aaru.Images/HDCopy/Unsupported.cs +++ b/Aaru.Images/HDCopy/Unsupported.cs @@ -55,11 +55,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/IMD/Unsupported.cs b/Aaru.Images/IMD/Unsupported.cs index 8be83f4a1..c5a3ab5ce 100644 --- a/Aaru.Images/IMD/Unsupported.cs +++ b/Aaru.Images/IMD/Unsupported.cs @@ -46,12 +46,20 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } /// public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer) diff --git a/Aaru.Images/KryoFlux/Read.cs b/Aaru.Images/KryoFlux/Read.cs index 0d58e4310..38fea0c06 100644 --- a/Aaru.Images/KryoFlux/Read.cs +++ b/Aaru.Images/KryoFlux/Read.cs @@ -284,11 +284,15 @@ namespace Aaru.DiscImages throw new NotImplementedException("Flux decoding is not yet implemented."); /// - 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); /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/MaxiDisk/Unsupported.cs b/Aaru.Images/MaxiDisk/Unsupported.cs index efe5317d0..90aef21ef 100644 --- a/Aaru.Images/MaxiDisk/Unsupported.cs +++ b/Aaru.Images/MaxiDisk/Unsupported.cs @@ -46,12 +46,20 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } /// public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer) diff --git a/Aaru.Images/NDIF/Unsupported.cs b/Aaru.Images/NDIF/Unsupported.cs index 7c96df916..054ee8e3a 100644 --- a/Aaru.Images/NDIF/Unsupported.cs +++ b/Aaru.Images/NDIF/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages } /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/NHDr0/Unsupported.cs b/Aaru.Images/NHDr0/Unsupported.cs index 84dd3eabc..03e966a8e 100644 --- a/Aaru.Images/NHDr0/Unsupported.cs +++ b/Aaru.Images/NHDr0/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/Nero/Read.cs b/Aaru.Images/Nero/Read.cs index df560bf84..db61fe06e 100644 --- a/Aaru.Images/Nero/Read.cs +++ b/Aaru.Images/Nero/Read.cs @@ -2082,21 +2082,28 @@ namespace Aaru.DiscImages } /// - public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1); + public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) => + ReadSectorsLong(sectorAddress, 1, out buffer); /// public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track); /// - public byte[] ReadSectorsLong(ulong sectorAddress, uint length) + public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer) { + buffer = null; + foreach(KeyValuePair 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; } /// diff --git a/Aaru.Images/Nero/Verify.cs b/Aaru.Images/Nero/Verify.cs index fcbc7acfb..041985213 100644 --- a/Aaru.Images/Nero/Verify.cs +++ b/Aaru.Images/Nero/Verify.cs @@ -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 /// 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); } /// public bool? VerifySectors(ulong sectorAddress, uint length, out List failingLbas, out List unknownLbas) { - byte[] buffer = ReadSectorsLong(sectorAddress, length); - int bps = (int)(buffer.Length / length); - byte[] sector = new byte[bps]; failingLbas = new List(); unknownLbas = new List(); + 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++) { diff --git a/Aaru.Images/Parallels/Unsupported.cs b/Aaru.Images/Parallels/Unsupported.cs index 3f0ad184b..9fef423aa 100644 --- a/Aaru.Images/Parallels/Unsupported.cs +++ b/Aaru.Images/Parallels/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages } /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/PartClone/Unsupported.cs b/Aaru.Images/PartClone/Unsupported.cs index 25d579b8a..d6578f9a8 100644 --- a/Aaru.Images/PartClone/Unsupported.cs +++ b/Aaru.Images/PartClone/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages } /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/Partimage/Unsupported.cs b/Aaru.Images/Partimage/Unsupported.cs index 4d1e6c8ea..cfa4245f1 100644 --- a/Aaru.Images/Partimage/Unsupported.cs +++ b/Aaru.Images/Partimage/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages } /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/QCOW/Unsupported.cs b/Aaru.Images/QCOW/Unsupported.cs index cb70a59d0..d35a89c66 100644 --- a/Aaru.Images/QCOW/Unsupported.cs +++ b/Aaru.Images/QCOW/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages } /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/QCOW2/Unsupported.cs b/Aaru.Images/QCOW2/Unsupported.cs index 71c18660f..57219f9b7 100644 --- a/Aaru.Images/QCOW2/Unsupported.cs +++ b/Aaru.Images/QCOW2/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages } /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/QED/Unsupported.cs b/Aaru.Images/QED/Unsupported.cs index 4c5ea1e02..7d8ba38ee 100644 --- a/Aaru.Images/QED/Unsupported.cs +++ b/Aaru.Images/QED/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages } /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/RayDIM/Unsupported.cs b/Aaru.Images/RayDIM/Unsupported.cs index fb888eb6d..472f3e47c 100644 --- a/Aaru.Images/RayDIM/Unsupported.cs +++ b/Aaru.Images/RayDIM/Unsupported.cs @@ -46,12 +46,20 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } /// public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer) diff --git a/Aaru.Images/RsIde/Unsupported.cs b/Aaru.Images/RsIde/Unsupported.cs index 3d8e657fd..092f60557 100644 --- a/Aaru.Images/RsIde/Unsupported.cs +++ b/Aaru.Images/RsIde/Unsupported.cs @@ -46,11 +46,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/SaveDskF/Unsupported.cs b/Aaru.Images/SaveDskF/Unsupported.cs index 95b061754..1b830c880 100644 --- a/Aaru.Images/SaveDskF/Unsupported.cs +++ b/Aaru.Images/SaveDskF/Unsupported.cs @@ -46,12 +46,20 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } /// public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer) diff --git a/Aaru.Images/SuperCardPro/Read.cs b/Aaru.Images/SuperCardPro/Read.cs index 557458f89..100844508 100644 --- a/Aaru.Images/SuperCardPro/Read.cs +++ b/Aaru.Images/SuperCardPro/Read.cs @@ -285,11 +285,15 @@ namespace Aaru.DiscImages throw new NotImplementedException("Flux decoding is not yet implemented."); /// - 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); /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/T98/Unsupported.cs b/Aaru.Images/T98/Unsupported.cs index 099d3c795..59a1f7526 100644 --- a/Aaru.Images/T98/Unsupported.cs +++ b/Aaru.Images/T98/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/TeleDisk/Read.cs b/Aaru.Images/TeleDisk/Read.cs index 4cffed66b..8ef5766aa 100644 --- a/Aaru.Images/TeleDisk/Read.cs +++ b/Aaru.Images/TeleDisk/Read.cs @@ -578,20 +578,12 @@ namespace Aaru.DiscImages } /// - 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); /// - 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); /// public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer) diff --git a/Aaru.Images/UDIF/Unsupported.cs b/Aaru.Images/UDIF/Unsupported.cs index 9a1c0474b..5c94bf265 100644 --- a/Aaru.Images/UDIF/Unsupported.cs +++ b/Aaru.Images/UDIF/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages } /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/UkvFdi/Unsupported.cs b/Aaru.Images/UkvFdi/Unsupported.cs index 249c06d97..87ba2cfad 100644 --- a/Aaru.Images/UkvFdi/Unsupported.cs +++ b/Aaru.Images/UkvFdi/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/VDI/Unsupported.cs b/Aaru.Images/VDI/Unsupported.cs index 3481b421d..0d6389cd6 100644 --- a/Aaru.Images/VDI/Unsupported.cs +++ b/Aaru.Images/VDI/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages } /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/VHD/Unsupported.cs b/Aaru.Images/VHD/Unsupported.cs index 49b26fbb2..84be44f3a 100644 --- a/Aaru.Images/VHD/Unsupported.cs +++ b/Aaru.Images/VHD/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/VHDX/Unsupported.cs b/Aaru.Images/VHDX/Unsupported.cs index e53fb1caa..8fcb9a918 100644 --- a/Aaru.Images/VHDX/Unsupported.cs +++ b/Aaru.Images/VHDX/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/VMware/Unsupported.cs b/Aaru.Images/VMware/Unsupported.cs index 16cc51582..41b48e510 100644 --- a/Aaru.Images/VMware/Unsupported.cs +++ b/Aaru.Images/VMware/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages } /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/Virtual98/Unsupported.cs b/Aaru.Images/Virtual98/Unsupported.cs index 6c103d56c..eb5a9b491 100644 --- a/Aaru.Images/Virtual98/Unsupported.cs +++ b/Aaru.Images/Virtual98/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/WCDiskImage/Unsupported.cs b/Aaru.Images/WCDiskImage/Unsupported.cs index 3e02fa25f..865ae651b 100644 --- a/Aaru.Images/WCDiskImage/Unsupported.cs +++ b/Aaru.Images/WCDiskImage/Unsupported.cs @@ -54,11 +54,19 @@ namespace Aaru.DiscImages throw new FeatureUnsupportedImageException("Feature not supported by image format"); /// - 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; + } /// - 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; + } } } \ No newline at end of file diff --git a/Aaru.Images/ZZZRawImage/Read.cs b/Aaru.Images/ZZZRawImage/Read.cs index 70541b6d6..d887d9842 100644 --- a/Aaru.Images/ZZZRawImage/Read.cs +++ b/Aaru.Images/ZZZRawImage/Read.cs @@ -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; } /// @@ -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; } /// @@ -1535,20 +1539,23 @@ namespace Aaru.DiscImages } /// - public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1); + public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) => + ReadSectorsLong(sectorAddress, 1, out buffer); /// - 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; } /// diff --git a/Aaru.Images/ZZZRawImage/Verify.cs b/Aaru.Images/ZZZRawImage/Verify.cs index d2e6f1db3..f00d7cad7 100644 --- a/Aaru.Images/ZZZRawImage/Verify.cs +++ b/Aaru.Images/ZZZRawImage/Verify.cs @@ -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); } /// @@ -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(); unknownLbas = new List(); + 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++) { diff --git a/Aaru.Tests/Issues/OpticalImageConvertIssueTest.cs b/Aaru.Tests/Issues/OpticalImageConvertIssueTest.cs index da27744bf..5c9ee6827 100644 --- a/Aaru.Tests/Issues/OpticalImageConvertIssueTest.cs +++ b/Aaru.Tests/Issues/OpticalImageConvertIssueTest.cs @@ -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) diff --git a/Aaru.Tests/WritableImages/WritableOpticalMediaImageTest.cs b/Aaru.Tests/WritableImages/WritableOpticalMediaImageTest.cs index 86a3b61d0..973d15592 100644 --- a/Aaru.Tests/WritableImages/WritableOpticalMediaImageTest.cs +++ b/Aaru.Tests/WritableImages/WritableOpticalMediaImageTest.cs @@ -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) diff --git a/Aaru/Commands/Image/Convert.cs b/Aaru/Commands/Image/Convert.cs index 911997c9a..b9e63e77b 100644 --- a/Aaru/Commands/Image/Convert.cs +++ b/Aaru/Commands/Image/Convert.cs @@ -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) diff --git a/Aaru/Commands/Image/Print.cs b/Aaru/Commands/Image/Print.cs index 2c481d17c..f97252084 100644 --- a/Aaru/Commands/Image/Print.cs +++ b/Aaru/Commands/Image/Print.cs @@ -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)