| 63 | } |
| 64 | |
| 65 | int write_chunkfile(struct chunkfile *cf, void *data) |
| 66 | { |
| 67 | int i, result = 0; |
| 68 | uint64_t cur_offset = hashfile_total(cf->f); |
| 69 | |
| 70 | trace2_region_enter("chunkfile", "write", the_repository); |
| 71 | |
| 72 | /* Add the table of contents to the current offset */ |
| 73 | cur_offset += (cf->chunks_nr + 1) * CHUNK_TOC_ENTRY_SIZE; |
| 74 | |
| 75 | for (i = 0; i < cf->chunks_nr; i++) { |
| 76 | hashwrite_be32(cf->f, cf->chunks[i].id); |
| 77 | hashwrite_be64(cf->f, cur_offset); |
| 78 | |
| 79 | cur_offset += cf->chunks[i].size; |
| 80 | } |
| 81 | |
| 82 | /* Trailing entry marks the end of the chunks */ |
| 83 | hashwrite_be32(cf->f, 0); |
| 84 | hashwrite_be64(cf->f, cur_offset); |
| 85 | |
| 86 | for (i = 0; i < cf->chunks_nr; i++) { |
| 87 | off_t start_offset = hashfile_total(cf->f); |
| 88 | result = cf->chunks[i].write_fn(cf->f, data); |
| 89 | |
| 90 | if (result) |
| 91 | goto cleanup; |
| 92 | |
| 93 | if (hashfile_total(cf->f) - start_offset != cf->chunks[i].size) |
| 94 | BUG("expected to write %"PRId64" bytes to chunk %"PRIx32", but wrote %"PRId64" instead", |
| 95 | cf->chunks[i].size, cf->chunks[i].id, |
| 96 | hashfile_total(cf->f) - start_offset); |
| 97 | } |
| 98 | |
| 99 | cleanup: |
| 100 | trace2_region_leave("chunkfile", "write", the_repository); |
| 101 | return result; |
| 102 | } |
| 103 | |
| 104 | int read_table_of_contents(struct chunkfile *cf, |
| 105 | const unsigned char *mfile, |
no test coverage detected