2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2016-10-07 00:41:59 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Xattr.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Apple DOS filesystem plugin.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Methods to handle Apple DOS extended attributes (file type).
|
|
|
|
|
//
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2016-10-07 00:41:59 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-09-16 04:42:14 +01:00
|
|
|
using Aaru.CommonTypes.Enums;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public sealed partial class AppleDOS
|
2016-10-07 00:41:59 +01:00
|
|
|
{
|
2023-10-03 23:22:08 +01:00
|
|
|
#region IReadOnlyFilesystem Members
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber ListXAttr(string path, out List<string> xattrs)
|
2016-10-07 00:41:59 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
xattrs = null;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!_mounted)
|
|
|
|
|
return ErrorNumber.AccessDenied;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
string[] pathElements = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(pathElements.Length != 1)
|
|
|
|
|
return ErrorNumber.NotSupported;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
string filename = pathElements[0].ToUpperInvariant();
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(filename.Length > 30)
|
|
|
|
|
return ErrorNumber.NameTooLong;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
xattrs = new List<string>();
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
if(_debug && (string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
2022-03-06 13:29:38 +00:00
|
|
|
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
|
|
|
|
|
string.Compare(path, "$Vtoc", StringComparison.InvariantCulture) == 0)) {}
|
|
|
|
|
else
|
2016-10-07 00:41:59 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!_catalogCache.ContainsKey(filename))
|
|
|
|
|
return ErrorNumber.NoSuchFile;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
xattrs.Add("com.apple.dos.type");
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(_debug)
|
|
|
|
|
xattrs.Add("com.apple.dos.tracksectorlist");
|
|
|
|
|
}
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber GetXattr(string path, string xattr, ref byte[] buf)
|
|
|
|
|
{
|
|
|
|
|
if(!_mounted)
|
|
|
|
|
return ErrorNumber.AccessDenied;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
string[] pathElements = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(pathElements.Length != 1)
|
|
|
|
|
return ErrorNumber.NotSupported;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
string filename = pathElements[0].ToUpperInvariant();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(filename.Length > 30)
|
|
|
|
|
return ErrorNumber.NameTooLong;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
if(_debug && (string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
2022-03-06 13:29:38 +00:00
|
|
|
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
|
|
|
|
|
string.Compare(path, "$Vtoc", StringComparison.InvariantCulture) == 0))
|
|
|
|
|
return ErrorNumber.NoSuchExtendedAttribute;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!_catalogCache.ContainsKey(filename))
|
|
|
|
|
return ErrorNumber.NoSuchFile;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(string.Compare(xattr, "com.apple.dos.type", StringComparison.InvariantCulture) == 0)
|
|
|
|
|
{
|
|
|
|
|
if(!_fileTypeCache.TryGetValue(filename, out byte type))
|
2021-09-16 04:42:14 +01:00
|
|
|
return ErrorNumber.InvalidArgument;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
buf = new byte[1];
|
|
|
|
|
buf[0] = type;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2021-09-16 04:42:14 +01:00
|
|
|
return ErrorNumber.NoError;
|
2016-10-07 00:41:59 +01:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
if(string.Compare(xattr, "com.apple.dos.tracksectorlist", StringComparison.InvariantCulture) != 0 ||
|
|
|
|
|
!_debug)
|
|
|
|
|
return ErrorNumber.NoSuchExtendedAttribute;
|
|
|
|
|
|
|
|
|
|
if(!_extentCache.TryGetValue(filename, out byte[] ts))
|
|
|
|
|
return ErrorNumber.InvalidArgument;
|
|
|
|
|
|
|
|
|
|
buf = new byte[ts.Length];
|
|
|
|
|
Array.Copy(ts, 0, buf, 0, buf.Length);
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
2016-10-07 00:41:59 +01:00
|
|
|
}
|
2023-10-03 23:22:08 +01:00
|
|
|
|
|
|
|
|
#endregion
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|