static int calculate_chunk_sha1(struct filedes *in_fd, size_t this_chunk_size, off_t offset, u8 sha1_md[]) { u8 buf[BUFFER_SIZE]; SHA_CTX ctx; size_t bytes_remaining; size_t bytes_to_read; int ret; bytes_remaining = this_chunk_size; sha1_init(&ctx); do { bytes_to_read = min(bytes_remaining, sizeof(buf)); ret = full_pread(in_fd, buf, bytes_to_read, offset); if (ret) { ERROR_WITH_ERRNO("Read error while calculating " "integrity checksums"); return ret; } sha1_update(&ctx, buf, bytes_to_read); bytes_remaining -= bytes_to_read; offset += bytes_to_read; } while (bytes_remaining); sha1_final(sha1_md, &ctx); return 0; }
int do_pread(long fd, char *buffer, int length, int offset) { if(do_chirp) { return chirp_reli_pread((struct chirp_file *) fd, buffer, length, offset, stoptime); } else { return full_pread(fd, buffer, length, offset); } }