Files
Aaru/Aaru.Filesystems/CPM/Xattr.cs

99 lines
3.7 KiB
C#
Raw Normal View History

2017-05-19 20:28:49 +01:00
// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Xattr.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : CP/M filesystem plugin.
//
// --[ Description ] ----------------------------------------------------------
//
// Methods to handle CP/M extended attributes (password).
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
2020-12-31 23:08:23 +00:00
// Copyright © 2011-2021 Natalia Portillo
// ****************************************************************************/
using System;
using System.Collections.Generic;
2021-09-16 04:42:14 +01:00
using Aaru.CommonTypes.Enums;
2020-07-20 15:43:52 +01:00
namespace Aaru.Filesystems
{
2020-07-22 13:20:25 +01:00
public sealed partial class CPM
{
2020-07-20 05:20:18 +01:00
/// <inheritdoc />
2021-09-16 04:42:14 +01:00
public ErrorNumber GetXattr(string path, string xattr, ref byte[] buf)
{
2020-07-20 21:11:32 +01:00
if(!_mounted)
2021-09-16 04:42:14 +01:00
return ErrorNumber.AccessDenied;
2020-02-29 18:03:35 +00:00
string[] pathElements = path.Split(new[]
{
'/'
}, StringSplitOptions.RemoveEmptyEntries);
2020-02-29 18:03:35 +00:00
if(pathElements.Length != 1)
2021-09-16 04:42:14 +01:00
return ErrorNumber.NotSupported;
2020-02-29 18:03:35 +00:00
2020-07-20 21:11:32 +01:00
if(!_fileCache.ContainsKey(pathElements[0].ToUpperInvariant()))
2021-09-16 04:42:14 +01:00
return ErrorNumber.NoSuchFile;
if(string.Compare(xattr, "com.caldera.cpm.password", StringComparison.InvariantCulture) == 0)
2020-07-20 21:11:32 +01:00
if(!_passwordCache.TryGetValue(pathElements[0].ToUpperInvariant(), out buf))
2021-09-16 04:42:14 +01:00
return ErrorNumber.NoError;
if(string.Compare(xattr, "com.caldera.cpm.password.text", StringComparison.InvariantCulture) != 0)
2021-09-16 04:42:14 +01:00
return ErrorNumber.NoSuchExtendedAttribute;
2021-09-16 04:42:14 +01:00
return !_passwordCache.TryGetValue(pathElements[0].ToUpperInvariant(), out buf) ? ErrorNumber.NoError
: ErrorNumber.NoSuchExtendedAttribute;
}
2020-07-20 05:20:18 +01:00
/// <inheritdoc />
2021-09-16 04:42:14 +01:00
public ErrorNumber ListXAttr(string path, out List<string> xattrs)
{
xattrs = null;
2020-07-20 21:11:32 +01:00
if(!_mounted)
2021-09-16 04:42:14 +01:00
return ErrorNumber.AccessDenied;
2020-02-29 18:03:35 +00:00
string[] pathElements = path.Split(new[]
{
'/'
}, StringSplitOptions.RemoveEmptyEntries);
2020-02-29 18:03:35 +00:00
if(pathElements.Length != 1)
2021-09-16 04:42:14 +01:00
return ErrorNumber.NotSupported;
2020-02-29 18:03:35 +00:00
2020-07-20 21:11:32 +01:00
if(!_fileCache.ContainsKey(pathElements[0].ToUpperInvariant()))
2021-09-16 04:42:14 +01:00
return ErrorNumber.NoSuchFile;
xattrs = new List<string>();
2020-02-29 18:03:35 +00:00
2020-07-20 21:11:32 +01:00
if(_passwordCache.ContainsKey(pathElements[0].ToUpperInvariant()))
2020-02-29 18:03:35 +00:00
xattrs.Add("com.caldera.cpm.password");
2020-07-20 21:11:32 +01:00
if(_decodedPasswordCache.ContainsKey(pathElements[0].ToUpperInvariant()))
xattrs.Add("com.caldera.cpm.password.text");
2021-09-16 04:42:14 +01:00
return ErrorNumber.NoError;
}
}
2017-12-19 20:33:03 +00:00
}