2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-09-17 21:23:01 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2019-04-06 11:03:43 +01:00
|
|
|
|
// Filename : Info.cs
|
2016-09-17 21:23:01 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2019-04-06 11:03:43 +01:00
|
|
|
|
// Component : FATX filesystem plugin.
|
2016-09-17 21:23:01 +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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2016-09-17 21:23:01 +01:00
|
|
|
|
// ****************************************************************************/
|
2016-09-17 21:25:14 +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;
|
|
|
|
|
|
using Aaru.Helpers;
|
2022-12-15 22:21:07 +00:00
|
|
|
|
using Partition = Aaru.CommonTypes.Partition;
|
2016-09-17 21:25:14 +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 XboxFatPlugin
|
2016-09-17 21:23:01 +01:00
|
|
|
|
{
|
2023-10-03 23:22:08 +01:00
|
|
|
|
#region IReadOnlyFilesystem Members
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2016-09-17 21:23:01 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512)
|
|
|
|
|
|
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);
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return false;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Superblock sb = Marshal.ByteArrayToStructureBigEndian<Superblock>(sector);
|
2016-09-17 21:23:01 +01:00
|
|
|
|
|
2022-03-16 11:47:00 +00:00
|
|
|
|
return sb.magic is FATX_MAGIC or FATX_CIGAM;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2020-02-29 18:03:35 +00: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
|
|
|
|
{
|
|
|
|
|
|
information = "";
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata = new FileSystem();
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512)
|
|
|
|
|
|
return;
|
2019-04-06 12:35:47 +01:00
|
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
|
var bigEndian = true;
|
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-09-17 21:25:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Superblock fatxSb = Marshal.ByteArrayToStructureBigEndian<Superblock>(sector);
|
2019-04-06 12:25:00 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(fatxSb.magic == FATX_CIGAM)
|
|
|
|
|
|
{
|
|
|
|
|
|
fatxSb = Marshal.ByteArrayToStructureLittleEndian<Superblock>(sector);
|
|
|
|
|
|
bigEndian = false;
|
|
|
|
|
|
}
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(fatxSb.magic != FATX_MAGIC)
|
|
|
|
|
|
return;
|
2019-04-06 12:29:20 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
int logicalSectorsPerPhysicalSectors = partition.Offset == 0 && !bigEndian ? 8 : 1;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var sb = new StringBuilder();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendLine(Localization.FATX_filesystem);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization._0_logical_sectors_1_bytes_per_physical_sector, logicalSectorsPerPhysicalSectors,
|
2023-10-04 17:34:40 +01:00
|
|
|
|
logicalSectorsPerPhysicalSectors * imagePlugin.Info.SectorSize).
|
|
|
|
|
|
AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization._0_sectors_1_bytes_per_cluster, fatxSb.sectorsPerCluster,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
fatxSb.sectorsPerCluster * logicalSectorsPerPhysicalSectors * imagePlugin.Info.SectorSize).
|
|
|
|
|
|
AppendLine();
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2023-10-01 04:00:02 +01:00
|
|
|
|
sb.AppendFormat(Localization.Root_directory_starts_at_cluster_0, fatxSb.rootDirectoryCluster).AppendLine();
|
2019-04-06 12:35:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
string volumeLabel = StringHandlers.CToString(fatxSb.volumeLabel,
|
2022-03-07 07:36:44 +00:00
|
|
|
|
bigEndian ? Encoding.BigEndianUnicode : Encoding.Unicode, true);
|
2019-04-06 12:35:47 +01:00
|
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
|
sb.AppendFormat(Localization.Volume_label_0, volumeLabel).AppendLine();
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Volume_serial_0_X8, fatxSb.id).AppendLine();
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
information = sb.ToString();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata = new FileSystem
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
Type = FS_TYPE,
|
2023-10-04 17:34:40 +01:00
|
|
|
|
ClusterSize = (uint)(fatxSb.sectorsPerCluster *
|
|
|
|
|
|
logicalSectorsPerPhysicalSectors *
|
2022-03-06 13:29:38 +00:00
|
|
|
|
imagePlugin.Info.SectorSize),
|
|
|
|
|
|
VolumeName = volumeLabel,
|
|
|
|
|
|
VolumeSerial = $"{fatxSb.id:X8}"
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata.Clusters = (partition.End - partition.Start + 1) * imagePlugin.Info.SectorSize / metadata.ClusterSize;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
}
|
2023-10-03 23:22:08 +01:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2016-09-17 21:25:14 +01:00
|
|
|
|
}
|