CREATE_VIRTUAL_DISK_VERSION_2的正确参数是什么?

时间:2016-06-25 22:54:58

标签: winapi vhd

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

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;

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

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

translateY

1 个答案:

答案 0 :(得分:0)

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

//  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;