From 6f35b2f382a6510139c863faee779ef3cca6b103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 9 Apr 2024 18:47:25 +0800 Subject: [PATCH] Disk (Linux): detect create time --- CMakeLists.txt | 5 +++++ src/detection/disk/disk_linux.c | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 316048646..33c8e3d65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -699,6 +699,7 @@ check_function_exists(wcwidth HAVE_WCWIDTH) if(NOT HAVE_WCWIDTH) list(APPEND LIBFASTFETCH_SRC src/3rdparty/mk_wcwidch/wcwidth.c) endif() +check_function_exists(statx HAVE_STATX) if(ENABLE_SYSTEM_YYJSON) find_package(yyjson) @@ -762,6 +763,10 @@ elseif(APPLE) target_compile_definitions(libfastfetch PUBLIC _DARWIN_C_SOURCE) endif() +if(HAVE_STATX) + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_STATX) +endif() + if(HAVE_WCWIDTH) target_compile_definitions(libfastfetch PRIVATE FF_HAVE_WCWIDTH) endif() diff --git a/src/detection/disk/disk_linux.c b/src/detection/disk/disk_linux.c index b7150bb47..89194414f 100644 --- a/src/detection/disk/disk_linux.c +++ b/src/detection/disk/disk_linux.c @@ -6,9 +6,9 @@ #include #include #include +#include #include #include -#include #include #ifdef __USE_LARGEFILE64 @@ -241,6 +241,13 @@ static void detectStats(FFDisk* disk) if(fs.f_flag & ST_RDONLY) disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT; + + disk->createTime = 0; + #ifdef FF_HAVE_STATX + struct statx stx; + if (statx(0, disk->mountpoint.chars, 0, STATX_BTIME, &stx) == 0 && (stx.stx_mask & STATX_BTIME)) + disk->createTime = (uint64_t)((stx.stx_btime.tv_sec * 1000) + (stx.stx_btime.tv_nsec / 1000000)); + #endif } const char* ffDetectDisksImpl(FFlist* disks)