Moved the creation and initialization of the FileSystem subclass instance

into the FS interface specific libraries, thus making the server completely
independent of those.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29359 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-02-28 18:56:35 +00:00
parent dd0eadec73
commit afd265501f
7 changed files with 166 additions and 149 deletions
@@ -2,13 +2,16 @@
#include "HaikuKernelFileSystem.h"
#include <string.h>
#include <new>
#include <fs_interface.h>
#include "block_cache.h"
#include "condition_variable.h"
#include "HaikuKernelVolume.h"
using std::nothrow;
// constructor
HaikuKernelFileSystem::HaikuKernelFileSystem(file_system_module_info* fsModule)
@@ -24,16 +27,34 @@ HaikuKernelFileSystem::~HaikuKernelFileSystem()
// call the kernel module uninitialization
if (fFSModule->info.std_ops)
fFSModule->info.std_ops(B_MODULE_UNINIT);
// TODO: Call the cleanup methods (condition vars, block cache)!
}
// Init
status_t
HaikuKernelFileSystem::Init()
{
// call the kernel module initialization
// init condition variables
status_t error = condition_variable_init();
if (error != B_OK)
RETURN_ERROR(error);
// TODO: Call the cleanup methods, if something goes wrong!
// init block cache
error = block_cache_init();
if (error != B_OK)
RETURN_ERROR(error);
// call the kernel module initialization (if any)
if (!fFSModule->info.std_ops)
return B_OK;
return fFSModule->info.std_ops(B_MODULE_INIT);
error = fFSModule->info.std_ops(B_MODULE_INIT);
if (error != B_OK)
RETURN_ERROR(error);
return B_OK;
}
// CreateVolume
@@ -45,7 +66,7 @@ HaikuKernelFileSystem::CreateVolume(Volume** volume, dev_t id)
return B_BAD_VALUE;
// create the volume
*volume = new(nothrow) HaikuKernelVolume(this, id, fFSModule);
*volume = new(std::nothrow) HaikuKernelVolume(this, id, fFSModule);
if (!*volume)
return B_NO_MEMORY;
return B_OK;
@@ -73,3 +94,49 @@ HaikuKernelFileSystem::_InitCapabilities()
// FS operations
fCapabilities.Set(FS_CAPABILITY_MOUNT, fFSModule->mount);
}
// #pragma mark - bootstrapping
status_t
userlandfs_create_file_system(const char* fsName, image_id image,
FileSystem** _fileSystem)
{
// get the modules
module_info** modules;
status_t error = get_image_symbol(image, "modules", B_SYMBOL_TYPE_DATA,
(void**)&modules);
if (error != B_OK)
RETURN_ERROR(error);
// module name must match "file_systems/<name>/v1"
char moduleName[B_PATH_NAME_LENGTH];
snprintf(moduleName, sizeof(moduleName), "file_systems/%s/v1", fsName);
// find the module
file_system_module_info* module = NULL;
for (int32 i = 0; modules[i]->name; i++) {
if (strcmp(modules[i]->name, moduleName) == 0) {
module = (file_system_module_info*)modules[i];
break;
}
}
if (!module)
RETURN_ERROR(B_ERROR);
// create the file system
HaikuKernelFileSystem* fileSystem
= new(std::nothrow) HaikuKernelFileSystem(module);
if (!fileSystem)
RETURN_ERROR(B_NO_MEMORY);
error = fileSystem->Init();
if (error != B_OK) {
delete fileSystem;
return error;
}
*_fileSystem = fileSystem;
return B_OK;
}