2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2016-10-07 00:41:59 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Super.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Apple DOS filesystem plugin.
|
|
|
|
|
//
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-12-19 10:45:18 +00:00
|
|
|
// Copyright © 2011-2025 Natalia Portillo
|
2016-10-07 00:41:59 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2017-12-27 23:55:59 +00:00
|
|
|
using System.Collections.Generic;
|
2022-12-15 22:21:07 +00:00
|
|
|
using Aaru.CommonTypes.AaruMetadata;
|
2021-09-16 04:42:14 +01:00
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
using Aaru.CommonTypes.Structs;
|
|
|
|
|
using Aaru.Console;
|
|
|
|
|
using Aaru.Helpers;
|
2020-02-29 18:03:35 +00:00
|
|
|
using Claunia.Encoding;
|
2017-12-26 06:05:12 +00:00
|
|
|
using Encoding = System.Text.Encoding;
|
2022-12-15 22:21:07 +00:00
|
|
|
using Partition = Aaru.CommonTypes.Partition;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public sealed partial class AppleDOS
|
2016-10-07 00:41:59 +01:00
|
|
|
{
|
2023-10-03 23:22:08 +01:00
|
|
|
#region IReadOnlyFilesystem Members
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
2023-10-03 23:22:08 +01:00
|
|
|
public ErrorNumber Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding,
|
|
|
|
|
Dictionary<string, string> options, string @namespace)
|
2016-10-07 00:41:59 +01:00
|
|
|
{
|
2022-12-17 23:17:18 +00:00
|
|
|
_device = imagePlugin;
|
|
|
|
|
_start = partition.Start;
|
|
|
|
|
_encoding = encoding ?? new Apple2();
|
2022-03-06 13:29:38 +00:00
|
|
|
|
2023-10-04 17:34:40 +01:00
|
|
|
if(_device.Info.Sectors != 455 && _device.Info.Sectors != 560)
|
2016-10-07 00:41:59 +01:00
|
|
|
{
|
2023-10-03 17:47:32 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Incorrect_device_size);
|
2017-12-26 08:01:40 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.InOutError;
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(_start > 0)
|
|
|
|
|
{
|
2023-10-03 17:47:32 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Partitions_are_not_supported);
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.InOutError;
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(_device.Info.SectorSize != 256)
|
|
|
|
|
{
|
2023-10-03 17:47:32 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Incorrect_sector_size);
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.InOutError;
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
_sectorsPerTrack = _device.Info.Sectors == 455 ? 13 : 16;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// Read the VTOC
|
|
|
|
|
ErrorNumber error = _device.ReadSector((ulong)(17 * _sectorsPerTrack), out _vtocBlocks);
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(error != ErrorNumber.NoError) return error;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
_vtoc = Marshal.ByteArrayToStructureLittleEndian<Vtoc>(_vtocBlocks);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
_track1UsedByFiles = false;
|
|
|
|
|
_track2UsedByFiles = false;
|
|
|
|
|
_usedSectors = 1;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
error = ReadCatalog();
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(error != ErrorNumber.NoError)
|
|
|
|
|
{
|
2023-10-03 17:47:32 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Unable_to_read_catalog);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return error;
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-12-19 10:45:07 +00:00
|
|
|
_fileSizeCache = new Dictionary<string, int>();
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
error = CacheAllFiles();
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(error != ErrorNumber.NoError)
|
|
|
|
|
{
|
2023-10-03 17:47:32 +01:00
|
|
|
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Unable_cache_all_files);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return error;
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// Create XML metadata for mounted filesystem
|
2022-12-15 22:21:07 +00:00
|
|
|
Metadata = new FileSystem
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2022-12-15 22:21:07 +00:00
|
|
|
Bootable = true,
|
|
|
|
|
Clusters = _device.Info.Sectors,
|
|
|
|
|
ClusterSize = _vtoc.bytesPerSector,
|
|
|
|
|
Files = (ulong)_catalogCache.Count,
|
|
|
|
|
Type = FS_TYPE
|
2022-03-06 13:29:38 +00:00
|
|
|
};
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-12-15 22:21:07 +00:00
|
|
|
Metadata.FreeClusters = Metadata.Clusters - _usedSectors;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
options ??= GetDefaultOptions();
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
if(options.TryGetValue("debug", out string debugString)) bool.TryParse(debugString, out _debug);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
_mounted = true;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber Unmount()
|
|
|
|
|
{
|
|
|
|
|
_mounted = false;
|
|
|
|
|
_extentCache = null;
|
|
|
|
|
_fileCache = null;
|
|
|
|
|
_catalogCache = null;
|
|
|
|
|
_fileSizeCache = null;
|
|
|
|
|
|
|
|
|
|
return ErrorNumber.NoError;
|
|
|
|
|
}
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ErrorNumber StatFs(out FileSystemInfo stat)
|
|
|
|
|
{
|
|
|
|
|
stat = new FileSystemInfo
|
2016-10-07 00:41:59 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
Blocks = _device.Info.Sectors,
|
|
|
|
|
FilenameLength = 30,
|
|
|
|
|
Files = (ulong)_catalogCache.Count,
|
|
|
|
|
PluginId = Id,
|
2022-11-28 02:59:53 +00:00
|
|
|
Type = FS_TYPE
|
2022-03-06 13:29:38 +00:00
|
|
|
};
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
stat.FreeFiles = _totalFileEntries - stat.Files;
|
|
|
|
|
stat.FreeBlocks = stat.Blocks - _usedSectors;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return ErrorNumber.NoError;
|
2016-10-07 00:41:59 +01:00
|
|
|
}
|
2023-10-03 23:22:08 +01:00
|
|
|
|
|
|
|
|
#endregion
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|