diff options
Diffstat (limited to 'com32/hdt')
-rw-r--r-- | com32/hdt/hdt-cli.c | 24 | ||||
-rw-r--r-- | com32/hdt/hdt-cli.h | 5 | ||||
-rw-r--r-- | com32/hdt/hdt-common.c | 48 | ||||
-rw-r--r-- | com32/hdt/hdt-common.h | 10 | ||||
-rw-r--r-- | com32/hdt/hdt-menu-kernel.c | 6 | ||||
-rw-r--r-- | com32/hdt/hdt-menu-pci.c | 6 | ||||
-rw-r--r-- | com32/hdt/hdt-menu.c | 34 | ||||
-rw-r--r-- | com32/hdt/hdt-menu.h | 6 |
8 files changed, 93 insertions, 46 deletions
diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c index 53c47438..2f6b6fa6 100644 --- a/com32/hdt/hdt-cli.c +++ b/com32/hdt/hdt-cli.c @@ -44,11 +44,14 @@ void start_cli_mode(int argc, char *argv[]) { memset(cli_line,0,sizeof cli_line); printf("hdt:"); fgets(cli_line, sizeof cli_line, stdin); - /* We use sizeof BLAH - 2 to remove the return char */ - if ( !strncmp(cli_line, CLI_EXIT, sizeof CLI_EXIT - 2 ) ) + cli_line[strlen(cli_line)-1]='\0'; + /* We use sizeof BLAH - 1 to remove the last \0 */ + if ( !strncmp(cli_line, CLI_EXIT, sizeof CLI_EXIT - 1) ) break; - if ( !strncmp(cli_line, CLI_HELP, sizeof CLI_HELP - 2) ) + if ( !strncmp(cli_line, CLI_HELP, sizeof CLI_HELP - 1) ) show_cli_help(); + if ( !strncmp(cli_line, CLI_SHOW, sizeof CLI_SHOW - 1) ) + main_show(strstr(cli_line,"show")+ sizeof CLI_SHOW, &hardware); } } @@ -57,3 +60,18 @@ void show_cli_help() { printf("Available commands are : %s %s\n",CLI_EXIT,CLI_HELP); } +void main_show_dmi(struct s_hardware *hardware) { + printf("Let's show dmi stuff !\n"); +} + +void main_show_pci(struct s_hardware *hardware) { + if (hardware->pci_detection==false) { + detect_pci(hardware); + } + printf("%d PCI devices detected\n",hardware->nb_pci_devices); +} + +void main_show(char *item, struct s_hardware *hardware) { + if (!strncmp(item,CLI_PCI, sizeof CLI_PCI)) main_show_pci(hardware); + if (!strncmp(item,CLI_DMI, sizeof CLI_DMI)) main_show_dmi(hardware); +} diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h index e348c9b4..48bfa546 100644 --- a/com32/hdt/hdt-cli.h +++ b/com32/hdt/hdt-cli.h @@ -29,10 +29,15 @@ #ifndef DEFINE_HDT_CLI_H #define DEFINE_HDT_CLI_H #include <stdio.h> +#include "hdt-common.h" #define CLI_EXIT "exit" #define CLI_HELP "help" +#define CLI_SHOW "show" +#define CLI_PCI "pci" +#define CLI_DMI "dmi" void show_cli_help(); void start_cli_mode(int argc, char *argv[]); +void main_show(char *item, struct s_hardware *hardware); #endif diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c index 70064127..2c98d6ec 100644 --- a/com32/hdt/hdt-common.c +++ b/com32/hdt/hdt-common.c @@ -31,6 +31,12 @@ #include <string.h> void init_hardware(struct s_hardware *hardware) { + hardware->pci_ids_return_code=0; + hardware->modules_pcimap_return_code=0; + hardware->cpu_detection=false; + hardware->pci_detection=false; + hardware->disk_detection=false; + hardware->dmi_detection=false; hardware->nb_pci_devices=0; hardware->is_dmi_valid=false; hardware->pci_domain=NULL; @@ -44,8 +50,8 @@ void init_hardware(struct s_hardware *hardware) { /* Detecting if a DMI table exist * if yes, let's parse it */ int detect_dmi(struct s_hardware *hardware) { + hardware->dmi_detection=true; if (dmi_iterate(&(hardware->dmi)) == -ENODMITABLE ) { - printf("No DMI Structure found\n"); hardware->is_dmi_valid=false; return -ENODMITABLE; } @@ -56,15 +62,49 @@ int detect_dmi(struct s_hardware *hardware) { } /* Try to detects disk from port 0x80 to 0xff*/ -void detect_disks(struct diskinfo *disk_info) { +void detect_disks(struct s_hardware *hardware) { + hardware->disk_detection=true; for (int drive = 0x80; drive < 0xff; drive++) { - if (get_disk_params(drive,disk_info) != 0) + if (get_disk_params(drive,hardware->disk_info) != 0) continue; - struct diskinfo d=disk_info[drive]; + struct diskinfo d=hardware->disk_info[drive]; 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, d.sectors, d.sectors_per_track,d.heads,d.edd_version); } } +void detect_pci(struct s_hardware *hardware) { + hardware->pci_detection=true; + printf("PCI: Detecting Devices\n"); + /* Scanning to detect pci buses and devices */ + hardware->pci_domain = pci_scan(); + + struct pci_device *pci_device; + for_each_pci_func(pci_device, hardware->pci_domain) { + hardware->nb_pci_devices++; + } + + printf("PCI: %d Devices Found\n",hardware->nb_pci_devices); + + printf("PCI: Resolving names\n"); + /* Assigning product & vendor name for each device*/ + hardware->pci_ids_return_code=get_name_from_pci_ids(hardware->pci_domain); + + printf("PCI: Resolving class names\n"); + /* Assigning class name for each device*/ + hardware->pci_ids_return_code=get_class_name_from_pci_ids(hardware->pci_domain); + + + printf("PCI: Resolving module names\n"); + /* Detecting which kernel module should match each device */ + hardware->modules_pcimap_return_code=get_module_name_from_pci_ids(hardware->pci_domain); + +} + +void cpu_detect(struct s_hardware *hardware) { + hardware->cpu_detection=true; + detect_cpu(&(hardware->cpu)); +} + /* Find the last instance of a particular command line argument (which should include the final =; do not use for boolean arguments) */ char *find_argument(char **argv, const char *argument) diff --git a/com32/hdt/hdt-common.h b/com32/hdt/hdt-common.h index 4a78fb95..78d8bfbc 100644 --- a/com32/hdt/hdt-common.h +++ b/com32/hdt/hdt-common.h @@ -39,12 +39,20 @@ struct s_hardware { s_cpu cpu; /* CPU information */ struct pci_domain *pci_domain; /* PCI Devices */ struct diskinfo disk_info[256]; /* Disk Information*/ + int pci_ids_return_code; + int modules_pcimap_return_code; int nb_pci_devices; bool is_dmi_valid; + bool dmi_detection; /* Does the dmi stuff have been already detected */ + bool pci_detection; /* Does the pci stuff have been already detected */ + bool cpu_detection; /* Does the cpu stuff have been already detected */ + bool disk_detection; /* Does the disk stuff have been already detected */ }; char *find_argument(char **argv, const char *argument); int detect_dmi(struct s_hardware *hardware); -void detect_disks(struct diskinfo *disk_info); +void detect_disks(struct s_hardware *hardware); +void detect_pci(struct s_hardware *hardware); +void cpu_detect(struct s_hardware *hardware); void init_hardware(struct s_hardware *hardware); #endif diff --git a/com32/hdt/hdt-menu-kernel.c b/com32/hdt/hdt-menu-kernel.c index c6776fa5..39979279 100644 --- a/com32/hdt/hdt-menu-kernel.c +++ b/com32/hdt/hdt-menu-kernel.c @@ -29,7 +29,7 @@ #include "hdt-menu.h" /* Main Kernel Menu*/ -void compute_kernel(struct s_my_menu *menu,struct pci_domain **pci_domain) { +void compute_kernel(struct s_my_menu *menu,struct s_hardware *hardware) { char buffer[SUBMENULEN+1]; char infobar[STATLEN+1]; char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE]; @@ -39,14 +39,14 @@ void compute_kernel(struct s_my_menu *menu,struct pci_domain **pci_domain) { menu->items_count=0; set_menu_pos(SUBMENU_Y,SUBMENU_X); - if (modules_pcimap == -ENOMODULESPCIMAP) { + if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) { add_item("The modules.pcimap file is missing","Missing modules.pcimap file",OPT_INACTIVE,NULL,0); add_item("Kernel modules can't be computed.","Missing modules.pcimap file",OPT_INACTIVE,NULL,0); add_item("Please put one in same dir as hdt","Missing modules.pcimap file",OPT_INACTIVE,NULL,0); add_item("","",OPT_SEP,"",0); } else { /* For every detected pci device, grab its kernel module to compute this submenu */ - for_each_pci_func(pci_device, *pci_domain) { + for_each_pci_func(pci_device, hardware->pci_domain) { memset(kernel_modules,0,sizeof kernel_modules); for (int i=0; i<pci_device->dev_info->linux_kernel_module_count;i++) { if (i>0) { diff --git a/com32/hdt/hdt-menu-pci.c b/com32/hdt/hdt-menu-pci.c index 25b9527d..c37cdd1b 100644 --- a/com32/hdt/hdt-menu-pci.c +++ b/com32/hdt/hdt-menu-pci.c @@ -81,7 +81,7 @@ void compute_pci_device(struct s_my_menu *menu,struct pci_device *pci_device,int } /* Main PCI Menu*/ -int compute_PCI(struct s_hdt_menu *hdt_menu, struct pci_domain **pci_domain) { +int compute_PCI(struct s_hdt_menu *hdt_menu, struct s_hardware *hardware) { int i=0; char menuname[255][MENULEN+1]; char infobar[255][STATLEN+1]; @@ -89,7 +89,7 @@ int compute_PCI(struct s_hdt_menu *hdt_menu, struct pci_domain **pci_domain) { char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE]; /* For every detected pci device, compute its submenu */ - for_each_pci_func(pci_device, *pci_domain) { + for_each_pci_func(pci_device, hardware->pci_domain) { memset(kernel_modules,0,sizeof kernel_modules); for (int i=0; i<pci_device->dev_info->linux_kernel_module_count;i++) { if (i>0) { @@ -110,7 +110,7 @@ int compute_PCI(struct s_hdt_menu *hdt_menu, struct pci_domain **pci_domain) { hdt_menu->pci_menu.menu = add_menu(" PCI Devices ",-1); hdt_menu->pci_menu.items_count=0; - if (pci_ids == -ENOPCIIDS) { + if (hardware->pci_ids_return_code == -ENOPCIIDS) { add_item("The pci.ids file is missing","Missing pci.ids file",OPT_INACTIVE,NULL,0); add_item("PCI Device names can't be computed.","Missing pci.ids file",OPT_INACTIVE,NULL,0); add_item("Please put one in same dir as hdt","Missing pci.ids file",OPT_INACTIVE,NULL,0); diff --git a/com32/hdt/hdt-menu.c b/com32/hdt/hdt-menu.c index 662fe2c9..64787f60 100644 --- a/com32/hdt/hdt-menu.c +++ b/com32/hdt/hdt-menu.c @@ -132,8 +132,8 @@ 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); #ifdef WITH_PCI - compute_PCI(hdt_menu,&(hardware->pci_domain)); - compute_kernel(&(hdt_menu->kernel_menu),&(hardware->pci_domain)); + compute_PCI(hdt_menu,hardware); + compute_kernel(&(hdt_menu->kernel_menu),hardware); #endif compute_syslinuxmenu(&(hdt_menu->syslinux_menu)); compute_aboutmenu(&(hdt_menu->about_menu)); @@ -194,41 +194,19 @@ if (hardware->is_dmi_valid) { void detect_hardware(struct s_hardware *hardware) { printf("CPU: Detecting\n"); - detect_cpu(&(hardware->cpu)); + cpu_detect(hardware); printf("DISKS: Detecting\n"); - detect_disks(hardware->disk_info); + detect_disks(hardware); printf("DMI: Detecting Table\n"); - if (detect_dmi(&(hardware->dmi)) == -ENODMITABLE ) { + if (detect_dmi(hardware) == -ENODMITABLE ) { printf("DMI: ERROR ! Table not found ! \n"); printf("DMI: Many hardware components will not be detected ! \n"); } else { printf("DMI: Table found ! (version %d.%d)\n",hardware->dmi.dmitable.major_version,hardware->dmi.dmitable.minor_version); } #ifdef WITH_PCI - printf("PCI: Detecting Devices\n"); - /* Scanning to detect pci buses and devices */ - hardware->pci_domain = pci_scan(); - - struct pci_device *pci_device; - for_each_pci_func(pci_device, hardware->pci_domain) { - hardware->nb_pci_devices++; - } - - printf("PCI: %d Devices Found\n",hardware->nb_pci_devices); - - printf("PCI: Resolving names\n"); - /* Assigning product & vendor name for each device*/ - get_name_from_pci_ids(hardware->pci_domain); - - printf("PCI: Resolving class names\n"); - /* Assigning class name for each device*/ - pci_ids=get_class_name_from_pci_ids(hardware->pci_domain); - - - printf("PCI: Resolving module names\n"); - /* Detecting which kernel module should match each device */ - modules_pcimap=get_module_name_from_pci_ids(hardware->pci_domain); + detect_pci(hardware); #endif } diff --git a/com32/hdt/hdt-menu.h b/com32/hdt/hdt-menu.h index f965282b..bebdff58 100644 --- a/com32/hdt/hdt-menu.h +++ b/com32/hdt/hdt-menu.h @@ -77,13 +77,11 @@ TIMEOUTCODE ontimeout(); void keys_handler(t_menusystem *ms, t_menuitem *mi,unsigned int scancode); // PCI Stuff -static int pci_ids=0; void compute_pci_device(struct s_my_menu *menu,struct pci_device *pci_device,int pci_bus, int pci_slot, int pci_func); -int compute_PCI(struct s_hdt_menu *hdt_menu, struct pci_domain **pci_domain); +int compute_PCI(struct s_hdt_menu *hdt_menu, struct s_hardware *hardware); // KERNEL Stuff -static int modules_pcimap=0; -void compute_kernel(struct s_my_menu *menu,struct pci_domain **pci_domain); +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); |