mirror of https://github.com/dahall/Vanara.git
Made some optimizing changes to PInvoke.VirtDisk and added VirtualDisk.SetParentPath and SetParentPathWithDepth methods.
parent
600d50bf0c
commit
46c3324ade
|
@ -2363,8 +2363,14 @@ namespace Vanara.PInvoke
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>Contains virtual hard disk (VHD) information for set request.</summary>
|
||||
[PInvokeData("VirtDisk.h", MSDNShortId = "dd323686", MinClient = PInvokeClient.Windows7)]
|
||||
/// <summary>
|
||||
/// Contains virtual hard disk (VHD) information to use when you call the SetVirtualDiskInformation function to set VHD properties.
|
||||
/// </summary>
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/virtdisk/ns-virtdisk-set_virtual_disk_info typedef struct
|
||||
// _SET_VIRTUAL_DISK_INFO { SET_VIRTUAL_DISK_INFO_VERSION Version; union { PCWSTR ParentFilePath; GUID UniqueIdentifier; struct {
|
||||
// ULONG ChildDepth; PCWSTR ParentFilePath; } ParentPathWithDepthInfo; ULONG VhdPhysicalSectorSize; GUID VirtualDiskId; BOOL
|
||||
// ChangeTrackingEnabled; struct { GUID LinkageId; PCWSTR ParentFilePath; } ParentLocator; }; } SET_VIRTUAL_DISK_INFO, *PSET_VIRTUAL_DISK_INFO;
|
||||
[PInvokeData("virtdisk.h", MSDNShortId = "NS:virtdisk._SET_VIRTUAL_DISK_INFO")]
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode,
|
||||
#if X64
|
||||
Pack = 8
|
||||
|
@ -2382,6 +2388,14 @@ namespace Vanara.PInvoke
|
|||
|
||||
private UNION union;
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="SET_VIRTUAL_DISK_INFO"/> struct.</summary>
|
||||
/// <param name="version">The version that determines the type of information set..</param>
|
||||
public SET_VIRTUAL_DISK_INFO(SET_VIRTUAL_DISK_INFO_VERSION version)
|
||||
{
|
||||
Version = version;
|
||||
union = default;
|
||||
}
|
||||
|
||||
/// <summary>Path to the parent backing store.</summary>
|
||||
[PInvokeData("VirtDisk.h", MinClient = PInvokeClient.Windows7)]
|
||||
public StrPtrUni ParentFilePath { get => union.ParentFilePath; set => union.ParentFilePath = value; }
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace Vanara.IO
|
|||
get => GetInformation<Guid>(GET_VIRTUAL_DISK_INFO_VERSION.GET_VIRTUAL_DISK_INFO_IDENTIFIER);
|
||||
set
|
||||
{
|
||||
var si = new SET_VIRTUAL_DISK_INFO { Version = SET_VIRTUAL_DISK_INFO_VERSION.SET_VIRTUAL_DISK_INFO_IDENTIFIER, UniqueIdentifier = value };
|
||||
SET_VIRTUAL_DISK_INFO si = new(SET_VIRTUAL_DISK_INFO_VERSION.SET_VIRTUAL_DISK_INFO_IDENTIFIER) { UniqueIdentifier = value };
|
||||
SetVirtualDiskInformation(Handle, si).ThrowIfFailed();
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ namespace Vanara.IO
|
|||
get => GetInformation<uint>(GET_VIRTUAL_DISK_INFO_VERSION.GET_VIRTUAL_DISK_INFO_PHYSICAL_DISK, 4);
|
||||
set
|
||||
{
|
||||
var si = new SET_VIRTUAL_DISK_INFO { Version = SET_VIRTUAL_DISK_INFO_VERSION.SET_VIRTUAL_DISK_INFO_PHYSICAL_SECTOR_SIZE, VhdPhysicalSectorSize = value };
|
||||
SET_VIRTUAL_DISK_INFO si = new(SET_VIRTUAL_DISK_INFO_VERSION.SET_VIRTUAL_DISK_INFO_PHYSICAL_SECTOR_SIZE) { VhdPhysicalSectorSize = value };
|
||||
SetVirtualDiskInformation(Handle, si).ThrowIfFailed();
|
||||
}
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ namespace Vanara.IO
|
|||
get => GetInformation<bool>(GET_VIRTUAL_DISK_INFO_VERSION.GET_VIRTUAL_DISK_INFO_CHANGE_TRACKING_STATE);
|
||||
set
|
||||
{
|
||||
var si = new SET_VIRTUAL_DISK_INFO { Version = SET_VIRTUAL_DISK_INFO_VERSION.SET_VIRTUAL_DISK_INFO_CHANGE_TRACKING_STATE, ChangeTrackingEnabled = value };
|
||||
SET_VIRTUAL_DISK_INFO si = new(SET_VIRTUAL_DISK_INFO_VERSION.SET_VIRTUAL_DISK_INFO_CHANGE_TRACKING_STATE) { ChangeTrackingEnabled = value };
|
||||
SetVirtualDiskInformation(Handle, si).ThrowIfFailed();
|
||||
}
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ namespace Vanara.IO
|
|||
get => GetInformation<Guid>(GET_VIRTUAL_DISK_INFO_VERSION.GET_VIRTUAL_DISK_INFO_VIRTUAL_DISK_ID);
|
||||
set
|
||||
{
|
||||
var si = new SET_VIRTUAL_DISK_INFO { Version = SET_VIRTUAL_DISK_INFO_VERSION.SET_VIRTUAL_DISK_INFO_VIRTUAL_DISK_ID, VirtualDiskId = value };
|
||||
SET_VIRTUAL_DISK_INFO si = new(SET_VIRTUAL_DISK_INFO_VERSION.SET_VIRTUAL_DISK_INFO_VIRTUAL_DISK_ID) { VirtualDiskId = value };
|
||||
SetVirtualDiskInformation(Handle, si).ThrowIfFailed();
|
||||
}
|
||||
}
|
||||
|
@ -607,6 +607,26 @@ namespace Vanara.IO
|
|||
}
|
||||
);
|
||||
|
||||
/// <summary>Sets the path to virtal hard disk's parent.</summary>
|
||||
/// <param name="path">The full path to the parent disk.</param>
|
||||
public void SetParentPath(string path)
|
||||
{
|
||||
using var pStr = new SafeCoTaskMemString(path);
|
||||
SET_VIRTUAL_DISK_INFO si = new(SET_VIRTUAL_DISK_INFO_VERSION.SET_VIRTUAL_DISK_INFO_PARENT_PATH) { ParentFilePath = (IntPtr)pStr };
|
||||
SetVirtualDiskInformation(Handle, si).ThrowIfFailed();
|
||||
}
|
||||
|
||||
/// <summary>Sets the path to virtal hard disk's parent and the child depth.</summary>
|
||||
/// <param name="path">The full path to the parent disk.</param>
|
||||
/// <param name="childDepth">Specifies the depth to the child from the leaf. The leaf itself is at depth 1.</param>
|
||||
public void SetParentPathAndDepth(string path, uint childDepth)
|
||||
{
|
||||
using var pStr = new SafeCoTaskMemString(path);
|
||||
SET_VIRTUAL_DISK_INFO si = new(SET_VIRTUAL_DISK_INFO_VERSION.SET_VIRTUAL_DISK_INFO_PARENT_PATH_WITH_DEPTH)
|
||||
{ ParentPathWithDepthInfo = new() { ParentFilePath = (IntPtr)pStr, ChildDepth = childDepth } };
|
||||
SetVirtualDiskInformation(Handle, si).ThrowIfFailed();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes a virtual disk without checking the virtual disk's partition table to ensure that this truncation is safe. <note
|
||||
/// type="warning">This method can cause unrecoverable data loss; use with care.</note>
|
||||
|
|
Loading…
Reference in New Issue