]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - SQUASHFS/squashfs-tools-4.4/squashfs-tools/lzma_wrapper.c
1.1.07 release
[Ventoy.git] / SQUASHFS / squashfs-tools-4.4 / squashfs-tools / lzma_wrapper.c
1 /*
2 * Copyright (c) 2009, 2010, 2013
3 * Phillip Lougher <phillip@squashfs.org.uk>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2,
8 * or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 * lzma_wrapper.c
20 *
21 * Support for LZMA1 compression using LZMA SDK (4.65 used in
22 * development, other versions may work) http://www.7-zip.org/sdk.html
23 */
24
25 #include <LzmaLib.h>
26
27 #include "squashfs_fs.h"
28 #include "compressor.h"
29
30 #define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)
31
32 static int lzma_compress(void *strm, void *dest, void *src, int size, int block_size,
33 int *error)
34 {
35 return 0;
36 }
37
38
39 static int lzma_uncompress(void *dest, void *src, int size, int outsize,
40 int *error)
41 {
42 unsigned char *s = src;
43 size_t outlen, inlen = size - LZMA_HEADER_SIZE;
44 int res;
45
46 outlen = s[LZMA_PROPS_SIZE] |
47 (s[LZMA_PROPS_SIZE + 1] << 8) |
48 (s[LZMA_PROPS_SIZE + 2] << 16) |
49 (s[LZMA_PROPS_SIZE + 3] << 24);
50
51 if(outlen > outsize) {
52 *error = 0;
53 return -1;
54 }
55
56 res = LzmaUncompress(dest, &outlen, src + LZMA_HEADER_SIZE, &inlen, src,
57 LZMA_PROPS_SIZE);
58
59 if(res == SZ_OK)
60 return outlen;
61 else {
62 *error = res;
63 return -1;
64 }
65 }
66
67
68 struct compressor lzma_comp_ops = {
69 .init = NULL,
70 .compress = lzma_compress,
71 .uncompress = lzma_uncompress,
72 .options = NULL,
73 .usage = NULL,
74 .id = LZMA_COMPRESSION,
75 .name = "lzma",
76 .supported = 1
77 };
78