Files
linuxinstall/src/disk.h
2024-02-17 12:35:33 +01:00

60 lines
2.2 KiB
C

#pragma once
#include "utils.h"
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
/// @brief The information about a disk.
typedef struct {
/// @brief The virtual size of the disk.
uint64_t virtual_size;
/// @brief The actual size of the disk.
uint64_t actual_size;
/// @brief The path to the backing file of the disk. This is NULL if the disk is not backed.
char* backing_file;
} DiskInfo;
/// @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_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.
/// @param backing_disk The disk to back the new disk with.
/// @param permissions The permissions to set on the disk.
/// @return The result of the operation.
Result create_backed_disk(const char* path, const char* backing_disk, mode_t permissions);
/// @brief Trims a disk to remove any unused space.
/// @param path The path to the disk to trim.
/// @return The result of the operation.
Result trim_disk(const char* path);
/// @brief Moves a disk's backing file to the given path.
/// @param path The path to the disk to move.
/// @param backing_disk The new path to the backing disk.
/// @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.
/// @return The result of the operation.
Result get_disk_info(const char* path, DiskInfo* out_info);
/// @brief Frees the resources used by the given disk information.
/// @param info The disk information to free.
void free_disk_info(DiskInfo* info);