From fdc0486c5d47ca692c755b8a03550e42f5f14257 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Fri, 27 Mar 2009 22:03:24 +0100 Subject: [PATCH] hdt: prevent unless disk's menu Impact: none No need to compute disk's menu if no disk are detected --- com32/hdt/hdt-common.c | 2 ++ com32/hdt/hdt-common.h | 1 + com32/hdt/hdt-menu-disk.c | 8 ++++++-- com32/hdt/hdt-menu.c | 2 +- com32/hdt/hdt-menu.h | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c index b2fdf8e..8ab0f12 100644 --- a/com32/hdt/hdt-common.c +++ b/com32/hdt/hdt-common.c @@ -82,6 +82,7 @@ void init_hardware(struct s_hardware *hardware) hardware->cpu_detection = false; hardware->pci_detection = false; hardware->disk_detection = false; + hardware->disks_count=0; hardware->dmi_detection = false; hardware->pxe_detection = false; hardware->vesa_detection = false; @@ -197,6 +198,7 @@ void detect_disks(struct s_hardware *hardware) if (get_disk_params(drive, hardware->disk_info) != 0) continue; struct diskinfo *d = &hardware->disk_info[drive]; + hardware->disks_count++; printf (" DISK 0x%X: %s : %s %s: sectors=%d, s/t=%d head=%d : EDD=%s\n", drive, d->aid.model, d->host_bus_type, d->interface_type, diff --git a/com32/hdt/hdt-common.h b/com32/hdt/hdt-common.h index 9d6bc5f..dc78328 100644 --- a/com32/hdt/hdt-common.h +++ b/com32/hdt/hdt-common.h @@ -96,6 +96,7 @@ struct s_hardware { s_cpu cpu; /* CPU information */ struct pci_domain *pci_domain; /* PCI Devices */ struct diskinfo disk_info[256]; /* Disk Information */ + int disks_count; /* Number of detected disks */ struct s_pxe pxe; struct s_vesa vesa; diff --git a/com32/hdt/hdt-menu-disk.c b/com32/hdt/hdt-menu-disk.c index 1b27303..02f12f7 100644 --- a/com32/hdt/hdt-menu-disk.c +++ b/com32/hdt/hdt-menu-disk.c @@ -152,10 +152,15 @@ int compute_disk_module(struct s_my_menu *menu, int nb_sub_disk_menu, } /* Compute the Disks menu */ -void compute_disks(struct s_hdt_menu *menu, struct diskinfo *disk_info) +void compute_disks(struct s_hdt_menu *menu, struct diskinfo *disk_info, struct s_hardware *hardware) { char buffer[MENULEN + 1]; int nb_sub_disk_menu = 0; + + /* No need to compute that menu if no disks were detected */ + menu->disk_menu.items_count = 0; + if (hardware->disks_count == 0) return; + for (int i = 0; i < 0xff; i++) { if (compute_disk_module ((struct s_my_menu*) &(menu->disk_sub_menu), nb_sub_disk_menu, disk_info, @@ -164,7 +169,6 @@ void compute_disks(struct s_hdt_menu *menu, struct diskinfo *disk_info) } menu->disk_menu.menu = add_menu(" Disks ", -1); - menu->disk_menu.items_count = 0; for (int i = 0; i < nb_sub_disk_menu; i++) { snprintf(buffer, sizeof buffer, " Disk <%d> ", i); diff --git a/com32/hdt/hdt-menu.c b/com32/hdt/hdt-menu.c index 224974e..a865e67 100644 --- a/com32/hdt/hdt-menu.c +++ b/com32/hdt/hdt-menu.c @@ -153,7 +153,7 @@ void compute_submenus(struct s_hdt_menu *hdt_menu, struct s_hardware *hardware) } compute_processor(&(hdt_menu->cpu_menu), hardware); - compute_disks(hdt_menu, hardware->disk_info); + compute_disks(hdt_menu, hardware->disk_info, hardware); #ifdef WITH_PCI compute_PCI(hdt_menu, hardware); diff --git a/com32/hdt/hdt-menu.h b/com32/hdt/hdt-menu.h index 7986c86..91809e2 100644 --- a/com32/hdt/hdt-menu.h +++ b/com32/hdt/hdt-menu.h @@ -92,7 +92,7 @@ void compute_kernel(struct s_my_menu *menu, struct s_hardware *hardware); // Disk Stuff int compute_disk_module(struct s_my_menu *menu, int nb_sub_disk_menu, struct diskinfo *d, int disk_number); -void compute_disks(struct s_hdt_menu *menu, struct diskinfo *disk_info); +void compute_disks(struct s_hdt_menu *menu, struct diskinfo *disk_info, struct s_hardware *hardware); // DMI Stuff void compute_motherboard(struct s_my_menu *menu, s_dmi * dmi); -- 2.7.4