mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Expose MODE2 subheaders as extended attributes of HSF/ISO9660/CD-i filesystems. Fixes #358
This commit is contained in:
@@ -37,6 +37,7 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.CommonTypes.Structs;
|
||||
using Aaru.Console;
|
||||
using Aaru.Helpers;
|
||||
@@ -175,9 +176,8 @@ namespace Aaru.Filesystems.ISO9660
|
||||
|
||||
stat = new FileEntryInfo
|
||||
{
|
||||
Attributes = new FileAttributes(), Blocks = (long)(entry.Size / 2048), // TODO: XA
|
||||
BlockSize = 2048, Length = (long)entry.Size, Links = 1,
|
||||
LastWriteTimeUtc = entry.Timestamp
|
||||
Attributes = new FileAttributes(), Blocks = (long)(entry.Size / 2048), // TODO: XA
|
||||
BlockSize = 2048, Length = (long)entry.Size, Links = 1, LastWriteTimeUtc = entry.Timestamp
|
||||
};
|
||||
|
||||
if(entry.Extents?.Count > 0)
|
||||
@@ -556,5 +556,37 @@ namespace Aaru.Filesystems.ISO9660
|
||||
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
byte[] ReadSubheaderWithExtents(List<(uint extent, uint size)> extents, bool copy)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
|
||||
for(int i = 0; i < extents.Count; i++)
|
||||
{
|
||||
long leftExtentSize = extents[i].size;
|
||||
uint currentExtentSector = 0;
|
||||
|
||||
while(leftExtentSize > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] fullSector =
|
||||
image.ReadSectorTag(extents[i].extent + currentExtentSector,
|
||||
SectorTagType.CdSectorSubHeader);
|
||||
|
||||
ms.Write(fullSector, copy ? 0 : 4, 4);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
currentExtentSector++;
|
||||
leftExtentSize -= 2048;
|
||||
}
|
||||
}
|
||||
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,18 @@ namespace Aaru.Filesystems.ISO9660
|
||||
if(entry.AmigaComment != null)
|
||||
xattrs.Add("com.amiga.comments");
|
||||
|
||||
if(entry.Flags.HasFlag(FileFlags.Directory) ||
|
||||
entry.Extents.Count == 0)
|
||||
return Errno.NoError;
|
||||
|
||||
byte[] sector = image.ReadSectorLong(entry.Extents[0].extent);
|
||||
|
||||
if(sector[15] != 2)
|
||||
return Errno.NoError;
|
||||
|
||||
xattrs.Add("org.iso.mode2.subheader");
|
||||
xattrs.Add("org.iso.mode2.subheader.copy");
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
@@ -120,8 +132,7 @@ namespace Aaru.Filesystems.ISO9660
|
||||
}
|
||||
|
||||
buf = ReadWithExtents(0, (long)entry.AssociatedFile.Size, entry.AssociatedFile.Extents,
|
||||
entry.AssociatedFile.XA?.signature ==
|
||||
XA_MAGIC &&
|
||||
entry.AssociatedFile.XA?.signature == XA_MAGIC &&
|
||||
entry.AssociatedFile.XA?.attributes.HasFlag(XaAttributes.Interleaved) == true,
|
||||
entry.AssociatedFile.XA?.filenumber ?? 0);
|
||||
|
||||
@@ -156,8 +167,7 @@ namespace Aaru.Filesystems.ISO9660
|
||||
}
|
||||
|
||||
buf = ReadWithExtents(0, (long)entry.ResourceFork.Size, entry.ResourceFork.Extents,
|
||||
entry.ResourceFork.XA?.signature ==
|
||||
XA_MAGIC &&
|
||||
entry.ResourceFork.XA?.signature == XA_MAGIC &&
|
||||
entry.ResourceFork.XA?.attributes.HasFlag(XaAttributes.Interleaved) == true,
|
||||
entry.ResourceFork.XA?.filenumber ?? 0);
|
||||
|
||||
@@ -184,6 +194,14 @@ namespace Aaru.Filesystems.ISO9660
|
||||
buf = new byte[entry.AmigaComment.Length];
|
||||
Array.Copy(entry.AmigaComment, 0, buf, 0, entry.AmigaComment.Length);
|
||||
|
||||
return Errno.NoError;
|
||||
case "org.iso.mode2.subheader":
|
||||
buf = ReadSubheaderWithExtents(entry.Extents, false);
|
||||
|
||||
return Errno.NoError;
|
||||
case "org.iso.mode2.subheader.copy":
|
||||
buf = ReadSubheaderWithExtents(entry.Extents, true);
|
||||
|
||||
return Errno.NoError;
|
||||
default: return Errno.NoSuchExtendedAttribute;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user