Lines Matching refs:f
181 bool hashtree_info::ecc_read_hashes(fec_handle *f, uint64_t hash_offset, in ecc_read_hashes() argument
184 check(f); in ecc_read_hashes()
187 fec_pread(f, hash, digest_length_, hash_offset) != digest_length_) { in ecc_read_hashes()
195 if (fec_pread(f, data, FEC_BLOCKSIZE, data_offset) != FEC_BLOCKSIZE) { in ecc_read_hashes()
204 int hashtree_info::verify_tree(const fec_handle *f, const uint8_t *root) { in verify_tree() argument
205 check(f); in verify_tree()
217 check(hash_start + hash_size <= f->data_size); in verify_tree()
223 if (!raw_pread(f->fd, data, FEC_BLOCKSIZE, hash_offset) || in verify_tree()
226 if (!ecc_read_hashes(const_cast<fec_handle *>(f), 0, nullptr, in verify_tree()
231 } else if (f->mode & O_RDWR && in verify_tree()
232 !raw_pwrite(f->fd, data, FEC_BLOCKSIZE, hash_offset)) { in verify_tree()
264 check(hash_data_offset < f->data_size); in verify_tree()
265 check(hash_data_offset + hash_data_blocks * FEC_BLOCKSIZE <= f->data_size); in verify_tree()
281 if (!raw_pread(f->fd, buffer.data(), padded_digest_length_, in verify_tree()
283 !raw_pread(f->fd, data, FEC_BLOCKSIZE, in verify_tree()
291 if (!ecc_read_hashes(const_cast<fec_handle *>(f), in verify_tree()
305 if (f->mode & O_RDWR) { in verify_tree()
306 if (!raw_pwrite(f->fd, buffer.data(), padded_digest_length_, in verify_tree()
308 !raw_pwrite(f->fd, data, FEC_BLOCKSIZE, in verify_tree()
342 static int parse_table(fec_handle *f, uint64_t offset, uint32_t size, bool useecc) in parse_table() argument
344 check(f); in parse_table()
353 if (!raw_pread(f->fd, const_cast<char *>(table.data()), size, offset)) { in parse_table()
357 } else if (fec_pread(f, const_cast<char *>(table.data()), size, offset) != in parse_table()
390 if (parse_uint64(token.c_str(), f->data_size / FEC_BLOCKSIZE, in parse_table()
398 if (parse_uint64(token.c_str(), f->data_size / FEC_BLOCKSIZE, in parse_table()
443 check(hash_start < f->data_size); in parse_table()
445 verity_info *v = &f->verity; in parse_table()
455 if (!(f->flags & FEC_VERITY_DISABLE)) { in parse_table()
456 if (v->hashtree.verify_tree(f, root) == -1) { in parse_table()
468 static int rewrite_metadata(fec_handle *f, uint64_t offset) in rewrite_metadata() argument
470 check(f); in rewrite_metadata()
471 check(f->data_size > VERITY_METADATA_SIZE); in rewrite_metadata()
472 check(offset <= f->data_size - VERITY_METADATA_SIZE); in rewrite_metadata()
484 verity_info *v = &f->verity; in rewrite_metadata()
493 return raw_pwrite(f->fd, metadata.get(), VERITY_METADATA_SIZE, offset); in rewrite_metadata()
496 static int validate_header(const fec_handle *f, const verity_header *header, in validate_header() argument
499 check(f); in validate_header()
527 } else if (offset + header->length >= f->data_size) { in validate_header()
537 int verity_parse_header(fec_handle *f, uint64_t offset) in verity_parse_header() argument
539 check(f); in verity_parse_header()
540 check(f->data_size > VERITY_METADATA_SIZE); in verity_parse_header()
542 if (offset > f->data_size - VERITY_METADATA_SIZE) { in verity_parse_header()
548 verity_info *v = &f->verity; in verity_parse_header()
549 uint64_t errors = f->errors; in verity_parse_header()
551 if (!raw_pread(f->fd, &v->header, sizeof(v->header), offset)) { in verity_parse_header()
564 if (fec_pread(f, &v->ecc_header, sizeof(v->ecc_header), offset) != in verity_parse_header()
570 if (validate_header(f, &v->header, offset)) { in verity_parse_header()
574 if (validate_header(f, &v->ecc_header, offset)) { in verity_parse_header()
604 if (parse_table(f, offset + sizeof(v->header), v->header.length, in verity_parse_header()
606 parse_table(f, offset + sizeof(v->header), v->header.length, in verity_parse_header()
613 if (f->mode & O_RDWR && f->errors > errors && in verity_parse_header()
614 rewrite_metadata(f, offset) < 0) { in verity_parse_header()
619 f->data_size = v->metadata_start; in verity_parse_header()
621 f->data_size = v->hashtree.hash_start; in verity_parse_header()
627 int fec_verity_set_status(struct fec_handle *f, bool enabled) in fec_verity_set_status() argument
629 check(f); in fec_verity_set_status()
631 if (!(f->mode & O_RDWR)) { in fec_verity_set_status()
637 verity_info *v = &f->verity; in fec_verity_set_status()
651 if (!raw_pwrite(f->fd, &magic, sizeof(magic), v->metadata_start)) { in fec_verity_set_status()