16cc87319960209b29c1c0b05f5c4e0a5e30c797
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.23 / 003-squashfs_lzma.patch
1 --- a/fs/squashfs/inode.c
2 +++ b/fs/squashfs/inode.c
3 @@ -4,6 +4,9 @@
4 * Copyright (c) 2002, 2003, 2004, 2005, 2006
5 * Phillip Lougher <phillip@lougher.org.uk>
6 *
7 + * LZMA decompressor support added by Oleg I. Vdovikin
8 + * Copyright (c) 2005 Oleg I.Vdovikin <oleg@cs.msu.su>
9 + *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2,
13 @@ -21,6 +24,7 @@
14 * inode.c
15 */
16
17 +#define SQUASHFS_LZMA
18 #include <linux/types.h>
19 #include <linux/squashfs_fs.h>
20 #include <linux/module.h>
21 @@ -44,6 +48,19 @@
22
23 #include "squashfs.h"
24
25 +#ifdef SQUASHFS_LZMA
26 +#include <linux/LzmaDecode.h>
27 +
28 +/* default LZMA settings, should be in sync with mksquashfs */
29 +#define LZMA_LC 3
30 +#define LZMA_LP 0
31 +#define LZMA_PB 2
32 +
33 +#define LZMA_WORKSPACE_SIZE ((LZMA_BASE_SIZE + \
34 + (LZMA_LIT_SIZE << (LZMA_LC + LZMA_LP))) * sizeof(CProb))
35 +
36 +#endif
37 +
38 static void squashfs_put_super(struct super_block *);
39 static int squashfs_statfs(struct dentry *, struct kstatfs *);
40 static int squashfs_symlink_readpage(struct file *file, struct page *page);
41 @@ -64,7 +81,11 @@
42 const char *, void *, struct vfsmount *);
43
44
45 +#ifdef SQUASHFS_LZMA
46 +static unsigned char lzma_workspace[LZMA_WORKSPACE_SIZE];
47 +#else
48 static z_stream stream;
49 +#endif
50
51 static struct file_system_type squashfs_fs_type = {
52 .owner = THIS_MODULE,
53 @@ -249,6 +270,15 @@
54 if (compressed) {
55 int zlib_err;
56
57 +#ifdef SQUASHFS_LZMA
58 + if ((zlib_err = LzmaDecode(lzma_workspace,
59 + LZMA_WORKSPACE_SIZE, LZMA_LC, LZMA_LP, LZMA_PB,
60 + c_buffer, c_byte, buffer, msblk->read_size, &bytes)) != LZMA_RESULT_OK)
61 + {
62 + ERROR("lzma returned unexpected result 0x%x\n", zlib_err);
63 + bytes = 0;
64 + }
65 +#else
66 stream.next_in = c_buffer;
67 stream.avail_in = c_byte;
68 stream.next_out = buffer;
69 @@ -263,7 +293,7 @@
70 bytes = 0;
71 } else
72 bytes = stream.total_out;
73 -
74 +#endif
75 up(&msblk->read_data_mutex);
76 }
77
78 @@ -2045,15 +2075,19 @@
79 printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
80 "Phillip Lougher\n");
81
82 +#ifndef SQUASHFS_LZMA
83 if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
84 ERROR("Failed to allocate zlib workspace\n");
85 destroy_inodecache();
86 err = -ENOMEM;
87 goto out;
88 }
89 +#endif
90
91 if ((err = register_filesystem(&squashfs_fs_type))) {
92 +#ifndef SQUASHFS_LZMA
93 vfree(stream.workspace);
94 +#endif
95 destroy_inodecache();
96 }
97
98 @@ -2064,7 +2098,9 @@
99
100 static void __exit exit_squashfs_fs(void)
101 {
102 +#ifndef SQUASHFS_LZMA
103 vfree(stream.workspace);
104 +#endif
105 unregister_filesystem(&squashfs_fs_type);
106 destroy_inodecache();
107 }
This page took 0.044187 seconds and 3 git commands to generate.