mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Swap (Windows): detect detailed info
This commit is contained in:
@@ -4,8 +4,9 @@
|
||||
|
||||
typedef struct FFSwapResult
|
||||
{
|
||||
FFstrbuf name;
|
||||
uint64_t bytesUsed;
|
||||
uint64_t bytesTotal;
|
||||
} FFSwapResult;
|
||||
|
||||
const char* ffDetectSwap(FFSwapResult* swap);
|
||||
const char* ffDetectSwap(FFlist* result /* List of FFSwapResult */);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "swap.h"
|
||||
#include "util/mallocHelper.h"
|
||||
#include "util/windows/unicode.h"
|
||||
|
||||
#include <winternl.h>
|
||||
#include <ntstatus.h>
|
||||
#include <windows.h>
|
||||
|
||||
const char* ffDetectSwap(FFSwapResult* swap)
|
||||
const char* ffDetectSwap(FFlist* result)
|
||||
{
|
||||
uint8_t buffer[4096];
|
||||
ULONG size = sizeof(buffer);
|
||||
@@ -13,16 +14,18 @@ const char* ffDetectSwap(FFSwapResult* swap)
|
||||
if(!NT_SUCCESS(NtQuerySystemInformation(SystemPagefileInformation, pstart, size, &size)))
|
||||
return "NtQuerySystemInformation(SystemPagefileInformation, size) failed";
|
||||
|
||||
uint32_t pageSize = instance.state.platform.sysinfo.pageSize;
|
||||
for (SYSTEM_PAGEFILE_INFORMATION* current = pstart; ; current = (SYSTEM_PAGEFILE_INFORMATION*)((uint8_t*) current + current->NextEntryOffset))
|
||||
{
|
||||
swap->bytesUsed += current->TotalUsed;
|
||||
swap->bytesTotal += current->CurrentSize;
|
||||
FFSwapResult* swap = ffListAdd(result);
|
||||
ffStrbufInitNWS(&swap->name, current->FileName.Length / sizeof(wchar_t), current->FileName.Buffer);
|
||||
if (ffStrbufStartsWithS(&swap->name, "\\??\\"))
|
||||
ffStrbufSubstrAfter(&swap->name, strlen("\\??\\") - 1);
|
||||
swap->bytesUsed = current->TotalUsed * pageSize;
|
||||
swap->bytesTotal = current->CurrentSize * pageSize;
|
||||
if (current->NextEntryOffset == 0)
|
||||
break;
|
||||
}
|
||||
uint32_t pageSize = instance.state.platform.sysinfo.pageSize;
|
||||
swap->bytesUsed *= pageSize;
|
||||
swap->bytesTotal *= pageSize;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user