static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len, u64 *decompress_len) { size_t new_len; size_t in_len; size_t out_len = 0; size_t tot_len; size_t tot_in; int ret; ret = lzo_init(); if (ret != LZO_E_OK) { fprintf(stderr, "lzo init returned %d\n", ret); return -1; } tot_len = read_compress_length(inbuf); inbuf += LZO_LEN; tot_in = LZO_LEN; while (tot_in < tot_len) { in_len = read_compress_length(inbuf); if ((tot_in + LZO_LEN + in_len) > tot_len) { fprintf(stderr, "bad compress length %lu\n", (unsigned long)in_len); return -1; } inbuf += LZO_LEN; tot_in += LZO_LEN; new_len = lzo1x_worst_compress(PAGE_CACHE_SIZE); ret = lzo1x_decompress_safe((const unsigned char *)inbuf, in_len, (unsigned char *)outbuf, (void *)&new_len, NULL); if (ret != LZO_E_OK) { fprintf(stderr, "failed to inflate: %d\n", ret); return -1; } out_len += new_len; outbuf += new_len; inbuf += in_len; tot_in += in_len; } *decompress_len = out_len; return 0; }
static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len, u64 *decompress_len) { size_t new_len; size_t in_len; size_t out_len = 0; size_t tot_len; size_t tot_in; int ret; ret = lzo_init(); if (ret != LZO_E_OK) { fprintf(stderr, "lzo init returned %d\n", ret); return -1; } tot_len = read_compress_length(inbuf); inbuf += LZO_LEN; tot_in = LZO_LEN; while (tot_in < tot_len) { size_t mod_page; size_t rem_page; in_len = read_compress_length(inbuf); if ((tot_in + LZO_LEN + in_len) > tot_len) { fprintf(stderr, "bad compress length %lu\n", (unsigned long)in_len); return -1; } inbuf += LZO_LEN; tot_in += LZO_LEN; new_len = lzo1x_worst_compress(PAGE_CACHE_SIZE); ret = lzo1x_decompress_safe((const unsigned char *)inbuf, in_len, (unsigned char *)outbuf, (void *)&new_len, NULL); if (ret != LZO_E_OK) { fprintf(stderr, "failed to inflate: %d\n", ret); return -1; } out_len += new_len; outbuf += new_len; inbuf += in_len; tot_in += in_len; /* * If the 4 byte header does not fit to the rest of the page we * have to move to the next one, unless we read some garbage */ mod_page = tot_in % PAGE_CACHE_SIZE; rem_page = PAGE_CACHE_SIZE - mod_page; if (rem_page < LZO_LEN) { inbuf += rem_page; tot_in += rem_page; } } *decompress_len = out_len; return 0; }
static int decompress_lzo(struct btrfs_root *root, unsigned char *inbuf, char *outbuf, u64 compress_len, u64 *decompress_len) { size_t new_len; size_t in_len; size_t out_len = 0; size_t tot_len; size_t tot_in; int ret; ret = lzo_init(); if (ret != LZO_E_OK) { error("lzo init returned %d", ret); return -1; } tot_len = read_compress_length(inbuf); inbuf += LZO_LEN; tot_in = LZO_LEN; while (tot_in < tot_len) { size_t mod_page; size_t rem_page; in_len = read_compress_length(inbuf); if ((tot_in + LZO_LEN + in_len) > tot_len) { error("bad compress length %lu", (unsigned long)in_len); return -1; } inbuf += LZO_LEN; tot_in += LZO_LEN; new_len = lzo1x_worst_compress(root->fs_info->sectorsize); ret = lzo1x_decompress_safe((const unsigned char *)inbuf, in_len, (unsigned char *)outbuf, (void *)&new_len, NULL); if (ret != LZO_E_OK) { error("lzo decompress failed: %d", ret); return -1; } out_len += new_len; outbuf += new_len; inbuf += in_len; tot_in += in_len; /* * If the 4 byte header does not fit to the rest of the page we * have to move to the next one, unless we read some garbage */ mod_page = tot_in % root->fs_info->sectorsize; rem_page = root->fs_info->sectorsize - mod_page; if (rem_page < LZO_LEN) { inbuf += rem_page; tot_in += rem_page; } } *decompress_len = out_len; return 0; }