]> git.ipfire.org Git - thirdparty/git.git/blame - chunk-format.h
The fourteenth batch
[thirdparty/git.git] / chunk-format.h
CommitLineData
570df426
DS
1#ifndef CHUNK_FORMAT_H
2#define CHUNK_FORMAT_H
3
d1cbe1e6 4#include "hash-ll.h"
570df426
DS
5
6struct hashfile;
7struct chunkfile;
8
9#define CHUNK_TOC_ENTRY_SIZE (sizeof(uint32_t) + sizeof(uint64_t))
10
5f0879f5
DS
11/*
12 * Initialize a 'struct chunkfile' for writing _or_ reading a file
13 * with the chunk format.
14 *
15 * If writing a file, supply a non-NULL 'struct hashfile *' that will
16 * be used to write.
17 *
18 * If reading a file, use a NULL 'struct hashfile *' and then call
19 * read_table_of_contents(). Supply the memory-mapped data to the
20 * pair_chunk() or read_chunk() methods, as appropriate.
21 *
22 * DO NOT MIX THESE MODES. Use different 'struct chunkfile' instances
23 * for reading and writing.
24 */
570df426
DS
25struct chunkfile *init_chunkfile(struct hashfile *f);
26void free_chunkfile(struct chunkfile *cf);
27int get_num_chunks(struct chunkfile *cf);
28typedef int (*chunk_write_fn)(struct hashfile *f, void *data);
29void add_chunk(struct chunkfile *cf,
30 uint32_t id,
31 size_t size,
32 chunk_write_fn fn);
33int write_chunkfile(struct chunkfile *cf, void *data);
34
5f0879f5
DS
35int read_table_of_contents(struct chunkfile *cf,
36 const unsigned char *mfile,
37 size_t mfile_size,
38 uint64_t toc_offset,
c9b9fefc
JK
39 int toc_length,
40 unsigned expected_alignment);
5f0879f5
DS
41
42#define CHUNK_NOT_FOUND (-2)
43
44/*
45 * Find 'chunk_id' in the given chunkfile and assign the
46 * given pointer to the position in the mmap'd file where
570b8b88
JK
47 * that chunk begins. Likewise the "size" parameter is filled
48 * with the size of the chunk.
5f0879f5
DS
49 *
50 * Returns CHUNK_NOT_FOUND if the chunk does not exist.
51 */
52int pair_chunk(struct chunkfile *cf,
53 uint32_t chunk_id,
570b8b88
JK
54 const unsigned char **p,
55 size_t *size);
56
5f0879f5
DS
57typedef int (*chunk_read_fn)(const unsigned char *chunk_start,
58 size_t chunk_size, void *data);
59/*
60 * Find 'chunk_id' in the given chunkfile and call the
61 * given chunk_read_fn method with the information for
62 * that chunk.
63 *
64 * Returns CHUNK_NOT_FOUND if the chunk does not exist.
65 */
66int read_chunk(struct chunkfile *cf,
67 uint32_t chunk_id,
68 chunk_read_fn fn,
69 void *data);
70
d9fef9d9
TB
71uint8_t oid_version(const struct git_hash_algo *algop);
72
570df426 73#endif