Added disk resetting

This commit is contained in:
Alexei KADIR 2024-02-17 12:35:33 +01:00
parent 694092e12e
commit 2d1f228ad0
3 changed files with 50 additions and 0 deletions

View File

@ -206,6 +206,24 @@ Result rebase_disk(const char* path, const char* backing_disk) {
return SUCCESS; return SUCCESS;
} }
Result reset_disk(const char* path) {
// Get the backing file of the disk
DiskInfo info;
Result result = get_disk_info(path, &info);
if (result != SUCCESS)
return result;
if (info.backing_file == NULL)
result = create_root_disk(path, info.virtual_size, 0644);
else
result = create_backed_disk(path, info.backing_file, 0644);
// Free the disk info as it is no longer needed
free_disk_info(&info);
return result;
}
Result get_disk_info(const char* path, DiskInfo* out_info) { Result get_disk_info(const char* path, DiskInfo* out_info) {
// Initialize the output // Initialize the output
out_info->backing_file = NULL; out_info->backing_file = NULL;

View File

@ -43,6 +43,11 @@ Result trim_disk(const char* path);
/// @return The result of the operation. /// @return The result of the operation.
Result rebase_disk(const char* path, const char* backing_disk); Result rebase_disk(const char* path, const char* backing_disk);
/// @brief Resets a disk to its original state.
/// @param path The path to the disk to reset.
/// @return The result of the operation.
Result reset_disk(const char* path);
/// @brief Gathers information about a disk. /// @brief Gathers information about a disk.
/// @param path The path to the disk to gather information about. /// @param path The path to the disk to gather information about.
/// @param out_info The information about the disk. /// @param out_info The information about the disk.

View File

@ -230,6 +230,33 @@ Result remove_entry(const char* entry_id) {
return SUCCESS; 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;
}
Result get_entry_info(const char* entry_id, EntryInfo* out_info) { Result get_entry_info(const char* entry_id, EntryInfo* out_info) {
out_info->backing_id = NULL; out_info->backing_id = NULL;
out_info->type = ENTRY_TYPE_UNKNOWN; out_info->type = ENTRY_TYPE_UNKNOWN;