[PATCH 6/9] Squashfs: add support for LZMA compressed filesystems
Signed-off-by: Phillip Lougher phil...@lougher.demon.co.uk --- fs/squashfs/Kconfig|5 ++ fs/squashfs/Makefile |1 + fs/squashfs/decompressor.c |4 + fs/squashfs/lzma_wrapper.c | 151 fs/squashfs/squashfs.h |3 + 5 files changed, 164 insertions(+), 0 deletions(-) create mode 100644 fs/squashfs/lzma_wrapper.c diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig index 25a00d1..0294aa2 100644 --- a/fs/squashfs/Kconfig +++ b/fs/squashfs/Kconfig @@ -26,6 +26,11 @@ config SQUASHFS If unsure, say N. +config SQUASHFS_LZMA + bool Include support for LZMA compressed file systems + depends on SQUASHFS + select DECOMPRESS_LZMA + config SQUASHFS_EMBEDDED bool Additional option for memory-constrained systems diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile index df8a19e..45aaefd 100644 --- a/fs/squashfs/Makefile +++ b/fs/squashfs/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_SQUASHFS) += squashfs.o squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o +squashfs-$(CONFIG_SQUASHFS_LZMA) += lzma_wrapper.o diff --git a/fs/squashfs/decompressor.c b/fs/squashfs/decompressor.c index 157478d..0b6ad9b 100644 --- a/fs/squashfs/decompressor.c +++ b/fs/squashfs/decompressor.c @@ -50,7 +50,11 @@ static const struct squashfs_decompressor squashfs_unknown_comp_ops = { static const struct squashfs_decompressor *decompressor[] = { squashfs_zlib_comp_ops, +#ifdef CONFIG_SQUASHFS_LZMA + squashfs_lzma_comp_ops, +#else squashfs_lzma_unsupported_comp_ops, +#endif squashfs_lzo_unsupported_comp_ops, squashfs_unknown_comp_ops }; diff --git a/fs/squashfs/lzma_wrapper.c b/fs/squashfs/lzma_wrapper.c new file mode 100644 index 000..cef06d6 --- /dev/null +++ b/fs/squashfs/lzma_wrapper.c @@ -0,0 +1,151 @@ +/* + * Squashfs - a compressed read only filesystem for Linux + * + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 + * Phillip Lougher phil...@lougher.demon.co.uk + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * lzma_wrapper.c + */ + +#include asm/unaligned.h +#include linux/buffer_head.h +#include linux/mutex.h +#include linux/vmalloc.h +#include linux/decompress/unlzma.h + +#include squashfs_fs.h +#include squashfs_fs_sb.h +#include squashfs_fs_i.h +#include squashfs.h +#include decompressor.h + +struct squashfs_lzma { + void*input; + void*output; +}; + +/* decompress_unlzma.c is currently non re-entrant... */ +DEFINE_MUTEX(lzma_mutex); + +/* decompress_unlzma.c doesn't provide any context in its callbacks... */ +static int lzma_error; + +static void error(char *m) +{ + ERROR(unlzma error: %s\n, m); + lzma_error = 1; +} + + +static void *lzma_init(struct squashfs_sb_info *msblk) +{ + struct squashfs_lzma *stream = kzalloc(sizeof(*stream), GFP_KERNEL); + if (stream == NULL) + goto failed; + stream-input = vmalloc(msblk-block_size); + if (stream-input == NULL) + goto failed; + stream-output = vmalloc(msblk-block_size); + if (stream-output == NULL) + goto failed2; + + return stream; + +failed2: + vfree(stream-input); +failed: + ERROR(failed to allocate lzma workspace\n); + kfree(stream); + return NULL; +} + + +static void lzma_free(void *strm) +{ + struct squashfs_lzma *stream = strm; + + if (stream) { + vfree(stream-input); + vfree(stream-output); + } + kfree(stream); +} + + +static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer, + struct buffer_head **bh, int b, int offset, int length, int srclength, + int pages) +{ + struct squashfs_lzma *stream = msblk-stream; + void *buff = stream-input; + int avail, i, bytes = length, res; + + mutex_lock(lzma_mutex); + + for (i = 0; i b; i++) { + wait_on_buffer(bh[i]); + if (!buffer_uptodate(bh[i])) + goto block_release; + + avail = min(bytes, msblk-devblksize - offset); + memcpy(buff, bh[i]-b_data + offset, avail); + buff +=
[PATCH 6/9] Squashfs: add support for LZMA compressed filesystems
Signed-off-by: Phillip Lougher phil...@lougher.demon.co.uk --- fs/squashfs/Kconfig|5 ++ fs/squashfs/Makefile |1 + fs/squashfs/decompressor.c |4 + fs/squashfs/lzma_wrapper.c | 151 fs/squashfs/squashfs.h |3 + 5 files changed, 164 insertions(+), 0 deletions(-) create mode 100644 fs/squashfs/lzma_wrapper.c diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig index 25a00d1..0294aa2 100644 --- a/fs/squashfs/Kconfig +++ b/fs/squashfs/Kconfig @@ -26,6 +26,11 @@ config SQUASHFS If unsure, say N. +config SQUASHFS_LZMA + bool Include support for LZMA compressed file systems + depends on SQUASHFS + select DECOMPRESS_LZMA + config SQUASHFS_EMBEDDED bool Additional option for memory-constrained systems diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile index df8a19e..45aaefd 100644 --- a/fs/squashfs/Makefile +++ b/fs/squashfs/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_SQUASHFS) += squashfs.o squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o +squashfs-$(CONFIG_SQUASHFS_LZMA) += lzma_wrapper.o diff --git a/fs/squashfs/decompressor.c b/fs/squashfs/decompressor.c index 157478d..0b6ad9b 100644 --- a/fs/squashfs/decompressor.c +++ b/fs/squashfs/decompressor.c @@ -50,7 +50,11 @@ static const struct squashfs_decompressor squashfs_unknown_comp_ops = { static const struct squashfs_decompressor *decompressor[] = { squashfs_zlib_comp_ops, +#ifdef CONFIG_SQUASHFS_LZMA + squashfs_lzma_comp_ops, +#else squashfs_lzma_unsupported_comp_ops, +#endif squashfs_lzo_unsupported_comp_ops, squashfs_unknown_comp_ops }; diff --git a/fs/squashfs/lzma_wrapper.c b/fs/squashfs/lzma_wrapper.c new file mode 100644 index 000..cef06d6 --- /dev/null +++ b/fs/squashfs/lzma_wrapper.c @@ -0,0 +1,151 @@ +/* + * Squashfs - a compressed read only filesystem for Linux + * + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 + * Phillip Lougher phil...@lougher.demon.co.uk + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * lzma_wrapper.c + */ + +#include asm/unaligned.h +#include linux/buffer_head.h +#include linux/mutex.h +#include linux/vmalloc.h +#include linux/decompress/unlzma.h + +#include squashfs_fs.h +#include squashfs_fs_sb.h +#include squashfs_fs_i.h +#include squashfs.h +#include decompressor.h + +struct squashfs_lzma { + void*input; + void*output; +}; + +/* decompress_unlzma.c is currently non re-entrant... */ +DEFINE_MUTEX(lzma_mutex); + +/* decompress_unlzma.c doesn't provide any context in its callbacks... */ +static int lzma_error; + +static void error(char *m) +{ + ERROR(unlzma error: %s\n, m); + lzma_error = 1; +} + + +static void *lzma_init(struct squashfs_sb_info *msblk) +{ + struct squashfs_lzma *stream = kzalloc(sizeof(*stream), GFP_KERNEL); + if (stream == NULL) + goto failed; + stream-input = vmalloc(msblk-block_size); + if (stream-input == NULL) + goto failed; + stream-output = vmalloc(msblk-block_size); + if (stream-output == NULL) + goto failed2; + + return stream; + +failed2: + vfree(stream-input); +failed: + ERROR(failed to allocate lzma workspace\n); + kfree(stream); + return NULL; +} + + +static void lzma_free(void *strm) +{ + struct squashfs_lzma *stream = strm; + + if (stream) { + vfree(stream-input); + vfree(stream-output); + } + kfree(stream); +} + + +static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer, + struct buffer_head **bh, int b, int offset, int length, int srclength, + int pages) +{ + struct squashfs_lzma *stream = msblk-stream; + void *buff = stream-input; + int avail, i, bytes = length, res; + + mutex_lock(lzma_mutex); + + for (i = 0; i b; i++) { + wait_on_buffer(bh[i]); + if (!buffer_uptodate(bh[i])) + goto block_release; + + avail = min(bytes, msblk-devblksize - offset); + memcpy(buff, bh[i]-b_data + offset, avail); + buff +=