2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2016-08-26 01:43:15 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : File.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
2016-08-26 01:45:58 +01:00
|
|
|
// Component : CP/M filesystem plugin.
|
2016-08-26 01:43:15 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-08-26 01:45:58 +01:00
|
|
|
// Methods to handle files.
|
2016-08-26 01:43:15 +01:00
|
|
|
//
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2016-08-26 01:43:15 +01:00
|
|
|
// ****************************************************************************/
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2016-08-26 01:43:15 +01:00
|
|
|
using System;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2016-08-26 01:43:15 +01:00
|
|
|
namespace DiscImageChef.Filesystems.CPM
|
|
|
|
|
{
|
2016-08-26 01:45:58 +01:00
|
|
|
partial class CPM : Filesystem
|
2016-08-26 01:43:15 +01:00
|
|
|
{
|
2016-08-26 01:45:58 +01:00
|
|
|
public override Errno GetAttributes(string path, ref FileAttributes attributes)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!mounted) return Errno.AccessDenied;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
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;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
FileEntryInfo fInfo;
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(string.IsNullOrEmpty(pathElements[0]) ||
|
|
|
|
|
string.Compare(pathElements[0], "/", StringComparison.OrdinalIgnoreCase) == 0)
|
2016-08-26 01:45:58 +01:00
|
|
|
{
|
|
|
|
|
attributes = new FileAttributes();
|
|
|
|
|
attributes = FileAttributes.Directory;
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
if(!statCache.TryGetValue(pathElements[0].ToUpperInvariant(), out fInfo)) return Errno.NoSuchFile;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
attributes = fInfo.Attributes;
|
|
|
|
|
return Errno.NoError;
|
2016-08-26 01:45:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Errno MapBlock(string path, long fileBlock, ref long deviceBlock)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!mounted) return Errno.AccessDenied;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// TODO: Implementing this would require storing the interleaving
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Errno Read(string path, long offset, long size, ref byte[] buf)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!mounted) return Errno.AccessDenied;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
if(size == 0)
|
|
|
|
|
{
|
|
|
|
|
buf = new byte[0];
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(offset < 0) return Errno.InvalidArgument;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
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;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
byte[] file;
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!fileCache.TryGetValue(pathElements[0].ToUpperInvariant(), out file)) return Errno.NoSuchFile;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(offset >= file.Length) return Errno.EINVAL;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(size + offset >= file.Length) size = file.Length - offset;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
buf = new byte[size];
|
|
|
|
|
Array.Copy(file, offset, buf, 0, size);
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Errno ReadLink(string path, ref string dest)
|
2016-08-26 01:43:15 +01:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!mounted) return Errno.AccessDenied;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
return Errno.NotSupported;
|
2016-08-26 01:43:15 +01:00
|
|
|
}
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
public override Errno Stat(string path, ref FileEntryInfo stat)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(!mounted) return Errno.AccessDenied;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
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;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
if(string.IsNullOrEmpty(path) || string.Compare(path, "/", StringComparison.OrdinalIgnoreCase) == 0)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(labelCreationDate != null) stat.CreationTime = DateHandlers.CPMToDateTime(labelCreationDate);
|
|
|
|
|
if(labelUpdateDate != null) stat.StatusChangeTime = DateHandlers.CPMToDateTime(labelUpdateDate);
|
2016-08-26 01:45:58 +01:00
|
|
|
stat.Attributes = FileAttributes.Directory;
|
|
|
|
|
stat.BlockSize = xmlFSType.ClusterSize;
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(statCache.TryGetValue(pathElements[0].ToUpperInvariant(), out stat)) return Errno.NoError;
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
return Errno.NoSuchFile;
|
|
|
|
|
}
|
2016-08-26 01:43:15 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|