Administrative Disk Operations
These functions rename, grow, defragment, shrink, and remove virtual disk.
Rename an Existing Disk
VixDiskLib_Rename() changes the name of a virtual disk. Use this function only when the virtual machine is powered off.
vixError = VixDiskLib_Rename(oldGlobals.diskPath, newGlobals.diskPath);
Grow an Existing Local Disk
VixDiskLib_Grow() extends an existing virtual disk by adding sectors. This function supports hosted disk, but not managed disk.
vixError =
VixDiskLib_Grow(appGlobals.connection, appGlobals.diskPath, size, FALSE, GrowProgressFunc, NULL);
Defragment an Existing Disk
VixDiskLib_Defragment() defragments an existing virtual disk. Defragmentation is effective with SPARSE type files, but might not do anything with FLAT type. In either case, the function returns VIX_OK. This function supports hosted disk, but not managed disk.
vixError = VixDiskLib_Defragment(disk.Handle(), DefragProgressFunc, NULL);
Defragment consolidates data in the 2GB extents, moving data to lower-numbered extents, and is independent of defragmentation tools in the guest OS, such as Disk > Properties > Tools > Defragmentation in Windows, or the defrag command for the Linux Ext2 file system.
VMware recommends defragmentation from the inside out: first within the virtual machine, then using this function or a VMware defragmentation tool, and finally within the host operating system.
Shrink an Existing Local Disk
VixDiskLib_Shrink() reclaims unused space in an existing virtual disk, unused space being recognized as blocks of zeroes. This is more effective (gains more space) with SPARSE type files than with pre-allocated FLAT type. On success, the function returns VIX_OK. This function supports hosted disk, but not managed disk.
vixError = VixDiskLib_Shrink(disk.Handle(), ShrinkProgressFunc, NULL);
In VMware system utilities, “prepare” zeros out unused blocks in the VMDK so “shrink” can reclaim them. In the API, use VixDiskLib_Write() to zero out unused blocks, and VixDiskLib_Shrink() to reclaim space. Shrink does not change the virtual disk capacity, but it makes more space available.
Unlink Extents to Remove Disk
VixDiskLib_Unlink() deletes all extents of the specified virtual disk, which unlinks (removes) the disk data. This is similar to the remove or erase command in a command tool.
vixError = VixDiskLib_Unlink(appGlobals.connection, appGlobals.diskPath);