/* Returns length of decompressed data. */
int cramfs_uncompress_block_gzip(void *dst, int dstlen, void *src, int srclen)
{
	int err;

	stream.next_in = src;
	stream.avail_in = srclen;

	stream.next_out = dst;
	stream.avail_out = dstlen;

	err = zlib_inflateReset(&stream);
	if (err != Z_OK) {
		printk("zlib_inflateReset error %d\n", err);
		zlib_inflateEnd(&stream);
		zlib_inflateInit(&stream);
	}

	err = zlib_inflate(&stream, Z_FINISH);
	if (err != Z_STREAM_END)
		goto err;
	return stream.total_out;

err:
	printk("Error %d while decompressing!\n", err);
	printk("%p(%d)->%p(%d)\n", src, srclen, dst, dstlen);
	return 0;
}
Beispiel #2
0
/**
 *	z_decomp_reset - reset a previously-allocated decompressor.
 *	@arg:	pointer to private state for the decompressor.
 *
 *	This clears the history for the decompressor and makes it
 *	ready to receive a new compressed stream.
 */
static void z_decomp_reset(void *arg)
{
	struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;

	state->seqno = 0;
	zlib_inflateReset(&state->strm);
}
Beispiel #3
0
int sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,
	      struct sized_buf *dst)
{
	int err, by_lzma = 1;
	if (un->un_lzma && is_lzma(*src->buf)) {
		un->un_cmbuf = src->buf;
		un->un_cmlen = src->sz;
		un->un_resbuf = dst->buf;
		un->un_reslen = dst->sz;

		/* this library is thread-safe */
		err = LzmaUncompress(un);
		goto out;
	}

	by_lzma = 0;

//#if defined(CONFIG_MIPS_BRCM)
#if 1//disable zlib inflate
    /* The FS is compressed with LZMA for BRCM: do not use zlib */
    printk("%s: ZLIB decompression is not supported\n", __func__);
    err = -EINVAL;
#else
	err = zlib_inflateReset(&un->un_stream);
	if (unlikely(err != Z_OK))
		goto out;
	un->un_stream.next_in = src->buf;
	un->un_stream.avail_in = src->sz;
	un->un_stream.next_out = dst->buf;
	un->un_stream.avail_out = dst->sz;
	err = zlib_inflate(&un->un_stream, Z_FINISH);
	if (err == Z_STREAM_END)
		err = 0;
#endif 
 out:
	if (unlikely(err)) {
#ifdef __KERNEL__
		WARN_ON_ONCE(1);
#else
		char a[64] = "ZLIB ";
		if (by_lzma) {
			strcpy(a, "LZMA ");
#ifdef _REENTRANT
			strerror_r(err, a + 5, sizeof(a) - 5);
#else
			strncat(a, strerror(err), sizeof(a) - 5);
#endif
		} else
			strncat(a, zError(err), sizeof(a) - 5);
		fprintf(stderr, "%s: %.*s\n", __func__, sizeof(a), a);
#endif
	}
	return err;
}
Beispiel #4
0
static int zlib_decompress_init(struct crypto_pcomp *tfm)
{
	int ret;
	struct zlib_ctx *dctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
	struct z_stream_s *stream = &dctx->decomp_stream;

	ret = zlib_inflateReset(stream);
	if (ret != Z_OK)
		return -EINVAL;

	return 0;
}
int zlib_inflateSync(
	z_streamp z
)
{
  uInt n;       /* number of bytes to look at */
  Byte *p;      /* pointer to bytes */
  uInt m;       /* number of marker bytes found in a row */
  uLong r, w;   /* temporaries to save total_in and total_out */

  /* set up */
  if (z == NULL || z->state == NULL)
    return Z_STREAM_ERROR;
  if (z->state->mode != I_BAD)
  {
    z->state->mode = I_BAD;
    z->state->sub.marker = 0;
  }
  if ((n = z->avail_in) == 0)
    return Z_BUF_ERROR;
  p = z->next_in;
  m = z->state->sub.marker;

  /* search */
  while (n && m < 4)
  {
    static const Byte mark[4] = {0, 0, 0xff, 0xff};
    if (*p == mark[m])
      m++;
    else if (*p)
      m = 0;
    else
      m = 4 - m;
    p++, n--;
  }

  /* restore */
  z->total_in += p - z->next_in;
  z->next_in = p;
  z->avail_in = n;
  z->state->sub.marker = m;

  /* return no joy or set up to restart on a new block */
  if (m != 4)
    return Z_DATA_ERROR;
  r = z->total_in;  w = z->total_out;
  zlib_inflateReset(z);
  z->total_in = r;  z->total_out = w;
  z->state->mode = BLOCKS;
  return Z_OK;
}
Beispiel #6
0
int sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,
	      struct sized_buf *dst)
{
	int err, by_lzma = 0;
	if (un->un_lzma && is_lzma(*src->buf)) {
		by_lzma = 1;
		un->un_cmbuf = src->buf;
		un->un_cmlen = src->sz;
		un->un_resbuf = dst->buf;
		un->un_reslen = dst->sz;

		/* this library is thread-safe */
		err = LzmaUncompress(un);
		goto out;
	}

