Esempio n. 1
0
/* grub_fatal() on error */
static grub_err_t
grub_cmd_readpcr( grub_command_t cmd __attribute__ ((unused)), int argc, char **args) {

	if ( argc == 0 ) {
		grub_fatal( "grub_cmd_readpcr: index expected" );
	}

	if ( argc > 1 ) {
		grub_fatal( "grub_cmd_readpcr: Too many arguments" );
	}

	unsigned long index = grub_strtoul( args[0], NULL, 10 );

	/* if index is invalid */
	if( grub_errno != GRUB_ERR_NONE ) {
        grub_fatal( "grub_cmd_readpcr: invalid format for index" );
	}

	grub_uint8_t result[SHA1_DIGEST_SIZE] = { 0 };
    grub_TPM_readpcr( index, &result[0] );

	grub_printf( "PCR[%lu]=", index );
	print_sha1( result );
	grub_printf("\n");

	return GRUB_ERR_NONE;
}
Esempio n. 2
0
void
grub_backtrace_pointer (void *ebp)
{
  void *ptr, *nptr;
  unsigned i;

  ptr = ebp;
  while (1)
    {
      grub_printf ("%p: ", ptr);
      grub_backtrace_print_address (((void **) ptr)[1]);
      grub_printf (" (");
      for (i = 0; i < 2; i++)
	grub_printf ("%p,", ((void **)ptr) [i + 2]);
      grub_printf ("%p)\n", ((void **)ptr) [i + 2]);
      nptr = *(void **)ptr;
      if (nptr < ptr || (void **) nptr - (void **) ptr > MAX_STACK_FRAME
	  || nptr == ptr)
	{
	  grub_printf ("Invalid stack frame at %p (%p)\n", ptr, nptr);
	  break;
	}
      ptr = nptr;
    }
}
Esempio n. 3
0
static void
dump_vendor_path (const char *type, grub_efi_vendor_device_path_t *vendor)
{
  grub_uint32_t vendor_data_len = vendor->header.length - sizeof (*vendor);
  grub_printf ("/%sVendor(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)[%x: ",
	       type,
	       (unsigned) vendor->vendor_guid.data1,
	       (unsigned) vendor->vendor_guid.data2,
	       (unsigned) vendor->vendor_guid.data3,
	       (unsigned) vendor->vendor_guid.data4[0],
	       (unsigned) vendor->vendor_guid.data4[1],
	       (unsigned) vendor->vendor_guid.data4[2],
	       (unsigned) vendor->vendor_guid.data4[3],
	       (unsigned) vendor->vendor_guid.data4[4],
	       (unsigned) vendor->vendor_guid.data4[5],
	       (unsigned) vendor->vendor_guid.data4[6],
	       (unsigned) vendor->vendor_guid.data4[7],
	       vendor_data_len);
  if (vendor->header.length > sizeof (*vendor))
    {
      grub_uint32_t i;
      for (i = 0; i < vendor_data_len; i++)
	grub_printf ("%02x ", vendor->vendor_defined_data[i]);
    }
  grub_printf ("]");
}
Esempio n. 4
0
static int try_blksize (int tmp)
{
	unsigned long nr;

	pxe_blksize = tmp;
	grub_printf ("\nTry block size %d ...\n", pxe_blksize);
	if ((tmp = pxe_dir (pxe_tftp_name)))
	{
	    if (filemax <= pxe_blksize)
	    {
		grub_printf ("\nFailure: Size %ld too small.\n", filemax);
	        pxe_close ();
		return 1;
	    }
	    nr = pxe_read_blk (PXE_BUF, 1);
	    if (nr == PXE_ERR_LEN)
	    {
		grub_printf ("\nFailure: Cannot read the first block.\n");
	        pxe_close ();
		return 1;
	    }
	    if (pxe_blksize != nr && filemax > nr && nr <= PXE_MAX_BLKSIZE && nr >= PXE_MIN_BLKSIZE)
	    {
		grub_printf ("\npxe_blksize tuned from %d to %d\n", pxe_blksize, nr);
		pxe_blksize = nr;
	    }
	    grub_printf ("\nUse block size %d\n", pxe_blksize);
	    pxe_close ();
	    return 0;
	}
	return 1;	/* return 0 for seccess, 1 for failure */
}
Esempio n. 5
0
static grub_err_t
grub_cmd_cat (grub_extcmd_context_t ctxt, int argc, char **args)
{
  struct grub_arg_list *state = ctxt->state;
  int dos = 0;
  grub_file_t file;
  char buf[GRUB_DISK_SECTOR_SIZE];
  grub_ssize_t size;
  int key = 0;

  if (state[0].set)
    dos = 1;

  if (argc != 1)
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");

  file = grub_file_open (args[0]);
  if (! file)
    return grub_errno;

  while ((size = grub_file_read (file, buf, sizeof (buf))) > 0
	 && key != GRUB_TERM_ESC)
    {
      int i;

      for (i = 0; i < size; i++)
	{
	  unsigned char c = buf[i];

	  if ((grub_isprint (c) || grub_isspace (c)) && c != '\r')
	    grub_printf ("%c", c);
	  else if (dos && c == '\r' && i + 1 < size && buf[i + 1] == '\n')
	    {
	      grub_printf ("\n");
	      i++;
	    }
	  else
	    {
	      grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
	      grub_printf ("<%x>", (int) c);
	      grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
	    }
	}

      while (grub_checkkey () >= 0 &&
	     (key = grub_getkey ()) != GRUB_TERM_ESC)
	;
    }

  grub_xputs ("\n");
  grub_refresh ();
  grub_file_close (file);

  return 0;
}
Esempio n. 6
0
  int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, 
			     grub_memory_type_t type)
    {
      if (type < ARRAY_SIZE (names) && names[type])
	grub_printf ("base_addr = 0x%llx, length = 0x%llx, %s\n",
		     (long long) addr, (long long) size, names[type]);
      else
	grub_printf ("base_addr = 0x%llx, length = 0x%llx, type = 0x%x\n",
		     (long long) addr, (long long) size, type);
      return 0;
    }
