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

Dave Allan dallan at redhat.com
Tue Feb 16 15:17:12 UTC 2010


On 02/15/2010 11:29 PM, Eric Blake wrote:
> 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.

That's ok, I was only asking about behavior with regular files here. 
Thanks for the pointer--that's exactly what I was looking for.

Dave




More information about the libvir-list mailing list