coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dd: add 'skip_bytes' and 'count_bytes' operands


From: Eric Blake
Subject: Re: dd: add 'skip_bytes' and 'count_bytes' operands
Date: Wed, 08 Feb 2012 09:05:43 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20120131 Thunderbird/10.0

On 02/08/2012 08:14 AM, Jérémy Compostella wrote:
>> That leads onto the only other possible implementation I suppose.
>> I.E. since we don't need to specify skip and skip_bytes together,
>> the option value could select between each mode. I.E.
>>
>> skip=2      => skip    2 blocks,
>> skip=2b     => skip 1024 blocks,
>> skip=2bytes => skip    2 bytes
>>
>> Hmm, that's not too bad at all really
> I do agree, it looks like a very interesting idea indeed. However, I
> have two questions:
> 1. Why skip=2b => 1024 blocks ?

Because POSIX requires that one.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/dd.html

For the bs=, cbs=, ibs=, and obs= operands, the application shall supply
an expression specifying a size in bytes. The expression, expr, can be:

    A positive decimal number

    A positive decimal number followed by k, specifying multiplication
by 1024

    A positive decimal number followed by b, specifying multiplication
by 512

    Two or more positive decimal numbers (with or without k or b)
separated by x, specifying the product of the indicated values

> 2. Do you know if there is a utility function somewhere in coreutils or
> gnulib which could help me to parse this ? If such a function exists it
> could be able to manage more units (bytes, kbytes, megabytes, ...). If
> have to write such a function we have to discuss the possibilities I have to
> provide.

See how parse_integer() is already using xstrtoumax; it would just be a
matter of special-casing 'bytes', differently than 'b', and more like
'x' is special-cased.

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]