39 #include <linux/types.h>
43 #include <linux/compiler.h>
44 #include <asm/unaligned.h>
46 static const unsigned char lzop_magic[] = {
47 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a };
49 #define LZO_BLOCK_SIZE (256*1024l)
50 #define HEADER_HAS_FILTER 0x00000800L
51 #define HEADER_SIZE_MIN (9 + 7 + 4 + 8 + 1 + 4)
52 #define HEADER_SIZE_MAX (9 + 7 + 1 + 8 + 8 + 4 + 1 + 255 + 4)
71 for (l = 0; l < 9; l++) {
72 if (*parse++ != lzop_magic[l])
78 version = get_unaligned_be16(parse);
80 if (version >= 0x0940)
93 if (end - parse < 8 + 1 + 4)
98 if (version >= 0x0940)
103 if (end - parse < l + 4)
107 *skip = parse -
input;
112 int (*
fill) (
void *,
unsigned int),
113 int (*flush) (
void *,
unsigned int),
114 u8 *output,
int *posp,
119 u32 src_len, dst_len;
121 u8 *in_buf, *in_buf_save, *out_buf;
127 error(
"NULL output pointer and no flush function provided");
132 error(
"Could not allocate output buffer");
138 error(
"Both input pointer and fill function provided, don't know what to do");
143 error(
"NULL input pointer and missing fill function");
148 error(
"Could not allocate input buffer");
152 in_buf_save = in_buf;
169 error(
"invalid header");
177 memcpy(in_buf_save, in_buf, in_len);
178 in_buf = in_buf_save;
186 if (
fill && in_len < 4) {
187 skip =
fill(in_buf + in_len, 4 - in_len);
192 error(
"file corrupted");
207 error(
"dest len longer than block size");
212 if (
fill && in_len < 8) {
213 skip =
fill(in_buf + in_len, 8 - in_len);
218 error(
"file corrupted");
225 if (src_len <= 0 || src_len > dst_len) {
226 error(
"file corrupted");
231 if (
fill && in_len < src_len) {
232 skip =
fill(in_buf + in_len, src_len - in_len);
236 if (in_len < src_len) {
237 error(
"file corrupted");
246 memcpy(out_buf, in_buf, src_len);
251 if (r !=
LZO_E_OK || dst_len != tmp) {
252 error(
"Compressed data violation");
257 if (flush && flush(out_buf, dst_len) != dst_len)
262 *posp += src_len + 12;
274 in_buf_save[skip] = in_buf[skip];
275 in_buf = in_buf_save;
290 #define decompress unlzo