2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2016-09-17 21:23:01 +01:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : FATX.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : FATX filesystem plugin
|
2016-09-17 21:23:01 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2016-09-17 21:25:14 +01:00
|
|
|
|
// Identifies the FATX filesystem and shows information.
|
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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-12-29 17:34:38 +00:00
|
|
|
|
// Copyright © 2011-2019 Natalia Portillo
|
2016-09-17 21:23:01 +01:00
|
|
|
|
// ****************************************************************************/
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2016-09-17 21:23:01 +01:00
|
|
|
|
using System;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2018-06-25 19:08:16 +01:00
|
|
|
|
using DiscImageChef.CommonTypes.Interfaces;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using Schemas;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2016-09-17 21:23:01 +01:00
|
|
|
|
namespace DiscImageChef.Filesystems
|
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class FATX : IFilesystem
|
2016-09-17 21:23:01 +01:00
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
const uint FATX_MAGIC = 0x58544146;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public FileSystemType XmlFsType { get; private set; }
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public Encoding Encoding { get; private set; }
|
|
|
|
|
|
public string Name => "FATX Filesystem Plugin";
|
|
|
|
|
|
public Guid Id => new Guid("ED27A721-4A17-4649-89FD-33633B46E228");
|
2018-08-29 22:15:43 +01:00
|
|
|
|
public string Author => "Natalia Portillo";
|
2017-10-12 23:54:02 +01:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2016-09-17 21:25:14 +01:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512) return false;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSector(partition.Start);
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
|
FATX_Superblock fatxSb = BigEndianMarshal.ByteArrayToStructureBigEndian<FATX_Superblock>(sector);
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
return fatxSb.magic == FATX_MAGIC;
|
2016-09-17 21:23:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Encoding encoding)
|
2016-09-17 21:25:14 +01:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Encoding = Encoding.UTF8;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
information = "";
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512) return;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSector(partition.Start);
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2018-06-20 22:22:21 +01:00
|
|
|
|
FATX_Superblock fatxSb = BigEndianMarshal.ByteArrayToStructureBigEndian<FATX_Superblock>(sector);
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(fatxSb.magic != FATX_MAGIC) return;
|
2016-09-17 21:25:14 +01:00
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
sb.AppendLine("FATX filesystem");
|
|
|
|
|
|
sb.AppendFormat("Filesystem id {0}", fatxSb.id).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sb.AppendFormat("{0} sectors ({1} bytes) per cluster", fatxSb.sectorsPerCluster,
|
2017-12-26 06:05:12 +00:00
|
|
|
|
fatxSb.sectorsPerCluster * imagePlugin.Info.SectorSize).AppendLine();
|
2016-09-17 21:25:14 +01:00
|
|
|
|
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
|
2017-12-22 08:43:22 +00:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Type = "FATX filesystem",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
ClusterSize = (int)(fatxSb.sectorsPerCluster * imagePlugin.Info.SectorSize)
|
2017-12-22 08:43:22 +00:00
|
|
|
|
};
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType.Clusters = (long)((partition.End - partition.Start + 1) * imagePlugin.Info.SectorSize /
|
|
|
|
|
|
(ulong)XmlFsType.ClusterSize);
|
2016-09-17 21:25:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct FATX_Superblock
|
|
|
|
|
|
{
|
|
|
|
|
|
public uint magic;
|
|
|
|
|
|
public uint id;
|
|
|
|
|
|
public uint sectorsPerCluster;
|
|
|
|
|
|
public uint rootDirectoryCluster;
|
|
|
|
|
|
}
|
2016-09-17 21:25:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|