mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add . and .. support to kernel filesystems.
This makes the hack in ls(1) not needed and is hence removed.
This commit is contained in:
parent
e761332366
commit
17a93359dd
5 changed files with 27 additions and 15 deletions
|
@ -302,7 +302,7 @@ namespace Sortix
|
|||
|
||||
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;
|
||||
if ( position < DeviceFS::GetNumDevices() )
|
||||
{
|
||||
|
|
|
@ -191,9 +191,6 @@ namespace Sortix
|
|||
size_t namelen = String::Length(name);
|
||||
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 )
|
||||
{
|
||||
dirent->d_namelen = needed;
|
||||
|
|
|
@ -341,22 +341,30 @@ namespace Sortix
|
|||
|
||||
size_t DevRAMFS::GetNumFiles()
|
||||
{
|
||||
size_t result = BINDEVHACK ? 2 : 0;
|
||||
size_t result = 2 + (BINDEVHACK ? 2 : 0);
|
||||
if ( files ) { result += files->Length(); }
|
||||
return result;
|
||||
}
|
||||
|
||||
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 1: return "dev";
|
||||
default: index -= 2;
|
||||
}
|
||||
size_t filesindex = BINDEVHACK ? index - 2 : index;
|
||||
if ( !files ) { return NULL; }
|
||||
if ( files->Length() <= filesindex ) { return NULL; }
|
||||
DevRAMFSFile* file = files->Get(filesindex);
|
||||
if ( !files )
|
||||
return NULL;
|
||||
if ( files->Length() <= index )
|
||||
return NULL;
|
||||
DevRAMFSFile* file = files->Get(index);
|
||||
return file->name;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,12 +200,24 @@ Device* MakeFB(int flags, mode_t /*mode*/)
|
|||
return new DevFrameBuffer();
|
||||
}
|
||||
|
||||
Device* MakeDot(int /*flags*/, mode_t /*mode*/)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Device* MakeDotDot(int /*flags*/, mode_t /*mode*/)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct
|
||||
{
|
||||
const char* name;
|
||||
Device* (*factory)(int, mode_t);
|
||||
} nodes[] =
|
||||
{
|
||||
{ ".", MakeDot },
|
||||
{ "..", MakeDotDot },
|
||||
{ "mode", MakeMode },
|
||||
{ "modes", MakeModes },
|
||||
{ "supports", MakeSupports },
|
||||
|
|
|
@ -99,11 +99,6 @@ int ls(const char* path)
|
|||
DIR* dir = opendir(path);
|
||||
if ( !dir ) { finishoutput(); error(0, errno, "%s", path); return 2; }
|
||||
|
||||
#if defined(sortix)
|
||||
handleentry(path, ".");
|
||||
handleentry(path, "..");
|
||||
#endif
|
||||
|
||||
struct dirent* entry;
|
||||
while ( (entry = readdir(dir)) )
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue