From 6bcb3d7384bac8bbfe516d5271f3699bc65e2507 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Tue, 6 Mar 2012 13:10:59 +0100 Subject: [PATCH] Added stat(2) and fstat(2) in the kernel. It's a bit hacky, but it works. lstat(2) currently redirects to stat(2). --- libmaxsi/include/libmaxsi/types.h | 2 ++ sortix/filesystem.cpp | 34 +++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/libmaxsi/include/libmaxsi/types.h b/libmaxsi/include/libmaxsi/types.h index fd632377..3235a286 100644 --- a/libmaxsi/include/libmaxsi/types.h +++ b/libmaxsi/include/libmaxsi/types.h @@ -44,6 +44,8 @@ @include(nlink_t.h) @include(blksize_t.h) @include(blkcnt_t.h) +@include(dev_t.h) +@include(time_t.h) @include(va_list.h) diff --git a/sortix/filesystem.cpp b/sortix/filesystem.cpp index e46c0696..8700e7a2 100644 --- a/sortix/filesystem.cpp +++ b/sortix/filesystem.cpp @@ -31,6 +31,7 @@ #include "filesystem.h" #include "directory.h" #include "mount.h" +#include #include #include @@ -137,18 +138,39 @@ namespace Sortix return -1; } + void HackStat(Device* dev, struct stat* st) + { + Memory::Set(st, 0, sizeof(*st)); + st->st_mode = 0777; + if ( dev->IsType(Device::BUFFER) ) + { + st->st_mode |= S_IFREG; + DevBuffer* buffer = (DevBuffer*) dev; + st->st_size = buffer->Size(); + st->st_blksize = 1; + st->st_blocks = st->st_size; + } + if ( dev->IsType(Device::DIRECTORY) ) { st->st_mode |= S_IFDIR; } + st->st_nlink = 1; + } + int SysStat(const char* pathname, struct stat* st) { - // TODO: Add the proper filesystem support! - Error::Set(ENOSYS); - return -1; + Device* dev = Open(pathname, O_RDONLY, 0); + if ( !dev ) { return -1; } + HackStat(dev, st); + dev->Unref(); + return 0; } int SysFStat(int fd, struct stat* st) { - // TODO: Add the proper filesystem support! - Error::Set(ENOSYS); - return -1; + Process* process = CurrentProcess(); + DescriptorTable* descs = &(process->descriptors); + Device* dev = descs->Get(fd); + if ( !dev ) { Error::Set(EBADF); return -1; } + HackStat(dev, st); + return 0; } int SysFCntl(int fd, int cmd, unsigned long arg)