Mount-points are now handled properly within the kernel.

This commit is contained in:
Jonas 'Sortie' Termansen 2011-11-21 19:39:13 +01:00
parent 8b2b52b9f6
commit 91a97a2667
2 changed files with 84 additions and 20 deletions

View File

@ -34,42 +34,105 @@ using namespace Maxsi;
namespace Sortix namespace Sortix
{ {
class MountPoint
{
public:
MountPoint(DevFileSystem* fs, char* path);
~MountPoint();
public:
MountPoint* prev;
MountPoint* next;
public:
DevFileSystem* fs;
char* path;
};
MountPoint::MountPoint(DevFileSystem* fs, char* path)
{
this->path = path;
this->fs = fs;
this->fs->Refer();
prev = NULL;
next = NULL;
}
MountPoint::~MountPoint()
{
fs->Unref();
delete[] path;
}
namespace Mount namespace Mount
{ {
DevFileSystem* initfs; MountPoint* root;
DevFileSystem* rootfs;
bool MatchesMountPath(const char* path, const char* mount) bool MatchesMountPath(const char* path, const char* mount)
{ {
size_t mountlen = String::Length(mount); size_t mountlen = String::Length(mount);
if ( !String::StartsWith(path, mount) ) { return false; } if ( !String::StartsWith(path, mount) ) { return false; }
switch ( path[mountlen] ) int c = path[mountlen];
{ return c == '/' || c == '\0';
case '\0':
case '/':
return true;
default:
return false;
}
} }
DevFileSystem* WhichFileSystem(const char* path, size_t* pathoffset) DevFileSystem* WhichFileSystem(const char* path, size_t* pathoffset)
{ {
if ( MatchesMountPath(path, "/bin") ) DevFileSystem* result = NULL;
{
*pathoffset = 4;
return initfs;
}
*pathoffset = 0; *pathoffset = 0;
return rootfs;
for ( MountPoint* tmp = root; tmp; tmp = tmp->next )
{
if ( MatchesMountPath(path, tmp->path) )
{
result = tmp->fs;
*pathoffset = String::Length(tmp->path);
}
}
return result;
}
bool Register(DevFileSystem* fs, const char* path)
{
char* newpath = String::Clone(path);
if ( !newpath ) { return false; }
MountPoint* mp = new MountPoint(fs, newpath);
if ( !mp ) { delete[] newpath; return false; }
if ( !root ) { root = mp; return true; }
if ( String::Compare(path, root->path) < 0 )
{
mp->next = root;
root->prev = mp;
root = mp;
return false;
}
for ( MountPoint* tmp = root; tmp; tmp = tmp->next )
{
if ( tmp->next == NULL || String::Compare(path, tmp->next->path) < 0 )
{
mp->next = tmp->next;
tmp->next = mp;
return true;
}
}
return false; // Shouldn't happen.
} }
void Init() void Init()
{ {
initfs = new DevInitFS(); root = NULL;
if ( !initfs ) { Panic("Unable to allocate initfs"); }
rootfs = new DevRAMFS(); DevFileSystem* rootfs = new DevRAMFS();
if ( !rootfs ) { Panic("Unable to allocate rootfs"); } if ( !rootfs || !Register(rootfs, "") ) { Panic("Unable to allocate rootfs"); }
DevFileSystem* initfs = new DevInitFS();
if ( !initfs || !Register(initfs, "/bin") ) { Panic("Unable to allocate initfs"); }
} }
} }
} }

View File

@ -33,6 +33,7 @@ namespace Sortix
{ {
void Init(); void Init();
DevFileSystem* WhichFileSystem(const char* path, size_t* pathoffset); DevFileSystem* WhichFileSystem(const char* path, size_t* pathoffset);
bool Register(DevFileSystem* fs, const char* path);
} }
} }