diff --git a/src/disk.c b/src/disk.c index 526fac2..3578799 100644 --- a/src/disk.c +++ b/src/disk.c @@ -7,7 +7,7 @@ #include #include -Result create_empty_disk(const char* path, uint64_t size, mode_t permissions) { +Result create_root_disk(const char* path, uint64_t size, mode_t permissions) { // Convert the size to a string char* size_str; Result result = format(&size_str, "%lu", size); diff --git a/src/disk.h b/src/disk.h index 1c7a87e..62a9416 100644 --- a/src/disk.h +++ b/src/disk.h @@ -18,12 +18,12 @@ typedef struct { char* backing_file; } DiskInfo; -/// @brief Creates an empty disk at the given path, with the given size and with the given permissions. +/// @brief Creates a root disk at the given path, with the given size and with the given permissions. /// @param path The path to the disk to create. /// @param size The size of the disk to create. /// @param permissions The permissions to set on the disk. /// @return The result of the operation. -Result create_empty_disk(const char* path, uint64_t size, mode_t permissions); +Result create_root_disk(const char* path, uint64_t size, mode_t permissions); /// @brief Creates a backed disk at the given path, with the given backing disk and with the given permissions. /// @param path The path to the disk to create. diff --git a/src/entry.c b/src/entry.c index 69de2eb..eba037f 100644 --- a/src/entry.c +++ b/src/entry.c @@ -62,34 +62,3 @@ Result entry_exists(const char* entry_id, bool* out_exists) { return SUCCESS; } - -Result add_entry(const char* entry_id) { - // Check if the entry already exists - bool exists; - Result result = entry_exists(entry_id, &exists); - if (result != SUCCESS) - return result; - - if (exists) { - log_message(LOG_LEVEL_ERROR, "Entry '%s' already exists.", entry_id); - return FAILURE; - } - - // Create the entry directory - char* path; - result = get_entry_path(entry_id, &path); - if (result != SUCCESS) - return result; - - int result_code = mkdir(path, 0755); - - free(path); - - // Check if the operation failed - if (result_code != 0) { - log_message(LOG_LEVEL_ERROR, "Failed to create entry '%s' (%s).", entry_id, strerror(errno)); - return FAILURE; - } - - return SUCCESS; -} diff --git a/src/entry.h b/src/entry.h index 26de77d..8abe526 100644 --- a/src/entry.h +++ b/src/entry.h @@ -25,10 +25,17 @@ Result get_entry_path(const char* entry_id, char** out_path); /// @return The result of the operation. Result entry_exists(const char* entry_id, bool* out_exists); -/// @brief Adds an entry to the entry pool. +/// @brief Adds a root entry to the entry pool. /// @param entry_id The entry id. +/// @param size The size of the entry, in bytes. /// @return The result of the operation. -Result add_entry(const char* entry_id); +Result add_root_entry(const char* entry_id, uint64_t size); + +/// @brief Adds a backed entry to the entry pool. +/// @param entry_id The entry id. +/// @param backing_id The backing id. +/// @return The result of the operation. +Result add_backed_entry(const char* entry_id, const char* backing_id); /// @brief Removes an entry from the entry pool. /// @param entry_id The entry id. diff --git a/src/sandbox.c b/src/sandbox.c index a5834b2..7ee5e84 100644 --- a/src/sandbox.c +++ b/src/sandbox.c @@ -17,6 +17,9 @@ const Command COMMANDS[] = { {}, {command_add_entry, "add-entry", " [--root|-r ] [--backed|-b ]", "Adds an entry to the entry pool.", "Adds an entry to the entry pool with the given id. The entry can either be a root entry or a backed entry. If the entry is a root entry, the size of the entry must be specified. If the entry is a backed entry, the backing id must be specified. By default, the entry is backed by the latest backing disk available."}, + {}, + {command_add_backing, "add-backing", " []", "Adds a backing disk to the backing pool, from the given entry.", + "TODO"}, }; int main(int argc, char* argv[]) { @@ -111,19 +114,20 @@ int command_add_entry(int argc, char* argv[]) { return EXIT_FAILURE; } - // TODO: Parse arguments + // TODO: Parse options - // Extract the entry id - const char* entry_id = argv[0]; - - // Create the entry - Result result = add_entry(entry_id); - if (result != SUCCESS) - return result; - - // Add the disk to the entry - - // If this fails, remove the entry + // TODO: Call add_root_entry or add_backed_entry depending on the options return EXIT_SUCCESS; -} \ No newline at end of file +} + +int command_add_backing(int argc, char* argv[]) { + if (argc < 1) { + log_message(LOG_LEVEL_ERROR, "Missing entry id."); + return EXIT_FAILURE; + } + + // TODO: Call add_backing + + return EXIT_SUCCESS; +} diff --git a/src/sandbox.h b/src/sandbox.h index 441f143..4fbc2e5 100644 --- a/src/sandbox.h +++ b/src/sandbox.h @@ -17,4 +17,6 @@ int main(int argc, char* argv[]); int command_help(int argc, char* argv[]); int command_version(int argc, char* argv[]); -int command_add_entry(int argc, char* argv[]); \ No newline at end of file +int command_add_entry(int argc, char* argv[]); + +int command_add_backing(int argc, char* argv[]); \ No newline at end of file