decompress.c revision ae115bc77f6fcde83175c75b4206dc2e50747966
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Decompression module for stand alone file systems.
*/
#include <sys/sysmacros.h>
#ifdef _BOOT
#else
#endif
#define MAX_DECOMP_BUFS 8
#define GZIP_ID_BYTE_1 0x1f
#define GZIP_ID_BYTE_2 0x8b
#define GZIP_CM_DEFLATE 0x08
#define SEEKBUFSIZE 8192
#ifdef _BOOT
#else
#endif
extern int bootrd_debug;
extern void *bkmem_alloc(size_t);
extern void bkmem_free(void *, size_t);
int decomp_bufcnt; /* total no, of allocated decomp bufs */
int free_dcomp_bufs; /* no. of free decomp bufs */
int cf_debug; /* non-zero enables debug prints */
void *
{
unsigned int nbytes;
} else {
}
return (ptr);
}
/*
* Decompression scratch memory free routine, does nothing since we free
* the entire scratch area all at once on file close.
*/
/* ARGSUSED */
void
{
}
/*
* Read the first block of the file described by filep and determine if
* the file is gzip-compressed. If so, the compressed flag will be set
* in the fileid_t struct pointed to by filep and it will be initialized
* for doing decompression on reads to the file.
*/
int
{
unsigned char *filebytes;
return (-1);
return (0); /* not compressed */
/*
* Allocate decompress scratch buffer
*/
if (free_dcomp_bufs) {
} else {
}
filep->fi_dcscrused = 0;
/*
* Initialize the decompression stream
*/
return (-1);
return (0);
}
/*
* If the file described by fileid_t struct at *filep is compressed
* free any resources associated with the decompression. (decompression
* buffer, etc.).
*/
void
{
return;
if (free_dcomp_bufs == MAX_DECOMP_BUFS) {
} else {
}
}
void
{
(void) inflateReset(zsp);
}
/*
* Calculate the header length of a gzip compressed file
*/
static int
cf_headerlen(unsigned char *hp)
{
unsigned char flag;
if (flag & FLG_FEXTRA) {
}
if (flag & FLG_FCOMMENT)
return (hlen);
}
/*
* Read at the current uncompressed offset from the compressed file described
* by *filep. Will return decompressed data.
*/
int
{
/*
* read a block of the file to inflate
*/
return (-1);
/*
* If we are reading the first block of the file, we
* need to skip over the header bytes before inflating
*/
}
}
dprintf("attempting inflate of %x bytes to buf at: %lx\n",
/*
* break out if we hit end of the compressed file
* or the end of the compressed byte stream
*/
break;
}
}
/*
* Seek to the location specified by addr
*/
void
{
int readsz;
/*
* To seek backwards, must rewind and seek forwards
*/
} else {
}
while (addr > 0) {
}
}