コード例 #1
0
ファイル: autofs.c プロジェクト: 376473984/TrustedGRUB2
/* The auto-loading hook for filesystems.  */
static int
autoload_fs_module (void)
{
  grub_named_list_t p;
  int ret = 0;
  grub_file_filter_t grub_file_filters_was[GRUB_FILE_FILTER_MAX];

  grub_memcpy (grub_file_filters_was, grub_file_filters_enabled,
	       sizeof (grub_file_filters_enabled));
  grub_memcpy (grub_file_filters_enabled, grub_file_filters_all,
	       sizeof (grub_file_filters_enabled));

  while ((p = fs_module_list) != NULL)
    {
      if (! grub_dl_get (p->name) && grub_dl_load (p->name))
	{
	  ret = 1;
	  break;
	}

      if (grub_errno)
	grub_print_error ();

      fs_module_list = p->next;
      grub_free (p->name);
      grub_free (p);
    }

  grub_memcpy (grub_file_filters_enabled, grub_file_filters_was,
	       sizeof (grub_file_filters_enabled));

  return ret;
}
コード例 #2
0
ファイル: dl.c プロジェクト: IntelBUAP/Inicializacion
/* Keep global so that GDB scripts work.  */
grub_err_t
grub_dl_add (grub_dl_t mod)
{
  if (grub_dl_get (mod->name))
    return grub_error (GRUB_ERR_BAD_MODULE,
		       "`%s' is already loaded", mod->name);

  return GRUB_ERR_NONE;
}
コード例 #3
0
ファイル: dl.c プロジェクト: GrandTyRant/grub2
static grub_err_t
grub_dl_add (grub_dl_t mod)
{
  grub_dl_list_t l;

  if (grub_dl_get (mod->name))
    return grub_error (GRUB_ERR_BAD_MODULE,
		       "`%s' is already loaded", mod->name);
  
  l = (grub_dl_list_t) grub_malloc (sizeof (*l));
  if (! l)
    return grub_errno;

  l->mod = mod;
  l->next = grub_dl_head;
  grub_dl_head = l;

  return GRUB_ERR_NONE;
}
コード例 #4
0
ファイル: autofs.c プロジェクト: Firef0x/burg-new
/* The auto-loading hook for filesystems.  */
static int
autoload_fs_module (void)
{
  grub_named_list_t p;

  while ((p = fs_module_list) != NULL)
    {
      if (! grub_dl_get (p->name) && grub_dl_load (p->name))
	return 1;

      if (grub_errno)
	grub_print_error ();

      fs_module_list = p->next;
      grub_free (p->name);
      grub_free (p);
    }

  return 0;
}
コード例 #5
0
ファイル: nativedisk.c プロジェクト: 376473984/TrustedGRUB2
static grub_err_t
grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
		     int argc, char **args_in)
{
  char *uuid_root = 0, *uuid_prefix, *prefdev = 0;
  const char *prefix = 0;
  const char *path_prefix = 0;
  int mods_loaded = 0;
  grub_dl_t *mods;
  const char **args;
  int i;

  if (argc == 0)
    {
      argc = ARRAY_SIZE (modnames_def);
      args = modnames_def;
    }
  else
    args = (const char **) args_in;

  prefix = grub_env_get ("prefix");

  if (! prefix)
    return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "prefix");

  if (prefix)
    path_prefix = (prefix[0] == '(') ? grub_strchr (prefix, ')') : NULL;
  if (path_prefix)
    path_prefix++;
  else
    path_prefix = prefix;

  mods = grub_malloc (argc * sizeof (mods[0]));
  if (!mods)
    return grub_errno;

  if (get_uuid (NULL, &uuid_root, 0))
    return grub_errno;

  prefdev = grub_file_get_device_name (prefix);
  if (grub_errno)
    {
      grub_print_error ();
      prefdev = 0;
    }

  if (get_uuid (prefdev, &uuid_prefix, 0))
    {
      grub_free (uuid_root);
      return grub_errno;
    }

  grub_dprintf ("nativedisk", "uuid_prefix = %s, uuid_root = %s\n",
		uuid_prefix, uuid_root);

  for (mods_loaded = 0; mods_loaded < argc; mods_loaded++)
    {
      char *filename;
      grub_dl_t mod;
      grub_file_t file = NULL;
      grub_ssize_t size;
      void *core = 0;

      mod = grub_dl_get (args[mods_loaded]);
      if (mod)
	{
	  mods[mods_loaded] = 0;
	  continue;
	}

      filename = grub_xasprintf ("%s/" GRUB_TARGET_CPU "-" GRUB_PLATFORM "/%s.mod",
				 prefix, args[mods_loaded]);
      if (! filename)
	goto fail;

      file = grub_file_open (filename);
      grub_free (filename);
      if (! file)
	goto fail;

      size = grub_file_size (file);
      core = grub_malloc (size);
      if (! core)
	{
	  grub_file_close (file);
	  goto fail;
	}

      if (grub_file_read (file, core, size) != (grub_ssize_t) size)
	{
	  grub_file_close (file);
	  grub_free (core);
	  goto fail;
	}

      grub_file_close (file);

      mods[mods_loaded] = grub_dl_load_core_noinit (core, size);
      if (! mods[mods_loaded])
	goto fail;
    }

  for (i = 0; i < argc; i++)
    if (mods[i])
      grub_dl_init (mods[i]);

  if (uuid_prefix || uuid_root)
    {
      struct search_ctx ctx;
      grub_fs_autoload_hook_t saved_autoload;

      /* No need to autoload FS since obviously we already have the necessary fs modules.  */
      saved_autoload = grub_fs_autoload_hook;
      grub_fs_autoload_hook = 0;

      ctx.root_uuid = uuid_root;
      ctx.prefix_uuid = uuid_prefix;
      ctx.prefix_path = path_prefix;
      ctx.prefix_found = !uuid_prefix;
      ctx.root_found = !uuid_root;

      /* FIXME: try to guess the correct values.  */
      grub_device_iterate (iterate_device, &ctx);

      grub_fs_autoload_hook = saved_autoload;
    }
  grub_free (uuid_root);
  grub_free (uuid_prefix);

  return GRUB_ERR_NONE;

 fail:
  grub_free (uuid_root);
  grub_free (uuid_prefix);

  for (i = 0; i < mods_loaded; i++)
    if (mods[i])
      {
	mods[i]->fini = 0;
	grub_dl_unload (mods[i]);
      }
  return grub_errno;
}
コード例 #6
0
ファイル: dyncmd.c プロジェクト: remfalc/vyt-vyatta-grub
/* Read the file command.lst for auto-loading.  */
void
read_command_list (const char *prefix)
{
  if (prefix)
    {
      char *filename;

      filename = grub_xasprintf ("%s/command.lst", prefix);
      if (filename)
	{
	  grub_file_t file;

	  file = grub_file_open (filename);
	  if (file)
	    {
	      char *buf = NULL;
	      grub_command_t ptr, last = 0, next;

	      /* Override previous commands.lst.  */
	      for (ptr = grub_command_list; ptr; ptr = next)
		{
		  next = ptr->next;
		  if (ptr->func == grub_dyncmd_dispatcher)
		    {
		      if (last)
			last->next = ptr->next;
		      else
			grub_command_list = ptr->next;
		      grub_free (ptr);
		    }
		  else
		    last = ptr;
		}

	      for (;; grub_free (buf))
		{
		  char *p, *name, *modname;
		  grub_command_t cmd;
		  int prio = 0;

		  buf = grub_file_getline (file);

		  if (! buf)
		    break;

		  name = buf;
		  if (*name == '*')
		    {
		      name++;
		      prio++;
		    }

		  if (! grub_isgraph (name[0]))
		    continue;

		  p = grub_strchr (name, ':');
		  if (! p)
		    continue;

		  *p = '\0';
		  while (*++p == ' ')
		    ;

		  if (! grub_isgraph (*p))
		    continue;

		  if (grub_dl_get (p))
		    continue;

		  name = grub_strdup (name);
		  if (! name)
		    continue;

		  modname = grub_strdup (p);
		  if (! modname)
		    {
		      grub_free (name);
		      continue;
		    }

		  cmd = grub_register_command_prio (name,
						    grub_dyncmd_dispatcher,
						    0, N_("not loaded"), prio);
		  if (! cmd)
		    {
		      grub_free (name);
		      grub_free (modname);
		      continue;
		    }
		  cmd->flags |= GRUB_COMMAND_FLAG_DYNCMD;
		  cmd->data = modname;

		  /* Update the active flag.  */
		  grub_command_find (name);
		}

	      grub_file_close (file);
	    }

	  grub_free (filename);
	}
    }

  /* Ignore errors.  */
  grub_errno = GRUB_ERR_NONE;
}