is_path_owned_by_current_uid(): mark "report" parameter as unused
[git.git] / csum-file.h
blob0d29f528fbcb51df13eac225c0e2cc120198bd3f
1 #ifndef CSUM_FILE_H
2 #define CSUM_FILE_H
4 #include "cache.h"
5 #include "hash.h"
7 struct progress;
9 /* A SHA1-protected file */
10 struct hashfile {
11 int fd;
12 int check_fd;
13 unsigned int offset;
14 git_hash_ctx ctx;
15 off_t total;
16 struct progress *tp;
17 const char *name;
18 int do_crc;
19 uint32_t crc32;
20 size_t buffer_len;
21 unsigned char *buffer;
22 unsigned char *check_buffer;
25 /* Checkpoint */
26 struct hashfile_checkpoint {
27 off_t offset;
28 git_hash_ctx ctx;
31 void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *);
32 int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);
34 /* finalize_hashfile flags */
35 #define CSUM_CLOSE 1
36 #define CSUM_FSYNC 2
37 #define CSUM_HASH_IN_STREAM 4
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);
42 int finalize_hashfile(struct hashfile *, unsigned char *, enum fsync_component, unsigned int);
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 *);
48 /* Verify checksum validity while reading. Returns non-zero on success. */
49 int hashfile_checksum_valid(const unsigned char *data, size_t len);
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).
55 static inline off_t hashfile_total(struct hashfile *f)
57 return f->total + f->offset;
60 static inline void hashwrite_u8(struct hashfile *f, uint8_t data)
62 hashwrite(f, &data, sizeof(data));
65 static inline void hashwrite_be32(struct hashfile *f, uint32_t data)
67 data = htonl(data);
68 hashwrite(f, &data, sizeof(data));
71 static inline size_t hashwrite_be64(struct hashfile *f, uint64_t data)
73 data = htonll(data);
74 hashwrite(f, &data, sizeof(data));
75 return sizeof(data);
78 #endif