]>
Commit | Line | Data |
---|---|---|
c38138cd LT |
1 | #ifndef CSUM_FILE_H |
2 | #define CSUM_FILE_H | |
3 | ||
020406ea | 4 | #include "cache.h" |
ef3ca954 EN |
5 | #include "hash.h" |
6 | ||
2a128d63 NP |
7 | struct progress; |
8 | ||
c38138cd | 9 | /* A SHA1-protected file */ |
98a3beab | 10 | struct hashfile { |
ec640ed1 | 11 | int fd; |
e337a04d | 12 | int check_fd; |
ec640ed1 | 13 | unsigned int offset; |
4d273500 | 14 | git_hash_ctx ctx; |
218558af | 15 | off_t total; |
2a128d63 | 16 | struct progress *tp; |
ec640ed1 | 17 | const char *name; |
78d1e84f NP |
18 | int do_crc; |
19 | uint32_t crc32; | |
2ca245f8 DS |
20 | size_t buffer_len; |
21 | unsigned char *buffer; | |
22 | unsigned char *check_buffer; | |
c38138cd LT |
23 | }; |
24 | ||
6c526148 | 25 | /* Checkpoint */ |
98a3beab | 26 | struct hashfile_checkpoint { |
6c526148 | 27 | off_t offset; |
4d273500 | 28 | git_hash_ctx ctx; |
6c526148 JH |
29 | }; |
30 | ||
55454427 DL |
31 | void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *); |
32 | int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *); | |
6c526148 | 33 | |
f2af9f5e | 34 | /* finalize_hashfile flags */ |
cfe83216 DS |
35 | #define CSUM_CLOSE 1 |
36 | #define CSUM_FSYNC 2 | |
37 | #define CSUM_HASH_IN_STREAM 4 | |
4c81b03e | 38 | |
55454427 DL |
39 | struct hashfile *hashfd(int fd, const char *name); |
40 | struct hashfile *hashfd_check(const char *name); | |
41 | struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp); | |
020406ea | 42 | int finalize_hashfile(struct hashfile *, unsigned char *, enum fsync_component, unsigned int); |
55454427 DL |
43 | void hashwrite(struct hashfile *, const void *, unsigned int); |
44 | void hashflush(struct hashfile *f); | |
45 | void crc32_begin(struct hashfile *); | |
46 | uint32_t crc32_end(struct hashfile *); | |
c38138cd | 47 | |
f9221e2c TB |
48 | /* Verify checksum validity while reading. Returns non-zero on success. */ |
49 | int hashfile_checksum_valid(const unsigned char *data, size_t len); | |
50 | ||
2f4af776 JK |
51 | /* |
52 | * Returns the total number of bytes fed to the hashfile so far (including ones | |
53 | * that have not been written out to the descriptor yet). | |
54 | */ | |
55 | static inline off_t hashfile_total(struct hashfile *f) | |
56 | { | |
57 | return f->total + f->offset; | |
58 | } | |
59 | ||
98a3beab | 60 | static inline void hashwrite_u8(struct hashfile *f, uint8_t data) |
b5007211 | 61 | { |
98a3beab | 62 | hashwrite(f, &data, sizeof(data)); |
b5007211 KB |
63 | } |
64 | ||
98a3beab | 65 | static inline void hashwrite_be32(struct hashfile *f, uint32_t data) |
b5007211 KB |
66 | { |
67 | data = htonl(data); | |
98a3beab | 68 | hashwrite(f, &data, sizeof(data)); |
b5007211 KB |
69 | } |
70 | ||
54273d10 RS |
71 | static inline size_t hashwrite_be64(struct hashfile *f, uint64_t data) |
72 | { | |
73 | data = htonll(data); | |
74 | hashwrite(f, &data, sizeof(data)); | |
75 | return sizeof(data); | |
76 | } | |
77 | ||
c38138cd | 78 | #endif |