From d88c45c6f2162b39280da26621b3121f55430e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 15 Jun 2004 16:59:59 +0000 Subject: [PATCH] Now maintains the inode field in the preloaded_image structure. It will now load all modules only once by identifying them using their inode number. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7991 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/boot/loader/elf.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/kernel/boot/loader/elf.cpp b/src/kernel/boot/loader/elf.cpp index ce9605fa24..33d1f297d3 100644 --- a/src/kernel/boot/loader/elf.cpp +++ b/src/kernel/boot/loader/elf.cpp @@ -289,6 +289,22 @@ elf_load_image(Directory *directory, const char *path) if (fd < 0) return fd; + // check if this file has already been loaded + + struct stat stat; + fstat(fd, &stat); + + image = gKernelArgs.preloaded_images; + for (; image != NULL; image = image->next) { + if (image->inode == stat.st_ino) { + // file has already been loaded, no need to load it twice! + close(fd); + return B_OK; + } + } + + // we still need to load it, so do it + image = (preloaded_image *)kernel_args_malloc(sizeof(preloaded_image)); if (image == NULL) { close(fd); @@ -298,6 +314,7 @@ elf_load_image(Directory *directory, const char *path) status_t status = elf_load_image(fd, image); if (status == B_OK) { image->name = kernel_args_strdup(path); + image->inode = stat.st_ino; // insert to kernel args image->next = gKernelArgs.preloaded_images;