1998-08-21 03:17:42 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-08-25 23:30:41 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
/*
|
2000-05-01 17:41:25 +00:00
|
|
|
* file/module function dispatcher, support, etc.
|
1998-08-21 03:17:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stand.h>
|
|
|
|
#include <string.h>
|
1998-10-09 23:12:34 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/linker.h>
|
2001-09-11 01:09:24 +00:00
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/queue.h>
|
2014-08-05 23:41:40 +00:00
|
|
|
#include <sys/stdint.h>
|
1998-08-21 03:17:42 +00:00
|
|
|
|
|
|
|
#include "bootstrap.h"
|
|
|
|
|
2001-09-11 01:09:24 +00:00
|
|
|
#define MDIR_REMOVED 0x0001
|
|
|
|
#define MDIR_NOHINTS 0x0002
|
|
|
|
|
|
|
|
struct moduledir {
|
|
|
|
char *d_path; /* path of modules directory */
|
|
|
|
u_char *d_hints; /* content of linker.hints file */
|
|
|
|
int d_hintsz; /* size of hints data */
|
|
|
|
int d_flags;
|
|
|
|
STAILQ_ENTRY(moduledir) d_link;
|
|
|
|
};
|
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
static int file_load(char *filename, vm_offset_t dest, struct preloaded_file **result);
|
2001-11-16 21:08:40 +00:00
|
|
|
static int file_load_dependencies(struct preloaded_file *base_mod);
|
2001-09-11 01:09:24 +00:00
|
|
|
static char * file_search(const char *name, char **extlist);
|
|
|
|
static struct kernel_module * file_findmodule(struct preloaded_file *fp, char *modname, struct mod_depend *verinfo);
|
|
|
|
static int file_havepath(const char *name);
|
|
|
|
static char *mod_searchmodule(char *name, struct mod_depend *verinfo);
|
2000-05-01 17:41:25 +00:00
|
|
|
static void file_insert_tail(struct preloaded_file *mp);
|
|
|
|
struct file_metadata* metadata_next(struct file_metadata *base_mp, int type);
|
2001-09-11 01:09:24 +00:00
|
|
|
static void moduledir_readhints(struct moduledir *mdp);
|
|
|
|
static void moduledir_rebuild(void);
|
1998-09-03 02:10:09 +00:00
|
|
|
|
1998-09-14 18:27:06 +00:00
|
|
|
/* load address should be tweaked by first module loaded (kernel) */
|
1998-08-21 03:17:42 +00:00
|
|
|
static vm_offset_t loadaddr = 0;
|
|
|
|
|
2014-09-03 21:25:36 +00:00
|
|
|
#if defined(LOADER_FDT_SUPPORT)
|
|
|
|
static const char *default_searchpath =
|
|
|
|
"/boot/kernel;/boot/modules;/boot/dtb";
|
|
|
|
#else
|
2003-03-03 22:53:35 +00:00
|
|
|
static const char *default_searchpath ="/boot/kernel;/boot/modules";
|
2014-09-03 21:25:36 +00:00
|
|
|
#endif
|
1998-09-14 18:27:06 +00:00
|
|
|
|
2001-09-11 01:09:24 +00:00
|
|
|
static STAILQ_HEAD(, moduledir) moduledir_list = STAILQ_HEAD_INITIALIZER(moduledir_list);
|
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
struct preloaded_file *preloaded_files = NULL;
|
1998-08-21 03:17:42 +00:00
|
|
|
|
2001-09-11 01:09:24 +00:00
|
|
|
static char *kld_ext_list[] = {
|
|
|
|
".ko",
|
|
|
|
"",
|
2007-10-04 18:29:52 +00:00
|
|
|
".debug",
|
2001-09-11 01:09:24 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1998-09-03 02:10:09 +00:00
|
|
|
/*
|
|
|
|
* load an object, either a disk file or code module.
|
|
|
|
*
|
|
|
|
* To load a file, the syntax is:
|
|
|
|
*
|
|
|
|
* load -t <type> <path>
|
|
|
|
*
|
|
|
|
* code modules are loaded as:
|
|
|
|
*
|
|
|
|
* load <path> <options>
|
|
|
|
*/
|
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
COMMAND_SET(load, "load", "load a kernel or module", command_load);
|
|
|
|
|
|
|
|
static int
|
|
|
|
command_load(int argc, char *argv[])
|
|
|
|
{
|
2015-08-03 16:27:36 +00:00
|
|
|
struct preloaded_file *fp;
|
1998-09-03 02:10:09 +00:00
|
|
|
char *typestr;
|
2001-09-11 01:09:24 +00:00
|
|
|
int dofile, dokld, ch, error;
|
2016-05-12 01:19:11 +00:00
|
|
|
|
2001-09-11 01:09:24 +00:00
|
|
|
dokld = dofile = 0;
|
1998-09-03 02:10:09 +00:00
|
|
|
optind = 1;
|
1999-01-11 06:41:32 +00:00
|
|
|
optreset = 1;
|
1998-09-03 02:10:09 +00:00
|
|
|
typestr = NULL;
|
1999-12-01 18:30:26 +00:00
|
|
|
if (argc == 1) {
|
|
|
|
command_errmsg = "no filename specified";
|
2016-01-13 18:33:12 +00:00
|
|
|
return (CMD_CRIT);
|
1999-12-01 18:30:26 +00:00
|
|
|
}
|
2001-09-11 01:09:24 +00:00
|
|
|
while ((ch = getopt(argc, argv, "kt:")) != -1) {
|
1998-09-03 02:10:09 +00:00
|
|
|
switch(ch) {
|
2001-09-11 01:09:24 +00:00
|
|
|
case 'k':
|
|
|
|
dokld = 1;
|
|
|
|
break;
|
1998-09-03 02:10:09 +00:00
|
|
|
case 't':
|
|
|
|
typestr = optarg;
|
|
|
|
dofile = 1;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
/* getopt has already reported an error */
|
2016-01-13 18:33:12 +00:00
|
|
|
return (CMD_OK);
|
1998-09-03 02:10:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
argv += (optind - 1);
|
|
|
|
argc -= (optind - 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Request to load a raw file?
|
|
|
|
*/
|
|
|
|
if (dofile) {
|
2001-06-10 11:15:37 +00:00
|
|
|
if ((argc != 2) || (typestr == NULL) || (*typestr == 0)) {
|
1998-09-03 02:10:09 +00:00
|
|
|
command_errmsg = "invalid load type";
|
2016-01-13 18:33:12 +00:00
|
|
|
return (CMD_CRIT);
|
1998-09-03 02:10:09 +00:00
|
|
|
}
|
2015-08-03 16:27:36 +00:00
|
|
|
|
|
|
|
fp = file_findfile(argv[1], typestr);
|
|
|
|
if (fp) {
|
2016-08-20 16:23:19 +00:00
|
|
|
snprintf(command_errbuf, sizeof(command_errbuf),
|
|
|
|
"warning: file '%s' already loaded", argv[1]);
|
2016-01-13 18:33:12 +00:00
|
|
|
return (CMD_WARN);
|
2015-08-03 16:27:36 +00:00
|
|
|
}
|
|
|
|
|
2016-01-13 18:33:12 +00:00
|
|
|
if (file_loadraw(argv[1], typestr, 1) != NULL)
|
|
|
|
return (CMD_OK);
|
|
|
|
|
|
|
|
/* Failing to load mfs_root is never going to end well! */
|
|
|
|
if (strcmp("mfs_root", typestr) == 0)
|
|
|
|
return (CMD_FATAL);
|
|
|
|
|
|
|
|
return (CMD_ERROR);
|
1998-09-03 02:10:09 +00:00
|
|
|
}
|
2001-09-11 01:09:24 +00:00
|
|
|
/*
|
|
|
|
* Do we have explicit KLD load ?
|
|
|
|
*/
|
|
|
|
if (dokld || file_havepath(argv[1])) {
|
|
|
|
error = mod_loadkld(argv[1], argc - 2, argv + 2);
|
2016-01-13 18:33:12 +00:00
|
|
|
if (error == EEXIST) {
|
2016-08-20 16:23:19 +00:00
|
|
|
snprintf(command_errbuf, sizeof(command_errbuf),
|
|
|
|
"warning: KLD '%s' already loaded", argv[1]);
|
2016-01-13 18:33:12 +00:00
|
|
|
return (CMD_WARN);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error == 0 ? CMD_OK : CMD_CRIT);
|
2001-09-11 01:09:24 +00:00
|
|
|
}
|
1998-09-03 02:10:09 +00:00
|
|
|
/*
|
|
|
|
* Looks like a request for a module.
|
|
|
|
*/
|
2001-09-11 01:09:24 +00:00
|
|
|
error = mod_load(argv[1], NULL, argc - 2, argv + 2);
|
2016-01-13 18:33:12 +00:00
|
|
|
if (error == EEXIST) {
|
2016-08-20 16:23:19 +00:00
|
|
|
snprintf(command_errbuf, sizeof(command_errbuf),
|
|
|
|
"warning: module '%s' already loaded", argv[1]);
|
2016-01-13 18:33:12 +00:00
|
|
|
return (CMD_WARN);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error == 0 ? CMD_OK : CMD_CRIT);
|
1998-08-21 03:17:42 +00:00
|
|
|
}
|
|
|
|
|
2009-02-16 02:42:17 +00:00
|
|
|
COMMAND_SET(load_geli, "load_geli", "load a geli key", command_load_geli);
|
|
|
|
|
|
|
|
static int
|
|
|
|
command_load_geli(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char typestr[80];
|
|
|
|
char *cp;
|
|
|
|
int ch, num;
|
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
command_errmsg = "usage is [-n key#] <prov> <file>";
|
|
|
|
return(CMD_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
num = 0;
|
|
|
|
optind = 1;
|
|
|
|
optreset = 1;
|
|
|
|
while ((ch = getopt(argc, argv, "n:")) != -1) {
|
|
|
|
switch(ch) {
|
|
|
|
case 'n':
|
|
|
|
num = strtol(optarg, &cp, 0);
|
|
|
|
if (cp == optarg) {
|
2016-08-20 16:23:19 +00:00
|
|
|
snprintf(command_errbuf, sizeof(command_errbuf),
|
|
|
|
"bad key index '%s'", optarg);
|
2009-02-16 02:42:17 +00:00
|
|
|
return(CMD_ERROR);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
/* getopt has already reported an error */
|
|
|
|
return(CMD_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argv += (optind - 1);
|
|
|
|
argc -= (optind - 1);
|
|
|
|
sprintf(typestr, "%s:geli_keyfile%d", argv[1], num);
|
loader: implement multiboot support for Xen Dom0
Implement a subset of the multiboot specification in order to boot Xen
and a FreeBSD Dom0 from the FreeBSD bootloader. This multiboot
implementation is tailored to boot Xen and FreeBSD Dom0, and it will
most surely fail to boot any other multiboot compilant kernel.
In order to detect and boot the Xen microkernel, two new file formats
are added to the bootloader, multiboot and multiboot_obj. Multiboot
support must be tested before regular ELF support, since Xen is a
multiboot kernel that also uses ELF. After a multiboot kernel is
detected, all the other loaded kernels/modules are parsed by the
multiboot_obj format.
The layout of the loaded objects in memory is the following; first the
Xen kernel is loaded as a 32bit ELF into memory (Xen will switch to
long mode by itself), after that the FreeBSD kernel is loaded as a RAW
file (Xen will parse and load it using it's internal ELF loader), and
finally the metadata and the modules are loaded using the native
FreeBSD way. After everything is loaded we jump into Xen's entry point
using a small trampoline. The order of the multiboot modules passed to
Xen is the following, the first module is the RAW FreeBSD kernel, and
the second module is the metadata and the FreeBSD modules.
Since Xen will relocate the memory position of the second
multiboot module (the one that contains the metadata and native
FreeBSD modules), we need to stash the original modulep address inside
of the metadata itself in order to recalculate its position once
booted. This also means the metadata must come before the loaded
modules, so after loading the FreeBSD kernel a portion of memory is
reserved in order to place the metadata before booting.
In order to tell the loader to boot Xen and then the FreeBSD kernel the
following has to be added to the /boot/loader.conf file:
xen_cmdline="dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga"
xen_kernel="/boot/xen"
The first argument contains the command line that will be passed to the Xen
kernel, while the second argument is the path to the Xen kernel itself. This
can also be done manually from the loader command line, by for example
typing the following set of commands:
OK unload
OK load /boot/xen dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga
OK load kernel
OK load zfs
OK load if_tap
OK load ...
OK boot
Sponsored by: Citrix Systems R&D
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D517
For the Forth bits:
Submitted by: Julien Grall <julien.grall AT citrix.com>
2015-01-15 16:27:20 +00:00
|
|
|
return (file_loadraw(argv[2], typestr, 1) ? CMD_OK : CMD_ERROR);
|
2009-02-16 02:42:17 +00:00
|
|
|
}
|
|
|
|
|
2014-08-06 00:06:25 +00:00
|
|
|
void
|
|
|
|
unload(void)
|
1998-08-31 21:10:43 +00:00
|
|
|
{
|
2014-08-06 00:06:25 +00:00
|
|
|
struct preloaded_file *fp;
|
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
while (preloaded_files != NULL) {
|
|
|
|
fp = preloaded_files;
|
|
|
|
preloaded_files = preloaded_files->f_next;
|
|
|
|
file_discard(fp);
|
1998-08-31 21:10:43 +00:00
|
|
|
}
|
|
|
|
loadaddr = 0;
|
2000-09-08 16:47:05 +00:00
|
|
|
unsetenv("kernelname");
|
2014-08-06 00:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
COMMAND_SET(unload, "unload", "unload all modules", command_unload);
|
|
|
|
|
|
|
|
static int
|
|
|
|
command_unload(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
unload();
|
1998-08-31 21:10:43 +00:00
|
|
|
return(CMD_OK);
|
|
|
|
}
|
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
COMMAND_SET(lsmod, "lsmod", "list loaded modules", command_lsmod);
|
|
|
|
|
|
|
|
static int
|
|
|
|
command_lsmod(int argc, char *argv[])
|
|
|
|
{
|
2000-05-01 17:41:25 +00:00
|
|
|
struct preloaded_file *fp;
|
|
|
|
struct kernel_module *mp;
|
|
|
|
struct file_metadata *md;
|
1998-08-21 03:17:42 +00:00
|
|
|
char lbuf[80];
|
2016-11-08 06:50:18 +00:00
|
|
|
int ch, verbose, ret = 0;
|
1998-09-03 02:10:09 +00:00
|
|
|
|
|
|
|
verbose = 0;
|
|
|
|
optind = 1;
|
1999-01-11 06:41:32 +00:00
|
|
|
optreset = 1;
|
1998-09-03 02:10:09 +00:00
|
|
|
while ((ch = getopt(argc, argv, "v")) != -1) {
|
|
|
|
switch(ch) {
|
|
|
|
case 'v':
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
/* getopt has already reported an error */
|
|
|
|
return(CMD_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
pager_open();
|
2000-05-01 17:41:25 +00:00
|
|
|
for (fp = preloaded_files; fp; fp = fp->f_next) {
|
2016-11-08 06:50:18 +00:00
|
|
|
snprintf(lbuf, sizeof(lbuf), " %p: ", (void *) fp->f_addr);
|
2014-08-05 23:55:23 +00:00
|
|
|
pager_output(lbuf);
|
|
|
|
pager_output(fp->f_name);
|
2016-11-08 06:50:18 +00:00
|
|
|
snprintf(lbuf, sizeof(lbuf), " (%s, 0x%lx)\n", fp->f_type,
|
|
|
|
(long)fp->f_size);
|
|
|
|
if (pager_output(lbuf))
|
|
|
|
break;
|
2000-05-01 17:41:25 +00:00
|
|
|
if (fp->f_args != NULL) {
|
1998-08-21 03:17:42 +00:00
|
|
|
pager_output(" args: ");
|
2000-05-01 17:41:25 +00:00
|
|
|
pager_output(fp->f_args);
|
2016-05-18 05:59:05 +00:00
|
|
|
if (pager_output("\n"))
|
|
|
|
break;
|
1998-08-21 03:17:42 +00:00
|
|
|
}
|
2000-05-01 17:41:25 +00:00
|
|
|
if (fp->f_modules) {
|
|
|
|
pager_output(" modules: ");
|
|
|
|
for (mp = fp->f_modules; mp; mp = mp->m_next) {
|
2016-11-08 06:50:18 +00:00
|
|
|
snprintf(lbuf, sizeof(lbuf), "%s.%d ", mp->m_name,
|
|
|
|
mp->m_version);
|
2000-05-01 17:41:25 +00:00
|
|
|
pager_output(lbuf);
|
|
|
|
}
|
2016-05-18 05:59:05 +00:00
|
|
|
if (pager_output("\n"))
|
|
|
|
break;
|
|
|
|
}
|
2000-05-01 17:41:25 +00:00
|
|
|
if (verbose) {
|
1998-09-03 02:10:09 +00:00
|
|
|
/* XXX could add some formatting smarts here to display some better */
|
2000-05-01 17:41:25 +00:00
|
|
|
for (md = fp->f_metadata; md != NULL; md = md->md_next) {
|
2016-11-08 06:50:18 +00:00
|
|
|
snprintf(lbuf, sizeof(lbuf), " 0x%04x, 0x%lx\n",
|
|
|
|
md->md_type, (long) md->md_size);
|
2016-05-18 05:59:05 +00:00
|
|
|
if (pager_output(lbuf))
|
|
|
|
break;
|
1998-09-03 02:10:09 +00:00
|
|
|
}
|
2000-05-01 17:41:25 +00:00
|
|
|
}
|
2016-11-08 06:50:18 +00:00
|
|
|
if (ret)
|
|
|
|
break;
|
1998-08-21 03:17:42 +00:00
|
|
|
}
|
|
|
|
pager_close();
|
|
|
|
return(CMD_OK);
|
|
|
|
}
|
|
|
|
|
1998-09-03 02:10:09 +00:00
|
|
|
/*
|
2000-05-01 17:41:25 +00:00
|
|
|
* File level interface, functions file_*
|
1998-09-03 02:10:09 +00:00
|
|
|
*/
|
1998-08-21 03:17:42 +00:00
|
|
|
int
|
2000-05-01 17:41:25 +00:00
|
|
|
file_load(char *filename, vm_offset_t dest, struct preloaded_file **result)
|
1998-08-21 03:17:42 +00:00
|
|
|
{
|
2012-09-30 13:14:37 +00:00
|
|
|
static int last_file_format = 0;
|
2000-05-01 17:41:25 +00:00
|
|
|
struct preloaded_file *fp;
|
|
|
|
int error;
|
|
|
|
int i;
|
|
|
|
|
2011-04-03 22:31:51 +00:00
|
|
|
if (archsw.arch_loadaddr != NULL)
|
|
|
|
dest = archsw.arch_loadaddr(LOAD_RAW, filename, dest);
|
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
error = EFTYPE;
|
2012-09-30 13:14:37 +00:00
|
|
|
for (i = last_file_format, fp = NULL;
|
|
|
|
file_formats[i] && fp == NULL; i++) {
|
2011-04-04 16:59:46 +00:00
|
|
|
error = (file_formats[i]->l_load)(filename, dest, &fp);
|
2000-05-01 17:41:25 +00:00
|
|
|
if (error == 0) {
|
2012-09-30 13:14:37 +00:00
|
|
|
fp->f_loader = last_file_format = i; /* remember the loader */
|
2000-05-01 17:41:25 +00:00
|
|
|
*result = fp;
|
|
|
|
break;
|
2012-09-30 13:14:37 +00:00
|
|
|
} else if (last_file_format == i && i != 0) {
|
2012-09-30 13:17:33 +00:00
|
|
|
/* Restart from the beginning */
|
2013-04-21 09:10:35 +00:00
|
|
|
i = -1;
|
|
|
|
last_file_format = 0;
|
2012-09-30 13:17:33 +00:00
|
|
|
fp = NULL;
|
|
|
|
continue;
|
2000-05-01 17:41:25 +00:00
|
|
|
}
|
|
|
|
if (error == EFTYPE)
|
|
|
|
continue; /* Unknown to this handler? */
|
|
|
|
if (error) {
|
2016-08-20 16:23:19 +00:00
|
|
|
snprintf(command_errbuf, sizeof(command_errbuf),
|
|
|
|
"can't load file '%s': %s", filename, strerror(error));
|
2000-05-01 17:41:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
1998-09-03 02:10:09 +00:00
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
static int
|
2010-05-10 18:23:00 +00:00
|
|
|
file_load_dependencies(struct preloaded_file *base_file)
|
|
|
|
{
|
2000-05-01 17:41:25 +00:00
|
|
|
struct file_metadata *md;
|
|
|
|
struct preloaded_file *fp;
|
2001-09-11 01:09:24 +00:00
|
|
|
struct mod_depend *verinfo;
|
|
|
|
struct kernel_module *mp;
|
2000-05-01 17:41:25 +00:00
|
|
|
char *dmodname;
|
|
|
|
int error;
|
2000-02-25 05:10:44 +00:00
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
md = file_findmetadata(base_file, MODINFOMD_DEPLIST);
|
|
|
|
if (md == NULL)
|
|
|
|
return (0);
|
|
|
|
error = 0;
|
|
|
|
do {
|
2001-09-11 01:09:24 +00:00
|
|
|
verinfo = (struct mod_depend*)md->md_data;
|
|
|
|
dmodname = (char *)(verinfo + 1);
|
|
|
|
if (file_findmodule(NULL, dmodname, verinfo) == NULL) {
|
2000-05-01 17:41:25 +00:00
|
|
|
printf("loading required module '%s'\n", dmodname);
|
2001-09-11 01:09:24 +00:00
|
|
|
error = mod_load(dmodname, verinfo, 0, NULL);
|
2000-05-01 17:41:25 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
2001-09-11 01:09:24 +00:00
|
|
|
/*
|
|
|
|
* If module loaded via kld name which isn't listed
|
|
|
|
* in the linker.hints file, we should check if it have
|
|
|
|
* required version.
|
|
|
|
*/
|
|
|
|
mp = file_findmodule(NULL, dmodname, verinfo);
|
|
|
|
if (mp == NULL) {
|
2016-08-20 16:23:19 +00:00
|
|
|
snprintf(command_errbuf, sizeof(command_errbuf),
|
|
|
|
"module '%s' exists but with wrong version", dmodname);
|
2001-09-11 01:09:24 +00:00
|
|
|
error = ENOENT;
|
|
|
|
break;
|
|
|
|
}
|
2000-05-01 17:41:25 +00:00
|
|
|
}
|
|
|
|
md = metadata_next(md, MODINFOMD_DEPLIST);
|
|
|
|
} while (md);
|
2000-02-25 05:10:44 +00:00
|
|
|
if (!error)
|
|
|
|
return (0);
|
|
|
|
/* Load failed; discard everything */
|
2000-05-01 17:41:25 +00:00
|
|
|
while (base_file != NULL) {
|
|
|
|
fp = base_file;
|
|
|
|
base_file = base_file->f_next;
|
|
|
|
file_discard(fp);
|
1998-09-03 02:10:09 +00:00
|
|
|
}
|
2000-02-25 05:10:44 +00:00
|
|
|
return (error);
|
1998-09-03 02:10:09 +00:00
|
|
|
}
|
2013-02-18 23:13:13 +00:00
|
|
|
|
1998-09-03 02:10:09 +00:00
|
|
|
/*
|
2016-01-15 00:55:36 +00:00
|
|
|
* We've been asked to load (fname) as (type), so just suck it in,
|
1998-09-03 02:10:09 +00:00
|
|
|
* no arguments or anything.
|
|
|
|
*/
|
2014-02-22 22:03:26 +00:00
|
|
|
struct preloaded_file *
|
2016-01-15 00:55:36 +00:00
|
|
|
file_loadraw(const char *fname, char *type, int insert)
|
1998-09-03 02:10:09 +00:00
|
|
|
{
|
2000-05-01 17:41:25 +00:00
|
|
|
struct preloaded_file *fp;
|
2016-01-15 00:55:36 +00:00
|
|
|
char *name;
|
1998-09-03 02:10:09 +00:00
|
|
|
int fd, got;
|
|
|
|
vm_offset_t laddr;
|
|
|
|
|
|
|
|
/* We can't load first */
|
2000-05-01 17:41:25 +00:00
|
|
|
if ((file_findfile(NULL, NULL)) == NULL) {
|
1998-09-03 02:10:09 +00:00
|
|
|
command_errmsg = "can't load file before kernel";
|
2014-02-22 22:03:26 +00:00
|
|
|
return(NULL);
|
1998-09-03 02:10:09 +00:00
|
|
|
}
|
|
|
|
|
1998-09-14 18:27:06 +00:00
|
|
|
/* locate the file on the load path */
|
2016-01-15 00:55:36 +00:00
|
|
|
name = file_search(fname, NULL);
|
|
|
|
if (name == NULL) {
|
2016-08-20 16:23:19 +00:00
|
|
|
snprintf(command_errbuf, sizeof(command_errbuf),
|
|
|
|
"can't find '%s'", fname);
|
2014-02-22 22:03:26 +00:00
|
|
|
return(NULL);
|
1998-09-14 18:27:06 +00:00
|
|
|
}
|
2011-04-03 22:31:51 +00:00
|
|
|
|
1998-09-03 02:10:09 +00:00
|
|
|
if ((fd = open(name, O_RDONLY)) < 0) {
|
2016-08-20 16:23:19 +00:00
|
|
|
snprintf(command_errbuf, sizeof(command_errbuf),
|
|
|
|
"can't open '%s': %s", name, strerror(errno));
|
1999-03-08 10:32:39 +00:00
|
|
|
free(name);
|
2014-02-22 22:03:26 +00:00
|
|
|
return(NULL);
|
1998-09-03 02:10:09 +00:00
|
|
|
}
|
|
|
|
|
2011-04-03 22:31:51 +00:00
|
|
|
if (archsw.arch_loadaddr != NULL)
|
|
|
|
loadaddr = archsw.arch_loadaddr(LOAD_RAW, name, loadaddr);
|
2009-12-31 12:17:38 +00:00
|
|
|
|
2014-08-05 23:41:40 +00:00
|
|
|
printf("%s ", name);
|
|
|
|
|
1998-09-03 02:10:09 +00:00
|
|
|
laddr = loadaddr;
|
|
|
|
for (;;) {
|
|
|
|
/* read in 4k chunks; size is not really important */
|
|
|
|
got = archsw.arch_readin(fd, laddr, 4096);
|
|
|
|
if (got == 0) /* end of file */
|
|
|
|
break;
|
|
|
|
if (got < 0) { /* error */
|
2016-08-20 16:23:19 +00:00
|
|
|
snprintf(command_errbuf, sizeof(command_errbuf),
|
|
|
|
"error reading '%s': %s", name, strerror(errno));
|
1999-02-22 13:12:37 +00:00
|
|
|
free(name);
|
2000-02-17 02:19:19 +00:00
|
|
|
close(fd);
|
2014-02-22 22:03:26 +00:00
|
|
|
return(NULL);
|
1998-09-03 02:10:09 +00:00
|
|
|
}
|
|
|
|
laddr += got;
|
|
|
|
}
|
2014-08-05 23:41:40 +00:00
|
|
|
|
|
|
|
printf("size=%#jx\n", (uintmax_t)(laddr - loadaddr));
|
|
|
|
|
1998-09-03 02:10:09 +00:00
|
|
|
/* Looks OK so far; create & populate control structure */
|
2000-05-01 17:41:25 +00:00
|
|
|
fp = file_alloc();
|
2012-09-11 06:18:36 +00:00
|
|
|
fp->f_name = strdup(name);
|
2000-05-01 17:41:25 +00:00
|
|
|
fp->f_type = strdup(type);
|
|
|
|
fp->f_args = NULL;
|
|
|
|
fp->f_metadata = NULL;
|
|
|
|
fp->f_loader = -1;
|
|
|
|
fp->f_addr = loadaddr;
|
|
|
|
fp->f_size = laddr - loadaddr;
|
1998-09-03 02:10:09 +00:00
|
|
|
|
|
|
|
/* recognise space consumption */
|
|
|
|
loadaddr = laddr;
|
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
/* Add to the list of loaded files */
|
loader: implement multiboot support for Xen Dom0
Implement a subset of the multiboot specification in order to boot Xen
and a FreeBSD Dom0 from the FreeBSD bootloader. This multiboot
implementation is tailored to boot Xen and FreeBSD Dom0, and it will
most surely fail to boot any other multiboot compilant kernel.
In order to detect and boot the Xen microkernel, two new file formats
are added to the bootloader, multiboot and multiboot_obj. Multiboot
support must be tested before regular ELF support, since Xen is a
multiboot kernel that also uses ELF. After a multiboot kernel is
detected, all the other loaded kernels/modules are parsed by the
multiboot_obj format.
The layout of the loaded objects in memory is the following; first the
Xen kernel is loaded as a 32bit ELF into memory (Xen will switch to
long mode by itself), after that the FreeBSD kernel is loaded as a RAW
file (Xen will parse and load it using it's internal ELF loader), and
finally the metadata and the modules are loaded using the native
FreeBSD way. After everything is loaded we jump into Xen's entry point
using a small trampoline. The order of the multiboot modules passed to
Xen is the following, the first module is the RAW FreeBSD kernel, and
the second module is the metadata and the FreeBSD modules.
Since Xen will relocate the memory position of the second
multiboot module (the one that contains the metadata and native
FreeBSD modules), we need to stash the original modulep address inside
of the metadata itself in order to recalculate its position once
booted. This also means the metadata must come before the loaded
modules, so after loading the FreeBSD kernel a portion of memory is
reserved in order to place the metadata before booting.
In order to tell the loader to boot Xen and then the FreeBSD kernel the
following has to be added to the /boot/loader.conf file:
xen_cmdline="dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga"
xen_kernel="/boot/xen"
The first argument contains the command line that will be passed to the Xen
kernel, while the second argument is the path to the Xen kernel itself. This
can also be done manually from the loader command line, by for example
typing the following set of commands:
OK unload
OK load /boot/xen dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga
OK load kernel
OK load zfs
OK load if_tap
OK load ...
OK boot
Sponsored by: Citrix Systems R&D
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D517
For the Forth bits:
Submitted by: Julien Grall <julien.grall AT citrix.com>
2015-01-15 16:27:20 +00:00
|
|
|
if (insert != 0)
|
|
|
|
file_insert_tail(fp);
|
2000-02-17 02:19:19 +00:00
|
|
|
close(fd);
|
2014-02-22 22:03:26 +00:00
|
|
|
return(fp);
|
1998-09-03 02:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-05-01 17:41:25 +00:00
|
|
|
* Load the module (name), pass it (argc),(argv), add container file
|
|
|
|
* to the list of loaded files.
|
|
|
|
* If module is already loaded just assign new argc/argv.
|
1998-09-03 02:10:09 +00:00
|
|
|
*/
|
2000-05-01 17:41:25 +00:00
|
|
|
int
|
2001-09-11 01:09:24 +00:00
|
|
|
mod_load(char *modname, struct mod_depend *verinfo, int argc, char *argv[])
|
1998-09-03 02:10:09 +00:00
|
|
|
{
|
2000-05-01 17:41:25 +00:00
|
|
|
struct kernel_module *mp;
|
|
|
|
int err;
|
|
|
|
char *filename;
|
1998-09-03 02:10:09 +00:00
|
|
|
|
2001-09-11 01:09:24 +00:00
|
|
|
if (file_havepath(modname)) {
|
|
|
|
printf("Warning: mod_load() called instead of mod_loadkld() for module '%s'\n", modname);
|
|
|
|
return (mod_loadkld(modname, argc, argv));
|
|
|
|
}
|
2000-02-25 05:10:44 +00:00
|
|
|
/* see if module is already loaded */
|
2001-09-11 01:09:24 +00:00
|
|
|
mp = file_findmodule(NULL, modname, verinfo);
|
2000-02-25 05:10:44 +00:00
|
|
|
if (mp) {
|
2000-05-01 17:41:25 +00:00
|
|
|
#ifdef moduleargs
|
|
|
|
if (mp->m_args)
|
|
|
|
free(mp->m_args);
|
|
|
|
mp->m_args = unargv(argc, argv);
|
|
|
|
#endif
|
2016-08-20 16:23:19 +00:00
|
|
|
snprintf(command_errbuf, sizeof(command_errbuf),
|
|
|
|
"warning: module '%s' already loaded", mp->m_name);
|
2000-05-01 17:41:25 +00:00
|
|
|
return (0);
|
2000-02-25 05:10:44 +00:00
|
|
|
}
|
2000-05-01 17:41:25 +00:00
|
|
|
/* locate file with the module on the search path */
|
2001-09-11 01:09:24 +00:00
|
|
|
filename = mod_searchmodule(modname, verinfo);
|
2000-05-01 17:41:25 +00:00
|
|
|
if (filename == NULL) {
|
2016-08-20 16:23:19 +00:00
|
|
|
snprintf(command_errbuf, sizeof(command_errbuf),
|
|
|
|
"can't find '%s'", modname);
|
2000-05-01 17:41:25 +00:00
|
|
|
return (ENOENT);
|
|
|
|
}
|
2001-09-11 01:09:24 +00:00
|
|
|
err = mod_loadkld(filename, argc, argv);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load specified KLD. If path is omitted, then try to locate it via
|
|
|
|
* search path.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
mod_loadkld(const char *kldname, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct preloaded_file *fp, *last_file;
|
|
|
|
int err;
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get fully qualified KLD name
|
|
|
|
*/
|
|
|
|
filename = file_search(kldname, kld_ext_list);
|
|
|
|
if (filename == NULL) {
|
2016-08-20 16:23:19 +00:00
|
|
|
snprintf(command_errbuf, sizeof(command_errbuf),
|
|
|
|
"can't find '%s'", kldname);
|
2001-09-11 01:09:24 +00:00
|
|
|
return (ENOENT);
|
|
|
|
}
|
2016-05-12 01:19:11 +00:00
|
|
|
/*
|
2001-09-11 01:09:24 +00:00
|
|
|
* Check if KLD already loaded
|
|
|
|
*/
|
|
|
|
fp = file_findfile(filename, NULL);
|
|
|
|
if (fp) {
|
2016-08-20 16:23:19 +00:00
|
|
|
snprintf(command_errbuf, sizeof(command_errbuf),
|
|
|
|
"warning: KLD '%s' already loaded", filename);
|
2001-09-11 01:09:24 +00:00
|
|
|
free(filename);
|
|
|
|
return (0);
|
|
|
|
}
|
2016-05-12 01:19:11 +00:00
|
|
|
for (last_file = preloaded_files;
|
2000-05-01 17:41:25 +00:00
|
|
|
last_file != NULL && last_file->f_next != NULL;
|
|
|
|
last_file = last_file->f_next)
|
|
|
|
;
|
2000-02-25 05:10:44 +00:00
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
do {
|
|
|
|
err = file_load(filename, loadaddr, &fp);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
fp->f_args = unargv(argc, argv);
|
|
|
|
loadaddr = fp->f_addr + fp->f_size;
|
|
|
|
file_insert_tail(fp); /* Add to the list of loaded files */
|
2001-11-16 21:08:40 +00:00
|
|
|
if (file_load_dependencies(fp) != 0) {
|
2000-05-01 17:41:25 +00:00
|
|
|
err = ENOENT;
|
|
|
|
last_file->f_next = NULL;
|
|
|
|
loadaddr = last_file->f_addr + last_file->f_size;
|
|
|
|
fp = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while(0);
|
2016-08-20 16:23:19 +00:00
|
|
|
if (err == EFTYPE) {
|
|
|
|
snprintf(command_errbuf, sizeof(command_errbuf),
|
|
|
|
"don't know how to load module '%s'", filename);
|
|
|
|
}
|
2000-05-01 17:41:25 +00:00
|
|
|
if (err && fp)
|
|
|
|
file_discard(fp);
|
|
|
|
free(filename);
|
2000-02-25 05:10:44 +00:00
|
|
|
return (err);
|
1998-09-03 02:10:09 +00:00
|
|
|
}
|
1998-08-21 03:17:42 +00:00
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
/*
|
|
|
|
* Find a file matching (name) and (type).
|
|
|
|
* NULL may be passed as a wildcard to either.
|
|
|
|
*/
|
|
|
|
struct preloaded_file *
|
loader: implement multiboot support for Xen Dom0
Implement a subset of the multiboot specification in order to boot Xen
and a FreeBSD Dom0 from the FreeBSD bootloader. This multiboot
implementation is tailored to boot Xen and FreeBSD Dom0, and it will
most surely fail to boot any other multiboot compilant kernel.
In order to detect and boot the Xen microkernel, two new file formats
are added to the bootloader, multiboot and multiboot_obj. Multiboot
support must be tested before regular ELF support, since Xen is a
multiboot kernel that also uses ELF. After a multiboot kernel is
detected, all the other loaded kernels/modules are parsed by the
multiboot_obj format.
The layout of the loaded objects in memory is the following; first the
Xen kernel is loaded as a 32bit ELF into memory (Xen will switch to
long mode by itself), after that the FreeBSD kernel is loaded as a RAW
file (Xen will parse and load it using it's internal ELF loader), and
finally the metadata and the modules are loaded using the native
FreeBSD way. After everything is loaded we jump into Xen's entry point
using a small trampoline. The order of the multiboot modules passed to
Xen is the following, the first module is the RAW FreeBSD kernel, and
the second module is the metadata and the FreeBSD modules.
Since Xen will relocate the memory position of the second
multiboot module (the one that contains the metadata and native
FreeBSD modules), we need to stash the original modulep address inside
of the metadata itself in order to recalculate its position once
booted. This also means the metadata must come before the loaded
modules, so after loading the FreeBSD kernel a portion of memory is
reserved in order to place the metadata before booting.
In order to tell the loader to boot Xen and then the FreeBSD kernel the
following has to be added to the /boot/loader.conf file:
xen_cmdline="dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga"
xen_kernel="/boot/xen"
The first argument contains the command line that will be passed to the Xen
kernel, while the second argument is the path to the Xen kernel itself. This
can also be done manually from the loader command line, by for example
typing the following set of commands:
OK unload
OK load /boot/xen dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga
OK load kernel
OK load zfs
OK load if_tap
OK load ...
OK boot
Sponsored by: Citrix Systems R&D
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D517
For the Forth bits:
Submitted by: Julien Grall <julien.grall AT citrix.com>
2015-01-15 16:27:20 +00:00
|
|
|
file_findfile(const char *name, const char *type)
|
1998-09-03 02:10:09 +00:00
|
|
|
{
|
2000-05-01 17:41:25 +00:00
|
|
|
struct preloaded_file *fp;
|
2000-02-25 05:10:44 +00:00
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
for (fp = preloaded_files; fp != NULL; fp = fp->f_next) {
|
|
|
|
if (((name == NULL) || !strcmp(name, fp->f_name)) &&
|
|
|
|
((type == NULL) || !strcmp(type, fp->f_type)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (fp);
|
1998-08-21 03:17:42 +00:00
|
|
|
}
|
|
|
|
|
1998-09-03 02:10:09 +00:00
|
|
|
/*
|
2000-05-01 17:41:25 +00:00
|
|
|
* Find a module matching (name) inside of given file.
|
|
|
|
* NULL may be passed as a wildcard.
|
1998-09-03 02:10:09 +00:00
|
|
|
*/
|
2000-05-01 17:41:25 +00:00
|
|
|
struct kernel_module *
|
2001-09-11 01:09:24 +00:00
|
|
|
file_findmodule(struct preloaded_file *fp, char *modname,
|
|
|
|
struct mod_depend *verinfo)
|
1998-08-21 03:17:42 +00:00
|
|
|
{
|
2001-09-11 01:09:24 +00:00
|
|
|
struct kernel_module *mp, *best;
|
|
|
|
int bestver, mver;
|
2000-05-01 17:41:25 +00:00
|
|
|
|
|
|
|
if (fp == NULL) {
|
|
|
|
for (fp = preloaded_files; fp; fp = fp->f_next) {
|
2001-09-11 01:09:24 +00:00
|
|
|
mp = file_findmodule(fp, modname, verinfo);
|
2016-05-12 01:19:11 +00:00
|
|
|
if (mp)
|
2001-09-11 01:09:24 +00:00
|
|
|
return (mp);
|
2000-05-01 17:41:25 +00:00
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
2001-09-11 01:09:24 +00:00
|
|
|
best = NULL;
|
|
|
|
bestver = 0;
|
2000-05-01 17:41:25 +00:00
|
|
|
for (mp = fp->f_modules; mp; mp = mp->m_next) {
|
2001-09-11 01:09:24 +00:00
|
|
|
if (strcmp(modname, mp->m_name) == 0) {
|
|
|
|
if (verinfo == NULL)
|
|
|
|
return (mp);
|
|
|
|
mver = mp->m_version;
|
|
|
|
if (mver == verinfo->md_ver_preferred)
|
|
|
|
return (mp);
|
2016-05-12 01:19:11 +00:00
|
|
|
if (mver >= verinfo->md_ver_minimum &&
|
2001-09-11 01:09:24 +00:00
|
|
|
mver <= verinfo->md_ver_maximum &&
|
|
|
|
mver > bestver) {
|
|
|
|
best = mp;
|
|
|
|
bestver = mver;
|
|
|
|
}
|
|
|
|
}
|
1998-08-21 03:17:42 +00:00
|
|
|
}
|
2001-09-11 01:09:24 +00:00
|
|
|
return (best);
|
1998-08-21 03:17:42 +00:00
|
|
|
}
|
1998-09-03 02:10:09 +00:00
|
|
|
/*
|
|
|
|
* Make a copy of (size) bytes of data from (p), and associate them as
|
|
|
|
* metadata of (type) to the module (mp).
|
|
|
|
*/
|
1998-08-31 21:10:43 +00:00
|
|
|
void
|
2000-05-01 17:41:25 +00:00
|
|
|
file_addmetadata(struct preloaded_file *fp, int type, size_t size, void *p)
|
1998-08-31 21:10:43 +00:00
|
|
|
{
|
2000-05-01 17:41:25 +00:00
|
|
|
struct file_metadata *md;
|
1998-08-31 21:10:43 +00:00
|
|
|
|
2000-08-03 09:14:02 +00:00
|
|
|
md = malloc(sizeof(struct file_metadata) - sizeof(md->md_data) + size);
|
1998-08-31 21:10:43 +00:00
|
|
|
md->md_size = size;
|
|
|
|
md->md_type = type;
|
|
|
|
bcopy(p, md->md_data, size);
|
2000-05-01 17:41:25 +00:00
|
|
|
md->md_next = fp->f_metadata;
|
|
|
|
fp->f_metadata = md;
|
1998-08-31 21:10:43 +00:00
|
|
|
}
|
|
|
|
|
1998-09-03 02:10:09 +00:00
|
|
|
/*
|
2000-05-01 17:41:25 +00:00
|
|
|
* Find a metadata object of (type) associated with the file (fp)
|
1998-09-03 02:10:09 +00:00
|
|
|
*/
|
2000-05-01 17:41:25 +00:00
|
|
|
struct file_metadata *
|
|
|
|
file_findmetadata(struct preloaded_file *fp, int type)
|
1998-08-31 21:10:43 +00:00
|
|
|
{
|
2000-05-01 17:41:25 +00:00
|
|
|
struct file_metadata *md;
|
1998-08-31 21:10:43 +00:00
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
for (md = fp->f_metadata; md != NULL; md = md->md_next)
|
1998-08-31 21:10:43 +00:00
|
|
|
if (md->md_type == type)
|
|
|
|
break;
|
|
|
|
return(md);
|
|
|
|
}
|
1998-09-03 02:10:09 +00:00
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
struct file_metadata *
|
|
|
|
metadata_next(struct file_metadata *md, int type)
|
2000-02-25 05:10:44 +00:00
|
|
|
{
|
|
|
|
if (md == NULL)
|
|
|
|
return (NULL);
|
|
|
|
while((md = md->md_next) != NULL)
|
|
|
|
if (md->md_type == type)
|
|
|
|
break;
|
|
|
|
return (md);
|
|
|
|
}
|
|
|
|
|
2001-09-11 01:09:24 +00:00
|
|
|
static char *emptyextlist[] = { "", NULL };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the given file is in place and return full path to it.
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
file_lookup(const char *path, const char *name, int namelen, char **extlist)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
char *result, *cp, **cpp;
|
|
|
|
int pathlen, extlen, len;
|
|
|
|
|
|
|
|
pathlen = strlen(path);
|
|
|
|
extlen = 0;
|
|
|
|
if (extlist == NULL)
|
|
|
|
extlist = emptyextlist;
|
|
|
|
for (cpp = extlist; *cpp; cpp++) {
|
|
|
|
len = strlen(*cpp);
|
|
|
|
if (len > extlen)
|
|
|
|
extlen = len;
|
|
|
|
}
|
|
|
|
result = malloc(pathlen + namelen + extlen + 2);
|
|
|
|
if (result == NULL)
|
|
|
|
return (NULL);
|
|
|
|
bcopy(path, result, pathlen);
|
|
|
|
if (pathlen > 0 && result[pathlen - 1] != '/')
|
|
|
|
result[pathlen++] = '/';
|
|
|
|
cp = result + pathlen;
|
|
|
|
bcopy(name, cp, namelen);
|
|
|
|
cp += namelen;
|
|
|
|
for (cpp = extlist; *cpp; cpp++) {
|
|
|
|
strcpy(cp, *cpp);
|
|
|
|
if (stat(result, &st) == 0 && S_ISREG(st.st_mode))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
free(result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if file name have any qualifiers
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
file_havepath(const char *name)
|
|
|
|
{
|
|
|
|
const char *cp;
|
|
|
|
|
|
|
|
archsw.arch_getdev(NULL, name, &cp);
|
|
|
|
return (cp != name || strchr(name, '/') != NULL);
|
|
|
|
}
|
|
|
|
|
1998-09-03 02:10:09 +00:00
|
|
|
/*
|
1998-09-14 18:27:06 +00:00
|
|
|
* Attempt to find the file (name) on the module searchpath.
|
1998-09-03 02:10:09 +00:00
|
|
|
* If (name) is qualified in any way, we simply check it and
|
|
|
|
* return it or NULL. If it is not qualified, then we attempt
|
|
|
|
* to construct a path using entries in the environment variable
|
|
|
|
* module_path.
|
|
|
|
*
|
|
|
|
* The path we return a pointer to need never be freed, as we manage
|
|
|
|
* it internally.
|
|
|
|
*/
|
|
|
|
static char *
|
2001-09-11 01:09:24 +00:00
|
|
|
file_search(const char *name, char **extlist)
|
1998-09-03 02:10:09 +00:00
|
|
|
{
|
2001-09-11 01:09:24 +00:00
|
|
|
struct moduledir *mdp;
|
1998-09-03 02:10:09 +00:00
|
|
|
struct stat sb;
|
2001-09-11 01:09:24 +00:00
|
|
|
char *result;
|
|
|
|
int namelen;
|
1998-09-03 02:10:09 +00:00
|
|
|
|
|
|
|
/* Don't look for nothing */
|
1999-02-22 13:12:37 +00:00
|
|
|
if (name == NULL)
|
2001-09-11 01:09:24 +00:00
|
|
|
return(NULL);
|
1998-09-03 02:10:09 +00:00
|
|
|
|
1999-02-22 13:12:37 +00:00
|
|
|
if (*name == 0)
|
|
|
|
return(strdup(name));
|
|
|
|
|
2001-09-11 01:09:24 +00:00
|
|
|
if (file_havepath(name)) {
|
1998-09-03 02:10:09 +00:00
|
|
|
/* Qualified, so just see if it exists */
|
|
|
|
if (stat(name, &sb) == 0)
|
1999-02-22 13:12:37 +00:00
|
|
|
return(strdup(name));
|
1998-09-03 02:10:09 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
2001-09-11 01:09:24 +00:00
|
|
|
moduledir_rebuild();
|
1999-03-08 10:32:39 +00:00
|
|
|
result = NULL;
|
2001-09-11 01:09:24 +00:00
|
|
|
namelen = strlen(name);
|
|
|
|
STAILQ_FOREACH(mdp, &moduledir_list, d_link) {
|
|
|
|
result = file_lookup(mdp->d_path, name, namelen, extlist);
|
|
|
|
if (result)
|
1998-09-03 02:10:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2001-09-11 01:09:24 +00:00
|
|
|
#define INT_ALIGN(base, ptr) ptr = \
|
2016-04-21 19:57:40 +00:00
|
|
|
(base) + roundup2((ptr) - (base), sizeof(int))
|
2001-09-11 01:09:24 +00:00
|
|
|
|
|
|
|
static char *
|
|
|
|
mod_search_hints(struct moduledir *mdp, const char *modname,
|
|
|
|
struct mod_depend *verinfo)
|
|
|
|
{
|
|
|
|
u_char *cp, *recptr, *bufend, *best;
|
|
|
|
char *result;
|
|
|
|
int *intp, bestver, blen, clen, found, ival, modnamelen, reclen;
|
|
|
|
|
|
|
|
moduledir_readhints(mdp);
|
|
|
|
modnamelen = strlen(modname);
|
|
|
|
found = 0;
|
|
|
|
result = NULL;
|
|
|
|
bestver = 0;
|
|
|
|
if (mdp->d_hints == NULL)
|
|
|
|
goto bad;
|
|
|
|
recptr = mdp->d_hints;
|
|
|
|
bufend = recptr + mdp->d_hintsz;
|
|
|
|
clen = blen = 0;
|
|
|
|
best = cp = NULL;
|
|
|
|
while (recptr < bufend && !found) {
|
|
|
|
intp = (int*)recptr;
|
|
|
|
reclen = *intp++;
|
|
|
|
ival = *intp++;
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
cp = (u_char*)intp;
|
2001-09-11 01:09:24 +00:00
|
|
|
switch (ival) {
|
|
|
|
case MDT_VERSION:
|
|
|
|
clen = *cp++;
|
|
|
|
if (clen != modnamelen || bcmp(cp, modname, clen) != 0)
|
|
|
|
break;
|
|
|
|
cp += clen;
|
|
|
|
INT_ALIGN(mdp->d_hints, cp);
|
|
|
|
ival = *(int*)cp;
|
|
|
|
cp += sizeof(int);
|
|
|
|
clen = *cp++;
|
|
|
|
if (verinfo == NULL || ival == verinfo->md_ver_preferred) {
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
2016-05-12 01:19:11 +00:00
|
|
|
if (ival >= verinfo->md_ver_minimum &&
|
2001-09-11 01:09:24 +00:00
|
|
|
ival <= verinfo->md_ver_maximum &&
|
|
|
|
ival > bestver) {
|
|
|
|
bestver = ival;
|
|
|
|
best = cp;
|
|
|
|
blen = clen;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
recptr += reclen + sizeof(int);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Finally check if KLD is in the place
|
|
|
|
*/
|
|
|
|
if (found)
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
result = file_lookup(mdp->d_path, (const char *)cp, clen, NULL);
|
2001-09-11 01:09:24 +00:00
|
|
|
else if (best)
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
result = file_lookup(mdp->d_path, (const char *)best, blen, NULL);
|
2001-09-11 01:09:24 +00:00
|
|
|
bad:
|
|
|
|
/*
|
|
|
|
* If nothing found or hints is absent - fallback to the old way
|
|
|
|
* by using "kldname[.ko]" as module name.
|
|
|
|
*/
|
|
|
|
if (!found && !bestver && result == NULL)
|
|
|
|
result = file_lookup(mdp->d_path, modname, modnamelen, kld_ext_list);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-09-14 18:27:06 +00:00
|
|
|
/*
|
|
|
|
* Attempt to locate the file containing the module (name)
|
|
|
|
*/
|
|
|
|
static char *
|
2001-09-11 01:09:24 +00:00
|
|
|
mod_searchmodule(char *name, struct mod_depend *verinfo)
|
1998-09-14 18:27:06 +00:00
|
|
|
{
|
2001-09-11 01:09:24 +00:00
|
|
|
struct moduledir *mdp;
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
moduledir_rebuild();
|
|
|
|
/*
|
|
|
|
* Now we ready to lookup module in the given directories
|
|
|
|
*/
|
|
|
|
result = NULL;
|
|
|
|
STAILQ_FOREACH(mdp, &moduledir_list, d_link) {
|
|
|
|
result = mod_search_hints(mdp, name, verinfo);
|
|
|
|
if (result)
|
|
|
|
break;
|
|
|
|
}
|
1998-09-14 18:27:06 +00:00
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
int
|
2001-09-11 01:09:24 +00:00
|
|
|
file_addmodule(struct preloaded_file *fp, char *modname, int version,
|
2000-05-01 17:41:25 +00:00
|
|
|
struct kernel_module **newmp)
|
|
|
|
{
|
|
|
|
struct kernel_module *mp;
|
2001-09-11 01:09:24 +00:00
|
|
|
struct mod_depend mdepend;
|
2000-05-01 17:41:25 +00:00
|
|
|
|
2001-09-11 01:09:24 +00:00
|
|
|
bzero(&mdepend, sizeof(mdepend));
|
|
|
|
mdepend.md_ver_preferred = version;
|
|
|
|
mp = file_findmodule(fp, modname, &mdepend);
|
2000-05-01 17:41:25 +00:00
|
|
|
if (mp)
|
|
|
|
return (EEXIST);
|
|
|
|
mp = malloc(sizeof(struct kernel_module));
|
|
|
|
if (mp == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
bzero(mp, sizeof(struct kernel_module));
|
|
|
|
mp->m_name = strdup(modname);
|
2001-09-11 01:09:24 +00:00
|
|
|
mp->m_version = version;
|
2000-05-01 17:41:25 +00:00
|
|
|
mp->m_fp = fp;
|
|
|
|
mp->m_next = fp->f_modules;
|
|
|
|
fp->f_modules = mp;
|
|
|
|
if (newmp)
|
|
|
|
*newmp = mp;
|
|
|
|
return (0);
|
|
|
|
}
|
1998-09-14 18:27:06 +00:00
|
|
|
|
1998-09-03 02:10:09 +00:00
|
|
|
/*
|
2000-05-01 17:41:25 +00:00
|
|
|
* Throw a file away
|
1998-09-03 02:10:09 +00:00
|
|
|
*/
|
|
|
|
void
|
2000-05-01 17:41:25 +00:00
|
|
|
file_discard(struct preloaded_file *fp)
|
1998-09-03 02:10:09 +00:00
|
|
|
{
|
2000-05-01 17:41:25 +00:00
|
|
|
struct file_metadata *md, *md1;
|
|
|
|
struct kernel_module *mp, *mp1;
|
|
|
|
if (fp == NULL)
|
|
|
|
return;
|
|
|
|
md = fp->f_metadata;
|
|
|
|
while (md) {
|
|
|
|
md1 = md;
|
|
|
|
md = md->md_next;
|
|
|
|
free(md1);
|
1998-09-14 18:27:06 +00:00
|
|
|
}
|
2000-05-01 17:41:25 +00:00
|
|
|
mp = fp->f_modules;
|
|
|
|
while (mp) {
|
|
|
|
if (mp->m_name)
|
|
|
|
free(mp->m_name);
|
|
|
|
mp1 = mp;
|
|
|
|
mp = mp->m_next;
|
|
|
|
free(mp1);
|
2016-05-12 01:19:11 +00:00
|
|
|
}
|
2000-05-01 17:41:25 +00:00
|
|
|
if (fp->f_name != NULL)
|
|
|
|
free(fp->f_name);
|
|
|
|
if (fp->f_type != NULL)
|
|
|
|
free(fp->f_type);
|
|
|
|
if (fp->f_args != NULL)
|
|
|
|
free(fp->f_args);
|
|
|
|
free(fp);
|
1998-09-03 02:10:09 +00:00
|
|
|
}
|
|
|
|
|
1998-09-14 18:27:06 +00:00
|
|
|
/*
|
2000-05-01 17:41:25 +00:00
|
|
|
* Allocate a new file; must be used instead of malloc()
|
1998-09-14 18:27:06 +00:00
|
|
|
* to ensure safe initialisation.
|
|
|
|
*/
|
2000-05-01 17:41:25 +00:00
|
|
|
struct preloaded_file *
|
|
|
|
file_alloc(void)
|
1998-09-14 18:27:06 +00:00
|
|
|
{
|
2000-05-01 17:41:25 +00:00
|
|
|
struct preloaded_file *fp;
|
2016-05-12 01:19:11 +00:00
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
if ((fp = malloc(sizeof(struct preloaded_file))) != NULL) {
|
|
|
|
bzero(fp, sizeof(struct preloaded_file));
|
1998-09-14 18:27:06 +00:00
|
|
|
}
|
2000-05-01 17:41:25 +00:00
|
|
|
return (fp);
|
1998-09-14 18:27:06 +00:00
|
|
|
}
|
|
|
|
|
1998-09-03 02:10:09 +00:00
|
|
|
/*
|
|
|
|
* Add a module to the chain
|
|
|
|
*/
|
|
|
|
static void
|
2000-05-01 17:41:25 +00:00
|
|
|
file_insert_tail(struct preloaded_file *fp)
|
1998-09-03 02:10:09 +00:00
|
|
|
{
|
2000-05-01 17:41:25 +00:00
|
|
|
struct preloaded_file *cm;
|
1998-09-03 02:10:09 +00:00
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
/* Append to list of loaded file */
|
|
|
|
fp->f_next = NULL;
|
|
|
|
if (preloaded_files == NULL) {
|
|
|
|
preloaded_files = fp;
|
1998-09-03 02:10:09 +00:00
|
|
|
} else {
|
2000-05-01 17:41:25 +00:00
|
|
|
for (cm = preloaded_files; cm->f_next != NULL; cm = cm->f_next)
|
1998-09-03 02:10:09 +00:00
|
|
|
;
|
2000-05-01 17:41:25 +00:00
|
|
|
cm->f_next = fp;
|
1998-09-03 02:10:09 +00:00
|
|
|
}
|
|
|
|
}
|
2000-05-01 17:41:25 +00:00
|
|
|
|
2001-09-11 01:09:24 +00:00
|
|
|
static char *
|
|
|
|
moduledir_fullpath(struct moduledir *mdp, const char *fname)
|
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
cp = malloc(strlen(mdp->d_path) + strlen(fname) + 2);
|
|
|
|
if (cp == NULL)
|
|
|
|
return NULL;
|
|
|
|
strcpy(cp, mdp->d_path);
|
|
|
|
strcat(cp, "/");
|
|
|
|
strcat(cp, fname);
|
|
|
|
return (cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read linker.hints file into memory performing some sanity checks.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
moduledir_readhints(struct moduledir *mdp)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
char *path;
|
|
|
|
int fd, size, version;
|
|
|
|
|
|
|
|
if (mdp->d_hints != NULL || (mdp->d_flags & MDIR_NOHINTS))
|
|
|
|
return;
|
|
|
|
path = moduledir_fullpath(mdp, "linker.hints");
|
2006-01-12 13:18:49 +00:00
|
|
|
if (stat(path, &st) != 0 ||
|
|
|
|
st.st_size < (ssize_t)(sizeof(version) + sizeof(int)) ||
|
2014-11-29 17:29:30 +00:00
|
|
|
st.st_size > LINKER_HINTS_MAX || (fd = open(path, O_RDONLY)) < 0) {
|
2001-09-11 01:09:24 +00:00
|
|
|
free(path);
|
|
|
|
mdp->d_flags |= MDIR_NOHINTS;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(path);
|
|
|
|
size = read(fd, &version, sizeof(version));
|
|
|
|
if (size != sizeof(version) || version != LINKER_HINTS_VERSION)
|
|
|
|
goto bad;
|
|
|
|
size = st.st_size - size;
|
|
|
|
mdp->d_hints = malloc(size);
|
|
|
|
if (mdp->d_hints == NULL)
|
|
|
|
goto bad;
|
|
|
|
if (read(fd, mdp->d_hints, size) != size)
|
|
|
|
goto bad;
|
|
|
|
mdp->d_hintsz = size;
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
bad:
|
|
|
|
close(fd);
|
|
|
|
if (mdp->d_hints) {
|
|
|
|
free(mdp->d_hints);
|
|
|
|
mdp->d_hints = NULL;
|
|
|
|
}
|
|
|
|
mdp->d_flags |= MDIR_NOHINTS;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract directories from the ';' separated list, remove duplicates.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
moduledir_rebuild(void)
|
|
|
|
{
|
|
|
|
struct moduledir *mdp, *mtmp;
|
|
|
|
const char *path, *cp, *ep;
|
2016-01-12 02:17:39 +00:00
|
|
|
size_t cplen;
|
2001-09-11 01:09:24 +00:00
|
|
|
|
|
|
|
path = getenv("module_path");
|
|
|
|
if (path == NULL)
|
|
|
|
path = default_searchpath;
|
|
|
|
/*
|
|
|
|
* Rebuild list of module directories if it changed
|
|
|
|
*/
|
|
|
|
STAILQ_FOREACH(mdp, &moduledir_list, d_link)
|
|
|
|
mdp->d_flags |= MDIR_REMOVED;
|
|
|
|
|
|
|
|
for (ep = path; *ep != 0; ep++) {
|
|
|
|
cp = ep;
|
|
|
|
for (; *ep != 0 && *ep != ';'; ep++)
|
|
|
|
;
|
|
|
|
/*
|
|
|
|
* Ignore trailing slashes
|
|
|
|
*/
|
|
|
|
for (cplen = ep - cp; cplen > 1 && cp[cplen - 1] == '/'; cplen--)
|
|
|
|
;
|
|
|
|
STAILQ_FOREACH(mdp, &moduledir_list, d_link) {
|
|
|
|
if (strlen(mdp->d_path) != cplen || bcmp(cp, mdp->d_path, cplen) != 0)
|
|
|
|
continue;
|
|
|
|
mdp->d_flags &= ~MDIR_REMOVED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mdp == NULL) {
|
|
|
|
mdp = malloc(sizeof(*mdp) + cplen + 1);
|
|
|
|
if (mdp == NULL)
|
|
|
|
return;
|
|
|
|
mdp->d_path = (char*)(mdp + 1);
|
|
|
|
bcopy(cp, mdp->d_path, cplen);
|
|
|
|
mdp->d_path[cplen] = 0;
|
|
|
|
mdp->d_hints = NULL;
|
|
|
|
mdp->d_flags = 0;
|
|
|
|
STAILQ_INSERT_TAIL(&moduledir_list, mdp, d_link);
|
|
|
|
}
|
2002-04-11 10:00:44 +00:00
|
|
|
if (*ep == 0)
|
|
|
|
break;
|
2001-09-11 01:09:24 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Delete unused directories if any
|
|
|
|
*/
|
|
|
|
mdp = STAILQ_FIRST(&moduledir_list);
|
|
|
|
while (mdp) {
|
|
|
|
if ((mdp->d_flags & MDIR_REMOVED) == 0) {
|
|
|
|
mdp = STAILQ_NEXT(mdp, d_link);
|
|
|
|
} else {
|
|
|
|
if (mdp->d_hints)
|
|
|
|
free(mdp->d_hints);
|
|
|
|
mtmp = mdp;
|
|
|
|
mdp = STAILQ_NEXT(mdp, d_link);
|
|
|
|
STAILQ_REMOVE(&moduledir_list, mtmp, moduledir, d_link);
|
|
|
|
free(mtmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|