Modified some signatures
This commit is contained in:
parent
ab244698c5
commit
a2339d7515
@ -7,7 +7,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <json-c/json.h>
|
||||
|
||||
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);
|
||||
|
@ -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.
|
||||
|
31
src/entry.c
31
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;
|
||||
}
|
||||
|
11
src/entry.h
11
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.
|
||||
|
@ -17,6 +17,9 @@ const Command COMMANDS[] = {
|
||||
{},
|
||||
{command_add_entry, "add-entry", "<entry id> [--root|-r <size>] [--backed|-b <backing id>]", "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", "<entry id> [<backing id>]", "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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
@ -18,3 +18,5 @@ int command_help(int argc, char* argv[]);
|
||||
int command_version(int argc, char* argv[]);
|
||||
|
||||
int command_add_entry(int argc, char* argv[]);
|
||||
|
||||
int command_add_backing(int argc, char* argv[]);
|
Loading…
Reference in New Issue
Block a user