2 efd2a263 2018-01-19 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
4 efd2a263 2018-01-19 stsp * Permission to use, copy, modify, and distribute this software for any
5 efd2a263 2018-01-19 stsp * purpose with or without fee is hereby granted, provided that the above
6 efd2a263 2018-01-19 stsp * copyright notice and this permission notice appear in all copies.
8 efd2a263 2018-01-19 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 efd2a263 2018-01-19 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 efd2a263 2018-01-19 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 efd2a263 2018-01-19 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 efd2a263 2018-01-19 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 efd2a263 2018-01-19 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 efd2a263 2018-01-19 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 c3703302 2018-01-23 stsp struct got_delta {
18 c3703302 2018-01-23 stsp SIMPLEQ_ENTRY(got_delta) entry;
19 96f5e8b3 2018-01-23 stsp char *path_packfile;
20 96f5e8b3 2018-01-23 stsp off_t offset;
21 0e22967e 2018-02-11 stsp size_t tslen;
23 5a2e13f7 2018-01-23 stsp size_t size;
24 bdd2fbb3 2018-02-11 stsp off_t data_offset;
27 96f5e8b3 2018-01-23 stsp struct got_delta_chain {
28 96f5e8b3 2018-01-23 stsp int nentries;
29 c3703302 2018-01-23 stsp SIMPLEQ_HEAD(, got_delta) entries;
32 bdd2fbb3 2018-02-11 stsp struct got_delta *got_delta_open(const char *, off_t, size_t, int, size_t,
34 c3703302 2018-01-23 stsp void got_delta_close(struct got_delta *);
35 96f5e8b3 2018-01-23 stsp const struct got_error *got_delta_chain_get_base_type(int *,
36 6691714a 2018-01-23 stsp struct got_delta_chain *);
37 885d3e02 2018-01-27 stsp const struct got_error *got_delta_apply(FILE *, const uint8_t *, size_t,
41 96a1d717 2018-01-24 stsp * Definitions for delta data streams.
44 96a1d717 2018-01-24 stsp #define GOT_DELTA_STREAM_LENGTH_MIN 4 /* bytes */
47 96a1d717 2018-01-24 stsp * A delta stream begins with two size fields. The first specifies the
48 96a1d717 2018-01-24 stsp * size of the delta base, and the second describes the expected size of
49 96a1d717 2018-01-24 stsp * the data which results from combining the delta base and the delta.
51 96a1d717 2018-01-24 stsp * Each size field uses a variable length encoding:
52 96a1d717 2018-01-24 stsp * size0...sizeN form a 7+7+7+...+7 bit integer, where size0 is the
53 96a1d717 2018-01-24 stsp * least significant part and sizeN is the most significant part.
54 96a1d717 2018-01-24 stsp * If the MSB of a size byte is set, an additional size byte follows.
56 96a1d717 2018-01-24 stsp #define GOT_DELTA_SIZE_VAL_MASK 0x7f
57 96a1d717 2018-01-24 stsp #define GOT_DELTA_SIZE_SHIFT 7
58 96a1d717 2018-01-24 stsp #define GOT_DELTA_SIZE_MORE 0x80
61 824801e7 2018-01-27 stsp * The rest of the delta stream contains copy instructions.
63 824801e7 2018-01-27 stsp * A base copy instruction tells the delta combiner to copy N bytes starting
64 824801e7 2018-01-27 stsp * at offset X from the delta base to the output. Base copy instructions begin
65 824801e7 2018-01-27 stsp * with a byte which has its MSB set. The remaining bits of this byte describe
66 824801e7 2018-01-27 stsp * how many offset and length value bytes follow.
67 96a1d717 2018-01-24 stsp * The offset X is encoded in 1 to 4 bytes, and the length N is encoded in
68 96a1d717 2018-01-24 stsp * 1 to 3 bytes. For both values, the first byte contributes the least
69 96a1d717 2018-01-24 stsp * significant part and the last byte which is present contributes the
70 96a1d717 2018-01-24 stsp * most significant part.
71 96a1d717 2018-01-24 stsp * If the offset value is omitted, an offset of zero is implied.
72 96a1d717 2018-01-24 stsp * If the length value is omitted, a default length of 65536 bytes is implied.
74 824801e7 2018-01-27 stsp * An inline copy instruction tells the delta combiner to copy data from
75 824801e7 2018-01-27 stsp * the delta stream to the output.
76 824801e7 2018-01-27 stsp * Such instructions begin with one byte which does not have the MSB set
77 824801e7 2018-01-27 stsp * and which specifies the length of the inline data which follows (i.e.
78 96a1d717 2018-01-24 stsp * at most 127 bytes). A length value of zero is invalid.
81 824801e7 2018-01-27 stsp #define GOT_DELTA_BASE_COPY 0x80
83 96a1d717 2018-01-24 stsp #define GOT_DELTA_COPY_OFF1 0x01 /* byte 1 of offset is present */
84 96a1d717 2018-01-24 stsp #define GOT_DELTA_COPY_OFF2 0x02 /* byte 2 of offset is present */
85 96a1d717 2018-01-24 stsp #define GOT_DELTA_COPY_OFF3 0x04 /* byte 3 of offset is present */
86 96a1d717 2018-01-24 stsp #define GOT_DELTA_COPY_OFF4 0x08 /* byte 4 of offset is present */
88 96a1d717 2018-01-24 stsp #define GOT_DELTA_COPY_LEN1 0x10 /* byte 1 of length is present */
89 96a1d717 2018-01-24 stsp #define GOT_DELTA_COPY_LEN2 0x20 /* byte 2 of length is present */
90 96a1d717 2018-01-24 stsp #define GOT_DELTA_COPY_LEN3 0x40 /* byte 3 of length is present */
92 96a1d717 2018-01-24 stsp #define GOT_DELTA_COPY_DEFAULT_OFF 0x0 /* default offset if omitted */
93 96a1d717 2018-01-24 stsp #define GOT_DELTA_COPY_DEFAULT_LEN 0x10000 /* default length if omitted */