5 #include "write-or-die.h"
9 /* A SHA1-protected file */
21 unsigned char *buffer
;
22 unsigned char *check_buffer
;
25 * If non-zero, skip_hash indicates that we should
26 * not actually compute the hash for this hashfile and
27 * instead only use it as a buffered write.
33 struct hashfile_checkpoint
{
38 void hashfile_checkpoint(struct hashfile
*, struct hashfile_checkpoint
*);
39 int hashfile_truncate(struct hashfile
*, struct hashfile_checkpoint
*);
41 /* finalize_hashfile flags */
44 #define CSUM_HASH_IN_STREAM 4
46 struct hashfile
*hashfd(int fd
, const char *name
);
47 struct hashfile
*hashfd_check(const char *name
);
48 struct hashfile
*hashfd_throughput(int fd
, const char *name
, struct progress
*tp
);
49 int finalize_hashfile(struct hashfile
*, unsigned char *, enum fsync_component
, unsigned int);
50 void discard_hashfile(struct hashfile
*);
51 void hashwrite(struct hashfile
*, const void *, unsigned int);
52 void hashflush(struct hashfile
*f
);
53 void crc32_begin(struct hashfile
*);
54 uint32_t crc32_end(struct hashfile
*);
56 /* Verify checksum validity while reading. Returns non-zero on success. */
57 int hashfile_checksum_valid(const unsigned char *data
, size_t len
);
60 * Returns the total number of bytes fed to the hashfile so far (including ones
61 * that have not been written out to the descriptor yet).
63 static inline off_t
hashfile_total(struct hashfile
*f
)
65 return f
->total
+ f
->offset
;
68 static inline void hashwrite_u8(struct hashfile
*f
, uint8_t data
)
70 hashwrite(f
, &data
, sizeof(data
));
73 static inline void hashwrite_be32(struct hashfile
*f
, uint32_t data
)
76 hashwrite(f
, &data
, sizeof(data
));
79 static inline size_t hashwrite_be64(struct hashfile
*f
, uint64_t data
)
82 hashwrite(f
, &data
, sizeof(data
));