Ticket #2185: devfs.cpp.diff

File devfs.cpp.diff, 2.2 KB (added by kaoutsis, 11 years ago)
  • src/system/kernel/fs/devfs.cpp

     
    2525#include <boot_device.h>
    2626#include <debug.h>
    2727#include <elf.h>
     28#include <FindDirectory.h>
    2829#include <kdevice_manager.h>
    2930#include <KPath.h>
    3031#include <lock.h>
     
    490491
    491492
    492493static int32
    493 get_priority(const char *path)
     494get_priority(const char* path)
    494495{
    495     // TODO: use find_directory()
    496     const char *kPaths[] = {"/boot/beos", "/boot/common", "/boot/home", NULL};
     496    const directory_which whichPath[] = {
     497        B_BEOS_DIRECTORY,
     498        B_COMMON_DIRECTORY,
     499        B_USER_DIRECTORY
     500    };
     501    KPath pathBuffer;
    497502
    498     for (int32 i = 0; kPaths[i] != NULL; i++) {
    499         if (!strncmp(kPaths[i], path, strlen(kPaths[i])))
    500             return i;
     503    for (uint32 index = 0; index < sizeof(whichPath) / sizeof(whichPath[0]); index++) {
     504        if (find_directory(whichPath[index], gBootDevice, false,
     505            pathBuffer.LockBuffer(), pathBuffer.BufferSize()) == B_OK) {
     506            pathBuffer.UnlockBuffer();
     507            if (!strncmp(pathBuffer.Path(), path, pathBuffer.BufferSize()))
     508                return index;
     509        }
    501510    }
    502511
    503512    return -1;
     
    28372846    struct preloaded_image* image;
    28382847    for (image = args->preloaded_images; image != NULL; image = image->next) {
    28392848        if (!image->is_module && image->id >= 0) {
    2840             // fake an absolute path
    2841             char path[B_PATH_NAME_LENGTH];
    2842             strlcpy(path, "/boot/beos/system/add-ons/kernel/", sizeof(path));
    2843             strlcat(path, image->name, sizeof(path));
     2849            KPath imagePath;
     2850            status_t status = find_directory(B_BEOS_ADDONS_DIRECTORY, gBootDevice, false,
     2851                imagePath.LockBuffer(), imagePath.BufferSize());
     2852            if (status < B_OK) {
     2853                dprintf("devfs_add_preloaded_drivers: Failed when find_directory \"%s\"\n",
     2854                    strerror(status));
     2855            } else {
     2856                imagePath.UnlockBuffer();
     2857                imagePath.Append("kernel/");
     2858                imagePath.Append(image->name);
     2859            }
    28442860
    28452861            // try to add the driver
    2846             status_t error = add_driver(path, image->id);
    2847             if (error != B_OK) {
     2862            status = add_driver(imagePath.Path(), image->id);
     2863            if (status != B_OK) {
    28482864                dprintf("devfs_add_preloaded_drivers: Failed to add \"%s\"\n",
    28492865                    image->name);
    28502866                unload_kernel_add_on(image->id);