CREATE_VIRTUAL_DISK_VERSION_2的正确参数是什么?



当我运行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;

相关内容

  • 没有找到相关文章

最新更新