Esempio n. 7
0
grub_error_t
grub_cln_mfh_entry_lookup (const grub_uint8_t *mfh_addr, unsigned int entry_type,
                           grub_uint8_t **addr, grub_uint32_t *len)
{
  unsigned int offset = 0x0;
  unsigned int i = 0;
  grub_cln_mfh_item_t item = 0x0;

  if (! mfh_addr || ! addr || ! len)
    {
      grub_printf ("%s: NULL pointer\n", __func__);
      errnum = ERR_BAD_ARGUMENT;
      return errnum;
    }

  /* Fetch the MFH if not done yet.  */
  if (! cln_mfh_loaded)
    grub_cln_mfh_load ((grub_cln_mfh_t) mfh_addr);

  /* Sanity check.  */
  if (GRUB_CLN_MFH_IDENTIFIER != cln_mfh.identifier)
    {
      cln_mfh_loaded = 0;
      grub_printf ("%s: invalid MFH identifier\n", __func__);
      errnum = ERR_EXEC_FORMAT;
      return errnum;
    }

  /* Look up.  */
  offset = offsetof (struct grub_cln_mfh, padding)
           + sizeof (grub_uint32_t) * cln_mfh.boot_prio_list_count;
  for (i = 0; i < cln_mfh.flash_item_count; i ++, offset += sizeof (*item))
    {
      item = (grub_cln_mfh_item_t) ((grub_uint8_t *) &cln_mfh + offset);
      if (item->type == entry_type)
        {
          *len = item->flash_item_len;
          *addr = (grub_uint8_t *) item->flash_item_addr;
          if (grub_cln_debug)
            grub_printf ("%s: found entry 0x%x @addr=0x%x, len=0x%x\n",
                         __func__, item->type, *addr, *len);
          return errnum;
        }
    }

  /* At this stage, we haven't found the item.  */
  if (grub_cln_debug)
    {
      grub_printf ("%s: flash item 0x%x not found\n", __func__, entry_type);
    }
  errnum = ERR_FILE_NOT_FOUND;
  return errnum;
}
Esempio n. 8
0
  void NESTED_FUNC_ATTR print_blocklist (grub_disk_addr_t sector, unsigned num,
			unsigned offset, unsigned length)
    {
      if (num_entries++)
	grub_printf (",");

      grub_printf ("%llu", (unsigned long long) (sector - part_start));
      if (num > 0)
	grub_printf ("+%u", num);
      if (offset != 0 || length != 0)
	grub_printf ("[%u-%u]", offset, offset + length);
    }
