]> git.ipfire.org Git - thirdparty/git.git/blame_incremental - csum-file.h
Merge branch 'rs/hashwrite-be64'
[thirdparty/git.git] / csum-file.h
... / ...
CommitLineData
1#ifndef CSUM_FILE_H
2#define CSUM_FILE_H
3
4#include "hash.h"
5
6struct progress;
7
8/* A SHA1-protected file */
9struct hashfile {
10 int fd;
11 int check_fd;
12 unsigned int offset;
13 git_hash_ctx ctx;
14 off_t total;
15 struct progress *tp;
16 const char *name;
17 int do_crc;
18 uint32_t crc32;
19 unsigned char buffer[8192];
20};
21
22/* Checkpoint */
23struct hashfile_checkpoint {
24 off_t offset;
25 git_hash_ctx ctx;
26};
27
28void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *);
29int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);
30
31/* finalize_hashfile flags */
32#define CSUM_CLOSE 1
33#define CSUM_FSYNC 2
34#define CSUM_HASH_IN_STREAM 4
35
36struct hashfile *hashfd(int fd, const char *name);
37struct hashfile *hashfd_check(const char *name);
38struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp);
39int finalize_hashfile(struct hashfile *, unsigned char *, unsigned int);
40void hashwrite(struct hashfile *, const void *, unsigned int);
41void hashflush(struct hashfile *f);
42void crc32_begin(struct hashfile *);
43uint32_t crc32_end(struct hashfile *);
44
45/*
46 * Returns the total number of bytes fed to the hashfile so far (including ones
47 * that have not been written out to the descriptor yet).
48 */
49static inline off_t hashfile_total(struct hashfile *f)
50{
51 return f->total + f->offset;
52}
53
54static inline void hashwrite_u8(struct hashfile *f, uint8_t data)
55{
56 hashwrite(f, &data, sizeof(data));
57}
58
59static inline void hashwrite_be32(struct hashfile *f, uint32_t data)
60{
61 data = htonl(data);
62 hashwrite(f, &data, sizeof(data));
63}
64
65static inline size_t hashwrite_be64(struct hashfile *f, uint64_t data)
66{
67 data = htonll(data);
68 hashwrite(f, &data, sizeof(data));
69 return sizeof(data);
70}
71
72#endif