linux/lib/decompress_bunzip2.c

/*	Small bzip2 deflate implementation, by Rob Landley ([email protected]).

	Based on bzip2 decompression code by Julian R Seward ([email protected]),
	which also acknowledges contributions by Mike Burrows, David Wheeler,
	Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten,
	Robert Sedgewick, and Jon L. Bentley.

	This code is licensed under the LGPLv2:
		LGPL (http://www.gnu.org/copyleft/lgpl.html
*/

/*
	Size and speed optimizations by Manuel Novoa III  ([email protected]).

	More efficient reading of Huffman codes, a streamlined read_bunzip()
	function, and various other tweaks.  In (limited) tests, approximately
	20% faster than bzcat on x86 and about 10% faster on arm.

	Note that about 2/3 of the time is spent in read_unzip() reversing
	the Burrows-Wheeler transformation.  Much of that time is delay
	resulting from cache misses.

	I would ask that anyone benefiting from this work, especially those
	using it in commercial products, consider making a donation to my local
	non-profit hospice organization in the name of the woman I loved, who
	passed away Feb. 12, 2003.

		In memory of Toni W. Hagan

		Hospice of Acadiana, Inc.
		2600 Johnston St., Suite 200
		Lafayette, LA 70503-3240

		Phone (337) 232-1234 or 1-800-738-2226
		Fax   (337) 232-1297

		https://www.hospiceacadiana.com/

	Manuel
 */

/*
	Made it fit for running in Linux Kernel by Alain Knaff ([email protected])
*/


#ifdef STATIC
#define PREBOOT
#else
#include <linux/decompress/bunzip2.h>
#endif /* STATIC */

#include <linux/decompress/mm.h>
#include <linux/crc32poly.h>

#ifndef INT_MAX
#define INT_MAX
#endif

/* Constants for Huffman coding */
#define MAX_GROUPS
#define GROUP_SIZE
#define MAX_HUFCODE_BITS
#define MAX_SYMBOLS
#define SYMBOL_RUNA
#define SYMBOL_RUNB

/* Status return values */
#define RETVAL_OK
#define RETVAL_LAST_BLOCK
#define RETVAL_NOT_BZIP_DATA
#define RETVAL_UNEXPECTED_INPUT_EOF
#define RETVAL_UNEXPECTED_OUTPUT_EOF
#define RETVAL_DATA_ERROR
#define RETVAL_OUT_OF_MEMORY
#define RETVAL_OBSOLETE_INPUT

/* Other housekeeping constants */
#define BZIP2_IOBUF_SIZE

/* This is what we know about each Huffman coding group */
struct group_data {};

/* Structure holding all the housekeeping data, including IO buffers and
   memory that persists between calls to bunzip */
struct bunzip_data {};


/* Return the next nnn bits of input.  All reads from the compressed input
   are done through this function.  All reads are big endian */
static unsigned int INIT get_bits(struct bunzip_data *bd, char bits_wanted)
{}

/* Unpacks the next block and sets up for the inverse burrows-wheeler step. */

static int INIT get_next_block(struct bunzip_data *bd)
{}

/* Undo burrows-wheeler transform on intermediate buffer to produce output.
   If start_bunzip was initialized with out_fd =-1, then up to len bytes of
   data are written to outbuf.  Return value is number of bytes written or
   error (all errors are negative numbers).  If out_fd!=-1, outbuf and len
   are ignored, data is written to out_fd and return is RETVAL_OK or error.
*/

static int INIT read_bunzip(struct bunzip_data *bd, char *outbuf, int len)
{}

static long INIT nofill(void *buf, unsigned long len)
{}

/* Allocate the structure, read file header.  If in_fd ==-1, inbuf must contain
   a complete bunzip file (len bytes long).  If in_fd!=-1, inbuf and len are
   ignored, and data is read from file handle into temporary buffer. */
static int INIT start_bunzip(struct bunzip_data **bdp, void *inbuf, long len,
			     long (*fill)(void*, unsigned long))
{}

/* Example usage: decompress src_fd to dst_fd.  (Stops at end of bzip2 data,
   not end of file.) */
STATIC int INIT bunzip2(unsigned char *buf, long len,
			long (*fill)(void*, unsigned long),
			long (*flush)(void*, unsigned long),
			unsigned char *outbuf,
			long *pos,
			void(*error)(char *x))
{}

#ifdef PREBOOT
STATIC int INIT __decompress(unsigned char *buf, long len,
			long (*fill)(void*, unsigned long),
			long (*flush)(void*, unsigned long),
			unsigned char *outbuf, long olen,
			long *pos,
			void (*error)(char *x))
{
	return bunzip2(buf, len - 4, fill, flush, outbuf, pos, error);
}
#endif