Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (c) 2013
0004  * Phillip Lougher <phillip@squashfs.org.uk>
0005  */
0006 
0007 #include <linux/types.h>
0008 #include <linux/mutex.h>
0009 #include <linux/slab.h>
0010 #include <linux/bio.h>
0011 
0012 #include "squashfs_fs.h"
0013 #include "squashfs_fs_sb.h"
0014 #include "decompressor.h"
0015 #include "squashfs.h"
0016 
0017 /*
0018  * This file implements single-threaded decompression in the
0019  * decompressor framework
0020  */
0021 
0022 struct squashfs_stream {
0023     void        *stream;
0024     struct mutex    mutex;
0025 };
0026 
0027 void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
0028                         void *comp_opts)
0029 {
0030     struct squashfs_stream *stream;
0031     int err = -ENOMEM;
0032 
0033     stream = kmalloc(sizeof(*stream), GFP_KERNEL);
0034     if (stream == NULL)
0035         goto out;
0036 
0037     stream->stream = msblk->decompressor->init(msblk, comp_opts);
0038     if (IS_ERR(stream->stream)) {
0039         err = PTR_ERR(stream->stream);
0040         goto out;
0041     }
0042 
0043     kfree(comp_opts);
0044     mutex_init(&stream->mutex);
0045     return stream;
0046 
0047 out:
0048     kfree(stream);
0049     return ERR_PTR(err);
0050 }
0051 
0052 void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
0053 {
0054     struct squashfs_stream *stream = msblk->stream;
0055 
0056     if (stream) {
0057         msblk->decompressor->free(stream->stream);
0058         kfree(stream);
0059     }
0060 }
0061 
0062 int squashfs_decompress(struct squashfs_sb_info *msblk, struct bio *bio,
0063             int offset, int length,
0064             struct squashfs_page_actor *output)
0065 {
0066     int res;
0067     struct squashfs_stream *stream = msblk->stream;
0068 
0069     mutex_lock(&stream->mutex);
0070     res = msblk->decompressor->decompress(msblk, stream->stream, bio,
0071         offset, length, output);
0072     mutex_unlock(&stream->mutex);
0073 
0074     if (res < 0)
0075         ERROR("%s decompression failed, data probably corrupt\n",
0076             msblk->decompressor->name);
0077 
0078     return res;
0079 }
0080 
0081 int squashfs_max_decompressors(void)
0082 {
0083     return 1;
0084 }