2017-12-30 17:47:55 +00:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2017-12-30 17:47:55 +00:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : ReFS.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Resilient File System plugin
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Identifies the Resilient File System 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2017-12-30 17:47:55 +00:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
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.Console;
|
2020-07-20 15:43:52 +01:00
|
|
|
|
using Aaru.Helpers;
|
2017-12-30 17:47:55 +00:00
|
|
|
|
using Schemas;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Marshal = Aaru.Helpers.Marshal;
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
/// <summary>Implements detection of Microsoft's Resilient filesystem (ReFS)</summary>
|
|
|
|
|
|
public sealed class ReFS : IFilesystem
|
2017-12-30 17:47:55 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
const uint FSRS = 0x53525346;
|
2022-11-28 02:59:53 +00:00
|
|
|
|
|
|
|
|
|
|
const string FS_TYPE = "refs";
|
2022-03-06 13:29:38 +00:00
|
|
|
|
readonly byte[] _signature =
|
2017-12-30 17:47:55 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
0x52, 0x65, 0x46, 0x53, 0x00, 0x00, 0x00, 0x00
|
|
|
|
|
|
};
|
|
|
|
|
|
/// <inheritdoc />
|
2022-11-28 02:59:53 +00:00
|
|
|
|
public string Name => Localization.ReFS_Name;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public Guid Id => new("37766C4E-EBF5-4113-A712-B758B756ABD6");
|
|
|
|
|
|
/// <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 Author => Authors.NataliaPortillo;
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
|
|
|
|
|
{
|
2022-11-15 15:58:43 +00:00
|
|
|
|
uint sbSize = (uint)(Marshal.SizeOf<VolumeHeader>() / imagePlugin.Info.SectorSize);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(Marshal.SizeOf<VolumeHeader>() % imagePlugin.Info.SectorSize != 0)
|
|
|
|
|
|
sbSize++;
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(partition.Start + sbSize >= partition.End)
|
|
|
|
|
|
return false;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, sbSize, out byte[] sector);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return false;
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sector.Length < Marshal.SizeOf<VolumeHeader>())
|
|
|
|
|
|
return false;
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
VolumeHeader vhdr = Marshal.ByteArrayToStructureLittleEndian<VolumeHeader>(sector);
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return vhdr.identifier == FSRS && ArrayHelpers.ArrayIsNullOrEmpty(vhdr.mustBeZero) &&
|
|
|
|
|
|
vhdr.signature.SequenceEqual(_signature);
|
|
|
|
|
|
}
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
2022-03-07 07:36:44 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
Encoding = Encoding.UTF8;
|
|
|
|
|
|
information = "";
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
uint sbSize = (uint)(Marshal.SizeOf<VolumeHeader>() / imagePlugin.Info.SectorSize);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(Marshal.SizeOf<VolumeHeader>() % imagePlugin.Info.SectorSize != 0)
|
|
|
|
|
|
sbSize++;
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(partition.Start + sbSize >= partition.End)
|
|
|
|
|
|
return;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start, sbSize, out byte[] sector);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return;
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sector.Length < Marshal.SizeOf<VolumeHeader>())
|
|
|
|
|
|
return;
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
VolumeHeader vhdr = Marshal.ByteArrayToStructureLittleEndian<VolumeHeader>(sector);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.jump empty? = {0}",
|
|
|
|
|
|
ArrayHelpers.ArrayIsNullOrEmpty(vhdr.jump));
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.signature = {0}",
|
|
|
|
|
|
StringHandlers.CToString(vhdr.signature));
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.mustBeZero empty? = {0}",
|
|
|
|
|
|
ArrayHelpers.ArrayIsNullOrEmpty(vhdr.mustBeZero));
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.identifier = {0}",
|
|
|
|
|
|
StringHandlers.CToString(BitConverter.GetBytes(vhdr.identifier)));
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.length = {0}", vhdr.length);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.checksum = 0x{0:X4}", vhdr.checksum);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.sectors = {0}", vhdr.sectors);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.bytesPerSector = {0}", vhdr.bytesPerSector);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.sectorsPerCluster = {0}", vhdr.sectorsPerCluster);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown1 zero? = {0}", vhdr.unknown1 == 0);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown2 zero? = {0}", vhdr.unknown2 == 0);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown3 zero? = {0}", vhdr.unknown3 == 0);
|
|
|
|
|
|
AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown4 zero? = {0}", vhdr.unknown4 == 0);
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown5 empty? = {0}",
|
|
|
|
|
|
ArrayHelpers.ArrayIsNullOrEmpty(vhdr.unknown5));
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(vhdr.identifier != FSRS ||
|
|
|
|
|
|
!ArrayHelpers.ArrayIsNullOrEmpty(vhdr.mustBeZero) ||
|
|
|
|
|
|
!vhdr.signature.SequenceEqual(_signature))
|
|
|
|
|
|
return;
|
2017-12-30 17:47:55 +00: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.Microsoft_Resilient_File_System);
|
|
|
|
|
|
sb.AppendFormat(Localization.Volume_uses_0_bytes_per_sector, vhdr.bytesPerSector).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Volume_uses_0_sectors_per_cluster_1_bytes, vhdr.sectorsPerCluster,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
vhdr.sectorsPerCluster * vhdr.bytesPerSector).AppendLine();
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Volume_has_0_sectors_1_bytes, vhdr.sectors, vhdr.sectors * vhdr.bytesPerSector).
|
2022-03-06 13:29:38 +00:00
|
|
|
|
AppendLine();
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
information = sb.ToString();
|
2017-12-30 17:47:55 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
XmlFsType = new FileSystemType
|
2017-12-30 17:47:55 +00:00
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
Type = FS_TYPE,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ClusterSize = vhdr.bytesPerSector * vhdr.sectorsPerCluster,
|
|
|
|
|
|
Clusters = vhdr.sectors / vhdr.sectorsPerCluster
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
readonly struct VolumeHeader
|
|
|
|
|
|
{
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
|
|
|
|
|
public readonly byte[] jump;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
|
|
|
|
|
public readonly byte[] signature;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
|
|
|
|
|
|
public readonly byte[] mustBeZero;
|
|
|
|
|
|
public readonly uint identifier;
|
|
|
|
|
|
public readonly ushort length;
|
|
|
|
|
|
public readonly ushort checksum;
|
|
|
|
|
|
public readonly ulong sectors;
|
|
|
|
|
|
public readonly uint bytesPerSector;
|
|
|
|
|
|
public readonly uint sectorsPerCluster;
|
|
|
|
|
|
public readonly uint unknown1;
|
|
|
|
|
|
public readonly uint unknown2;
|
|
|
|
|
|
public readonly ulong unknown3;
|
|
|
|
|
|
public readonly ulong unknown4;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15872)]
|
|
|
|
|
|
public readonly byte[] unknown5;
|
2017-12-30 17:47:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|