From 3f89bce410469ee2c3c7f65f47423c5671ed43d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 9 Mar 2008 14:21:04 +0000 Subject: [PATCH] * 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 --- src/system/kernel/fs/vfs.cpp | 4 ++- src/system/kernel/module.cpp | 54 ++++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index b6eea17a92..751b93db28 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -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); diff --git a/src/system/kernel/module.cpp b/src/system/kernel/module.cpp index 27f8bea42b..eb9f3ff8fc 100644 --- a/src/system/kernel/module.cpp +++ b/src/system/kernel/module.cpp @@ -16,6 +16,8 @@ #include #include +#include + #include #include #include @@ -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,15 +1134,23 @@ 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; - + size_t length = strlen(path); // TODO: it would currently be nicer to use the commented