コード例 #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
ファイル: dyncmd.c プロジェクト: remfalc/vyt-vyatta-grub
static grub_err_t
grub_dyncmd_dispatcher (struct grub_command *cmd,
			int argc, char **args)
{
  char *modname = cmd->data;
  grub_dl_t mod;
  grub_err_t ret;

  mod = grub_dl_load (modname);
  if (mod)
    {
      char *name;

      grub_free (modname);
      grub_dl_ref (mod);

      name = (char *) cmd->name;
      grub_unregister_command (cmd);

      cmd = grub_command_find (name);
      if (cmd)
	ret = (cmd->func) (cmd, argc, args);
      else
	ret = grub_errno;

      grub_free (name);
    }
  else
    ret = grub_errno;

  return ret;
}
コード例 #3
0
ファイル: command.c プロジェクト: GrandTyRant/grub2
grub_command_t
grub_command_find (char *cmdline)
{
  char *first_space;
  grub_command_t cmd;
  int count = 0;
  
  first_space = grub_strchr (cmdline, ' ');
  if (first_space)
    *first_space = '\0';

 again:
  
  for (cmd = grub_command_list; cmd; cmd = cmd->next)
    if (grub_strcmp (cmdline, cmd->name) == 0)
      break;

  if (! cmd)
    grub_error (GRUB_ERR_UNKNOWN_COMMAND, "unknown command `%s'", cmdline);
  else if (cmd->flags & GRUB_COMMAND_FLAG_NOT_LOADED)
    {
      /* Automatically load the command.  */
      if (count == 0)
	{
	  grub_dl_t mod;
	  char *module_name;

	  module_name = grub_strdup (cmd->module_name);
	  if (module_name)
	    {
	      mod = grub_dl_load (module_name);
	      if (mod)
		{
		  grub_dl_ref (mod);
		  count++;
		  grub_free (module_name);
  		  goto again;
		}

	      grub_free (module_name);
	    }
	}

      /* This module seems broken.  */
      grub_unregister_command (cmdline);
      grub_error (GRUB_ERR_UNKNOWN_COMMAND, "unknown command `%s'", cmdline);
      cmd = 0;
    }
  
  if (first_space)
    *first_space = ' ';

  return cmd;
}
コード例 #4
0
ファイル: menu.c プロジェクト: kphillisjr/burg
static void
menu_init (int entry, grub_menu_t menu, int nested)
{
  struct grub_term_output *term;
  int gfxmenu = 0;

  FOR_ACTIVE_TERM_OUTPUTS(term)
    if (grub_strcmp (term->name, "gfxterm") == 0)
      {
	if (grub_env_get ("theme"))
	  {
	    if (!grub_gfxmenu_try_hook)
	      {
		grub_dl_load ("gfxmenu");
		grub_print_error ();
	      }
	    if (grub_gfxmenu_try_hook)
	      {
		grub_err_t err;
		err = grub_gfxmenu_try_hook (entry, menu, nested);
		if(!err)
		  {
		    gfxmenu = 1;
		    break;
		  }
	      }
	    else
	      grub_error (GRUB_ERR_BAD_MODULE,
			  N_("module `%s' isn't loaded"),
			  "gfxmenu");
	    grub_print_error ();
	    grub_wait_after_message ();
	  }
	grub_errno = GRUB_ERR_NONE;
	grub_gfxterm_fullscreen ();
	break;
      }

  FOR_ACTIVE_TERM_OUTPUTS(term)
  {
    grub_err_t err;

    if (grub_strcmp (term->name, "gfxterm") == 0 && gfxmenu)
      continue;

    err = grub_menu_try_text (term, entry, menu, nested);
    if(!err)
      continue;
    grub_print_error ();
    grub_errno = GRUB_ERR_NONE;
  }
}
コード例 #5
0
ファイル: crypto.c プロジェクト: rododo-meow/myburg
static void
grub_crypto_autoload (const char *name)
{
    struct load_spec *cur;
    grub_dl_t mod;

    for (cur = crypto_specs; cur; cur = cur->next)
        if (grub_strcasecmp (name, cur->name) == 0)
        {
            mod = grub_dl_load (cur->modname);
            if (mod)
                grub_dl_ref (mod);
            grub_errno = GRUB_ERR_NONE;
        }
}
コード例 #6
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;
}
コード例 #7
0
ファイル: crypto.c プロジェクト: Arvian/GRUB2
static void 
grub_crypto_autoload (const char *name)
{
  struct load_spec *cur;
  grub_dl_t mod;
  static int depth = 0;

  /* Some bufio of filesystems may want some crypto modules.
     It may result in infinite recursion. Hence this check.  */
  if (depth)
    return;
  depth++;

  for (cur = crypto_specs; cur; cur = cur->next)
    if (grub_strcasecmp (name, cur->name) == 0)
      {
	mod = grub_dl_load (cur->modname);
	if (mod)
	  grub_dl_ref (mod);
	grub_errno = GRUB_ERR_NONE;
      }
  depth--;
}
コード例 #8
0
ファイル: dynld_grub.c プロジェクト: BaJIeK/brltty
void *
loadSharedObject (const char *name) {
  return grub_dl_load(name);
}
コード例 #9
0
ファイル: terminal.c プロジェクト: pendor/grub-zfs
static grub_err_t
handle_command (int argc, char **args, struct abstract_terminal **enabled,
                struct abstract_terminal **disabled,
                struct grub_term_autoload *autoloads,
                const char *active_str,
                const char *available_str)
{
    int i;
    struct abstract_terminal *term;
    struct grub_term_autoload *aut;

    if (argc == 0)
    {
        grub_puts_ (active_str);
        for (term = *enabled; term; term = term->next)
            grub_printf ("%s ", term->name);
        grub_printf ("\n");
        grub_puts_ (available_str);
        for (term = *disabled; term; term = term->next)
            grub_printf ("%s ", term->name);
        /* This is quadratic but we don't expect mode than 30 terminal
          modules ever.  */
        for (aut = autoloads; aut; aut = aut->next)
        {
            for (term = *disabled; term; term = term->next)
                if (grub_strcmp (term->name, aut->name) == 0
                        || (aut->name[0] && aut->name[grub_strlen (aut->name) - 1] == '*'
                            && grub_memcmp (term->name, aut->name,
                                            grub_strlen (aut->name) - 1) == 0))
                    break;
            if (!term)
                for (term = *enabled; term; term = term->next)
                    if (grub_strcmp (term->name, aut->name) == 0
                            || (aut->name[0] && aut->name[grub_strlen (aut->name) - 1] == '*'
                                && grub_memcmp (term->name, aut->name,
                                                grub_strlen (aut->name) - 1) == 0))
                        break;
            if (!term)
                grub_printf ("%s ", aut->name);
        }
        grub_printf ("\n");
        return GRUB_ERR_NONE;
    }
    i = 0;

    if (grub_strcmp (args[0], "--append") == 0
            || grub_strcmp (args[0], "--remove") == 0)
        i++;

    if (i == argc)
        return grub_error (GRUB_ERR_BAD_ARGUMENT, N_ ("no terminal specified"));

    for (; i < argc; i++)
    {
        int again = 0;
        while (1)
        {
            for (term = *disabled; term; term = term->next)
                if (grub_strcmp (args[i], term->name) == 0)
                    break;
            if (term == 0)
                for (term = *enabled; term; term = term->next)
                    if (grub_strcmp (args[i], term->name) == 0)
                        break;
            if (term)
                break;
            if (again)
                return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n",
                                   args[i]);
            for (aut = autoloads; aut; aut = aut->next)
                if (grub_strcmp (args[i], aut->name) == 0
                        || (aut->name[0] && aut->name[grub_strlen (aut->name) - 1] == '*'
                            && grub_memcmp (args[i], aut->name,
                                            grub_strlen (aut->name) - 1) == 0))
                {
                    grub_dl_t mod;
                    mod = grub_dl_load (aut->modname);
                    if (mod)
                        grub_dl_ref (mod);
                    grub_errno = GRUB_ERR_NONE;
                    break;
                }
            if (!aut)
                return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n",
                                   args[i]);
            again = 1;
        }
    }

    if (grub_strcmp (args[0], "--append") == 0)
    {
        for (i = 1; i < argc; i++)
        {
            for (term = *disabled; term; term = term->next)
                if (grub_strcmp (args[i], term->name) == 0)
                    break;
            if (term)
            {
                if (term->init && term->init (term) != GRUB_ERR_NONE)
                    return grub_errno;

                grub_list_remove (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
                grub_list_push (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
            }
        }
        return GRUB_ERR_NONE;
    }

    if (grub_strcmp (args[0], "--remove") == 0)
    {
        for (i = 1; i < argc; i++)
        {
            for (term = *enabled; term; term = term->next)
                if (grub_strcmp (args[i], term->name) == 0)
                    break;
            if (term)
            {
                if (!term->next && term == *enabled)
                    return grub_error (GRUB_ERR_BAD_ARGUMENT,
                                       "can't remove the last terminal");
                grub_list_remove (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
                if (term->fini)
                    term->fini (term);
                grub_list_push (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
            }
        }
        return GRUB_ERR_NONE;
    }
    for (i = 0; i < argc; i++)
    {
        for (term = *disabled; term; term = term->next)
            if (grub_strcmp (args[i], term->name) == 0)
                break;
        if (term)
        {
            if (term->init && term->init (term) != GRUB_ERR_NONE)
                return grub_errno;

            grub_list_remove (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
            grub_list_push (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
        }
    }

    {
        struct abstract_terminal *next;
        for (term = *enabled; term; term = next)
        {
            next = term->next;
            for (i = 0; i < argc; i++)
                if (grub_strcmp (args[i], term->name) == 0)
                    break;
            if (i == argc)
            {
                if (!term->next && term == *enabled)
                    return grub_error (GRUB_ERR_BAD_ARGUMENT,
                                       "can't remove the last terminal");
                grub_list_remove (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term));
                if (term->fini)
                    term->fini (term);
                grub_list_push (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term));
            }
        }
    }

    return GRUB_ERR_NONE;
}
コード例 #10
0
ファイル: videotest.c プロジェクト: Spacy/grub-fuse
static grub_err_t
grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),
                    int argc, char **args)
{
  grub_err_t err;
  grub_video_color_t color;
  unsigned int x;
  unsigned int y;
  unsigned int width;
  unsigned int height;
  int i;
  struct grub_video_render_target *text_layer;
  grub_video_color_t palette[16];
  const char *mode = NULL;

#ifdef GRUB_MACHINE_PCBIOS
  if (grub_strcmp (cmd->name, "vbetest") == 0)
    grub_dl_load ("vbe");
#endif

  mode = grub_env_get ("gfxmode");
  if (argc)
    mode = args[0];
  if (!mode)
    mode = "auto";

  err = grub_video_set_mode (mode, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0);
  if (err)
    return err;

  grub_video_get_viewport (&x, &y, &width, &height);

  {
    const char *str;
    int texty;
    grub_font_t sansbig;
    grub_font_t sans;
    grub_font_t sanssmall;
    grub_font_t fixed;
    struct grub_font_glyph *glyph;

    grub_video_create_render_target (&text_layer, width, height,
				     GRUB_VIDEO_MODE_TYPE_RGB
				     | GRUB_VIDEO_MODE_TYPE_ALPHA);

    grub_video_set_active_render_target (text_layer);

    color = grub_video_map_rgb (0, 255, 255);
    sansbig = grub_font_get ("Unknown Regular 16");
    sans = grub_font_get ("Unknown Regular 16");
    sanssmall = grub_font_get ("Unknown Regular 16");
    fixed = grub_font_get ("Fixed 20");
    if (! sansbig || ! sans || ! sanssmall || ! fixed)
      return grub_error (GRUB_ERR_BAD_FONT, "no font loaded");

    glyph = grub_font_get_glyph (fixed, '*');
    grub_font_draw_glyph (glyph, color, 200 ,0);

    color = grub_video_map_rgb (255, 255, 255);

    texty = 32;
    grub_font_draw_string ("The quick brown fox jumped over the lazy dog.",
			   sans, color, 16, texty);
    texty += grub_font_get_descent (sans) + grub_font_get_leading (sans);

    texty += grub_font_get_ascent (fixed);
    grub_font_draw_string ("The quick brown fox jumped over the lazy dog.",
			   fixed, color, 16, texty);
    texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);

    /* To convert Unicode characters into UTF-8 for this test, the following
       command is useful:
       echo -ne '\x00\x00\x26\x3A' | iconv -f UTF-32BE -t UTF-8 | od -t x1
       This converts the Unicode character U+263A to UTF-8.  */

    /* Characters used:
       Code point  Description                    UTF-8 encoding
       ----------- ------------------------------ --------------
       U+263A      unfilled smiley face           E2 98 BA
       U+00A1      inverted exclamation point     C2 A1
       U+00A3      British pound currency symbol  C2 A3
       U+03C4      Greek tau                      CF 84
       U+00E4      lowercase letter a with umlaut C3 A4
       U+2124      set 'Z' symbol (integers)      E2 84 A4
       U+2287      subset symbol                  E2 8A 87
       U+211D      set 'R' symbol (real numbers)  E2 84 9D  */

    str =
      "Unicode test: happy\xE2\x98\xBA \xC2\xA3 5.00"
      " \xC2\xA1\xCF\x84\xC3\xA4u! "
      " \xE2\x84\xA4\xE2\x8A\x87\xE2\x84\x9D";
    color = grub_video_map_rgb (128, 128, 255);

    /* All characters in the string exist in the 'Fixed 20' (10x20) font.  */
    texty += grub_font_get_ascent(fixed);
    grub_font_draw_string (str, fixed, color, 16, texty);
    texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);

    texty += grub_font_get_ascent(sansbig);
    grub_font_draw_string (str, sansbig, color, 16, texty);
    texty += grub_font_get_descent (sansbig) + grub_font_get_leading (sansbig);

    texty += grub_font_get_ascent(sans);
    grub_font_draw_string (str, sans, color, 16, texty);
    texty += grub_font_get_descent (sans) + grub_font_get_leading (sans);

    texty += grub_font_get_ascent(sanssmall);
    grub_font_draw_string (str, sanssmall, color, 16, texty);
    texty += (grub_font_get_descent (sanssmall)
	      + grub_font_get_leading (sanssmall));

    glyph = grub_font_get_glyph (fixed, '*');

    for (i = 0; i < 16; i++)
      {
	color = grub_video_map_color (i);
	palette[i] = color;
	grub_font_draw_glyph (glyph, color, 16 + i * 16, 220);
      }
  }

  grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);

  for (i = 0; i < 2; i++)
    {
      color = grub_video_map_rgb (0, 0, 0);
      grub_video_fill_rect (color, 0, 0, width, height);

      color = grub_video_map_rgb (255, 0, 0);
      grub_video_fill_rect (color, 0, 0, 100, 100);

      color = grub_video_map_rgb (0, 255, 255);
      grub_video_fill_rect (color, 100, 100, 100, 100);

      grub_video_set_viewport (x + 150, y + 150,
			       width - 150 * 2, height - 150 * 2);
      color = grub_video_map_rgb (77, 33, 77);
      grub_video_fill_rect (color, 0, 0, width, height);
      grub_video_swap_buffers ();
    }

  for (i = 0; i < 5; i++)
    {
      color = grub_video_map_rgb (i, 33, 77);
      grub_video_fill_rect (color, 0, 0, width, height);
      grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_BLEND, 0, 0,
                                     0, 0, width, height);
      grub_video_swap_buffers ();
    }

  grub_getkey ();

  grub_video_delete_render_target (text_layer);

  grub_video_restore ();

  for (i = 0; i < 16; i++)
    grub_printf("color %d: %08x\n", i, palette[i]);

  grub_errno = GRUB_ERR_NONE;
  return grub_errno;
}