Skip to content

Commit 2a1f7c0

Browse files
adam900710kdave
authored andcommitted
btrfs: lzo: document the compressed data format
Although it's not that complex, but such comment could still save several minutes for newer reader/reviewer instead of inferring that from the code. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> [ minor wording updates ] Signed-off-by: David Sterba <dsterba@suse.com>
1 parent d5c1d68 commit 2a1f7c0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

fs/btrfs/lzo.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,43 @@
1717

1818
#define LZO_LEN 4
1919

20+
/*
21+
* Btrfs LZO compression format
22+
*
23+
* Regular and inlined LZO compressed data extents consist of:
24+
*
25+
* 1. Header
26+
* Fixed size. LZO_LEN (4) bytes long, LE32.
27+
* Records the total size (including the header) of compressed data.
28+
*
29+
* 2. Segment(s)
30+
* Variable size. Each segment includes one segment header, followd by data
31+
* payload.
32+
* One regular LZO compressed extent can have one or more segments.
33+
* For inlined LZO compressed extent, only one segment is allowed.
34+
* One segment represents at most one page of uncompressed data.
35+
*
36+
* 2.1 Segment header
37+
* Fixed size. LZO_LEN (4) bytes long, LE32.
38+
* Records the total size of the segment (not including the header).
39+
* Segment header never crosses page boundary, thus it's possible to
40+
* have at most 3 padding zeros at the end of the page.
41+
*
42+
* 2.2 Data Payload
43+
* Variable size. Size up limit should be lzo1x_worst_compress(PAGE_SIZE)
44+
* which is 4419 for a 4KiB page.
45+
*
46+
* Example:
47+
* Page 1:
48+
* 0 0x2 0x4 0x6 0x8 0xa 0xc 0xe 0x10
49+
* 0x0000 | Header | SegHdr 01 | Data payload 01 ... |
50+
* ...
51+
* 0x0ff0 | SegHdr N | Data payload N ... |00|
52+
* ^^ padding zeros
53+
* Page 2:
54+
* 0x1000 | SegHdr N+1| Data payload N+1 ... |
55+
*/
56+
2057
struct workspace {
2158
void *mem;
2259
void *buf; /* where decompressed data goes */

0 commit comments

Comments
 (0)