From 1511422a9548bf214ca0ca05ec570232204ae1b7 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 6 Apr 2019 11:03:43 +0100 Subject: [PATCH] Add FATX IReadOnlyFilesystem skeleton. --- .../.idea/contentModel.xml | 10 ++- .../DiscImageChef.Filesystems.csproj | 8 ++- DiscImageChef.Filesystems/FATX/Consts.cs | 54 ++++++++++++++ DiscImageChef.Filesystems/FATX/Dir.cs | 43 ++++++++++++ DiscImageChef.Filesystems/FATX/FATX.cs | 70 +++++++++++++++++++ DiscImageChef.Filesystems/FATX/File.cs | 48 +++++++++++++ .../{FATX.cs => FATX/Info.cs} | 59 ++-------------- DiscImageChef.Filesystems/FATX/Structs.cs | 66 +++++++++++++++++ DiscImageChef.Filesystems/FATX/Super.cs | 52 ++++++++++++++ 9 files changed, 354 insertions(+), 56 deletions(-) create mode 100644 DiscImageChef.Filesystems/FATX/Consts.cs create mode 100644 DiscImageChef.Filesystems/FATX/Dir.cs create mode 100644 DiscImageChef.Filesystems/FATX/FATX.cs create mode 100644 DiscImageChef.Filesystems/FATX/File.cs rename DiscImageChef.Filesystems/{FATX.cs => FATX/Info.cs} (63%) create mode 100644 DiscImageChef.Filesystems/FATX/Structs.cs create mode 100644 DiscImageChef.Filesystems/FATX/Super.cs diff --git a/.idea/.idea.DiscImageChef/.idea/contentModel.xml b/.idea/.idea.DiscImageChef/.idea/contentModel.xml index 4e5dcf06c..1539911a3 100644 --- a/.idea/.idea.DiscImageChef/.idea/contentModel.xml +++ b/.idea/.idea.DiscImageChef/.idea/contentModel.xml @@ -1246,7 +1246,15 @@ - + + + + + + + + + diff --git a/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj b/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj index 9bbe96bc6..3b21fd63f 100644 --- a/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj +++ b/DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj @@ -53,6 +53,13 @@ + + + + + + + @@ -131,7 +138,6 @@ - diff --git a/DiscImageChef.Filesystems/FATX/Consts.cs b/DiscImageChef.Filesystems/FATX/Consts.cs new file mode 100644 index 000000000..0efb42b52 --- /dev/null +++ b/DiscImageChef.Filesystems/FATX/Consts.cs @@ -0,0 +1,54 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Consts.cs +// Author(s) : Natalia Portillo +// +// Component : FATX filesystem plugin. +// +// --[ Description ] ---------------------------------------------------------- +// +// FATX filesystem constants. +// +// --[ 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; + +namespace DiscImageChef.Filesystems.FATX +{ + public partial class XboxFatPlugin + { + const uint FATX_MAGIC = 0x58544146; + const byte UNUSED_DIRENTRY = 0x00; + const byte DELETED_DIRENTRY = 0xE5; + const byte MAX_FILENAME = 42; + + [Flags] + enum Attributes : byte + { + ReadOnly = 0x01, + Hidden = 0x02, + System = 0x04, + Directory = 0x10, + Archive = 0x20 + } + } +} \ No newline at end of file diff --git a/DiscImageChef.Filesystems/FATX/Dir.cs b/DiscImageChef.Filesystems/FATX/Dir.cs new file mode 100644 index 000000000..fecaac0c0 --- /dev/null +++ b/DiscImageChef.Filesystems/FATX/Dir.cs @@ -0,0 +1,43 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Dir.cs +// Author(s) : Natalia Portillo +// +// Component : FATX filesystem plugin. +// +// --[ Description ] ---------------------------------------------------------- +// +// Methods to show the FATX directories. +// +// --[ 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using DiscImageChef.CommonTypes.Structs; + +namespace DiscImageChef.Filesystems.FATX +{ + public partial class XboxFatPlugin + { + public Errno ReadDir(string path, out List contents) => throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/DiscImageChef.Filesystems/FATX/FATX.cs b/DiscImageChef.Filesystems/FATX/FATX.cs new file mode 100644 index 000000000..680b3bad7 --- /dev/null +++ b/DiscImageChef.Filesystems/FATX/FATX.cs @@ -0,0 +1,70 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : FATX.cs +// Author(s) : Natalia Portillo +// +// Component : FATX filesystem plugin +// +// --[ Description ] ---------------------------------------------------------- +// +// Constructors and common variables for the FATX 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.CommonTypes.Structs; +using Schemas; + +namespace DiscImageChef.Filesystems.FATX +{ + public partial class XboxFatPlugin : IReadOnlyFilesystem + { + public FileSystemType XmlFsType { get; private set; } + public Encoding Encoding { get; private set; } + public string Name => "FATX Filesystem Plugin"; + public Guid Id => new Guid("ED27A721-4A17-4649-89FD-33633B46E228"); + public string Author => "Natalia Portillo"; + + public Errno ListXAttr(string path, out List xattrs) + { + xattrs = null; + return Errno.NotSupported; + } + + public Errno GetXattr(string path, string xattr, ref byte[] buf) => Errno.NotSupported; + + public Errno ReadLink(string path, out string dest) + { + dest = null; + return Errno.NotSupported; + } + + public IEnumerable<(string name, Type type, string description)> SupportedOptions => + new (string name, Type type, string description)[] { }; + + static Dictionary GetDefaultOptions() => + new Dictionary {{"debug", false.ToString()}}; + } +} \ No newline at end of file diff --git a/DiscImageChef.Filesystems/FATX/File.cs b/DiscImageChef.Filesystems/FATX/File.cs new file mode 100644 index 000000000..9c05a7b19 --- /dev/null +++ b/DiscImageChef.Filesystems/FATX/File.cs @@ -0,0 +1,48 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : File.cs +// Author(s) : Natalia Portillo +// +// Component : FATX filesystem plugin. +// +// --[ Description ] ---------------------------------------------------------- +// +// Methods to handle files. +// +// --[ 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using DiscImageChef.CommonTypes.Structs; + +namespace DiscImageChef.Filesystems.FATX +{ + public partial class XboxFatPlugin + { + public Errno MapBlock(string path, long fileBlock, out long deviceBlock) => throw new NotImplementedException(); + + public Errno GetAttributes(string path, out FileAttributes attributes) => throw new NotImplementedException(); + + public Errno Read(string path, long offset, long size, ref byte[] buf) => throw new NotImplementedException(); + + public Errno Stat(string path, out FileEntryInfo stat) => throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/DiscImageChef.Filesystems/FATX.cs b/DiscImageChef.Filesystems/FATX/Info.cs similarity index 63% rename from DiscImageChef.Filesystems/FATX.cs rename to DiscImageChef.Filesystems/FATX/Info.cs index 952c86677..cecf19e82 100644 --- a/DiscImageChef.Filesystems/FATX.cs +++ b/DiscImageChef.Filesystems/FATX/Info.cs @@ -2,10 +2,10 @@ // The Disc Image Chef // ---------------------------------------------------------------------------- // -// Filename : FATX.cs +// Filename : Info.cs // Author(s) : Natalia Portillo // -// Component : FATX filesystem plugin +// Component : FATX filesystem plugin. // // --[ Description ] ---------------------------------------------------------- // @@ -30,28 +30,16 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System; -using System.Runtime.InteropServices; using System.Text; using DiscImageChef.CommonTypes; using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.Helpers; using Schemas; -using Marshal = DiscImageChef.Helpers.Marshal; -namespace DiscImageChef.Filesystems +namespace DiscImageChef.Filesystems.FATX { - public class FATX : IFilesystem + public partial class XboxFatPlugin { - const uint FATX_MAGIC = 0x58544146; - const byte UNUSED_DIRENTRY = 0x00; - const byte DELETED_DIRENTRY = 0xE5; - const byte MAX_FILENAME = 42; - public FileSystemType XmlFsType { get; private set; } - public Encoding Encoding { get; private set; } - public string Name => "FATX Filesystem Plugin"; - public Guid Id => new Guid("ED27A721-4A17-4649-89FD-33633B46E228"); - public string Author => "Natalia Portillo"; - public bool Identify(IMediaImage imagePlugin, Partition partition) { if(imagePlugin.Info.SectorSize < 512) return false; @@ -94,42 +82,5 @@ namespace DiscImageChef.Filesystems XmlFsType.Clusters = (long)((partition.End - partition.Start + 1) * imagePlugin.Info.SectorSize / (ulong)XmlFsType.ClusterSize); } - - [StructLayout(LayoutKind.Sequential, Pack = 1)] - struct Superblock - { - public uint magic; - public uint id; - public uint sectorsPerCluster; - public uint rootDirectoryCluster; - public ushort unknown; - } - - [StructLayout(LayoutKind.Sequential, Pack = 1)] - struct DirectoryEntry - { - public byte filenameSize; - public Attributes attributes; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_FILENAME)] - public byte[] filename; - public uint firstCluster; - public uint length; - public ushort lastWrittenTime; - public ushort lastWrittenDate; - public ushort creationTime; - public ushort creationDate; - public ushort lastAccessTime; - public ushort lastAccessDate; - } - - [Flags] - enum Attributes : byte - { - ReadOnly = 0x01, - Hidden = 0x02, - System = 0x04, - Directory = 0x10, - Archive = 0x20 - } } } \ No newline at end of file diff --git a/DiscImageChef.Filesystems/FATX/Structs.cs b/DiscImageChef.Filesystems/FATX/Structs.cs new file mode 100644 index 000000000..ab80415b4 --- /dev/null +++ b/DiscImageChef.Filesystems/FATX/Structs.cs @@ -0,0 +1,66 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Structs.cs +// Author(s) : Natalia Portillo +// +// Component : FATX filesystem plugin. +// +// --[ Description ] ---------------------------------------------------------- +// +// FATX filesystem structures. +// +// --[ 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System.Runtime.InteropServices; + +namespace DiscImageChef.Filesystems.FATX +{ + public partial class XboxFatPlugin + { + [StructLayout(LayoutKind.Sequential, Pack = 1)] + struct Superblock + { + public uint magic; + public uint id; + public uint sectorsPerCluster; + public uint rootDirectoryCluster; + public ushort unknown; + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + struct DirectoryEntry + { + public byte filenameSize; + public Attributes attributes; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_FILENAME)] + public byte[] filename; + public uint firstCluster; + public uint length; + public ushort lastWrittenTime; + public ushort lastWrittenDate; + public ushort creationTime; + public ushort creationDate; + public ushort lastAccessTime; + public ushort lastAccessDate; + } + } +} \ No newline at end of file diff --git a/DiscImageChef.Filesystems/FATX/Super.cs b/DiscImageChef.Filesystems/FATX/Super.cs new file mode 100644 index 000000000..384098aaf --- /dev/null +++ b/DiscImageChef.Filesystems/FATX/Super.cs @@ -0,0 +1,52 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Super.cs +// Author(s) : Natalia Portillo +// +// Component : FATX filesystem plugin. +// +// --[ Description ] ---------------------------------------------------------- +// +// Handles mounting and umounting the FATX filesystem. +// +// --[ 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using DiscImageChef.CommonTypes; +using DiscImageChef.CommonTypes.Interfaces; +using DiscImageChef.CommonTypes.Structs; + +namespace DiscImageChef.Filesystems.FATX +{ + public partial class XboxFatPlugin + { + public Errno Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding, + Dictionary options) => + throw new NotImplementedException(); + + public Errno Unmount() => throw new NotImplementedException(); + + public Errno StatFs(out FileSystemInfo stat) => throw new NotImplementedException(); + } +} \ No newline at end of file