[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#6268: Suggestion: truncate should allow -r and -s options together
From: |
Eric Blake |
Subject: |
bug#6268: Suggestion: truncate should allow -r and -s options together |
Date: |
Tue, 01 Jun 2010 09:53:48 -0600 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100430 Fedora/3.0.4-3.fc13 Lightning/1.0b2pre Mnenhy/0.8.2 Thunderbird/3.0.4 |
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 address@hidden +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature