From f01d7951c1952476c2cb97371a457081b63c8be7 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 11 Mar 2012 17:56:20 +0100 Subject: [PATCH] stat(2) now supports directories. A bit hackily, though. --- sortix/filesystem.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sortix/filesystem.cpp b/sortix/filesystem.cpp index 8700e7a2..93da49a6 100644 --- a/sortix/filesystem.cpp +++ b/sortix/filesystem.cpp @@ -142,6 +142,7 @@ namespace Sortix { Memory::Set(st, 0, sizeof(*st)); st->st_mode = 0777; + st->st_nlink = 1; if ( dev->IsType(Device::BUFFER) ) { st->st_mode |= S_IFREG; @@ -150,13 +151,20 @@ namespace Sortix st->st_blksize = 1; st->st_blocks = st->st_size; } - if ( dev->IsType(Device::DIRECTORY) ) { st->st_mode |= S_IFDIR; } - st->st_nlink = 1; + if ( dev->IsType(Device::DIRECTORY) ) + { + st->st_mode |= S_IFDIR; + st->st_nlink = 2; + } } int SysStat(const char* pathname, struct stat* st) { Device* dev = Open(pathname, O_RDONLY, 0); + if ( !dev && Error::Last() == EISDIR ) + { + dev = Open(pathname, O_SEARCH, 0); + } if ( !dev ) { return -1; } HackStat(dev, st); dev->Unref();