Files
Aaru/DiscImageChef.Filesystems/FATX/Info.cs

93 lines
3.9 KiB
C#
Raw Normal View History

// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
2019-04-06 11:03:43 +01:00
// Filename : Info.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
2019-04-06 11:03:43 +01:00
// Component : FATX filesystem plugin.
//
// --[ Description ] ----------------------------------------------------------
//
// Identifies the FATX filesystem and shows information.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
2018-12-29 17:34:38 +00:00
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
using System.Text;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Interfaces;
2019-04-06 11:03:43 +01:00
using DiscImageChef.Helpers;
2017-12-21 14:30:38 +00:00
using Schemas;
2019-04-06 11:03:43 +01:00
namespace DiscImageChef.Filesystems.FATX
{
2019-04-06 11:03:43 +01:00
public partial class XboxFatPlugin
{
public bool Identify(IMediaImage imagePlugin, Partition partition)
{
if(imagePlugin.Info.SectorSize < 512) return false;
2017-07-19 16:37:11 +01:00
byte[] sector = imagePlugin.ReadSector(partition.Start);
Superblock sb = Marshal.ByteArrayToStructureBigEndian<Superblock>(sector);
return sb.magic == FATX_MAGIC || sb.magic == FATX_CIGAM;
}
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
2018-06-22 08:08:38 +01:00
Encoding encoding)
{
2018-06-22 08:08:38 +01:00
Encoding = Encoding.UTF8;
information = "";
if(imagePlugin.Info.SectorSize < 512) return;
2017-07-19 16:37:11 +01:00
byte[] sector = imagePlugin.ReadSector(partition.Start);
Superblock fatxSb = Marshal.ByteArrayToStructureBigEndian<Superblock>(sector);
if(fatxSb.magic == FATX_CIGAM) fatxSb = Marshal.ByteArrayToStructureLittleEndian<Superblock>(sector);
if(fatxSb.magic != FATX_MAGIC) return;
int logicalSectorsPerPhysicalSectors = partition.Offset == 0 ? 8 : 1;
StringBuilder sb = new StringBuilder();
sb.AppendLine("FATX filesystem");
sb.AppendFormat("Filesystem id {0}", fatxSb.id).AppendLine();
sb.AppendFormat("{0} logical sectors ({1} bytes) per physical sector", logicalSectorsPerPhysicalSectors,
logicalSectorsPerPhysicalSectors * imagePlugin.Info.SectorSize).AppendLine();
2017-12-19 20:33:03 +00:00
sb.AppendFormat("{0} sectors ({1} bytes) per cluster", fatxSb.sectorsPerCluster,
fatxSb.sectorsPerCluster * logicalSectorsPerPhysicalSectors * imagePlugin.Info.SectorSize)
.AppendLine();
sb.AppendFormat("Root directory starts on cluster {0}", fatxSb.rootDirectoryCluster).AppendLine();
information = sb.ToString();
2017-12-26 08:01:40 +00:00
XmlFsType = new FileSystemType
{
2018-06-22 08:08:38 +01:00
Type = "FATX filesystem",
ClusterSize = (int)(fatxSb.sectorsPerCluster * imagePlugin.Info.SectorSize)
};
2017-12-26 08:01:40 +00:00
XmlFsType.Clusters = (long)((partition.End - partition.Start + 1) * imagePlugin.Info.SectorSize /
(ulong)XmlFsType.ClusterSize);
}
}
}