2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-06-22 05:01:13 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2022-12-07 13:07:31 +00:00
|
|
|
|
// Filename : Info.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2016-06-22 05:01:13 +01:00
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Component : Apple filesystem plugin.
|
2016-06-22 05:01:13 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// 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
|
2016-06-22 05:01:13 +01:00
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// 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.
|
2016-06-22 05:01:13 +01:00
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// 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/>.
|
2016-06-22 05:01:13 +01:00
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-05-01 04:17:32 +01:00
|
|
|
|
// Copyright © 2011-2024 Natalia Portillo
|
2016-06-22 05:01:13 +01:00
|
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
|
2020-07-20 07:47:12 +01:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2016-06-22 05:01:13 +01:00
|
|
|
|
using System.Text;
|
2022-12-15 22:21:07 +00:00
|
|
|
|
using Aaru.CommonTypes.AaruMetadata;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2022-12-07 13:07:31 +00:00
|
|
|
|
using Aaru.Helpers;
|
2022-12-15 22:21:07 +00:00
|
|
|
|
using Partition = Aaru.CommonTypes.Partition;
|
2016-06-22 05:01:13 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
/// <summary>Implements detection of the Apple File System (APFS)</summary>
|
|
|
|
|
|
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
2022-12-07 13:07:31 +00:00
|
|
|
|
public sealed partial class APFS
|
2016-06-22 05:01:13 +01:00
|
|
|
|
{
|
2023-10-03 23:22:08 +01:00
|
|
|
|
#region IFilesystem 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(partition.Start >= partition.End) return false;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(partition.Start, out byte[] sector);
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(errno != ErrorNumber.NoError) return false;
|
2016-06-22 05:01:13 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ContainerSuperBlock nxSb;
|
2016-06-22 05:01:13 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
nxSb = Marshal.ByteArrayToStructureLittleEndian<ContainerSuperBlock>(sector);
|
2016-06-22 05:01:13 +01:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
catch
|
2016-06-22 05:01:13 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2016-06-22 05:01:13 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return nxSb.magic == APFS_CONTAINER_MAGIC;
|
|
|
|
|
|
}
|
2016-06-22 05:01:13 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
2022-12-17 22:41:56 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, Encoding encoding, out string information,
|
|
|
|
|
|
out FileSystem metadata)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
var sbInformation = new StringBuilder();
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata = new FileSystem();
|
2022-03-06 13:29:38 +00:00
|
|
|
|
information = "";
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(partition.Start >= partition.End) return;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(partition.Start, out byte[] sector);
|
2016-06-22 05:01:13 +01:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(errno != ErrorNumber.NoError) return;
|
2016-06-22 05:01:13 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ContainerSuperBlock nxSb;
|
2016-06-22 05:01:13 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
nxSb = Marshal.ByteArrayToStructureLittleEndian<ContainerSuperBlock>(sector);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2024-05-01 04:05:22 +01:00
|
|
|
|
if(nxSb.magic != APFS_CONTAINER_MAGIC) return;
|
2016-06-22 05:01:13 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sbInformation.AppendLine(Localization.Apple_File_System);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
sbInformation.AppendLine();
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sbInformation.AppendFormat(Localization._0_bytes_per_block, nxSb.blockSize).AppendLine();
|
2016-06-22 05:01:13 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sbInformation.AppendFormat(Localization.Container_has_0_bytes_in_1_blocks,
|
2024-05-01 04:05:22 +01:00
|
|
|
|
nxSb.containerBlocks * nxSb.blockSize,
|
|
|
|
|
|
nxSb.containerBlocks)
|
|
|
|
|
|
.AppendLine();
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
information = sbInformation.ToString();
|
2016-07-21 17:16:08 +01:00
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata = new FileSystem
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Bootable = false,
|
|
|
|
|
|
Clusters = nxSb.containerBlocks,
|
|
|
|
|
|
ClusterSize = nxSb.blockSize,
|
2022-11-28 02:59:53 +00:00
|
|
|
|
Type = FS_TYPE
|
2022-03-06 13:29:38 +00:00
|
|
|
|
};
|
|
|
|
|
|
}
|
2023-10-03 23:22:08 +01:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|