gpt4 book ai didi

winapi - CREATE_VIRTUAL_DISK_VERSION_2 的正确参数是什么?

转载 作者:行者123 更新时间:2023-12-03 07:48:57 25 4
gpt4 key购买 nike

当我运行 CreateVritualDisk 时,收到错误 87 (ERROR_INVALID_PARAMETER)。可能缺少参数或不正确。问题出在版本 CREATE_VIRTUAL_DISK_VERSION_2 上,CREATE_VIRTUAL_DISK_VERSION_1 运行成功。

function TForm3.CreateVHDX(const AFilePath: string; const ASize: ULONG; const AType: integer; out AReturn: DWORD): Boolean;
var
params: TCreateVirtualDiskParameters;
mask: TVIRTUAL_DISK_ACCESS_MASK;
vst: TVirtualStorageType;
hvhd: THandle;
begin
hVhd := INVALID_HANDLE_VALUE;

// vst.DeviceId := VIRTUAL_STORAGE_TYPE_DEVICE_VHDX;
vst.DeviceId := VIRTUAL_STORAGE_TYPE_DEVICE_UNKNOWN;
// vst.VendorId := VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT ;
vst.VendorId := VIRTUAL_STORAGE_TYPE_VENDOR_UNKNOWN;

params.Version:= CREATE_VIRTUAL_DISK_VERSION_2;
params.Version2.UniqueId := TGUID.Empty;
params.Version2.MaximumSize:= ASize * 1024 * 1024;
params.Version2.BlockSizeInBytes := CREATE_VIRTUAL_DISK_PARAMETERS_DEFAULT_BLOCK_SIZE; //0
params.Version2.SectorSizeInBytes := $200;
params.Version2.PhysicalSectorSize := $200;
params.Version2.ParentPath := nil;
// params.Version2.OpenFlags := OPEN_VIRTUAL_DISK_FLAG_NONE;
params.Version2.ResiliencyGuid := TGUID.Empty;
// params.Version2.ParentVirtualStorageType := ;

mask := VIRTUAL_DISK_ACCESS_NONE;

if AType = 0 then //dynamic
begin
AReturn := CreateVirtualDisk(
@vst,
PWideChar(AFilePath),
mask,
nil,
CREATE_VIRTUAL_DISK_FLAG_NONE,
0,
@params,
nil,
hvhd);
Result := AReturn = ERROR_SUCCESS;
end;

if AType = 1 then //fixed
begin
AReturn := CreateVirtualDisk(
@vst,
PWideChar(AFilePath),
mask,
nil,
CREATE_VIRTUAL_DISK_FLAG_FULL_PHYSICAL_ALLOCATION,
0,
@params,
nil,
hvhd);
Result := AReturn = ERROR_SUCCESS;
end;

if hvhd <> INVALID_HANDLE_VALUE then
CloseHandle( hvhd )
end;

我已经尝试了几种组合,但没有成功。

编辑:我使用 Windows 10。将来,我想通过一种方法调用创建 VHD 和 VHDX 文件(固定、动态和差异)。此时,我想创建VHDX(固定、动态和差分)。

TCreateVirtualDiskParametersVersion2 = record
UniqueId: TGUID;
MaximumSize: ULONGLONG;
BlockSizeInBytes: ULONG;
SectorSizeInBytes: ULONG;
PhysicalSectorSize: ULONG;
ParentPath: LPCWSTR;
SourcePath: LPCWSTR;
OpenFlags: TOPEN_VIRTUAL_DISK_FLAG;
ParentVirtualStorageType: VIRTUAL_STORAGE_TYPE;
SourceVirtualStorageType: VIRTUAL_STORAGE_TYPE;
ResiliencyGuid: TGUID;
end;

最佳答案

我明白了。我有这个参数:

//  vst.DeviceId := VIRTUAL_STORAGE_TYPE_DEVICE_VHDX;
vst.DeviceId := VIRTUAL_STORAGE_TYPE_DEVICE_UNKNOWN;
// vst.VendorId := VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT ;
vst.VendorId := VIRTUAL_STORAGE_TYPE_VENDOR_UNKNOWN;

