VixDiskLib_Attach() attaches the child disk into its parent disk chain. Afterwards, the parent handle is invalid and the child handle represents the combined disk chain of redo logs. On failure (vixError != VIX_OK) the parent handle is also invalid, so do not close it.

vixError = VixDiskLib_Attach(parent.Handle(), child.Handle());

For example, suppose you want to access the older disk image recorded by Child1. Attach the handle of new Child1a to Child1, which provides Child1a’s parent handle, as shown below. It is now permissible to open, read, and write the Child1a virtual disk.

The parent-child disk chain is efficient in terms of storage space, because the child VMDK records only the sectors that changed since the last VixDiskLib_CreateChild(). The parent-child disk chain also provides a redo mechanism, permitting programmatic access to any generation with VixDiskLib_Attach().

Figure 1. Child disk attached to disk chain
Shows how a child disk can be attached to the middle of a disk chain.

Before VDDK 6.7.1 it was an error to close parentHandle after VixDiskLib_Attach succeeds. The VDDK library now marks parentHandle internally to prevent closure and ensure cleanup. Here is the calling sequence for open and attach:

  1. Open the disk for attach.
  2. Create a local connection.
  3. With backed-up disk (referred to as the parent disk) still open, create child disk with a unique name.
  4. Open uniquely named tmp.vmdk (referred to as the redo log).
  5. Attach the redo log to its parent disk.
VixDiskLib_Open(remoteConnection, virtualDiskPath, flags, &parentHandle);
VixDiskLib_Connect(NULL, &localConnection);
VixDiskLib_CreateChild(parentHandle, "C:\tmp.vmdk", VIXDISKLIB_DISK_MONOLITHIC_SPARSE, NULL, NULL);
VixDiskLib_Open(localConnection, "C:\tmp.vmdk", VIXDISKLIB_FLAG_OPEN_SINGLE_LINK, &redoHandle);
VixDiskLib_Attach(parentHandle, redoHandle);

Here is the calling sequence for close:

  1. Close the redo log. Whether to close the parent disk handle is release dependent.
  2. Unlink the redo log to detach it from the parent disk.
VixDiskLib_Close(redoHandle);
if (VIXDISKLIB_VERSION_MAJOR > 7) {
   VixDiskLib_Close(parentHandle); // to avoid memory leaks
}
VixDiskLib_Unlink(localConnection, "C:\tmp.vmdk");