Made some small modifications (backing extraction)
This commit is contained in:
parent
7513bb37cc
commit
a260002a6c
@ -396,24 +396,24 @@ result_t get_backing_parent(char** _parent, const char* backing) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// If the disk is not backed, return success and a null parent
|
||||
// Free the backing path as it is not needed anymore
|
||||
free(path);
|
||||
|
||||
// Check if the disk is backed
|
||||
if (info.backing_path == NULL) {
|
||||
free_disk_info(&info);
|
||||
free(path);
|
||||
return success();
|
||||
}
|
||||
|
||||
// Get the backing identifier of the parent
|
||||
char* parent = strdup(basename(info.backing_path));
|
||||
if (parent == NULL) {
|
||||
free_disk_info(&info);
|
||||
free(path);
|
||||
return failure("Failed to get the backing identifier of the parent.");
|
||||
}
|
||||
|
||||
// Free the disk info as it is not needed anymore
|
||||
free_disk_info(&info);
|
||||
free(path);
|
||||
|
||||
if (parent == NULL)
|
||||
return failure("Failed to get the backing identifier of the parent.");
|
||||
|
||||
*_parent = parent;
|
||||
return result;
|
||||
return success();
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ result_t list_backings(char*** _backings);
|
||||
result_t get_default_backing(char** _backing);
|
||||
|
||||
/// @brief Sets the default backing identifier.
|
||||
/// @param backing The backing identifier to set as the default.
|
||||
/// @param backing The backing identifier to set as the default. This parameter can be NULL to remove the default backing.
|
||||
/// @return The result of the operation.
|
||||
result_t set_default_backing(const char* backing);
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
result_t check_container_identifier(const char* container) {
|
||||
@ -236,3 +237,48 @@ result_t list_containers(char*** _containers) {
|
||||
free(pool_path);
|
||||
return result;
|
||||
}
|
||||
|
||||
result_t get_container_backing(char** _backing, const char* container) {
|
||||
// Initialize the output parameters
|
||||
*_backing = NULL;
|
||||
|
||||
// Check that the container exists
|
||||
result_t result = check_container_exists(container);
|
||||
if (result != success())
|
||||
return result;
|
||||
|
||||
// Get the container path
|
||||
char* path;
|
||||
result = get_container_path(&path, container);
|
||||
if (result != success())
|
||||
return result;
|
||||
|
||||
// Get the disk information
|
||||
disk_info_t info;
|
||||
result = get_disk_info(&info, path);
|
||||
if (result != success()) {
|
||||
free(path);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Free the container path as it is no longer needed
|
||||
free(path);
|
||||
|
||||
// Check if the disk is backed
|
||||
if (info.backing_path == NULL) {
|
||||
free_disk_info(&info);
|
||||
success();
|
||||
}
|
||||
|
||||
// Get the backing identifier
|
||||
char* backing = strdup(basename(info.backing_path));
|
||||
|
||||
// Free the disk information as it is no longer needed
|
||||
free_disk_info(&info);
|
||||
|
||||
if (backing == NULL)
|
||||
return failure("Failed to get backing identifier for container '%s'.", container);
|
||||
|
||||
*_backing = backing;
|
||||
return success();
|
||||
}
|
||||
|
@ -61,3 +61,9 @@ bool container_filter(const char* file);
|
||||
/// @param _containers The string pointer array to store the resulting array in. The caller is responsible for freeing the strings and the array.
|
||||
/// @return The result of the operation.
|
||||
result_t list_containers(char*** _containers);
|
||||
|
||||
/// @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.
|
||||
/// @return The result of the operation.
|
||||
result_t get_container_backing(char** _backing, const char* container);
|
Loading…
Reference in New Issue
Block a user