2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2016-09-14 00:13:14 +01:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2016-09-14 00:13:14 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.DiscImages;
|
|
|
|
|
|
using Schemas;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Filesystems
|
|
|
|
|
|
{
|
2017-07-01 03:26:08 +01:00
|
|
|
|
public class VMfs : Filesystem
|
2016-09-14 00:13:14 +01:00
|
|
|
|
{
|
|
|
|
|
|
public VMfs()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "VMware filesystem";
|
2017-12-22 08:43:22 +00:00
|
|
|
|
PluginUuid = new Guid("EE52BDB8-B49C-4122-A3DA-AD21CBE79843");
|
2017-06-06 21:23:20 +01:00
|
|
|
|
CurrentEncoding = Encoding.UTF8;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 23:54:02 +01:00
|
|
|
|
public VMfs(Encoding encoding)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "VMware filesystem";
|
2017-12-22 08:43:22 +00:00
|
|
|
|
PluginUuid = new Guid("EE52BDB8-B49C-4122-A3DA-AD21CBE79843");
|
|
|
|
|
|
CurrentEncoding = encoding ?? Encoding.UTF8;
|
2017-10-12 23:54:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
|
public VMfs(ImagePlugin imagePlugin, Partition partition, Encoding encoding)
|
2016-09-14 00:13:14 +01:00
|
|
|
|
{
|
|
|
|
|
|
Name = "VMware filesystem";
|
2017-12-22 08:43:22 +00:00
|
|
|
|
PluginUuid = new Guid("EE52BDB8-B49C-4122-A3DA-AD21CBE79843");
|
|
|
|
|
|
CurrentEncoding = encoding ?? Encoding.UTF8;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Flags]
|
|
|
|
|
|
enum VMfsFlags : byte
|
|
|
|
|
|
{
|
|
|
|
|
|
RecyledFolder = 64,
|
|
|
|
|
|
CaseSensitive = 128
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct VolumeInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
public uint magic;
|
|
|
|
|
|
public uint version;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] public byte[] unknown1;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
public byte lun;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] unknown2;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 28)] public byte[] name;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 49)] public byte[] unknown3;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
public uint size;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)] public byte[] unknown4;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
public Guid uuid;
|
|
|
|
|
|
public ulong ctime;
|
|
|
|
|
|
public ulong mtime;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Identifier for VMfs
|
|
|
|
|
|
/// </summary>
|
2017-12-22 08:43:22 +00:00
|
|
|
|
const uint VMFS_MAGIC = 0xC001D00D;
|
|
|
|
|
|
const uint VMFS_BASE = 0x00100000;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
|
public override bool Identify(ImagePlugin imagePlugin, Partition partition)
|
2016-09-14 00:13:14 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(partition.Start >= partition.End) return false;
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
ulong vmfsSuperOff = VMFS_BASE / imagePlugin.ImageInfo.SectorSize;
|
2016-09-14 16:05:46 +01:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(partition.Start + vmfsSuperOff > partition.End) return false;
|
|
|
|
|
|
|
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-21 14:30:38 +00:00
|
|
|
|
public override void GetInformation(ImagePlugin imagePlugin, Partition partition,
|
2017-12-19 20:33:03 +00:00
|
|
|
|
out string information)
|
2016-09-14 00:13:14 +01:00
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
ulong vmfsSuperOff = VMFS_BASE / imagePlugin.ImageInfo.SectorSize;
|
2017-07-19 16:37:11 +01:00
|
|
|
|
byte[] sector = imagePlugin.ReadSector(partition.Start + vmfsSuperOff);
|
2016-09-14 00:13:14 +01:00
|
|
|
|
|
|
|
|
|
|
VolumeInfo volInfo = new VolumeInfo();
|
|
|
|
|
|
IntPtr volInfoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(volInfo));
|
|
|
|
|
|
Marshal.Copy(sector, 0, volInfoPtr, Marshal.SizeOf(volInfo));
|
|
|
|
|
|
volInfo = (VolumeInfo)Marshal.PtrToStructure(volInfoPtr, typeof(VolumeInfo));
|
|
|
|
|
|
Marshal.FreeHGlobal(volInfoPtr);
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sbInformation = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendLine("VMware file system");
|
|
|
|
|
|
|
|
|
|
|
|
uint ctimeSecs = (uint)(volInfo.ctime / 1000000);
|
|
|
|
|
|
uint ctimeNanoSecs = (uint)(volInfo.ctime % 1000000);
|
|
|
|
|
|
uint mtimeSecs = (uint)(volInfo.mtime / 1000000);
|
|
|
|
|
|
uint mtimeNanoSecs = (uint)(volInfo.mtime % 1000000);
|
|
|
|
|
|
|
|
|
|
|
|
sbInformation.AppendFormat("Volume version {0}", volInfo.version).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation.AppendFormat("Volume name {0}", StringHandlers.CToString(volInfo.name, CurrentEncoding))
|
|
|
|
|
|
.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();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sbInformation
|
2017-12-23 03:59:48 +00:00
|
|
|
|
.AppendFormat("Volume created on {0}", DateHandlers.UnixUnsignedToDateTime(ctimeSecs, ctimeNanoSecs))
|
2017-12-19 20:33:03 +00:00
|
|
|
|
.AppendLine();
|
|
|
|
|
|
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-22 08:43:22 +00:00
|
|
|
|
XmlFsType = new FileSystemType
|
|
|
|
|
|
{
|
|
|
|
|
|
Type = "VMware file system",
|
2017-12-23 03:59:48 +00:00
|
|
|
|
CreationDate = DateHandlers.UnixUnsignedToDateTime(ctimeSecs, ctimeNanoSecs),
|
2017-12-22 08:43:22 +00:00
|
|
|
|
CreationDateSpecified = true,
|
2017-12-23 03:59:48 +00:00
|
|
|
|
ModificationDate = DateHandlers.UnixUnsignedToDateTime(mtimeSecs, mtimeNanoSecs),
|
2017-12-22 08:43:22 +00:00
|
|
|
|
ModificationDateSpecified = true,
|
|
|
|
|
|
Clusters = volInfo.size * 256 / imagePlugin.ImageInfo.SectorSize,
|
|
|
|
|
|
ClusterSize = (int)imagePlugin.ImageInfo.SectorSize,
|
|
|
|
|
|
VolumeSerial = volInfo.uuid.ToString()
|
|
|
|
|
|
};
|
2016-09-14 00:13:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno Mount()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno Mount(bool debug)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno Unmount()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno MapBlock(string path, long fileBlock, ref long deviceBlock)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno GetAttributes(string path, ref FileAttributes attributes)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno ListXAttr(string path, ref List<string> xattrs)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno GetXattr(string path, string xattr, ref byte[] buf)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno Read(string path, long offset, long size, ref byte[] buf)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno ReadDir(string path, ref List<string> contents)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno StatFs(ref FileSystemInfo stat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno Stat(string path, ref FileEntryInfo stat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno ReadLink(string path, ref string dest)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|