feat: vfs - add stat syscall
This commit is contained in:
1 parent
5c02c5fe79
commit
de7edaf623
12 files changed
+110
-1
No files matched your search
@@ -12,4 +12,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MONTAUK_BUILD_NUMBER 2
|
||||
#define MONTAUK_BUILD_NUMBER 4
|
||||
@@ -116,6 +116,23 @@ namespace montauk::abi {
|
||||
return Fs::Vfs::VfsDelete(resolved);
|
||||
}
|
||||
|
||||
static int Sys_Stat(const char* path, FileStat* out) {
|
||||
if (out == nullptr) return -1;
|
||||
char resolved[256];
|
||||
if (!ResolveProcessPath(path, resolved, sizeof(resolved))) return -1;
|
||||
|
||||
Fs::Vfs::StatInfo info;
|
||||
if (Fs::Vfs::VfsStat(resolved, info) != 0) return -1;
|
||||
|
||||
out->size = info.size;
|
||||
out->mtime = info.mtime;
|
||||
out->ctime = info.ctime;
|
||||
out->atime = info.atime;
|
||||
out->mode = info.mode;
|
||||
out->isDir = info.isDir ? 1u : 0u;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Sys_FMkdir(const char* path) {
|
||||
char resolved[256];
|
||||
if (!ResolveProcessPath(path, resolved, sizeof(resolved))) return -1;
|
||||
|
||||
@@ -153,6 +153,10 @@ namespace montauk::abi {
|
||||
case SYS_GETEXECPATH:
|
||||
if (!UserMemory::Range(frame->arg2 ? frame->arg1 : frame->arg1, frame->arg2, true)) return -1;
|
||||
return Sys_GetExecPath((char*)frame->arg1, frame->arg2);
|
||||
case SYS_STAT:
|
||||
if (!UserMemory::String(frame->arg1, kMaxPathBytes)) return -1;
|
||||
if (!UserMemory::Writable<FileStat>(frame->arg2)) return -1;
|
||||
return (int64_t)Sys_Stat((const char*)frame->arg1, (FileStat*)frame->arg2);
|
||||
case SYS_TERMSIZE:
|
||||
return (int64_t)Sys_TermSize();
|
||||
case SYS_GETARGS:
|
||||
|
||||
@@ -285,6 +285,9 @@ namespace montauk::abi {
|
||||
// Absolute path of the running executable (for argv[0]).
|
||||
static constexpr uint64_t SYS_GETEXECPATH = 151; // (index, flags) -> new front index; index=-1 queries support (1/0); flags bit0 = wait vsync
|
||||
|
||||
// Path metadata (size, timestamps, mode). (const char* path, FileStat* out) -> 0, -1 on error/unsupported.
|
||||
static constexpr uint64_t SYS_STAT = 152;
|
||||
|
||||
// Tunable parameters (for SYS_SDR_SETPARAM / SYS_SDR_GETPARAM).
|
||||
static constexpr int SDR_PARAM_FREQ = 0; // center frequency, Hz
|
||||
static constexpr int SDR_PARAM_SAMPLE_RATE = 1; // sample rate, Hz
|
||||
@@ -326,6 +329,17 @@ namespace montauk::abi {
|
||||
uint8_t Second;
|
||||
};
|
||||
|
||||
// Path metadata returned by SYS_STAT. Timestamps are UTC unix seconds;
|
||||
// a filesystem that does not record a given time reports it as 0.
|
||||
struct FileStat {
|
||||
uint64_t size; // file size in bytes
|
||||
int64_t mtime; // last data modification time
|
||||
int64_t ctime; // last inode (metadata) change time
|
||||
int64_t atime; // last access time
|
||||
uint32_t mode; // ext2/POSIX mode bits (type + permissions)
|
||||
uint32_t isDir; // 1 if the entry is a directory, else 0
|
||||
};
|
||||
|
||||
struct FbInfo {
|
||||
uint64_t width;
|
||||
uint64_t height;
|
||||
|
||||
Reference in new issue
Block a user