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 */ |
brian m. carlson | 98a3bea | 2018-02-01 02:18:46 +0000 | [diff] [blame] | 7 | struct hashfile { |
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; |
brian m. carlson | 4d27350 | 2018-02-01 02:18:47 +0000 | [diff] [blame] | 11 | git_hash_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 */ |
brian m. carlson | 98a3bea | 2018-02-01 02:18:46 +0000 | [diff] [blame] | 21 | struct hashfile_checkpoint { |
Junio C Hamano | 6c52614 | 2011-11-17 16:26:54 -0800 | [diff] [blame] | 22 | off_t offset; |
brian m. carlson | 4d27350 | 2018-02-01 02:18:47 +0000 | [diff] [blame] | 23 | git_hash_ctx ctx; |
Junio C Hamano | 6c52614 | 2011-11-17 16:26:54 -0800 | [diff] [blame] | 24 | }; |
| 25 | |
brian m. carlson | 98a3bea | 2018-02-01 02:18:46 +0000 | [diff] [blame] | 26 | extern void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *); |
| 27 | extern int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *); |
Junio C Hamano | 6c52614 | 2011-11-17 16:26:54 -0800 | [diff] [blame] | 28 | |
Derrick Stolee | f2af9f5 | 2018-04-02 16:34:14 -0400 | [diff] [blame] | 29 | /* finalize_hashfile flags */ |
Derrick Stolee | cfe8321 | 2018-04-02 16:34:15 -0400 | [diff] [blame] | 30 | #define CSUM_CLOSE 1 |
| 31 | #define CSUM_FSYNC 2 |
| 32 | #define CSUM_HASH_IN_STREAM 4 |
Linus Torvalds | 4c81b03 | 2008-05-30 08:42:16 -0700 | [diff] [blame] | 33 | |
brian m. carlson | 98a3bea | 2018-02-01 02:18:46 +0000 | [diff] [blame] | 34 | extern struct hashfile *hashfd(int fd, const char *name); |
| 35 | extern struct hashfile *hashfd_check(const char *name); |
| 36 | extern struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp); |
Derrick Stolee | f2af9f5 | 2018-04-02 16:34:14 -0400 | [diff] [blame] | 37 | extern int finalize_hashfile(struct hashfile *, unsigned char *, unsigned int); |
brian m. carlson | 98a3bea | 2018-02-01 02:18:46 +0000 | [diff] [blame] | 38 | extern void hashwrite(struct hashfile *, const void *, unsigned int); |
| 39 | extern void hashflush(struct hashfile *f); |
| 40 | extern void crc32_begin(struct hashfile *); |
| 41 | extern uint32_t crc32_end(struct hashfile *); |
Linus Torvalds | c38138c | 2005-06-26 20:27:56 -0700 | [diff] [blame] | 42 | |
brian m. carlson | 98a3bea | 2018-02-01 02:18:46 +0000 | [diff] [blame] | 43 | static inline void hashwrite_u8(struct hashfile *f, uint8_t data) |
Karsten Blees | b500721 | 2014-11-27 00:24:01 -0500 | [diff] [blame] | 44 | { |
brian m. carlson | 98a3bea | 2018-02-01 02:18:46 +0000 | [diff] [blame] | 45 | hashwrite(f, &data, sizeof(data)); |
Karsten Blees | b500721 | 2014-11-27 00:24:01 -0500 | [diff] [blame] | 46 | } |
| 47 | |
brian m. carlson | 98a3bea | 2018-02-01 02:18:46 +0000 | [diff] [blame] | 48 | static inline void hashwrite_be32(struct hashfile *f, uint32_t data) |
Karsten Blees | b500721 | 2014-11-27 00:24:01 -0500 | [diff] [blame] | 49 | { |
| 50 | data = htonl(data); |
brian m. carlson | 98a3bea | 2018-02-01 02:18:46 +0000 | [diff] [blame] | 51 | hashwrite(f, &data, sizeof(data)); |
Karsten Blees | b500721 | 2014-11-27 00:24:01 -0500 | [diff] [blame] | 52 | } |
| 53 | |
Linus Torvalds | c38138c | 2005-06-26 20:27:56 -0700 | [diff] [blame] | 54 | #endif |