Lines Matching +full:block +full:- +full:offset

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Squashfs - a compressed read only filesystem for Linux
8 * block.c
12 * This file implements the low-level routines to read and decompress
35 int offset, int req_length) in copy_bio_to_actor() argument
50 int bytes_to_copy = min_t(int, bvec->bv_len - offset, in copy_bio_to_actor()
51 PAGE_SIZE - actor_offset); in copy_bio_to_actor()
54 req_length - copied_bytes); in copy_bio_to_actor()
57 offset, bytes_to_copy); in copy_bio_to_actor()
61 offset += bytes_to_copy; in copy_bio_to_actor()
69 if (offset >= bvec->bv_len) { in copy_bio_to_actor()
72 offset = 0; in copy_bio_to_actor()
84 struct block_device *bdev = fullbio->bi_bdev; in squashfs_bio_read_cached()
97 struct page *page = bv->bv_page; in squashfs_bio_read_cached()
99 if (page->mapping == cache_mapping) { in squashfs_bio_read_cached()
105 * We only use this when the device block size is the same as in squashfs_bio_read_cached()
115 else if (idx == page_count - 1 && index + length != read_end) in squashfs_bio_read_cached()
129 (end_idx - start_idx) * PAGE_SECTORS); in squashfs_bio_read_cached()
144 (end_idx - start_idx) * PAGE_SECTORS); in squashfs_bio_read_cached()
166 (read_end >> PAGE_SHIFT) - 1, in squashfs_bio_read_cached()
220 struct squashfs_sb_info *msblk = sb->s_fs_info; in squashfs_bio_read()
221 struct address_space *cache_mapping = msblk->cache_mapping; in squashfs_bio_read()
222 const u64 read_start = round_down(index, msblk->devblksize); in squashfs_bio_read()
223 const sector_t block = read_start >> msblk->devblksize_log2; in squashfs_bio_read() local
224 const u64 read_end = round_up(index + length, msblk->devblksize); in squashfs_bio_read()
225 const sector_t block_end = read_end >> msblk->devblksize_log2; in squashfs_bio_read()
226 int offset = read_start - round_down(index, PAGE_SIZE); in squashfs_bio_read() local
227 int total_len = (block_end - block) << msblk->devblksize_log2; in squashfs_bio_read()
228 const int page_count = DIV_ROUND_UP(total_len + offset, PAGE_SIZE); in squashfs_bio_read()
234 return -ENOMEM; in squashfs_bio_read()
235 bio_init(bio, sb->s_bdev, bio->bi_inline_vecs, page_count, REQ_OP_READ); in squashfs_bio_read()
236 bio->bi_iter.bi_sector = block * (msblk->devblksize >> SECTOR_SHIFT); in squashfs_bio_read()
240 min_t(unsigned int, PAGE_SIZE - offset, total_len); in squashfs_bio_read()
249 error = -ENOMEM; in squashfs_bio_read()
257 __bio_add_page(bio, page, len, offset); in squashfs_bio_read()
258 offset = 0; in squashfs_bio_read()
259 total_len -= len; in squashfs_bio_read()
272 *block_offset = index & ((1 << msblk->devblksize_log2) - 1); in squashfs_bio_read()
283 * Read and decompress a metadata block or datablock. Length is non-zero
286 * the metadata block. A bit in the length field indicates if the block
288 * generated a larger block - this does occasionally happen with compression
294 struct squashfs_sb_info *msblk = sb->s_fs_info; in squashfs_read_data()
298 int offset; in squashfs_read_data() local
306 TRACE("Block @ 0x%llx, %scompressed size %d, src size %d\n", in squashfs_read_data()
307 index, compressed ? "" : "un", length, output->length); in squashfs_read_data()
310 * Metadata block. in squashfs_read_data()
316 if (index + 2 > msblk->bytes_used) { in squashfs_read_data()
317 res = -EIO; in squashfs_read_data()
320 res = squashfs_bio_read(sb, index, 2, &bio, &offset); in squashfs_read_data()
325 res = -EIO; in squashfs_read_data()
328 /* Extract the length of the metadata block */ in squashfs_read_data()
330 length = data[offset]; in squashfs_read_data()
331 if (offset < bvec->bv_len - 1) { in squashfs_read_data()
332 length |= data[offset + 1] << 8; in squashfs_read_data()
335 res = -EIO; in squashfs_read_data()
349 TRACE("Block @ 0x%llx, %scompressed size %d\n", index - 2, in squashfs_read_data()
352 if (length <= 0 || length > output->length || in squashfs_read_data()
353 (index + length) > msblk->bytes_used) { in squashfs_read_data()
354 res = -EIO; in squashfs_read_data()
361 res = squashfs_bio_read(sb, index, length, &bio, &offset); in squashfs_read_data()
366 if (!msblk->stream) { in squashfs_read_data()
367 res = -EIO; in squashfs_read_data()
370 res = msblk->thread_ops->decompress(msblk, bio, offset, length, output); in squashfs_read_data()
372 res = copy_bio_to_actor(bio, output, offset, length); in squashfs_read_data()
381 ERROR("Failed to read block 0x%llx: %d\n", index, res); in squashfs_read_data()
382 if (msblk->panic_on_errors) in squashfs_read_data()