Skip to content

Commit

Permalink
Handle range lock sector
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-visionaid committed Dec 5, 2024
1 parent 3753eaa commit 020b640
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions OpenMcdf/Fat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ namespace OpenMcdf;
/// </summary>
internal sealed class Fat : ContextBase, IEnumerable<FatEntry>, IDisposable
{
const uint RangeLockSectorOffset = 0x7FFFFF00;
const uint RangeLockSectorId = RangeLockSectorOffset / (uint)(1 << Header.SectorShiftV4);

private readonly FatSectorEnumerator fatSectorEnumerator;
private readonly Func<uint, bool> isFree;
private readonly byte[] cachedSectorBuffer;
Sector cachedSector = Sector.EndOfChain;
private bool isDirty;
Expand All @@ -20,6 +24,13 @@ public Fat(RootContextSite rootContextSite)
{
fatSectorEnumerator = new(rootContextSite);
cachedSectorBuffer = new byte[Context.SectorSize];

if (Context.Version == Version.V3)
isFree = value => value == SectorType.Free;
else if (Context.Version == Version.V4)
isFree = value => value == SectorType.Free && value != RangeLockSectorId;
else
throw new NotSupportedException($"Unsupported major version: {Context.Version}.");
}

public void Dispose()
Expand All @@ -29,6 +40,8 @@ public void Dispose()
fatSectorEnumerator.Dispose();
}

public bool IsFree(uint key) => isFree(key);

public uint this[uint key]
{
get
Expand Down
2 changes: 1 addition & 1 deletion OpenMcdf/FatEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public bool MoveNextFreeEntry()
{
while (MoveNext())
{
if (value == SectorType.Free)
if (fat.IsFree(value))
return true;
}

Expand Down

0 comments on commit 020b640

Please sign in to comment.