fs/squashfs/block.c

Source file repositories/reference/linux-study-clean/fs/squashfs/block.c

File Facts

System
Linux kernel
Corpus path
fs/squashfs/block.c
Extension
.c
Size
9458 bytes
Lines
387
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

if (actor_offset >= PAGE_SIZE) {
			actor_addr = squashfs_next_page(actor);
			if (!actor_addr)
				break;
			actor_offset = 0;
		}
		if (offset >= bvec->bv_len) {
			if (!bio_next_segment(bio, &iter_all))
				break;
			offset = 0;
		}
	}
	squashfs_finish_page(actor);
	return copied_bytes;
}

static int squashfs_bio_read_cached(struct bio *fullbio,
		struct address_space *cache_mapping, u64 index, int length,
		u64 read_start, u64 read_end, int page_count)
{
	struct folio *head_to_cache = NULL, *tail_to_cache = NULL;
	struct block_device *bdev = fullbio->bi_bdev;
	int start_idx = 0, end_idx = 0;
	struct folio_iter fi;
	struct bio *bio = NULL;
	int idx = 0;
	int err = 0;
#ifdef CONFIG_SQUASHFS_COMP_CACHE_FULL
	struct folio **cache_folios = kmalloc_objs(*cache_folios, page_count,
						   GFP_KERNEL | __GFP_ZERO);
#endif

	bio_for_each_folio_all(fi, fullbio) {
		struct folio *folio = fi.folio;

		if (folio->mapping == cache_mapping) {
			idx++;
			continue;
		}

		/*
		 * We only use this when the device block size is the same as
		 * the page size, so read_start and read_end cover full pages.
		 *
		 * Compare these to the original required index and length to
		 * only cache pages which were requested partially, since these
		 * are the ones which are likely to be needed when reading
		 * adjacent blocks.
		 */
		if (idx == 0 && index != read_start)
			head_to_cache = folio;
		else if (idx == page_count - 1 && index + length != read_end)
			tail_to_cache = folio;
#ifdef CONFIG_SQUASHFS_COMP_CACHE_FULL
		/* Cache all pages in the BIO for repeated reads */
		else if (cache_folios)
			cache_folios[idx] = folio;
#endif

		if (!bio || idx != end_idx) {
			struct bio *new = bio_alloc_clone(bdev, fullbio,
							  GFP_NOIO, &fs_bio_set);

			if (bio) {
				bio_trim(bio, start_idx * PAGE_SECTORS,
					 (end_idx - start_idx) * PAGE_SECTORS);
				bio_chain(bio, new);
				submit_bio(bio);
			}

			bio = new;
			start_idx = idx;
		}

		idx++;
		end_idx = idx;
	}

	if (bio) {
		bio_trim(bio, start_idx * PAGE_SECTORS,
			 (end_idx - start_idx) * PAGE_SECTORS);
		err = submit_bio_wait(bio);
		bio_put(bio);
	}

	if (err)
		return err;

	if (head_to_cache) {
		int ret = filemap_add_folio(cache_mapping, head_to_cache,

Annotation

Implementation Notes