Reading and Writing Local Disk

Demonstrating random I/O, this function reads a sector at a time backwards through a VMDK. If it sees the string “VmWare” it substitutes the string “VMware” in its place and writes the sector back to VMDK.

#include <string>
static void DoEdit(void)/
{
    VixDisk disk(appGlobals.connection, appGlobals.diskPath, appGlobals.openFlags);
    uint8 buf[VIXDISKLIB_SECTOR_SIZE];
    VixDiskLibSectorType i;
    string str;
    for (i = appGlobals.numSectors; i >= 0; i--) {
       VixError vixError;
       vixError = VixDiskLib_Read(disk.Handle(), appGlobals.startSector + i, 1, buf);
       CHECK_AND_THROW(vixError);
       str = buf;
       if (pos = str.find("VmWare", 0)) {
          str.replace(pos, 5, "VMware");
          buf = str;
          vixError = VixDiskLib_Write(disk.Handle(), appGlobals.startSector + i, 1, buf);
          CHECK_AND_THROW(vixError);
       }
    }
}