Haiku: ストレージ

このコミットが含まれているのは:
守矢諏訪子 2024-07-15 05:24:55 +00:00
コミット 7d6a896c53
1個のファイルの変更65行の追加0行の削除

ファイルの表示

@ -1,6 +1,9 @@
#include "storage.h" #include "storage.h"
#include "common.h" #include "common.h"
#if defined(__HAIKU__)
#include <stdio.h>
#endif
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -8,9 +11,71 @@ const char *display_storage() {
const char *excode = run_command_s("zpool list 2>/dev/null || echo $?"); const char *excode = run_command_s("zpool list 2>/dev/null || echo $?");
if (excode != NULL && (strncmp(excode, "127", strlen("127")) == 0)) { if (excode != NULL && (strncmp(excode, "127", strlen("127")) == 0)) {
free((void *)excode); free((void *)excode);
#if defined(__HAIKU__)
long long int usedstore = 0;
long long int totalstore = run_command_lld("df -h | "
"awk '/^\\/boot / {printf \"%s\", $3}'");
long long int freestore = run_command_lld("df -h | "
"awk '/^\\/boot / {printf \"%s\", $5}'");
const char *totunit = run_command_s("df -h | "
"awk '/^\\/boot / {printf \"%s\", $4}'");
const char *freunit = run_command_s("df -h | "
"awk '/^\\/boot / {printf \"%s\", $6}'");
char tu[2] = {'\0'};
char uu[2] = {'\0'};
if (strncmp(totunit, "TiB", 3) == 0) tu[0] = 'T';
else if (strncmp(totunit, "GiB", 3) == 0) tu[0] = 'G';
else if (strncmp(totunit, "MiB", 3) == 0) tu[0] = 'M';
else if (strncmp(totunit, "KiB", 3) == 0) tu[0] = 'K';
else tu[0] = 'B';
tu[1] = '\0';
if (strncmp(freunit, "TiB", 3) == 0) uu[0] = 'T';
else if (strncmp(freunit, "GiB", 3) == 0) uu[0] = 'G';
else if (strncmp(freunit, "MiB", 3) == 0) uu[0] = 'M';
else if (strncmp(freunit, "KiB", 3) == 0) uu[0] = 'K';
else uu[0] = 'B';
uu[1] = '\0';
if (strncmp(totunit, freunit, 3) != 0) {
if (strncmp(totunit, "TiB", 3) == 0 && strncmp(freunit, "GiB", 3) == 0)
usedstore = (totalstore - (freestore / 1024));
else if (strncmp(totunit, "GiB", 3) == 0 && strncmp(freunit, "MiB", 3) == 0)
usedstore = (totalstore - (freestore / 1024));
else if (strncmp(totunit, "MiB", 3) == 0 && strncmp(freunit, "KiB", 3) == 0)
usedstore = (totalstore - (freestore / 1024));
else if (strncmp(totunit, "KiB", 3) == 0 && strncmp(freunit, "B", 3) == 0)
usedstore = (totalstore - (freestore / 1024));
else if (strncmp(totunit, "TiB", 3) == 0 && strncmp(freunit, "MiB", 3) == 0)
usedstore = (totalstore - (freestore / 1024 / 1024));
else if (strncmp(totunit, "GiB", 3) == 0 && strncmp(freunit, "KiB", 3) == 0)
usedstore = (totalstore - (freestore / 1024 / 1024));
else if (strncmp(totunit, "MiB", 3) == 0 && strncmp(freunit, "B", 3) == 0)
usedstore = (totalstore - (freestore / 1024 / 1024));
else if (strncmp(totunit, "TiB", 3) == 0 && strncmp(freunit, "KiB", 3) == 0)
usedstore = (totalstore - (freestore / 1024 / 1024 / 1024));
else if (strncmp(totunit, "GiB", 3) == 0 && strncmp(freunit, "B", 3) == 0)
usedstore = (totalstore - (freestore / 1024 / 1024 / 1024));
else if (strncmp(totunit, "TiB", 3) == 0 && strncmp(freunit, "B", 3) == 0)
usedstore = (totalstore - (freestore / 1024 / 1024 / 1024 / 1024));
} else {
usedstore = (totalstore - freestore);
}
char *cmd = (char *)malloc(128 * sizeof(char));
if (!cmd) {
return NULL;
}
snprintf(cmd, 128, "/boot: %lld%s / %lld%s", usedstore, uu, totalstore, tu);
return cmd;
#else
return run_command_s("df -h | " return run_command_s("df -h | "
"awk '/^\\/dev\\// {printf \"%s: %s / %s, \", $1, $3, $2}' | " "awk '/^\\/dev\\// {printf \"%s: %s / %s, \", $1, $3, $2}' | "
"awk '{sub(/, $/, \"\"); print}'"); "awk '{sub(/, $/, \"\"); print}'");
#endif
} }
free((void *)excode); free((void *)excode);