mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
Disk (macOS): detect create time
This commit is contained in:
parent
5c37ebec70
commit
6700f63091
@ -17,6 +17,8 @@ typedef struct FFDisk
|
||||
|
||||
uint32_t filesUsed;
|
||||
uint32_t filesTotal;
|
||||
|
||||
uint64_t createTime;
|
||||
} FFDisk;
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#include <libgeom.h>
|
||||
@ -130,6 +131,10 @@ const char* ffDetectDisksImpl(FFlist* disks)
|
||||
|
||||
if(fs->f_flags & MNT_RDONLY)
|
||||
disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
|
||||
|
||||
struct stat st;
|
||||
if(stat(fs->f_mntonname, &st) == 0)
|
||||
disk->createTime = (uint64_t)((st.st_birthtimespec.tv_sec * 1000) + (st.st_birthtimespec.tv_nsec / 1000000));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -6,7 +6,9 @@
|
||||
#include "modules/disk/disk.h"
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#define FF_DISK_NUM_FORMAT_ARGS 11
|
||||
#include <time.h>
|
||||
|
||||
#define FF_DISK_NUM_FORMAT_ARGS 12
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
|
||||
static void printDisk(FFDiskOptions* options, const FFDisk* disk)
|
||||
@ -112,6 +114,13 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
|
||||
bool isExternal = !!(disk->type & FF_DISK_VOLUME_TYPE_EXTERNAL_BIT);
|
||||
bool isHidden = !!(disk->type & FF_DISK_VOLUME_TYPE_HIDDEN_BIT);
|
||||
bool isReadOnly = !!(disk->type & FF_DISK_VOLUME_TYPE_READONLY_BIT);
|
||||
|
||||
char buf[64] = "";
|
||||
if(disk->createTime)
|
||||
{
|
||||
time_t time = (time_t) (disk->createTime / 1000);
|
||||
strftime(buf, sizeof(buf), "%FT%T%z", localtime(&time));
|
||||
}
|
||||
FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISK_NUM_FORMAT_ARGS, ((FFformatarg[]) {
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty},
|
||||
@ -124,6 +133,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->filesystem},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->name},
|
||||
{FF_FORMAT_ARG_TYPE_BOOL, &isReadOnly},
|
||||
{FF_FORMAT_ARG_TYPE_STRING, buf},
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -448,6 +458,8 @@ void ffGenerateDiskJsonResult(FFDiskOptions* options, yyjson_mut_doc* doc, yyjso
|
||||
yyjson_mut_arr_add_str(doc, typeArr, "Hidden");
|
||||
if(item->type & FF_DISK_VOLUME_TYPE_READONLY_BIT)
|
||||
yyjson_mut_arr_add_str(doc, typeArr, "Read-only");
|
||||
|
||||
yyjson_mut_obj_add_uint(doc, obj, "createTime", item->createTime);
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFDisk, item, disks)
|
||||
@ -473,6 +485,7 @@ void ffPrintDiskHelpFormat(void)
|
||||
"Filesystem",
|
||||
"Label / name",
|
||||
"True if read-only",
|
||||
"Create time",
|
||||
}));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user