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