⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stage2.c

📁 i386的bootloader源码grub
💻 C
📖 第 1 页 / 共 2 页
字号:
			first_entry++;		      		      c = 'O';		    }		  cur_entry = get_entry (menu_entries,					 first_entry + entryno,					 0);		  if (c == 'O')		    {		      grub_memmove (cur_entry + 2, cur_entry,				    ((int) heap) - ((int) cur_entry));		      cur_entry[0] = ' ';		      cur_entry[1] = 0;		      heap += 2;		      num_entries++;		    }		  else if (num_entries > 0)		    {		      char *ptr = get_entry(menu_entries,					    first_entry + entryno + 1,					    0);		      grub_memmove (cur_entry, ptr,				    ((int) heap) - ((int) ptr));		      heap -= (((int) ptr) - ((int) cur_entry));		      num_entries--;		      if (entryno >= num_entries)			entryno--;		      if (first_entry && num_entries < 12 + first_entry)			first_entry--;		    }		  if (current_term->flags & TERM_DUMB)		    {		      grub_printf ("\n\n");		      print_entries_raw (num_entries, first_entry,					 menu_entries);		      grub_printf ("\n");		    }		  else		    print_entries (3, 12, first_entry, entryno, menu_entries);		}	      cur_entry = menu_entries;	      if (c == 27)		return;	      if (c == 'b')		break;	    }	  if (! auth && password)	    {	      if (c == 'p')		{		  /* Do password check here! */		  char entered[32];		  char *pptr = password;		  if (current_term->flags & TERM_DUMB)		    grub_printf ("\r                                    ");		  else		    gotoxy (1, 21);		  /* Wipe out the previously entered password */		  grub_memset (entered, 0, sizeof (entered));		  get_cmdline (" Password: ", entered, 31, '*', 0);		  while (! isspace (*pptr) && *pptr)		    pptr++;		  /* Make sure that PASSWORD is NUL-terminated.  */		  *pptr++ = 0;		  if (! check_password (entered, password, password_type))		    {		      char *new_file = config_file;		      while (isspace (*pptr))			pptr++;		      /* If *PPTR is NUL, then allow the user to use			 privileged instructions, otherwise, load			 another configuration file.  */		      if (*pptr != 0)			{			  while ((*(new_file++) = *(pptr++)) != 0)			    ;			  /* Make sure that the user will not have			     authority in the next configuration.  */			  auth = 0;			  return;			}		      else			{			  /* Now the user is superhuman.  */			  auth = 1;			  goto restart;			}		    }		  else		    {		      grub_printf ("Failed!\n      Press any key to continue...");		      getkey ();		      goto restart;		    }		}	    }	  else	    {	      if (c == 'e')		{		  int new_num_entries = 0, i = 0;		  char *new_heap;		  if (config_entries)		    {		      new_heap = heap;		      cur_entry = get_entry (config_entries,					     first_entry + entryno,					     1);		    }		  else		    {		      /* safe area! */		      new_heap = heap + NEW_HEAPSIZE + 1;		      cur_entry = get_entry (menu_entries,					     first_entry + entryno,					     0);		    }		  do		    {		      while ((*(new_heap++) = cur_entry[i++]) != 0);		      new_num_entries++;		    }		  while (config_entries && cur_entry[i]);		  /* this only needs to be done if config_entries is non-NULL,		     but it doesn't hurt to do it always */		  *(new_heap++) = 0;		  if (config_entries)		    run_menu (heap, NULL, new_num_entries, new_heap, 0);		  else		    {		      cls ();		      print_cmdline_message (0);		      new_heap = heap + NEW_HEAPSIZE + 1;		      saved_drive = boot_drive;		      saved_partition = install_partition;		      current_drive = GRUB_INVALID_DRIVE;		      if (! get_cmdline (PACKAGE " edit> ", new_heap,					 NEW_HEAPSIZE + 1, 0, 1))			{			  int j = 0;			  /* get length of new command */			  while (new_heap[j++])			    ;			  if (j < 2)			    {			      j = 2;			      new_heap[0] = ' ';			      new_heap[1] = 0;			    }			  /* align rest of commands properly */			  grub_memmove (cur_entry + j, cur_entry + i,					(int) heap - ((int) cur_entry + i));			  /* copy command to correct area */			  grub_memmove (cur_entry, new_heap, j);			  heap += (j - i);			}		    }		  goto restart;		}	      if (c == 'c')		{		  enter_cmdline (heap, 0);		  goto restart;		}#ifdef GRUB_UTIL	      if (c == 'q')		{		  /* The same as ``quit''.  */		  stop ();		}#endif	    }	}    }    /* Attempt to boot an entry.  */   boot_entry:    cls ();  setcursor (1);    while (1)    {      if (config_entries)	printf ("  Booting \'%s\'\n\n",		get_entry (menu_entries, first_entry + entryno, 0));      else	printf ("  Booting command-list\n\n");      if (! cur_entry)	cur_entry = get_entry (config_entries, first_entry + entryno, 1);      /* Set CURRENT_ENTRYNO for the command "savedefault".  */      current_entryno = first_entry + entryno;            if (run_script (cur_entry, heap))	{	  if (fallback_entry < 0)	    break;	  else	    {	      cur_entry = NULL;	      first_entry = 0;	      entryno = fallback_entry;	      fallback_entry = -1;	    }	}      else	break;    }  show_menu = 1;  goto restart;}static intget_line_from_config (char *cmdline, int maxlen, int read_from_file){  int pos = 0, literal = 0, comment = 0;  char c;  /* since we're loading it a byte at a time! */    while (1)    {      if (read_from_file)	{	  if (! grub_read (&c, 1))	    break;	}      else	{	  if (! read_from_preset_menu (&c, 1))	    break;	}      /* Skip all carriage returns.  */      if (c == '\r')	continue;      /* Replace tabs with spaces.  */      if (c == '\t')	c = ' ';      /* The previous is a backslash, then...  */      if (literal)	{	  /* If it is a newline, replace it with a space and continue.  */	  if (c == '\n')	    {	      c = ' ';	      	      /* Go back to overwrite a backslash.  */	      if (pos > 0)		pos--;	    }	    	  literal = 0;	}	        /* translate characters first! */      if (c == '\\' && ! literal)	literal = 1;      if (comment)	{	  if (c == '\n')	    comment = 0;	}      else if (! pos)	{	  if (c == '#')	    comment = 1;	  else if ((c != ' ') && (c != '\n'))	    cmdline[pos++] = c;	}      else	{	  if (c == '\n')	    break;	  if (pos < maxlen)	    cmdline[pos++] = c;	}    }  cmdline[pos] = 0;  return pos;}/* This is the starting function in C.  */voidcmain (void){  int config_len, menu_len, num_entries;  char *config_entries, *menu_entries;  char *kill_buf = (char *) KILL_BUF;  auto void reset (void);  void reset (void)    {      count_lines = -1;      config_len = 0;      menu_len = 0;      num_entries = 0;      config_entries = (char *) mbi.drives_addr + mbi.drives_length;      menu_entries = (char *) MENU_BUF;      init_config ();    }        /* Initialize the environment for restarting Stage 2.  */  grub_setjmp (restart_env);    /* Initialize the kill buffer.  */  *kill_buf = 0;  /* Never return.  */  for (;;)    {      int is_opened, is_preset;      reset ();            /* Here load the configuration file.  */      #ifdef GRUB_UTIL      if (use_config_file)#endif /* GRUB_UTIL */	{	  do	    {	      /* STATE 0:  Before any title command.		 STATE 1:  In a title command.		 STATE >1: In a entry after a title command.  */	      int state = 0, prev_config_len = 0, prev_menu_len = 0;	      char *cmdline;	      /* Try the preset menu first. This will succeed at most once,		 because close_preset_menu disables the preset menu.  */	      is_opened = is_preset = open_preset_menu ();	      if (! is_opened)		{		  is_opened = grub_open (config_file);		  errnum = ERR_NONE;		}	      if (! is_opened)		break;	      /* This is necessary, because the menu must be overrided.  */	      reset ();	      	      cmdline = (char *) CMDLINE_BUF;	      while (get_line_from_config (cmdline, NEW_HEAPSIZE,					   ! is_preset))		{		  struct builtin *builtin;		  		  /* Get the pointer to the builtin structure.  */		  builtin = find_command (cmdline);		  errnum = 0;		  if (! builtin)		    /* Unknown command. Just skip now.  */		    continue;		  		  if (builtin->flags & BUILTIN_TITLE)		    {		      char *ptr;		      		      /* the command "title" is specially treated.  */		      if (state > 1)			{			  /* The next title is found.  */			  num_entries++;			  config_entries[config_len++] = 0;			  prev_menu_len = menu_len;			  prev_config_len = config_len;			}		      else			{			  /* The first title is found.  */			  menu_len = prev_menu_len;			  config_len = prev_config_len;			}		      		      /* Reset the state.  */		      state = 1;		      		      /* Copy title into menu area.  */		      ptr = skip_to (1, cmdline);		      while ((menu_entries[menu_len++] = *(ptr++)) != 0)			;		    }		  else if (! state)		    {		      /* Run a command found is possible.  */		      if (builtin->flags & BUILTIN_MENU)			{			  char *arg = skip_to (1, cmdline);			  (builtin->func) (arg, BUILTIN_MENU);			  errnum = 0;			}		      else			/* Ignored.  */			continue;		    }		  else		    {		      char *ptr = cmdline;		      		      state++;		      /* Copy config file data to config area.  */		      while ((config_entries[config_len++] = *ptr++) != 0)			;		    }		}	      	      if (state > 1)		{		  /* Finish the last entry.  */		  num_entries++;		  config_entries[config_len++] = 0;		}	      else		{		  menu_len = prev_menu_len;		  config_len = prev_config_len;		}	      	      menu_entries[menu_len++] = 0;	      config_entries[config_len++] = 0;	      grub_memmove (config_entries + config_len, menu_entries,			    menu_len);	      menu_entries = config_entries + config_len;	      	      /* Check if the default entry is present. Otherwise reset		 it to fallback if fallback is valid, or to DEFAULT_ENTRY 		 if not.  */	      if (default_entry >= num_entries)		{		  if (fallback_entry < 0 || fallback_entry >= num_entries)		    default_entry = 0;		  else		    default_entry = fallback_entry;		}	      	      if (is_preset)		close_preset_menu ();	      else		grub_close ();	    }	  while (is_preset);	}      if (! num_entries)	{	  /* If no acceptable config file, goto command-line, starting	     heap from where the config entries would have been stored	     if there were any.  */	  enter_cmdline (config_entries, 1);	}      else	{	  /* Run menu interface.  */	  run_menu (menu_entries, config_entries, num_entries,		    menu_entries + menu_len, default_entry);	}    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -