1 // SPDX-License-Identifier: GPL-2.0-only
4 * Phillip Lougher <phillip@squashfs.org.uk>
7 #include <linux/types.h>
8 #include <linux/mutex.h>
9 #include <linux/slab.h>
10 #include <linux/buffer_head.h>
12 #include "squashfs_fs.h"
13 #include "squashfs_fs_sb.h"
14 #include "decompressor.h"
18 * This file implements single-threaded decompression in the
19 * decompressor framework
22 struct squashfs_stream
{
27 void *squashfs_decompressor_create(struct squashfs_sb_info
*msblk
,
30 struct squashfs_stream
*stream
;
33 stream
= kmalloc(sizeof(*stream
), GFP_KERNEL
);
37 stream
->stream
= msblk
->decompressor
->init(msblk
, comp_opts
);
38 if (IS_ERR(stream
->stream
)) {
39 err
= PTR_ERR(stream
->stream
);
44 mutex_init(&stream
->mutex
);
52 void squashfs_decompressor_destroy(struct squashfs_sb_info
*msblk
)
54 struct squashfs_stream
*stream
= msblk
->stream
;
57 msblk
->decompressor
->free(stream
->stream
);
62 int squashfs_decompress(struct squashfs_sb_info
*msblk
, struct buffer_head
**bh
,
63 int b
, int offset
, int length
, struct squashfs_page_actor
*output
)
66 struct squashfs_stream
*stream
= msblk
->stream
;
68 mutex_lock(&stream
->mutex
);
69 res
= msblk
->decompressor
->decompress(msblk
, stream
->stream
, bh
, b
,
70 offset
, length
, output
);
71 mutex_unlock(&stream
->mutex
);
74 ERROR("%s decompression failed, data probably corrupt\n",
75 msblk
->decompressor
->name
);
80 int squashfs_max_decompressors(void)