2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-09-14 00:13:14 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : VMfs.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2016-09-14 02:31:32 +01:00
|
|
|
|
// Component : VMware file system plugin.
|
2016-09-14 00:13:14 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Identifies the VMware 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
|
2016-09-14 00:13:14 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2020-07-20 07:47:12 +01:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
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;
|
2020-07-20 15:43:52 +01:00
|
|
|
|
using Aaru.Helpers;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using Schemas;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Marshal = Aaru.Helpers.Marshal;
|
2016-09-14 00:13:14 +01: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 the VMware filesystem</summary>
|
|
|
|
|
|
[SuppressMessage("ReSharper", "UnusedType.Local"), SuppressMessage("ReSharper", "IdentifierTypo"),
|
|
|
|
|
|
SuppressMessage("ReSharper", "UnusedMember.Local")]
|
|
|
|
|
|
public sealed class VMfs : IFilesystem
|
2016-09-14 00:13:14 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <summary>Identifier for VMfs</summary>
|
|
|
|
|
|
const uint VMFS_MAGIC = 0xC001D00D;
|
|
|
|
|
|
const uint VMFS_BASE = 0x00100000;
|
|
|
|
|
|
|
2021-08-17 14:25:12 +01:00
|
|
|
|
/// <inheritdoc />
|
2022-03-06 13:29:38 +00:00
|
|
|
|
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.VMfs_Name;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public Guid Id => new("EE52BDB8-B49C-4122-A3DA-AD21CBE79843");
|
|
|
|
|
|
/// <inheritdoc />
|
2022-11-28 02:59:53 +00:00
|
|
|
|
public string Author => Authors.NataliaPortillo;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(partition.Start >= partition.End)
|
|
|
|
|
|
return false;
|
2016-09-14 16:05:46 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ulong vmfsSuperOff = VMFS_BASE / imagePlugin.Info.SectorSize;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(partition.Start + vmfsSuperOff > partition.End)
|
|
|
|
|
|
return false;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(partition.Start + vmfsSuperOff, out byte[] sector);
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return false;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
uint magic = BitConverter.ToUInt32(sector, 0x00);
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return magic == VMFS_MAGIC;
|
|
|
|
|
|
}
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
const string FS_TYPE = "vmfs";
|
|
|
|
|
|
|
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 ?? Encoding.UTF8;
|
|
|
|
|
|
information = "";
|
|
|
|
|
|
ulong vmfsSuperOff = VMFS_BASE / imagePlugin.Info.SectorSize;
|
|
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(partition.Start + vmfsSuperOff, out byte[] sector);
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
VolumeInfo volInfo = Marshal.ByteArrayToStructureLittleEndian<VolumeInfo>(sector);
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var sbInformation = new StringBuilder();
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sbInformation.AppendLine(Localization.VMware_file_system);
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
uint ctimeSecs = (uint)(volInfo.ctime / 1000000);
|
|
|
|
|
|
uint ctimeNanoSecs = (uint)(volInfo.ctime % 1000000);
|
|
|
|
|
|
uint mtimeSecs = (uint)(volInfo.mtime / 1000000);
|
|
|
|
|
|
uint mtimeNanoSecs = (uint)(volInfo.mtime % 1000000);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sbInformation.AppendFormat(Localization.Volume_version_0, volInfo.version).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sbInformation.AppendFormat(Localization.Volume_name_0, StringHandlers.CToString(volInfo.name, Encoding)).
|
|
|
|
|
|
AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sbInformation.AppendFormat(Localization.Volume_size_0_bytes, volInfo.size * 256).AppendLine();
|
|
|
|
|
|
sbInformation.AppendFormat(Localization.Volume_UUID_0, volInfo.uuid).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sbInformation.AppendFormat(Localization.Volume_created_on_0,
|
|
|
|
|
|
DateHandlers.UnixUnsignedToDateTime(ctimeSecs, ctimeNanoSecs)).AppendLine();
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sbInformation.AppendFormat(Localization.Volume_last_modified_on_0,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
DateHandlers.UnixUnsignedToDateTime(mtimeSecs, mtimeNanoSecs)).AppendLine();
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
information = sbInformation.ToString();
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
XmlFsType = new FileSystemType
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
Type = FS_TYPE,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
CreationDate = DateHandlers.UnixUnsignedToDateTime(ctimeSecs, ctimeNanoSecs),
|
|
|
|
|
|
CreationDateSpecified = true,
|
|
|
|
|
|
ModificationDate = DateHandlers.UnixUnsignedToDateTime(mtimeSecs, mtimeNanoSecs),
|
|
|
|
|
|
ModificationDateSpecified = true,
|
|
|
|
|
|
Clusters = volInfo.size * 256 / imagePlugin.Info.SectorSize,
|
|
|
|
|
|
ClusterSize = imagePlugin.Info.SectorSize,
|
|
|
|
|
|
VolumeSerial = volInfo.uuid.ToString()
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2017-12-24 02:37:41 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[Flags]
|
|
|
|
|
|
enum Flags : byte
|
|
|
|
|
|
{
|
2022-11-15 15:58:43 +00:00
|
|
|
|
RecyledFolder = 64, CaseSensitive = 128
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
readonly struct VolumeInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
public readonly uint magic;
|
|
|
|
|
|
public readonly uint version;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
|
|
|
|
|
|
public readonly byte[] unknown1;
|
|
|
|
|
|
public readonly byte lun;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
|
|
|
|
|
public readonly byte[] unknown2;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 28)]
|
|
|
|
|
|
public readonly byte[] name;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 49)]
|
|
|
|
|
|
public readonly byte[] unknown3;
|
|
|
|
|
|
public readonly uint size;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
|
|
|
|
|
|
public readonly byte[] unknown4;
|
|
|
|
|
|
public readonly Guid uuid;
|
|
|
|
|
|
public readonly ulong ctime;
|
|
|
|
|
|
public readonly ulong mtime;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|