blob: 7530927d774562f82636aa773481ae93600c1756 [file] [log] [blame]
Linus Torvaldsc38138c2005-06-26 20:27:56 -07001#ifndef CSUM_FILE_H
2#define CSUM_FILE_H
3
Nicolas Pitre2a128d62007-10-30 17:06:21 -04004struct progress;
5
Linus Torvaldsc38138c2005-06-26 20:27:56 -07006/* A SHA1-protected file */
7struct sha1file {
Nicolas Pitreec640ed2007-11-04 22:54:50 -05008 int fd;
Junio C Hamanoe337a042011-02-02 17:29:01 -08009 int check_fd;
Nicolas Pitreec640ed2007-11-04 22:54:50 -050010 unsigned int offset;
Nicolas Pitre9126f002008-10-01 14:05:20 -040011 git_SHA_CTX ctx;
Nicolas Pitre218558a2007-11-04 22:15:41 -050012 off_t total;
Nicolas Pitre2a128d62007-10-30 17:06:21 -040013 struct progress *tp;
Nicolas Pitreec640ed2007-11-04 22:54:50 -050014 const char *name;
Nicolas Pitre78d1e842007-04-09 01:06:31 -040015 int do_crc;
16 uint32_t crc32;
Linus Torvaldsc38138c2005-06-26 20:27:56 -070017 unsigned char buffer[8192];
18};
19
Junio C Hamano6c526142011-11-17 16:26:54 -080020/* Checkpoint */
21struct sha1file_checkpoint {
22 off_t offset;
23 git_SHA_CTX ctx;
24};
25
26extern void sha1file_checkpoint(struct sha1file *, struct sha1file_checkpoint *);
27extern int sha1file_truncate(struct sha1file *, struct sha1file_checkpoint *);
28
Linus Torvalds4c81b032008-05-30 08:42:16 -070029/* sha1close flags */
30#define CSUM_CLOSE 1
31#define CSUM_FSYNC 2
32
Linus Torvalds4397f012005-06-28 11:10:06 -070033extern struct sha1file *sha1fd(int fd, const char *name);
Junio C Hamanoe337a042011-02-02 17:29:01 -080034extern struct sha1file *sha1fd_check(const char *name);
Nicolas Pitre2a128d62007-10-30 17:06:21 -040035extern struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp);
Linus Torvalds4c81b032008-05-30 08:42:16 -070036extern int sha1close(struct sha1file *, unsigned char *, unsigned int);
Junio C Hamanof06a5e62014-01-10 10:33:09 -080037extern void sha1write(struct sha1file *, const void *, unsigned int);
Nicolas Pitre838cd342008-10-09 22:08:51 -040038extern void sha1flush(struct sha1file *f);
Nicolas Pitre78d1e842007-04-09 01:06:31 -040039extern void crc32_begin(struct sha1file *);
40extern uint32_t crc32_end(struct sha1file *);
Linus Torvaldsc38138c2005-06-26 20:27:56 -070041
Karsten Bleesb5007212014-11-27 00:24:01 -050042static inline void sha1write_u8(struct sha1file *f, uint8_t data)
43{
44 sha1write(f, &data, sizeof(data));
45}
46
47static inline void sha1write_be32(struct sha1file *f, uint32_t data)
48{
49 data = htonl(data);
50 sha1write(f, &data, sizeof(data));
51}
52
Linus Torvaldsc38138c2005-06-26 20:27:56 -070053#endif