Add . and .. support to kernel filesystems.

This makes the hack in ls(1) not needed and is hence removed.
This commit is contained in:
Jonas 'Sortie' Termansen 2012-09-06 16:16:42 +02:00
parent e761332366
commit 17a93359dd
5 changed files with 27 additions and 15 deletions

View File

@ -302,7 +302,7 @@ namespace Sortix
int DevDevFSDir::Read(sortix_dirent* dirent, size_t available) int DevDevFSDir::Read(sortix_dirent* dirent, size_t available)
{ {
const char* names[] = { "null", "tty", "video", "vga" }; const char* names[] = { ".", "..", "null", "tty", "video", "vga" };
const char* name = NULL; const char* name = NULL;
if ( position < DeviceFS::GetNumDevices() ) if ( position < DeviceFS::GetNumDevices() )
{ {

View File

@ -191,9 +191,6 @@ namespace Sortix
size_t namelen = String::Length(name); size_t namelen = String::Length(name);
size_t needed = sizeof(sortix_dirent) + namelen + 1; size_t needed = sizeof(sortix_dirent) + namelen + 1;
// Oh right, the kernel is stupid and doesn't support dot and dotdot.
if ( name[0] == '.' ) { position++; return Read(dirent, available); }
if ( available < needed ) if ( available < needed )
{ {
dirent->d_namelen = needed; dirent->d_namelen = needed;

View File

@ -341,22 +341,30 @@ namespace Sortix
size_t DevRAMFS::GetNumFiles() size_t DevRAMFS::GetNumFiles()
{ {
size_t result = BINDEVHACK ? 2 : 0; size_t result = 2 + (BINDEVHACK ? 2 : 0);
if ( files ) { result += files->Length(); } if ( files ) { result += files->Length(); }
return result; return result;
} }
const char* DevRAMFS::GetFilename(size_t index) const char* DevRAMFS::GetFilename(size_t index)
{ {
switch ( BINDEVHACK ? index : 2 ) switch ( index )
{
case 0: return ".";
case 1: return "..";
default: index -= 2;
}
if ( BINDEVHACK ) switch ( index )
{ {
case 0: return "bin"; case 0: return "bin";
case 1: return "dev"; case 1: return "dev";
default: index -= 2;
} }
size_t filesindex = BINDEVHACK ? index - 2 : index; if ( !files )
if ( !files ) { return NULL; } return NULL;
if ( files->Length() <= filesindex ) { return NULL; } if ( files->Length() <= index )
DevRAMFSFile* file = files->Get(filesindex); return NULL;
DevRAMFSFile* file = files->Get(index);
return file->name; return file->name;
} }
} }

View File

@ -200,12 +200,24 @@ Device* MakeFB(int flags, mode_t /*mode*/)
return new DevFrameBuffer(); return new DevFrameBuffer();
} }
Device* MakeDot(int /*flags*/, mode_t /*mode*/)
{
return NULL;
}
Device* MakeDotDot(int /*flags*/, mode_t /*mode*/)
{
return NULL;
}
struct struct
{ {
const char* name; const char* name;
Device* (*factory)(int, mode_t); Device* (*factory)(int, mode_t);
} nodes[] = } nodes[] =
{ {
{ ".", MakeDot },
{ "..", MakeDotDot },
{ "mode", MakeMode }, { "mode", MakeMode },
{ "modes", MakeModes }, { "modes", MakeModes },
{ "supports", MakeSupports }, { "supports", MakeSupports },

View File

@ -99,11 +99,6 @@ int ls(const char* path)
DIR* dir = opendir(path); DIR* dir = opendir(path);
if ( !dir ) { finishoutput(); error(0, errno, "%s", path); return 2; } if ( !dir ) { finishoutput(); error(0, errno, "%s", path); return 2; }
#if defined(sortix)
handleentry(path, ".");
handleentry(path, "..");
#endif
struct dirent* entry; struct dirent* entry;
while ( (entry = readdir(dir)) ) while ( (entry = readdir(dir)) )
{ {