Improved the entry listing
This commit is contained in:
parent
cf6e692289
commit
444bbc6ebe
@ -196,3 +196,19 @@ Status GetLatestBacking(char** _backing_identifier) {
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
Status GetBackingDiskInfo(const char* backing_identifier, DiskInfo* _info) {
|
||||
*_info = (DiskInfo){0};
|
||||
|
||||
// Get the backing path
|
||||
char* backing_path = NULL;
|
||||
Status status = GetBackingPath(backing_identifier, &backing_path);
|
||||
if (status != SUCCESS)
|
||||
return status;
|
||||
|
||||
// Get the disk info
|
||||
status = GetDiskInfo(backing_path, _info);
|
||||
free(backing_path);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "disk.h"
|
||||
|
||||
bool IsBackingIdentifierValid(const char* backing_identifier);
|
||||
int GetBackingIndex(const char* backing_identifier);
|
||||
@ -15,3 +16,5 @@ Status RemoveBacking(const char* backing_identifier);
|
||||
|
||||
Status ListBackings(char*** _backings);
|
||||
Status GetLatestBacking(char** _backing_identifier);
|
||||
|
||||
Status GetBackingDiskInfo(const char* backing_identifier, DiskInfo* _info);
|
11
src/disk.c
11
src/disk.c
@ -5,6 +5,7 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
#include <sys/stat.h>
|
||||
#include <json-c/json.h>
|
||||
|
||||
@ -233,9 +234,19 @@ Status GetDiskInfo(const char* path, DiskInfo* _info) {
|
||||
|
||||
json_object_put(root);
|
||||
|
||||
if (_info->backing_file != NULL) {
|
||||
_info->backing_identifier = strdup(basename(_info->backing_file));
|
||||
if (_info->backing_identifier == NULL) {
|
||||
Log(LOG_LEVEL_ERROR, "Failed to duplicate the backing identifier (%s).", strerror(errno));
|
||||
FreeDiskInfo(_info);
|
||||
return FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
void FreeDiskInfo(DiskInfo* info) {
|
||||
free(info->backing_file);
|
||||
free(info->backing_identifier);
|
||||
}
|
@ -6,6 +6,7 @@ typedef struct {
|
||||
uint64_t size;
|
||||
uint64_t allocated;
|
||||
char* backing_file;
|
||||
char* backing_identifier;
|
||||
} DiskInfo;
|
||||
|
||||
Status CreateRootDisk(const char* path, uint64_t disk_size);
|
||||
|
16
src/entry.c
16
src/entry.c
@ -489,3 +489,19 @@ Status TrimEntryDisk(const char* entry_identifier) {
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
Status GetEntryDiskInfo(const char* entry_identifier, DiskInfo* _info) {
|
||||
*_info = (DiskInfo){0};
|
||||
|
||||
// Get the disk path
|
||||
char* entry_disk_path = NULL;
|
||||
Status status = GetEntryDiskPath(entry_identifier, &entry_disk_path);
|
||||
if (status != SUCCESS)
|
||||
return status;
|
||||
|
||||
// Get the disk info
|
||||
status = GetDiskInfo(entry_disk_path, _info);
|
||||
free(entry_disk_path);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "utils.h"
|
||||
#include "disk.h"
|
||||
|
||||
bool IsEntryIdentifierValid(const char* entry_identifier);
|
||||
|
||||
@ -22,3 +23,5 @@ Status AddBackedEntryDisk(const char* entry_identifier, const char* backing_iden
|
||||
Status RemoveEntryDisk(const char* entry_identifier);
|
||||
Status ResetEntryDisk(const char* entry_identifier, const char* backing_identifier);
|
||||
Status TrimEntryDisk(const char* entry_identifier);
|
||||
|
||||
Status GetEntryDiskInfo(const char* entry_identifier, DiskInfo* _info);
|
||||
|
@ -221,10 +221,21 @@ int CommandListEntries(int argc, char* argv[]) {
|
||||
if (status != SUCCESS)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (has_disk)
|
||||
fprintf(stdout, "%zu | %-*s | %s |\n", i, (int)max_length, entries[i], "Has disk");
|
||||
else
|
||||
fprintf(stdout, "%zu | %-*s | %s |\n", i, (int)max_length, entries[i], "No disk ");
|
||||
if (has_disk) {
|
||||
DiskInfo info;
|
||||
status = GetEntryDiskInfo(entries[i], &info);
|
||||
if (status != SUCCESS)
|
||||
continue;
|
||||
|
||||
// Format the size
|
||||
char* size_fmt;
|
||||
status = FormatSize(info.allocated, &size_fmt);
|
||||
if (status != SUCCESS)
|
||||
continue;
|
||||
|
||||
fprintf(stdout, "%zu | %-*s | %-10s | %s%s\n", i, (int)max_length, entries[i], size_fmt, info.backing_identifier == NULL ? "No backing" : "Backed by ", info.backing_identifier == NULL ? "" : info.backing_identifier);
|
||||
} else
|
||||
fprintf(stdout, "%zu | %-*s | %s\n", i, (int)max_length, entries[i], "No disk ");
|
||||
}
|
||||
|
||||
// Free the entries
|
||||
|
Loading…
Reference in New Issue
Block a user