Perfected the disk utilities

This commit is contained in:
2024-02-15 19:42:22 +01:00
parent e6bc757343
commit 01ea511b2d
10 changed files with 581 additions and 1183 deletions

View File

@@ -1,32 +1,43 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stdbool.h>
/// @brief Creates an empty disk.
/// @param disk The path to the disk to create. Warning: the disk must not exist, otherwise it will be overwritten.
/// @param size The size of the disk to create in bytes.
/// @return true if the disk is created, otherwise false.
bool create_empty_disk(const char* disk, uint64_t size);
typedef struct DiskInfo {
uint64_t virtual_size;
uint64_t actual_size;
char* backing_file;
} DiskInfo;
/// @brief Creates a backed disk.
/// @param disk The path to the disk to create. Warning: the disk must not exist, otherwise it will be overwritten.
/// @param backing The path to the backing file, which exists.
/// @return true if the disk is created, otherwise false.
bool create_backed_disk(const char* disk, const char* backing);
/// @brief Creates an empty disk at the given path with the given size.
/// @param path The path to the disk. Any existing file at this path will be overwritten.
/// @param size The size of the disk, in bytes.
/// @return True if the disk was created successfully, false otherwise.
bool create_empty_disk(const char* path, uint64_t size);
/// @brief Packs the disk to reduce its size.
/// @param disk The path to the disk to pack, which exists.
/// @return true if the disk is packed, otherwise false.
bool pack_disk(const char* disk);
/// @brief Creates a disk at the given path with the given backing disk.
/// @param path The path to the disk.
/// @param backing_disk The path to the backing disk.
/// @return True if the disk was created successfully, false otherwise.
bool create_backed_disk(const char* path, const char* backing_disk);
/// @brief Moves the backing file of a disk.
/// @param disk The path to the disk, which exists.
/// @param backing The path to the new backing file, which exists.
/// @return true if the backing file is moved, otherwise false.
bool move_backing_file(const char* disk, const char* backing);
/// @brief Trims the given disk to remove any unused space.
/// @param path The path to the disk.
/// @return True if the disk was trimmed successfully, false otherwise.
bool trim_disk(const char* path);
/// @brief Gets the backing file of a disk.
/// @param disk The path to the disk, which exists.
/// @return The backing file of the disk. The caller is responsible for freeing the returned string. This function can return NULL.
char* get_backing_file(const char* disk);
/// @brief Changes the backing disk of the given disk.
/// @param path The path to the disk.
/// @param backing_disk The path to the new backing disk.
/// @return True if the disk was rebased successfully, false otherwise.
bool rebase_disk(const char* path, const char* backing_disk);
/// @brief Gets information about the given disk.
/// @param path The path to the disk.
/// @param info The DiskInfo struct to fill with information about the disk.
/// @return True if the disk information was retrieved successfully, false otherwise.
bool get_disk_info(const char* path, DiskInfo* info);
/// @brief Frees the memory used by the given DiskInfo struct.
/// @param info The DiskInfo struct to free.
void free_disk_info(DiskInfo* info);