wok-next diff linux/stuff/004-squashfs-add-xz-compression-support.patch @ rev 8193

imported patch toolchain/libgomp.patch
author Antoine Bodin <gokhlayeh@slitaz.org>
date Thu Jan 27 00:20:50 2011 +0100 (2011-01-27)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/linux/stuff/004-squashfs-add-xz-compression-support.patch	Thu Jan 27 00:20:50 2011 +0100
     1.3 @@ -0,0 +1,183 @@
     1.4 +From: Phillip Lougher <phillip@lougher.demon.co.uk>
     1.5 +Date: Thu, 9 Dec 2010 02:02:29 +0000 (+0000)
     1.6 +Subject: Squashfs: add XZ compression support
     1.7 +X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Fpkl%2Fsquashfs-xz.git;a=commitdiff_plain;h=d3e6969b9ff1f3a3c6bf3da71433c77046aa80e4
     1.8 +
     1.9 +Squashfs: add XZ compression support
    1.10 +
    1.11 +Add XZ decompressor wrapper code.
    1.12 +
    1.13 +Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
    1.14 +---
    1.15 +
    1.16 +diff --git a/fs/squashfs/squashfs_fs.h b/fs/squashfs/squashfs_fs.h
    1.17 +index c5137fc..39533fe 100644
    1.18 +--- a/fs/squashfs/squashfs_fs.h
    1.19 ++++ b/fs/squashfs/squashfs_fs.h
    1.20 +@@ -238,6 +238,7 @@ struct meta_index {
    1.21 + #define ZLIB_COMPRESSION	1
    1.22 + #define LZMA_COMPRESSION	2
    1.23 + #define LZO_COMPRESSION		3
    1.24 ++#define XZ_COMPRESSION		4
    1.25 + 
    1.26 + struct squashfs_super_block {
    1.27 + 	__le32			s_magic;
    1.28 +diff --git a/fs/squashfs/xz_wrapper.c b/fs/squashfs/xz_wrapper.c
    1.29 +new file mode 100644
    1.30 +index 0000000..053fe35
    1.31 +--- /dev/null
    1.32 ++++ b/fs/squashfs/xz_wrapper.c
    1.33 +@@ -0,0 +1,153 @@
    1.34 ++/*
    1.35 ++ * Squashfs - a compressed read only filesystem for Linux
    1.36 ++ *
    1.37 ++ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
    1.38 ++ * Phillip Lougher <phillip@lougher.demon.co.uk>
    1.39 ++ *
    1.40 ++ * This program is free software; you can redistribute it and/or
    1.41 ++ * modify it under the terms of the GNU General Public License
    1.42 ++ * as published by the Free Software Foundation; either version 2,
    1.43 ++ * or (at your option) any later version.
    1.44 ++ *
    1.45 ++ * This program is distributed in the hope that it will be useful,
    1.46 ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.47 ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.48 ++ * GNU General Public License for more details.
    1.49 ++ *
    1.50 ++ * You should have received a copy of the GNU General Public License
    1.51 ++ * along with this program; if not, write to the Free Software
    1.52 ++ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    1.53 ++ *
    1.54 ++ * xz_wrapper.c
    1.55 ++ */
    1.56 ++
    1.57 ++
    1.58 ++#include <linux/mutex.h>
    1.59 ++#include <linux/buffer_head.h>
    1.60 ++#include <linux/slab.h>
    1.61 ++#include <linux/xz.h>
    1.62 ++
    1.63 ++#include "squashfs_fs.h"
    1.64 ++#include "squashfs_fs_sb.h"
    1.65 ++#include "squashfs_fs_i.h"
    1.66 ++#include "squashfs.h"
    1.67 ++#include "decompressor.h"
    1.68 ++
    1.69 ++struct squashfs_xz {
    1.70 ++	struct xz_dec *state;
    1.71 ++	struct xz_buf buf;
    1.72 ++};
    1.73 ++
    1.74 ++static void *squashfs_xz_init(struct squashfs_sb_info *msblk)
    1.75 ++{
    1.76 ++        int block_size = max_t(int, msblk->block_size, SQUASHFS_METADATA_SIZE);
    1.77 ++
    1.78 ++        struct squashfs_xz *stream = kmalloc(sizeof(*stream), GFP_KERNEL);
    1.79 ++        if (stream == NULL)
    1.80 ++                goto failed;
    1.81 ++	stream->state = xz_dec_init(XZ_PREALLOC, block_size);
    1.82 ++	if (stream->state == NULL)
    1.83 ++		goto failed;
    1.84 ++
    1.85 ++	return stream;
    1.86 ++
    1.87 ++failed:
    1.88 ++	ERROR("Failed to allocate xz workspace\n");
    1.89 ++	kfree(stream);
    1.90 ++	return NULL;
    1.91 ++}
    1.92 ++
    1.93 ++
    1.94 ++static void squashfs_xz_free(void *strm)
    1.95 ++{
    1.96 ++	struct squashfs_xz *stream = strm;
    1.97 ++
    1.98 ++	if (stream) {
    1.99 ++		xz_dec_end(stream->state);
   1.100 ++		kfree(stream);
   1.101 ++	}
   1.102 ++}
   1.103 ++
   1.104 ++
   1.105 ++static int squashfs_xz_uncompress(struct squashfs_sb_info *msblk, void **buffer,
   1.106 ++	struct buffer_head **bh, int b, int offset, int length, int srclength,
   1.107 ++	int pages)
   1.108 ++{
   1.109 ++	enum xz_ret xz_err;
   1.110 ++	int avail, total = 0, k = 0, page = 0;
   1.111 ++	struct squashfs_xz *stream = msblk->stream;
   1.112 ++
   1.113 ++	mutex_lock(&msblk->read_data_mutex);
   1.114 ++
   1.115 ++	xz_dec_reset(stream->state);
   1.116 ++	stream->buf.in_pos = 0;
   1.117 ++	stream->buf.in_size = 0;
   1.118 ++	stream->buf.out_pos = 0;
   1.119 ++	stream->buf.out_size = PAGE_CACHE_SIZE;
   1.120 ++	stream->buf.out = buffer[page++];
   1.121 ++
   1.122 ++	do {
   1.123 ++		if (stream->buf.in_pos == stream->buf.in_size && k < b) {
   1.124 ++			avail = min(length, msblk->devblksize - offset);
   1.125 ++			length -= avail;
   1.126 ++			wait_on_buffer(bh[k]);
   1.127 ++			if (!buffer_uptodate(bh[k]))
   1.128 ++				goto release_mutex;
   1.129 ++
   1.130 ++			if (avail == 0) {
   1.131 ++				offset = 0;
   1.132 ++				put_bh(bh[k++]);
   1.133 ++				continue;
   1.134 ++			}
   1.135 ++
   1.136 ++			stream->buf.in = bh[k]->b_data + offset;
   1.137 ++			stream->buf.in_size = avail;
   1.138 ++			stream->buf.in_pos = 0;
   1.139 ++			offset = 0;
   1.140 ++		}
   1.141 ++
   1.142 ++		if (stream->buf.out_pos == stream->buf.out_size
   1.143 ++							&& page < pages) {
   1.144 ++			stream->buf.out = buffer[page++];
   1.145 ++			stream->buf.out_pos = 0;
   1.146 ++			total += PAGE_CACHE_SIZE;
   1.147 ++		}
   1.148 ++
   1.149 ++		xz_err = xz_dec_run(stream->state, &stream->buf);
   1.150 ++
   1.151 ++		if (stream->buf.in_pos == stream->buf.in_size && k < b)
   1.152 ++			put_bh(bh[k++]);
   1.153 ++	} while (xz_err == XZ_OK);
   1.154 ++
   1.155 ++	if (xz_err != XZ_STREAM_END) {
   1.156 ++		ERROR("xz_dec_run error, data probably corrupt\n");
   1.157 ++		goto release_mutex;
   1.158 ++	}
   1.159 ++
   1.160 ++	if (k < b) {
   1.161 ++		ERROR("xz_uncompress error, input remaining\n");
   1.162 ++		goto release_mutex;
   1.163 ++	}
   1.164 ++
   1.165 ++	total += stream->buf.out_pos;
   1.166 ++	mutex_unlock(&msblk->read_data_mutex);
   1.167 ++	return total;
   1.168 ++
   1.169 ++release_mutex:
   1.170 ++	mutex_unlock(&msblk->read_data_mutex);
   1.171 ++
   1.172 ++	for (; k < b; k++)
   1.173 ++		put_bh(bh[k]);
   1.174 ++
   1.175 ++	return -EIO;
   1.176 ++}
   1.177 ++
   1.178 ++const struct squashfs_decompressor squashfs_xz_comp_ops = {
   1.179 ++	.init = squashfs_xz_init,
   1.180 ++	.free = squashfs_xz_free,
   1.181 ++	.decompress = squashfs_xz_uncompress,
   1.182 ++	.id = XZ_COMPRESSION,
   1.183 ++	.name = "xz",
   1.184 ++	.supported = 1
   1.185 ++};
   1.186 ++