1 // SPDX-License-Identifier: GPL-2.0-or-later << 2 /* 1 /* 3 * Squashfs - a compressed read only filesyste 2 * Squashfs - a compressed read only filesystem for Linux 4 * 3 * 5 * Copyright (c) 2010 LG Electronics 4 * Copyright (c) 2010 LG Electronics 6 * Chan Jeong <chan.jeong@lge.com> 5 * Chan Jeong <chan.jeong@lge.com> 7 * 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 * 8 * lzo_wrapper.c 21 * lzo_wrapper.c 9 */ 22 */ 10 23 11 #include <linux/mutex.h> 24 #include <linux/mutex.h> 12 #include <linux/bio.h> !! 25 #include <linux/buffer_head.h> 13 #include <linux/slab.h> 26 #include <linux/slab.h> 14 #include <linux/vmalloc.h> 27 #include <linux/vmalloc.h> 15 #include <linux/lzo.h> 28 #include <linux/lzo.h> 16 29 17 #include "squashfs_fs.h" 30 #include "squashfs_fs.h" 18 #include "squashfs_fs_sb.h" 31 #include "squashfs_fs_sb.h" 19 #include "squashfs.h" 32 #include "squashfs.h" 20 #include "decompressor.h" 33 #include "decompressor.h" 21 #include "page_actor.h" 34 #include "page_actor.h" 22 35 23 struct squashfs_lzo { 36 struct squashfs_lzo { 24 void *input; 37 void *input; 25 void *output; 38 void *output; 26 }; 39 }; 27 40 28 static void *lzo_init(struct squashfs_sb_info 41 static void *lzo_init(struct squashfs_sb_info *msblk, void *buff) 29 { 42 { 30 int block_size = max_t(int, msblk->blo 43 int block_size = max_t(int, msblk->block_size, SQUASHFS_METADATA_SIZE); 31 44 32 struct squashfs_lzo *stream = kzalloc( 45 struct squashfs_lzo *stream = kzalloc(sizeof(*stream), GFP_KERNEL); 33 if (stream == NULL) 46 if (stream == NULL) 34 goto failed; 47 goto failed; 35 stream->input = vmalloc(block_size); 48 stream->input = vmalloc(block_size); 36 if (stream->input == NULL) 49 if (stream->input == NULL) 37 goto failed; 50 goto failed; 38 stream->output = vmalloc(block_size); 51 stream->output = vmalloc(block_size); 39 if (stream->output == NULL) 52 if (stream->output == NULL) 40 goto failed2; 53 goto failed2; 41 54 42 return stream; 55 return stream; 43 56 44 failed2: 57 failed2: 45 vfree(stream->input); 58 vfree(stream->input); 46 failed: 59 failed: 47 ERROR("Failed to allocate lzo workspac 60 ERROR("Failed to allocate lzo workspace\n"); 48 kfree(stream); 61 kfree(stream); 49 return ERR_PTR(-ENOMEM); 62 return ERR_PTR(-ENOMEM); 50 } 63 } 51 64 52 65 53 static void lzo_free(void *strm) 66 static void lzo_free(void *strm) 54 { 67 { 55 struct squashfs_lzo *stream = strm; 68 struct squashfs_lzo *stream = strm; 56 69 57 if (stream) { 70 if (stream) { 58 vfree(stream->input); 71 vfree(stream->input); 59 vfree(stream->output); 72 vfree(stream->output); 60 } 73 } 61 kfree(stream); 74 kfree(stream); 62 } 75 } 63 76 64 77 65 static int lzo_uncompress(struct squashfs_sb_i 78 static int lzo_uncompress(struct squashfs_sb_info *msblk, void *strm, 66 struct bio *bio, int offset, int lengt !! 79 struct buffer_head **bh, int b, int offset, int length, 67 struct squashfs_page_actor *output) 80 struct squashfs_page_actor *output) 68 { 81 { 69 struct bvec_iter_all iter_all = {}; << 70 struct bio_vec *bvec = bvec_init_iter_ << 71 struct squashfs_lzo *stream = strm; 82 struct squashfs_lzo *stream = strm; 72 void *buff = stream->input, *data; 83 void *buff = stream->input, *data; 73 int bytes = length, res; !! 84 int avail, i, bytes = length, res; 74 size_t out_len = output->length; 85 size_t out_len = output->length; 75 86 76 while (bio_next_segment(bio, &iter_all !! 87 for (i = 0; i < b; i++) { 77 int avail = min(bytes, ((int)b !! 88 avail = min(bytes, msblk->devblksize - offset); 78 !! 89 memcpy(buff, bh[i]->b_data + offset, avail); 79 data = bvec_virt(bvec); << 80 memcpy(buff, data + offset, av << 81 buff += avail; 90 buff += avail; 82 bytes -= avail; 91 bytes -= avail; 83 offset = 0; 92 offset = 0; >> 93 put_bh(bh[i]); 84 } 94 } 85 95 86 res = lzo1x_decompress_safe(stream->in 96 res = lzo1x_decompress_safe(stream->input, (size_t)length, 87 stream 97 stream->output, &out_len); 88 if (res != LZO_E_OK) 98 if (res != LZO_E_OK) 89 goto failed; 99 goto failed; 90 100 91 res = bytes = (int)out_len; 101 res = bytes = (int)out_len; 92 data = squashfs_first_page(output); 102 data = squashfs_first_page(output); 93 buff = stream->output; 103 buff = stream->output; 94 while (data) { 104 while (data) { 95 if (bytes <= PAGE_SIZE) { !! 105 if (bytes <= PAGE_CACHE_SIZE) { 96 if (!IS_ERR(data)) !! 106 memcpy(data, buff, bytes); 97 memcpy(data, b << 98 break; 107 break; 99 } else { 108 } else { 100 if (!IS_ERR(data)) !! 109 memcpy(data, buff, PAGE_CACHE_SIZE); 101 memcpy(data, b !! 110 buff += PAGE_CACHE_SIZE; 102 buff += PAGE_SIZE; !! 111 bytes -= PAGE_CACHE_SIZE; 103 bytes -= PAGE_SIZE; << 104 data = squashfs_next_p 112 data = squashfs_next_page(output); 105 } 113 } 106 } 114 } 107 squashfs_finish_page(output); 115 squashfs_finish_page(output); 108 116 109 return res; 117 return res; 110 118 111 failed: 119 failed: 112 return -EIO; 120 return -EIO; 113 } 121 } 114 122 115 const struct squashfs_decompressor squashfs_lz 123 const struct squashfs_decompressor squashfs_lzo_comp_ops = { 116 .init = lzo_init, 124 .init = lzo_init, 117 .free = lzo_free, 125 .free = lzo_free, 118 .decompress = lzo_uncompress, 126 .decompress = lzo_uncompress, 119 .id = LZO_COMPRESSION, 127 .id = LZO_COMPRESSION, 120 .name = "lzo", 128 .name = "lzo", 121 .alloc_buffer = 0, << 122 .supported = 1 129 .supported = 1 123 }; 130 }; 124 131
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.