Subject: Re: bug#6268: Suggestion: truncate should allow -r and -s options together

From: Eric Blake <[email-masked]>
Date: Tue, 01 Jun 2010 09:53:48 -0600

On 05/31/2010 02:50 AM, Pádraig Brady wrote:
>> So the user could use:
>> 	truncate --ref=- -s +5G myfile < /dev/sda5
>>
>> Just a thought ...
> 
> Well we never supported referencing stdin as
> we stat() the name. Also one needs to use a separate
> operation to get the size of a block device,
> so before the patch we just returned 0 which was invalid.
> 
> I wrote a comment in the code to say referencing
> the size of a block device is probably useful,
> but we'll need to worry about portability of that.

The only portable way to get the size of a block device is to open() it,
then do lseek(fd,0,SEEK_END).  Other more efficient methods, like an
ioctl, may exist for some platforms, but then it could become a
maintenance nightmare to figure out where the shortcuts are available.

-- 
Eric Blake   [email-masked]    +1-801-349-2682
Libvirt virtualization library http://libvirt.org