Small regression to a more stable state

This commit is contained in:
2024-02-17 18:10:07 +01:00
parent c1b3f3c262
commit 1cd34dd514
8 changed files with 53 additions and 180 deletions

View File

@@ -63,6 +63,46 @@ Result get_entry_disk_path(const char* entry_id, char** out_path) {
return result;
}
Result get_entry_backing_id(const char* entry_id, char** out_backing_id) {
*out_backing_id = NULL;
// Get the path of the disk
char* disk_path;
Result result = get_entry_disk_path(entry_id, &disk_path);
if (result != SUCCESS)
return result;
// Get the backing file of the disk
DiskInfo info;
result = get_disk_info(disk_path, &info);
if (result != SUCCESS) {
free(disk_path);
return result;
}
// Free the disk path
free(disk_path);
// Check that the disk is backed
if (info.backing_file == NULL) {
free_disk_info(&info);
return SUCCESS;
}
// Get the backing id
*out_backing_id = strdup(basename(info.backing_file));
if (*out_backing_id == NULL) {
log_message(LOG_LEVEL_ERROR, "Failed to allocate memory for the backing id.");
free_disk_info(&info);
return OUT_OF_MEMORY;
}
// Free the disk info
free_disk_info(&info);
return SUCCESS;
}
Result get_entry_type_path(const char* entry_id, char** out_path) {
*out_path = NULL;
@@ -412,30 +452,3 @@ Result clear_entries(void) {
return SUCCESS;
}
Result reset_entry(const char* entry_id) {
// Check that it exists
bool exists;
Result result = entry_exists(entry_id, &exists);
if (result != SUCCESS)
return result;
if (!exists) {
log_message(LOG_LEVEL_ERROR, "The entry '%s' does not exist.", entry_id);
return FAILURE;
}
// Get the path of the disk
char* disk_path;
result = get_entry_disk_path(entry_id, &disk_path);
if (result != SUCCESS)
return result;
// Reset the disk
result = reset_disk(disk_path);
// Free the disk path
free(disk_path);
return result;
}