fs/smb/common/compress/lz77.c
Source file repositories/reference/linux-study-clean/fs/smb/common/compress/lz77.c
File Facts
- System
- Linux kernel
- Corpus path
fs/smb/common/compress/lz77.c- Extension
.c- Size
- 10467 bytes
- Lines
- 462
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
Dependency Surface
linux/slab.hlinux/sizes.hlinux/count_zeros.hlinux/unaligned.hlinux/module.hlinux/overflow.hlz77.h
Detected Declarations
function Copyrightfunction lz77_read32function lz77_read64function lz77_write8function lz77_write16function lz77_write32function lz77_match_lenfunction lz77_encode_matchfunction lz77_encode_literalsfunction lz77_hashfunction smb_lz77_compressfunction lz77_decode_match_lenfunction smb_lz77_decompressexport smb_lz77_compressexport smb_lz77_decompress
Annotated Snippet
if (!diff) {
cur += LZ77_MSTEP_SIZE;
match += LZ77_MSTEP_SIZE;
continue;
}
/* This computes the number of common bytes in @diff. */
cur += count_trailing_zeros(diff) >> 3;
return (cur - start);
} while (likely(cur + LZ77_MSTEP_SIZE <= end));
/* Fallback to byte-by-byte comparison for last <8 bytes. */
while (cur < end && lz77_read8(cur) == lz77_read8(match)) {
cur++;
match++;
}
return (cur - start);
}
/**
* lz77_encode_match() - Match encoding.
* @dst: compressed buffer
* @nib: pointer to an address in @dst
* @dist: match distance
* @len: match length
*
* Assumes all args were previously checked.
*
* Return: @dst advanced to new position
*
* Ref: MS-XCA 2.3.4 "Plain LZ77 Compression Algorithm Details" - "Processing"
*/
static __always_inline void *lz77_encode_match(void *dst, void **nib, u16 dist, u32 len)
{
len -= 3;
dist--;
dist <<= 3;
if (len < 7) {
lz77_write16(dst, dist + len);
return dst + sizeof(u16);
}
dist |= 7;
lz77_write16(dst, dist);
dst += sizeof(u16);
len -= 7;
if (!*nib) {
lz77_write8(dst, umin(len, 15));
*nib = dst;
dst++;
} else {
u8 *b = *nib;
lz77_write8(b, *b | umin(len, 15) << 4);
*nib = NULL;
}
if (len < 15)
return dst;
len -= 15;
if (len < 255) {
lz77_write8(dst, len);
return dst + 1;
}
lz77_write8(dst, 0xff);
dst++;
len += 7 + 15;
if (len <= 0xffff) {
lz77_write16(dst, len);
return dst + sizeof(u16);
}
lz77_write16(dst, 0);
dst += sizeof(u16);
lz77_write32(dst, len);
return dst + sizeof(u32);
}
/**
Annotation
- Immediate include surface: `linux/slab.h`, `linux/sizes.h`, `linux/count_zeros.h`, `linux/unaligned.h`, `linux/module.h`, `linux/overflow.h`, `lz77.h`.
- Detected declarations: `function Copyright`, `function lz77_read32`, `function lz77_read64`, `function lz77_write8`, `function lz77_write16`, `function lz77_write32`, `function lz77_match_len`, `function lz77_encode_match`, `function lz77_encode_literals`, `function lz77_hash`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration 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.