Code in SDK
Flush
bool protected_fs_file::pre_close(sgx_key_128bit_t* key, bool import)
{
int32_t result32 = 0;
bool retval = true;
sgx_status_t status = SGX_SUCCESS;
sgx_thread_mutex_lock(&mutex);
if (import == true)
{
if (use_user_kdk_key == 1)
retval = false;
else
need_writing = true;
}
if (file_status != SGX_FILE_STATUS_OK)
{
sgx_thread_mutex_unlock(&mutex);
clear_error();
sgx_thread_mutex_lock(&mutex);
}
else
{
internal_flush( true);
}
if (file_status != SGX_FILE_STATUS_OK)
retval = false;
if (file != NULL)
{
status = u_sgxprotectedfs_fclose(&result32, file);
if (status != SGX_SUCCESS || result32 != 0)
{
last_error = (status != SGX_SUCCESS) ? status :
(result32 != -1) ? result32 : SGX_ERROR_FILE_CLOSE_FAILED;
retval = false;
}
file = NULL;
}
if (file_status == SGX_FILE_STATUS_OK &&
last_error == SGX_SUCCESS)
erase_recovery_file();
if (key != NULL)
{
if (use_user_kdk_key == 1)
{
retval = false;
}
else
{
if (restore_current_meta_data_key(NULL) == true)
memcpy(key, cur_key, sizeof(sgx_key_128bit_t));
else
retval = false;
}
}
file_status = SGX_FILE_STATUS_CLOSED;
sgx_thread_mutex_unlock(&mutex);
return retval;
}