Improved the entry listing
This commit is contained in:
parent
cf6e692289
commit
444bbc6ebe
@ -196,3 +196,19 @@ Status GetLatestBacking(char** _backing_identifier) {
|
|||||||
|
|
||||||
return status;
|
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
|
#pragma once
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "disk.h"
|
||||||
|
|
||||||
bool IsBackingIdentifierValid(const char* backing_identifier);
|
bool IsBackingIdentifierValid(const char* backing_identifier);
|
||||||
int GetBackingIndex(const char* backing_identifier);
|
int GetBackingIndex(const char* backing_identifier);
|
||||||
@ -14,4 +15,6 @@ Status AddBacking(const char* backing_identifier, const char* entry_identifier);
|
|||||||
Status RemoveBacking(const char* backing_identifier);
|
Status RemoveBacking(const char* backing_identifier);
|
||||||
|
|
||||||
Status ListBackings(char*** _backings);
|
Status ListBackings(char*** _backings);
|
||||||
Status GetLatestBacking(char** _backing_identifier);
|
Status GetLatestBacking(char** _backing_identifier);
|
||||||
|
|
||||||
|
Status GetBackingDiskInfo(const char* backing_identifier, DiskInfo* _info);
|
13
src/disk.c
13
src/disk.c
@ -5,6 +5,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <libgen.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <json-c/json.h>
|
#include <json-c/json.h>
|
||||||
|
|
||||||
@ -233,9 +234,19 @@ Status GetDiskInfo(const char* path, DiskInfo* _info) {
|
|||||||
|
|
||||||
json_object_put(root);
|
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;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreeDiskInfo(DiskInfo* info) {
|
void FreeDiskInfo(DiskInfo* info) {
|
||||||
free(info->backing_file);
|
free(info->backing_file);
|
||||||
}
|
free(info->backing_identifier);
|
||||||
|
}
|
@ -6,6 +6,7 @@ typedef struct {
|
|||||||
uint64_t size;
|
uint64_t size;
|
||||||
uint64_t allocated;
|
uint64_t allocated;
|
||||||
char* backing_file;
|
char* backing_file;
|
||||||
|
char* backing_identifier;
|
||||||
} DiskInfo;
|
} DiskInfo;
|
||||||
|
|
||||||
Status CreateRootDisk(const char* path, uint64_t disk_size);
|
Status CreateRootDisk(const char* path, uint64_t disk_size);
|
||||||
@ -15,4 +16,4 @@ Status TrimDisk(const char* path);
|
|||||||
Status RebaseDisk(const char* path, const char* backing_file);
|
Status RebaseDisk(const char* path, const char* backing_file);
|
||||||
|
|
||||||
Status GetDiskInfo(const char* path, DiskInfo* _info);
|
Status GetDiskInfo(const char* path, DiskInfo* _info);
|
||||||
void FreeDiskInfo(DiskInfo* info);
|
void FreeDiskInfo(DiskInfo* info);
|
||||||
|
16
src/entry.c
16
src/entry.c
@ -489,3 +489,19 @@ Status TrimEntryDisk(const char* entry_identifier) {
|
|||||||
|
|
||||||
return status;
|
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
|
#pragma once
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "disk.h"
|
||||||
|
|
||||||
bool IsEntryIdentifierValid(const char* entry_identifier);
|
bool IsEntryIdentifierValid(const char* entry_identifier);
|
||||||
|
|
||||||
@ -21,4 +22,6 @@ Status AddRootEntryDisk(const char* entry_identifier, uint64_t disk_size);
|
|||||||
Status AddBackedEntryDisk(const char* entry_identifier, const char* backing_identifier);
|
Status AddBackedEntryDisk(const char* entry_identifier, const char* backing_identifier);
|
||||||
Status RemoveEntryDisk(const char* entry_identifier);
|
Status RemoveEntryDisk(const char* entry_identifier);
|
||||||
Status ResetEntryDisk(const char* entry_identifier, const char* backing_identifier);
|
Status ResetEntryDisk(const char* entry_identifier, const char* backing_identifier);
|
||||||
Status TrimEntryDisk(const char* entry_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)
|
if (status != SUCCESS)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
if (has_disk)
|
if (has_disk) {
|
||||||
fprintf(stdout, "%zu | %-*s | %s |\n", i, (int)max_length, entries[i], "Has disk");
|
DiskInfo info;
|
||||||
else
|
status = GetEntryDiskInfo(entries[i], &info);
|
||||||
fprintf(stdout, "%zu | %-*s | %s |\n", i, (int)max_length, entries[i], "No disk ");
|
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
|
// Free the entries
|
||||||
|
Loading…
Reference in New Issue
Block a user