Lines Matching refs:f

69 static inline bool is_erasure(fec_handle *f, uint64_t offset,  in is_erasure()  argument
72 if (unlikely(offset >= f->data_size)) { in is_erasure()
82 return !f->hashtree().check_block_hash_with_index(n, data); in is_erasure()
86 static inline bool is_zero(fec_handle *f, uint64_t offset) in is_zero() argument
88 auto hashtree = f->hashtree(); in is_zero()
90 if (hashtree.hash_data.empty() || unlikely(offset >= f->data_size)) { in is_zero()
107 static int __ecc_read(fec_handle *f, void *rs, uint8_t *dest, uint64_t offset, in __ecc_read() argument
111 ecc_info *e = &f->ecc; in __ecc_read()
122 check(!use_erasures || !f->hashtree().hash_data.empty()); in __ecc_read()
136 if (likely(interleaved < e->start) && !is_zero(f, interleaved)) { in __ecc_read()
138 if (!raw_pread(f->fd, bbuf, FEC_BLOCKSIZE, interleaved)) { in __ecc_read()
146 is_erasure(f, interleaved, bbuf)) { in __ecc_read()
163 if (!raw_pread(f->fd, &ecc_data[i * FEC_RSM + e->rsn], e->roots, in __ecc_read()
183 } else if (f->hashtree().hash_data.empty()) { in __ecc_read()
208 static int ecc_init(fec_handle *f, rs_unique_ptr& rs, in ecc_init() argument
211 check(f); in ecc_init()
213 rs.reset(init_rs_char(FEC_PARAMS(f->ecc.roots))); in ecc_init()
234 static ssize_t ecc_read(fec_handle *f, uint8_t *dest, size_t count, in ecc_read() argument
237 check(f); in ecc_read()
239 check(offset < f->data_size); in ecc_read()
240 check(offset + count <= f->data_size); in ecc_read()
248 if (ecc_init(f, rs, ecc_data) == -1) { in ecc_read()
260 if (__ecc_read(f, rs.get(), data, curr * FEC_BLOCKSIZE, false, in ecc_read()
285 static ssize_t verity_read(fec_handle *f, uint8_t *dest, size_t count, in verity_read() argument
288 check(f); in verity_read()
290 check(offset < f->data_size); in verity_read()
291 check(offset + count <= f->data_size); in verity_read()
292 check(!f->hashtree().hash_data.empty()); in verity_read()
300 if (f->ecc.start && ecc_init(f, rs, ecc_data) == -1) { in verity_read()
310 (f->hashtree().hash_data.size() - SHA256_DIGEST_LENGTH) / in verity_read()
317 bool expect_zeros = is_zero(f, curr_offset); in verity_read()
321 if ((f->mode & O_ACCMODE) == O_RDONLY && expect_zeros) { in verity_read()
327 if (!raw_pread(f->fd, data, FEC_BLOCKSIZE, curr_offset)) { in verity_read()
332 if (likely(f->hashtree().check_block_hash_with_index(curr, data))) { in verity_read()
343 if (!f->ecc.start) { in verity_read()
355 if (__ecc_read(f, rs.get(), data, curr_offset, false, ecc_data.get(), in verity_read()
357 f->hashtree().check_block_hash_with_index(curr, data)) { in verity_read()
362 if (__ecc_read(f, rs.get(), data, curr_offset, true, ecc_data.get(), in verity_read()
364 f->hashtree().check_block_hash_with_index(curr, data)) { in verity_read()
378 if (f->mode & O_RDWR && in verity_read()
379 !raw_pwrite(f->fd, data, FEC_BLOCKSIZE, curr_offset)) { in verity_read()
403 int fec_seek(struct fec_handle *f, int64_t offset, int whence) in fec_seek() argument
405 check(f); in fec_seek()
413 f->pos = offset; in fec_seek()
415 if (offset < 0 && f->pos < (uint64_t)-offset) { in fec_seek()
418 } else if (offset > 0 && (uint64_t)offset > UINT64_MAX - f->pos) { in fec_seek()
423 f->pos += offset; in fec_seek()
428 } else if ((uint64_t)-offset > f->size) { in fec_seek()
433 f->pos = f->size + offset; in fec_seek()
444 ssize_t fec_read(struct fec_handle *f, void *buf, size_t count) in fec_read() argument
446 ssize_t rc = fec_pread(f, buf, count, f->pos); in fec_read()
449 check(f->pos < UINT64_MAX - rc); in fec_read()
450 f->pos += rc; in fec_read()
516 ssize_t fec_pread(struct fec_handle *f, void *buf, size_t count, in fec_pread() argument
519 check(f); in fec_pread()
527 if (!f->hashtree().hash_data.empty()) { in fec_pread()
528 return process(f, (uint8_t *)buf, in fec_pread()
529 get_max_count(offset, count, f->data_size), offset, in fec_pread()
531 } else if (f->ecc.start) { in fec_pread()
532 check(f->ecc.start < f->size); in fec_pread()
534 count = get_max_count(offset, count, f->data_size); in fec_pread()
535 ssize_t rc = process(f, (uint8_t *)buf, count, offset, ecc_read); in fec_pread()
544 count = get_max_count(offset, count, f->size); in fec_pread()
547 if (raw_pread(f->fd, buf, count, offset)) { in fec_pread()