Lines Matching refs:bfc

33 void incfs_free_bfc(struct backing_file_context *bfc)  in incfs_free_bfc()  argument
35 if (!bfc) in incfs_free_bfc()
38 if (bfc->bc_file) in incfs_free_bfc()
39 fput(bfc->bc_file); in incfs_free_bfc()
41 mutex_destroy(&bfc->bc_mutex); in incfs_free_bfc()
42 kfree(bfc); in incfs_free_bfc()
58 static int truncate_backing_file(struct backing_file_context *bfc, in truncate_backing_file() argument
67 if (!bfc) in truncate_backing_file()
70 LOCK_REQUIRED(bfc->bc_mutex); in truncate_backing_file()
72 if (!bfc->bc_file) in truncate_backing_file()
75 old_end = incfs_get_end_offset(bfc->bc_file); in truncate_backing_file()
81 inode = bfc->bc_file->f_inode; in truncate_backing_file()
82 dentry = bfc->bc_file->f_path.dentry; in truncate_backing_file()
94 static int write_to_bf(struct backing_file_context *bfc, const void *buf, in write_to_bf() argument
97 ssize_t res = incfs_kwrite(bfc, buf, count, pos); in write_to_bf()
106 static int append_zeros_no_fallocate(struct backing_file_context *bfc, in append_zeros_no_fallocate() argument
115 int err = write_to_bf(bfc, buffer, to_write, file_size + i); in append_zeros_no_fallocate()
125 static int append_zeros(struct backing_file_context *bfc, size_t len) in append_zeros() argument
131 if (!bfc) in append_zeros()
137 LOCK_REQUIRED(bfc->bc_mutex); in append_zeros()
144 file_size = incfs_get_end_offset(bfc->bc_file); in append_zeros()
146 result = vfs_fallocate(bfc->bc_file, 0, new_last_byte_offset, 1); in append_zeros()
150 return append_zeros_no_fallocate(bfc, file_size, len); in append_zeros()
157 static int append_md_to_backing_file(struct backing_file_context *bfc, in append_md_to_backing_file() argument
166 if (!bfc || !record) in append_md_to_backing_file()
169 if (bfc->bc_last_md_record_offset < 0) in append_md_to_backing_file()
172 LOCK_REQUIRED(bfc->bc_mutex); in append_md_to_backing_file()
175 file_pos = incfs_get_end_offset(bfc->bc_file); in append_md_to_backing_file()
181 result = write_to_bf(bfc, record, record_size, file_pos); in append_md_to_backing_file()
186 if (bfc->bc_last_md_record_offset) { in append_md_to_backing_file()
191 file_pos = bfc->bc_last_md_record_offset + in append_md_to_backing_file()
201 result = write_to_bf(bfc, &new_md_offset, sizeof(new_md_offset), in append_md_to_backing_file()
206 bfc->bc_last_md_record_offset = record_offset; in append_md_to_backing_file()
214 int incfs_write_blockmap_to_backing_file(struct backing_file_context *bfc, in incfs_write_blockmap_to_backing_file() argument
222 if (!bfc) in incfs_write_blockmap_to_backing_file()
230 LOCK_REQUIRED(bfc->bc_mutex); in incfs_write_blockmap_to_backing_file()
233 file_end = incfs_get_end_offset(bfc->bc_file); in incfs_write_blockmap_to_backing_file()
234 result = append_zeros(bfc, map_size); in incfs_write_blockmap_to_backing_file()
240 result = append_md_to_backing_file(bfc, &blockmap.m_header); in incfs_write_blockmap_to_backing_file()
243 truncate_backing_file(bfc, file_end); in incfs_write_blockmap_to_backing_file()
248 int incfs_write_signature_to_backing_file(struct backing_file_context *bfc, in incfs_write_signature_to_backing_file() argument
258 if (!bfc) in incfs_write_signature_to_backing_file()
261 LOCK_REQUIRED(bfc->bc_mutex); in incfs_write_signature_to_backing_file()
263 rollback_pos = incfs_get_end_offset(bfc->bc_file); in incfs_write_signature_to_backing_file()
272 result = write_to_bf(bfc, sig.data, sig.len, rollback_pos); in incfs_write_signature_to_backing_file()
277 tree_area_pos = incfs_get_end_offset(bfc->bc_file); in incfs_write_signature_to_backing_file()
294 result = append_zeros(bfc, tree_size + alignment); in incfs_write_signature_to_backing_file()
303 result = append_md_to_backing_file(bfc, &sg.sg_header); in incfs_write_signature_to_backing_file()
307 truncate_backing_file(bfc, rollback_pos); in incfs_write_signature_to_backing_file()
318 static int write_new_status_to_backing_file(struct backing_file_context *bfc, in write_new_status_to_backing_file() argument
333 LOCK_REQUIRED(bfc->bc_mutex); in write_new_status_to_backing_file()
334 rollback_pos = incfs_get_end_offset(bfc->bc_file); in write_new_status_to_backing_file()
335 result = append_md_to_backing_file(bfc, &is.is_header); in write_new_status_to_backing_file()
337 truncate_backing_file(bfc, rollback_pos); in write_new_status_to_backing_file()
342 int incfs_write_status_to_backing_file(struct backing_file_context *bfc, in incfs_write_status_to_backing_file() argument
350 if (!bfc) in incfs_write_status_to_backing_file()
354 return write_new_status_to_backing_file(bfc, in incfs_write_status_to_backing_file()
357 result = incfs_kread(bfc, &is, sizeof(is), status_offset); in incfs_write_status_to_backing_file()
363 result = incfs_kwrite(bfc, &is, sizeof(is), status_offset); in incfs_write_status_to_backing_file()
371 struct backing_file_context *bfc, struct mem_range signature, in incfs_write_verity_signature_to_backing_file() argument
382 pos = incfs_get_end_offset(bfc->bc_file); in incfs_write_verity_signature_to_backing_file()
394 result = write_to_bf(bfc, signature.data, signature.len, pos); in incfs_write_verity_signature_to_backing_file()
398 result = append_md_to_backing_file(bfc, &vs.vs_header); in incfs_write_verity_signature_to_backing_file()
406 truncate_backing_file(bfc, pos); in incfs_write_verity_signature_to_backing_file()
416 int incfs_write_fh_to_backing_file(struct backing_file_context *bfc, in incfs_write_fh_to_backing_file() argument
422 if (!bfc) in incfs_write_fh_to_backing_file()
434 LOCK_REQUIRED(bfc->bc_mutex); in incfs_write_fh_to_backing_file()
436 file_pos = incfs_get_end_offset(bfc->bc_file); in incfs_write_fh_to_backing_file()
440 return write_to_bf(bfc, &fh, sizeof(fh), file_pos); in incfs_write_fh_to_backing_file()
447 int incfs_write_mapping_fh_to_backing_file(struct backing_file_context *bfc, in incfs_write_mapping_fh_to_backing_file() argument
453 if (!bfc) in incfs_write_mapping_fh_to_backing_file()
466 LOCK_REQUIRED(bfc->bc_mutex); in incfs_write_mapping_fh_to_backing_file()
468 file_pos = incfs_get_end_offset(bfc->bc_file); in incfs_write_mapping_fh_to_backing_file()
472 return write_to_bf(bfc, &fh, sizeof(fh), file_pos); in incfs_write_mapping_fh_to_backing_file()
476 int incfs_write_data_block_to_backing_file(struct backing_file_context *bfc, in incfs_write_data_block_to_backing_file() argument
486 if (!bfc) in incfs_write_data_block_to_backing_file()
492 LOCK_REQUIRED(bfc->bc_mutex); in incfs_write_data_block_to_backing_file()
494 data_offset = incfs_get_end_offset(bfc->bc_file); in incfs_write_data_block_to_backing_file()
501 result = write_to_bf(bfc, block.data, block.len, data_offset); in incfs_write_data_block_to_backing_file()
511 return write_to_bf(bfc, &bm_entry, sizeof(bm_entry), in incfs_write_data_block_to_backing_file()
515 int incfs_write_hash_block_to_backing_file(struct backing_file_context *bfc, in incfs_write_hash_block_to_backing_file() argument
531 if (!bfc) in incfs_write_hash_block_to_backing_file()
534 LOCK_REQUIRED(bfc->bc_mutex); in incfs_write_hash_block_to_backing_file()
537 file_end = incfs_get_end_offset(bfc->bc_file); in incfs_write_hash_block_to_backing_file()
543 result = write_to_bf(bfc, block.data, block.len, data_offset); in incfs_write_hash_block_to_backing_file()
551 return write_to_bf(bfc, &bm_entry, sizeof(bm_entry), bm_entry_off); in incfs_write_hash_block_to_backing_file()
554 int incfs_read_blockmap_entry(struct backing_file_context *bfc, int block_index, in incfs_read_blockmap_entry() argument
558 int error = incfs_read_blockmap_entries(bfc, bm_entry, block_index, 1, in incfs_read_blockmap_entry()
573 int incfs_read_blockmap_entries(struct backing_file_context *bfc, in incfs_read_blockmap_entries() argument
584 if (!bfc || !entries) in incfs_read_blockmap_entries()
590 result = incfs_kread(bfc, entries, bytes_to_read, bm_entry_off); in incfs_read_blockmap_entries()
596 int incfs_read_file_header(struct backing_file_context *bfc, in incfs_read_file_header() argument
603 if (!bfc || !first_md_off) in incfs_read_file_header()
606 bytes_read = incfs_kread(bfc, &fh, sizeof(fh), 0); in incfs_read_file_header()
640 int incfs_read_next_metadata_record(struct backing_file_context *bfc, in incfs_read_next_metadata_record() argument
650 if (!bfc || !handler) in incfs_read_next_metadata_record()
657 bytes_read = incfs_kread(bfc, &handler->md_buffer, max_md_size, in incfs_read_next_metadata_record()
725 bfc->bc_last_md_record_offset = in incfs_read_next_metadata_record()
734 ssize_t incfs_kread(struct backing_file_context *bfc, void *buf, size_t size, in incfs_kread() argument
737 const struct cred *old_cred = override_creds(bfc->bc_cred); in incfs_kread()
738 int ret = kernel_read(bfc->bc_file, buf, size, &pos); in incfs_kread()
744 ssize_t incfs_kwrite(struct backing_file_context *bfc, const void *buf, in incfs_kwrite() argument
747 const struct cred *old_cred = override_creds(bfc->bc_cred); in incfs_kwrite()
748 int ret = kernel_write(bfc->bc_file, buf, size, &pos); in incfs_kwrite()