[BusyBox] [patch] Add bunzip2 support to insmod

Stephen Warren swarren at wwwdotorg.org
Wed Aug 17 14:58:39 UTC 2005


Rob Landley wrote:
> On Tuesday 16 August 2005 20:50, Stephen Warren wrote:
>>Rob Landley wrote:
>>
>>>However, you shouldn't have to modify the generic bunzip code when I
>>>designed the sucker to be able to uncompress into a buffer.  I designed
>>>it so read_bunzip reads into a destination buffer that the caller
>>>provides and specifies the length of.  Don't muck up uncompressStream
>>>with a callback and a wrapper function.
>>
>>I would have just done that, except, how do I know how large to make the
>>output buffer? I didn't see any APIs in the bunzip code to say "given
>>this buffer, how big is the decompressed result".
>>
>>If there's a way to do that, then I'd prefer it too.
> 
> How are you figuring out how much space you need now?
> 
> Unless you store the uncompressed size in the file (which you could do), 
> determining the size requires decompressing it twice.  So what the current 
> code does instead is fill up a temporary buffer a chunk at a time and pass it 
> back to you until you stop asking for data.
> 
> It _can_ do short writes that way, and resume from them with the next call...

The basic algorithm is that I replaced the write() call in the bzip
decompression wrapper function with a callback function that's passed in
as a parameter (with the same prototype as write() so as to create
minimal changes).

The implementation of my write callback basically does this:

if (!size_left_in_the_big_output_buffer) {
  increase_size_of_output_buffer();
}
memcpy(to=big_output_buffer, from=small_buffer_used_in_bzip_algorithm)

the "big buffer" management is performed using mmap/mremap on a
private/anonymous mapping.

[Ah, finally found out why some of my messages aren't making it to the
mailing list; hence why this message will have a different ID to the one
that got through directly to Rob]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : http://lists.busybox.net/pipermail/busybox/attachments/20050817/878a7828/attachment.pgp 


More information about the busybox mailing list