📄 builtins.c
字号:
return 0;}static struct builtin builtin_embed ={ "embed", embed_func, BUILTIN_CMDLINE, "embed STAGE1_5 DEVICE", "Embed the Stage 1.5 STAGE1_5 in the sectors after MBR if DEVICE" " is a drive, or in the \"bootloader\" area if DEVICE is a FFS partition." " Print the number of sectors which STAGE1_5 occupies if successful."};/* fallback */static intfallback_func (char *arg, int flags){ if (! safe_parse_maxint (&arg, &fallback_entry)) return 1; return 0;}static struct builtin builtin_fallback ={ "fallback", fallback_func, BUILTIN_MENU,#if 0 "fallback NUM", "Go into unattended boot mode: if the default boot entry has any" " errors, instead of waiting for the user to do anything, it" " immediately starts over using the NUM entry (same numbering as the" " `default' command). This obviously won't help if the machine" " was rebooted by a kernel that GRUB loaded."#endif};/* find *//* Search for the filename ARG in all of partitions. */static intfind_func (char *arg, int flags){ char *filename = arg; unsigned long drive; unsigned long tmp_drive = saved_drive; unsigned long tmp_partition = saved_partition; int got_file = 0; /* Floppies. */ for (drive = 0; drive < 8; drive++) { current_drive = drive; current_partition = 0xFFFFFF; if (open_device ()) { saved_drive = current_drive; saved_partition = current_partition; if (grub_open (filename)) { grub_close (); grub_printf (" (fd%d)\n", drive); got_file = 1; } } errnum = ERR_NONE; } /* Hard disks. */ for (drive = 0x80; drive < 0x88; drive++) { unsigned long part = 0xFFFFFF; unsigned long start, len, offset, ext_offset; int type, entry; char buf[SECTOR_SIZE]; current_drive = drive; while (next_partition (drive, 0xFFFFFF, &part, &type, &start, &len, &offset, &entry, &ext_offset, buf)) { if (type != PC_SLICE_TYPE_NONE && ! IS_PC_SLICE_TYPE_BSD (type) && ! IS_PC_SLICE_TYPE_EXTENDED (type)) { current_partition = part; if (open_device ()) { saved_drive = current_drive; saved_partition = current_partition; if (grub_open (filename)) { int bsd_part = (part >> 8) & 0xFF; int pc_slice = part >> 16; grub_close (); if (bsd_part == 0xFF) grub_printf (" (hd%d,%d)\n", drive - 0x80, pc_slice); else grub_printf (" (hd%d,%d,%c)\n", drive - 0x80, pc_slice, bsd_part + 'a'); got_file = 1; } } } /* We want to ignore any error here. */ errnum = ERR_NONE; } /* next_partition always sets ERRNUM in the last call, so clear it. */ errnum = ERR_NONE; } saved_drive = tmp_drive; saved_partition = tmp_partition; if (got_file) { errnum = ERR_NONE; return 0; } errnum = ERR_FILE_NOT_FOUND; return 1;}static struct builtin builtin_find ={ "find", find_func, BUILTIN_CMDLINE | BUILTIN_HELP_LIST, "find FILENAME", "Search for the filename FILENAME in all of partitions and print the list of" " the devices which contain the file."};/* fstest */static intfstest_func (char *arg, int flags){ if (disk_read_hook) { disk_read_hook = NULL; printf (" Filesystem tracing is now off\n"); } else { disk_read_hook = disk_read_print_func; printf (" Filesystem tracing is now on\n"); } return 0;}static struct builtin builtin_fstest ={ "fstest", fstest_func, BUILTIN_CMDLINE, "fstest", "Toggle filesystem test mode."};/* geometry */static intgeometry_func (char *arg, int flags){ struct geometry geom; char *msg; char *device = arg;#ifdef GRUB_UTIL char *ptr;#endif /* Get the device number. */ set_device (device); if (errnum) return 1; /* Check for the geometry. */ if (get_diskinfo (current_drive, &geom)) { errnum = ERR_NO_DISK; return 1; } /* Attempt to read the first sector, because some BIOSes turns out not to support LBA even though they set the bit 0 in the support bitmap, only after reading something actually. */ if (biosdisk (BIOSDISK_READ, current_drive, &geom, 0, 1, SCRATCHSEG)) { errnum = ERR_READ; return 1; }#ifdef GRUB_UTIL ptr = skip_to (0, device); if (*ptr) { char *cylinder, *head, *sector, *total_sector; int num_cylinder, num_head, num_sector, num_total_sector; cylinder = ptr; head = skip_to (0, cylinder); sector = skip_to (0, head); total_sector = skip_to (0, sector); if (! safe_parse_maxint (&cylinder, &num_cylinder) || ! safe_parse_maxint (&head, &num_head) || ! safe_parse_maxint (§or, &num_sector)) return 1; disks[current_drive].cylinders = num_cylinder; disks[current_drive].heads = num_head; disks[current_drive].sectors = num_sector; if (safe_parse_maxint (&total_sector, &num_total_sector)) disks[current_drive].total_sectors = num_total_sector; else disks[current_drive].total_sectors = num_cylinder * num_head * num_sector; errnum = 0; geom = disks[current_drive]; buf_drive = -1; }#endif /* GRUB_UTIL */#ifdef GRUB_UTIL msg = device_map[current_drive];#else if (geom.flags & BIOSDISK_FLAG_LBA_EXTENSION) msg = "LBA"; else msg = "CHS";#endif grub_printf ("drive 0x%x: C/H/S = %d/%d/%d, " "The number of sectors = %d, %s\n", current_drive, geom.cylinders, geom.heads, geom.sectors, geom.total_sectors, msg); real_open_partition (1); return 0;}static struct builtin builtin_geometry ={ "geometry", geometry_func, BUILTIN_CMDLINE | BUILTIN_HELP_LIST, "geometry DRIVE [CYLINDER HEAD SECTOR [TOTAL_SECTOR]]", "Print the information for a drive DRIVE. In the grub shell, you can" " set the geometry of the drive arbitrarily. The number of the cylinders," " the one of the heads, the one of the sectors and the one of the total" " sectors are set to CYLINDER, HEAD, SECTOR and TOTAL_SECTOR," " respectively. If you omit TOTAL_SECTOR, then it will be calculated based" " on the C/H/S values automatically."};/* halt */static inthalt_func (char *arg, int flags){ int no_apm; no_apm = (grub_memcmp (arg, "--no-apm", 8) == 0); grub_halt (no_apm); /* Never reach here. */ return 1;}static struct builtin builtin_halt ={ "halt", halt_func, BUILTIN_CMDLINE | BUILTIN_HELP_LIST, "halt [--no-apm]", "Halt your system. If APM is avaiable on it, turn off the power using" " the APM BIOS, unless you specify the option `--no-apm'."};/* help */#define MAX_SHORT_DOC_LEN 39#define MAX_LONG_DOC_LEN 66static inthelp_func (char *arg, int flags){ int all = 0; if (grub_memcmp (arg, "--all", sizeof ("--all") - 1) == 0) { all = 1; arg = skip_to (0, arg); } if (! *arg) { /* Invoked with no argument. Print the list of the short docs. */ struct builtin **builtin; int left = 1; for (builtin = builtin_table; *builtin != 0; builtin++) { int len; int i; /* If this cannot be used in the command-line interface, skip this. */ if (! ((*builtin)->flags & BUILTIN_CMDLINE)) continue; /* If this doesn't need to be listed automatically and "--all" is not specified, skip this. */ if (! all && ! ((*builtin)->flags & BUILTIN_HELP_LIST)) continue; len = grub_strlen ((*builtin)->short_doc); /* If the length of SHORT_DOC is too long, truncate it. */ if (len > MAX_SHORT_DOC_LEN - 1) len = MAX_SHORT_DOC_LEN - 1; for (i = 0; i < len; i++) grub_putchar ((*builtin)->short_doc[i]); for (; i < MAX_SHORT_DOC_LEN; i++) grub_putchar (' '); if (! left) grub_putchar ('\n'); left = ! left; } /* If the last entry was at the left column, no newline was printed at the end. */ if (! left) grub_putchar ('\n'); } else { /* Invoked with one or more patterns. */ do { struct builtin **builtin; char *next_arg; /* Get the next argument. */ next_arg = skip_to (0, arg); /* Terminate ARG. */ nul_terminate (arg); for (builtin = builtin_table; *builtin; builtin++) { /* Skip this if this is only for the configuration file. */ if (! ((*builtin)->flags & BUILTIN_CMDLINE)) continue; if (substring (arg, (*builtin)->name) < 1) { char *doc = (*builtin)->long_doc; /* At first, print the name and the short doc. */ grub_printf ("%s: %s\n", (*builtin)->name, (*builtin)->short_doc); /* Print the long doc. */ while (*doc) { int len = grub_strlen (doc); int i; /* If LEN is too long, fold DOC. */ if (len > MAX_LONG_DOC_LEN) { /* Fold this line at the position of a space. */ for (len = MAX_LONG_DOC_LEN; len > 0; len--) if (doc[len - 1] == ' ') break; } grub_printf (" "); for (i = 0; i < len; i++) grub_putchar (*doc++); grub_putchar ('\n'); } } } arg = next_arg; } while (*arg); } return 0;}static struct builtin builtin_help ={ "help", help_func, BUILTIN_CMDLINE | BUILTIN_HELP_LIST, "help [--all] [PATTERN ...]", "Display helpful information about builtin commands. Not all commands" " aren't shown without the option `--all'."};/* hiddenmenu */static inthiddenmenu_func (char *arg, int flags){ show_menu = 0; return 0;}static struct builtin builtin_hiddenmenu ={ "hiddenmenu", hiddenmenu_func, BUILTIN_MENU,#if 0 "hiddenmenu", "Hide the menu."#endif};/* hide */static inthide_func (char *arg, int flags){ if (! set_device (arg)) return 1; if (! set_partition_hidden_flag (1)) return 1; return 0;}static struct builtin builtin_hide ={ "hide", hide_func, BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST, "hide PARTITION", "Hide PARTITION by setting the \"hidden\" bit in" " its partition type code."};#ifdef SUPPORT_NETBOOT/* ifconfig */static intifconfig_func (char *arg, int flags){ char *svr = 0, *ip = 0, *gw = 0, *sm = 0; if (! eth_probe ()) { grub_printf ("No ethernet card found.\n"); errnum = ERR_DEV_VALUES; return 1; } while (*arg) { if (! grub_memcmp ("--server=", arg, sizeof ("--server=") - 1)) svr = arg + sizeof("--server=") - 1; else if (! grub_memcmp ("--address=", arg, sizeof ("--address=") - 1)) ip = arg + sizeof ("--address=") - 1; else if (! grub_memcmp ("--gateway=", arg, sizeof ("--gateway=") - 1)) gw = arg + sizeof ("--gateway=") - 1; else if (! grub_memcmp ("--mask=", arg, sizeof("--mask=") - 1)) sm = arg + sizeof ("--mask=") - 1; else { errnum = ERR_BAD_ARGUMENT; return 1; } arg = skip_to (0, arg); } if (! ifconfig (ip, sm, gw, svr)) { errnum = ERR_BAD_ARGUMENT; return 1; } print_network_configuration (); return 0;}static struct builtin builtin_ifconfig ={ "ifconfig", ifconfig_func, BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST, "ifconfig [--address=IP] [--gateway=IP] [--mask=MASK] [--server=IP]", "Configure the IP address, the netmask, the gateway and the server" " address or print current network configuration."};#endif /* SUPPORT_NETBOOT *//* impsprobe */static intimpsprobe_func (char *arg, int flags){#ifdef GRUB_UTIL /* In the grub shell, we cannot probe IMPS. */ errnum = ERR_UNRECOGNIZED; return 1;#else /* ! GRUB_UTIL */ if (!imps_probe ()) printf (" No MPS information found or probe failed\n"); return 0;#endif /* ! GRUB_UTIL */}static struct builtin builtin_impsprobe ={ "impsprobe", impsprobe_func, BUILTIN_CMDLINE, "impsprobe", "Probe the Intel Multiprocessor Specification 1.1 or 1.4" " configuration table and boot the various CPUs which are found into" " a tight loop."};/* initrd */static intinitrd_func (char *arg, int flags){ switch (kernel_type) { case KERNEL_TYPE_LINUX: case KERNEL_TYPE_BIG_LINUX: if (! load_initrd (arg)) return 1; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -