3.4.5.2.41.4 IVdsOpenVDisk::Compact (Opnum 6)

The Compact method reduces the size of the virtual disk file (the backing store). This requires that the virtual disk be detached. Compact is applicable only to differencing type virtual disks and virtual disks created using CREATE_VIRTUAL_DISK_FLAG_NONE. The Compact method does not change the size of the virtual disk.

 HRESULT Compact(
   [in] COMPACT_VIRTUAL_DISK_FLAG Flags,
   [in] ULONG Reserved,
   [out] IVdsAsync** ppAsync
 );

Flags: A COMPACT_VIRTUAL_DISK_FLAG (section 2.2.2.20.1.3) enumeration value that specifies how the virtual disk is to be compacted.

Reserved: This parameter is reserved for system use and MUST be ignored.

ppAsync: A pointer to an IVdsAsync (section 3.1.3.1) interface that if the operation is successfully completed receives the IVdsAsync interface to monitor and control this operation. Callers MUST release the interface when they are done with it.

Return Values: The method MUST return zero to indicate success, or return an implementation-specific nonzero error code to indicate failure.

When the server receives this message, it MUST validate the following parameters:

  • Verify that Flags is a bitwise OR of values from the COMPACT_VIRTUAL_DISK_FLAG enumeration.

  • Verify that ppAsync is not NULL.

The server MUST perform the following:

  • Create a new async object implementing the IVdsAsync interface with an output type of VDS_ASYNCOUT_COMPACT_VDISK and set the pointer ppAsync to the interface.

  • Return an HRESULT indicating failure or success. Any errors encountered up through this point in processing the operation are returned in this HRESULT.

The server MUST then perform the following in sequence. Errors generated in this sequence of steps are returned in the pHrResult parameter to the IVdsAsync::Wait or IVdsAsyncQueryStatus methods.

  • Pass the input parameters to the operating system to compact the disk.

  • Set the return code in the async object to an HRESULT indicating failure or success of the operating system.

  • If the task completed successfully, set the percentage completed value in the async object to 100.

  •  Set the signal state in the async object to TRUE.

At any point in the preceding sequence--before the percentage completed value in the async object is 100--the server MUST update the percentage completed value if forward progress is made during the compact operation.