csum-file.h 1.36 KB
Newer Older
1 2 3
#ifndef CSUM_FILE_H
#define CSUM_FILE_H

4 5
#include "hash.h"

6 7
struct progress;

8
/* A SHA1-protected file */
9
struct hashfile {
10
	int fd;
Junio C Hamano's avatar
Junio C Hamano committed
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 18
	int do_crc;
	uint32_t crc32;
19 20 21
	unsigned char buffer[8192];
};

22
/* Checkpoint */
23
struct hashfile_checkpoint {
24
	off_t offset;
25
	git_hash_ctx ctx;
26 27
};

28 29
extern void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *);
extern int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);
30

31
/* finalize_hashfile flags */
32 33 34
#define CSUM_CLOSE		1
#define CSUM_FSYNC		2
#define CSUM_HASH_IN_STREAM	4
35

36 37 38
extern struct hashfile *hashfd(int fd, const char *name);
extern struct hashfile *hashfd_check(const char *name);
extern struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp);
39
extern int finalize_hashfile(struct hashfile *, unsigned char *, unsigned int);
40 41 42 43
extern void hashwrite(struct hashfile *, const void *, unsigned int);
extern void hashflush(struct hashfile *f);
extern void crc32_begin(struct hashfile *);
extern uint32_t crc32_end(struct hashfile *);
44

45
static inline void hashwrite_u8(struct hashfile *f, uint8_t data)
46
{
47
	hashwrite(f, &data, sizeof(data));
48 49
}

50
static inline void hashwrite_be32(struct hashfile *f, uint32_t data)
51 52
{
	data = htonl(data);
53
	hashwrite(f, &data, sizeof(data));
54 55
}

56
#endif