Refactor sector writing methods to include SectorStatus parameter and update related logic

This commit is contained in:
2025-10-22 20:25:23 +01:00
parent 0ac2a48fb6
commit ce0e0dff22
55 changed files with 927 additions and 676 deletions

View File

@@ -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);