* The module code now uses find_directory() and no hard-coded paths anymore.

* It now also supports the common directory path.
* search_module() checked the module paths in the wrong order, ie. it preferred
  modules in the system directory over the user directory.
* Clarified comment in vfs_get_module_path().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24323 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2008-03-09 14:21:04 +00:00
parent fa28330bbf
commit 3f89bce410
2 changed files with 40 additions and 18 deletions

View File

@ -3304,6 +3304,7 @@ vfs_get_fs_node_from_path(dev_t mountID, const char *path, bool kernel,
\c B_ENTRY_NOT_FOUNT if no file could be found.
\a pathBuffer is clobbered in any case and must not be relied on if this
functions returns unsuccessfully.
\a basePath and \a pathBuffer must not point to the same space.
*/
status_t
vfs_get_module_path(const char *basePath, const char *moduleName,
@ -3314,7 +3315,8 @@ vfs_get_module_path(const char *basePath, const char *moduleName,
size_t length;
char *path;
if (bufferSize == 0 || strlcpy(pathBuffer, basePath, bufferSize) >= bufferSize)
if (bufferSize == 0
|| strlcpy(pathBuffer, basePath, bufferSize) >= bufferSize)
return B_BUFFER_OVERFLOW;
status = path_to_vnode(pathBuffer, true, &dir, NULL, true);

View File

@ -16,6 +16,8 @@
#include <string.h>
#include <sys/stat.h>
#include <FindDirectory.h>
#include <boot_device.h>
#include <elf.h>
#include <lock.h>
@ -147,15 +149,16 @@ static recursive_lock sModulesLock;
/* These are the standard base paths where we start to look for modules
* to load. Order is important, the last entry here will be searched
* first.
* ToDo: these should probably be retrieved by using find_directory().
*/
static const char * const sModulePaths[] = {
"/boot/beos/system/add-ons/kernel",
"/boot/home/config/add-ons/kernel",
static const directory_which kModulePaths[] = {
B_BEOS_ADDONS_DIRECTORY,
B_COMMON_ADDONS_DIRECTORY,
B_USER_ADDONS_DIRECTORY,
};
#define NUM_MODULE_PATHS (sizeof(sModulePaths) / sizeof(sModulePaths[0]))
#define FIRST_USER_MODULE_PATH (NUM_MODULE_PATHS - 1) /* first user path */
static const uint32 kNumModulePaths = sizeof(kModulePaths)
/ sizeof(kModulePaths[0]);
static const uint32 kFirstNonSystemModulePath = 1;
/* We store the loaded modules by directory path, and all known modules
* by module name in a hash table for quick access
@ -467,17 +470,26 @@ search_module(const char *name)
TRACE(("search_module(%s)\n", name));
for (i = 0; i < NUM_MODULE_PATHS; i++) {
char path[B_FILE_NAME_LENGTH];
if (sDisableUserAddOns && i >= FIRST_USER_MODULE_PATH)
return NULL;
for (i = kNumModulePaths; i-- > 0;) {
if (sDisableUserAddOns && i >= kFirstNonSystemModulePath)
continue;
// let the VFS find that module for us
status = vfs_get_module_path(sModulePaths[i], name, path, sizeof(path));
KPath basePath;
if (find_directory(kModulePaths[i], gBootDevice, true,
basePath.LockBuffer(), basePath.BufferSize()) != B_OK)
continue;
basePath.UnlockBuffer();
basePath.Append("kernel");
KPath path;
status = vfs_get_module_path(basePath.Path(), name, path.LockBuffer(),
path.BufferSize());
if (status == B_OK) {
status = check_module_image(path, name);
path.UnlockBuffer();
status = check_module_image(path.Path(), name);
if (status == B_OK)
break;
}
@ -1122,12 +1134,20 @@ open_module_list(const char *prefix)
iterator->loaded_modules = false;
// put all search paths on the stack
for (i = 0; i < NUM_MODULE_PATHS; i++) {
if (sDisableUserAddOns && i >= FIRST_USER_MODULE_PATH)
for (i = 0; i < kNumModulePaths; i++) {
if (sDisableUserAddOns && i >= kFirstNonSystemModulePath)
break;
KPath pathBuffer;
if (find_directory(kModulePaths[i], gBootDevice, true,
pathBuffer.LockBuffer(), pathBuffer.BufferSize()) != B_OK)
continue;
pathBuffer.UnlockBuffer();
pathBuffer.Append("kernel");
// Copy base path onto the iterator stack
char *path = strdup(sModulePaths[i]);
char *path = strdup(pathBuffer.Path());
if (path == NULL)
continue;