From 5c8a25e3698c42e64ac1d4f5f6aa3dbaac11ca63 Mon Sep 17 00:00:00 2001 From: acevest Date: Mon, 16 Oct 2023 02:06:35 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E8=AF=BB=E5=88=86=E5=8C=BA?= =?utf8?q?=E6=97=B6part=5Fid=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- drivers/ata.c | 54 ++++++++++++++++++++++++-------------------- drivers/block.c | 2 +- scripts/iso.grub.cfg | 2 +- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/drivers/ata.c b/drivers/ata.c index 610b4d6..f23b489 100644 --- a/drivers/ata.c +++ b/drivers/ata.c @@ -216,13 +216,6 @@ void read_partition_table(ide_drive_t *drv, uint32_t ext_lba, uint32_t partition ide_part_t *part = 0; uint32_t part_id = 0; - if (depth == 0) { - // MBR里的分区占据 [1,4] - part_id = 1; - } else { - // 扩展分区里的逻辑分区占据 [5,MAX_DISK_PARTIONS) - part_id = 5 + depth - 1; - } const char *p = sect + PARTITION_TABLE_OFFSET; for (int i = 0; i < 4; i++) { @@ -230,34 +223,46 @@ void read_partition_table(ide_drive_t *drv, uint32_t ext_lba, uint32_t partition 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 - 1; - if (part->type == 0x00) { + if (depth == 0) { + // MBR里的分区占据 [1,4] + part_id = 1 + i; + } else { + // 扩展分区里的逻辑分区占据 [5,MAX_DISK_PARTIONS) + part_id = 5 + depth - 1; + } + + ide_part_t tpart; + tpart.flags = (uint8_t)p[0]; + tpart.type = (uint8_t)p[4]; + tpart.lba_start = *((uint32_t *)(p + 8)); + tpart.lba_end = *((uint32_t *)(p + 12)); + + if (tpart.type == 0x00) { continue; } uint32_t lba_offset = 0; - if (part->type == 0x05) { - ext_lba = ext_lba != 0 ? ext_lba : part->lba_start; - uint32_t offset = depth == 0 ? partition_table_lba : part->lba_start; + if (tpart.type == 0x05) { + ext_lba = ext_lba != 0 ? ext_lba : tpart.lba_start; + uint32_t offset = depth == 0 ? partition_table_lba : tpart.lba_start; lba_offset = ext_lba + offset; } else { - lba_offset = partition_table_lba + part->lba_start; + lba_offset = partition_table_lba + tpart.lba_start; + + part = drv->partions + part_id; + part->flags = tpart.flags; + part->type = tpart.type; + part->lba_start = lba_offset; + uint32_t size = tpart.lba_end; + part->lba_end = part->lba_start + size - 1; } - if (part->type == 0x05) { + if (tpart.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, lba_offset, - lba_offset + size - 1); + printk("part[%d] %02X %u %u\n", part_id, tpart.type, lba_offset, part->lba_end); } - part_id++; - // 每个分区16个字节 p += 16; } @@ -282,7 +287,8 @@ void ide_read_partions() { void ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, char *buf) { ide_drive_t *drv = ide_get_drive(dev); - uint64_t lba_offset = drv->partions[DEV_MINOR((dev))].lba_start; + int part_id = DEV_MINOR((dev)) & 0xFF; // TODO: 换成宏定义 + uint64_t lba_offset = drv->partions[part_id].lba_start; disk_request_t r; r.dev = dev; diff --git a/drivers/block.c b/drivers/block.c index cb03173..4ce1bde 100644 --- a/drivers/block.c +++ b/drivers/block.c @@ -25,7 +25,7 @@ blk_buffer_t *block_read(dev_t dev, uint32_t block) { blk_buffer_t *bb = 0; assert(DEV_MAJOR(dev) == DEV_MAJOR_DISK); - assert(DEV_MINOR(dev) == 1); + // assert(DEV_MINOR(dev) == 1); // 目前不提供hash表组强起来的缓冲功能 // 直接读 diff --git a/scripts/iso.grub.cfg b/scripts/iso.grub.cfg index 00c0acc..a68cfbc 100644 --- a/scripts/iso.grub.cfg +++ b/scripts/iso.grub.cfg @@ -10,6 +10,6 @@ menuentry 'Kernel' --class os { #insmod ext2 #set gfxpayload=1024x768x32 #insmod all_video - multiboot2 /boot/Kernel root=hda1 delay=2 + multiboot2 /boot/Kernel root=hda7 delay=2 boot } -- 2.44.0