1 // SPDX-License-Identifier: GPL-2.0-or-later 1 2 /* 3 * Squashfs - a compressed read only filesyste 4 * 5 * Copyright (c) 2002, 2003, 2004, 2005, 2006, 6 * Phillip Lougher <phillip@squashfs.org.uk> 7 * 8 * fragment.c 9 */ 10 11 /* 12 * This file implements code to handle compres 13 * datablocks). 14 * 15 * Regular files contain a fragment index whic 16 * location on disk and compressed size using 17 * Like everything in Squashfs this fragment l 18 * compressed into metadata blocks. A second 19 * these. This second index table for speed o 20 * is small) is read at mount time and cached 21 */ 22 23 #include <linux/fs.h> 24 #include <linux/vfs.h> 25 #include <linux/slab.h> 26 27 #include "squashfs_fs.h" 28 #include "squashfs_fs_sb.h" 29 #include "squashfs.h" 30 31 /* 32 * Look-up fragment using the fragment index t 33 * location of the fragment and its compressed 34 */ 35 int squashfs_frag_lookup(struct super_block *s 36 u64 *fragment_ 37 { 38 struct squashfs_sb_info *msblk = sb->s 39 int block, offset, size; 40 struct squashfs_fragment_entry fragmen 41 u64 start_block; 42 43 if (fragment >= msblk->fragments) 44 return -EIO; 45 block = SQUASHFS_FRAGMENT_INDEX(fragme 46 offset = SQUASHFS_FRAGMENT_INDEX_OFFSE 47 48 start_block = le64_to_cpu(msblk->fragm 49 50 size = squashfs_read_metadata(sb, &fra 51 &offse 52 if (size < 0) 53 return size; 54 55 *fragment_block = le64_to_cpu(fragment 56 return squashfs_block_size(fragment_en 57 } 58 59 60 /* 61 * Read the uncompressed fragment lookup table 62 */ 63 __le64 *squashfs_read_fragment_index_table(str 64 u64 fragment_table_start, u64 next_tab 65 { 66 unsigned int length = SQUASHFS_FRAGMEN 67 __le64 *table; 68 69 /* 70 * Sanity check, length bytes should n 71 * this check also traps instances whe 72 * incorrectly larger than the next ta 73 */ 74 if (fragment_table_start + length > ne 75 return ERR_PTR(-EINVAL); 76 77 table = squashfs_read_table(sb, fragme 78 79 /* 80 * table[0] points to the first fragme 81 * should be less than fragment_table_ 82 */ 83 if (!IS_ERR(table) && le64_to_cpu(tabl 84 kfree(table); 85 return ERR_PTR(-EINVAL); 86 } 87 88 return table; 89 } 90
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.