Date:2010-09-11 04:35:55 (12 years 24 days ago)
Author:Phillip Lougher
Commit:45c3204b42c8333664975ab15c3cd9438754fe94
Message:Squashfs: add LZMA compression

Add support for LZMA compressed filesystems. This is an initial
implementation.

Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
Files: fs/squashfs/Kconfig (1 diff)
fs/squashfs/Makefile (1 diff)
fs/squashfs/decompressor.c (1 diff)
fs/squashfs/lzma_wrapper.c (1 diff)
fs/squashfs/squashfs.h (1 diff)

Change Details

fs/squashfs/Kconfig
3737
3838      If unsure, say N.
3939
40config SQUASHFS_LZMA
41    bool "Include support for LZMA compressed file systems"
42    depends on SQUASHFS
43    select DECOMPRESS_LZMA
44
4045config SQUASHFS_EMBEDDED
4146
4247    bool "Additional option for memory-constrained systems"
fs/squashfs/Makefile
66squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o
77squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o
88squashfs-$(CONFIG_SQUASHFS_XATTRS) += xattr.o xattr_id.o
9squashfs-$(CONFIG_SQUASHFS_LZMA) += lzma_wrapper.o
910
fs/squashfs/decompressor.c
5050
5151static const struct squashfs_decompressor *decompressor[] = {
5252    &squashfs_zlib_comp_ops,
53#ifdef CONFIG_SQUASHFS_LZMA
54    &squashfs_lzma_comp_ops,
55#else
5356    &squashfs_lzma_unsupported_comp_ops,
57#endif
5458    &squashfs_lzo_unsupported_comp_ops,
5559    &squashfs_unknown_comp_ops
5660};
fs/squashfs/lzma_wrapper.c
1/*
2 * Squashfs - a compressed read only filesystem for Linux
3 *
4 * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
5 * Phillip Lougher <phillip@lougher.demon.co.uk>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 * lzma_wrapper.c
22 */
23
24#include <asm/unaligned.h>
25#include <linux/buffer_head.h>
26#include <linux/mutex.h>
27#include <linux/vmalloc.h>
28#include <linux/decompress/unlzma.h>
29#include <linux/slab.h>
30
31#include "squashfs_fs.h"
32#include "squashfs_fs_sb.h"
33#include "squashfs_fs_i.h"
34#include "squashfs.h"
35#include "decompressor.h"
36
37struct squashfs_lzma {
38    void *input;
39    void *output;
40};
41
42/* decompress_unlzma.c is currently non re-entrant... */
43DEFINE_MUTEX(lzma_mutex);
44
45/* decompress_unlzma.c doesn't provide any context in its callbacks... */
46static int lzma_error;
47
48static void error(char *m)
49{
50    ERROR("unlzma error: %s\n", m);
51    lzma_error = 1;
52}
53
54
55static void *lzma_init(struct squashfs_sb_info *msblk)
56{
57    struct squashfs_lzma *stream = kzalloc(sizeof(*stream), GFP_KERNEL);
58    if (stream == NULL)
59        goto failed;
60    stream->input = vmalloc(msblk->block_size);
61    if (stream->input == NULL)
62        goto failed;
63    stream->output = vmalloc(msblk->block_size);
64    if (stream->output == NULL)
65        goto failed2;
66
67    return stream;
68
69failed2:
70    vfree(stream->input);
71failed:
72    ERROR("failed to allocate lzma workspace\n");
73    kfree(stream);
74    return NULL;
75}
76
77
78static void lzma_free(void *strm)
79{
80    struct squashfs_lzma *stream = strm;
81
82    if (stream) {
83        vfree(stream->input);
84        vfree(stream->output);
85    }
86    kfree(stream);
87}
88
89
90static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer,
91    struct buffer_head **bh, int b, int offset, int length, int srclength,
92    int pages)
93{
94    struct squashfs_lzma *stream = msblk->stream;
95    void *buff = stream->input;
96    int avail, i, bytes = length, res;
97
98    mutex_lock(&lzma_mutex);
99
100    for (i = 0; i < b; i++) {
101        wait_on_buffer(bh[i]);
102        if (!buffer_uptodate(bh[i]))
103            goto block_release;
104
105        avail = min(bytes, msblk->devblksize - offset);
106        memcpy(buff, bh[i]->b_data + offset, avail);
107        buff += avail;
108        bytes -= avail;
109        offset = 0;
110        put_bh(bh[i]);
111    }
112
113    lzma_error = 0;
114    res = unlzma(stream->input, length, NULL, NULL, stream->output, NULL,
115                            error);
116    if (res || lzma_error)
117        goto failed;
118
119    /* uncompressed size is stored in the LZMA header (5 byte offset) */
120    res = bytes = get_unaligned_le32(stream->input + 5);
121    for (i = 0, buff = stream->output; bytes && i < pages; i++) {
122        avail = min_t(int, bytes, PAGE_CACHE_SIZE);
123        memcpy(buffer[i], buff, avail);
124        buff += avail;
125        bytes -= avail;
126    }
127    if (bytes)
128        goto failed;
129
130    mutex_unlock(&lzma_mutex);
131    return res;
132
133block_release:
134    for (; i < b; i++)
135        put_bh(bh[i]);
136
137failed:
138    mutex_unlock(&lzma_mutex);
139
140    ERROR("lzma decompression failed, data probably corrupt\n");
141    return -EIO;
142}
143
144const struct squashfs_decompressor squashfs_lzma_comp_ops = {
145    .init = lzma_init,
146    .free = lzma_free,
147    .decompress = lzma_uncompress,
148    .id = LZMA_COMPRESSION,
149    .name = "lzma",
150    .supported = 1
151};
152
fs/squashfs/squashfs.h
104104
105105/* zlib_wrapper.c */
106106extern const struct squashfs_decompressor squashfs_zlib_comp_ops;
107
108/* lzma wrapper.c */
109extern const struct squashfs_decompressor squashfs_lzma_comp_ops;

Archive Download the corresponding diff file



interactive