1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

stat(2) now supports directories.

A bit hackily, though.
This commit is contained in:
Jonas 'Sortie' Termansen 2012-03-11 17:56:20 +01:00
parent 6e536ba8f9
commit f01d7951c1

View file

@ -142,6 +142,7 @@ namespace Sortix
{ {
Memory::Set(st, 0, sizeof(*st)); Memory::Set(st, 0, sizeof(*st));
st->st_mode = 0777; st->st_mode = 0777;
st->st_nlink = 1;
if ( dev->IsType(Device::BUFFER) ) if ( dev->IsType(Device::BUFFER) )
{ {
st->st_mode |= S_IFREG; st->st_mode |= S_IFREG;
@ -150,13 +151,20 @@ namespace Sortix
st->st_blksize = 1; st->st_blksize = 1;
st->st_blocks = st->st_size; st->st_blocks = st->st_size;
} }
if ( dev->IsType(Device::DIRECTORY) ) { st->st_mode |= S_IFDIR; } if ( dev->IsType(Device::DIRECTORY) )
st->st_nlink = 1; {
st->st_mode |= S_IFDIR;
st->st_nlink = 2;
}
} }
int SysStat(const char* pathname, struct stat* st) int SysStat(const char* pathname, struct stat* st)
{ {
Device* dev = Open(pathname, O_RDONLY, 0); Device* dev = Open(pathname, O_RDONLY, 0);
if ( !dev && Error::Last() == EISDIR )
{
dev = Open(pathname, O_SEARCH, 0);
}
if ( !dev ) { return -1; } if ( !dev ) { return -1; }
HackStat(dev, st); HackStat(dev, st);
dev->Unref(); dev->Unref();