2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2016-07-31 20:55:58 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Super.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
|
|
|
// Handles mounting and umounting the U.C.S.D. Pascal filesystem.
|
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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2016-07-31 20:55:58 +01:00
|
|
|
// ****************************************************************************/
|
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
|
|
|
using System.Collections.Generic;
|
2017-12-26 06:05:12 +00:00
|
|
|
using Claunia.Encoding;
|
|
|
|
|
using DiscImageChef.CommonTypes;
|
|
|
|
|
using DiscImageChef.DiscImages;
|
2017-12-21 14:30:38 +00:00
|
|
|
using Schemas;
|
2017-12-26 06:05:12 +00:00
|
|
|
using Encoding = System.Text.Encoding;
|
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
|
2017-12-21 16:27:09 +00:00
|
|
|
public partial class PascalPlugin
|
2016-07-31 20:55:58 +01:00
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
public virtual Errno Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding, bool debug)
|
2016-07-31 20:56:53 +01:00
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
device = imagePlugin;
|
|
|
|
|
// TODO: Until Apple ][ encoding is implemented
|
|
|
|
|
currentEncoding = new LisaRoman();
|
2016-07-31 20:56:53 +01:00
|
|
|
this.debug = debug;
|
2017-12-26 06:05:12 +00:00
|
|
|
if(device.Info.Sectors < 3) return Errno.InvalidArgument;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
// Blocks 0 and 1 are boot code
|
|
|
|
|
catalogBlocks = device.ReadSector(2);
|
|
|
|
|
|
|
|
|
|
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
|
|
|
|
|
|
|
|
|
mountedVolEntry.firstBlock = BigEndianBitConverter.ToInt16(catalogBlocks, 0x00);
|
|
|
|
|
mountedVolEntry.lastBlock = BigEndianBitConverter.ToInt16(catalogBlocks, 0x02);
|
|
|
|
|
mountedVolEntry.entryType = (PascalFileKind)BigEndianBitConverter.ToInt16(catalogBlocks, 0x04);
|
|
|
|
|
mountedVolEntry.volumeName = new byte[8];
|
|
|
|
|
Array.Copy(catalogBlocks, 0x06, mountedVolEntry.volumeName, 0, 8);
|
|
|
|
|
mountedVolEntry.blocks = BigEndianBitConverter.ToInt16(catalogBlocks, 0x0E);
|
|
|
|
|
mountedVolEntry.files = BigEndianBitConverter.ToInt16(catalogBlocks, 0x10);
|
|
|
|
|
mountedVolEntry.dummy = BigEndianBitConverter.ToInt16(catalogBlocks, 0x12);
|
|
|
|
|
mountedVolEntry.lastBoot = BigEndianBitConverter.ToInt16(catalogBlocks, 0x14);
|
|
|
|
|
mountedVolEntry.tail = BigEndianBitConverter.ToInt32(catalogBlocks, 0x16);
|
|
|
|
|
|
|
|
|
|
if(mountedVolEntry.firstBlock != 0 || mountedVolEntry.lastBlock <= mountedVolEntry.firstBlock ||
|
2017-12-26 06:05:12 +00:00
|
|
|
(ulong)mountedVolEntry.lastBlock > device.Info.Sectors - 2 ||
|
2017-12-20 17:26:28 +00:00
|
|
|
mountedVolEntry.entryType != PascalFileKind.Volume &&
|
|
|
|
|
mountedVolEntry.entryType != PascalFileKind.Secure || mountedVolEntry.volumeName[0] > 7 ||
|
2017-12-26 06:05:12 +00:00
|
|
|
mountedVolEntry.blocks < 0 || (ulong)mountedVolEntry.blocks != device.Info.Sectors ||
|
2017-12-19 20:33:03 +00:00
|
|
|
mountedVolEntry.files < 0) return Errno.InvalidArgument;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
catalogBlocks = device.ReadSectors(2, (uint)(mountedVolEntry.lastBlock - mountedVolEntry.firstBlock - 2));
|
|
|
|
|
int offset = 26;
|
|
|
|
|
|
|
|
|
|
fileEntries = new List<PascalFileEntry>();
|
|
|
|
|
while(offset + 26 < catalogBlocks.Length)
|
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
PascalFileEntry entry = new PascalFileEntry
|
|
|
|
|
{
|
|
|
|
|
filename = new byte[16],
|
|
|
|
|
firstBlock = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x00),
|
|
|
|
|
lastBlock = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x02),
|
|
|
|
|
entryType = (PascalFileKind)BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x04),
|
|
|
|
|
lastBytes = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x16),
|
|
|
|
|
mtime = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x18)
|
|
|
|
|
};
|
2016-07-31 20:56:53 +01:00
|
|
|
Array.Copy(catalogBlocks, offset + 0x06, entry.filename, 0, 16);
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(entry.filename[0] <= 15 && entry.filename[0] > 0) fileEntries.Add(entry);
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
offset += 26;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bootBlocks = device.ReadSectors(0, 2);
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
xmlFsType = new FileSystemType
|
2017-12-22 08:43:22 +00:00
|
|
|
{
|
|
|
|
|
Bootable = !ArrayHelpers.ArrayIsNullOrEmpty(bootBlocks),
|
|
|
|
|
Clusters = mountedVolEntry.blocks,
|
2017-12-26 06:05:12 +00:00
|
|
|
ClusterSize = (int)device.Info.SectorSize,
|
2017-12-22 08:43:22 +00:00
|
|
|
Files = mountedVolEntry.files,
|
|
|
|
|
FilesSpecified = true,
|
|
|
|
|
Type = "UCSD Pascal",
|
2017-12-26 06:05:12 +00:00
|
|
|
VolumeName = StringHandlers.PascalToString(mountedVolEntry.volumeName, currentEncoding)
|
2017-12-22 08:43:22 +00:00
|
|
|
};
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
mounted = true;
|
|
|
|
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
public virtual Errno Unmount()
|
2016-07-31 20:56:53 +01:00
|
|
|
{
|
|
|
|
|
mounted = false;
|
|
|
|
|
fileEntries = null;
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
public virtual Errno StatFs(ref FileSystemInfo stat)
|
2016-07-31 20:56:53 +01:00
|
|
|
{
|
2017-12-24 02:37:41 +00:00
|
|
|
stat = new FileSystemInfo
|
|
|
|
|
{
|
|
|
|
|
Blocks = mountedVolEntry.blocks,
|
|
|
|
|
FilenameLength = 16,
|
|
|
|
|
Files = (ulong)mountedVolEntry.files,
|
|
|
|
|
FreeBlocks = 0,
|
2017-12-26 06:05:12 +00:00
|
|
|
PluginId = Id,
|
2017-12-24 02:37:41 +00:00
|
|
|
Type = "UCSD Pascal"
|
|
|
|
|
};
|
2016-07-31 20:56:53 +01:00
|
|
|
|
2016-07-31 22:12:48 +01:00
|
|
|
stat.FreeBlocks = mountedVolEntry.blocks - (mountedVolEntry.lastBlock - mountedVolEntry.firstBlock);
|
2017-12-20 17:26:28 +00:00
|
|
|
foreach(PascalFileEntry entry in fileEntries) stat.FreeBlocks -= entry.lastBlock - entry.firstBlock;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
return Errno.NotImplemented;
|
2016-07-31 20:55:58 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|