mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Refactor IOpticalMediaImage.ReadSector(s)Long to return error status instead of buffer.
This commit is contained in:
2
.idea/.idea.Aaru/.idea/vcs.xml
generated
2
.idea/.idea.Aaru/.idea/vcs.xml
generated
@@ -9,12 +9,12 @@
|
|||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/Aaru.Checksums" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$/Aaru.Checksums" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/Aaru.CommonTypes" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$/Aaru.CommonTypes" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/Aaru.Compression/cuetools.net" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/Aaru.Console" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$/Aaru.Console" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/Aaru.Decoders" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$/Aaru.Decoders" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/Aaru.Decryption" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$/Aaru.Decryption" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/Aaru.Dto" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$/Aaru.Dto" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/Aaru.Helpers" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$/Aaru.Helpers" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/CICMMetadata" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$/CICMMetadata" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/cuetools.net" vcs="Git" />
|
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
Submodule Aaru.CommonTypes updated: 0fc3e1ef94...cc5779c1ff
@@ -417,7 +417,7 @@ namespace Aaru.Core
|
|||||||
|
|
||||||
if(errno != ErrorNumber.NoError)
|
if(errno != ErrorNumber.NoError)
|
||||||
{
|
{
|
||||||
AaruConsole.ErrorWriteLine($"Error {errno} reading sector {doneSectors}");
|
UpdateStatus($"Error {errno} reading sector {doneSectors}");
|
||||||
EndProgress2();
|
EndProgress2();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -432,7 +432,7 @@ namespace Aaru.Core
|
|||||||
|
|
||||||
if(errno != ErrorNumber.NoError)
|
if(errno != ErrorNumber.NoError)
|
||||||
{
|
{
|
||||||
AaruConsole.ErrorWriteLine($"Error {errno} reading sector {doneSectors}");
|
UpdateStatus($"Error {errno} reading sector {doneSectors}");
|
||||||
EndProgress2();
|
EndProgress2();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ namespace Aaru.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
MediaType dskType = image.Info.MediaType;
|
MediaType dskType = image.Info.MediaType;
|
||||||
|
ErrorNumber errno;
|
||||||
|
|
||||||
UpdateStatus("Hashing media tags...");
|
UpdateStatus("Hashing media tags...");
|
||||||
|
|
||||||
@@ -109,7 +110,7 @@ namespace Aaru.Core
|
|||||||
if(_aborted)
|
if(_aborted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ErrorNumber errno = image.ReadMediaTag(tagType, out byte[] tag);
|
errno = image.ReadMediaTag(tagType, out byte[] tag);
|
||||||
|
|
||||||
if(errno != ErrorNumber.NoError)
|
if(errno != ErrorNumber.NoError)
|
||||||
continue;
|
continue;
|
||||||
@@ -446,21 +447,38 @@ namespace Aaru.Core
|
|||||||
|
|
||||||
if(sectors - doneSectors >= sectorsToRead)
|
if(sectors - doneSectors >= sectorsToRead)
|
||||||
{
|
{
|
||||||
sector = image.ReadSectorsLong(doneSectors, sectorsToRead, xmlTrk.Sequence.TrackNumber);
|
errno = image.ReadSectorsLong(doneSectors, sectorsToRead, xmlTrk.Sequence.TrackNumber,
|
||||||
|
out sector);
|
||||||
|
|
||||||
UpdateProgress2("Hashing sector {0} of {1}", (long)doneSectors,
|
UpdateProgress2("Hashing sector {0} of {1}", (long)doneSectors,
|
||||||
(long)(trk.EndSector - trk.StartSector + 1));
|
(long)(trk.EndSector - trk.StartSector + 1));
|
||||||
|
|
||||||
|
if(errno != ErrorNumber.NoError)
|
||||||
|
{
|
||||||
|
UpdateStatus($"Error {errno} reading sector {doneSectors}");
|
||||||
|
EndProgress2();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
doneSectors += sectorsToRead;
|
doneSectors += sectorsToRead;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sector = image.ReadSectorsLong(doneSectors, (uint)(sectors - doneSectors),
|
errno = image.ReadSectorsLong(doneSectors, (uint)(sectors - doneSectors),
|
||||||
xmlTrk.Sequence.TrackNumber);
|
xmlTrk.Sequence.TrackNumber, out sector);
|
||||||
|
|
||||||
UpdateProgress2("Hashing sector {0} of {1}", (long)doneSectors,
|
UpdateProgress2("Hashing sector {0} of {1}", (long)doneSectors,
|
||||||
(long)(trk.EndSector - trk.StartSector + 1));
|
(long)(trk.EndSector - trk.StartSector + 1));
|
||||||
|
|
||||||
|
if(errno != ErrorNumber.NoError)
|
||||||
|
{
|
||||||
|
UpdateStatus($"Error {errno} reading sector {doneSectors}");
|
||||||
|
EndProgress2();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
doneSectors += sectors - doneSectors;
|
doneSectors += sectors - doneSectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -705,7 +723,7 @@ namespace Aaru.Core
|
|||||||
xmlTrk.FileSystemInformation[0].FileSystems = lstFs.ToArray();
|
xmlTrk.FileSystemInformation[0].FileSystems = lstFs.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorNumber errno = image.ReadSectorTag(trk.Sequence, SectorTagType.CdTrackIsrc, out byte[] isrcData);
|
errno = image.ReadSectorTag(trk.Sequence, SectorTagType.CdTrackIsrc, out byte[] isrcData);
|
||||||
|
|
||||||
if(errno == ErrorNumber.NoError)
|
if(errno == ErrorNumber.NoError)
|
||||||
xmlTrk.ISRC = Encoding.UTF8.GetString(isrcData);
|
xmlTrk.ISRC = Encoding.UTF8.GetString(isrcData);
|
||||||
|
|||||||
@@ -2197,19 +2197,17 @@ namespace Aaru.DiscImages
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track)
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
|
buffer = null;
|
||||||
|
|
||||||
if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc)
|
if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc)
|
||||||
throw new FeatureNotPresentImageException("Feature not present in image");
|
return ErrorNumber.NotSupported;
|
||||||
|
|
||||||
Track trk = Tracks.FirstOrDefault(t => t.Sequence == track);
|
Track trk = Tracks.FirstOrDefault(t => t.Sequence == track);
|
||||||
|
|
||||||
if(trk?.Sequence != track)
|
return trk?.Sequence != track ? ErrorNumber.SectorNotFound
|
||||||
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
: ReadSectorLong(trk.StartSector + sectorAddress, out buffer);
|
||||||
|
|
||||||
ErrorNumber errno = ReadSectorLong(trk.StartSector + sectorAddress, out byte[] buffer);
|
|
||||||
|
|
||||||
return errno != ErrorNumber.NoError ? null : buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -2391,23 +2389,20 @@ namespace Aaru.DiscImages
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
|
buffer = null;
|
||||||
|
|
||||||
if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc)
|
if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc)
|
||||||
throw new FeatureNotPresentImageException("Feature not present in image");
|
return ErrorNumber.NotSupported;
|
||||||
|
|
||||||
Track trk = Tracks.FirstOrDefault(t => t.Sequence == track);
|
Track trk = Tracks.FirstOrDefault(t => t.Sequence == track);
|
||||||
|
|
||||||
if(trk?.Sequence != track)
|
return trk?.Sequence != track
|
||||||
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
? ErrorNumber.SectorNotFound
|
||||||
|
: trk.StartSector + sectorAddress + length > trk.EndSector + 1
|
||||||
if(trk.StartSector + sectorAddress + length > trk.EndSector + 1)
|
? ErrorNumber.OutOfRange
|
||||||
throw new ArgumentOutOfRangeException(nameof(length),
|
: ReadSectorsLong(trk.StartSector + sectorAddress, length, out buffer);
|
||||||
$"Requested more sectors ({length + sectorAddress}) than present in track ({trk.EndSector - trk.StartSector + 1}), won't cross tracks");
|
|
||||||
|
|
||||||
ErrorNumber errno = ReadSectorsLong(trk.StartSector + sectorAddress, length, out byte[] buffer);
|
|
||||||
|
|
||||||
return errno == ErrorNumber.NoError ? buffer : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -283,12 +283,17 @@ namespace Aaru.DiscImages
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
|
||||||
int bps = (int)(buffer.Length / length);
|
|
||||||
byte[] sector = new byte[bps];
|
|
||||||
failingLbas = new List<ulong>();
|
failingLbas = new List<ulong>();
|
||||||
unknownLbas = new List<ulong>();
|
unknownLbas = new List<ulong>();
|
||||||
|
|
||||||
|
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, track, 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++)
|
for(int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
Array.Copy(buffer, i * bps, sector, 0, bps);
|
Array.Copy(buffer, i * bps, sector, 0, bps);
|
||||||
|
|||||||
@@ -1384,7 +1384,8 @@ namespace Aaru.DiscImages
|
|||||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, uint track, out byte[] buffer) =>
|
||||||
|
ReadSectorsLong(sectorAddress, 1, track, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||||
@@ -1402,24 +1403,23 @@ namespace Aaru.DiscImages
|
|||||||
if(sectorAddress - kvp.Value >= alcExtra.sectors + alcExtra.pregap)
|
if(sectorAddress - kvp.Value >= alcExtra.sectors + alcExtra.pregap)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key, out buffer);
|
||||||
|
|
||||||
return buffer == null ? ErrorNumber.NoData : ErrorNumber.NoError;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ErrorNumber.SectorNotFound;
|
return ErrorNumber.SectorNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
|
buffer = null;
|
||||||
|
|
||||||
if(!_alcTracks.TryGetValue((int)track, out Track alcTrack) ||
|
if(!_alcTracks.TryGetValue((int)track, out Track alcTrack) ||
|
||||||
!_alcTrackExtras.TryGetValue((int)track, out TrackExtra alcExtra))
|
!_alcTrackExtras.TryGetValue((int)track, out TrackExtra alcExtra))
|
||||||
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
return ErrorNumber.SectorNotFound;
|
||||||
|
|
||||||
if(length + sectorAddress > alcExtra.sectors + alcExtra.pregap)
|
if(length + sectorAddress > alcExtra.sectors + alcExtra.pregap)
|
||||||
throw new ArgumentOutOfRangeException(nameof(length),
|
return ErrorNumber.OutOfRange;
|
||||||
$"Requested more sectors ({length}) than present in track ({alcExtra.sectors + alcExtra.pregap}), won't cross tracks");
|
|
||||||
|
|
||||||
uint sectorOffset;
|
uint sectorOffset;
|
||||||
uint sectorSize;
|
uint sectorSize;
|
||||||
@@ -1445,19 +1445,19 @@ namespace Aaru.DiscImages
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
default: return ErrorNumber.NotSupported;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(alcTrack.subMode == SubchannelMode.Interleaved)
|
if(alcTrack.subMode == SubchannelMode.Interleaved)
|
||||||
sectorSkip = 96;
|
sectorSkip = 96;
|
||||||
|
|
||||||
byte[] buffer = new byte[sectorSize * length];
|
buffer = new byte[sectorSize * length];
|
||||||
|
|
||||||
if(alcTrack.point == 1 &&
|
if(alcTrack.point == 1 &&
|
||||||
alcExtra.pregap > 150)
|
alcExtra.pregap > 150)
|
||||||
{
|
{
|
||||||
if(sectorAddress + 150 < alcExtra.pregap)
|
if(sectorAddress + 150 < alcExtra.pregap)
|
||||||
return buffer;
|
return ErrorNumber.NoError;
|
||||||
|
|
||||||
sectorAddress -= alcExtra.pregap - 150;
|
sectorAddress -= alcExtra.pregap - 150;
|
||||||
}
|
}
|
||||||
@@ -1487,7 +1487,7 @@ namespace Aaru.DiscImages
|
|||||||
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer;
|
return ErrorNumber.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -89,11 +89,15 @@ namespace Aaru.DiscImages
|
|||||||
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
||||||
out List<ulong> unknownLbas)
|
out List<ulong> unknownLbas)
|
||||||
{
|
{
|
||||||
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
|
||||||
int bps = (int)(buffer.Length / length);
|
|
||||||
byte[] sector = new byte[bps];
|
|
||||||
failingLbas = new List<ulong>();
|
failingLbas = new List<ulong>();
|
||||||
unknownLbas = new List<ulong>();
|
unknownLbas = new List<ulong>();
|
||||||
|
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, track, 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++)
|
for(int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1182,7 +1182,8 @@ namespace Aaru.DiscImages
|
|||||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, uint track, out byte[] buffer) =>
|
||||||
|
ReadSectorsLong(sectorAddress, 1, track, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||||
@@ -1193,36 +1194,22 @@ namespace Aaru.DiscImages
|
|||||||
from track in Tracks where track.Sequence == kvp.Key
|
from track in Tracks where track.Sequence == kvp.Key
|
||||||
where sectorAddress - kvp.Value <
|
where sectorAddress - kvp.Value <
|
||||||
track.EndSector - track.StartSector + 1 select kvp)
|
track.EndSector - track.StartSector + 1 select kvp)
|
||||||
{
|
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key, out buffer);
|
||||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
|
||||||
|
|
||||||
return buffer is null ? ErrorNumber.SectorNotFound : ErrorNumber.NoError;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ErrorNumber.SectorNotFound;
|
return ErrorNumber.SectorNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
var aaruTrack = new Track
|
buffer = null;
|
||||||
{
|
Track? aaruTrack = Tracks.FirstOrDefault(bwTrack => bwTrack.Sequence == track);
|
||||||
Sequence = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach(Track bwTrack in Tracks.Where(bwTrack => bwTrack.Sequence == track))
|
|
||||||
{
|
|
||||||
aaruTrack = bwTrack;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(aaruTrack is null)
|
if(aaruTrack is null)
|
||||||
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
return ErrorNumber.SectorNotFound;
|
||||||
|
|
||||||
if(length + sectorAddress > aaruTrack.EndSector - aaruTrack.StartSector + 1)
|
if(length + sectorAddress > aaruTrack.EndSector - aaruTrack.StartSector + 1)
|
||||||
throw new ArgumentOutOfRangeException(nameof(length),
|
return ErrorNumber.OutOfRange;
|
||||||
$"Requested more sectors ({length + sectorAddress}) than present in track ({aaruTrack.EndSector - aaruTrack.StartSector + 1}), won't cross tracks");
|
|
||||||
|
|
||||||
uint sectorOffset;
|
uint sectorOffset;
|
||||||
uint sectorSize;
|
uint sectorSize;
|
||||||
@@ -1241,7 +1228,7 @@ namespace Aaru.DiscImages
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
default: return ErrorNumber.NotSupported;
|
||||||
}
|
}
|
||||||
|
|
||||||
_imageStream = aaruTrack.Filter.GetDataForkStream();
|
_imageStream = aaruTrack.Filter.GetDataForkStream();
|
||||||
@@ -1251,9 +1238,9 @@ namespace Aaru.DiscImages
|
|||||||
Seek((long)aaruTrack.FileOffset + (long)(sectorAddress * (sectorOffset + sectorSize + sectorSkip)),
|
Seek((long)aaruTrack.FileOffset + (long)(sectorAddress * (sectorOffset + sectorSize + sectorSkip)),
|
||||||
SeekOrigin.Begin);
|
SeekOrigin.Begin);
|
||||||
|
|
||||||
byte[] buffer = br.ReadBytes((int)(sectorSize * length));
|
buffer = br.ReadBytes((int)(sectorSize * length));
|
||||||
|
|
||||||
return buffer;
|
return ErrorNumber.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -89,11 +89,15 @@ namespace Aaru.DiscImages
|
|||||||
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
||||||
out List<ulong> unknownLbas)
|
out List<ulong> unknownLbas)
|
||||||
{
|
{
|
||||||
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
|
||||||
int bps = (int)(buffer.Length / length);
|
|
||||||
byte[] sector = new byte[bps];
|
|
||||||
failingLbas = new List<ulong>();
|
failingLbas = new List<ulong>();
|
||||||
unknownLbas = new List<ulong>();
|
unknownLbas = new List<ulong>();
|
||||||
|
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, track, 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++)
|
for(int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2102,7 +2102,8 @@ namespace Aaru.DiscImages
|
|||||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, uint track, out byte[] buffer) =>
|
||||||
|
ReadSectorsLong(sectorAddress, 1, track, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||||
@@ -2113,37 +2114,24 @@ namespace Aaru.DiscImages
|
|||||||
from track in Tracks where track.Sequence == kvp.Key
|
from track in Tracks where track.Sequence == kvp.Key
|
||||||
where sectorAddress - kvp.Value <
|
where sectorAddress - kvp.Value <
|
||||||
track.EndSector - track.StartSector + 1 select kvp)
|
track.EndSector - track.StartSector + 1 select kvp)
|
||||||
{
|
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key, out buffer);
|
||||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
|
||||||
|
|
||||||
return buffer is null ? ErrorNumber.SectorNotFound : ErrorNumber.NoError;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ErrorNumber.SectorNotFound;
|
return ErrorNumber.SectorNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
|
buffer = null;
|
||||||
|
|
||||||
// TODO: Cross data files
|
// TODO: Cross data files
|
||||||
var aaruTrack = new Track
|
Track? aaruTrack = Tracks.FirstOrDefault(bwTrack => bwTrack.Sequence == track);
|
||||||
{
|
|
||||||
Sequence = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach(Track bwTrack in Tracks.Where(bwTrack => bwTrack.Sequence == track))
|
|
||||||
{
|
|
||||||
aaruTrack = bwTrack;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(aaruTrack is null)
|
if(aaruTrack is null)
|
||||||
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
return ErrorNumber.SectorNotFound;
|
||||||
|
|
||||||
if(length + sectorAddress > aaruTrack.EndSector - aaruTrack.StartSector + 1)
|
if(length + sectorAddress > aaruTrack.EndSector - aaruTrack.StartSector + 1)
|
||||||
throw new ArgumentOutOfRangeException(nameof(length),
|
return ErrorNumber.OutOfRange;
|
||||||
$"Requested more sectors ({length + sectorAddress}) than present in track ({aaruTrack.EndSector - aaruTrack.StartSector + 1}), won't cross tracks");
|
|
||||||
|
|
||||||
DataFileCharacteristics chars = (from characteristics in _filePaths let firstSector =
|
DataFileCharacteristics chars = (from characteristics in _filePaths let firstSector =
|
||||||
characteristics.StartLba let lastSector =
|
characteristics.StartLba let lastSector =
|
||||||
@@ -2154,7 +2142,7 @@ namespace Aaru.DiscImages
|
|||||||
|
|
||||||
if(string.IsNullOrEmpty(chars.FilePath) ||
|
if(string.IsNullOrEmpty(chars.FilePath) ||
|
||||||
chars.FileFilter == null)
|
chars.FileFilter == null)
|
||||||
throw new ArgumentOutOfRangeException(nameof(chars.FileFilter), "Track does not exist in disc image");
|
return ErrorNumber.SectorNotFound;
|
||||||
|
|
||||||
uint sectorOffset;
|
uint sectorOffset;
|
||||||
uint sectorSize;
|
uint sectorSize;
|
||||||
@@ -2182,7 +2170,7 @@ namespace Aaru.DiscImages
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
default: return ErrorNumber.NotSupported;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(chars.Subchannel)
|
switch(chars.Subchannel)
|
||||||
@@ -2199,10 +2187,10 @@ namespace Aaru.DiscImages
|
|||||||
sectorSkip += 96;
|
sectorSkip += 96;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported subchannel type");
|
default: return ErrorNumber.NotSupported;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] buffer = new byte[sectorSize * length];
|
buffer = new byte[sectorSize * length];
|
||||||
|
|
||||||
_imageStream = aaruTrack.Filter.GetDataForkStream();
|
_imageStream = aaruTrack.Filter.GetDataForkStream();
|
||||||
var br = new BinaryReader(_imageStream);
|
var br = new BinaryReader(_imageStream);
|
||||||
@@ -2223,7 +2211,7 @@ namespace Aaru.DiscImages
|
|||||||
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
Array.Copy(sector, 0, buffer, i * sectorSize, sectorSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer;
|
return ErrorNumber.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -89,11 +89,15 @@ namespace Aaru.DiscImages
|
|||||||
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
||||||
out List<ulong> unknownLbas)
|
out List<ulong> unknownLbas)
|
||||||
{
|
{
|
||||||
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
|
||||||
int bps = (int)(buffer.Length / length);
|
|
||||||
byte[] sector = new byte[bps];
|
|
||||||
failingLbas = new List<ulong>();
|
failingLbas = new List<ulong>();
|
||||||
unknownLbas = new List<ulong>();
|
unknownLbas = new List<ulong>();
|
||||||
|
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, track, 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++)
|
for(int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1309,7 +1309,8 @@ namespace Aaru.DiscImages
|
|||||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, uint track, out byte[] buffer) =>
|
||||||
|
ReadSectorsLong(sectorAddress, 1, track, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||||
@@ -1320,18 +1321,16 @@ namespace Aaru.DiscImages
|
|||||||
from cdrdaoTrack in _discimage.Tracks
|
from cdrdaoTrack in _discimage.Tracks
|
||||||
where cdrdaoTrack.Sequence == kvp.Key
|
where cdrdaoTrack.Sequence == kvp.Key
|
||||||
where sectorAddress - kvp.Value < cdrdaoTrack.Sectors select kvp)
|
where sectorAddress - kvp.Value < cdrdaoTrack.Sectors select kvp)
|
||||||
{
|
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key, out buffer);
|
||||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
|
||||||
|
|
||||||
return buffer is null ? ErrorNumber.SectorNotFound : ErrorNumber.NoError;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ErrorNumber.SectorNotFound;
|
return ErrorNumber.SectorNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
|
buffer = null;
|
||||||
|
|
||||||
var aaruTrack = new CdrdaoTrack
|
var aaruTrack = new CdrdaoTrack
|
||||||
{
|
{
|
||||||
Sequence = 0
|
Sequence = 0
|
||||||
@@ -1345,11 +1344,10 @@ namespace Aaru.DiscImages
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(aaruTrack.Sequence == 0)
|
if(aaruTrack.Sequence == 0)
|
||||||
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
return ErrorNumber.SectorNotFound;
|
||||||
|
|
||||||
if(length > aaruTrack.Sectors)
|
if(length > aaruTrack.Sectors)
|
||||||
throw new ArgumentOutOfRangeException(nameof(length),
|
return ErrorNumber.OutOfRange;
|
||||||
"Requested more sectors than present in track, won't cross tracks");
|
|
||||||
|
|
||||||
uint sectorOffset;
|
uint sectorOffset;
|
||||||
uint sectorSize;
|
uint sectorSize;
|
||||||
@@ -1393,13 +1391,13 @@ namespace Aaru.DiscImages
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
default: return ErrorNumber.NotSupported;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(aaruTrack.Subchannel)
|
if(aaruTrack.Subchannel)
|
||||||
sectorSkip += 96;
|
sectorSkip += 96;
|
||||||
|
|
||||||
byte[] buffer = new byte[sectorSize * length];
|
buffer = new byte[sectorSize * length];
|
||||||
|
|
||||||
_imageStream = aaruTrack.Trackfile.Datafilter.GetDataForkStream();
|
_imageStream = aaruTrack.Trackfile.Datafilter.GetDataForkStream();
|
||||||
var br = new BinaryReader(_imageStream);
|
var br = new BinaryReader(_imageStream);
|
||||||
@@ -1517,7 +1515,7 @@ namespace Aaru.DiscImages
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer;
|
return ErrorNumber.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -89,11 +89,15 @@ namespace Aaru.DiscImages
|
|||||||
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
||||||
out List<ulong> unknownLbas)
|
out List<ulong> unknownLbas)
|
||||||
{
|
{
|
||||||
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
|
||||||
int bps = (int)(buffer.Length / length);
|
|
||||||
byte[] sector = new byte[bps];
|
|
||||||
failingLbas = new List<ulong>();
|
failingLbas = new List<ulong>();
|
||||||
unknownLbas = new List<ulong>();
|
unknownLbas = new List<ulong>();
|
||||||
|
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, track, 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++)
|
for(int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2042,7 +2042,8 @@ namespace Aaru.DiscImages
|
|||||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, uint track, out byte[] buffer) =>
|
||||||
|
ReadSectorsLong(sectorAddress, 1, track, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||||
@@ -2053,43 +2054,26 @@ namespace Aaru.DiscImages
|
|||||||
from cdrwinTrack in _discImage.Tracks
|
from cdrwinTrack in _discImage.Tracks
|
||||||
where cdrwinTrack.Sequence == kvp.Key
|
where cdrwinTrack.Sequence == kvp.Key
|
||||||
where sectorAddress - kvp.Value < cdrwinTrack.Sectors select kvp)
|
where sectorAddress - kvp.Value < cdrwinTrack.Sectors select kvp)
|
||||||
{
|
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key, out buffer);
|
||||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
|
||||||
|
|
||||||
return buffer is null ? ErrorNumber.SectorNotFound : ErrorNumber.NoError;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ErrorNumber.SectorNotFound;
|
return ErrorNumber.SectorNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
|
buffer = null;
|
||||||
|
|
||||||
if(!_isCd)
|
if(!_isCd)
|
||||||
{
|
return ReadSectors(sectorAddress, length, track, out buffer);
|
||||||
ErrorNumber errno = ReadSectors(sectorAddress, length, track, out byte[] nonCdBuffer);
|
|
||||||
|
|
||||||
return errno != ErrorNumber.NoError ? null : nonCdBuffer;
|
CdrWinTrack? aaruTrack = _discImage.Tracks.FirstOrDefault(cdrwinTrack => cdrwinTrack.Sequence == track);
|
||||||
}
|
|
||||||
|
|
||||||
var aaruTrack = new CdrWinTrack
|
if(aaruTrack is null)
|
||||||
{
|
return ErrorNumber.SectorNotFound;
|
||||||
Sequence = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach(CdrWinTrack cdrwinTrack in _discImage.Tracks.Where(cdrwinTrack => cdrwinTrack.Sequence == track))
|
|
||||||
{
|
|
||||||
aaruTrack = cdrwinTrack;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(aaruTrack.Sequence == 0)
|
|
||||||
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
|
||||||
|
|
||||||
if(length > aaruTrack.Sectors)
|
if(length > aaruTrack.Sectors)
|
||||||
throw new ArgumentOutOfRangeException(nameof(length),
|
return ErrorNumber.OutOfRange;
|
||||||
"Requested more sectors than present in track, won't cross tracks");
|
|
||||||
|
|
||||||
uint sectorOffset;
|
uint sectorOffset;
|
||||||
uint sectorSize;
|
uint sectorSize;
|
||||||
@@ -2142,10 +2126,10 @@ namespace Aaru.DiscImages
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
default: return ErrorNumber.NotSupported;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] buffer = new byte[sectorSize * length];
|
buffer = new byte[sectorSize * length];
|
||||||
|
|
||||||
// If it's the lost pregap
|
// If it's the lost pregap
|
||||||
if(track == 1 &&
|
if(track == 1 &&
|
||||||
@@ -2155,7 +2139,7 @@ namespace Aaru.DiscImages
|
|||||||
{
|
{
|
||||||
// If we need to mix lost with present data
|
// If we need to mix lost with present data
|
||||||
if(sectorAddress + length <= _lostPregap)
|
if(sectorAddress + length <= _lostPregap)
|
||||||
return buffer;
|
return ErrorNumber.NoError;
|
||||||
|
|
||||||
ulong pregapPos = _lostPregap - sectorAddress;
|
ulong pregapPos = _lostPregap - sectorAddress;
|
||||||
|
|
||||||
@@ -2163,11 +2147,11 @@ namespace Aaru.DiscImages
|
|||||||
ReadSectors(_lostPregap, (uint)(length - pregapPos), track, out byte[] presentData);
|
ReadSectors(_lostPregap, (uint)(length - pregapPos), track, out byte[] presentData);
|
||||||
|
|
||||||
if(errno != ErrorNumber.NoError)
|
if(errno != ErrorNumber.NoError)
|
||||||
return null;
|
return errno;
|
||||||
|
|
||||||
Array.Copy(presentData, 0, buffer, (long)(pregapPos * sectorSize), presentData.Length);
|
Array.Copy(presentData, 0, buffer, (long)(pregapPos * sectorSize), presentData.Length);
|
||||||
|
|
||||||
return buffer;
|
return ErrorNumber.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
sectorAddress -= _lostPregap;
|
sectorAddress -= _lostPregap;
|
||||||
@@ -2273,7 +2257,7 @@ namespace Aaru.DiscImages
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer;
|
return ErrorNumber.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -197,11 +197,14 @@ namespace Aaru.DiscImages
|
|||||||
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
||||||
out List<ulong> unknownLbas)
|
out List<ulong> unknownLbas)
|
||||||
{
|
{
|
||||||
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
|
||||||
int bps = (int)(buffer.Length / length);
|
|
||||||
byte[] sector = new byte[bps];
|
|
||||||
failingLbas = new List<ulong>();
|
failingLbas = new List<ulong>();
|
||||||
unknownLbas = new List<ulong>();
|
unknownLbas = new List<ulong>();
|
||||||
|
var errno = ReadSectorsLong(sectorAddress, length, track, 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++)
|
for(int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1978,23 +1978,21 @@ namespace Aaru.DiscImages
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track)
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
if(_isHdd)
|
buffer = null;
|
||||||
throw new FeaturedNotSupportedByDiscImageException("Cannot access optical tracks on a hard disk image");
|
|
||||||
|
|
||||||
ErrorNumber errno = ReadSectorLong(GetAbsoluteSector(sectorAddress, track), out byte[] buffer);
|
return _isHdd ? ErrorNumber.NotSupported
|
||||||
|
: ReadSectorLong(GetAbsoluteSector(sectorAddress, track), out buffer);
|
||||||
return errno == ErrorNumber.NoError ? buffer : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
if(_isHdd)
|
buffer = null;
|
||||||
throw new FeaturedNotSupportedByDiscImageException("Cannot access optical tracks on a hard disk image");
|
|
||||||
|
|
||||||
return ReadSectorLong(GetAbsoluteSector(sectorAddress, track), length);
|
return _isHdd ? ErrorNumber.NotSupported
|
||||||
|
: ReadSectorLong(GetAbsoluteSector(sectorAddress, track), length, out buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,11 @@ namespace Aaru.DiscImages
|
|||||||
if(_isHdd)
|
if(_isHdd)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, track, out byte[] buffer);
|
||||||
|
|
||||||
|
if(errno != ErrorNumber.NoError)
|
||||||
|
return null;
|
||||||
|
|
||||||
int bps = (int)(buffer.Length / length);
|
int bps = (int)(buffer.Length / length);
|
||||||
byte[] sector = new byte[bps];
|
byte[] sector = new byte[bps];
|
||||||
|
|
||||||
|
|||||||
@@ -1347,7 +1347,8 @@ namespace Aaru.DiscImages
|
|||||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, uint track, out byte[] buffer) =>
|
||||||
|
ReadSectorsLong(sectorAddress, 1, track, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||||
@@ -1358,43 +1359,29 @@ namespace Aaru.DiscImages
|
|||||||
from track in Tracks where track.Sequence == kvp.Key
|
from track in Tracks where track.Sequence == kvp.Key
|
||||||
where sectorAddress - kvp.Value <
|
where sectorAddress - kvp.Value <
|
||||||
track.EndSector - track.StartSector + 1 select kvp)
|
track.EndSector - track.StartSector + 1 select kvp)
|
||||||
{
|
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key, out buffer);
|
||||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
|
||||||
|
|
||||||
return buffer is null ? ErrorNumber.NoData : ErrorNumber.NoError;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ErrorNumber.SectorNotFound;
|
return ErrorNumber.SectorNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
var aaruTrack = new Track
|
buffer = null;
|
||||||
{
|
Track? aaruTrack = Tracks.FirstOrDefault(linqTrack => linqTrack.Sequence == track);
|
||||||
Sequence = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach(Track linqTrack in Tracks.Where(linqTrack => linqTrack.Sequence == track))
|
|
||||||
{
|
|
||||||
aaruTrack = linqTrack;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(aaruTrack is null)
|
if(aaruTrack is null)
|
||||||
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
return ErrorNumber.SectorNotFound;
|
||||||
|
|
||||||
if(length + sectorAddress - 1 > aaruTrack.EndSector)
|
if(length + sectorAddress - 1 > aaruTrack.EndSector)
|
||||||
throw new ArgumentOutOfRangeException(nameof(length),
|
return ErrorNumber.OutOfMemory;
|
||||||
$"Requested more sectors ({length + sectorAddress}) than present in track ({aaruTrack.EndSector}), won't cross tracks");
|
|
||||||
|
|
||||||
byte[] buffer = new byte[2352 * length];
|
buffer = new byte[2352 * length];
|
||||||
|
|
||||||
_dataStream.Seek((long)(aaruTrack.FileOffset + (sectorAddress * 2352)), SeekOrigin.Begin);
|
_dataStream.Seek((long)(aaruTrack.FileOffset + (sectorAddress * 2352)), SeekOrigin.Begin);
|
||||||
_dataStream.Read(buffer, 0, buffer.Length);
|
_dataStream.Read(buffer, 0, buffer.Length);
|
||||||
|
|
||||||
return buffer;
|
return ErrorNumber.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -89,11 +89,15 @@ namespace Aaru.DiscImages
|
|||||||
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
||||||
out List<ulong> unknownLbas)
|
out List<ulong> unknownLbas)
|
||||||
{
|
{
|
||||||
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
|
||||||
int bps = (int)(buffer.Length / length);
|
|
||||||
byte[] sector = new byte[bps];
|
|
||||||
failingLbas = new List<ulong>();
|
failingLbas = new List<ulong>();
|
||||||
unknownLbas = new List<ulong>();
|
unknownLbas = new List<ulong>();
|
||||||
|
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, track, 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++)
|
for(int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1237,7 +1237,8 @@ namespace Aaru.DiscImages
|
|||||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, uint track, out byte[] buffer) =>
|
||||||
|
ReadSectorsLong(sectorAddress, 1, track, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||||
@@ -1248,43 +1249,26 @@ namespace Aaru.DiscImages
|
|||||||
from track in Tracks where track.Sequence == kvp.Key
|
from track in Tracks where track.Sequence == kvp.Key
|
||||||
where sectorAddress - kvp.Value <
|
where sectorAddress - kvp.Value <
|
||||||
track.EndSector - track.StartSector + 1 select kvp)
|
track.EndSector - track.StartSector + 1 select kvp)
|
||||||
{
|
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key, out buffer);
|
||||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
|
||||||
|
|
||||||
return buffer is null ? ErrorNumber.NoData : ErrorNumber.NoError;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ErrorNumber.SectorNotFound;
|
return ErrorNumber.SectorNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
|
buffer = null;
|
||||||
|
|
||||||
if(!_isCd)
|
if(!_isCd)
|
||||||
{
|
return ReadSectors(sectorAddress, length, track, out buffer);
|
||||||
ErrorNumber errno = ReadSectors(sectorAddress, length, track, out byte[] nonCdBuffer);
|
|
||||||
|
|
||||||
return errno == ErrorNumber.NoError ? nonCdBuffer : null;
|
Track? aaruTrack = Tracks.FirstOrDefault(linqTrack => linqTrack.Sequence == track);
|
||||||
}
|
|
||||||
|
|
||||||
var aaruTrack = new Track
|
|
||||||
{
|
|
||||||
Sequence = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach(Track linqTrack in Tracks.Where(linqTrack => linqTrack.Sequence == track))
|
|
||||||
{
|
|
||||||
aaruTrack = linqTrack;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(aaruTrack is null)
|
if(aaruTrack is null)
|
||||||
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
return ErrorNumber.SectorNotFound;
|
||||||
|
|
||||||
if(length + sectorAddress > aaruTrack.EndSector - aaruTrack.StartSector + 1)
|
if(length + sectorAddress > aaruTrack.EndSector - aaruTrack.StartSector + 1)
|
||||||
throw new ArgumentOutOfRangeException(nameof(length),
|
return ErrorNumber.OutOfRange;
|
||||||
$"Requested more sectors ({length + sectorAddress}) than present in track ({aaruTrack.EndSector - aaruTrack.StartSector + 1}), won't cross tracks");
|
|
||||||
|
|
||||||
uint sectorSize = (uint)aaruTrack.RawBytesPerSector;
|
uint sectorSize = (uint)aaruTrack.RawBytesPerSector;
|
||||||
uint sectorSkip = 0;
|
uint sectorSkip = 0;
|
||||||
@@ -1303,10 +1287,10 @@ namespace Aaru.DiscImages
|
|||||||
sectorSkip += 96;
|
sectorSkip += 96;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported subchannel type");
|
default: return ErrorNumber.NotSupported;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] buffer = new byte[sectorSize * length];
|
buffer = new byte[sectorSize * length];
|
||||||
|
|
||||||
_imageStream.Seek((long)(aaruTrack.FileOffset + (sectorAddress * (sectorSize + sectorSkip))),
|
_imageStream.Seek((long)(aaruTrack.FileOffset + (sectorAddress * (sectorSize + sectorSkip))),
|
||||||
SeekOrigin.Begin);
|
SeekOrigin.Begin);
|
||||||
@@ -1361,7 +1345,7 @@ namespace Aaru.DiscImages
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer;
|
return ErrorNumber.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -89,11 +89,15 @@ namespace Aaru.DiscImages
|
|||||||
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
||||||
out List<ulong> unknownLbas)
|
out List<ulong> unknownLbas)
|
||||||
{
|
{
|
||||||
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
|
||||||
int bps = (int)(buffer.Length / length);
|
|
||||||
byte[] sector = new byte[bps];
|
|
||||||
failingLbas = new List<ulong>();
|
failingLbas = new List<ulong>();
|
||||||
unknownLbas = new List<ulong>();
|
unknownLbas = new List<ulong>();
|
||||||
|
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, track, 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++)
|
for(int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -697,7 +697,7 @@ namespace Aaru.DiscImages
|
|||||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, uint track, out byte[] buffer) => ReadSectorsLong(sectorAddress, 1, track, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||||
@@ -708,25 +708,23 @@ namespace Aaru.DiscImages
|
|||||||
from gdiTrack in _discImage.Tracks
|
from gdiTrack in _discImage.Tracks
|
||||||
where gdiTrack.Sequence == kvp.Key
|
where gdiTrack.Sequence == kvp.Key
|
||||||
where sectorAddress - kvp.Value < gdiTrack.Sectors select kvp)
|
where sectorAddress - kvp.Value < gdiTrack.Sectors select kvp)
|
||||||
{
|
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key, out buffer);
|
||||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
|
||||||
|
|
||||||
return buffer is null ? ErrorNumber.SectorNotFound : ErrorNumber.NoError;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ErrorNumber.SectorNotFound;
|
return ErrorNumber.SectorNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
|
buffer = null;
|
||||||
if(track == 0)
|
if(track == 0)
|
||||||
{
|
{
|
||||||
if(sectorAddress + length > _densitySeparationSectors)
|
if(sectorAddress + length > _densitySeparationSectors)
|
||||||
throw new ArgumentOutOfRangeException(nameof(length),
|
return ErrorNumber.OutOfRange;
|
||||||
"Requested more sectors than present in track, won't cross tracks");
|
|
||||||
|
|
||||||
return new byte[length * 2352];
|
buffer= new byte[length * 2352];
|
||||||
|
|
||||||
|
return ErrorNumber.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
var aaruTrack = new GdiTrack
|
var aaruTrack = new GdiTrack
|
||||||
@@ -742,11 +740,10 @@ namespace Aaru.DiscImages
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(aaruTrack.Sequence == 0)
|
if(aaruTrack.Sequence == 0)
|
||||||
throw new ArgumentOutOfRangeException(nameof(track), "Track does not exist in disc image");
|
return ErrorNumber.SectorNotFound;
|
||||||
|
|
||||||
if(sectorAddress + length > aaruTrack.Sectors)
|
if(sectorAddress + length > aaruTrack.Sectors)
|
||||||
throw new ArgumentOutOfRangeException(nameof(length),
|
return ErrorNumber.OutOfRange;
|
||||||
"Requested more sectors than present in track, won't cross tracks");
|
|
||||||
|
|
||||||
uint sectorOffset;
|
uint sectorOffset;
|
||||||
uint sectorSize;
|
uint sectorSize;
|
||||||
@@ -779,10 +776,10 @@ namespace Aaru.DiscImages
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
default: return ErrorNumber.NotSupported;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] buffer = new byte[sectorSize * length];
|
buffer = new byte[sectorSize * length];
|
||||||
|
|
||||||
ulong remainingSectors = length;
|
ulong remainingSectors = length;
|
||||||
|
|
||||||
@@ -795,7 +792,7 @@ namespace Aaru.DiscImages
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(remainingSectors == 0)
|
if(remainingSectors == 0)
|
||||||
return buffer;
|
return ErrorNumber.NoError;
|
||||||
|
|
||||||
_imageStream = aaruTrack.TrackFilter.GetDataForkStream();
|
_imageStream = aaruTrack.TrackFilter.GetDataForkStream();
|
||||||
var br = new BinaryReader(_imageStream);
|
var br = new BinaryReader(_imageStream);
|
||||||
@@ -811,9 +808,7 @@ namespace Aaru.DiscImages
|
|||||||
if(sectorOffset == 0 &&
|
if(sectorOffset == 0 &&
|
||||||
sectorSkip == 0 &&
|
sectorSkip == 0 &&
|
||||||
remainingSectors == length)
|
remainingSectors == length)
|
||||||
{
|
|
||||||
buffer = br.ReadBytes((int)(sectorSize * remainingSectors));
|
buffer = br.ReadBytes((int)(sectorSize * remainingSectors));
|
||||||
}
|
|
||||||
else if(sectorOffset == 0 &&
|
else if(sectorOffset == 0 &&
|
||||||
sectorSkip == 0)
|
sectorSkip == 0)
|
||||||
{
|
{
|
||||||
@@ -855,7 +850,7 @@ namespace Aaru.DiscImages
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer;
|
return ErrorNumber.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -89,11 +89,15 @@ namespace Aaru.DiscImages
|
|||||||
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
||||||
out List<ulong> unknownLbas)
|
out List<ulong> unknownLbas)
|
||||||
{
|
{
|
||||||
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
|
||||||
int bps = (int)(buffer.Length / length);
|
|
||||||
byte[] sector = new byte[bps];
|
|
||||||
failingLbas = new List<ulong>();
|
failingLbas = new List<ulong>();
|
||||||
unknownLbas = new List<ulong>();
|
unknownLbas = new List<ulong>();
|
||||||
|
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, track, 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++)
|
for(int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2091,7 +2091,8 @@ namespace Aaru.DiscImages
|
|||||||
ReadSectorsLong(sectorAddress, 1, out buffer);
|
ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, uint track, out byte[] buffer) =>
|
||||||
|
ReadSectorsLong(sectorAddress, 1, track, out buffer);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
|
||||||
@@ -2102,31 +2103,24 @@ namespace Aaru.DiscImages
|
|||||||
from track in Tracks where track.Sequence == kvp.Key
|
from track in Tracks where track.Sequence == kvp.Key
|
||||||
where sectorAddress - kvp.Value <=
|
where sectorAddress - kvp.Value <=
|
||||||
track.EndSector - track.StartSector select kvp)
|
track.EndSector - track.StartSector select kvp)
|
||||||
{
|
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key, out buffer);
|
||||||
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
|
|
||||||
|
|
||||||
return buffer is null ? ErrorNumber.NoData : ErrorNumber.NoError;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ErrorNumber.SectorNotFound;
|
return ErrorNumber.SectorNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
if(!_isCd)
|
buffer = null;
|
||||||
{
|
|
||||||
ErrorNumber errno = ReadSectors(sectorAddress, length, track, out byte[] nonCdBuffer);
|
|
||||||
|
|
||||||
return errno == ErrorNumber.NoError ? nonCdBuffer : null;
|
if(!_isCd)
|
||||||
}
|
return ReadSectors(sectorAddress, length, track, out buffer);
|
||||||
|
|
||||||
if(!_neroTracks.TryGetValue(track, out NeroTrack aaruTrack))
|
if(!_neroTracks.TryGetValue(track, out NeroTrack aaruTrack))
|
||||||
throw new ArgumentOutOfRangeException(nameof(track), "Track not found");
|
return ErrorNumber.SectorNotFound;
|
||||||
|
|
||||||
if(length > aaruTrack.Sectors)
|
if(length > aaruTrack.Sectors)
|
||||||
throw new ArgumentOutOfRangeException(nameof(length),
|
return ErrorNumber.OutOfRange;
|
||||||
$"Requested more sectors ({length}) than present in track ({aaruTrack.Sectors}), won't cross tracks");
|
|
||||||
|
|
||||||
uint sectorOffset;
|
uint sectorOffset;
|
||||||
uint sectorSize;
|
uint sectorSize;
|
||||||
@@ -2176,10 +2170,10 @@ namespace Aaru.DiscImages
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type");
|
default: return ErrorNumber.NotSupported;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] buffer = new byte[sectorSize * length];
|
buffer = new byte[sectorSize * length];
|
||||||
|
|
||||||
_imageStream = _neroFilter.GetDataForkStream();
|
_imageStream = _neroFilter.GetDataForkStream();
|
||||||
var br = new BinaryReader(_imageStream);
|
var br = new BinaryReader(_imageStream);
|
||||||
@@ -2260,7 +2254,7 @@ namespace Aaru.DiscImages
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer;
|
return ErrorNumber.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -89,11 +89,15 @@ namespace Aaru.DiscImages
|
|||||||
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
||||||
out List<ulong> unknownLbas)
|
out List<ulong> unknownLbas)
|
||||||
{
|
{
|
||||||
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
|
||||||
int bps = (int)(buffer.Length / length);
|
|
||||||
byte[] sector = new byte[bps];
|
|
||||||
failingLbas = new List<ulong>();
|
failingLbas = new List<ulong>();
|
||||||
unknownLbas = new List<ulong>();
|
unknownLbas = new List<ulong>();
|
||||||
|
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, track, 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++)
|
for(int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1366,31 +1366,25 @@ namespace Aaru.DiscImages
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorLong(ulong sectorAddress, uint track)
|
public ErrorNumber ReadSectorLong(ulong sectorAddress, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
|
buffer = null;
|
||||||
|
|
||||||
if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc)
|
if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc)
|
||||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
return ErrorNumber.NotSupported;
|
||||||
|
|
||||||
if(track != 1)
|
return track != 1 ? ErrorNumber.OutOfRange : ReadSectorsLong(sectorAddress, 1, out buffer);
|
||||||
throw new ArgumentOutOfRangeException(nameof(track), "Only a single track is supported");
|
|
||||||
|
|
||||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, 1, out byte[] buffer);
|
|
||||||
|
|
||||||
return errno != ErrorNumber.NoError ? null : buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, uint track, out byte[] buffer)
|
||||||
{
|
{
|
||||||
|
buffer = null;
|
||||||
|
|
||||||
if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc)
|
if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc)
|
||||||
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
return ErrorNumber.NotSupported;
|
||||||
|
|
||||||
if(track != 1)
|
return track != 1 ? ErrorNumber.OutOfRange : ReadSectorsLong(sectorAddress, length, out buffer);
|
||||||
throw new ArgumentOutOfRangeException(nameof(track), "Only a single track is supported");
|
|
||||||
|
|
||||||
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
|
|
||||||
|
|
||||||
return errno != ErrorNumber.NoError ? null : buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -114,11 +114,15 @@ namespace Aaru.DiscImages
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] buffer = ReadSectorsLong(sectorAddress, length, track);
|
|
||||||
int bps = (int)(buffer.Length / length);
|
|
||||||
byte[] sector = new byte[bps];
|
|
||||||
failingLbas = new List<ulong>();
|
failingLbas = new List<ulong>();
|
||||||
unknownLbas = new List<ulong>();
|
unknownLbas = new List<ulong>();
|
||||||
|
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, track, 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++)
|
for(int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -344,30 +344,20 @@ namespace Aaru.Tests.Images
|
|||||||
|
|
||||||
if(sectors - doneSectors >= SECTORS_TO_READ)
|
if(sectors - doneSectors >= SECTORS_TO_READ)
|
||||||
{
|
{
|
||||||
if(@long)
|
errno = @long ? image.ReadSectorsLong(doneSectors, SECTORS_TO_READ,
|
||||||
{
|
currentTrack.Sequence, out sector)
|
||||||
errno = ErrorNumber.NoError;
|
: image.ReadSectors(doneSectors, SECTORS_TO_READ,
|
||||||
|
currentTrack.Sequence,
|
||||||
sector = image.ReadSectorsLong(doneSectors, SECTORS_TO_READ,
|
out sector);
|
||||||
currentTrack.Sequence);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
errno = image.ReadSectors(doneSectors, SECTORS_TO_READ,
|
|
||||||
currentTrack.Sequence, out sector);
|
|
||||||
|
|
||||||
doneSectors += SECTORS_TO_READ;
|
doneSectors += SECTORS_TO_READ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(@long)
|
errno = @long ? image.ReadSectorsLong(doneSectors,
|
||||||
{
|
(uint)(sectors - doneSectors),
|
||||||
errno = ErrorNumber.NoError;
|
currentTrack.Sequence, out sector)
|
||||||
|
: image.ReadSectors(doneSectors, (uint)(sectors - doneSectors),
|
||||||
sector = image.ReadSectorsLong(doneSectors, (uint)(sectors - doneSectors),
|
|
||||||
currentTrack.Sequence);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
errno = image.ReadSectors(doneSectors, (uint)(sectors - doneSectors),
|
|
||||||
currentTrack.Sequence, out sector);
|
currentTrack.Sequence, out sector);
|
||||||
|
|
||||||
doneSectors += sectors - doneSectors;
|
doneSectors += sectors - doneSectors;
|
||||||
|
|||||||
@@ -575,30 +575,18 @@ namespace Aaru.Tests.WritableImages
|
|||||||
|
|
||||||
if(sectors - doneSectors >= SECTORS_TO_READ)
|
if(sectors - doneSectors >= SECTORS_TO_READ)
|
||||||
{
|
{
|
||||||
if(@long)
|
errno = @long ? image.ReadSectorsLong(doneSectors, SECTORS_TO_READ,
|
||||||
{
|
currentTrack.Sequence, out sector)
|
||||||
sector = image.ReadSectorsLong(doneSectors, SECTORS_TO_READ,
|
: image.ReadSectors(doneSectors, SECTORS_TO_READ, currentTrack.Sequence,
|
||||||
currentTrack.Sequence);
|
|
||||||
|
|
||||||
errno = ErrorNumber.NoError;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
errno = image.ReadSectors(doneSectors, SECTORS_TO_READ, currentTrack.Sequence,
|
|
||||||
out sector);
|
out sector);
|
||||||
|
|
||||||
doneSectors += SECTORS_TO_READ;
|
doneSectors += SECTORS_TO_READ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(@long)
|
errno = @long ? image.ReadSectorsLong(doneSectors, (uint)(sectors - doneSectors),
|
||||||
{
|
currentTrack.Sequence, out sector)
|
||||||
sector = image.ReadSectorsLong(doneSectors, (uint)(sectors - doneSectors),
|
: image.ReadSectors(doneSectors, (uint)(sectors - doneSectors),
|
||||||
currentTrack.Sequence);
|
|
||||||
|
|
||||||
errno = ErrorNumber.NoError;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
errno = image.ReadSectors(doneSectors, (uint)(sectors - doneSectors),
|
|
||||||
currentTrack.Sequence, out sector);
|
currentTrack.Sequence, out sector);
|
||||||
|
|
||||||
doneSectors += sectors - doneSectors;
|
doneSectors += sectors - doneSectors;
|
||||||
|
|||||||
Reference in New Issue
Block a user