2016-07-31 20:55:58 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : File.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2016-07-31 20:56:53 +01:00
|
|
|
|
// Component : U.C.S.D. Pascal filesystem plugin.
|
2016-07-31 20:55:58 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2016-07-31 20:56:53 +01:00
|
|
|
|
// Methods to handle files.
|
2016-07-31 20:55:58 +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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
// Copyright © 2011-2016 Natalia Portillo
|
|
|
|
|
|
// ****************************************************************************/
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
2016-07-31 20:55:58 +01:00
|
|
|
|
using System;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
2016-07-31 20:55:58 +01:00
|
|
|
|
namespace DiscImageChef.Filesystems.UCSDPascal
|
|
|
|
|
|
{
|
2016-07-31 20:56:53 +01:00
|
|
|
|
// Information from Call-A.P.P.L.E. Pascal Disk Directory Structure
|
|
|
|
|
|
public partial class PascalPlugin : Filesystem
|
2016-07-31 20:55:58 +01:00
|
|
|
|
{
|
2016-07-31 20:56:53 +01:00
|
|
|
|
public override Errno MapBlock(string path, long fileBlock, ref long deviceBlock)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!mounted)
|
|
|
|
|
|
return Errno.AccessDenied;
|
|
|
|
|
|
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno GetAttributes(string path, ref FileAttributes attributes)
|
2016-07-31 20:55:58 +01:00
|
|
|
|
{
|
2016-07-31 20:56:53 +01:00
|
|
|
|
if(!mounted)
|
|
|
|
|
|
return Errno.AccessDenied;
|
|
|
|
|
|
|
|
|
|
|
|
string[] pathElements = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
|
if(pathElements.Length != 1)
|
|
|
|
|
|
return Errno.NotSupported;
|
|
|
|
|
|
|
|
|
|
|
|
PascalFileEntry entry;
|
|
|
|
|
|
Errno error = GetFileEntry(path, out entry);
|
|
|
|
|
|
|
|
|
|
|
|
if(error == Errno.NoError)
|
|
|
|
|
|
{
|
|
|
|
|
|
attributes = new FileAttributes();
|
|
|
|
|
|
attributes = FileAttributes.File;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno Read(string path, long offset, long size, ref byte[] buf)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!mounted)
|
|
|
|
|
|
return Errno.AccessDenied;
|
|
|
|
|
|
|
|
|
|
|
|
string[] pathElements = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
|
if(pathElements.Length != 1)
|
|
|
|
|
|
return Errno.NotSupported;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] file;
|
|
|
|
|
|
Errno error;
|
|
|
|
|
|
|
|
|
|
|
|
if(debug &&
|
|
|
|
|
|
(string.Compare(path, "$", StringComparison.InvariantCulture) == 0
|
|
|
|
|
|
|| string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0))
|
|
|
|
|
|
{
|
|
|
|
|
|
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0)
|
|
|
|
|
|
file = catalogBlocks;
|
|
|
|
|
|
else
|
|
|
|
|
|
file = bootBlocks;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
PascalFileEntry entry;
|
|
|
|
|
|
error = GetFileEntry(path, out entry);
|
|
|
|
|
|
|
|
|
|
|
|
if(error != Errno.NoError)
|
|
|
|
|
|
return error;
|
|
|
|
|
|
|
2016-07-31 22:12:48 +01:00
|
|
|
|
byte[] tmp = device.ReadSectors((ulong)entry.firstBlock, (uint)(entry.lastBlock - entry.firstBlock));
|
|
|
|
|
|
file = new byte[(entry.lastBlock - entry.firstBlock - 1) * device.GetSectorSize() + entry.lastBytes];
|
2016-07-31 20:56:53 +01:00
|
|
|
|
Array.Copy(tmp, 0, file, 0, file.Length);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-31 22:12:48 +01:00
|
|
|
|
if(offset >= file.Length)
|
|
|
|
|
|
return Errno.EINVAL;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
2016-07-31 22:12:48 +01:00
|
|
|
|
if(size + offset >= file.Length)
|
2016-07-31 20:56:53 +01:00
|
|
|
|
size = file.Length - offset;
|
|
|
|
|
|
|
|
|
|
|
|
buf = new byte[size];
|
|
|
|
|
|
|
|
|
|
|
|
Array.Copy(file, offset, buf, 0, size);
|
|
|
|
|
|
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno Stat(string path, ref FileEntryInfo stat)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!mounted)
|
|
|
|
|
|
return Errno.AccessDenied;
|
|
|
|
|
|
|
|
|
|
|
|
if(!mounted)
|
|
|
|
|
|
return Errno.AccessDenied;
|
|
|
|
|
|
|
|
|
|
|
|
string[] pathElements = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
|
if(pathElements.Length != 1)
|
|
|
|
|
|
return Errno.NotSupported;
|
|
|
|
|
|
|
2016-07-31 22:12:48 +01:00
|
|
|
|
if(debug)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
|
|
|
|
|
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
stat = new FileEntryInfo();
|
|
|
|
|
|
stat.Attributes = new FileAttributes();
|
|
|
|
|
|
stat.Attributes = FileAttributes.System;
|
|
|
|
|
|
stat.BlockSize = device.GetSectorSize();
|
|
|
|
|
|
stat.DeviceNo = 0;
|
|
|
|
|
|
stat.GID = 0;
|
|
|
|
|
|
stat.Inode = 0;
|
|
|
|
|
|
stat.Links = 1;
|
|
|
|
|
|
stat.Mode = 0x124;
|
|
|
|
|
|
stat.UID = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
stat.Blocks = catalogBlocks.Length / stat.BlockSize;
|
|
|
|
|
|
stat.Length = catalogBlocks.Length;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
stat.Blocks = bootBlocks.Length / stat.BlockSize;
|
|
|
|
|
|
stat.Length = bootBlocks.Length;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-31 20:56:53 +01:00
|
|
|
|
PascalFileEntry entry;
|
|
|
|
|
|
Errno error = GetFileEntry(path, out entry);
|
|
|
|
|
|
|
|
|
|
|
|
if(error != Errno.NoError)
|
|
|
|
|
|
return error;
|
|
|
|
|
|
|
|
|
|
|
|
stat = new FileEntryInfo();
|
|
|
|
|
|
stat.Attributes = new FileAttributes();
|
|
|
|
|
|
stat.Attributes = FileAttributes.File;
|
2016-07-31 22:12:48 +01:00
|
|
|
|
stat.Blocks = entry.lastBlock - entry.firstBlock;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
stat.BlockSize = device.GetSectorSize();
|
|
|
|
|
|
stat.DeviceNo = 0;
|
|
|
|
|
|
stat.GID = 0;
|
|
|
|
|
|
stat.Inode = 0;
|
|
|
|
|
|
stat.LastWriteTimeUtc = DateHandlers.UCSDPascalToDateTime(entry.mtime);
|
|
|
|
|
|
stat.Length = (entry.lastBlock - entry.firstBlock) * device.GetSectorSize() + entry.lastBytes;
|
|
|
|
|
|
stat.Links = 1;
|
|
|
|
|
|
stat.Mode = 0x124;
|
|
|
|
|
|
stat.UID = 0;
|
|
|
|
|
|
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Errno GetFileEntry(string path, out PascalFileEntry entry)
|
|
|
|
|
|
{
|
|
|
|
|
|
entry = new PascalFileEntry();
|
|
|
|
|
|
|
|
|
|
|
|
foreach(PascalFileEntry ent in fileEntries)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(string.Compare(path, StringHandlers.PascalToString(ent.filename), StringComparison.InvariantCultureIgnoreCase) == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
entry = ent;
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Errno.NoSuchFile;
|
2016-07-31 20:55:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|