summaryrefslogtreecommitdiff
path: root/csum-file.h
diff options
context:
space:
mode:
Diffstat (limited to 'csum-file.h')
-rw-r--r--csum-file.h35
1 files changed, 32 insertions, 3 deletions
diff --git a/csum-file.h b/csum-file.h
index a98b1ee..bc5bec2 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -1,7 +1,8 @@
#ifndef CSUM_FILE_H
#define CSUM_FILE_H
-#include "hash.h"
+#include "hash-ll.h"
+#include "write-or-die.h"
struct progress;
@@ -16,7 +17,16 @@ struct hashfile {
const char *name;
int do_crc;
uint32_t crc32;
- unsigned char buffer[8192];
+ size_t buffer_len;
+ unsigned char *buffer;
+ unsigned char *check_buffer;
+
+ /**
+ * If non-zero, skip_hash indicates that we should
+ * not actually compute the hash for this hashfile and
+ * instead only use it as a buffered write.
+ */
+ int skip_hash;
};
/* Checkpoint */
@@ -36,12 +46,24 @@ int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);
struct hashfile *hashfd(int fd, const char *name);
struct hashfile *hashfd_check(const char *name);
struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp);
-int finalize_hashfile(struct hashfile *, unsigned char *, unsigned int);
+int finalize_hashfile(struct hashfile *, unsigned char *, enum fsync_component, unsigned int);
void hashwrite(struct hashfile *, const void *, unsigned int);
void hashflush(struct hashfile *f);
void crc32_begin(struct hashfile *);
uint32_t crc32_end(struct hashfile *);
+/* Verify checksum validity while reading. Returns non-zero on success. */
+int hashfile_checksum_valid(const unsigned char *data, size_t len);
+
+/*
+ * Returns the total number of bytes fed to the hashfile so far (including ones
+ * that have not been written out to the descriptor yet).
+ */
+static inline off_t hashfile_total(struct hashfile *f)
+{
+ return f->total + f->offset;
+}
+
static inline void hashwrite_u8(struct hashfile *f, uint8_t data)
{
hashwrite(f, &data, sizeof(data));
@@ -53,4 +75,11 @@ static inline void hashwrite_be32(struct hashfile *f, uint32_t data)
hashwrite(f, &data, sizeof(data));
}
+static inline size_t hashwrite_be64(struct hashfile *f, uint64_t data)
+{
+ data = htonll(data);
+ hashwrite(f, &data, sizeof(data));
+ return sizeof(data);
+}
+
#endif