From 282781cfd11edfc248e058eba32b06ec387daa5e Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 28 Jul 2019 17:29:45 +0100 Subject: [PATCH] Decode Amiga extensions to ISO9660. --- DiscImageChef.Filesystems/ISO9660/Dir.cs | 38 +++++++++++++++++++ DiscImageChef.Filesystems/ISO9660/File.cs | 15 ++++++++ .../ISO9660/Structs/Internal.cs | 2 + DiscImageChef.Filesystems/ISO9660/Xattr.cs | 8 ++++ 4 files changed, 63 insertions(+) diff --git a/DiscImageChef.Filesystems/ISO9660/Dir.cs b/DiscImageChef.Filesystems/ISO9660/Dir.cs index 94450d9c5..c36e88d76 100644 --- a/DiscImageChef.Filesystems/ISO9660/Dir.cs +++ b/DiscImageChef.Filesystems/ISO9660/Dir.cs @@ -390,6 +390,44 @@ namespace DiscImageChef.Filesystems.ISO9660 // All of these follow the SUSP indication of 2 bytes for signature 1 byte for length case AAIP_MAGIC: case AMIGA_MAGIC: + AmigaEntry amiga = + Marshal.ByteArrayToStructureBigEndian(data, systemAreaOff, + Marshal.SizeOf()); + + int protectionLength = 0; + + if(amiga.flags.HasFlag(AmigaFlags.Protection)) + { + entry.AmigaProtection = + Marshal.ByteArrayToStructureBigEndian(data, + systemAreaOff + + Marshal.SizeOf(), + Marshal + .SizeOf()); + + protectionLength = Marshal.SizeOf(); + } + + if(amiga.flags.HasFlag(AmigaFlags.Comment)) + { + if(entry.AmigaComment is null) entry.AmigaComment = new byte[0]; + + byte[] newComment = new byte[entry.AmigaComment.Length + + data + [systemAreaOff + Marshal.SizeOf() + protectionLength] - + 1]; + + Array.Copy(entry.AmigaComment, 0, newComment, 0, entry.AmigaComment.Length); + + Array.Copy(data, systemAreaOff + Marshal.SizeOf() + protectionLength, + newComment, entry.AmigaComment.Length, + data[systemAreaOff + Marshal.SizeOf() + protectionLength] - 1); + + entry.AmigaComment = newComment; + } + + systemAreaOff += amiga.length; + break; case RRIP_MAGIC: case RRIP_POSIX_ATTRIBUTES: case RRIP_POSIX_DEV_NO: diff --git a/DiscImageChef.Filesystems/ISO9660/File.cs b/DiscImageChef.Filesystems/ISO9660/File.cs index eacc30f32..e632aed30 100644 --- a/DiscImageChef.Filesystems/ISO9660/File.cs +++ b/DiscImageChef.Filesystems/ISO9660/File.cs @@ -132,6 +132,21 @@ namespace DiscImageChef.Filesystems.ISO9660 stat.Inode = entry.XA.Value.filenumber; } + if(entry.AmigaProtection != null) + { + if(entry.AmigaProtection.Value.Multiuser.HasFlag(AmigaMultiuser.GroupExec)) stat.Mode |= 8; + if(entry.AmigaProtection.Value.Multiuser.HasFlag(AmigaMultiuser.GroupRead)) stat.Mode |= 32; + if(entry.AmigaProtection.Value.Multiuser.HasFlag(AmigaMultiuser.GroupWrite)) stat.Mode |= 16; + if(entry.AmigaProtection.Value.Multiuser.HasFlag(AmigaMultiuser.OtherExec)) stat.Mode |= 1; + if(entry.AmigaProtection.Value.Multiuser.HasFlag(AmigaMultiuser.OtherRead)) stat.Mode |= 4; + if(entry.AmigaProtection.Value.Multiuser.HasFlag(AmigaMultiuser.OtherWrite)) stat.Mode |= 2; + if(entry.AmigaProtection.Value.Protection.HasFlag(AmigaAttributes.OwnerExec)) stat.Mode |= 64; + if(entry.AmigaProtection.Value.Protection.HasFlag(AmigaAttributes.OwnerRead)) stat.Mode |= 256; + if(entry.AmigaProtection.Value.Protection.HasFlag(AmigaAttributes.OwnerWrite)) stat.Mode |= 128; + if(entry.AmigaProtection.Value.Protection.HasFlag(AmigaAttributes.Archive)) + stat.Attributes |= FileAttributes.Archive; + } + if(entry.AssociatedFile is null || entry.AssociatedFile.Extent == 0 || entry.AssociatedFile.Size == 0) return Errno.NoError; diff --git a/DiscImageChef.Filesystems/ISO9660/Structs/Internal.cs b/DiscImageChef.Filesystems/ISO9660/Structs/Internal.cs index 80464fb4d..bcb3f7b65 100644 --- a/DiscImageChef.Filesystems/ISO9660/Structs/Internal.cs +++ b/DiscImageChef.Filesystems/ISO9660/Structs/Internal.cs @@ -57,6 +57,8 @@ namespace DiscImageChef.Filesystems.ISO9660 class DecodedDirectoryEntry { + public byte[] AmigaComment; + public AmigaProtection? AmigaProtection; public byte? AppleDosType; public byte[] AppleIcon; public ushort? AppleProDosType; diff --git a/DiscImageChef.Filesystems/ISO9660/Xattr.cs b/DiscImageChef.Filesystems/ISO9660/Xattr.cs index fb37dc54e..39e0644d1 100644 --- a/DiscImageChef.Filesystems/ISO9660/Xattr.cs +++ b/DiscImageChef.Filesystems/ISO9660/Xattr.cs @@ -22,6 +22,7 @@ namespace DiscImageChef.Filesystems.ISO9660 if(entry.ResourceFork != null) xattrs.Add("com.apple.ResourceFork"); if(entry.FinderInfo != null) xattrs.Add("com.apple.FinderInfo"); if(entry.AppleIcon != null) xattrs.Add("com.apple.Macintosh.Icon"); + if(entry.AmigaComment != null) xattrs.Add("com.amiga.comments"); return Errno.NoError; } @@ -115,6 +116,13 @@ namespace DiscImageChef.Filesystems.ISO9660 buf = new byte[entry.AppleIcon.Length]; Array.Copy(entry.AppleIcon, 0, buf, 0, entry.AppleIcon.Length); + return Errno.NoError; + case "com.amiga.comments": + if(entry.AmigaComment is null) return Errno.NoSuchExtendedAttribute; + + buf = new byte[entry.AmigaComment.Length]; + Array.Copy(entry.AmigaComment, 0, buf, 0, entry.AmigaComment.Length); + return Errno.NoError; default: return Errno.NoSuchExtendedAttribute; }