GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / fs / squashfs / lzo_wrapper.c
blob3c1011ca52d9082771bcd38f80aca1df2a1f72e7
1 /* Modified by Broadcom Corp. Portions Copyright (c) Broadcom Corp, 2012. */
2 /*
3 * Squashfs - a compressed read only filesystem for Linux
5 * Copyright (c) 2010 LG Electronics
6 * Chan Jeong <chan.jeong@lge.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2,
11 * or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * lzo_wrapper.c
25 #include <linux/mutex.h>
26 #include <linux/buffer_head.h>
27 #include <linux/slab.h>
28 #include <linux/vmalloc.h>
29 #include <linux/lzo.h>
31 #include "squashfs_fs.h"
32 #include "squashfs_fs_sb.h"
33 #include "squashfs.h"
34 #include "decompressor.h"
36 struct squashfs_lzo {
37 void *input;
38 void *output;
41 static void *lzo_init(struct squashfs_sb_info *msblk, void *buff, int len)
43 int block_size = max_t(int, msblk->block_size, SQUASHFS_METADATA_SIZE);
45 struct squashfs_lzo *stream = kzalloc(sizeof(*stream), GFP_KERNEL);
46 if (stream == NULL)
47 goto failed;
48 stream->input = vmalloc(block_size);
49 if (stream->input == NULL)
50 goto failed;
51 stream->output = vmalloc(block_size);
52 if (stream->output == NULL)
53 goto failed2;
55 return stream;
57 failed2:
58 vfree(stream->input);
59 failed:
60 ERROR("Failed to allocate lzo workspace\n");
61 kfree(stream);
62 return ERR_PTR(-ENOMEM);
66 static void lzo_free(void *strm)
68 struct squashfs_lzo *stream = strm;
70 if (stream) {
71 vfree(stream->input);
72 vfree(stream->output);
74 kfree(stream);
78 static int lzo_uncompress(struct squashfs_sb_info *msblk, void **buffer,
79 struct buffer_head **bh, int b, int offset, int length, int srclength,
80 int pages)
82 struct squashfs_lzo *stream = msblk->stream;
83 void *buff = stream->input;
84 int avail, i, bytes = length, res;
85 size_t out_len = srclength;
87 mutex_lock(&msblk->read_data_mutex);
89 for (i = 0; i < b; i++) {
90 wait_on_buffer(bh[i]);
91 if (!buffer_uptodate(bh[i]))
92 goto block_release;
94 avail = min(bytes, msblk->devblksize - offset);
95 memcpy(buff, bh[i]->b_data + offset, avail);
96 buff += avail;
97 bytes -= avail;
98 offset = 0;
99 put_bh(bh[i]);
102 res = lzo1x_decompress_safe(stream->input, (size_t)length,
103 stream->output, &out_len);
104 if (res != LZO_E_OK)
105 goto failed;
107 res = bytes = (int)out_len;
108 for (i = 0, buff = stream->output; bytes && i < pages; i++) {
109 avail = min_t(int, bytes, PAGE_CACHE_SIZE);
110 memcpy(buffer[i], buff, avail);
111 buff += avail;
112 bytes -= avail;
115 mutex_unlock(&msblk->read_data_mutex);
116 return res;
118 block_release:
119 for (; i < b; i++)
120 put_bh(bh[i]);
122 failed:
123 mutex_unlock(&msblk->read_data_mutex);
125 ERROR("lzo decompression failed, data probably corrupt\n");
126 return -EIO;
129 const struct squashfs_decompressor squashfs_lzo_comp_ops = {
130 .init = lzo_init,
131 .free = lzo_free,
132 .decompress = lzo_uncompress,
133 .id = LZO_COMPRESSION,
134 .name = "lzo",
135 .supported = 1