Steps
- Write recovery file and set flags if needed
- Update data and mht nodes if needed
- Update meta data node and update flags
- Write data to the disk
- Perform the actual data write in
protected_fs_file::write_all_changes_to_disk
. - LRU cache is used here for performance.
bool protected_fs_file::internal_flush( bool flush_to_disk)
{
if (need_writing == false)
return true;
if (encrypted_part_plain.size > MD_USER_DATA_SIZE && root_mht.need_writing == true)
{
if (_RECOVERY_HOOK_(0) || write_recovery_file() != true)
{
file_status = SGX_FILE_STATUS_FLUSH_ERROR;
return false;
}
if (_RECOVERY_HOOK_(1) || set_update_flag(flush_to_disk) != true)
{
file_status = SGX_FILE_STATUS_FLUSH_ERROR;
return false;
}
if (_RECOVERY_HOOK_(2) || update_all_data_and_mht_nodes() != true)
{
clear_update_flag();
file_status = SGX_FILE_STATUS_CRYPTO_ERROR;
return false;
}
}
if (_RECOVERY_HOOK_(3) || update_meta_data_node() != true)
{
clear_update_flag();
file_status = SGX_FILE_STATUS_CRYPTO_ERROR;
return false;
}
if (_RECOVERY_HOOK_(4) || write_all_changes_to_disk(flush_to_disk) != true)
{
file_status = SGX_FILE_STATUS_WRITE_TO_DISK_FAILED;
return false;
}
need_writing = false;
return true;
}