Linus Torvalds | c38138c | 2005-06-26 20:27:56 -0700 | [diff] [blame] | 1 | #ifndef CSUM_FILE_H |
| 2 | #define CSUM_FILE_H |
| 3 | |
Nicolas Pitre | 2a128d6 | 2007-10-30 17:06:21 -0400 | [diff] [blame] | 4 | struct progress; |
| 5 | |
Linus Torvalds | c38138c | 2005-06-26 20:27:56 -0700 | [diff] [blame] | 6 | /* A SHA1-protected file */ |
| 7 | struct sha1file { |
Nicolas Pitre | ec640ed | 2007-11-04 22:54:50 -0500 | [diff] [blame] | 8 | int fd; |
Junio C Hamano | e337a04 | 2011-02-02 17:29:01 -0800 | [diff] [blame] | 9 | int check_fd; |
Nicolas Pitre | ec640ed | 2007-11-04 22:54:50 -0500 | [diff] [blame] | 10 | unsigned int offset; |
Nicolas Pitre | 9126f00 | 2008-10-01 14:05:20 -0400 | [diff] [blame] | 11 | git_SHA_CTX ctx; |
Nicolas Pitre | 218558a | 2007-11-04 22:15:41 -0500 | [diff] [blame] | 12 | off_t total; |
Nicolas Pitre | 2a128d6 | 2007-10-30 17:06:21 -0400 | [diff] [blame] | 13 | struct progress *tp; |
Nicolas Pitre | ec640ed | 2007-11-04 22:54:50 -0500 | [diff] [blame] | 14 | const char *name; |
Nicolas Pitre | 78d1e84 | 2007-04-09 01:06:31 -0400 | [diff] [blame] | 15 | int do_crc; |
| 16 | uint32_t crc32; |
Linus Torvalds | c38138c | 2005-06-26 20:27:56 -0700 | [diff] [blame] | 17 | unsigned char buffer[8192]; |
| 18 | }; |
| 19 | |
Junio C Hamano | 6c52614 | 2011-11-17 16:26:54 -0800 | [diff] [blame] | 20 | /* Checkpoint */ |
| 21 | struct sha1file_checkpoint { |
| 22 | off_t offset; |
| 23 | git_SHA_CTX ctx; |
| 24 | }; |
| 25 | |
| 26 | extern void sha1file_checkpoint(struct sha1file *, struct sha1file_checkpoint *); |
| 27 | extern int sha1file_truncate(struct sha1file *, struct sha1file_checkpoint *); |
| 28 | |
Linus Torvalds | 4c81b03 | 2008-05-30 08:42:16 -0700 | [diff] [blame] | 29 | /* sha1close flags */ |
| 30 | #define CSUM_CLOSE 1 |
| 31 | #define CSUM_FSYNC 2 |
| 32 | |
Linus Torvalds | 4397f01 | 2005-06-28 11:10:06 -0700 | [diff] [blame] | 33 | extern struct sha1file *sha1fd(int fd, const char *name); |
Junio C Hamano | e337a04 | 2011-02-02 17:29:01 -0800 | [diff] [blame] | 34 | extern struct sha1file *sha1fd_check(const char *name); |
Nicolas Pitre | 2a128d6 | 2007-10-30 17:06:21 -0400 | [diff] [blame] | 35 | extern struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp); |
Linus Torvalds | 4c81b03 | 2008-05-30 08:42:16 -0700 | [diff] [blame] | 36 | extern int sha1close(struct sha1file *, unsigned char *, unsigned int); |
Junio C Hamano | f06a5e6 | 2014-01-10 10:33:09 -0800 | [diff] [blame] | 37 | extern void sha1write(struct sha1file *, const void *, unsigned int); |
Nicolas Pitre | 838cd34 | 2008-10-09 22:08:51 -0400 | [diff] [blame] | 38 | extern void sha1flush(struct sha1file *f); |
Nicolas Pitre | 78d1e84 | 2007-04-09 01:06:31 -0400 | [diff] [blame] | 39 | extern void crc32_begin(struct sha1file *); |
| 40 | extern uint32_t crc32_end(struct sha1file *); |
Linus Torvalds | c38138c | 2005-06-26 20:27:56 -0700 | [diff] [blame] | 41 | |
Karsten Blees | b500721 | 2014-11-27 00:24:01 -0500 | [diff] [blame] | 42 | static inline void sha1write_u8(struct sha1file *f, uint8_t data) |
| 43 | { |
| 44 | sha1write(f, &data, sizeof(data)); |
| 45 | } |
| 46 | |
| 47 | static inline void sha1write_be32(struct sha1file *f, uint32_t data) |
| 48 | { |
| 49 | data = htonl(data); |
| 50 | sha1write(f, &data, sizeof(data)); |
| 51 | } |
| 52 | |
Linus Torvalds | c38138c | 2005-06-26 20:27:56 -0700 | [diff] [blame] | 53 | #endif |