rust-kernel
Rustbelt: a hobby x86_64 kernel written in Rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | //! LZO1X decompression, hand-written (btrfs's "lzo" compression).
//!
//! LZO (Markus Oberhumer, 1996) is an LZ77-style compressor built for speed.
//! The compressed stream is a sequence of instructions, each either
//! "copy the next N bytes as they are" (a **literal run**) or "copy N bytes
//! from D bytes back in the output" (a **match**, which may overlap itself,
//! so `abcabcabc` is "abc" plus one match of 6 at distance 3).
//!
//! An instruction starts with one byte `t`; its range says what it is:
//!
//! ```text
//! t >= 64 M2 match: length 3-8, distance up to 2 KiB (one more byte)
//! 32 <= t < 64 M3 match: length from t (or a run of zero bytes), distance
//! up to 16 KiB in the next two bytes
//! 16 <= t < 32 M4 match: distance 16-48 KiB; distance 16 KiB exactly
//! means "end of stream"
//! t < 16 depends on what came before (the `state`):
//! after a match with no trailing literals: a literal run;
//! after 1-3 trailing literals: a 2-byte match, distance <= 1 KiB;
//! after a long literal run: a 3-byte match, distance 2-3 KiB
//! ```
//!
//! The low 2 bits of most match instructions say how many literals (0-3)
//! follow the match, so short literal runs cost no extra byte. Long lengths
//! are written as a 0 (meaning "more"), then zero bytes worth 255 each,
//! then a final byte that's added.
//!
//! This follows the Linux kernel's `lzo1x_decompress_safe`, with every
//! read and back-reference checked: bad input gives `Err`, never a panic.
use Vec;
/// Decompress one LZO1X stream, appending to `out`. `limit` is the most
/// bytes this stream may produce (btrfs: one sector).
|