Skip to content

Commit

Permalink
. 改进find函数的查找分区顺序为0,1,2....
Browse files Browse the repository at this point in the history
  改进有些UEFI固件返回大写字母无法识别的问题。 issues #423
  • Loading branch information
yaya2007 committed Aug 18, 2023
1 parent 2b155c9 commit aa78c12
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
4 changes: 4 additions & 0 deletions ChangeLog_UEFI.txt
@@ -1,4 +1,8 @@
更新说明:
2023-08-18 (yaya)
改进find函数的查找分区顺序为0,1,2....
改进有些UEFI固件返回大写字母无法识别的问题。 issues #423

2023-07-15 (yaya)
外部命令可以尾续压缩文件

Expand Down
22 changes: 13 additions & 9 deletions stage2/builtins.c
Expand Up @@ -7329,7 +7329,7 @@ void
add_part_data (int drive)
{
struct grub_part_data *p; //efi分区数据
struct grub_part_data *dp; //efi分区数据
struct grub_part_data *p_final; //efi分区数据
unsigned int back_saved_drive = saved_drive;
unsigned int back_current_drive = current_drive;
unsigned int back_saved_partition = saved_partition;
Expand All @@ -7339,9 +7339,9 @@ add_part_data (int drive)
return;

//查找分区数据结束
dp = partition_info;
while (dp->next)
dp = dp->next;
p_final = partition_info;
while (p_final->next)
p_final = p_final->next;

if (drive < 0x90)
{
Expand Down Expand Up @@ -7389,12 +7389,12 @@ add_part_data (int drive)
if (!partition_info)
{
partition_info = p;
dp = p;
p_final = p;
}
else
{
dp->next = p;
dp = dp->next;
p_final->next = p;
p_final = p;
}
}
if (get_efi_device_boot_path (drive, 1))
Expand Down Expand Up @@ -7422,10 +7422,10 @@ add_part_data (int drive)
// p->boot_size = cd_boot_size;
p->partition_boot = 1;
p->next = 0;
if (!partition_info) //使用 'if (!dp)' 会判断错误。 当 partition_info=bp=0 时,if (!partition_info) 返回1;而 if (!dp) 返回0。
if (!partition_info) //使用 'if (!p_final)' 会判断错误。 当 partition_info=bp=0 时,if (!partition_info) 返回1;而 if (!p_final) 返回0。
partition_info = p;
else
dp->next = p;
p_final->next = p;
get_efi_device_boot_path(drive, 1);
}
}
Expand Down Expand Up @@ -11229,6 +11229,10 @@ int
remap_ascii_char (int key)
{
int i;

//一些有bug的UEFI固件返回了每个SHIFT+键组合,如大写字母Q返回0x1000051而不是0x0051。为了适应这个bug。2023-08-09
if ((key & 0x1000000) && (key & 0xffffff) < 0x7f)
key = key & 0xff;
for (i=0; ascii_key_map[i].from_code; i++)
{
if (ascii_key_map[i].from_code == key)
Expand Down
35 changes: 29 additions & 6 deletions stage2/disk_io.c
Expand Up @@ -104,7 +104,7 @@ part_choice;
//char *mbr = (char *)0x8000; /* 512-byte buffer for any use. */

static unsigned int dest_partition;
static unsigned int entry;
//static unsigned int entry;

static unsigned int bsd_part_no;
static unsigned int pc_slice_no;
Expand Down Expand Up @@ -1054,7 +1054,8 @@ real_open_partition (int flags)
{
if (! do_completion)
{
int active = (PC_SLICE_FLAG (mbr, entry) == PC_SLICE_FLAG_BOOTABLE);
// int active = (PC_SLICE_FLAG (mbr, entry) == PC_SLICE_FLAG_BOOTABLE);
int active = q->partition_activity_flag;
grub_printf (" Partition num: %d%s, ",
(unsigned int)(unsigned char)(current_partition >> 16), (active ? ", active": ""));

Expand Down Expand Up @@ -3105,6 +3106,7 @@ partition_info_init (struct efidisk_data *devices)
struct grub_disk_data *d;
struct efidisk_data *d1;
struct grub_part_data *p;
struct grub_part_data *p_final;
grub_efi_device_path_t *dp = 0, *ldp = 0, *dp1; //路径
int drive;
unsigned int back_saved_drive = saved_drive;
Expand Down Expand Up @@ -3155,7 +3157,18 @@ partition_info_init (struct efidisk_data *devices)
p->partition_entry = *next_partition_entry; //2 2 2 2 0 1 2 0 0 0
p->partition_ext_offset = *next_partition_ext_offset; //0 0 0 0 0 0 0 a0029cc a0029cc a0029cc
p->partition_activity_flag = partition_activity_flag;
p->next = partition_info; //0 dfb0110 dfb00e0 dfb00b0 dfb0080 dfb0050 dfaff90 dfaff60
// p->next = partition_info; //0 dfb0110 dfb00e0 dfb00b0 dfb0080 dfb0050 dfaff90 dfaff60
p->next = 0;
if (!partition_info) //执行find时,分区顺序为0,1,2.... 2023-07-24
{
partition_info = p;
p_final = p;
}
else
{
p_final->next = p;
p_final = p;
}

grub_memcpy (&p->partition_signature, &partition_signature, 16);
//从efidisk_data中查找有关信息
Expand All @@ -3174,7 +3187,7 @@ partition_info_init (struct efidisk_data *devices)
}
}

partition_info = p; //dfb0110 dfb00e0 dfb00b0 dfb0080 dfb0050 dfaff90 dfaff60 dfaff30
// partition_info = p; //dfb0110 dfb00e0 dfb00b0 dfb0080 dfb0050 dfaff90 dfaff60 dfaff30
}
if (get_efi_device_boot_path (drive, 0))
{
Expand Down Expand Up @@ -3210,8 +3223,18 @@ partition_info_init (struct efidisk_data *devices)
p->partition_start = 0;
p->partition_size = 0;
p->partition_boot = 1;
p->next = partition_info;
partition_info = p;
// p->next = partition_info;
// partition_info = p;
if (!partition_info) //执行find时,分区顺序为0,1,2.... 2023-07-24
{
partition_info = p;
p_final = p;
}
else
{
p_final->next = p;
p_final = p;
}

for (d1 = devices; d1; d1 = d1->next)
{
Expand Down

0 comments on commit aa78c12

Please sign in to comment.