From 36ed0d4a9e918fa8467723ecb0b2be4210c560d0 Mon Sep 17 00:00:00 2001 From: boreddevnl Date: Sat, 9 May 2026 21:51:28 +0200 Subject: [PATCH] fix: ensure partitions are recognized after fdisk and fix AHCI slot bug --- src/dev/ahci.c | 9 +++++---- src/userland/cli/fdisk.c | 3 +++ src/userland/cli/rescan.c | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 src/userland/cli/rescan.c diff --git a/src/dev/ahci.c b/src/dev/ahci.c index 337c531..72f0927 100644 --- a/src/dev/ahci.c +++ b/src/dev/ahci.c @@ -120,11 +120,12 @@ static void ahci_port_rebase(ahci_port_state_t *ps) { if (!ps->cmd_tbl) return; mem_memset(ps->cmd_tbl, 0, cmd_tbl_size); - // Set command header 0 to point to our command table uint64_t ctba_phys = v2p((uint64_t)ps->cmd_tbl); - ps->cmd_list[0].ctba = (uint32_t)(ctba_phys & 0xFFFFFFFF); - ps->cmd_list[0].ctbau = (uint32_t)(ctba_phys >> 32); - ps->cmd_list[0].prdtl = 1; // 1 PRDT entry default + for (int i = 0; i < 32; i++) { + ps->cmd_list[i].ctba = (uint32_t)(ctba_phys & 0xFFFFFFFF); + ps->cmd_list[i].ctbau = (uint32_t)(ctba_phys >> 32); + ps->cmd_list[i].prdtl = 1; + } // Clear error and interrupt status port->serr = 0xFFFFFFFF; diff --git a/src/userland/cli/fdisk.c b/src/userland/cli/fdisk.c index 1ae4fd4..32b9ac1 100644 --- a/src/userland/cli/fdisk.c +++ b/src/userland/cli/fdisk.c @@ -362,5 +362,8 @@ int main(int argc, char **argv) { if (ret != 0) { printf("[ERROR] Partition write failed.\n"); return 1; } printf("Partition table written to /dev/%s.\n", devname); + + sys_disk_rescan(devname); + return 0; } diff --git a/src/userland/cli/rescan.c b/src/userland/cli/rescan.c new file mode 100644 index 0000000..72c77c3 --- /dev/null +++ b/src/userland/cli/rescan.c @@ -0,0 +1,26 @@ +// Copyright (c) 2023-2026 Chris (boreddevnl) +// This software is released under the GNU General Public License v3.0. See LICENSE file for details. +#include "../libc/syscall.h" +#include "../libc/stdio.h" +#include "../libc/string.h" + +int main(int argc, char **argv) { + if (argc < 2) { + printf("Usage: rescan /dev/DEVICE\n"); + return 1; + } + + const char *devname = argv[1]; + if (devname[0] == '/' && devname[1] == 'd' && devname[2] == 'e' && devname[3] == 'v' && devname[4] == '/') + devname += 5; + + printf("Rescanning /dev/%s...\n", devname); + int ret = sys_disk_rescan(devname); + if (ret != 0) { + printf("[ERROR] Rescan failed (ret=%d)\n", ret); + return 1; + } + + printf("Done.\n"); + return 0; +}