.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Squashfs - a compressed read only filesystem for Linux |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 |
---|
5 | 6 | * Phillip Lougher <phillip@squashfs.org.uk> |
---|
6 | 7 | * |
---|
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 | 8 | * zlib_wrapper.c |
---|
22 | 9 | */ |
---|
23 | 10 | |
---|
24 | 11 | |
---|
25 | 12 | #include <linux/mutex.h> |
---|
26 | | -#include <linux/buffer_head.h> |
---|
| 13 | +#include <linux/bio.h> |
---|
27 | 14 | #include <linux/slab.h> |
---|
28 | 15 | #include <linux/zlib.h> |
---|
29 | 16 | #include <linux/vmalloc.h> |
---|
.. | .. |
---|
63 | 50 | |
---|
64 | 51 | |
---|
65 | 52 | static int zlib_uncompress(struct squashfs_sb_info *msblk, void *strm, |
---|
66 | | - struct buffer_head **bh, int b, int offset, int length, |
---|
| 53 | + struct bio *bio, int offset, int length, |
---|
67 | 54 | struct squashfs_page_actor *output) |
---|
68 | 55 | { |
---|
69 | | - int zlib_err, zlib_init = 0, k = 0; |
---|
| 56 | + struct bvec_iter_all iter_all = {}; |
---|
| 57 | + struct bio_vec *bvec = bvec_init_iter_all(&iter_all); |
---|
| 58 | + int zlib_init = 0, error = 0; |
---|
70 | 59 | z_stream *stream = strm; |
---|
71 | 60 | |
---|
72 | 61 | stream->avail_out = PAGE_SIZE; |
---|
73 | 62 | stream->next_out = squashfs_first_page(output); |
---|
74 | 63 | stream->avail_in = 0; |
---|
75 | 64 | |
---|
76 | | - do { |
---|
77 | | - if (stream->avail_in == 0 && k < b) { |
---|
78 | | - int avail = min(length, msblk->devblksize - offset); |
---|
| 65 | + for (;;) { |
---|
| 66 | + int zlib_err; |
---|
| 67 | + |
---|
| 68 | + if (stream->avail_in == 0) { |
---|
| 69 | + const void *data; |
---|
| 70 | + int avail; |
---|
| 71 | + |
---|
| 72 | + if (!bio_next_segment(bio, &iter_all)) { |
---|
| 73 | + /* Z_STREAM_END must be reached. */ |
---|
| 74 | + error = -EIO; |
---|
| 75 | + break; |
---|
| 76 | + } |
---|
| 77 | + |
---|
| 78 | + avail = min(length, ((int)bvec->bv_len) - offset); |
---|
| 79 | + data = page_address(bvec->bv_page) + bvec->bv_offset; |
---|
79 | 80 | length -= avail; |
---|
80 | | - stream->next_in = bh[k]->b_data + offset; |
---|
| 81 | + stream->next_in = data + offset; |
---|
81 | 82 | stream->avail_in = avail; |
---|
82 | 83 | offset = 0; |
---|
83 | 84 | } |
---|
.. | .. |
---|
91 | 92 | if (!zlib_init) { |
---|
92 | 93 | zlib_err = zlib_inflateInit(stream); |
---|
93 | 94 | if (zlib_err != Z_OK) { |
---|
94 | | - squashfs_finish_page(output); |
---|
95 | | - goto out; |
---|
| 95 | + error = -EIO; |
---|
| 96 | + break; |
---|
96 | 97 | } |
---|
97 | 98 | zlib_init = 1; |
---|
98 | 99 | } |
---|
99 | 100 | |
---|
100 | 101 | zlib_err = zlib_inflate(stream, Z_SYNC_FLUSH); |
---|
101 | | - |
---|
102 | | - if (stream->avail_in == 0 && k < b) |
---|
103 | | - put_bh(bh[k++]); |
---|
104 | | - } while (zlib_err == Z_OK); |
---|
| 102 | + if (zlib_err == Z_STREAM_END) |
---|
| 103 | + break; |
---|
| 104 | + if (zlib_err != Z_OK) { |
---|
| 105 | + error = -EIO; |
---|
| 106 | + break; |
---|
| 107 | + } |
---|
| 108 | + } |
---|
105 | 109 | |
---|
106 | 110 | squashfs_finish_page(output); |
---|
107 | 111 | |
---|
108 | | - if (zlib_err != Z_STREAM_END) |
---|
109 | | - goto out; |
---|
| 112 | + if (!error) |
---|
| 113 | + if (zlib_inflateEnd(stream) != Z_OK) |
---|
| 114 | + error = -EIO; |
---|
110 | 115 | |
---|
111 | | - zlib_err = zlib_inflateEnd(stream); |
---|
112 | | - if (zlib_err != Z_OK) |
---|
113 | | - goto out; |
---|
114 | | - |
---|
115 | | - if (k < b) |
---|
116 | | - goto out; |
---|
117 | | - |
---|
118 | | - return stream->total_out; |
---|
119 | | - |
---|
120 | | -out: |
---|
121 | | - for (; k < b; k++) |
---|
122 | | - put_bh(bh[k]); |
---|
123 | | - |
---|
124 | | - return -EIO; |
---|
| 116 | + return error ? error : stream->total_out; |
---|
125 | 117 | } |
---|
126 | 118 | |
---|
127 | 119 | const struct squashfs_decompressor squashfs_zlib_comp_ops = { |
---|