	err = zlib_inflateReset(&un->un_stream);
	if (unlikely(err != Z_OK))
		goto out;
	un->un_stream.next_in = src->buf;
	un->un_stream.avail_in = src->sz;
	un->un_stream.next_out = dst->buf;
	un->un_stream.avail_out = dst->sz;
	err = zlib_inflate(&un->un_stream, Z_FINISH);
	if (err == Z_STREAM_END)
		err = 0;

 out:
	if (err) {
#ifdef __KERNEL__
		WARN_ON_ONCE(1);
#else
		char a[64] = "ZLIB ";
		if (by_lzma) {
			strcpy(a, "LZMA ");
#ifdef _REENTRANT
			strerror_r(err, a + 5, sizeof(a) - 5);
#else
			strncat(a, strerror(err), sizeof(a) - 5);
#endif
		} else
			strncat(a, zError(err), sizeof(a) - 5);
		fprintf(stderr, "%s: %.*s\n", __func__, sizeof(a), a);
#endif
	}
	return err;
}
Beispiel #7
0
static void
gzip1_decompress(coa_t coa, __u8 * src_first, size_t src_len,
                 __u8 * dst_first, size_t *dst_len)
{
    int ret = 0;
    struct z_stream_s stream;

    assert("edward-843", coa != NULL);
    assert("edward-876", src_len != 0);

    stream.workspace = coa;
    ret = zlib_inflateInit2(&stream, -GZIP1_DEF_WINBITS);
    if (ret != Z_OK) {
        warning("edward-774", "zlib_inflateInit2 returned %d\n", ret);
        return;
    }
    ret = zlib_inflateReset(&stream);
    if (ret != Z_OK) {
        warning("edward-775", "zlib_inflateReset returned %d\n", ret);
        return;
    }

    stream.next_in = src_first;
    stream.avail_in = src_len;
    stream.next_out = dst_first;
    stream.avail_out = *dst_len;

    ret = zlib_inflate(&stream, Z_SYNC_FLUSH);
    /*
     * Work around a bug in zlib, which sometimes wants to taste an extra
     * byte when being used in the (undocumented) raw deflate mode.
     * (From USAGI).
     */
    if (ret == Z_OK && !stream.avail_in && stream.avail_out) {
        u8 zerostuff = 0;
        stream.next_in = &zerostuff;
        stream.avail_in = 1;
        ret = zlib_inflate(&stream, Z_FINISH);
    }
    if (ret != Z_STREAM_END) {
        warning("edward-776", "zlib_inflate returned %d\n", ret);
        return;
    }
    *dst_len = stream.total_out;
    return;
}
Beispiel #8
0
static int deflate_decompress(struct crypto_tfm *tfm, const u8 *src,
                              unsigned int slen, u8 *dst, unsigned int *dlen)
{

    int ret = 0;
    struct deflate_ctx *dctx = crypto_tfm_ctx(tfm);
    struct z_stream_s *stream = &dctx->decomp_stream;

    ret = zlib_inflateReset(stream);
    if (ret != Z_OK) {
        ret = -EINVAL;
        goto out;
    }

    stream->next_in = (u8 *)src;
    stream->avail_in = slen;
    stream->next_out = (u8 *)dst;
    stream->avail_out = *dlen;

    ret = zlib_inflate(stream, Z_SYNC_FLUSH);
    /*
     * Work around a bug in zlib, which sometimes wants to taste an extra
     * byte when being used in the (undocumented) raw deflate mode.
     * (From USAGI).
     */
    if (ret == Z_OK && !stream->avail_in && stream->avail_out) {
        u8 zerostuff = 0;
        stream->next_in = &zerostuff;
        stream->avail_in = 1;
        ret = zlib_inflate(stream, Z_FINISH);
    }
    if (ret != Z_STREAM_END) {
        ret = -EINVAL;
        goto out;
    }
    ret = 0;
    *dlen = stream->total_out;
out:
    return ret;
}
Beispiel #9
0
/**
 *	z_decomp_init - initialize a previously-allocated decompressor.
 *	@arg:	pointer to the private state for the decompressor
 *	@options: pointer to the CCP option data describing the
 *		compression that was negotiated with the peer
 *	@opt_len: length of the CCP option data at @options
 *	@unit:	PPP unit number for diagnostic messages
 *	@hdrlen: ignored (present for backwards compatibility)
 *	@mru:	maximum length of decompressed packets
 *	@debug:	debug flag; if non-zero, debug messages are printed.
 *
 *	The CCP options described by @options must match the options
 *	specified when the decompressor was allocated.  The decompressor
 *	history is reset.  Returns 0 for failure (CCP options don't
 *	match) or 1 for success.
 */
static int z_decomp_init(void *arg, unsigned char *options, int opt_len,
			 int unit, int hdrlen, int mru, int debug)
{
	struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;

	if (opt_len < CILEN_DEFLATE
	    || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
	    || options[1] != CILEN_DEFLATE
	    || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
	    || DEFLATE_SIZE(options[2]) != state->w_size
	    || options[3] != DEFLATE_CHK_SEQUENCE)
		return 0;

	state->seqno = 0;
	state->unit  = unit;
	state->debug = debug;
	state->mru   = mru;

	zlib_inflateReset(&state->strm);

	return 1;
}