Esempio n. 9
0
/* Helper for grub_cmd_blocklist.  */
static void
print_blocklist (grub_disk_addr_t sector, unsigned num,
		 unsigned offset, unsigned length, struct blocklist_ctx *ctx)
{
  if (ctx->num_entries++)
    grub_printf (",");

  grub_printf ("%llu", (unsigned long long) (sector - ctx->part_start));
  if (num > 0)
    grub_printf ("+%u", num);
  if (offset != 0 || length != 0)
    grub_printf ("[%u-%u]", offset, offset + length);
}
Esempio n. 10
0
File: compat.c Progetto: xk/bits
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
{
    grub_errno = GRUB_ERR_NONE;
    if (stream != stdout && stream != stderr) {
        grub_printf("Internal error: Python attempted to write to a file.\n");
        return 0;
    }
    if (size > GRUB_INT_MAX || nmemb > GRUB_INT_MAX || (uint64_t)size * (uint64_t)nmemb > GRUB_INT_MAX) {
        grub_error(GRUB_ERR_OUT_OF_RANGE, "Internal error: Python attempted to write more than 2GB to stdout or stderr.\n");
        return 0;
    }
    return grub_printf("%.*s", (int)(size * nmemb), (char *)ptr);
}
Esempio n. 11
0
static grub_err_t
grub_rescue_parse_line (char *line, grub_reader_getline_t getline,
			void *closure)
{
  char *name;
  int n;
  grub_command_t cmd;
  char **args;

  if (grub_parser_split_cmdline (line, getline, closure, &n, &args) || n < 0)
    return grub_errno;

  if (n == 0)
    return GRUB_ERR_NONE;

  /* In case of an assignment set the environment accordingly
     instead of calling a function.  */
  if (n == 1 && grub_strchr (line, '='))
    {
      char *val = grub_strchr (args[0], '=');
      val[0] = 0;
      grub_env_set (args[0], val + 1);
      val[0] = '=';
      goto quit;
    }

  /* Get the command name.  */
  name = args[0];

  /* If nothing is specified, restart.  */
  if (*name == '\0')
    goto quit;

  cmd = grub_command_find (name);
  if (cmd)
    {
      (cmd->func) (cmd, n - 1, &args[1]);
    }
  else
    {
      grub_printf ("Unknown command `%s'\n", name);
      if (grub_command_find ("help"))
	grub_printf ("Try `help' for usage\n");
    }

 quit:
  grub_free (args[0]);
  grub_free (args);

  return grub_errno;
}
Esempio n. 12
0
void
print_network_configuration (void)
{
  if (! eth_probe ())
    grub_printf ("No ethernet card found.\n");
  else if (! network_ready)
    grub_printf ("Not initialized yet.\n");
  else
    {
      etherboot_printf ("Address: %@\n", arptable[ARP_CLIENT].ipaddr.s_addr);
      etherboot_printf ("Netmask: %@\n", netmask);
      etherboot_printf ("Server: %@\n", arptable[ARP_SERVER].ipaddr.s_addr);
      etherboot_printf ("Gateway: %@\n", arptable[ARP_GATEWAY].ipaddr.s_addr);
    }
}
Esempio n. 13
0
unsigned
grub_term_map_key (grub_keyboard_key_t code, int status)
{
    int alt_gr_consumed = 0;
    int key;

    if (code >= 0x59 && code <= 0x63 && (status & GRUB_TERM_STATUS_NUM))
    {
        if (status & (GRUB_TERM_STATUS_RSHIFT | GRUB_TERM_STATUS_LSHIFT))
            status &= ~(GRUB_TERM_STATUS_RSHIFT | GRUB_TERM_STATUS_LSHIFT);
        else
            status |= GRUB_TERM_STATUS_RSHIFT;
    }

    key = map_key_core (code, status, &alt_gr_consumed);

    if (key == 0 || key == GRUB_TERM_SHIFT)
        grub_printf ("Unknown key 0x%x detected\n", code);

    if (status & GRUB_TERM_STATUS_CAPS)
    {
        if ((key >= 'a') && (key <= 'z'))
            key += 'A' - 'a';
        else if ((key >= 'A') && (key <= 'Z'))
            key += 'a' - 'A';
    }

    if ((status & GRUB_TERM_STATUS_LALT) ||
            ((status & GRUB_TERM_STATUS_RALT) && !alt_gr_consumed))
        key |= GRUB_TERM_ALT;
    if (status & (GRUB_TERM_STATUS_LCTRL | GRUB_TERM_STATUS_RCTRL))
        key |= GRUB_TERM_CTRL;

    return key;
}
Esempio n. 14
0
static inline grub_uint32_t
skip_data_ref_object (const grub_uint8_t *ptr, const grub_uint8_t *end)
{
  grub_dprintf ("acpi", "data type = 0x%x\n", *ptr);
  switch (*ptr)
    {
    case GRUB_ACPI_OPCODE_PACKAGE:
    case GRUB_ACPI_OPCODE_BUFFER:
      return 1 + decode_length (ptr + 1, 0);
    case GRUB_ACPI_OPCODE_ZERO:
    case GRUB_ACPI_OPCODE_ONES:
    case GRUB_ACPI_OPCODE_ONE:
      return 1;
    case GRUB_ACPI_OPCODE_BYTE_CONST:
      return 2;
    case GRUB_ACPI_OPCODE_WORD_CONST:
      return 3;
    case GRUB_ACPI_OPCODE_DWORD_CONST:
      return 5;
    case GRUB_ACPI_OPCODE_STRING_CONST:
      {
	const grub_uint8_t *ptr0 = ptr;
	for (ptr++; ptr < end && *ptr; ptr++);
	if (ptr == end)
	  return 0;
	return ptr - ptr0 + 1;
      }
    default:
      if (*ptr == '^' || *ptr == '\\' || *ptr == '_'
	  || (*ptr >= 'A' && *ptr <= 'Z'))
	return skip_name_string (ptr, end);
      grub_printf ("Unknown opcode 0x%x\n", *ptr);
      return 0;
    }
}
Esempio n. 15
0
static inline grub_uint32_t
skip_ext_op (const grub_uint8_t *ptr, const grub_uint8_t *end)
{
  const grub_uint8_t *ptr0 = ptr;
  int add;
  grub_dprintf ("acpi", "Extended opcode: 0x%x\n", *ptr);
  switch (*ptr)
    {
    case GRUB_ACPI_EXTOPCODE_MUTEX:
      ptr++;
      ptr += skip_name_string (ptr, end);
      ptr++;
      break;
    case GRUB_ACPI_EXTOPCODE_OPERATION_REGION:
      ptr++;
      ptr += skip_name_string (ptr, end);
      ptr++;
      ptr += add = skip_data_ref_object (ptr, end);
      if (!add)
	return 0;
      ptr += add = skip_data_ref_object (ptr, end);
      if (!add)
	return 0;
      break;
    case GRUB_ACPI_EXTOPCODE_FIELD_OP:
    case GRUB_ACPI_EXTOPCODE_INDEX_FIELD_OP:
      ptr++;
      ptr += decode_length (ptr, 0);
      break;
    default:
      grub_printf ("Unexpected extended opcode: 0x%x\n", *ptr);
      return 0;
    }
  return ptr - ptr0;
}
Esempio n. 16
0
static grub_err_t
grub_cmd_time (grub_command_t ctxt __attribute__ ((unused)),
	       int argc, char **args)
{
  grub_command_t cmd;
  grub_uint32_t start;
  grub_uint32_t end;

  if (argc == 0)
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "command expected");

  cmd = grub_command_find (args[0]);

  if (!cmd)
    return grub_error (GRUB_ERR_UNKNOWN_COMMAND, "Unknown command `%s'\n",
		       args[0]);

  start = grub_get_time_ms ();
  (cmd->func) (cmd, argc - 1, &args[1]);
  end = grub_get_time_ms ();

  grub_printf ("Elapsed time: %d.%03d seconds \n", (end - start) / 1000,
	       (end - start) % 1000);

  return grub_errno;
}
Esempio n. 17
0
static void
set_scancodes (void)
{
  /* You must have visited computer museum. Keyboard without scancode set
     knowledge. Assume XT. */
  if (!grub_keyboard_orig_set)
    {
      grub_dprintf ("atkeyb", "No sets support assumed\n");
      current_set = 1;
      return;
    }

  grub_keyboard_controller_write (grub_keyboard_controller_orig
				  & ~KEYBOARD_AT_TRANSLATE);

  write_mode (2);
  current_set = query_mode ();
  grub_dprintf ("atkeyb", "returned set %d\n", current_set);
  if (current_set == 2)
    return;

  write_mode (1);
  current_set = query_mode ();
  grub_dprintf ("atkeyb", "returned set %d\n", current_set);
  if (current_set == 1)
    return;
  grub_printf ("No supported scancode set found\n");
}
Esempio n. 18
0
File: ls.c Progetto: hisilicon/grub
static grub_err_t
grub_ls_list_devices (int longlist)
{
  grub_device_iterate (grub_ls_print_devices, &longlist);
  grub_xputs ("\n");

#if 0
  {
    grub_net_app_level_t proto;
    int first = 1;
    FOR_NET_APP_LEVEL (proto)
    {
      if (first)
	grub_puts_ (N_ ("Network protocols:"));
      first = 0;
      grub_printf ("%s ", proto->name);
    }
    grub_xputs ("\n");
  }
#endif

  grub_refresh ();

  return 0;
}
Esempio n. 19
0
static int NESTED_FUNC_ATTR
scan_card (grub_pci_device_t dev, grub_pci_id_t pciid)
{
  grub_pci_address_t addr;

  addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
  if (grub_pci_read_byte (addr + 3) == 0x3)
    {
      struct grub_video_patch *p = video_patches;

      while (p->name)
	{
	  if (p->pci_id == pciid)
	    {
	      grub_target_addr_t base;

	      grub_printf ("Found graphic card: %s\n", p->name);
	      addr += 8 + p->mmio_bar * 4;
	      base = grub_pci_read (addr);
	      if ((! base) || (base & GRUB_PCI_ADDR_SPACE_IO) ||
		  (base & GRUB_PCI_ADDR_MEM_PREFETCH))
		grub_printf ("Invalid MMIO bar %d\n", p->mmio_bar);
	      else
		{
		  base &= GRUB_PCI_ADDR_MEM_MASK;
		  base += p->mmio_reg;

		  if (*((volatile grub_uint32_t *) base) != p->mmio_old)
		    grub_printf ("Old value don't match\n");
		  else
		    {
		      *((volatile grub_uint32_t *) base) = 0;
		      if (*((volatile grub_uint32_t *) base))
			grub_printf ("Set MMIO fails\n");
		    }
		}

	      return 1;
	    }
	  p++;
	}

      grub_printf ("Unknown graphic card: %x\n", pciid);
    }

  return 0;
}
Esempio n. 20
0
/* Helper for grub_claim_heap.  */
static int
heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type,
	   void *data)
{
  unsigned long *total = data;

  if (type != GRUB_MEMORY_AVAILABLE)
    return 0;

  if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM))
    {
      if (addr + len <= 0x180000)
	return 0;

      if (addr < 0x180000)
	{
	  len = addr + len - 0x180000;
	  addr = 0x180000;
	}
    }
  len -= 1; /* Required for some firmware.  */

  /* Never exceed HEAP_MAX_SIZE  */
  if (*total + len > HEAP_MAX_SIZE)
    len = HEAP_MAX_SIZE - *total;

  /* Avoid claiming anything above HEAP_MAX_ADDR, if possible. */
  if ((addr < HEAP_MAX_ADDR) &&				/* if it's too late, don't bother */
      (addr + len > HEAP_MAX_ADDR) &&				/* if it wasn't available anyway, don't bother */
      (*total + (HEAP_MAX_ADDR - addr) > HEAP_MIN_SIZE))	/* only limit ourselves when we can afford to */
     len = HEAP_MAX_ADDR - addr;

  /* In theory, firmware should already prevent this from happening by not
     listing our own image in /memory/available.  The check below is intended
     as a safeguard in case that doesn't happen.  However, it doesn't protect
     us from corrupting our module area, which extends up to a
     yet-undetermined region above _end.  */
  if ((addr < (grub_addr_t) _end) && ((addr + len) > (grub_addr_t) _start))
    {
      grub_printf ("Warning: attempt to claim over our own code!\n");
      len = 0;
    }

  if (len)
    {
      grub_err_t err;
      /* Claim and use it.  */
      err = grub_claimmap (addr, len);
      if (err)
	return err;
      grub_mm_init_region ((void *) (grub_addr_t) addr, len);
    }

  *total += len;
  if (*total >= HEAP_MAX_SIZE)
    return 1;

  return 0;
}
Esempio n. 21
0
void
grub_machine_set_prefix (void)
{
#ifndef __i386__
  char bootpath[64]; /* XXX check length */
  char *filename;
  char *prefix;
#endif

  if (grub_prefix[0])
    {
      grub_env_set ("prefix", grub_prefix);
      /* Prefix is hardcoded in the core image.  */
      return;
    }

#ifdef __i386__
  grub_env_set ("prefix", "(sd,1)/");
#else
  if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", &bootpath,
				  sizeof (bootpath), 0))
    {
      /* Should never happen.  */
      grub_printf ("/chosen/bootpath property missing!\n");
      grub_env_set ("prefix", "");
      return;
    }

  /* Transform an OF device path to a GRUB path.  */

  prefix = grub_ieee1275_encode_devname (bootpath);

  filename = grub_ieee1275_get_filename (bootpath);
  if (filename)
    {
      char *newprefix;
      char *lastslash = grub_strrchr (filename, '\\');

      /* Truncate at last directory.  */
      if (lastslash)
        {
	  *lastslash = '\0';
	  grub_translate_ieee1275_path (filename);

	  newprefix = grub_xasprintf ("%s%s", prefix, filename);
	  if (newprefix)
	    {
	      grub_free (prefix);
	      prefix = newprefix;
	    }
	}
    }

  grub_env_set ("prefix", prefix);

  grub_free (filename);
  grub_free (prefix);
