mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Refactor sector writing methods to include SectorStatus parameter and update related logic
This commit is contained in:
@@ -241,16 +241,20 @@ public sealed partial class A2R
|
||||
public bool WriteMediaTag(byte[] data, MediaTagType tag) => false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress) => throw new NotImplementedException();
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress) => throw new NotImplementedException();
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length) => throw new NotImplementedException();
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length) => throw new NotImplementedException();
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -66,9 +66,9 @@ public sealed partial class AaruFormat
|
||||
#region IWritableOpticalImage Members
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
Status res = aaruf_write_sector(_context, sectorAddress, false, data, SectorStatus.Dumped, (uint)data.Length);
|
||||
Status res = aaruf_write_sector(_context, sectorAddress, false, data, sectorStatus, (uint)data.Length);
|
||||
|
||||
if(res == Status.Ok) return true;
|
||||
|
||||
@@ -78,10 +78,9 @@ public sealed partial class AaruFormat
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
Status res =
|
||||
aaruf_write_sector_long(_context, sectorAddress, false, data, SectorStatus.Dumped, (uint)data.Length);
|
||||
Status res = aaruf_write_sector_long(_context, sectorAddress, false, data, sectorStatus, (uint)data.Length);
|
||||
|
||||
if(res == Status.Ok) return true;
|
||||
|
||||
@@ -137,7 +136,7 @@ public sealed partial class AaruFormat
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
var sectorSize = (uint)(data.Length / length);
|
||||
|
||||
@@ -146,14 +145,14 @@ public sealed partial class AaruFormat
|
||||
var sectorData = new byte[sectorSize];
|
||||
Array.Copy(data, i * sectorSize, sectorData, 0, sectorSize);
|
||||
|
||||
if(!WriteSector(sectorData, sectorAddress + i)) return false;
|
||||
if(!WriteSector(sectorData, sectorAddress + i, sectorStatus[i])) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
var sectorSize = (uint)(data.Length / length);
|
||||
|
||||
@@ -162,7 +161,7 @@ public sealed partial class AaruFormat
|
||||
var sectorData = new byte[sectorSize];
|
||||
Array.Copy(data, i * sectorSize, sectorData, 0, sectorSize);
|
||||
|
||||
if(!WriteSectorLong(sectorData, sectorAddress + i)) return false;
|
||||
if(!WriteSectorLong(sectorData, sectorAddress + i, sectorStatus[i])) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -288,9 +287,8 @@ public sealed partial class AaruFormat
|
||||
|
||||
// Convert array of booleans to List of enums
|
||||
for(nuint i = 0; i < sizet_length; i++)
|
||||
{
|
||||
if(sectorTagsBuffer[i] != 0) _imageInfo.ReadableSectorTags.Add((SectorTagType)i);
|
||||
}
|
||||
if(sectorTagsBuffer[i] != 0)
|
||||
_imageInfo.ReadableSectorTags.Add((SectorTagType)i);
|
||||
|
||||
sizet_length = 0;
|
||||
ret = aaruf_get_readable_media_tags(_context, null, ref sizet_length);
|
||||
@@ -314,9 +312,8 @@ public sealed partial class AaruFormat
|
||||
|
||||
// Convert array of booleans to List of enums
|
||||
for(nuint i = 0; i < sizet_length; i++)
|
||||
{
|
||||
if(mediaTagsBuffer[i] != 0) _imageInfo.ReadableMediaTags.Add((MediaTagType)i);
|
||||
}
|
||||
if(mediaTagsBuffer[i] != 0)
|
||||
_imageInfo.ReadableMediaTags.Add((MediaTagType)i);
|
||||
|
||||
ret = aaruf_get_media_sequence(_context, out int sequence, out int lastSequence);
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ public sealed partial class Alcohol120
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -261,7 +261,7 @@ public sealed partial class Alcohol120
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -343,7 +343,7 @@ public sealed partial class Alcohol120
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -369,7 +369,7 @@ public sealed partial class Alcohol120
|
||||
return false;
|
||||
}
|
||||
|
||||
uint subchannelSize = (uint)(track.SubchannelType != TrackSubchannelType.None ? 96 : 0);
|
||||
var subchannelSize = (uint)(track.SubchannelType != TrackSubchannelType.None ? 96 : 0);
|
||||
|
||||
_imageStream.Seek((long)(track.FileOffset +
|
||||
(sectorAddress - track.StartSector) *
|
||||
@@ -382,7 +382,7 @@ public sealed partial class Alcohol120
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -415,7 +415,7 @@ public sealed partial class Alcohol120
|
||||
return false;
|
||||
}
|
||||
|
||||
uint subchannelSize = (uint)(track.SubchannelType != TrackSubchannelType.None ? 96 : 0);
|
||||
var subchannelSize = (uint)(track.SubchannelType != TrackSubchannelType.None ? 96 : 0);
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
@@ -441,7 +441,7 @@ public sealed partial class Alcohol120
|
||||
{
|
||||
CommonTypes.Structs.Track[] tmpTracks = tracks.OrderBy(t => t.Sequence).ToArray();
|
||||
|
||||
for(int i = 1; i < tmpTracks.Length; i++)
|
||||
for(var i = 1; i < tmpTracks.Length; i++)
|
||||
{
|
||||
CommonTypes.Structs.Track firstTrackInSession =
|
||||
tracks.FirstOrDefault(t => t.Session == tmpTracks[i].Session);
|
||||
@@ -548,9 +548,9 @@ public sealed partial class Alcohol120
|
||||
FullTOC.CDFullTOC? decodedToc = FullTOC.Decode(tmpToc);
|
||||
|
||||
long currentExtraOffset = currentTrackOffset;
|
||||
int extraCount = 0;
|
||||
var extraCount = 0;
|
||||
|
||||
for(int i = 1; i <= sessions; i++)
|
||||
for(var i = 1; i <= sessions; i++)
|
||||
{
|
||||
if(decodedToc.HasValue)
|
||||
{
|
||||
@@ -619,7 +619,7 @@ public sealed partial class Alcohol120
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 1; i <= sessions; i++)
|
||||
for(var i = 1; i <= sessions; i++)
|
||||
{
|
||||
CommonTypes.Structs.Track firstTrack = _writingTracks.First(t => t.Session == i);
|
||||
CommonTypes.Structs.Track lastTrack = _writingTracks.Last(t => t.Session == i);
|
||||
@@ -915,8 +915,8 @@ public sealed partial class Alcohol120
|
||||
|
||||
// Write header
|
||||
_descriptorStream.Seek(0, SeekOrigin.Begin);
|
||||
byte[] block = new byte[Marshal.SizeOf<Header>()];
|
||||
nint blockPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
var block = new byte[Marshal.SizeOf<Header>()];
|
||||
nint blockPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
System.Runtime.InteropServices.Marshal.StructureToPtr(header, blockPtr, true);
|
||||
System.Runtime.InteropServices.Marshal.Copy(blockPtr, block, 0, block.Length);
|
||||
System.Runtime.InteropServices.Marshal.FreeHGlobal(blockPtr);
|
||||
|
||||
@@ -113,7 +113,7 @@ public sealed partial class Anex86
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -145,7 +145,7 @@ public sealed partial class Anex86
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -177,7 +177,7 @@ public sealed partial class Anex86
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -185,7 +185,7 @@ public sealed partial class Anex86
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -233,7 +233,7 @@ public sealed partial class Anex86
|
||||
}
|
||||
}
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
var hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
MemoryMarshal.Write(hdr, in _header);
|
||||
|
||||
_writingStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
@@ -109,7 +109,7 @@ public sealed partial class Apple2Mg
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -141,7 +141,7 @@ public sealed partial class Apple2Mg
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -173,7 +173,7 @@ public sealed partial class Apple2Mg
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -181,7 +181,7 @@ public sealed partial class Apple2Mg
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -199,7 +199,7 @@ public sealed partial class Apple2Mg
|
||||
}
|
||||
|
||||
_writingStream.Seek(0x40 + 17 * 16 * 256, SeekOrigin.Begin);
|
||||
byte[] tmp = new byte[256];
|
||||
var tmp = new byte[256];
|
||||
_writingStream.EnsureRead(tmp, 0, tmp.Length);
|
||||
|
||||
bool isDos = tmp[0x01] == 17 &&
|
||||
@@ -235,8 +235,8 @@ public sealed partial class Apple2Mg
|
||||
_writingStream.WriteByte(0);
|
||||
}
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
var hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
System.Runtime.InteropServices.Marshal.StructureToPtr(_imageHeader, hdrPtr, true);
|
||||
System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
|
||||
System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr);
|
||||
|
||||
@@ -114,10 +114,11 @@ public sealed partial class AppleDos
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress) => WriteSectors(data, sectorAddress, 1);
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus) =>
|
||||
WriteSectors(data, sectorAddress, 1, [SectorStatus.Dumped]);
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -148,7 +149,7 @@ public sealed partial class AppleDos
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -156,7 +157,7 @@ public sealed partial class AppleDos
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -195,9 +196,9 @@ public sealed partial class AppleDos
|
||||
? _interleave
|
||||
: _deinterleave;
|
||||
|
||||
for(int t = 0; t < 35; t++)
|
||||
for(var t = 0; t < 35; t++)
|
||||
{
|
||||
for(int s = 0; s < 16; s++)
|
||||
for(var s = 0; s < 16; s++)
|
||||
Array.Copy(_deinterleaved, t * 16 * 256 + offsets[s] * 256, tmp, t * 16 * 256 + s * 256, 256);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public sealed partial class Apridisk
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
(ushort cylinder, byte head, byte sector) = LbaToChs(sectorAddress);
|
||||
|
||||
@@ -124,7 +124,7 @@ public sealed partial class Apridisk
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
@@ -158,7 +158,7 @@ public sealed partial class Apridisk
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -166,7 +166,7 @@ public sealed partial class Apridisk
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -180,7 +180,7 @@ public sealed partial class Apridisk
|
||||
_writingStream.Seek(0, SeekOrigin.Begin);
|
||||
_writingStream.Write(_signature, 0, _signature.Length);
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<Record>()];
|
||||
var hdr = new byte[Marshal.SizeOf<Record>()];
|
||||
|
||||
for(ushort c = 0; c < _imageInfo.Cylinders; c++)
|
||||
{
|
||||
|
||||
@@ -111,7 +111,7 @@ public sealed partial class Blu
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
int longSectorSize = _imageInfo.MediaType == MediaType.PriamDataTower ? 536 : 532;
|
||||
|
||||
@@ -145,7 +145,7 @@ public sealed partial class Blu
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
int longSectorSize = _imageInfo.MediaType == MediaType.PriamDataTower ? 536 : 532;
|
||||
|
||||
@@ -179,7 +179,7 @@ public sealed partial class Blu
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -269,7 +269,7 @@ public sealed partial class Blu
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -387,7 +387,7 @@ public sealed partial class Blu
|
||||
|
||||
byte[] markerTag = Encoding.UTF8.GetBytes("Aaru " + Version.GetVersion());
|
||||
byte[] driveName;
|
||||
byte[] driveType = new byte[3];
|
||||
var driveType = new byte[3];
|
||||
byte[] driveBlocks = BigEndianBitConverter.GetBytes((uint)_imageInfo.Sectors);
|
||||
int longSectorSize = _imageInfo.MediaType == MediaType.PriamDataTower ? 536 : 532;
|
||||
byte[] blockSize = BigEndianBitConverter.GetBytes((ushort)longSectorSize);
|
||||
|
||||
@@ -143,7 +143,7 @@ public sealed partial class Cdrdao
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -188,7 +188,7 @@ public sealed partial class Cdrdao
|
||||
// cdrdao audio tracks are endian swapped corresponding to Aaru
|
||||
if(track.Type == TrackType.Audio)
|
||||
{
|
||||
byte[] swapped = new byte[data.Length];
|
||||
var swapped = new byte[data.Length];
|
||||
|
||||
for(long i = 0; i < swapped.Length; i += 2)
|
||||
{
|
||||
@@ -209,7 +209,7 @@ public sealed partial class Cdrdao
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -261,7 +261,7 @@ public sealed partial class Cdrdao
|
||||
// cdrdao audio tracks are endian swapped corresponding to Aaru
|
||||
if(track.Type == TrackType.Audio)
|
||||
{
|
||||
byte[] swapped = new byte[data.Length];
|
||||
var swapped = new byte[data.Length];
|
||||
|
||||
for(long i = 0; i < swapped.Length; i += 2)
|
||||
{
|
||||
@@ -307,7 +307,7 @@ public sealed partial class Cdrdao
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -345,7 +345,7 @@ public sealed partial class Cdrdao
|
||||
// cdrdao audio tracks are endian swapped corresponding to Aaru
|
||||
if(track.Type == TrackType.Audio)
|
||||
{
|
||||
byte[] swapped = new byte[data.Length];
|
||||
var swapped = new byte[data.Length];
|
||||
|
||||
for(long i = 0; i < swapped.Length; i += 2)
|
||||
{
|
||||
@@ -356,7 +356,7 @@ public sealed partial class Cdrdao
|
||||
data = swapped;
|
||||
}
|
||||
|
||||
uint subchannelSize = (uint)(track.SubchannelType != TrackSubchannelType.None ? 96 : 0);
|
||||
var subchannelSize = (uint)(track.SubchannelType != TrackSubchannelType.None ? 96 : 0);
|
||||
|
||||
trackStream.Seek((long)(track.FileOffset +
|
||||
(sectorAddress - track.StartSector) *
|
||||
@@ -369,7 +369,7 @@ public sealed partial class Cdrdao
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -414,7 +414,7 @@ public sealed partial class Cdrdao
|
||||
// cdrdao audio tracks are endian swapped corresponding to Aaru
|
||||
if(track.Type == TrackType.Audio)
|
||||
{
|
||||
byte[] swapped = new byte[data.Length];
|
||||
var swapped = new byte[data.Length];
|
||||
|
||||
for(long i = 0; i < swapped.Length; i += 2)
|
||||
{
|
||||
@@ -425,7 +425,7 @@ public sealed partial class Cdrdao
|
||||
data = swapped;
|
||||
}
|
||||
|
||||
uint subchannelSize = (uint)(track.SubchannelType != TrackSubchannelType.None ? 96 : 0);
|
||||
var subchannelSize = (uint)(track.SubchannelType != TrackSubchannelType.None ? 96 : 0);
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
@@ -458,9 +458,8 @@ public sealed partial class Cdrdao
|
||||
}
|
||||
|
||||
if(_writingTracks != null && _writingStreams != null)
|
||||
{
|
||||
foreach(FileStream oldTrack in _writingStreams.Select(t => t.Value).Distinct()) oldTrack.Close();
|
||||
}
|
||||
foreach(FileStream oldTrack in _writingStreams.Select(t => t.Value).Distinct())
|
||||
oldTrack.Close();
|
||||
|
||||
ulong currentOffset = 0;
|
||||
_writingTracks = [];
|
||||
|
||||
@@ -110,7 +110,7 @@ public sealed partial class CdrWin
|
||||
Tracks = []
|
||||
};
|
||||
|
||||
int mediaTypeAsInt = (int)_discImage.MediaType;
|
||||
var mediaTypeAsInt = (int)_discImage.MediaType;
|
||||
|
||||
_isCd = mediaTypeAsInt is >= 10 and <= 39
|
||||
or 112
|
||||
@@ -168,7 +168,7 @@ public sealed partial class CdrWin
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -220,7 +220,7 @@ public sealed partial class CdrWin
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -279,7 +279,7 @@ public sealed partial class CdrWin
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -324,7 +324,7 @@ public sealed partial class CdrWin
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -393,9 +393,8 @@ public sealed partial class CdrWin
|
||||
}
|
||||
|
||||
if(_writingTracks != null && _writingStreams != null)
|
||||
{
|
||||
foreach(FileStream oldTrack in _writingStreams.Select(t => t.Value).Distinct()) oldTrack.Close();
|
||||
}
|
||||
foreach(FileStream oldTrack in _writingStreams.Select(t => t.Value).Distinct())
|
||||
oldTrack.Close();
|
||||
|
||||
_writingTracks = [];
|
||||
|
||||
@@ -459,7 +458,7 @@ public sealed partial class CdrWin
|
||||
_writingStreams.First().Value.Close();
|
||||
}
|
||||
|
||||
int currentSession = 0;
|
||||
var currentSession = 0;
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(_discImage.Comment))
|
||||
{
|
||||
|
||||
@@ -128,11 +128,11 @@ public sealed partial class CisCopy
|
||||
DiskType.MF2DD or DiskType.MD2HD or DiskType.MF2HD => 160
|
||||
};
|
||||
|
||||
int headStep = 1;
|
||||
var headStep = 1;
|
||||
|
||||
if(diskType is DiskType.MD1DD or DiskType.MD1DD8) headStep = 2;
|
||||
|
||||
for(int i = 0; i < tracks; i += headStep)
|
||||
for(var i = 0; i < tracks; i += headStep)
|
||||
{
|
||||
_writingStream.WriteByte((byte)TrackType.Copied);
|
||||
|
||||
@@ -157,7 +157,7 @@ public sealed partial class CisCopy
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -189,7 +189,7 @@ public sealed partial class CisCopy
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -221,7 +221,7 @@ public sealed partial class CisCopy
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -229,7 +229,7 @@ public sealed partial class CisCopy
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ public sealed partial class CloneCd
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -142,7 +142,7 @@ public sealed partial class CloneCd
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -158,7 +158,7 @@ public sealed partial class CloneCd
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -193,7 +193,7 @@ public sealed partial class CloneCd
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -310,7 +310,7 @@ public sealed partial class CloneCd
|
||||
// Easy, just decode the real toc
|
||||
if(_fullToc != null)
|
||||
{
|
||||
byte[] tmp = new byte[_fullToc.Length + 2];
|
||||
var tmp = new byte[_fullToc.Length + 2];
|
||||
Array.Copy(BigEndianBitConverter.GetBytes((ushort)_fullToc.Length), 0, tmp, 0, 2);
|
||||
Array.Copy(_fullToc, 0, tmp, 2, _fullToc.Length);
|
||||
nullableToc = FullTOC.Decode(tmp);
|
||||
@@ -329,7 +329,7 @@ public sealed partial class CloneCd
|
||||
|
||||
if(!string.IsNullOrEmpty(_catalog)) _descriptorStream.WriteLine("CATALOG={0}", _catalog);
|
||||
|
||||
for(int i = 1; i <= toc.LastCompleteSession; i++)
|
||||
for(var i = 1; i <= toc.LastCompleteSession; i++)
|
||||
{
|
||||
_descriptorStream.WriteLine("[Session {0}]", i);
|
||||
|
||||
@@ -365,7 +365,7 @@ public sealed partial class CloneCd
|
||||
_descriptorStream.WriteLine("PreGapSubC=0");
|
||||
}
|
||||
|
||||
for(int i = 0; i < toc.TrackDescriptors.Length; i++)
|
||||
for(var i = 0; i < toc.TrackDescriptors.Length; i++)
|
||||
{
|
||||
long alba = MsfToLba((toc.TrackDescriptors[i].Min, toc.TrackDescriptors[i].Sec,
|
||||
toc.TrackDescriptors[i].Frame));
|
||||
@@ -484,7 +484,8 @@ public sealed partial class CloneCd
|
||||
ErrorMessage = string.Format(Localization.Could_not_create_subchannel_file_exception_0,
|
||||
ex.Message);
|
||||
|
||||
AaruLogging.Exception(ex,Localization.Could_not_create_subchannel_file_exception_0,
|
||||
AaruLogging.Exception(ex,
|
||||
Localization.Could_not_create_subchannel_file_exception_0,
|
||||
ex.Message);
|
||||
|
||||
return false;
|
||||
@@ -561,7 +562,8 @@ public sealed partial class CloneCd
|
||||
ErrorMessage = string.Format(Localization.Could_not_create_subchannel_file_exception_0,
|
||||
ex.Message);
|
||||
|
||||
AaruLogging.Exception(ex,Localization.Could_not_create_subchannel_file_exception_0,
|
||||
AaruLogging.Exception(ex,
|
||||
Localization.Could_not_create_subchannel_file_exception_0,
|
||||
ex.Message);
|
||||
|
||||
return false;
|
||||
|
||||
@@ -102,7 +102,7 @@ public sealed partial class CopyTape
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!_writtenBlockPositions.TryGetValue(sectorAddress, out ulong position))
|
||||
{
|
||||
@@ -138,11 +138,11 @@ public sealed partial class CopyTape
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
bool ret = WriteSector(data, sectorAddress + i);
|
||||
bool ret = WriteSector(data, sectorAddress + i, sectorStatus[i]);
|
||||
|
||||
if(!ret) return false;
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public sealed partial class CopyTape
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Unsupported_feature;
|
||||
|
||||
@@ -159,7 +159,7 @@ public sealed partial class CopyTape
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Unsupported_feature;
|
||||
|
||||
|
||||
@@ -51,8 +51,8 @@ public sealed partial class DiskCopy42
|
||||
uint sectorSize)
|
||||
{
|
||||
header = new Header();
|
||||
bool tags = false;
|
||||
bool macosx = false;
|
||||
var tags = false;
|
||||
var macosx = false;
|
||||
|
||||
if(options != null && options.TryGetValue("macosx", out string tmpOption)) bool.TryParse(tmpOption, out macosx);
|
||||
|
||||
@@ -223,7 +223,7 @@ public sealed partial class DiskCopy42
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -255,7 +255,7 @@ public sealed partial class DiskCopy42
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -287,7 +287,7 @@ public sealed partial class DiskCopy42
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -328,7 +328,7 @@ public sealed partial class DiskCopy42
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -387,7 +387,7 @@ public sealed partial class DiskCopy42
|
||||
if(writingStream.Length == 0x54 + header.DataSize) header.TagSize = 0;
|
||||
|
||||
writingStream.Seek(0x54, SeekOrigin.Begin);
|
||||
byte[] data = new byte[header.DataSize];
|
||||
var data = new byte[header.DataSize];
|
||||
writingStream.EnsureRead(data, 0, (int)header.DataSize);
|
||||
header.DataChecksum = CheckSum(data);
|
||||
writingStream.Seek(0x54 + header.DataSize, SeekOrigin.Begin);
|
||||
|
||||
@@ -131,7 +131,7 @@ public sealed partial class DriDiskCopy
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -163,7 +163,7 @@ public sealed partial class DriDiskCopy
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -195,7 +195,7 @@ public sealed partial class DriDiskCopy
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -203,7 +203,7 @@ public sealed partial class DriDiskCopy
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -220,8 +220,8 @@ public sealed partial class DriDiskCopy
|
||||
return false;
|
||||
}
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<Footer>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Footer>());
|
||||
var hdr = new byte[Marshal.SizeOf<Footer>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Footer>());
|
||||
System.Runtime.InteropServices.Marshal.StructureToPtr(_footer, hdrPtr, true);
|
||||
System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
|
||||
System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr);
|
||||
|
||||
@@ -125,7 +125,7 @@ public sealed partial class MaxiDisk
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -159,7 +159,7 @@ public sealed partial class MaxiDisk
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -193,7 +193,7 @@ public sealed partial class MaxiDisk
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -201,7 +201,7 @@ public sealed partial class MaxiDisk
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -232,8 +232,8 @@ public sealed partial class MaxiDisk
|
||||
i >>= 1;
|
||||
}
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
var hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
System.Runtime.InteropServices.Marshal.StructureToPtr(header, hdrPtr, true);
|
||||
System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
|
||||
System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr);
|
||||
|
||||
@@ -100,7 +100,7 @@ public sealed partial class Nhdr0
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -134,7 +134,7 @@ public sealed partial class Nhdr0
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -168,7 +168,7 @@ public sealed partial class Nhdr0
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -176,7 +176,7 @@ public sealed partial class Nhdr0
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -239,8 +239,8 @@ public sealed partial class Nhdr0
|
||||
commentBytes.Length >= 0x100 ? 0x100 : commentBytes.Length);
|
||||
}
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
var hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
System.Runtime.InteropServices.Marshal.StructureToPtr(header, hdrPtr, true);
|
||||
System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
|
||||
System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr);
|
||||
|
||||
@@ -92,7 +92,7 @@ public sealed partial class Parallels
|
||||
return false;
|
||||
}
|
||||
|
||||
uint batEntries = (uint)(sectors * sectorSize / DEFAULT_CLUSTER_SIZE);
|
||||
var batEntries = (uint)(sectors * sectorSize / DEFAULT_CLUSTER_SIZE);
|
||||
|
||||
if(sectors * sectorSize % DEFAULT_CLUSTER_SIZE > 0) batEntries++;
|
||||
|
||||
@@ -129,7 +129,7 @@ public sealed partial class Parallels
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -180,7 +180,7 @@ public sealed partial class Parallels
|
||||
|
||||
// TODO: This can be optimized
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -208,10 +208,10 @@ public sealed partial class Parallels
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
byte[] tmp = new byte[512];
|
||||
var tmp = new byte[512];
|
||||
Array.Copy(data, i * 512, tmp, 0, 512);
|
||||
|
||||
if(!WriteSector(tmp, sectorAddress + i)) return false;
|
||||
if(!WriteSector(tmp, sectorAddress + i, sectorStatus[i])) return false;
|
||||
}
|
||||
|
||||
ErrorMessage = "";
|
||||
@@ -220,7 +220,7 @@ public sealed partial class Parallels
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -228,7 +228,7 @@ public sealed partial class Parallels
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -267,8 +267,8 @@ public sealed partial class Parallels
|
||||
}
|
||||
}
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
var hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
System.Runtime.InteropServices.Marshal.StructureToPtr(_pHdr, hdrPtr, true);
|
||||
System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
|
||||
System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr);
|
||||
|
||||
@@ -113,10 +113,10 @@ public sealed partial class Qcow
|
||||
_l1Table = new ulong[_l1Size];
|
||||
|
||||
_l1Mask = 0;
|
||||
int c = 0;
|
||||
var c = 0;
|
||||
_l1Shift = _qHdr.l2_bits + _qHdr.cluster_bits;
|
||||
|
||||
for(int i = 0; i < 64; i++)
|
||||
for(var i = 0; i < 64; i++)
|
||||
{
|
||||
_l1Mask <<= 1;
|
||||
|
||||
@@ -128,15 +128,15 @@ public sealed partial class Qcow
|
||||
|
||||
_l2Mask = 0;
|
||||
|
||||
for(int i = 0; i < _qHdr.l2_bits; i++) _l2Mask = (_l2Mask << 1) + 1;
|
||||
for(var i = 0; i < _qHdr.l2_bits; i++) _l2Mask = (_l2Mask << 1) + 1;
|
||||
|
||||
_l2Mask <<= _qHdr.cluster_bits;
|
||||
|
||||
_sectorMask = 0;
|
||||
|
||||
for(int i = 0; i < _qHdr.cluster_bits; i++) _sectorMask = (_sectorMask << 1) + 1;
|
||||
for(var i = 0; i < _qHdr.cluster_bits; i++) _sectorMask = (_sectorMask << 1) + 1;
|
||||
|
||||
byte[] empty = new byte[_qHdr.l1_table_offset + _l1Size * 8];
|
||||
var empty = new byte[_qHdr.l1_table_offset + _l1Size * 8];
|
||||
_writingStream.Write(empty, 0, empty.Length);
|
||||
|
||||
IsWriting = true;
|
||||
@@ -154,7 +154,7 @@ public sealed partial class Qcow
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -197,7 +197,7 @@ public sealed partial class Qcow
|
||||
{
|
||||
_writingStream.Seek(0, SeekOrigin.End);
|
||||
_l1Table[l1Off] = (ulong)((_writingStream.Length + _clusterSize - 1) / _clusterSize * _clusterSize);
|
||||
byte[] l2TableB = new byte[_l2Size * 8];
|
||||
var l2TableB = new byte[_l2Size * 8];
|
||||
_writingStream.Position = (long)_l1Table[l1Off];
|
||||
_writingStream.Write(l2TableB, 0, l2TableB.Length);
|
||||
}
|
||||
@@ -208,14 +208,14 @@ public sealed partial class Qcow
|
||||
|
||||
_writingStream.Seek((long)(_l1Table[l1Off] + l2Off * 8), SeekOrigin.Begin);
|
||||
|
||||
byte[] entry = new byte[8];
|
||||
var entry = new byte[8];
|
||||
_writingStream.EnsureRead(entry, 0, 8);
|
||||
ulong offset = BigEndianBitConverter.ToUInt64(entry, 0);
|
||||
var offset = BigEndianBitConverter.ToUInt64(entry, 0);
|
||||
|
||||
if(offset == 0)
|
||||
{
|
||||
offset = (ulong)_writingStream.Length;
|
||||
byte[] cluster = new byte[_clusterSize];
|
||||
var cluster = new byte[_clusterSize];
|
||||
entry = BigEndianBitConverter.GetBytes(offset);
|
||||
_writingStream.Seek((long)(_l1Table[l1Off] + l2Off * 8), SeekOrigin.Begin);
|
||||
_writingStream.Write(entry, 0, 8);
|
||||
@@ -233,7 +233,7 @@ public sealed partial class Qcow
|
||||
|
||||
// TODO: This can be optimized
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -261,10 +261,10 @@ public sealed partial class Qcow
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
byte[] tmp = new byte[_imageInfo.SectorSize];
|
||||
var tmp = new byte[_imageInfo.SectorSize];
|
||||
Array.Copy(data, i * _imageInfo.SectorSize, tmp, 0, _imageInfo.SectorSize);
|
||||
|
||||
if(!WriteSector(tmp, sectorAddress + i)) return false;
|
||||
if(!WriteSector(tmp, sectorAddress + i, sectorStatus[i])) return false;
|
||||
}
|
||||
|
||||
ErrorMessage = "";
|
||||
@@ -273,7 +273,7 @@ public sealed partial class Qcow
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -281,7 +281,7 @@ public sealed partial class Qcow
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
|
||||
@@ -112,10 +112,10 @@ public sealed partial class Qcow2
|
||||
_l2Size = 1 << _l2Bits;
|
||||
|
||||
_l1Mask = 0;
|
||||
int c = 0;
|
||||
var c = 0;
|
||||
_l1Shift = (int)(_l2Bits + _qHdr.cluster_bits);
|
||||
|
||||
for(int i = 0; i < 64; i++)
|
||||
for(var i = 0; i < 64; i++)
|
||||
{
|
||||
_l1Mask <<= 1;
|
||||
|
||||
@@ -127,13 +127,13 @@ public sealed partial class Qcow2
|
||||
|
||||
_l2Mask = 0;
|
||||
|
||||
for(int i = 0; i < _l2Bits; i++) _l2Mask = (_l2Mask << 1) + 1;
|
||||
for(var i = 0; i < _l2Bits; i++) _l2Mask = (_l2Mask << 1) + 1;
|
||||
|
||||
_l2Mask <<= (int)_qHdr.cluster_bits;
|
||||
|
||||
_sectorMask = 0;
|
||||
|
||||
for(int i = 0; i < _qHdr.cluster_bits; i++) _sectorMask = (_sectorMask << 1) + 1;
|
||||
for(var i = 0; i < _qHdr.cluster_bits; i++) _sectorMask = (_sectorMask << 1) + 1;
|
||||
|
||||
_qHdr.l1_size = (uint)((long)_qHdr.size + (1 << _l1Shift) - 1 >> _l1Shift);
|
||||
|
||||
@@ -159,7 +159,7 @@ public sealed partial class Qcow2
|
||||
|
||||
if(l1TableClusters == 0) l1TableClusters = 1;
|
||||
|
||||
byte[] empty = new byte[_qHdr.l1_table_offset + l1TableClusters * (ulong)_clusterSize];
|
||||
var empty = new byte[_qHdr.l1_table_offset + l1TableClusters * (ulong)_clusterSize];
|
||||
_writingStream.Write(empty, 0, empty.Length);
|
||||
|
||||
IsWriting = true;
|
||||
@@ -177,7 +177,7 @@ public sealed partial class Qcow2
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -220,7 +220,7 @@ public sealed partial class Qcow2
|
||||
{
|
||||
_writingStream.Seek(0, SeekOrigin.End);
|
||||
_l1Table[l1Off] = (ulong)_writingStream.Position;
|
||||
byte[] l2TableB = new byte[_l2Size * 8];
|
||||
var l2TableB = new byte[_l2Size * 8];
|
||||
_writingStream.Seek(0, SeekOrigin.End);
|
||||
_writingStream.Write(l2TableB, 0, l2TableB.Length);
|
||||
}
|
||||
@@ -231,14 +231,14 @@ public sealed partial class Qcow2
|
||||
|
||||
_writingStream.Seek((long)(_l1Table[l1Off] + l2Off * 8), SeekOrigin.Begin);
|
||||
|
||||
byte[] entry = new byte[8];
|
||||
var entry = new byte[8];
|
||||
_writingStream.EnsureRead(entry, 0, 8);
|
||||
ulong offset = BigEndianBitConverter.ToUInt64(entry, 0);
|
||||
var offset = BigEndianBitConverter.ToUInt64(entry, 0);
|
||||
|
||||
if(offset == 0)
|
||||
{
|
||||
offset = (ulong)_writingStream.Length;
|
||||
byte[] cluster = new byte[_clusterSize];
|
||||
var cluster = new byte[_clusterSize];
|
||||
entry = BigEndianBitConverter.GetBytes(offset);
|
||||
_writingStream.Seek((long)(_l1Table[l1Off] + l2Off * 8), SeekOrigin.Begin);
|
||||
_writingStream.Write(entry, 0, 8);
|
||||
@@ -259,7 +259,7 @@ public sealed partial class Qcow2
|
||||
{
|
||||
refBlockOffset = (ulong)_writingStream.Length;
|
||||
_refCountTable[refCountTableIndex] = refBlockOffset;
|
||||
byte[] cluster = new byte[_clusterSize];
|
||||
var cluster = new byte[_clusterSize];
|
||||
_writingStream.Seek(0, SeekOrigin.End);
|
||||
_writingStream.Write(cluster, 0, cluster.Length);
|
||||
}
|
||||
@@ -275,7 +275,7 @@ public sealed partial class Qcow2
|
||||
|
||||
// TODO: This can be optimized
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -303,10 +303,10 @@ public sealed partial class Qcow2
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
byte[] tmp = new byte[_imageInfo.SectorSize];
|
||||
var tmp = new byte[_imageInfo.SectorSize];
|
||||
Array.Copy(data, i * _imageInfo.SectorSize, tmp, 0, _imageInfo.SectorSize);
|
||||
|
||||
if(!WriteSector(tmp, sectorAddress + i)) return false;
|
||||
if(!WriteSector(tmp, sectorAddress + i, sectorStatus[i])) return false;
|
||||
}
|
||||
|
||||
ErrorMessage = "";
|
||||
@@ -315,7 +315,7 @@ public sealed partial class Qcow2
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -323,7 +323,7 @@ public sealed partial class Qcow2
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
|
||||
@@ -109,12 +109,12 @@ public sealed partial class Qed
|
||||
|
||||
_l1Table = new ulong[_tableSize];
|
||||
_l1Mask = 0;
|
||||
int c = 0;
|
||||
var c = 0;
|
||||
_clusterBits = Ctz32(_qHdr.cluster_size);
|
||||
_l2Mask = _tableSize - 1 << _clusterBits;
|
||||
_l1Shift = _clusterBits + Ctz32(_tableSize);
|
||||
|
||||
for(int i = 0; i < 64; i++)
|
||||
for(var i = 0; i < 64; i++)
|
||||
{
|
||||
_l1Mask <<= 1;
|
||||
|
||||
@@ -126,9 +126,9 @@ public sealed partial class Qed
|
||||
|
||||
_sectorMask = 0;
|
||||
|
||||
for(int i = 0; i < _clusterBits; i++) _sectorMask = (_sectorMask << 1) + 1;
|
||||
for(var i = 0; i < _clusterBits; i++) _sectorMask = (_sectorMask << 1) + 1;
|
||||
|
||||
byte[] empty = new byte[_qHdr.l1_table_offset + _tableSize * 8];
|
||||
var empty = new byte[_qHdr.l1_table_offset + _tableSize * 8];
|
||||
_writingStream.Write(empty, 0, empty.Length);
|
||||
|
||||
IsWriting = true;
|
||||
@@ -146,7 +146,7 @@ public sealed partial class Qed
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -189,7 +189,7 @@ public sealed partial class Qed
|
||||
{
|
||||
_writingStream.Seek(0, SeekOrigin.End);
|
||||
_l1Table[l1Off] = (ulong)_writingStream.Position;
|
||||
byte[] l2TableB = new byte[_tableSize * 8];
|
||||
var l2TableB = new byte[_tableSize * 8];
|
||||
_writingStream.Seek(0, SeekOrigin.End);
|
||||
_writingStream.Write(l2TableB, 0, l2TableB.Length);
|
||||
}
|
||||
@@ -200,14 +200,14 @@ public sealed partial class Qed
|
||||
|
||||
_writingStream.Seek((long)(_l1Table[l1Off] + l2Off * 8), SeekOrigin.Begin);
|
||||
|
||||
byte[] entry = new byte[8];
|
||||
var entry = new byte[8];
|
||||
_writingStream.EnsureRead(entry, 0, 8);
|
||||
ulong offset = BitConverter.ToUInt64(entry, 0);
|
||||
var offset = BitConverter.ToUInt64(entry, 0);
|
||||
|
||||
if(offset == 0)
|
||||
{
|
||||
offset = (ulong)_writingStream.Length;
|
||||
byte[] cluster = new byte[_qHdr.cluster_size];
|
||||
var cluster = new byte[_qHdr.cluster_size];
|
||||
entry = BitConverter.GetBytes(offset);
|
||||
_writingStream.Seek((long)(_l1Table[l1Off] + l2Off * 8), SeekOrigin.Begin);
|
||||
_writingStream.Write(entry, 0, 8);
|
||||
@@ -225,7 +225,7 @@ public sealed partial class Qed
|
||||
|
||||
// TODO: This can be optimized
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -253,10 +253,10 @@ public sealed partial class Qed
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
byte[] tmp = new byte[_imageInfo.SectorSize];
|
||||
var tmp = new byte[_imageInfo.SectorSize];
|
||||
Array.Copy(data, i * _imageInfo.SectorSize, tmp, 0, _imageInfo.SectorSize);
|
||||
|
||||
if(!WriteSector(tmp, sectorAddress + i)) return false;
|
||||
if(!WriteSector(tmp, sectorAddress + i, sectorStatus[i])) return false;
|
||||
}
|
||||
|
||||
ErrorMessage = "";
|
||||
@@ -265,7 +265,7 @@ public sealed partial class Qed
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -273,7 +273,7 @@ public sealed partial class Qed
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -290,7 +290,7 @@ public sealed partial class Qed
|
||||
return false;
|
||||
}
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<QedHeader>()];
|
||||
var hdr = new byte[Marshal.SizeOf<QedHeader>()];
|
||||
MemoryMarshal.Write(hdr, in _qHdr);
|
||||
|
||||
_writingStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
@@ -113,7 +113,7 @@ public sealed partial class RayDim
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -147,7 +147,7 @@ public sealed partial class RayDim
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -181,7 +181,7 @@ public sealed partial class RayDim
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -189,7 +189,7 @@ public sealed partial class RayDim
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -231,7 +231,7 @@ public sealed partial class RayDim
|
||||
return false;
|
||||
}
|
||||
|
||||
string headerSignature = $"Disk IMage VER 1.0 Copyright (C) {DateTime.Now.Year
|
||||
var headerSignature = $"Disk IMage VER 1.0 Copyright (C) {DateTime.Now.Year
|
||||
:D4} Ray Arachelian, All Rights Reserved. Aaru ";
|
||||
|
||||
var header = new Header
|
||||
@@ -245,8 +245,8 @@ public sealed partial class RayDim
|
||||
|
||||
header.signature[0x4A] = 0x00;
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
var hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
System.Runtime.InteropServices.Marshal.StructureToPtr(header, hdrPtr, true);
|
||||
System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
|
||||
System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr);
|
||||
|
||||
@@ -123,7 +123,7 @@ public sealed partial class RsIde
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -157,7 +157,7 @@ public sealed partial class RsIde
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -191,7 +191,7 @@ public sealed partial class RsIde
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -199,7 +199,7 @@ public sealed partial class RsIde
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -285,8 +285,8 @@ public sealed partial class RsIde
|
||||
if(string.IsNullOrEmpty(_imageInfo.DriveSerialNumber))
|
||||
_imageInfo.DriveSerialNumber = $"{new Random().NextDouble():16X}";
|
||||
|
||||
byte[] ataIdBytes = new byte[Marshal.SizeOf<Identify.IdentifyDevice>()];
|
||||
nint ptr = System.Runtime.InteropServices.Marshal.AllocHGlobal(512);
|
||||
var ataIdBytes = new byte[Marshal.SizeOf<Identify.IdentifyDevice>()];
|
||||
nint ptr = System.Runtime.InteropServices.Marshal.AllocHGlobal(512);
|
||||
System.Runtime.InteropServices.Marshal.StructureToPtr(ataId, ptr, true);
|
||||
|
||||
System.Runtime.InteropServices.Marshal.Copy(ptr, ataIdBytes, 0, Marshal.SizeOf<Identify.IdentifyDevice>());
|
||||
@@ -306,8 +306,8 @@ public sealed partial class RsIde
|
||||
else
|
||||
Array.Copy(_identify, 0, header.identify, 0, 106);
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
var hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
System.Runtime.InteropServices.Marshal.StructureToPtr(header, hdrPtr, true);
|
||||
System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
|
||||
System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr);
|
||||
|
||||
@@ -56,7 +56,7 @@ public sealed partial class SaveDskF
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -88,7 +88,7 @@ public sealed partial class SaveDskF
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -120,7 +120,7 @@ public sealed partial class SaveDskF
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -128,7 +128,7 @@ public sealed partial class SaveDskF
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -158,8 +158,8 @@ public sealed partial class SaveDskF
|
||||
: commentsBytes.Length);
|
||||
}
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
var hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
System.Runtime.InteropServices.Marshal.StructureToPtr(_header, hdrPtr, true);
|
||||
System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
|
||||
System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr);
|
||||
|
||||
@@ -101,9 +101,9 @@ public sealed partial class SuperCardPro
|
||||
|
||||
List<byte> scpData = FluxRepresentationsToUInt16List(dataBuffer, scpIndices, out uint[] trackLengths);
|
||||
|
||||
uint offset = (uint)(4 + 12 * Header.revolutions);
|
||||
var offset = (uint)(4 + 12 * Header.revolutions);
|
||||
|
||||
for(int i = 0; i < Header.revolutions; i++)
|
||||
for(var i = 0; i < Header.revolutions; i++)
|
||||
{
|
||||
_writingStream.Write(BitConverter.GetBytes(scpIndices[i]), 0, 4);
|
||||
_writingStream.Write(BitConverter.GetBytes(trackLengths[i]), 0, 4);
|
||||
@@ -179,7 +179,7 @@ public sealed partial class SuperCardPro
|
||||
_writingStream.WriteByte(Header.resolution);
|
||||
|
||||
_writingStream.Seek(0, SeekOrigin.End);
|
||||
string date = DateTime.Now.ToString("G");
|
||||
var date = DateTime.Now.ToString("G");
|
||||
_writingStream.Write(Encoding.ASCII.GetBytes(date), 0, date.Length);
|
||||
|
||||
Header.checksum = CalculateChecksum(_writingStream);
|
||||
@@ -207,14 +207,14 @@ public sealed partial class SuperCardPro
|
||||
|
||||
public bool WriteMediaTag(byte[] data, MediaTagType tag) => false;
|
||||
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Flux_decoding_is_not_yet_implemented;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Flux_decoding_is_not_yet_implemented;
|
||||
|
||||
@@ -222,7 +222,7 @@ public sealed partial class SuperCardPro
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Flux_decoding_is_not_yet_implemented;
|
||||
|
||||
@@ -230,7 +230,7 @@ public sealed partial class SuperCardPro
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Flux_decoding_is_not_yet_implemented;
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ public sealed partial class T98
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -132,7 +132,7 @@ public sealed partial class T98
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -164,7 +164,7 @@ public sealed partial class T98
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -172,7 +172,7 @@ public sealed partial class T98
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -189,7 +189,7 @@ public sealed partial class T98
|
||||
return false;
|
||||
}
|
||||
|
||||
int cylinders = (int)(_imageInfo.Sectors / 33 / 8);
|
||||
var cylinders = (int)(_imageInfo.Sectors / 33 / 8);
|
||||
_writingStream.Seek(0, SeekOrigin.Begin);
|
||||
_writingStream.Write(BitConverter.GetBytes(cylinders), 0, 4);
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ public sealed partial class Udif
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -179,7 +179,7 @@ public sealed partial class Udif
|
||||
|
||||
// TODO: This can be optimized
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -227,10 +227,10 @@ public sealed partial class Udif
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
byte[] tmp = new byte[_imageInfo.SectorSize];
|
||||
var tmp = new byte[_imageInfo.SectorSize];
|
||||
Array.Copy(data, i * _imageInfo.SectorSize, tmp, 0, _imageInfo.SectorSize);
|
||||
|
||||
if(!WriteSector(tmp, sectorAddress + i)) return false;
|
||||
if(!WriteSector(tmp, sectorAddress + i, sectorStatus[i])) return false;
|
||||
}
|
||||
|
||||
ErrorMessage = "";
|
||||
@@ -239,7 +239,7 @@ public sealed partial class Udif
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -247,7 +247,7 @@ public sealed partial class Udif
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ public sealed partial class Vdi
|
||||
return false;
|
||||
}
|
||||
|
||||
uint ibmEntries = (uint)(sectors * sectorSize / DEFAULT_BLOCK_SIZE);
|
||||
var ibmEntries = (uint)(sectors * sectorSize / DEFAULT_BLOCK_SIZE);
|
||||
|
||||
if(sectors * sectorSize % DEFAULT_BLOCK_SIZE > 0) ibmEntries++;
|
||||
|
||||
@@ -139,7 +139,7 @@ public sealed partial class Vdi
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -191,7 +191,7 @@ public sealed partial class Vdi
|
||||
|
||||
// TODO: This can be optimized
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -219,10 +219,10 @@ public sealed partial class Vdi
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
byte[] tmp = new byte[_imageInfo.SectorSize];
|
||||
var tmp = new byte[_imageInfo.SectorSize];
|
||||
Array.Copy(data, i * _imageInfo.SectorSize, tmp, 0, _imageInfo.SectorSize);
|
||||
|
||||
if(!WriteSector(tmp, sectorAddress + i)) return false;
|
||||
if(!WriteSector(tmp, sectorAddress + i, sectorStatus[i])) return false;
|
||||
}
|
||||
|
||||
ErrorMessage = "";
|
||||
@@ -231,7 +231,7 @@ public sealed partial class Vdi
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -239,7 +239,7 @@ public sealed partial class Vdi
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -281,8 +281,8 @@ public sealed partial class Vdi
|
||||
}
|
||||
}
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
var hdr = new byte[Marshal.SizeOf<Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
||||
System.Runtime.InteropServices.Marshal.StructureToPtr(_vHdr, hdrPtr, true);
|
||||
System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
|
||||
System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr);
|
||||
|
||||
@@ -49,6 +49,126 @@ namespace Aaru.Images;
|
||||
|
||||
public sealed partial class Vhd
|
||||
{
|
||||
void SetChsInFooter()
|
||||
{
|
||||
if(_imageInfo.Cylinders == 0)
|
||||
{
|
||||
ulong cylinderTimesHeads;
|
||||
|
||||
if(_imageInfo.Sectors > 65535 * 16 * 255)
|
||||
{
|
||||
_imageInfo.Cylinders = 65535;
|
||||
_imageInfo.Heads = 16;
|
||||
_imageInfo.SectorsPerTrack = 255;
|
||||
}
|
||||
|
||||
if(_imageInfo.Sectors >= 65535 * 16 * 63)
|
||||
{
|
||||
_imageInfo.Heads = 16;
|
||||
_imageInfo.SectorsPerTrack = 255;
|
||||
cylinderTimesHeads = _imageInfo.Sectors / _imageInfo.SectorsPerTrack;
|
||||
}
|
||||
else
|
||||
{
|
||||
_imageInfo.SectorsPerTrack = 17;
|
||||
cylinderTimesHeads = _imageInfo.Sectors / _imageInfo.SectorsPerTrack;
|
||||
|
||||
_imageInfo.Heads = (uint)((cylinderTimesHeads + 1023) / 1024);
|
||||
|
||||
if(_imageInfo.Heads < 4) _imageInfo.Heads = 4;
|
||||
|
||||
if(cylinderTimesHeads >= _imageInfo.Heads * 1024 || _imageInfo.Heads > 16)
|
||||
{
|
||||
_imageInfo.SectorsPerTrack = 31;
|
||||
_imageInfo.Heads = 16;
|
||||
cylinderTimesHeads = _imageInfo.Sectors / _imageInfo.SectorsPerTrack;
|
||||
}
|
||||
|
||||
if(cylinderTimesHeads >= _imageInfo.Heads * 1024)
|
||||
{
|
||||
_imageInfo.SectorsPerTrack = 63;
|
||||
_imageInfo.Heads = 16;
|
||||
cylinderTimesHeads = _imageInfo.Sectors / _imageInfo.SectorsPerTrack;
|
||||
}
|
||||
}
|
||||
|
||||
_imageInfo.Cylinders = (uint)(cylinderTimesHeads / _imageInfo.Heads);
|
||||
}
|
||||
|
||||
_thisFooter.DiskGeometry = ((_imageInfo.Cylinders & 0xFFFF) << 16) +
|
||||
((_imageInfo.Heads & 0xFF) << 8) +
|
||||
(_imageInfo.SectorsPerTrack & 0xFF);
|
||||
}
|
||||
|
||||
void Flush()
|
||||
{
|
||||
_thisFooter.Offset = _thisFooter.DiskType == TYPE_FIXED ? ulong.MaxValue : 512;
|
||||
|
||||
var footerBytes = new byte[512];
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.Cookie), 0, footerBytes, 0x00, 8);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.Features), 0, footerBytes, 0x08, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.Version), 0, footerBytes, 0x0C, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.Offset), 0, footerBytes, 0x10, 8);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.Timestamp), 0, footerBytes, 0x18, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.CreatorApplication), 0, footerBytes, 0x1C, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.CreatorVersion), 0, footerBytes, 0x20, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.CreatorHostOs), 0, footerBytes, 0x24, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.OriginalSize), 0, footerBytes, 0x28, 8);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.CurrentSize), 0, footerBytes, 0x30, 8);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.DiskGeometry), 0, footerBytes, 0x38, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.DiskType), 0, footerBytes, 0x3C, 4);
|
||||
Array.Copy(_thisFooter.UniqueId.ToByteArray(), 0, footerBytes, 0x44, 4);
|
||||
|
||||
_thisFooter.Checksum = VhdChecksum(footerBytes);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.Checksum), 0, footerBytes, 0x40, 4);
|
||||
|
||||
if(!_dynamic)
|
||||
{
|
||||
_writingStream.Seek((long)_thisFooter.OriginalSize, SeekOrigin.Begin);
|
||||
_writingStream.Write(footerBytes, 0, 512);
|
||||
|
||||
_writingStream.Flush();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(_blockInCache)
|
||||
{
|
||||
_writingStream.Position = _cachedBlockPosition;
|
||||
_writingStream.Write(_cachedBlock, 0, _cachedBlock.Length);
|
||||
_cachedBlock = null;
|
||||
_blockInCache = false;
|
||||
}
|
||||
|
||||
_writingStream.Position = (long)_thisDynamic.TableOffset;
|
||||
ReadOnlySpan<uint> span = _blockAllocationTable;
|
||||
|
||||
byte[] bat = MemoryMarshal.Cast<uint, byte>(span)[..(int)(_thisDynamic.MaxTableEntries * sizeof(uint))]
|
||||
.ToArray();
|
||||
|
||||
_writingStream.Write(bat, 0, bat.Length);
|
||||
|
||||
var dynamicBytes = new byte[1024];
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisDynamic.Cookie), 0, dynamicBytes, 0x00, 8);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisDynamic.DataOffset), 0, dynamicBytes, 0x08, 8);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisDynamic.TableOffset), 0, dynamicBytes, 0x10, 8);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisDynamic.HeaderVersion), 0, dynamicBytes, 0x18, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisDynamic.MaxTableEntries), 0, dynamicBytes, 0x1C, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisDynamic.BlockSize), 0, dynamicBytes, 0x20, 4);
|
||||
|
||||
_thisDynamic.Checksum = VhdChecksum(dynamicBytes);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisDynamic.Checksum), 0, dynamicBytes, 0x24, 4);
|
||||
|
||||
_writingStream.Position = 0;
|
||||
_writingStream.Write(footerBytes, 0, 512);
|
||||
_writingStream.Position = 512;
|
||||
_writingStream.Write(dynamicBytes, 0, 1024);
|
||||
_writingStream.Position = _currentFooterPosition;
|
||||
_writingStream.Write(footerBytes, 0, 512);
|
||||
|
||||
_writingStream.Flush();
|
||||
}
|
||||
|
||||
#region IWritableImage Members
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -202,7 +322,7 @@ public sealed partial class Vhd
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -236,7 +356,7 @@ public sealed partial class Vhd
|
||||
}
|
||||
|
||||
// Block number for BAT searching
|
||||
uint blockNumber = (uint)Math.Floor(sectorAddress / (_thisDynamic.BlockSize / 512.0));
|
||||
var blockNumber = (uint)Math.Floor(sectorAddress / (_thisDynamic.BlockSize / 512.0));
|
||||
|
||||
// If there's a cached block and it's the one we're looking for, flush cached data (clears cache)
|
||||
if(_blockInCache && _cachedBlockNumber != blockNumber) Flush();
|
||||
@@ -269,10 +389,10 @@ public sealed partial class Vhd
|
||||
}
|
||||
|
||||
// Sector number inside of block
|
||||
uint sectorInBlock = (uint)(sectorAddress % (_thisDynamic.BlockSize / 512));
|
||||
int bitmapByte = (int)Math.Floor((double)sectorInBlock / 8);
|
||||
int bitmapBit = (int)(sectorInBlock % 8);
|
||||
byte mask = (byte)(1 << 7 - bitmapBit);
|
||||
var sectorInBlock = (uint)(sectorAddress % (_thisDynamic.BlockSize / 512));
|
||||
var bitmapByte = (int)Math.Floor((double)sectorInBlock / 8);
|
||||
var bitmapBit = (int)(sectorInBlock % 8);
|
||||
var mask = (byte)(1 << 7 - bitmapBit);
|
||||
bool dirty = (_cachedBlock[bitmapByte] & mask) == mask;
|
||||
|
||||
// If there's no data in sector...
|
||||
@@ -304,16 +424,16 @@ public sealed partial class Vhd
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(_dynamic)
|
||||
{
|
||||
if(ArrayHelpers.ArrayIsNullOrEmpty(data))
|
||||
{
|
||||
for(int i = 0; i < length; i++)
|
||||
for(var i = 0; i < length; i++)
|
||||
{
|
||||
// Block number for BAT searching
|
||||
uint blockNumber = (uint)Math.Floor(sectorAddress / (_thisDynamic.BlockSize / 512.0));
|
||||
var blockNumber = (uint)Math.Floor(sectorAddress / (_thisDynamic.BlockSize / 512.0));
|
||||
|
||||
// Block not allocated, bail out
|
||||
if(_blockAllocationTable[blockNumber] == 0xFFFFFFFF) continue;
|
||||
@@ -330,10 +450,10 @@ public sealed partial class Vhd
|
||||
}
|
||||
|
||||
// Sector number inside of block
|
||||
uint sectorInBlock = (uint)(sectorAddress % (_thisDynamic.BlockSize / 512));
|
||||
int bitmapByte = (int)Math.Floor((double)sectorInBlock / 8);
|
||||
int bitmapBit = (int)(sectorInBlock % 8);
|
||||
byte mask = (byte)(1 << 7 - bitmapBit);
|
||||
var sectorInBlock = (uint)(sectorAddress % (_thisDynamic.BlockSize / 512));
|
||||
var bitmapByte = (int)Math.Floor((double)sectorInBlock / 8);
|
||||
var bitmapBit = (int)(sectorInBlock % 8);
|
||||
var mask = (byte)(1 << 7 - bitmapBit);
|
||||
bool dirty = (_cachedBlock[bitmapByte] & mask) == mask;
|
||||
|
||||
if(!dirty) continue;
|
||||
@@ -351,10 +471,9 @@ public sealed partial class Vhd
|
||||
return true;
|
||||
}
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
if(!WriteSector(data[(i * 512)..(i * 512 + 512)], sectorAddress + (ulong)i)) return false;
|
||||
}
|
||||
for(var i = 0; i < length; i++)
|
||||
if(!WriteSector(data[(i * 512)..(i * 512 + 512)], sectorAddress + (ulong)i, sectorStatus[i]))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -389,7 +508,7 @@ public sealed partial class Vhd
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -397,7 +516,7 @@ public sealed partial class Vhd
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -484,124 +603,4 @@ public sealed partial class Vhd
|
||||
public bool SetMetadata(Metadata metadata) => false;
|
||||
|
||||
#endregion
|
||||
|
||||
void SetChsInFooter()
|
||||
{
|
||||
if(_imageInfo.Cylinders == 0)
|
||||
{
|
||||
ulong cylinderTimesHeads;
|
||||
|
||||
if(_imageInfo.Sectors > 65535 * 16 * 255)
|
||||
{
|
||||
_imageInfo.Cylinders = 65535;
|
||||
_imageInfo.Heads = 16;
|
||||
_imageInfo.SectorsPerTrack = 255;
|
||||
}
|
||||
|
||||
if(_imageInfo.Sectors >= 65535 * 16 * 63)
|
||||
{
|
||||
_imageInfo.Heads = 16;
|
||||
_imageInfo.SectorsPerTrack = 255;
|
||||
cylinderTimesHeads = _imageInfo.Sectors / _imageInfo.SectorsPerTrack;
|
||||
}
|
||||
else
|
||||
{
|
||||
_imageInfo.SectorsPerTrack = 17;
|
||||
cylinderTimesHeads = _imageInfo.Sectors / _imageInfo.SectorsPerTrack;
|
||||
|
||||
_imageInfo.Heads = (uint)((cylinderTimesHeads + 1023) / 1024);
|
||||
|
||||
if(_imageInfo.Heads < 4) _imageInfo.Heads = 4;
|
||||
|
||||
if(cylinderTimesHeads >= _imageInfo.Heads * 1024 || _imageInfo.Heads > 16)
|
||||
{
|
||||
_imageInfo.SectorsPerTrack = 31;
|
||||
_imageInfo.Heads = 16;
|
||||
cylinderTimesHeads = _imageInfo.Sectors / _imageInfo.SectorsPerTrack;
|
||||
}
|
||||
|
||||
if(cylinderTimesHeads >= _imageInfo.Heads * 1024)
|
||||
{
|
||||
_imageInfo.SectorsPerTrack = 63;
|
||||
_imageInfo.Heads = 16;
|
||||
cylinderTimesHeads = _imageInfo.Sectors / _imageInfo.SectorsPerTrack;
|
||||
}
|
||||
}
|
||||
|
||||
_imageInfo.Cylinders = (uint)(cylinderTimesHeads / _imageInfo.Heads);
|
||||
}
|
||||
|
||||
_thisFooter.DiskGeometry = ((_imageInfo.Cylinders & 0xFFFF) << 16) +
|
||||
((_imageInfo.Heads & 0xFF) << 8) +
|
||||
(_imageInfo.SectorsPerTrack & 0xFF);
|
||||
}
|
||||
|
||||
void Flush()
|
||||
{
|
||||
_thisFooter.Offset = _thisFooter.DiskType == TYPE_FIXED ? ulong.MaxValue : 512;
|
||||
|
||||
byte[] footerBytes = new byte[512];
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.Cookie), 0, footerBytes, 0x00, 8);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.Features), 0, footerBytes, 0x08, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.Version), 0, footerBytes, 0x0C, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.Offset), 0, footerBytes, 0x10, 8);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.Timestamp), 0, footerBytes, 0x18, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.CreatorApplication), 0, footerBytes, 0x1C, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.CreatorVersion), 0, footerBytes, 0x20, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.CreatorHostOs), 0, footerBytes, 0x24, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.OriginalSize), 0, footerBytes, 0x28, 8);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.CurrentSize), 0, footerBytes, 0x30, 8);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.DiskGeometry), 0, footerBytes, 0x38, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.DiskType), 0, footerBytes, 0x3C, 4);
|
||||
Array.Copy(_thisFooter.UniqueId.ToByteArray(), 0, footerBytes, 0x44, 4);
|
||||
|
||||
_thisFooter.Checksum = VhdChecksum(footerBytes);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisFooter.Checksum), 0, footerBytes, 0x40, 4);
|
||||
|
||||
if(!_dynamic)
|
||||
{
|
||||
_writingStream.Seek((long)_thisFooter.OriginalSize, SeekOrigin.Begin);
|
||||
_writingStream.Write(footerBytes, 0, 512);
|
||||
|
||||
_writingStream.Flush();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(_blockInCache)
|
||||
{
|
||||
_writingStream.Position = _cachedBlockPosition;
|
||||
_writingStream.Write(_cachedBlock, 0, _cachedBlock.Length);
|
||||
_cachedBlock = null;
|
||||
_blockInCache = false;
|
||||
}
|
||||
|
||||
_writingStream.Position = (long)_thisDynamic.TableOffset;
|
||||
ReadOnlySpan<uint> span = _blockAllocationTable;
|
||||
|
||||
byte[] bat = MemoryMarshal.Cast<uint, byte>(span)[..(int)(_thisDynamic.MaxTableEntries * sizeof(uint))]
|
||||
.ToArray();
|
||||
|
||||
_writingStream.Write(bat, 0, bat.Length);
|
||||
|
||||
byte[] dynamicBytes = new byte[1024];
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisDynamic.Cookie), 0, dynamicBytes, 0x00, 8);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisDynamic.DataOffset), 0, dynamicBytes, 0x08, 8);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisDynamic.TableOffset), 0, dynamicBytes, 0x10, 8);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisDynamic.HeaderVersion), 0, dynamicBytes, 0x18, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisDynamic.MaxTableEntries), 0, dynamicBytes, 0x1C, 4);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisDynamic.BlockSize), 0, dynamicBytes, 0x20, 4);
|
||||
|
||||
_thisDynamic.Checksum = VhdChecksum(dynamicBytes);
|
||||
Array.Copy(BigEndianBitConverter.GetBytes(_thisDynamic.Checksum), 0, dynamicBytes, 0x24, 4);
|
||||
|
||||
_writingStream.Position = 0;
|
||||
_writingStream.Write(footerBytes, 0, 512);
|
||||
_writingStream.Position = 512;
|
||||
_writingStream.Write(dynamicBytes, 0, 1024);
|
||||
_writingStream.Position = _currentFooterPosition;
|
||||
_writingStream.Write(footerBytes, 0, 512);
|
||||
|
||||
_writingStream.Flush();
|
||||
}
|
||||
}
|
||||
@@ -184,7 +184,7 @@ public sealed partial class VMware
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -217,7 +217,7 @@ public sealed partial class VMware
|
||||
|
||||
// TODO: Implement sparse and split
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -249,7 +249,7 @@ public sealed partial class VMware
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -257,7 +257,7 @@ public sealed partial class VMware
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ public sealed partial class Virtual98
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -139,7 +139,7 @@ public sealed partial class Virtual98
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -171,7 +171,7 @@ public sealed partial class Virtual98
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -179,7 +179,7 @@ public sealed partial class Virtual98
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -238,8 +238,8 @@ public sealed partial class Virtual98
|
||||
if(commentsBytes != null)
|
||||
Array.Copy(commentsBytes, 0, _v98Hdr.comment, 0, commentsBytes.Length >= 128 ? 128 : commentsBytes.Length);
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<Virtual98Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Virtual98Header>());
|
||||
var hdr = new byte[Marshal.SizeOf<Virtual98Header>()];
|
||||
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Virtual98Header>());
|
||||
System.Runtime.InteropServices.Marshal.StructureToPtr(_v98Hdr, hdrPtr, true);
|
||||
System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
|
||||
System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr);
|
||||
|
||||
@@ -157,7 +157,7 @@ public sealed partial class ZZZRawImage
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSector(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -189,7 +189,7 @@ public sealed partial class ZZZRawImage
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
if(!IsWriting)
|
||||
{
|
||||
@@ -221,7 +221,7 @@ public sealed partial class ZZZRawImage
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
||||
public bool WriteSectorLong(byte[] data, ulong sectorAddress, SectorStatus sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
@@ -229,7 +229,7 @@ public sealed partial class ZZZRawImage
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
||||
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length, SectorStatus[] sectorStatus)
|
||||
{
|
||||
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user