Disk Operations
These functions create, open, read, write, query, and close virtual disk.
Create a New Hosted Disk
VixDiskLib_Create() locally creates a new virtual disk, after being connected to the host. In createParams, you must specify the disk type, adapter, hardware version, and capacity as a number of sectors. This function supports hosted disk. For managed disk, first create a hosted type virtual disk, then use VixDiskLib_Clone() to convert the virtual disk to managed disk.
vixError =
VixDiskLib_Create(appGlobals.connection, appGlobals.diskPath, &createParams, NULL, NULL);
Currently VixDiskLib_Create() enforces a 4GB limit for virtual disks on FAT32 and FAT file systems, a 16TB - 54KB (hex FFFFFFF0000) limit on NTFS file systems, and a 2^64 - 1 limit (more than an exabyte) on ReFS and exFAT file systems. Hosted virtual disk > 2TB is not supported.
POSIX based file systems including NFS version 3 no longer have a 2GB file size limit. Although various checks are done to avoid creating impossibly large files, it becomes the customer’s responsibility to cope with 2GB limits on NFS version 2 or Linux kernel 2.4 (EFS).
Open a Local or Remote Disk
After the library connects to a workstation or server, VixDiskLib_Open() opens a virtual disk. With SAN or HotAdd transport, opening a remote disk for writing requires a pre-existing snapshot.
vixError =
VixDiskLib_Open(appGlobals.connection, appGlobals.diskPath, appGlobals.openFlags, &srcHandle);
The following flags modify the open instruction:
VIXDISKLIB_FLAG_OPEN_UNBUFFERED – Disable host disk caching.
VIXDISKLIB_FLAG_OPEN_SINGLE_LINK – Open the current link, not the entire chain (hosted disk only).
VIXDISKLIB_FLAG_OPEN_READ_ONLY – Open the virtual disk read-only.
As of vSphere 6.5, the following additional flags are available:
VIXDISKLIB_FLAG_OPEN_COMPRESSION_ZLIB – Open for NBDSSL transport, zlib compression.
VIXDISKLIB_FLAG_OPEN_COMPRESSION_FASTLZ – Open for NBDSSL transport, fastlz compression.
VIXDISKLIB_FLAG_OPEN_COMPRESSION_SKIPZ – Open for NBDSSL transport, skipz compression.
Read Sectors From a Disk
VixDiskLib_Read() reads a range of sectors from an open virtual disk. You specify the beginning sector and the number of sectors. Sector size could vary, but is defined in <vixDiskLib.h> as 512 bytes because VMDK files have that sector size.
vixError = VixDiskLib_Read(srcHandle, i, j, buf);
Write Sectors To a Disk
VixDiskLib_Write() writes one or more sectors to an open virtual disk. This function expects the fourth parameter buf to be VIXDISKLIB_SECTOR_SIZE bytes long.
vixError = VixDiskLib_Write(newDisk.Handle(), i, j, buf);
Close a Local or Remote Disk
VixDiskLib_Close() closes an open virtual disk.
VixDiskLib_Close() returns VIX_OK if successful, otherwise a suitable error code. To obtain a list of possible return codes, see Finding Error Code Documentation.
If a program has worker threads called from a master process, errors might occur in the threads after the master process calls VixDiskLib_Close(). Always wait for worker threads to end before calling close.
Get Information About a Disk
vixError = VixDiskLib_GetInfo(srcHandle, diskInfo);
VixDiskLib_GetInfo() gets data about an open virtual disk, allocating a filled-in VixDiskLibDiskInfo structure. Some of this information overlaps with metadata (see Metadata Handling).
Free Memory from Get Information
This function deallocates memory allocated by VixDiskLib_GetInfo(). Call it to avoid a memory leak.
vixError = VixDiskLib_FreeInfo(diskInfo);