Files
Aaru/DiscImageChef.Filesystems/AppleMFS/Xattr.cs

169 lines
7.4 KiB
C#
Raw Normal View History

2017-05-19 20:28:49 +01:00
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Xattr.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Apple Macintosh File System plugin.
//
// --[ Description ] ----------------------------------------------------------
//
2016-08-01 00:43:31 +01:00
// Methods to handle Apple Macintosh File System extended attributes
// (Finder Info, Resource Fork, etc.)
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2018 Natalia Portillo
// ****************************************************************************/
using System;
2017-12-19 19:33:46 +00:00
using System.Collections.Generic;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Structs;
namespace DiscImageChef.Filesystems.AppleMFS
{
// Information from Inside Macintosh Volume II
public partial class AppleMFS
{
public Errno ListXAttr(string path, out List<string> xattrs)
{
xattrs = null;
2017-12-19 20:33:03 +00:00
if(!mounted) return Errno.AccessDenied;
2017-12-21 14:30:38 +00:00
string[] pathElements = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
2017-12-19 20:33:03 +00:00
if(pathElements.Length != 1) return Errno.NotSupported;
xattrs = new List<string>();
if(debug)
2018-06-22 08:08:38 +01:00
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
string.Compare(path, "$Bitmap", StringComparison.InvariantCulture) == 0 ||
2018-06-22 08:08:38 +01:00
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0)
{
if(device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag))
xattrs.Add("com.apple.macintosh.tags");
return Errno.NoError;
}
if(!filenameToId.TryGetValue(path.ToLowerInvariant(), out uint fileId)) return Errno.NoSuchFile;
if(!idToEntry.TryGetValue(fileId, out MFS_FileEntry entry)) return Errno.NoSuchFile;
if(entry.flRLgLen > 0)
{
xattrs.Add("com.apple.ResourceFork");
if(debug && device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag))
xattrs.Add("com.apple.ResourceFork.tags");
}
2017-12-19 20:33:03 +00:00
if(!ArrayHelpers.ArrayIsNullOrEmpty(entry.flUsrWds)) xattrs.Add("com.apple.FinderInfo");
if(debug && device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag) && entry.flLgLen > 0)
xattrs.Add("com.apple.macintosh.tags");
xattrs.Sort();
return Errno.NoError;
}
public Errno GetXattr(string path, string xattr, ref byte[] buf)
{
2017-12-19 20:33:03 +00:00
if(!mounted) return Errno.AccessDenied;
2017-12-21 14:30:38 +00:00
string[] pathElements = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
2017-12-19 20:33:03 +00:00
if(pathElements.Length != 1) return Errno.NotSupported;
if(debug)
2018-06-22 08:08:38 +01:00
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
string.Compare(path, "$Bitmap", StringComparison.InvariantCulture) == 0 ||
2018-06-22 08:08:38 +01:00
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0)
if(device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag) &&
string.Compare(xattr, "com.apple.macintosh.tags", StringComparison.InvariantCulture) == 0)
{
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0)
{
buf = new byte[directoryTags.Length];
Array.Copy(directoryTags, 0, buf, 0, buf.Length);
return Errno.NoError;
}
if(string.Compare(path, "$Bitmap", StringComparison.InvariantCulture) == 0)
{
buf = new byte[bitmapTags.Length];
Array.Copy(bitmapTags, 0, buf, 0, buf.Length);
return Errno.NoError;
}
if(string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0)
{
buf = new byte[bootTags.Length];
Array.Copy(bootTags, 0, buf, 0, buf.Length);
return Errno.NoError;
}
if(string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0)
{
buf = new byte[mdbTags.Length];
Array.Copy(mdbTags, 0, buf, 0, buf.Length);
return Errno.NoError;
}
}
2018-06-22 08:08:38 +01:00
else
return Errno.NoSuchExtendedAttribute;
Errno error;
if(!filenameToId.TryGetValue(path.ToLowerInvariant(), out uint fileId)) return Errno.NoSuchFile;
if(!idToEntry.TryGetValue(fileId, out MFS_FileEntry entry)) return Errno.NoSuchFile;
2018-06-22 08:08:38 +01:00
if(entry.flRLgLen > 0 &&
2017-12-19 20:33:03 +00:00
string.Compare(xattr, "com.apple.ResourceFork", StringComparison.InvariantCulture) == 0)
{
error = ReadFile(path, out buf, true, false);
return error;
}
2018-06-22 08:08:38 +01:00
if(entry.flRLgLen > 0 &&
2017-12-19 20:33:03 +00:00
string.Compare(xattr, "com.apple.ResourceFork.tags", StringComparison.InvariantCulture) == 0)
{
error = ReadFile(path, out buf, true, true);
return error;
}
2017-12-19 20:33:03 +00:00
if(!ArrayHelpers.ArrayIsNullOrEmpty(entry.flUsrWds) &&
string.Compare(xattr, "com.apple.FinderInfo", StringComparison.InvariantCulture) == 0)
{
buf = new byte[16];
Array.Copy(entry.flUsrWds, 0, buf, 0, 16);
return Errno.NoError;
}
if(!debug || !device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag) ||
string.Compare(xattr, "com.apple.macintosh.tags", StringComparison.InvariantCulture) != 0)
return Errno.NoSuchExtendedAttribute;
error = ReadFile(path, out buf, false, true);
return error;
}
}
2017-12-19 20:33:03 +00:00
}