Files
Aaru/Aaru.Filesystems/AppleDOS/Info.cs

108 lines
4.3 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 : Info.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-05-01 04:17:32 +01:00
// Copyright © 2011-2024 Natalia Portillo
// ****************************************************************************/
using System.Text;
using Aaru.CommonTypes.AaruMetadata;
using Aaru.CommonTypes.Enums;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
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 bool Identify(IMediaImage imagePlugin, Partition partition)
{
2024-05-01 04:05:22 +01:00
if(imagePlugin.Info.Sectors != 455 && imagePlugin.Info.Sectors != 560) return false;
2024-05-01 04:05:22 +01:00
if(partition.Start > 0 || imagePlugin.Info.SectorSize != 256) return false;
2022-03-06 13:29:38 +00:00
int spt = imagePlugin.Info.Sectors == 455 ? 13 : 16;
2022-03-07 07:36:44 +00:00
ErrorNumber errno = imagePlugin.ReadSector((ulong)(17 * spt), out byte[] vtocB);
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return false;
2022-03-06 13:29:38 +00:00
_vtoc = Marshal.ByteArrayToStructureLittleEndian<Vtoc>(vtocB);
return _vtoc.catalogSector < spt &&
_vtoc.maxTrackSectorPairsPerSector <= 122 &&
_vtoc.sectorsPerTrack == spt &&
_vtoc.bytesPerSector == 256;
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public void GetInformation(IMediaImage imagePlugin, Partition partition, Encoding encoding, out string information,
out FileSystem metadata)
2022-03-06 13:29:38 +00:00
{
information = "";
var sb = new StringBuilder();
metadata = new FileSystem();
2022-03-06 13:29:38 +00:00
int spt = imagePlugin.Info.Sectors == 455 ? 13 : 16;
2022-03-07 07:36:44 +00:00
ErrorNumber errno = imagePlugin.ReadSector((ulong)(17 * spt), out byte[] vtocB);
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return;
2022-03-06 13:29:38 +00:00
_vtoc = Marshal.ByteArrayToStructureLittleEndian<Vtoc>(vtocB);
sb.AppendLine(Localization.AppleDOS_Name);
2022-03-06 13:29:38 +00:00
sb.AppendLine();
2020-02-29 18:03:35 +00:00
2024-05-01 04:05:22 +01:00
sb.AppendFormat(Localization.Catalog_starts_at_sector_0_of_track_1, _vtoc.catalogSector, _vtoc.catalogTrack)
.AppendLine();
2020-02-29 18:03:35 +00:00
sb.AppendFormat(Localization.File_system_initialized_by_DOS_release_0, _vtoc.dosRelease).AppendLine();
sb.AppendFormat(Localization.Disk_volume_number_0, _vtoc.volumeNumber).AppendLine();
sb.AppendFormat(Localization.Sectors_allocated_at_most_in_track_0, _vtoc.lastAllocatedSector).AppendLine();
sb.AppendFormat(Localization._0_tracks_in_volume, _vtoc.tracks).AppendLine();
sb.AppendFormat(Localization._0_sectors_per_track, _vtoc.sectorsPerTrack).AppendLine();
sb.AppendFormat(Localization._0_bytes_per_sector, _vtoc.bytesPerSector).AppendLine();
sb.AppendLine(_vtoc.allocationDirection > 0
? Localization.Track_allocation_is_forward
: Localization.Track_allocation_is_reverse);
2022-03-06 13:29:38 +00:00
information = sb.ToString();
metadata = new FileSystem
2022-03-06 13:29:38 +00:00
{
Bootable = true,
Clusters = imagePlugin.Info.Sectors,
ClusterSize = imagePlugin.Info.SectorSize,
Type = FS_TYPE
2022-03-06 13:29:38 +00:00
};
}
#endregion
2017-12-19 20:33:03 +00:00
}