diff options
author | Stephen Hemminger <shemminger@osdl.org> | 2006-10-23 10:57:03 -0700 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2007-02-09 16:28:37 -0500 |
commit | fd3dc7be2449dc1b7950fcf22dbc2cf5a6504fa2 (patch) | |
tree | d84b8850f9241309c87ce917c2829c95545c48e0 /ethtool.c | |
parent | b9caefa09afc12072e8beee0596be19384e7a21f (diff) | |
download | ethtool-fd3dc7be2449dc1b7950fcf22dbc2cf5a6504fa2.tar.gz |
ethtool: flie option to register dump
Add ability to take old raw dumps from a file and decode them.
It is kind of limited because you still need to have same device
as the raw file, but useful for maintainers to decode raw dumps.
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'ethtool.c')
-rw-r--r-- | ethtool.c | 43 |
1 files changed, 37 insertions, 6 deletions
@@ -29,7 +29,9 @@ #include <sys/types.h> #include <string.h> #include <stdlib.h> +#include <sys/types.h> #include <sys/ioctl.h> +#include <sys/stat.h> #include <stdio.h> #include <string.h> #include <errno.h> @@ -150,7 +152,9 @@ static struct option { " [ ufo on|off ]\n" " [ gso on|off ]\n" }, { "-i", "--driver", MODE_GDRV, "Show driver information" }, - { "-d", "--register-dump", MODE_GREGS, "Do a register dump" }, + { "-d", "--register-dump", MODE_GREGS, "Do a register dump", + " [ raw on|off ]\n" + " [ file FILENAME ]\n" }, { "-e", "--eeprom-dump", MODE_GEEPROM, "Do a EEPROM dump", " [ raw on|off ]\n" " [ offset N ]\n" @@ -251,6 +255,7 @@ static int msglvl_wanted = -1; static int phys_id_time = 0; static int gregs_changed = 0; static int gregs_dump_raw = 0; +static char *gregs_dump_file = NULL; static int geeprom_changed = 0; static int geeprom_dump_raw = 0; static int geeprom_offset = 0; @@ -268,6 +273,7 @@ typedef enum { CMDL_NONE, CMDL_BOOL, CMDL_INT, + CMDL_STR, } cmdline_type_t; struct cmdline_info { @@ -279,6 +285,7 @@ struct cmdline_info { static struct cmdline_info cmdline_gregs[] = { { "raw", CMDL_BOOL, &gregs_dump_raw, NULL }, + { "file", CMDL_STR, &gregs_dump_file, NULL }, }; static struct cmdline_info cmdline_geeprom[] = { @@ -355,20 +362,28 @@ static void parse_generic_cmdline(int argc, char **argp, if (i >= argc) show_usage(1); p = info[idx].wanted_val; - if (info[idx].type == CMDL_BOOL) { + switch (info[idx].type) { + case CMDL_BOOL: if (!strcmp(argp[i], "on")) *p = 1; else if (!strcmp(argp[i], "off")) *p = 0; else show_usage(1); - } else if (info[idx].type == CMDL_INT) { - long v; - v = strtol(argp[i], NULL, 0); + break; + case CMDL_INT: { + long v = strtol(argp[i], NULL, 0); if (v < 0) show_usage(1); *p = (int) v; - } else { + break; + } + case CMDL_STR: { + char **s = info[idx].wanted_val; + *s = strdup(argp[i]); + break; + } + default: show_usage(1); } } @@ -970,6 +985,22 @@ static int dump_regs(struct ethtool_drvinfo *info, struct ethtool_regs *regs) return 0; } + if (gregs_dump_file) { + FILE *f = fopen(gregs_dump_file, "r"); + struct stat st; + + if (!f || fstat(fileno(f), &st) < 0) { + fprintf(stderr, "Can't open '%s': %s\n", + gregs_dump_file, strerror(errno)); + return -1; + } + + regs = realloc(regs, sizeof(*regs) + st.st_size); + regs->len = st.st_size; + fread(regs->data, regs->len, 1, f); + fclose(f); + } + for (i = 0; i < ARRAY_SIZE(driver_list); i++) if (!strncmp(driver_list[i].name, info->driver, ETHTOOL_BUSINFO_LEN)) |