Files
Aaru/Aaru.Filesystems/ISO9660/Xattr.cs

198 lines
7.6 KiB
C#
Raw Permalink Normal View History

2019-07-31 20:10:27 +01:00
// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
2019-07-31 20:10:27 +01:00
// ----------------------------------------------------------------------------
//
// Filename : Xattr.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : ISO9660 filesystem plugin.
//
// --[ Description ] ----------------------------------------------------------
//
// Handles extended attributes
//
// --[ License ] --------------------------------------------------------------
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
// In the loving memory of Facunda "Tata" Suárez Domínguez, R.I.P. 2019/07/24
2019-07-31 20:10:27 +01:00
// ****************************************************************************/
using System;
using System.Collections.Generic;
2021-09-16 04:42:14 +01:00
using Aaru.CommonTypes.Enums;
2020-02-27 00:33:26 +00:00
using Aaru.Helpers;
namespace Aaru.Filesystems;
2022-03-06 13:29:38 +00:00
public sealed partial class ISO9660
{
#region IReadOnlyFilesystem Members
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public ErrorNumber ListXAttr(string path, out List<string> xattrs)
{
2022-03-06 13:29:38 +00:00
xattrs = null;
2024-05-01 04:05:22 +01:00
if(!_mounted) return ErrorNumber.AccessDenied;
2019-07-22 01:29:51 +01:00
2022-03-06 13:29:38 +00:00
ErrorNumber err = GetFileEntry(path, out DecodedDirectoryEntry entry);
2019-07-22 01:29:51 +01:00
2024-05-01 04:05:22 +01:00
if(err != ErrorNumber.NoError) return err;
2024-05-01 04:39:38 +01:00
xattrs = [];
2024-05-01 04:05:22 +01:00
if(entry.XattrLength > 0) xattrs.Add("org.iso.9660.ea");
2024-05-01 04:05:22 +01:00
if(entry.AssociatedFile != null) xattrs.Add("org.iso.9660.AssociatedFile");
2024-05-01 04:05:22 +01:00
if(entry.AppleDosType is not null) xattrs.Add("com.apple.dos.type");
2024-05-01 04:05:22 +01:00
if(entry.AppleProDosType is not null) xattrs.Add("com.apple.prodos.type");
2024-05-01 04:05:22 +01:00
if(entry.ResourceFork != null) xattrs.Add("com.apple.ResourceFork");
2024-05-01 04:05:22 +01:00
if(entry.FinderInfo != null) xattrs.Add("com.apple.FinderInfo");
2019-07-22 01:29:51 +01:00
2024-05-01 04:05:22 +01:00
if(entry.AppleIcon != null) xattrs.Add("com.apple.Macintosh.Icon");
2024-05-01 04:05:22 +01:00
if(entry.AmigaComment != null) xattrs.Add("com.amiga.comments");
if(entry.Flags.HasFlag(FileFlags.Directory) || entry.Extents == null || entry.Extents.Count == 0)
2022-03-06 13:29:38 +00:00
return ErrorNumber.NoError;
ErrorNumber errno = _image.ReadSectorTag(entry.Extents[0].extent * _blockSize / 2048,
false,
SectorTagType.CdSectorSubHeader,
out _);
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return errno;
2022-03-06 13:29:38 +00:00
xattrs.Add("org.iso.mode2.subheader");
xattrs.Add("org.iso.mode2.subheader.copy");
2022-03-06 13:29:38 +00:00
return ErrorNumber.NoError;
}
2019-07-22 01:36:27 +01:00
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public ErrorNumber GetXattr(string path, string xattr, ref byte[] buf)
{
buf = null;
2024-05-01 04:05:22 +01:00
if(!_mounted) return ErrorNumber.AccessDenied;
2019-07-22 01:36:27 +01:00
2022-03-06 13:29:38 +00:00
ErrorNumber err = GetFileEntry(path, out DecodedDirectoryEntry entry);
2019-07-31 04:33:31 +01:00
2024-05-01 04:05:22 +01:00
if(err != ErrorNumber.NoError) return err;
2022-03-06 13:29:38 +00:00
switch(xattr)
{
case "org.iso.9660.ea":
2024-05-01 04:05:22 +01:00
return entry.XattrLength == 0
? ErrorNumber.NoSuchExtendedAttribute
: entry.Extents is null
? ErrorNumber.InvalidArgument
: ReadSingleExtent(entry.XattrLength * _blockSize, entry.Extents[0].extent, out buf);
2019-07-22 01:36:27 +01:00
2022-03-06 13:29:38 +00:00
case "org.iso.9660.AssociatedFile":
2024-05-01 04:05:22 +01:00
if(entry.AssociatedFile is null) return ErrorNumber.NoSuchExtendedAttribute;
2024-05-01 04:05:22 +01:00
if(entry.AssociatedFile.Extents is null) return ErrorNumber.InvalidArgument;
2019-07-22 01:36:27 +01:00
if(entry.AssociatedFile.Size != 0)
{
2024-05-01 04:05:22 +01:00
return ReadWithExtents(0,
(long)entry.AssociatedFile.Size,
entry.AssociatedFile.Extents,
entry.AssociatedFile.XA?.signature == XA_MAGIC &&
entry.AssociatedFile.XA?.attributes.HasFlag(XaAttributes.Interleaved) ==
2024-05-01 04:05:22 +01:00
true,
entry.AssociatedFile.XA?.filenumber ?? 0,
out buf);
}
2019-07-22 01:36:27 +01:00
2024-05-01 04:39:38 +01:00
buf = [];
return ErrorNumber.NoError;
2022-03-06 13:29:38 +00:00
case "com.apple.dos.type":
2024-05-01 04:05:22 +01:00
if(entry.AppleDosType is null) return ErrorNumber.NoSuchExtendedAttribute;
2022-03-06 13:29:38 +00:00
buf = new byte[1];
buf[0] = entry.AppleDosType.Value;
2022-03-06 13:29:38 +00:00
return ErrorNumber.NoError;
case "com.apple.prodos.type":
2024-05-01 04:05:22 +01:00
if(entry.AppleProDosType is null) return ErrorNumber.NoSuchExtendedAttribute;
2022-03-06 13:29:38 +00:00
buf = BitConverter.GetBytes(entry.AppleProDosType.Value);
2022-03-06 13:29:38 +00:00
return ErrorNumber.NoError;
case "com.apple.ResourceFork":
2024-05-01 04:05:22 +01:00
if(entry.ResourceFork is null) return ErrorNumber.NoSuchExtendedAttribute;
2024-05-01 04:05:22 +01:00
if(entry.ResourceFork.Extents is null) return ErrorNumber.InvalidArgument;
if(entry.ResourceFork.Size != 0)
{
2024-05-01 04:05:22 +01:00
return ReadWithExtents(0,
(long)entry.ResourceFork.Size,
entry.ResourceFork.Extents,
entry.ResourceFork.XA?.signature == XA_MAGIC &&
entry.ResourceFork.XA?.attributes.HasFlag(XaAttributes.Interleaved) == true,
2024-05-01 04:05:22 +01:00
entry.ResourceFork.XA?.filenumber ?? 0,
out buf);
}
2024-05-01 04:39:38 +01:00
buf = [];
return ErrorNumber.NoError;
2022-03-06 13:29:38 +00:00
case "com.apple.FinderInfo":
2024-05-01 04:05:22 +01:00
if(entry.FinderInfo is null) return ErrorNumber.NoSuchExtendedAttribute;
2022-03-06 13:29:38 +00:00
buf = Marshal.StructureToByteArrayBigEndian(entry.FinderInfo.Value);
2022-03-06 13:29:38 +00:00
return ErrorNumber.NoError;
case "com.apple.Macintosh.Icon":
2024-05-01 04:05:22 +01:00
if(entry.AppleIcon is null) return ErrorNumber.NoSuchExtendedAttribute;
2019-07-28 17:29:45 +01:00
2022-03-06 13:29:38 +00:00
buf = new byte[entry.AppleIcon.Length];
Array.Copy(entry.AppleIcon, 0, buf, 0, entry.AppleIcon.Length);
2019-07-28 17:29:45 +01:00
2022-03-06 13:29:38 +00:00
return ErrorNumber.NoError;
case "com.amiga.comments":
2024-05-01 04:05:22 +01:00
if(entry.AmigaComment is null) return ErrorNumber.NoSuchExtendedAttribute;
2022-03-06 13:29:38 +00:00
buf = new byte[entry.AmigaComment.Length];
Array.Copy(entry.AmigaComment, 0, buf, 0, entry.AmigaComment.Length);
2022-03-06 13:29:38 +00:00
return ErrorNumber.NoError;
case "org.iso.mode2.subheader":
buf = ReadSubheaderWithExtents(entry.Extents, false);
return ErrorNumber.NoError;
case "org.iso.mode2.subheader.copy":
buf = ReadSubheaderWithExtents(entry.Extents, true);
return ErrorNumber.NoError;
default:
return ErrorNumber.NoSuchExtendedAttribute;
2019-07-22 01:36:27 +01:00
}
}
#endregion
}