Hi Étienne,

> Le 17 mai 2020 à 22:24, Etienne Champetier <champetier.etie...@gmail.com> a 
> écrit :
> 
> Hi Thibaut,
> 
> Le dim. 17 mai 2020 à 15:46, Thibaut VARÈNE <ha...@slashdirt.org 
> <mailto:ha...@slashdirt.org>> a écrit :
>> 
>> -       dd if=$source of=$target iflag=skip_bytes bs=$count skip=$offset 
>> count=1 2>/dev/null || \
>> +       # dd doesn't handle partial reads from special files: use cat
>> +       cat $source | dd of=$target iflag=skip_bytes bs=$count skip=$offset 
>> count=1 2>/dev/null || \
> 
> Not way more elegant, but you could use something like
> tail -c+$start $source | head -c$count > $target
> with $start == $offset+1 I think
> 
> # head -c10 /dev/zero | wc
>        0         0        10
> # head -c10 /dev/zero | tail -c+3 | wc
>        0         0         8

I’m not sure there’s a good reason to do it that way: my change barely touches 
the current logic: it is trivial to confirm that it doesn’t break anything that 
was previously working. On the other hand, doing away with dd entirely will 
need more proofing, and if some extra dd flag is needed in the future it will 
have to be reinstated.

Your approach also puts more burden on the shell (it uses redirection to output 
the final file).
All in all I’m afraid it doesn’t look more elegant to me, and it seems less 
efficient too.

The really clean fix which isn’t available to us as busybox dd doesn’t support 
the ‘count_bytes’ iflag would be something along those lines:

dd if=$source of=$target iflag=skip_bytes,count_bytes bs=$PAGE_SIZE 
skip=$offset count=$count

And then everything would work correctly. This is a different approach which I 
tested successfully with the « real » dd.

Cheers,
Thibaut

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to