Rewrote a cleaner version of container / backing systems

This commit is contained in:
2024-02-28 17:50:27 +01:00
parent 788d46d071
commit a02cd9fe20
21 changed files with 1453 additions and 2489 deletions

114
src/container.h Executable file → Normal file
View File

@@ -1,91 +1,87 @@
#pragma once
#include "utils.h"
#include "disk.h"
#include "config.h"
#define CONTAINER_IDENTIFIER_MAX_LENGTH 64
/// @brief The maximum length of a container identifier.
#define MAX_CONTAINER_IDENTIFIER_LENGTH 64
/// @brief Checks whether the given string is a valid container identifier. If the string is not a valid container identifier, the call will return a failure result with an error message.
/// @param container The string to check.
/// @brief Checks whether the specified container identifier is valid. This call returns a failure if the identifier is invalid.
/// @param container The container identifier to check.
/// @return The result of the operation.
result_t check_container_identifier(const char* container);
/// @brief Checks whether the given container exists. If the container does not exist, the call will return a failure result with an error message.
/// @param container The container to check.
/// @brief Returns the path of the container pool.
/// @param _path The pointer to where the path should be stored. The caller is responsible for freeing the path.
/// @param config The program configuration to use.
/// @return The result of the operation.
result_t check_container_exists(const char* container);
result_t get_container_pool_path(char** _path, const config_t* config);
/// @brief Gets the container pool path.
/// @param _path The string pointer to store the resulting path in. The caller is responsible for freeing the string.
/// @brief Returns the path of the specified container.
/// @param _path The pointer to where the path should be stored. The caller is responsible for freeing the path.
/// @param config The program configuration to use.
/// @param container The identifier of the container to get the path of.
/// @return The result of the operation.
result_t get_container_pool_path(char** _path);
result_t get_container_path(char** _path, const config_t* config, const char* container);
/// @brief Gets the container path.
/// @param _path The string pointer to store the resulting path in. The caller is responsible for freeing the string.
/// @param container The container to get the path of.
/// @return The result of the operation.
result_t get_container_path(char** _path, const char* container);
/// @brief Checks whether the specified container exists. This call returns a failure if the container does not exist.
/// @param config The program configuration to use.
/// @param container The identifier of the container to check.
/// @return Whether the container exists.
result_t check_container_exists(const config_t* config, const char* container);
/// @brief Adds a root (empty) container to the pool, with the given size. If the container already exists, the call will return a failure result with an error message.
/// @param container The container to add.
/// @brief Adds a new root container to the container pool, with the specified identifier and size.
/// @param config The program configuration to use.
/// @param container The identifier of the container to add.
/// @param size The size of the container to add, in bytes.
/// @return The result of the operation.
result_t add_root_container(const char* container, uint64_t size);
result_t add_root_container(const config_t* config, const char* container, uint64_t size);
/// @brief Adds a backed container to the pool, with the given backing. If the container already exists, or the backing does not, the call will return a failure result with an error message.
/// @param container The container to add.
/// @param backing The backing to use for the container.
/// @brief Adds a new backed container to the container pool, with the specified identifier and backing.
/// @param config The program configuration to use.
/// @param container The identifier of the container to add.
/// @param backing The identifier of the backing to use.
/// @return The result of the operation.
result_t add_backed_container(const char* container, const char* backing);
result_t add_backed_container(const config_t* config, const char* container, const char* backing);
/// @brief Removes the given container from the pool. If the container does not exist, the call will return a failure result with an error message.
/// @param container The container to remove.
/// @brief Removes the specified container from the container pool.
/// @param config The program configuration to use.
/// @param container The identifier of the container to remove.
/// @return The result of the operation.
result_t remove_container(const char* container);
result_t remove_container(const config_t* config, const char* container);
/// @brief Trims (removes unused space) the given container.
/// @param container The container to trim.
/// @brief Resets the specified container to its original state.
/// @param config The program configuration to use.
/// @param container The identifier of the container to reset.
/// @return The result of the operation.
result_t trim_container(const char* container);
result_t reset_container(const config_t* config, const char* container);
/// @brief Resets the given container to its initial state.
/// @param container The container to reset.
/// @brief Trims the specified container.
/// @param config The program configuration to use.
/// @param container The identifier of the container to trim.
/// @return The result of the operation.
result_t reset_container(const char* container);
result_t trim_container(const config_t* config, const char* container);
/// @brief Checks that the given file is a container. This function is used as a filter for listing containers.
/// @param file The file to check.
/// @return Whether the file is a container.
bool container_filter(const char* file);
/// @brief Lists the containers in the pool.
/// @param _containers The string array pointer to store the resulting array in. The caller is responsible for freeing the strings and the array.
/// @brief Lists the containers in the container pool, and returns the result in a null-terminated array of strings.
/// @param _containers The pointer to where the containers array should be stored. The caller is responsible for freeing the containers array as well as the strings in the array.
/// @param config The program configuration to use.
/// @return The result of the operation.
result_t list_containers(char*** _containers);
result_t list_containers(char*** _containers, const config_t* config);
/// @brief Gets the backing of the given container. If the container does not exist, the call will return a failure result with an error message.
/// @param _backing The string pointer to store the resulting backing in.
/// @param container The container to get the backing of.
/// @brief Returns the oldest container in the container pool.
/// @param _container The pointer to where the container should be stored. The caller is responsible for freeing the container.
/// @param config The program configuration to use.
/// @return The result of the operation.
result_t get_container_backing(char** _backing, const char* container);
result_t get_oldest_container(char** _container, const config_t* config);
/// @brief Gets information about the given container. If the container does not exist, the call will return a failure result with an error message.
/// @param _info The string pointer to store the resulting disk information in. The caller is responsible for freeing the string.
/// @param container The container to get information about.
/// @brief Calculates the total available space in the container pool.
/// @param _size The pointer to where the size should be stored.
/// @param config The program configuration to use.
/// @return The result of the operation.
result_t get_container_info(disk_info_t* _info, const char* container);
result_t get_available_space(uint64_t* _size, const config_t* config);
/// @brief Gets the oldest container in the pool.
/// @param _container The string pointer to store the resulting container in. The caller is responsible for freeing the string.
/// @return The result of the operation.
result_t get_oldest_container(char** _container);
/// @brief Gets the available space in the pool.
/// @param _space The string pointer to store the resulting space in, in bytes. The caller is responsible for freeing the string.
/// @return The result of the operation.
result_t get_container_pool_space(uint64_t* _space);
/// @brief Reserves the given space in the pool. If the pool does not have enough space, the oldest containers will be removed to make space.
/// @brief Reserves the specified space in the container pool, by removing the oldest containers.
/// @param config The program configuration to use.
/// @param size The size to reserve, in bytes.
/// @return The result of the operation.
result_t reserve_container_pool_space(uint64_t size);
result_t reserve_space(const config_t* config, uint64_t size);