Added some signatures to handle updating entries

This commit is contained in:
Alexei KADIR 2024-02-17 12:11:09 +01:00
parent e38e07ca68
commit 188e57dc31
5 changed files with 45 additions and 30 deletions

View File

@ -206,24 +206,6 @@ Result rebase_disk(const char* path, const char* backing_disk) {
return SUCCESS;
}
Result reset_disk(const char* path) {
// Get the backing file of the disk
DiskInfo info;
Result result = get_disk_info(path, &info);
if (result != SUCCESS)
return result;
if (info.backing_file == NULL)
result = create_root_disk(path, info.virtual_size, 0644);
else
result = create_backed_disk(path, info.backing_file, 0644);
// Free the disk info as it is no longer needed
free_disk_info(&info);
return result;
}
Result get_disk_info(const char* path, DiskInfo* out_info) {
// Initialize the output
out_info->backing_file = NULL;

View File

@ -43,11 +43,6 @@ Result trim_disk(const char* path);
/// @return The result of the operation.
Result rebase_disk(const char* path, const char* backing_disk);
/// @brief Resets a disk to its original state.
/// @param path The path to the disk to reset.
/// @return The result of the operation.
Result reset_disk(const char* path);
/// @brief Gathers information about a disk.
/// @param path The path to the disk to gather information about.
/// @param out_info The information about the disk.

View File

@ -1,12 +1,26 @@
#pragma once
#include "utils.h"
#include "disk.h"
#include <stdbool.h>
#include <stdint.h>
#define ENTRY_POOL_DIR "/var/lib/sandbox/entries"
#define MAX_ENTRY_LENGTH 64
#define MAX_ENTRY_LENGTH 256
typedef enum {
ENTRY_TYPE_ROOT,
ENTRY_TYPE_BACKED,
ENTRY_TYPE_AUTOMATIC
} EntryType;
typedef struct {
EntryType type;
char* backing_id;
DiskInfo disk_info;
} EntryInfo;
/// @brief Checks whether the given entry id is valid.
/// @param entry_id The entry id to check.
@ -56,12 +70,22 @@ Result list_entries(char*** out_entries);
/// @return The result of the operation.
Result clear_entries(void);
/// @brief Resets an entry to its initial state. Automatic entries will be backed by the latest backing disk available.
/// @brief Resets an entry to its initial state.
/// @param entry_id The entry id.
/// @return The result of the operation.
Result reset_entry(const char* entry_id);
/// @brief Updates the backing disk of the given entry if it is an automatic entry.
/// @brief Updates the backing disk of the given entry to the latest available. Warning: This operation resets the entry.
/// @param entry_id The entry id.
/// @return The result of the operation.
Result update_entry(const char* entry_id);
Result update_entry(const char* entry_id);
/// @brief Gathers information about the given entry.
/// @param entry_id The entry id.
/// @param out_info The pointer to the output entry information.
/// @return The result of the operation.
Result get_entry_info(const char* entry_id, EntryInfo* out_info);
/// @brief Frees the resources used by the given entry information.
/// @param info The entry information to free.
void free_entry_info(EntryInfo* info);

View File

@ -16,15 +16,17 @@ const Command COMMANDS[] = {
"Prints the version of the program."},
{},
{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."},
"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 will be an automatic entry, which will be backed by the latest backing disk available and will automatically reset to its initial state when a new backing disk is added."},
{command_remove_entry, "remove-entry", "<entry id>", "Removes an entry from the entry pool.",
"Removes the entry with the given id from the entry pool."},
{command_list_entries, "list-entries", "", "Lists the entries in the entry pool.",
"Lists the entries in the entry pool."},
"Lists the entries in the entry pool, as well as their types and backing disks."},
{command_clear_entries, "clear-entries", "", "Removes all the entries from the entry pool.",
"Removes all the entries from the entry pool."},
{command_reset_entry, "reset-entry", "<entry id>", "Resets an entry to its initial state.",
"Resets the entry with the given id to its initial state. Automatic entries will be backed by the latest backing disk available."},
"TODO"},
{command_update_entry, "update-entry", "<entry id>", "Updates the backing disk of the given entry to the latest available.",
"TODO"},
{},
{command_add_backing, "add-backing", "<entry id> [<backing id>]", "Adds a backing disk to the backing pool, from the given entry.",
"TODO"},
@ -165,6 +167,17 @@ int command_reset_entry(int argc, char* argv[]) {
return EXIT_SUCCESS;
}
int command_update_entry(int argc, char* argv[]) {
if (argc < 1) {
log_message(LOG_LEVEL_ERROR, "Missing entry id.");
return EXIT_FAILURE;
}
// TODO: Call update_entry
return EXIT_SUCCESS;
}
int command_add_backing(int argc, char* argv[]) {
if (argc < 1) {
log_message(LOG_LEVEL_ERROR, "Missing entry id.");

View File

@ -22,5 +22,6 @@ int command_remove_entry(int argc, char* argv[]);
int command_list_entries(int argc, char* argv[]);
int command_clear_entries(int argc, char* argv[]);
int command_reset_entry(int argc, char* argv[]);
int command_update_entry(int argc, char* argv[]);
int command_add_backing(int argc, char* argv[]);