Added some small modifications
This commit is contained in:
40
src/entry.c
40
src/entry.c
@@ -1,6 +1,7 @@
|
||||
#include "entry.h"
|
||||
|
||||
#include "disk.h"
|
||||
#include "backing.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -199,6 +200,11 @@ Status ListEntries(char*** _entries) {
|
||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
bool exists;
|
||||
Status status = DoesEntryExist(entry->d_name, &exists);
|
||||
if (status != SUCCESS || !exists)
|
||||
continue;
|
||||
|
||||
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));
|
||||
@@ -282,6 +288,40 @@ Status AddRootEntryDisk(const char* entry_identifier, uint64_t disk_size) {
|
||||
return status;
|
||||
}
|
||||
|
||||
Status AddBackedEntryDisk(const char* entry_identifier, const char* backing_identifier) {
|
||||
// Check if the disk already 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' already exists.", entry_identifier);
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
// Get the backing disk path
|
||||
char* backing_disk_path = 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;
|
||||
}
|
||||
|
||||
// Create the disk
|
||||
status = CreateBackedDisk(entry_disk_path, backing_disk_path);
|
||||
free(backing_disk_path);
|
||||
free(entry_disk_path);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
Status RemoveEntryDisk(const char* entry_identifier) {
|
||||
// Check if the disk exists
|
||||
bool exists;
|
||||
|
Reference in New Issue
Block a user