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