Added commands for managing disks
This commit is contained in:
56
src/entry.c
56
src/entry.c
@@ -193,23 +193,23 @@ Status ListEntries(char*** _entries) {
|
||||
}
|
||||
(*_entries)[0] = NULL;
|
||||
|
||||
// Read the entries from the directory
|
||||
// Read the files in the entry pool directory
|
||||
size_t count = 0;
|
||||
struct dirent* entry;
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||
struct dirent* file;
|
||||
while ((file = readdir(dir)) != NULL) {
|
||||
if (strcmp(file->d_name, ".") == 0 || strcmp(file->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
// Check if the entry exists (this checks for validity)
|
||||
bool exists;
|
||||
Status status = DoesEntryExist(entry->d_name, &exists);
|
||||
Status status = DoesEntryExist(file->d_name, &exists);
|
||||
if (status != SUCCESS || !exists)
|
||||
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
|
||||
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 entry list (%s).", strerror(errno));
|
||||
closedir(dir);
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
@@ -221,7 +221,7 @@ Status ListEntries(char*** _entries) {
|
||||
*_entries = new_entries;
|
||||
|
||||
// Duplicate the entry name and add it to the list
|
||||
(*_entries)[count] = strdup(entry->d_name);
|
||||
(*_entries)[count] = strdup(file->d_name);
|
||||
if ((*_entries)[count] == NULL) {
|
||||
Log(LOG_LEVEL_ERROR, "Failed to duplicate the entry name (%s).", strerror(errno));
|
||||
closedir(dir);
|
||||
@@ -266,9 +266,19 @@ Status ClearEntries() {
|
||||
}
|
||||
|
||||
Status AddRootEntryDisk(const char* entry_identifier, uint64_t disk_size) {
|
||||
// Check if the disk already exists
|
||||
// Check that the entry exists
|
||||
bool exists;
|
||||
Status status = DoesEntryDiskExist(entry_identifier, &exists);
|
||||
Status status = DoesEntryExist(entry_identifier, &exists);
|
||||
if (status != SUCCESS)
|
||||
return status;
|
||||
|
||||
if (!exists) {
|
||||
Log(LOG_LEVEL_ERROR, "The entry '%s' does not exist.", entry_identifier);
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
// Check if the disk already exists
|
||||
status = DoesEntryDiskExist(entry_identifier, &exists);
|
||||
if (status != SUCCESS)
|
||||
return status;
|
||||
|
||||
@@ -291,9 +301,29 @@ Status AddRootEntryDisk(const char* entry_identifier, uint64_t disk_size) {
|
||||
}
|
||||
|
||||
Status AddBackedEntryDisk(const char* entry_identifier, const char* backing_identifier) {
|
||||
// Check if the disk already exists
|
||||
// Check that the entry exists
|
||||
bool exists;
|
||||
Status status = DoesEntryDiskExist(entry_identifier, &exists);
|
||||
Status status = DoesEntryExist(entry_identifier, &exists);
|
||||
if (status != SUCCESS)
|
||||
return status;
|
||||
|
||||
if (!exists) {
|
||||
Log(LOG_LEVEL_ERROR, "The entry '%s' does not exist.", entry_identifier);
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
// Check that the backing exists
|
||||
status = DoesBackingExist(backing_identifier, &exists);
|
||||
if (status != SUCCESS)
|
||||
return status;
|
||||
|
||||
if (!exists) {
|
||||
Log(LOG_LEVEL_ERROR, "The backing '%s' does not exist.", backing_identifier);
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
// Check if the disk already exists
|
||||
status = DoesEntryDiskExist(entry_identifier, &exists);
|
||||
if (status != SUCCESS)
|
||||
return status;
|
||||
|
||||
@@ -304,7 +334,7 @@ Status AddBackedEntryDisk(const char* entry_identifier, const char* backing_iden
|
||||
|
||||
// Get the backing disk path
|
||||
char* backing_disk_path = NULL;
|
||||
status = GetBackingDiskPath(backing_identifier, &backing_disk_path);
|
||||
status = GetBackingPath(backing_identifier, &backing_disk_path);
|
||||
if (status != SUCCESS)
|
||||
return status;
|
||||
|
||||
@@ -368,7 +398,7 @@ Status ResetEntryDisk(const char* entry_identifier, const char* backing_identifi
|
||||
// Get the backing disk path
|
||||
char* backing_disk_path = NULL;
|
||||
if (backing_identifier != NULL) {
|
||||
status = GetBackingDiskPath(backing_identifier, &backing_disk_path);
|
||||
status = GetBackingPath(backing_identifier, &backing_disk_path);
|
||||
if (status != SUCCESS)
|
||||
return status;
|
||||
}
|
||||
|
Reference in New Issue
Block a user