Implemented entry resetting

This commit is contained in:
Alexei KADIR 2024-02-18 13:20:30 +01:00
parent 1ff4d4df2f
commit a149a838d1

View File

@ -200,11 +200,13 @@ Status ListEntries(char*** _entries) {
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
continue; continue;
// Check if the entry exists (this checks for validity)
bool exists; bool exists;
Status status = DoesEntryExist(entry->d_name, &exists); Status status = DoesEntryExist(entry->d_name, &exists);
if (status != SUCCESS || !exists) if (status != SUCCESS || !exists)
continue; continue;
// Allocate memory for the new entry list
char** new_entries = realloc(*_entries, (count + 2) * sizeof(char*)); // +2 for the new entry and the NULL terminator char** new_entries = realloc(*_entries, (count + 2) * sizeof(char*)); // +2 for the new entry and the NULL terminator
if (new_entries == NULL) { if (new_entries == NULL) {
Log(LOG_LEVEL_ERROR, "Failed to reallocate memory for the entries list (%s).", strerror(errno)); Log(LOG_LEVEL_ERROR, "Failed to reallocate memory for the entries list (%s).", strerror(errno));
@ -351,6 +353,60 @@ Status RemoveEntryDisk(const char* entry_identifier) {
return SUCCESS; return SUCCESS;
} }
Status ResetEntryDisk(const char* entry_identifier, const char* backing_identifier) {
// Check if the disk exists
bool exists;
Status status = DoesEntryDiskExist(entry_identifier, &exists);
if (status != SUCCESS)
return status;
if (!exists) {
Log(LOG_LEVEL_ERROR, "The disk for the entry '%s' does not exist.", entry_identifier);
return FAILURE;
}
// Get the backing disk path
char* backing_disk_path = NULL;
if (backing_identifier != NULL) {
status = GetBackingDiskPath(backing_identifier, &backing_disk_path);
if (status != SUCCESS)
return status;
}
// Get the disk path
char* entry_disk_path = NULL;
status = GetEntryDiskPath(entry_identifier, &entry_disk_path);
if (status != SUCCESS) {
free(backing_disk_path);
return status;
}
// Get the disk info
DiskInfo disk_info;
status = GetDiskInfo(entry_disk_path, &disk_info);
if (status != SUCCESS) {
free(backing_disk_path);
free(entry_disk_path);
return status;
}
// If no backing disk is specified, use the current backing disk
if (backing_disk_path == NULL)
backing_disk_path = disk_info.backing_file;
// Reset the disk
if (backing_disk_path != NULL)
status = CreateBackedDisk(entry_disk_path, backing_disk_path);
else
status = CreateRootDisk(entry_disk_path, disk_info.size);
FreeDiskInfo(&disk_info);
free(backing_disk_path);
free(entry_disk_path);
return status;
}
Status TrimEntryDisk(const char* entry_identifier) { Status TrimEntryDisk(const char* entry_identifier) {
// Check if the disk exists // Check if the disk exists
bool exists; bool exists;