2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2016-07-31 20:55:58 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// 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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:30 +00:00
|
|
|
// Copyright © 2011-2020 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;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
using Aaru.CommonTypes.Structs;
|
2020-07-20 15:43:52 +01:00
|
|
|
using Aaru.Helpers;
|
2020-02-29 18:03:35 +00:00
|
|
|
using Claunia.Encoding;
|
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
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
namespace Aaru.Filesystems.UCSDPascal
|
2016-07-31 20:55:58 +01:00
|
|
|
{
|
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
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
public Errno Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding,
|
|
|
|
|
Dictionary<string, string> options, string @namespace)
|
2016-07-31 20:56:53 +01:00
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
device = imagePlugin;
|
|
|
|
|
Encoding = encoding ?? new Apple2();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
if(options == null)
|
|
|
|
|
options = GetDefaultOptions();
|
|
|
|
|
|
|
|
|
|
if(options.TryGetValue("debug", out string debugString))
|
|
|
|
|
bool.TryParse(debugString, out debug);
|
|
|
|
|
|
|
|
|
|
if(device.Info.Sectors < 3)
|
|
|
|
|
return Errno.InvalidArgument;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
2018-01-06 00:41:14 +00:00
|
|
|
multiplier = (uint)(imagePlugin.Info.SectorSize == 256 ? 2 : 1);
|
|
|
|
|
|
2016-07-31 20:56:53 +01:00
|
|
|
// Blocks 0 and 1 are boot code
|
2018-01-06 00:41:14 +00:00
|
|
|
catalogBlocks = device.ReadSectors(multiplier * 2, multiplier);
|
|
|
|
|
|
|
|
|
|
// On Apple //, it's little endian
|
2019-05-11 20:49:32 +01:00
|
|
|
// TODO: Fix
|
|
|
|
|
//BigEndianBitConverter.IsLittleEndian =
|
|
|
|
|
// multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian;
|
2018-01-06 00:41:14 +00:00
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
mountedVolEntry.FirstBlock = BigEndianBitConverter.ToInt16(catalogBlocks, 0x00);
|
|
|
|
|
mountedVolEntry.LastBlock = BigEndianBitConverter.ToInt16(catalogBlocks, 0x02);
|
2018-01-06 00:41:14 +00:00
|
|
|
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);
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
if(mountedVolEntry.FirstBlock != 0 ||
|
|
|
|
|
mountedVolEntry.LastBlock <= mountedVolEntry.FirstBlock ||
|
|
|
|
|
(ulong)mountedVolEntry.LastBlock > (device.Info.Sectors / multiplier) - 2 ||
|
|
|
|
|
(mountedVolEntry.EntryType != PascalFileKind.Volume &&
|
|
|
|
|
mountedVolEntry.EntryType != PascalFileKind.Secure) ||
|
|
|
|
|
mountedVolEntry.VolumeName[0] > 7 ||
|
|
|
|
|
mountedVolEntry.Blocks < 0 ||
|
|
|
|
|
(ulong)mountedVolEntry.Blocks != device.Info.Sectors / multiplier ||
|
|
|
|
|
mountedVolEntry.Files < 0)
|
2018-06-22 08:08:38 +01:00
|
|
|
return Errno.InvalidArgument;
|
2018-01-06 00:41:14 +00:00
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
catalogBlocks = device.ReadSectors(multiplier * 2,
|
2018-01-06 00:41:14 +00:00
|
|
|
(uint)(mountedVolEntry.LastBlock - mountedVolEntry.FirstBlock - 2) *
|
|
|
|
|
multiplier);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2018-01-06 00:41:14 +00:00
|
|
|
int offset = 26;
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
fileEntries = new List<PascalFileEntry>();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2016-07-31 20:56:53 +01:00
|
|
|
while(offset + 26 < catalogBlocks.Length)
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
var entry = new PascalFileEntry
|
2017-12-22 08:43:22 +00:00
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
Filename = new byte[16],
|
|
|
|
|
FirstBlock = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x00),
|
|
|
|
|
LastBlock = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x02),
|
2018-01-06 00:41:14 +00:00
|
|
|
EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x04),
|
2018-06-22 08:08:38 +01:00
|
|
|
LastBytes = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x16),
|
|
|
|
|
ModificationTime = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x18)
|
2017-12-22 08:43:22 +00:00
|
|
|
};
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2018-01-06 00:41:14 +00:00
|
|
|
Array.Copy(catalogBlocks, offset + 0x06, entry.Filename, 0, 16);
|
2016-07-31 20:56:53 +01:00
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
if(entry.Filename[0] <= 15 &&
|
|
|
|
|
entry.Filename[0] > 0)
|
|
|
|
|
fileEntries.Add(entry);
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
offset += 26;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-06 00:41:14 +00:00
|
|
|
bootBlocks = device.ReadSectors(0, 2 * multiplier);
|
2016-07-31 20:56:53 +01:00
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
XmlFsType = new FileSystemType
|
2017-12-22 08:43:22 +00:00
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
Bootable = !ArrayHelpers.ArrayIsNullOrEmpty(bootBlocks),
|
|
|
|
|
Clusters = (ulong)mountedVolEntry.Blocks,
|
|
|
|
|
ClusterSize = device.Info.SectorSize,
|
|
|
|
|
Files = (ulong)mountedVolEntry.Files,
|
2017-12-22 08:43:22 +00:00
|
|
|
FilesSpecified = true,
|
2017-12-27 23:55:59 +00:00
|
|
|
Type = "UCSD Pascal",
|
2020-07-20 04:34:16 +01:00
|
|
|
VolumeName = StringHandlers.PascalToString(mountedVolEntry.VolumeName, Encoding)
|
2017-12-22 08:43:22 +00:00
|
|
|
};
|
2016-07-31 20:56:53 +01:00
|
|
|
|
|
|
|
|
mounted = true;
|
|
|
|
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
public Errno Unmount()
|
2016-07-31 20:56:53 +01:00
|
|
|
{
|
2017-12-27 23:55:59 +00:00
|
|
|
mounted = false;
|
2016-07-31 20:56:53 +01:00
|
|
|
fileEntries = null;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2016-07-31 20:56:53 +01:00
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 08:17:28 +00:00
|
|
|
public Errno StatFs(out FileSystemInfo stat)
|
2016-07-31 20:56:53 +01:00
|
|
|
{
|
2017-12-24 02:37:41 +00:00
|
|
|
stat = new FileSystemInfo
|
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
Blocks = (ulong)mountedVolEntry.Blocks,
|
|
|
|
|
FilenameLength = 16,
|
|
|
|
|
Files = (ulong)mountedVolEntry.Files,
|
|
|
|
|
FreeBlocks = 0,
|
|
|
|
|
PluginId = Id,
|
|
|
|
|
Type = "UCSD Pascal"
|
2017-12-24 02:37:41 +00:00
|
|
|
};
|
2016-07-31 20:56:53 +01:00
|
|
|
|
2019-04-23 01:38:33 +01:00
|
|
|
stat.FreeBlocks =
|
|
|
|
|
(ulong)(mountedVolEntry.Blocks - (mountedVolEntry.LastBlock - mountedVolEntry.FirstBlock));
|
2017-12-27 23:55:59 +00:00
|
|
|
|
2019-04-23 01:38:33 +01:00
|
|
|
foreach(PascalFileEntry entry in fileEntries)
|
|
|
|
|
stat.FreeBlocks -= (ulong)(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
|
|
|
}
|