One of the tasks listed in Use Cases for the Virtual Disk Library is to scan a VMDK for virus signatures. Using the framework of our sample program, a function can implement the
-virus command-line option. The function in
Example: Function to Scan VMDK for Viruses relies on a pre-existing library routine called
SecureVirusScan(), which typically is supplied by a vendor of antivirus software. As it does for email messages, the library routine scans a buffer of any size against the vendor’s latest pattern library, and returns TRUE if it identifies a virus.
This function calls VixDiskLib_GetInfo() to determine the number of sectors allocated in the virtual disk. The number of sectors is available in the
VixDiskLibDiskInfo structure, but normally not in the metadata. With
SPARSE type layout, data can occur in any sector, so this function reads all sectors, whether filled or not.
VixDiskLib_Read() continues without error when it encounters an empty sector full of zeroes.