params.Version:= CREATE_VIRTUAL_DISK_VERSION_2;
params.Version2.UniqueId := TGUID.Empty;
params.Version2.MaximumSize:= ASize * 1024 * 1024;
params.Version2.BlockSizeInBytes := CREATE_VIRTUAL_DISK_PARAMETERS_DEFAULT_BLOCK_SIZE; //0
params.Version2.SectorSizeInBytes := 0;
params.Version2.PhysicalSectorSize := 0;
params.Version2.ParentPath := nil;
params.Version2.SourcePath := nil;
params.Version2.OpenFlags := OPEN_VIRTUAL_DISK_FLAG_NONE;
params.Version2.ResiliencyGuid := TGUID.Empty;
// params.Version2.ParentVirtualStorageType := ;

mask := VIRTUAL_DISK_ACCESS_NONE;

TCreateVirtualDiskParametersVersion2 记录中缺少两个参数。我添加了: SourceLimitPath: LPCWSTR; BackingStorageType:VIRTUAL_STORAGE_TYPE;

新记录:

TCreateVirtualDiskParametersVersion2 = record
UniqueId: TGUID;
MaximumSize: ULONGLONG;
BlockSizeInBytes: UINT;
SectorSizeInBytes: UINT;
PhysicalSectorSize: UINT;
ParentPath: LPCWSTR;
SourcePath: LPCWSTR;
OpenFlags: TOPEN_VIRTUAL_DISK_FLAG;
ParentVirtualStorageType: VIRTUAL_STORAGE_TYPE;
SourceVirtualStorageType: VIRTUAL_STORAGE_TYPE;
ResiliencyGuid: TGUID;
SourceLimitPath: LPCWSTR;
BackingStorageType: VIRTUAL_STORAGE_TYPE;
end;

我的临时工作职能:

function TForm3.CreateVHDX(const AFilePath: string; const ASize: ULONG; const AType: integer; out AReturn: DWORD): Boolean;
var
params: TCreateVirtualDiskParameters;
mask: TVIRTUAL_DISK_ACCESS_MASK;
vst: TVirtualStorageType;
hvhd: THandle;
begin
hVhd := INVALID_HANDLE_VALUE;

// vst.DeviceId := VIRTUAL_STORAGE_TYPE_DEVICE_VHDX;
vst.DeviceId := VIRTUAL_STORAGE_TYPE_DEVICE_UNKNOWN;
// vst.VendorId := VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT ;
vst.VendorId := VIRTUAL_STORAGE_TYPE_VENDOR_UNKNOWN;

params.Version:= CREATE_VIRTUAL_DISK_VERSION_2;
params.Version2.UniqueId := TGUID.Empty;
params.Version2.MaximumSize:= ASize * 1024 * 1024;
params.Version2.BlockSizeInBytes := CREATE_VIRTUAL_DISK_PARAMETERS_DEFAULT_BLOCK_SIZE; //0
params.Version2.SectorSizeInBytes := 0;
params.Version2.PhysicalSectorSize := 0;
params.Version2.ParentPath := nil;
params.Version1.SourcePath := nil;
params.Version2.OpenFlags := OPEN_VIRTUAL_DISK_FLAG_NONE;
params.Version2.ResiliencyGuid := TGUID.Empty;
// params.Version2.ParentVirtualStorageType := ;

mask := VIRTUAL_DISK_ACCESS_NONE;

if AType = 0 then //dynamic
begin
AReturn := CreateVirtualDisk(
@vst,
PWideChar(AFilePath),
mask,
nil,
CREATE_VIRTUAL_DISK_FLAG_NONE,
0,
@params,
nil,
hvhd);
Result := AReturn = ERROR_SUCCESS;
end;

if AType = 1 then //fixed
begin
AReturn := CreateVirtualDisk(
@vst,
PWideChar(AFilePath),
mask,
nil,
CREATE_VIRTUAL_DISK_FLAG_FULL_PHYSICAL_ALLOCATION,
0,
@params,
nil,
hvhd);
Result := AReturn = ERROR_SUCCESS;
end;

if hvhd <> INVALID_HANDLE_VALUE then
CloseHandle( hvhd );
end;

关于winapi - CREATE_VIRTUAL_DISK_VERSION_2 的正确参数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38033646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com