#endif
}
Esempio n. 22
0
static void
do_print (int n)
{
  grub_term_restore_pos (pos);
  /* NOTE: Do not remove the trailing space characters.
     They are required to clear the line.  */
  grub_printf ("%d    ", n);
}
Esempio n. 23
0
void
grub_parse_color_name_pair (grub_uint8_t *ret, const char *name)
{
  grub_uint8_t fg, bg;
  char *fg_name, *bg_name;

  /* nothing specified by user */
  if (name == NULL)
    return;

  fg_name = grub_strdup (name);
  if (fg_name == NULL)
    {
      /* "out of memory" message was printed by grub_strdup() */
      grub_wait_after_message ();
      return;
    }

  bg_name = grub_strchr (fg_name, '/');
  if (bg_name == NULL)
    {
      grub_printf ("Warning: syntax error (missing slash) in `%s'\n", fg_name);
      grub_wait_after_message ();
      goto free_and_return;
    }

  *(bg_name++) = '\0';

  if (parse_color_name (&fg, fg_name) == -1)
    {
      grub_printf ("Warning: invalid foreground color `%s'\n", fg_name);
      grub_wait_after_message ();
      goto free_and_return;
    }
  if (parse_color_name (&bg, bg_name) == -1)
    {
      grub_printf ("Warning: invalid background color `%s'\n", bg_name);
      grub_wait_after_message ();
      goto free_and_return;
    }

  *ret = (bg << 4) | fg;

free_and_return:
  grub_free (fg_name);
}
Esempio n. 24
0
void
init_page (void)
{
  cls ();

  grub_printf ("\n    GNU GRUB  version %s  (%dK lower / %dK upper memory)\n\n",
	  version_string, mbi.mem_lower, mbi.mem_upper);
}
Esempio n. 25
0
grub_err_t
grub_rescue_parse_line (char *line,
			grub_reader_getline_t getline, void *getline_data)
{
  char *name;
  int n;
  grub_command_t cmd;
  char **args;

  if (grub_parser_split_cmdline (line, getline, getline_data, &n, &args)
      || n < 0)
    return grub_errno;

  if (n == 0)
    return GRUB_ERR_NONE;

  /* In case of an assignment set the environment accordingly
     instead of calling a function.  */
  if (n == 1)
    {
      char *val = grub_strchr (args[0], '=');

      if (val)
	{
	  val[0] = 0;
	  grub_env_set (args[0], val + 1);
	  val[0] = '=';
	  goto quit;
	}
    }

  /* Get the command name.  */
  name = args[0];

  /* If nothing is specified, restart.  */
  if (*name == '\0')
    goto quit;

  cmd = grub_command_find (name);
  if (cmd)
    {
      (cmd->func) (cmd, n - 1, &args[1]);
    }
  else
    {
      grub_printf_ (N_("Unknown command `%s'.\n"), name);
      if (grub_command_find ("help"))
	grub_printf ("Try `help' for usage\n");
    }

 quit:
  /* Arguments are returned in single memory chunk separated by zeroes */
  grub_free (args[0]);
  grub_free (args);

  return grub_errno;
}
Esempio n. 26
0
File: compat.c Progetto: xk/bits
int vfprintf(FILE *stream, const char *format, va_list args)
{
    grub_errno = GRUB_ERR_NONE;
    if (stream != stdout && stream != stderr) {
        grub_printf("Internal error: Python attempted to write to a file.\n");
        return -1;
    }
    return grub_vprintf(format, args);
}
Esempio n. 27
0
static void
grub_uitree_dump_padding (int level)
{
  while (level > 0)
    {
      grub_printf ("  ");
      level--;
    }
}
Esempio n. 28
0
void
print_sha1( grub_uint8_t *inDigest ) {

	/* print SHA1 hash of input */
	unsigned int j;
	for( j = 0; j < SHA1_DIGEST_SIZE; j++ ) {
		grub_printf( "%02x", inDigest[j] );
	}
}
Esempio n. 29
0
File: compat.c Progetto: xk/bits
FILE *fopen(const char *path, const char *mode)
{
    grub_errno = GRUB_ERR_NONE;
    if (grub_strcmp(mode, "r") != 0 && grub_strcmp(mode, "rb") != 0) {
        grub_printf("Internal error: Python attempted to open a file with unsupported mode \"%s\"\n", mode);
        return NULL;
    }
    return grub_file_open(path);
}
Esempio n. 30
0
static void
usb_print_str (const char *description, grub_usb_device_t dev, int idx)
{
  char *name = NULL;
  grub_usb_err_t err;
  /* XXX: LANGID  */

  if (! idx)
    return;

  err = grub_usb_get_string (dev, idx, 0x0409, &name);
  if (err)
    grub_printf ("Error %d retrieving %s\n", err, description);
  else
    {
      grub_printf ("%s: `%s'\n", description, name);
      grub_free (name);
    }
}