Blame


1 69aa0e90 2021-03-10 stsp /*
2 69aa0e90 2021-03-10 stsp * Copyright (c) 2020 Ori Bernstein
3 69aa0e90 2021-03-10 stsp * Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
4 69aa0e90 2021-03-10 stsp *
5 69aa0e90 2021-03-10 stsp * Permission to use, copy, modify, and distribute this software for any
6 69aa0e90 2021-03-10 stsp * purpose with or without fee is hereby granted, provided that the above
7 69aa0e90 2021-03-10 stsp * copyright notice and this permission notice appear in all copies.
8 69aa0e90 2021-03-10 stsp *
9 69aa0e90 2021-03-10 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 69aa0e90 2021-03-10 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 69aa0e90 2021-03-10 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 69aa0e90 2021-03-10 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 69aa0e90 2021-03-10 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 69aa0e90 2021-03-10 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 69aa0e90 2021-03-10 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 69aa0e90 2021-03-10 stsp */
17 69aa0e90 2021-03-10 stsp
18 69aa0e90 2021-03-10 stsp struct got_delta_block {
19 69aa0e90 2021-03-10 stsp off_t len;
20 69aa0e90 2021-03-10 stsp off_t offset;
21 f6027426 2022-02-12 naddy uint32_t hash;
22 69aa0e90 2021-03-10 stsp };
23 69aa0e90 2021-03-10 stsp
24 69aa0e90 2021-03-10 stsp struct got_delta_table {
25 69aa0e90 2021-03-10 stsp struct got_delta_block *blocks;
26 69aa0e90 2021-03-10 stsp int nblocks;
27 69aa0e90 2021-03-10 stsp int nalloc;
28 69aa0e90 2021-03-10 stsp };
29 69aa0e90 2021-03-10 stsp
30 69aa0e90 2021-03-10 stsp struct got_delta_instruction {
31 69aa0e90 2021-03-10 stsp int copy;
32 69aa0e90 2021-03-10 stsp off_t offset;
33 69aa0e90 2021-03-10 stsp off_t len;
34 69aa0e90 2021-03-10 stsp };
35 69aa0e90 2021-03-10 stsp
36 69aa0e90 2021-03-10 stsp enum {
37 1ac8bad9 2022-02-11 stsp GOT_DELTIFY_MINCHUNK = 32,
38 69aa0e90 2021-03-10 stsp GOT_DELTIFY_MAXCHUNK = 8192,
39 69aa0e90 2021-03-10 stsp GOT_DELTIFY_SPLITMASK = (1 << 8) - 1,
40 69aa0e90 2021-03-10 stsp };
41 69aa0e90 2021-03-10 stsp
42 69aa0e90 2021-03-10 stsp const struct got_error *got_deltify_init(struct got_delta_table **dt, FILE *f,
43 d6a28ffe 2022-05-20 op off_t fileoffset, off_t filesize, uint32_t seed);
44 64a8571e 2022-01-07 stsp const struct got_error *got_deltify_init_mem(struct got_delta_table **dt,
45 d6a28ffe 2022-05-20 op uint8_t *data, off_t fileoffset, off_t filesize, uint32_t seed);
46 69aa0e90 2021-03-10 stsp const struct got_error *got_deltify(struct got_delta_instruction **deltas,
47 d6a28ffe 2022-05-20 op int *ndeltas, FILE *f, off_t fileoffset, off_t filesize, uint32_t seed,
48 f34b169e 2021-06-18 stsp struct got_delta_table *dt, FILE *basefile, off_t basefile_offset0,
49 f34b169e 2021-06-18 stsp off_t basefile_size);
50 64a8571e 2022-01-07 stsp const struct got_error *got_deltify_file_mem(
51 64a8571e 2022-01-07 stsp struct got_delta_instruction **deltas, int *ndeltas,
52 d6a28ffe 2022-05-20 op FILE *f, off_t fileoffset, off_t filesize, uint32_t seed,
53 d6a28ffe 2022-05-20 op struct got_delta_table *dt, uint8_t *basedata, off_t basefile_offset0,
54 d6a28ffe 2022-05-20 op off_t basefile_size);
55 64a8571e 2022-01-07 stsp const struct got_error *got_deltify_mem_file(
56 64a8571e 2022-01-07 stsp struct got_delta_instruction **deltas, int *ndeltas,
57 d6a28ffe 2022-05-20 op uint8_t *data, off_t fileoffset, off_t filesize, uint32_t seed,
58 d6a28ffe 2022-05-20 op struct got_delta_table *dt, FILE *basefile, off_t basefile_offset0,
59 d6a28ffe 2022-05-20 op off_t basefile_size);
60 64a8571e 2022-01-07 stsp const struct got_error *got_deltify_mem_mem(
61 64a8571e 2022-01-07 stsp struct got_delta_instruction **deltas, int *ndeltas,
62 d6a28ffe 2022-05-20 op uint8_t *data, off_t fileoffset, off_t filesize, uint32_t seed,
63 d6a28ffe 2022-05-20 op struct got_delta_table *dt, uint8_t *basedata, off_t basefile_offset0,
64 d6a28ffe 2022-05-20 op off_t basefile_size);
65 69aa0e90 2021-03-10 stsp void got_deltify_free(struct got_delta_table *dt);