Sufficiently Advanced Technology, or Magic?
September 3, 2012 10:54 PM Subscribe
How can a virtual machine track the guest OS's use of an emulated disk?
posted by spacewrench to computers & internet (9 answers total) 1 user marked this as a favorite
I use Parallels-7 Desktop on a MacBook Pro, and I run various guest OSes (Linux & Windows) using emulated (MacOS file) disks. From time to time, Parallels notifies me that a guest OS has freed a lot of space on one of these disks, and it offers to compress the MacOS file to reduce (real) disk usage.
How can a virtual machine determine whether an emulated disk sector is in-use or free?
I'd guess the simple way to do an emulated disk is just to tell the guest OS how big it is, and accept and store data blocks at whatever address the guest OS says it wants to write. You wouldn't have to allocate the whole file at once (and it seems this is what Parallels does: the "10GB" disk my guest OS sees only takes a few actual gigs in the Mac filesystem, at least until the guest OS disk gets full). You just keep track of what blocks have been written, and return zeros if the guest reads a block that it hasn't written yet.
However, I don't see how Parallels can know when a sector that the guest previously wrote, goes out of use, unless the guest OS somehow notifies it. And if there is such a notification, it seems that it would be a perfect place to write random data to the newly-freed block to prevent recovery of deleted files, etc.
I have some familiarity with filesystem logic & operations, but I've never heard of a "free-data-block" event. Is this something new? Or is there an even cooler trick Parallels uses to detect unused blocks?