From 50971115a52e00a6ee394eb802a4a2666fa5c353 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 22 Jul 2019 01:36:27 +0100 Subject: [PATCH] Implement getxattr for ISO9660. --- DiscImageChef.Filesystems/ISO9660/Xattr.cs | 40 +++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/DiscImageChef.Filesystems/ISO9660/Xattr.cs b/DiscImageChef.Filesystems/ISO9660/Xattr.cs index f412a4b6c..5e47c4ed8 100644 --- a/DiscImageChef.Filesystems/ISO9660/Xattr.cs +++ b/DiscImageChef.Filesystems/ISO9660/Xattr.cs @@ -16,14 +16,44 @@ namespace DiscImageChef.Filesystems.ISO9660 xattrs = new List(); - if(entry.AssociatedFile != null) - { - xattrs.Add("org.iso.9660.ea"); - } + if(entry.AssociatedFile != null) xattrs.Add("org.iso.9660.ea"); return Errno.NoError; } - public Errno GetXattr(string path, string xattr, ref byte[] buf) => throw new NotImplementedException(); + public Errno GetXattr(string path, string xattr, ref byte[] buf) + { + buf = null; + if(!mounted) return Errno.AccessDenied; + + Errno err = GetFileEntry(path, out DecodedDirectoryEntry entry); + if(err != Errno.NoError) return err; + + switch(xattr) + { + case "org.iso.9660.ea": + if(entry.AssociatedFile is null) return Errno.NoSuchExtendedAttribute; + + if(entry.AssociatedFile.Extent == 0) return Errno.InvalidArgument; + + if(entry.AssociatedFile.Size == 0) + { + buf = new byte[0]; + return Errno.NoError; + } + + // TODO: XA + uint eaSizeInSectors = entry.AssociatedFile.Size / 2048; + if(entry.AssociatedFile.Size % 2048 > 0) eaSizeInSectors++; + + byte[] ea = image.ReadSectors(entry.AssociatedFile.Extent, eaSizeInSectors); + + buf = new byte[entry.AssociatedFile.Size]; + Array.Copy(ea, 0, buf, 0, buf.LongLength); + + return Errno.NoError; + default: return Errno.NoSuchExtendedAttribute; + } + } } } \ No newline at end of file