fs/squashfs/lz4_wrapper.c
Source file repositories/reference/linux-study-clean/fs/squashfs/lz4_wrapper.c
File Facts
- System
- Linux kernel
- Corpus path
fs/squashfs/lz4_wrapper.c- Extension
.c- Size
- 3006 bytes
- Lines
- 147
- 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.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bio.hlinux/mutex.hlinux/slab.hlinux/vmalloc.hlinux/lz4.hsquashfs_fs.hsquashfs_fs_sb.hsquashfs.hdecompressor.hpage_actor.h
Detected Declarations
struct lz4_comp_optsstruct squashfs_lz4function lz4_freefunction lz4_uncompress
Annotated Snippet
struct lz4_comp_opts {
__le32 version;
__le32 flags;
};
struct squashfs_lz4 {
void *input;
void *output;
};
static void *lz4_comp_opts(struct squashfs_sb_info *msblk,
void *buff, int len)
{
struct lz4_comp_opts *comp_opts = buff;
/* LZ4 compressed filesystems always have compression options */
if (comp_opts == NULL || len < sizeof(*comp_opts))
return ERR_PTR(-EIO);
if (le32_to_cpu(comp_opts->version) != LZ4_LEGACY) {
/* LZ4 format currently used by the kernel is the 'legacy'
* format */
ERROR("Unknown LZ4 version\n");
return ERR_PTR(-EINVAL);
}
return NULL;
}
static void *lz4_init(struct squashfs_sb_info *msblk, void *buff)
{
int block_size = max_t(int, msblk->block_size, SQUASHFS_METADATA_SIZE);
struct squashfs_lz4 *stream;
stream = kzalloc_obj(*stream);
if (stream == NULL)
goto failed;
stream->input = vmalloc(block_size);
if (stream->input == NULL)
goto failed2;
stream->output = vmalloc(block_size);
if (stream->output == NULL)
goto failed3;
return stream;
failed3:
vfree(stream->input);
failed2:
kfree(stream);
failed:
ERROR("Failed to initialise LZ4 decompressor\n");
return ERR_PTR(-ENOMEM);
}
static void lz4_free(void *strm)
{
struct squashfs_lz4 *stream = strm;
if (stream) {
vfree(stream->input);
vfree(stream->output);
}
kfree(stream);
}
static int lz4_uncompress(struct squashfs_sb_info *msblk, void *strm,
struct bio *bio, int offset, int length,
struct squashfs_page_actor *output)
{
struct bvec_iter_all iter_all = {};
struct bio_vec *bvec = bvec_init_iter_all(&iter_all);
struct squashfs_lz4 *stream = strm;
void *buff = stream->input, *data;
int bytes = length, res;
while (bio_next_segment(bio, &iter_all)) {
int avail = min(bytes, ((int)bvec->bv_len) - offset);
data = bvec_virt(bvec);
memcpy(buff, data + offset, avail);
buff += avail;
bytes -= avail;
offset = 0;
}
Annotation
- Immediate include surface: `linux/bio.h`, `linux/mutex.h`, `linux/slab.h`, `linux/vmalloc.h`, `linux/lz4.h`, `squashfs_fs.h`, `squashfs_fs_sb.h`, `squashfs.h`.
- Detected declarations: `struct lz4_comp_opts`, `struct squashfs_lz4`, `function lz4_free`, `function lz4_uncompress`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.