[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: dd: add 'skip_bytes' and 'count_bytes' operands
From: |
Pádraig Brady |
Subject: |
Re: dd: add 'skip_bytes' and 'count_bytes' operands |
Date: |
Wed, 08 Feb 2012 16:16:09 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110816 Thunderbird/6.0 |
On 02/08/2012 03:14 PM, 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 ?
Old legacy stuff we must support,
and just presented for illustration.
2b = 2 blocks = 2x512
Another anomaly with the existing number syntax is that
'B' is used to indicate base 10 which is awkward.
Ideally M would be base 10 and Mi base 2. I.E.
skip=2 => skip 2 blocks
skip=2K => skip 2000 blocks
skip=2Ki => skip 2048 blocks
skip=2KiB => skip 2048 bytes
For completeness what the above actually mean are:
skip=2 => skip 2 blocks
skip=2K => skip 2048 blocks
skip=2Ki => invalid
skip=2KiB => skip 2048 blocks
But I'm sure that 'M' etc. is really old and hence
we have this awkwardness for backwards compat reasons.
A prime example of why we should be careful of the
interface before committing.
Anyway the existing 'B' means we could have this awkward form:
skip=2MBbytes
Maybe it's better to use '_bytes' as the tag.
skip=3KB_bytes
skip=2_bytes
Not too bad. A variation to tagging the number directly,
would be to add flags:
iflag=skip_bytes # Treat skip as number of bytes not blocks
iflag=count_bytes # Treat count as number of bytes not blocks
oflag=seek_bytes # Treat seek as number of bytes not blocks
While cleaner it's a bit less direct.
Though since this is slightly off the main use case,
I guess flags are OK.
> 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.
All was done already. See parse_integer().
If going with the '_bytes' tag then all that would
need to be done is something like:
if opt in ('skip', 'seek', 'count'):
if optarg.endswith('_bytes'):
opt_bytes_mode = True
optarg = optarg[:-6] # strip tag
parse_integer(optarg)
if opt_bytes_mode:
handle_as_in_previous_patch()
else:
handle_value()
Though as stated above, the flag's option is probably best.
Sorry for the churn on this, but I've not had
time to think about it and I'm just reacting to your
questions on the fly. At least the decision
process for the interface is documented.
cheers,
Pádraig.
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, (continued)
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Jérémy Compostella, 2012/02/06
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Pádraig Brady, 2012/02/06
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Jérémy Compostella, 2012/02/07
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Pádraig Brady, 2012/02/07
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Jérémy Compostella, 2012/02/08
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Jérémy Compostella, 2012/02/08
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Eric Blake, 2012/02/08
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Erik Auerswald, 2012/02/08
- RE: dd: add 'skip_bytes' and 'count_bytes' operands, Voelker, Bernhard, 2012/02/09
- Re: dd: add 'skip_bytes' and 'count_bytes' operands,
Pádraig Brady <=
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Jérémy Compostella, 2012/02/08
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Jérémy Compostella, 2012/02/10
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Pádraig Brady, 2012/02/10
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Pádraig Brady, 2012/02/11
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Pádraig Brady, 2012/02/13
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Bernhard Voelker, 2012/02/13
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Pádraig Brady, 2012/02/13
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Bernhard Voelker, 2012/02/13
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Pádraig Brady, 2012/02/13
- Re: dd: add 'skip_bytes' and 'count_bytes' operands, Bernhard Voelker, 2012/02/13