From 4d1073f1f8fa6e6a277b4a6020c6b125ddc492e7 Mon Sep 17 00:00:00 2001 From: acevest Date: Sun, 15 Oct 2023 22:59:50 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E8=AF=BB=E7=A1=AC=E7=9B=98?= =?utf8?q?=E5=88=86=E5=8C=BA=E6=97=B6=E9=80=BB=E8=BE=91=E5=88=86=E5=8C=BA?= =?utf8?q?=E8=B5=B7=E5=A7=8B=E5=9C=B0=E5=9D=80=E4=B8=8D=E5=AF=B9=E7=9A=84?= =?utf8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- drivers/ata.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/ata.c b/drivers/ata.c index b6baa08..610b4d6 100644 --- a/drivers/ata.c +++ b/drivers/ata.c @@ -200,17 +200,16 @@ void ide_ata_init() { } // ext_lba: 在MBR中的扩展分区记录里的偏移地址 -// offset_lba: 在扩展分区记录里的扩展分区的偏移地址 -void read_partition_table(ide_drive_t *drv, uint32_t ext_lba, uint32_t offset_lba, int depth) { - uint32_t base = depth <= 1 ? 0 : ext_lba; +// partition_table_lba: 扩展分区的真实偏移地址 +void read_partition_table(ide_drive_t *drv, uint32_t ext_lba, uint32_t partition_table_lba, int depth) { disk_request_t r; char *sect = kmalloc(SECT_SIZE, 0); // part_no == 0 代表整场硬盘 r.dev = MAKE_DISK_DEV(drv->drv_no, 0); r.command = DISK_REQ_READ; - r.pos = base + offset_lba; + r.pos = partition_table_lba; r.count = 1; r.buf = sect; send_disk_request(&r); @@ -230,24 +229,31 @@ void read_partition_table(ide_drive_t *drv, uint32_t ext_lba, uint32_t offset_lb if (part_id >= MAX_DISK_PARTIONS) { break; } + part = drv->partions + part_id; part->flags = (uint8_t)p[0]; part->type = (uint8_t)p[4]; part->lba_start = *((uint32_t *)(p + 8)); uint32_t size = *((uint32_t *)(p + 12)); - part->lba_end = part->lba_start + size; - part->lba_end = size; - + part->lba_end = part->lba_start + size - 1; if (part->type == 0x00) { continue; } + uint32_t lba_offset = 0; if (part->type == 0x05) { ext_lba = ext_lba != 0 ? ext_lba : part->lba_start; - read_partition_table(drv, ext_lba, part->lba_start, depth + 1); + uint32_t offset = depth == 0 ? partition_table_lba : part->lba_start; + lba_offset = ext_lba + offset; + } else { + lba_offset = partition_table_lba + part->lba_start; + } + + if (part->type == 0x05) { + read_partition_table(drv, ext_lba, lba_offset, depth + 1); } else { - printk("part[%d] %02X %u %u\n", part_id + drv->drv_no * MAX_DISK_PARTIONS, part->type, part->lba_start, - size); + printk("part[%d] %02X %u %u\n", part_id + drv->drv_no * MAX_DISK_PARTIONS, part->type, lba_offset, + lba_offset + size - 1); } part_id++; -- 2.44.0