Linux 4.2.1
[linux/fpc-iii.git] / fs / squashfs / decompressor_single.c
bloba6c75929a00ed22e10e77844aad7a21644f3485c
1 /*
2 * Copyright (c) 2013
3 * Phillip Lougher <phillip@squashfs.org.uk>
5 * This work is licensed under the terms of the GNU GPL, version 2. See
6 * the COPYING file in the top-level directory.
7 */
9 #include <linux/types.h>
10 #include <linux/mutex.h>
11 #include <linux/slab.h>
12 #include <linux/buffer_head.h>
14 #include "squashfs_fs.h"
15 #include "squashfs_fs_sb.h"
16 #include "decompressor.h"
17 #include "squashfs.h"
20 * This file implements single-threaded decompression in the
21 * decompressor framework
24 struct squashfs_stream {
25 void *stream;
26 struct mutex mutex;
29 void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
30 void *comp_opts)
32 struct squashfs_stream *stream;
33 int err = -ENOMEM;
35 stream = kmalloc(sizeof(*stream), GFP_KERNEL);
36 if (stream == NULL)
37 goto out;
39 stream->stream = msblk->decompressor->init(msblk, comp_opts);
40 if (IS_ERR(stream->stream)) {
41 err = PTR_ERR(stream->stream);
42 goto out;
45 kfree(comp_opts);
46 mutex_init(&stream->mutex);
47 return stream;
49 out:
50 kfree(stream);
51 return ERR_PTR(err);
54 void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
56 struct squashfs_stream *stream = msblk->stream;
58 if (stream) {
59 msblk->decompressor->free(stream->stream);
60 kfree(stream);
64 int squashfs_decompress(struct squashfs_sb_info *msblk, struct buffer_head **bh,
65 int b, int offset, int length, struct squashfs_page_actor *output)
67 int res;
68 struct squashfs_stream *stream = msblk->stream;
70 mutex_lock(&stream->mutex);
71 res = msblk->decompressor->decompress(msblk, stream->stream, bh, b,
72 offset, length, output);
73 mutex_unlock(&stream->mutex);
75 if (res < 0)
76 ERROR("%s decompression failed, data probably corrupt\n",
77 msblk->decompressor->name);
79 return res;
82 int squashfs_max_decompressors(void)
84 return 1;