[libvirt] [PATCH 3/3] Add volume zeroing

Eric Blake ebb9 at byu.net
Tue Feb 16 04:29:47 UTC 2010


According to Dave Allan on 2/15/2010 9:08 PM:
>> ftruncate (fd, 0);
>> ftruncate (fd, st.st_size);
>>
> That's a good point.  The only thing that makes me hesitate is that I'm
> not certain that the file is guaranteed to contain zeros following the
> second call to ftruncate, and I'm having trouble coming up with the
> relevant spec at the moment.

For regular files, POSIX guarantees that extending a file via ftruncate
will give zeros following the previous length.
http://www.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html
"If the file previously was smaller than this size, ftruncate() shall
increase the size of the file. If the file size is increased, the extended
area shall appear as if it were zero-filled."

But for all other file types (such as block devices), the results are
unspecified by POSIX.

-- 
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9 at byu.net




More information about the libvir-list mailing list