Files
Aaru/Aaru.Filesystems/AppleDOS/Super.cs

160 lines
4.9 KiB
C#
Raw Normal View History

2017-05-19 20:28:49 +01:00
// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// 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
// ****************************************************************************/
using System.Collections.Generic;
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.Helpers;
using Aaru.Logging;
2020-02-29 18:03:35 +00:00
using Claunia.Encoding;
using Encoding = System.Text.Encoding;
2025-08-14 15:51:32 +01:00
using FileSystemInfo = Aaru.CommonTypes.Structs.FileSystemInfo;
using Partition = Aaru.CommonTypes.Partition;
namespace Aaru.Filesystems;
2022-03-06 13:29:38 +00:00
public sealed partial class AppleDOS
{
#region IReadOnlyFilesystem Members
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public ErrorNumber Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding,
Dictionary<string, string> options, string @namespace)
{
_device = imagePlugin;
_start = partition.Start;
_encoding = encoding ?? new Apple2();
2022-03-06 13:29:38 +00:00
if(_device.Info.Sectors != 455 && _device.Info.Sectors != 560)
{
2025-08-17 06:11:22 +01:00
AaruLogging.Debug(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)
{
2025-08-17 06:11:22 +01:00
AaruLogging.Debug(MODULE_NAME, Localization.Partitions_are_not_supported);
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)
{
2025-08-17 06:11:22 +01:00
AaruLogging.Debug(MODULE_NAME, Localization.Incorrect_sector_size);
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;
2022-03-06 13:29:38 +00:00
// Read the VTOC
ErrorNumber error = _device.ReadSector((ulong)(17 * _sectorsPerTrack), false, out _vtocBlocks, out _);
2024-05-01 04:05:22 +01:00
if(error != ErrorNumber.NoError) return error;
2022-03-06 13:29:38 +00:00
_vtoc = Marshal.ByteArrayToStructureLittleEndian<Vtoc>(_vtocBlocks);
2022-03-06 13:29:38 +00:00
_track1UsedByFiles = false;
_track2UsedByFiles = false;
_usedSectors = 1;
2022-03-06 13:29:38 +00:00
error = ReadCatalog();
2022-03-06 13:29:38 +00:00
if(error != ErrorNumber.NoError)
{
2025-08-17 06:11:22 +01:00
AaruLogging.Debug(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();
2022-03-06 13:29:38 +00:00
if(error != ErrorNumber.NoError)
{
2025-08-17 06:11:22 +01:00
AaruLogging.Debug(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
Metadata = new FileSystem
2022-03-06 13:29:38 +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
};
Metadata.FreeClusters = Metadata.Clusters - _usedSectors;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
options ??= GetDefaultOptions();
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;
}
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public ErrorNumber StatFs(out FileSystemInfo stat)
{
stat = new FileSystemInfo
{
2022-03-06 13:29:38 +00:00
Blocks = _device.Info.Sectors,
FilenameLength = 30,
Files = (ulong)_catalogCache.Count,
PluginId = Id,
Type = FS_TYPE
2022-03-06 13:29:38 +00:00
};
2022-03-06 13:29:38 +00:00
stat.FreeFiles = _totalFileEntries - stat.Files;
stat.FreeBlocks = stat.Blocks - _usedSectors;
2022-03-06 13:29:38 +00:00
return ErrorNumber.NoError;
}
#endregion
2017-12-19 20:33:03 +00:00
}