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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:30 +00:00
|
|
|
|
// Copyright © 2011-2020 Natalia Portillo
|
2016-09-14 00:13:14 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
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
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.Filesystems
|
2016-09-14 00:13:14 +01:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class VMfs : IFilesystem
|
2016-09-14 00:13:14 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Identifier for VMfs</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
|
const uint VMFS_MAGIC = 0xC001D00D;
|
|
|
|
|
|
const uint VMFS_BASE = 0x00100000;
|
|
|
|
|
|
|
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 => "VMware filesystem";
|
|
|
|
|
|
public Guid Id => new Guid("EE52BDB8-B49C-4122-A3DA-AD21CBE79843");
|
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-14 00:13:14 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(partition.Start >= partition.End)
|
|
|
|
|
|
return false;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
ulong vmfsSuperOff = VMFS_BASE / imagePlugin.Info.SectorSize;
|
2016-09-14 16:05:46 +01:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
if(partition.Start + vmfsSuperOff > partition.End)
|
|
|
|
|
|
return false;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSector(partition.Start + vmfsSuperOff);
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
|
|
|
|
|
uint magic = BitConverter.ToUInt32(sector, 0x00);
|
|
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
return magic == VMFS_MAGIC;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Encoding encoding)
|
2016-09-14 00:13:14 +01:00
|
|
|
|
{
|
2017-12-26 08:01:40 +00:00
|
|
|
|
Encoding = encoding ?? Encoding.UTF8;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
ulong vmfsSuperOff = VMFS_BASE / imagePlugin.Info.SectorSize;
|
|
|
|
|
|
byte[] sector = imagePlugin.ReadSector(partition.Start + vmfsSuperOff);
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2019-03-01 07:35:22 +00:00
|
|
|
|
VolumeInfo volInfo = Marshal.ByteArrayToStructureLittleEndian<VolumeInfo>(sector);
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
|
var sbInformation = new StringBuilder();
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendLine("VMware file system");
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
uint ctimeSecs = (uint)(volInfo.ctime / 1000000);
|
2016-09-14 00:13:14 +01:00
|
|
|
|
uint ctimeNanoSecs = (uint)(volInfo.ctime % 1000000);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
uint mtimeSecs = (uint)(volInfo.mtime / 1000000);
|
2016-09-14 00:13:14 +01:00
|
|
|
|
uint mtimeNanoSecs = (uint)(volInfo.mtime % 1000000);
|
|
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendFormat("Volume version {0}", volInfo.version).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendFormat("Volume name {0}", StringHandlers.CToString(volInfo.name, Encoding)).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2016-09-14 00:13:14 +01:00
|
|
|
|
sbInformation.AppendFormat("Volume size {0} bytes", volInfo.size * 256).AppendLine();
|
|
|
|
|
|
sbInformation.AppendFormat("Volume UUID {0}", volInfo.uuid).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
sbInformation.
|
|
|
|
|
|
AppendFormat("Volume created on {0}", DateHandlers.UnixUnsignedToDateTime(ctimeSecs, ctimeNanoSecs)).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume last modified on {0}",
|
2017-12-23 03:59:48 +00:00
|
|
|
|
DateHandlers.UnixUnsignedToDateTime(mtimeSecs, mtimeNanoSecs)).AppendLine();
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
|
|
|
|
|
information = sbInformation.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 = "VMware file system",
|
|
|
|
|
|
CreationDate = DateHandlers.UnixUnsignedToDateTime(ctimeSecs, ctimeNanoSecs),
|
|
|
|
|
|
CreationDateSpecified = true,
|
|
|
|
|
|
ModificationDate = DateHandlers.UnixUnsignedToDateTime(mtimeSecs, mtimeNanoSecs),
|
2017-12-22 08:43:22 +00:00
|
|
|
|
ModificationDateSpecified = true,
|
2020-02-29 18:03:35 +00:00
|
|
|
|
Clusters = (volInfo.size * 256) / imagePlugin.Info.SectorSize,
|
|
|
|
|
|
ClusterSize = imagePlugin.Info.SectorSize, VolumeSerial = volInfo.uuid.ToString()
|
2017-12-22 08:43:22 +00:00
|
|
|
|
};
|
2016-09-14 00:13:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
[Flags]
|
|
|
|
|
|
enum VMfsFlags : byte
|
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
RecyledFolder = 64, CaseSensitive = 128
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct VolumeInfo
|
|
|
|
|
|
{
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly uint magic;
|
|
|
|
|
|
public readonly uint version;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] unknown1;
|
|
|
|
|
|
public readonly byte lun;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] unknown2;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 28)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] name;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 49)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] unknown3;
|
|
|
|
|
|
public readonly uint size;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
|
2019-04-23 01:38:33 +01:00
|
|
|
|
public readonly byte[] unknown4;
|
|
|
|
|
|
public readonly Guid uuid;
|
|
|
|
|
|
public readonly ulong ctime;
|
|
|
|
|
|
public readonly ulong mtime;
|
2017-12-24 02:37:41 +00:00
|
|
|
|
}
|
2016-09-14 00:13:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|