]> git.ipfire.org Git - thirdparty/git.git/blame - csum-file.h
reftable: add a test that verifies that writing empty keys fails
[thirdparty/git.git] / csum-file.h
CommitLineData
c38138cd
LT
1#ifndef CSUM_FILE_H
2#define CSUM_FILE_H
3
ef3ca954
EN
4#include "hash.h"
5
2a128d63
NP
6struct progress;
7
c38138cd 8/* A SHA1-protected file */
98a3beab 9struct hashfile {
ec640ed1 10 int fd;
e337a04d 11 int check_fd;
ec640ed1 12 unsigned int offset;
4d273500 13 git_hash_ctx ctx;
218558af 14 off_t total;
2a128d63 15 struct progress *tp;
ec640ed1 16 const char *name;
78d1e84f
NP
17 int do_crc;
18 uint32_t crc32;
2ca245f8
DS
19 size_t buffer_len;
20 unsigned char *buffer;
21 unsigned char *check_buffer;
c38138cd
LT
22};
23
6c526148 24/* Checkpoint */
98a3beab 25struct hashfile_checkpoint {
6c526148 26 off_t offset;
4d273500 27 git_hash_ctx ctx;
6c526148
JH
28};
29
55454427
DL
30void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *);
31int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);
6c526148 32
f2af9f5e 33/* finalize_hashfile flags */
cfe83216
DS
34#define CSUM_CLOSE 1
35#define CSUM_FSYNC 2
36#define CSUM_HASH_IN_STREAM 4
4c81b03e 37
55454427
DL
38struct hashfile *hashfd(int fd, const char *name);
39struct hashfile *hashfd_check(const char *name);
40struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp);
41int finalize_hashfile(struct hashfile *, unsigned char *, unsigned int);
42void hashwrite(struct hashfile *, const void *, unsigned int);
43void hashflush(struct hashfile *f);
44void crc32_begin(struct hashfile *);
45uint32_t crc32_end(struct hashfile *);
c38138cd 46
f9221e2c
TB
47/* Verify checksum validity while reading. Returns non-zero on success. */
48int hashfile_checksum_valid(const unsigned char *data, size_t len);
49
2f4af776
JK
50/*
51 * Returns the total number of bytes fed to the hashfile so far (including ones
52 * that have not been written out to the descriptor yet).
53 */
54static inline off_t hashfile_total(struct hashfile *f)
55{
56 return f->total + f->offset;
57}
58
98a3beab 59static inline void hashwrite_u8(struct hashfile *f, uint8_t data)
b5007211 60{
98a3beab 61 hashwrite(f, &data, sizeof(data));
b5007211
KB
62}
63
98a3beab 64static inline void hashwrite_be32(struct hashfile *f, uint32_t data)
b5007211
KB
65{
66 data = htonl(data);
98a3beab 67 hashwrite(f, &data, sizeof(data));
b5007211
KB
68}
69
54273d10
RS
70static inline size_t hashwrite_be64(struct hashfile *f, uint64_t data)
71{
72 data = htonll(data);
73 hashwrite(f, &data, sizeof(data));
74 return sizeof(data);
75}
76
c38138cd 77#endif