2019-04-25 01:25:13 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2019-04-25 01:25:13 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : FAT.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Microsoft FAT 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2019-04-25 01:25:13 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2019-04-26 00:54:51 +01:00
|
|
|
|
using System.Collections.Generic;
|
2019-04-27 00:40:58 +01:00
|
|
|
|
using System.Globalization;
|
2019-04-25 01:25:13 +01:00
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
|
using Aaru.CommonTypes.Structs;
|
2019-04-25 01:25:13 +01:00
|
|
|
|
using Schemas;
|
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
// TODO: Differentiate between Atari and X68k FAT, as this one uses a standard BPB.
|
|
|
|
|
|
// X68K uses cdate/adate from direntry for extending filename
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
/// <summary>Implements the File Allocation Table, aka FAT, filesystem (FAT12, FAT16 and FAT32 variants).</summary>
|
|
|
|
|
|
public sealed partial class FAT : IReadOnlyFilesystem
|
2019-04-25 01:25:13 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
uint _bytesPerCluster;
|
|
|
|
|
|
byte[] _cachedEaData;
|
|
|
|
|
|
CultureInfo _cultureInfo;
|
|
|
|
|
|
bool _debug;
|
|
|
|
|
|
Dictionary<string, Dictionary<string, CompleteDirectoryEntry>> _directoryCache;
|
|
|
|
|
|
DirectoryEntry _eaDirEntry;
|
|
|
|
|
|
bool _fat12;
|
|
|
|
|
|
bool _fat16;
|
|
|
|
|
|
bool _fat32;
|
|
|
|
|
|
ushort[] _fatEntries;
|
|
|
|
|
|
ulong _fatFirstSector;
|
|
|
|
|
|
ulong _firstClusterSector;
|
|
|
|
|
|
bool _mounted;
|
|
|
|
|
|
Namespace _namespace;
|
|
|
|
|
|
uint _reservedSectors;
|
|
|
|
|
|
Dictionary<string, CompleteDirectoryEntry> _rootDirectoryCache;
|
|
|
|
|
|
uint _sectorsPerCluster;
|
|
|
|
|
|
uint _sectorsPerFat;
|
|
|
|
|
|
FileSystemInfo _statfs;
|
|
|
|
|
|
bool _useFirstFat;
|
2019-04-26 00:54:51 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public FileSystemType XmlFsType { get; private set; }
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public Encoding Encoding { get; private set; }
|
|
|
|
|
|
/// <inheritdoc />
|
2022-11-28 02:59:53 +00:00
|
|
|
|
public string Name => Localization.FAT_Name;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public Guid Id => new("33513B2C-0D26-0D2D-32C3-79D8611158E0");
|
|
|
|
|
|
/// <inheritdoc />
|
2022-11-28 02:59:53 +00:00
|
|
|
|
public string Author => Authors.NataliaPortillo;
|
2019-04-26 00:54:51 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public IEnumerable<(string name, Type type, string description)> SupportedOptions =>
|
2022-03-16 23:43:36 +00:00
|
|
|
|
Array.Empty<(string name, Type type, string description)>();
|
2019-04-26 00:54:51 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public Dictionary<string, string> Namespaces => new()
|
|
|
|
|
|
{
|
|
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
"dos", Localization.DOS_8_3_all_uppercase
|
2022-03-06 13:29:38 +00:00
|
|
|
|
},
|
2020-02-29 18:03:35 +00:00
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
"nt", Localization.Windows_NT_8_3_mixed_case
|
2022-03-06 13:29:38 +00:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
"os2", Localization.OS2_LONGNAME_extended_attribute
|
2022-03-06 13:29:38 +00:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
"ecs", Localization.Use_LFN_when_available_with_fallback_to_LONGNAME_default
|
2022-03-06 13:29:38 +00:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
"lfn", Localization.Long_file_names
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2019-04-26 00:54:51 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
static Dictionary<string, string> GetDefaultOptions() => new()
|
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
"debug", false.ToString()
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2019-04-25 01:25:13 +01:00
|
|
|
|
}
|