📄 disk_io.c
字号:
//if (debug == -2) grub_printf ("real_open_partition: outer loop: 003\n"); while (next_part ()) {//if (debug == -2) grub_printf ("real_open_partition: inner loop: 004\n"); if (bsd_part_no == 0xFF) break; if (! got_part) { grub_printf ("[BSD sub-partitions immediately follow]\n"); got_part = 1; } grub_printf (" BSD Partition num: \'%c\', ", bsd_part_no + 'a'); check_and_print_mount (); } if (! got_part) grub_printf (" No BSD sub-partition found, partition type 0x%x\n", saved_slice); if (errnum) { errnum = ERR_NONE; break; } goto loop_start; } } else {//if (debug == -2) grub_printf ("real_open_partition: outer loop: 005\n"); if (bsd_part_no != 0xFF) { char str[16]; if (! (current_drive & 0x80) || (dest_partition >> 16) == pc_slice_no) grub_sprintf (str, "%c)", bsd_part_no + 'a'); else grub_sprintf (str, "%d,%c)", pc_slice_no, bsd_part_no + 'a'); print_a_completion (str); } else if (! IS_PC_SLICE_TYPE_BSD (current_slice)) { char str[8];//if (debug == -2) grub_printf ("real_open_partition: outer loop: 006\n"); grub_sprintf (str, "%d)", pc_slice_no); print_a_completion (str); } } }//if (debug == -2) grub_printf ("real_open_partition: outer loop: 007\n"); errnum = ERR_NONE;#endif /* ! STAGE1_5 */ /* Check if this is the destination partition. */ if (! flags && (dest_partition == current_partition || ((dest_partition >> 16) == 0xFF && ((dest_partition >> 8) & 0xFF) == bsd_part_no))) return 1;#ifndef STAGE1_5//if (debug == -2) grub_printf ("real_open_partition: outer loop: 008\n");#endif /* ! STAGE1_5 */ }#ifndef STAGE1_5//if (debug == -2) grub_printf ("real_open_partition: outer loop: 009\n");#endif /* ! STAGE1_5 */ }#ifndef STAGE1_5//if (debug == -2) grub_printf ("real_open_partition: outer loop: 010\n");#endif /* ! STAGE1_5 */#ifndef STAGE1_5 if (flags) { if (! (current_drive & 0x80)) { current_partition = 0xFFFFFF; check_and_print_mount (); }//if (debug == -2) grub_printf ("real_open_partition: outer loop: 011\n"); errnum = ERR_NONE; return 1; }#endif /* ! STAGE1_5 */#ifndef STAGE1_5//if (debug == -2) grub_printf ("real_open_partition: outer loop: 012\n");#endif /* ! STAGE1_5 */ return 0;}intopen_partition (void){ return real_open_partition (0);}#ifndef STAGE1_5static intsane_partition (void){// /* network drive */// if (current_drive == NETWORK_DRIVE)// return 1;//// /* ram drive */// if (current_drive == ram_drive)// return 1; if (!(current_partition & 0xFF000000uL) /* the drive field must be 0 */// && ((current_drive & 0xFFFFFF7F) < 8 /* and the drive must be < 8 ... */// || current_drive == cdrom_drive) /* ... or it is cdrom */ && (current_partition & 0xFF) == 0xFF /* the low byte is not used and must be 0xFF */ && ((current_partition & 0xFF00) == 0xFF00 /* the higher byte must be 0xFF for normal ... */ || (current_partition & 0xFF00) < 0x800) /* ... or < 8 for BSD partitions */ && ((current_partition >> 16) == 0xFF /* the partition field must be whole-drive for floppy */ || (current_drive & 0x80))) /* ... or it is hard drive */ return 1; errnum = ERR_DEV_VALUES; return 0;}#endif /* ! STAGE1_5 *//* Parse a device string and initialize the global parameters. */char *set_device (char *device){#ifdef STAGE1_5 /* In Stage 1.5, the first 4 bytes of FILENAME has a device number. */ unsigned long dev = *((unsigned long *) device); unsigned long drive = (dev >> 24) & 0xFF; unsigned long partition = dev & 0xFFFFFF; /* If DRIVE is disabled, use SAVED_DRIVE instead. */ if (drive == 0xFF/*GRUB_INVALID_DRIVE*/) current_drive = saved_drive; else current_drive = drive; /* The `partition' part must always have a valid number. */ current_partition = partition; errnum = 0; return device + sizeof (unsigned long);#else /* ! STAGE1_5 */ int result = 0; errnum = 0; incomplete = 0; disk_choice = 1; part_choice = PART_UNSPECIFIED; current_drive = saved_drive; current_partition = 0xFFFFFF; if (*device == '(' && !*(device + 1)) /* user has given '(' only, let disk_choice handle what disks we have */ return device + 1; if (*device == '(' && *(++device)) { if (*device == ')') /* the device "()" is for the current root */ { current_partition = saved_partition; return device + 1; } if (*device != ',' /* && *device != ')' */ ) { char ch = *device; if (*device == 'f' || *device == 'h' || *device == 'm' || *device == 'r'#ifdef SUPPORT_NETBOOT || (*device == 'n' && network_ready)#endif /* SUPPORT_NETBOOT */#ifdef FSYS_PXE || (*device == 'p' && pxe_entry)#endif /* FSYS_PXE */#ifndef GRUB_UTIL || (*device == 'c' && (cdrom_drive != GRUB_INVALID_DRIVE || atapi_dev_count)))#else || (*device == 'c' && cdrom_drive != GRUB_INVALID_DRIVE))#endif { /* user has given '([fhn]', check for resp. add 'd' and let disk_choice handle what disks we have */ if (!*(device + 1)) { device++; *device++ = 'd'; *device = '\0'; return device; } else if (*(device + 1) == 'd' && !*(device + 2)) return device + 2; } if ((*device == 'f' || *device == 'h' || *device == 'm' || *device == 'r'#ifdef SUPPORT_NETBOOT || (*device == 'n' && network_ready)#endif#ifdef FSYS_PXE || (*device == 'p' && pxe_entry)#endif#ifndef GRUB_UTIL || (*device == 'c' && (cdrom_drive != GRUB_INVALID_DRIVE || atapi_dev_count)))#else || (*device == 'c' && cdrom_drive != GRUB_INVALID_DRIVE))#endif && *(++device, device++) != 'd') errnum = ERR_NUMBER_PARSING;#ifdef SUPPORT_NETBOOT if (ch == 'n' && network_ready) current_drive = NETWORK_DRIVE; else#endif /* SUPPORT_NETBOOT */#ifdef FSYS_PXE if (ch == 'p' && pxe_entry) current_drive = PXE_DRIVE; else#endif /* FSYS_PXE */ { if (ch == 'c' && cdrom_drive != GRUB_INVALID_DRIVE && *device == ')') current_drive = cdrom_drive; else if (ch == 'm') current_drive = 0xffff; else if (ch == 'r') current_drive = ram_drive; else { safe_parse_maxint (&device, (int *)(void *) ¤t_drive); disk_choice = 0; if (ch == 'h') current_drive |= 0x80;#ifndef GRUB_UTIL //else if (ch == 'c' && cdrom_drive != GRUB_INVALID_DRIVE && current_drive < 8) //{ // if (cdrom_drives[current_drive] != GRUB_INVALID_DRIVE) // current_drive = cdrom_drives[current_drive]; //} else if (ch == 'c' && atapi_dev_count && current_drive < atapi_dev_count) { current_drive += min_cdrom_id; }#endif } } } if (errnum) return 0; if (*device == ')') { part_choice = PART_CHOSEN; result = 1; } else if (*device == ',') { /* Either an absolute PC or BSD partition. */ disk_choice = 0; part_choice ++; device++; if (*device >= '0' && *device <= '9') { part_choice ++; current_partition = 0; if (!(current_drive & 0x80) || !safe_parse_maxint (&device, (int *)(void *) ¤t_partition) || current_partition > 254) { errnum = ERR_DEV_FORMAT; return 0; } current_partition = (current_partition << 16) + 0xFFFF; if (*device == ',') device++; if (*device >= 'a' && *device <= 'h') { current_partition = (((*(device++) - 'a') << 8) | (current_partition & 0xFF00FF)); } } else if (*device >= 'a' && *device <= 'h') { part_choice ++; current_partition = ((*(device++) - 'a') << 8) | 0xFF00FF; } if (*device == ')') { if (part_choice == PART_DISK) { current_partition = saved_partition; part_choice ++; } result = 1; } } } if (! sane_partition ()) return 0; if (result) return device + 1; else { if (!*device) incomplete = 1; errnum = ERR_DEV_FORMAT; } return 0;#endif /* ! STAGE1_5 */}static char *setup_part (char *filename){ relative_path = 1;#ifdef STAGE1_5 if (! (filename = set_device (filename))) { current_drive = GRUB_INVALID_DRIVE; return 0; }# ifndef NO_BLOCK_FILES if (*filename != '/') open_partition (); else# endif /* ! NO_BLOCK_FILES */ open_device ();#else /* ! STAGE1_5 */ if (*filename == '(') { relative_path = 0; if ((filename = set_device (filename)) == 0) { current_drive = GRUB_INVALID_DRIVE; return 0; }# ifndef NO_BLOCK_FILES if (*filename != '/') open_partition (); else# endif /* ! NO_BLOCK_FILES */ open_device (); } else if (saved_drive != current_drive || saved_partition != current_partition || (*filename == '/' && fsys_type == NUM_FSYS) || buf_drive == -1) { current_drive = saved_drive; current_partition = saved_partition; /* allow for the error case of "no filesystem" after the partition is found. This makes block files work fine on no filesystem */# ifndef NO_BLOCK_FILES if (*filename != '/') open_partition (); else# endif /* ! NO_BLOCK_FILES */ open_device (); }#endif /* ! STAGE1_5 */ if (errnum && (*filename == '/' || errnum != ERR_FSYS_MOUNT)) return 0; else errnum = 0;#ifndef STAGE1_5 if (!sane_partition ()) return 0;#endif return filename;}#ifndef STAGE1_5///* Reposition a file offset. *///unsigned long//grub_seek (unsigned long offset)//{// if (offset > filemax /*|| offset < 0*/)// return -1;//// filepos = offset;// return offset;//}intdir (char *dirname){#ifndef NO_DECOMPRESSION compressed_file = 0;#endif /* NO_DECOMPRESSION */ if (!(dirname = setup_part (dirname))) return 0; if (*dirname != '/') errnum = ERR_BAD_FILENAME; if (fsys_type == NUM_FSYS) errnum = ERR_FSYS_MOUNT; if (relative_path) if (grub_strlen(saved_dir) + grub_strlen(dirname) >= sizeof(open_filename)) errnum = ERR_WONT_FIT; if (errnum) return 0; /* set "dir" function to list completions */ print_possibilities = 1; if (relative_path) grub_sprintf (open_filename, "%s%s", saved_dir, dirname); return (*(fsys_table[fsys_type].dir_func)) (relative_path ? open_filename : dirname);}#endif /* STAGE1_5 */#ifndef STAGE1_5/* If DO_COMPLETION is true, just print NAME. Otherwise save the unique part into UNIQUE_STRING. */voidprint_a_completion (char *name){ /* If NAME is "." or "..", do not count it. */ if (grub_strcmp (name, ".") == 0 || grub_strcmp (name, "..") == 0) return; if (do_completion) { char *buf = unique_string; if (! unique) while ((*buf++ = *name++)) ; else { while (*buf && (*buf == *name)) { buf++; name++; } /* mismatch, strip it. */ *buf = '\0'; } } else grub_printf (" %s", name); unique++;}/* * This lists the possible completions of a device string, filename, or * any sane combination of the two. */intprint_completions (int is_filename, int is_completion){ char *buf = (char *) COMPLETION_BUF; char *ptr = buf; unique_string = (char *) UNIQUE_BUF; *unique_string = 0; unique = 0; do_completion = is_completion;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -