Added a user system
This commit is contained in:
98
src/entry.c
98
src/entry.c
@@ -81,6 +81,40 @@ Result get_entry_type_path(const char* entry_id, char** out_path) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Result get_entry_type(const char* entry_id, EntryType* out_type) {
|
||||
// Get the path of the type file
|
||||
char* type_path;
|
||||
Result result = get_entry_type_path(entry_id, &type_path);
|
||||
if (result != SUCCESS)
|
||||
return result;
|
||||
|
||||
// Read the type file
|
||||
char* type;
|
||||
result = read_file(type_path, &type);
|
||||
if (result != SUCCESS) {
|
||||
free(type_path);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Free the type path
|
||||
free(type_path);
|
||||
|
||||
// Check the type
|
||||
if (strcmp(type, ENTRY_TYPE_ROOT_STRING) == 0)
|
||||
*out_type = ENTRY_TYPE_ROOT;
|
||||
else if (strcmp(type, ENTRY_TYPE_BACKED_STRING) == 0)
|
||||
*out_type = ENTRY_TYPE_BACKED;
|
||||
else if (strcmp(type, ENTRY_TYPE_AUTOMATIC_STRING) == 0)
|
||||
*out_type = ENTRY_TYPE_AUTOMATIC;
|
||||
else
|
||||
*out_type = ENTRY_TYPE_UNKNOWN;
|
||||
|
||||
// Free the type
|
||||
free(type);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
Result entry_exists(const char* entry_id, bool* out_exists) {
|
||||
*out_exists = false;
|
||||
|
||||
@@ -405,67 +439,3 @@ Result reset_entry(const char* entry_id) {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Result get_entry_info(const char* entry_id, EntryInfo* out_info) {
|
||||
out_info->backing_id = NULL;
|
||||
out_info->type = ENTRY_TYPE_UNKNOWN;
|
||||
|
||||
// Get the path of the type file
|
||||
char* type_path;
|
||||
Result result = get_entry_type_path(entry_id, &type_path);
|
||||
if (result != SUCCESS)
|
||||
return result;
|
||||
|
||||
// Read the type file
|
||||
char* type;
|
||||
result = read_file(type_path, &type);
|
||||
if (result != SUCCESS) {
|
||||
free(type_path);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Free the type path
|
||||
free(type_path);
|
||||
|
||||
// Check the type
|
||||
if (strcmp(type, ENTRY_TYPE_ROOT_STRING) == 0)
|
||||
out_info->type = ENTRY_TYPE_ROOT;
|
||||
else if (strcmp(type, ENTRY_TYPE_BACKED_STRING) == 0)
|
||||
out_info->type = ENTRY_TYPE_BACKED;
|
||||
else if (strcmp(type, ENTRY_TYPE_AUTOMATIC_STRING) == 0)
|
||||
out_info->type = ENTRY_TYPE_AUTOMATIC;
|
||||
|
||||
// Free the type
|
||||
free(type);
|
||||
|
||||
// Get the path of the entry disk
|
||||
char* disk_path;
|
||||
result = get_entry_disk_path(entry_id, &disk_path);
|
||||
if (result != SUCCESS)
|
||||
return result;
|
||||
|
||||
// Get the information about the disk
|
||||
result = get_disk_info(disk_path, &out_info->disk_info);
|
||||
|
||||
// Free the disk path
|
||||
free(disk_path);
|
||||
|
||||
if (result != SUCCESS)
|
||||
return result;
|
||||
|
||||
// Check if the disk is backed
|
||||
if (out_info->disk_info.backing_file != NULL) {
|
||||
out_info->backing_id = strdup(basename(out_info->disk_info.backing_file));
|
||||
if (out_info->backing_id == NULL) {
|
||||
free_disk_info(&out_info->disk_info);
|
||||
return OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
void free_entry_info(EntryInfo* info) {
|
||||
free(info->backing_id);
|
||||
free_disk_info(&info->disk_info);
|
||||
}
|
||||
|
Reference in New Issue
Block a user