wok annotate linux/stuff/004-squashfs-add-xz-compression-support.patch @ rev 12072

fix tuxmath bdeps
author Antoine Bodin <gokhlayeh@slitaz.org>
date Fri Mar 09 05:03:33 2012 +0100 (2012-03-09)
parents
children
rev   line source
slaxemulator@7650 1 From: Phillip Lougher <phillip@lougher.demon.co.uk>
slaxemulator@7650 2 Date: Thu, 9 Dec 2010 02:02:29 +0000 (+0000)
slaxemulator@7650 3 Subject: Squashfs: add XZ compression support
slaxemulator@7650 4 X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Fpkl%2Fsquashfs-xz.git;a=commitdiff_plain;h=d3e6969b9ff1f3a3c6bf3da71433c77046aa80e4
slaxemulator@7650 5
slaxemulator@7650 6 Squashfs: add XZ compression support
slaxemulator@7650 7
slaxemulator@7650 8 Add XZ decompressor wrapper code.
slaxemulator@7650 9
slaxemulator@7650 10 Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
slaxemulator@7650 11 ---
slaxemulator@7650 12
slaxemulator@7650 13 diff --git a/fs/squashfs/squashfs_fs.h b/fs/squashfs/squashfs_fs.h
slaxemulator@7650 14 index c5137fc..39533fe 100644
slaxemulator@7650 15 --- a/fs/squashfs/squashfs_fs.h
slaxemulator@7650 16 +++ b/fs/squashfs/squashfs_fs.h
slaxemulator@7650 17 @@ -238,6 +238,7 @@ struct meta_index {
slaxemulator@7650 18 #define ZLIB_COMPRESSION 1
slaxemulator@7650 19 #define LZMA_COMPRESSION 2
slaxemulator@7650 20 #define LZO_COMPRESSION 3
slaxemulator@7650 21 +#define XZ_COMPRESSION 4
slaxemulator@7650 22
slaxemulator@7650 23 struct squashfs_super_block {
slaxemulator@7650 24 __le32 s_magic;
slaxemulator@7650 25 diff --git a/fs/squashfs/xz_wrapper.c b/fs/squashfs/xz_wrapper.c
slaxemulator@7650 26 new file mode 100644
slaxemulator@7650 27 index 0000000..053fe35
slaxemulator@7650 28 --- /dev/null
slaxemulator@7650 29 +++ b/fs/squashfs/xz_wrapper.c
slaxemulator@7650 30 @@ -0,0 +1,153 @@
slaxemulator@7650 31 +/*
slaxemulator@7650 32 + * Squashfs - a compressed read only filesystem for Linux
slaxemulator@7650 33 + *
slaxemulator@7650 34 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
slaxemulator@7650 35 + * Phillip Lougher <phillip@lougher.demon.co.uk>
slaxemulator@7650 36 + *
slaxemulator@7650 37 + * This program is free software; you can redistribute it and/or
slaxemulator@7650 38 + * modify it under the terms of the GNU General Public License
slaxemulator@7650 39 + * as published by the Free Software Foundation; either version 2,
slaxemulator@7650 40 + * or (at your option) any later version.
slaxemulator@7650 41 + *
slaxemulator@7650 42 + * This program is distributed in the hope that it will be useful,
slaxemulator@7650 43 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
slaxemulator@7650 44 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
slaxemulator@7650 45 + * GNU General Public License for more details.
slaxemulator@7650 46 + *
slaxemulator@7650 47 + * You should have received a copy of the GNU General Public License
slaxemulator@7650 48 + * along with this program; if not, write to the Free Software
slaxemulator@7650 49 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
slaxemulator@7650 50 + *
slaxemulator@7650 51 + * xz_wrapper.c
slaxemulator@7650 52 + */
slaxemulator@7650 53 +
slaxemulator@7650 54 +
slaxemulator@7650 55 +#include <linux/mutex.h>
slaxemulator@7650 56 +#include <linux/buffer_head.h>
slaxemulator@7650 57 +#include <linux/slab.h>
slaxemulator@7650 58 +#include <linux/xz.h>
slaxemulator@7650 59 +
slaxemulator@7650 60 +#include "squashfs_fs.h"
slaxemulator@7650 61 +#include "squashfs_fs_sb.h"
slaxemulator@7650 62 +#include "squashfs_fs_i.h"
slaxemulator@7650 63 +#include "squashfs.h"
slaxemulator@7650 64 +#include "decompressor.h"
slaxemulator@7650 65 +
slaxemulator@7650 66 +struct squashfs_xz {
slaxemulator@7650 67 + struct xz_dec *state;
slaxemulator@7650 68 + struct xz_buf buf;
slaxemulator@7650 69 +};
slaxemulator@7650 70 +
slaxemulator@7650 71 +static void *squashfs_xz_init(struct squashfs_sb_info *msblk)
slaxemulator@7650 72 +{
slaxemulator@7650 73 + int block_size = max_t(int, msblk->block_size, SQUASHFS_METADATA_SIZE);
slaxemulator@7650 74 +
slaxemulator@7650 75 + struct squashfs_xz *stream = kmalloc(sizeof(*stream), GFP_KERNEL);
slaxemulator@7650 76 + if (stream == NULL)
slaxemulator@7650 77 + goto failed;
slaxemulator@7650 78 + stream->state = xz_dec_init(XZ_PREALLOC, block_size);
slaxemulator@7650 79 + if (stream->state == NULL)
slaxemulator@7650 80 + goto failed;
slaxemulator@7650 81 +
slaxemulator@7650 82 + return stream;
slaxemulator@7650 83 +
slaxemulator@7650 84 +failed:
slaxemulator@7650 85 + ERROR("Failed to allocate xz workspace\n");
slaxemulator@7650 86 + kfree(stream);
slaxemulator@7650 87 + return NULL;
slaxemulator@7650 88 +}
slaxemulator@7650 89 +
slaxemulator@7650 90 +
slaxemulator@7650 91 +static void squashfs_xz_free(void *strm)
slaxemulator@7650 92 +{
slaxemulator@7650 93 + struct squashfs_xz *stream = strm;
slaxemulator@7650 94 +
slaxemulator@7650 95 + if (stream) {
slaxemulator@7650 96 + xz_dec_end(stream->state);
slaxemulator@7650 97 + kfree(stream);
slaxemulator@7650 98 + }
slaxemulator@7650 99 +}
slaxemulator@7650 100 +
slaxemulator@7650 101 +
slaxemulator@7650 102 +static int squashfs_xz_uncompress(struct squashfs_sb_info *msblk, void **buffer,
slaxemulator@7650 103 + struct buffer_head **bh, int b, int offset, int length, int srclength,
slaxemulator@7650 104 + int pages)
slaxemulator@7650 105 +{
slaxemulator@7650 106 + enum xz_ret xz_err;
slaxemulator@7650 107 + int avail, total = 0, k = 0, page = 0;
slaxemulator@7650 108 + struct squashfs_xz *stream = msblk->stream;
slaxemulator@7650 109 +
slaxemulator@7650 110 + mutex_lock(&msblk->read_data_mutex);
slaxemulator@7650 111 +
slaxemulator@7650 112 + xz_dec_reset(stream->state);
slaxemulator@7650 113 + stream->buf.in_pos = 0;
slaxemulator@7650 114 + stream->buf.in_size = 0;
slaxemulator@7650 115 + stream->buf.out_pos = 0;
slaxemulator@7650 116 + stream->buf.out_size = PAGE_CACHE_SIZE;
slaxemulator@7650 117 + stream->buf.out = buffer[page++];
slaxemulator@7650 118 +
slaxemulator@7650 119 + do {
slaxemulator@7650 120 + if (stream->buf.in_pos == stream->buf.in_size && k < b) {
slaxemulator@7650 121 + avail = min(length, msblk->devblksize - offset);
slaxemulator@7650 122 + length -= avail;
slaxemulator@7650 123 + wait_on_buffer(bh[k]);
slaxemulator@7650 124 + if (!buffer_uptodate(bh[k]))
slaxemulator@7650 125 + goto release_mutex;
slaxemulator@7650 126 +
slaxemulator@7650 127 + if (avail == 0) {
slaxemulator@7650 128 + offset = 0;
slaxemulator@7650 129 + put_bh(bh[k++]);
slaxemulator@7650 130 + continue;
slaxemulator@7650 131 + }
slaxemulator@7650 132 +
slaxemulator@7650 133 + stream->buf.in = bh[k]->b_data + offset;
slaxemulator@7650 134 + stream->buf.in_size = avail;
slaxemulator@7650 135 + stream->buf.in_pos = 0;
slaxemulator@7650 136 + offset = 0;
slaxemulator@7650 137 + }
slaxemulator@7650 138 +
slaxemulator@7650 139 + if (stream->buf.out_pos == stream->buf.out_size
slaxemulator@7650 140 + && page < pages) {
slaxemulator@7650 141 + stream->buf.out = buffer[page++];
slaxemulator@7650 142 + stream->buf.out_pos = 0;
slaxemulator@7650 143 + total += PAGE_CACHE_SIZE;
slaxemulator@7650 144 + }
slaxemulator@7650 145 +
slaxemulator@7650 146 + xz_err = xz_dec_run(stream->state, &stream->buf);
slaxemulator@7650 147 +
slaxemulator@7650 148 + if (stream->buf.in_pos == stream->buf.in_size && k < b)
slaxemulator@7650 149 + put_bh(bh[k++]);
slaxemulator@7650 150 + } while (xz_err == XZ_OK);
slaxemulator@7650 151 +
slaxemulator@7650 152 + if (xz_err != XZ_STREAM_END) {
slaxemulator@7650 153 + ERROR("xz_dec_run error, data probably corrupt\n");
slaxemulator@7650 154 + goto release_mutex;
slaxemulator@7650 155 + }
slaxemulator@7650 156 +
slaxemulator@7650 157 + if (k < b) {
slaxemulator@7650 158 + ERROR("xz_uncompress error, input remaining\n");
slaxemulator@7650 159 + goto release_mutex;
slaxemulator@7650 160 + }
slaxemulator@7650 161 +
slaxemulator@7650 162 + total += stream->buf.out_pos;
slaxemulator@7650 163 + mutex_unlock(&msblk->read_data_mutex);
slaxemulator@7650 164 + return total;
slaxemulator@7650 165 +
slaxemulator@7650 166 +release_mutex:
slaxemulator@7650 167 + mutex_unlock(&msblk->read_data_mutex);
slaxemulator@7650 168 +
slaxemulator@7650 169 + for (; k < b; k++)
slaxemulator@7650 170 + put_bh(bh[k]);
slaxemulator@7650 171 +
slaxemulator@7650 172 + return -EIO;
slaxemulator@7650 173 +}
slaxemulator@7650 174 +
slaxemulator@7650 175 +const struct squashfs_decompressor squashfs_xz_comp_ops = {
slaxemulator@7650 176 + .init = squashfs_xz_init,
slaxemulator@7650 177 + .free = squashfs_xz_free,
slaxemulator@7650 178 + .decompress = squashfs_xz_uncompress,
slaxemulator@7650 179 + .id = XZ_COMPRESSION,
slaxemulator@7650 180 + .name = "xz",
slaxemulator@7650 181 + .supported = 1
slaxemulator@7650 182 +};
slaxemulator@7650 183 +