Remove redundant code.

Both mfi_flash.c and mfi_show.c contain very similar functions to print
a list of firmwares. Move these routines into mfiutil.c.

Reported by:	jhb
This commit is contained in:
ed 2012-10-20 10:20:06 +00:00
parent ff852f67bd
commit e65c2d3d07
4 changed files with 35 additions and 60 deletions

View File

@ -42,34 +42,6 @@
#define FLASH_BUF_SIZE (64 * 1024)
static void
scan_firmware(struct mfi_info_component *comp)
{
int len;
len = strlen(comp->name);
if (fw_name_width < len)
fw_name_width = len;
len = strlen(comp->version);
if (fw_version_width < len)
fw_version_width = len;
len = strlen(comp->build_date);
if (fw_date_width < len)
fw_date_width = len;
len = strlen(comp->build_time);
if (fw_time_width < len)
fw_time_width = len;
}
static void
display_firmware(struct mfi_info_component *comp)
{
printf("%-*s %-*s %-*s %-*s\n", fw_name_width, comp->name,
fw_version_width, comp->version, fw_date_width, comp->build_date,
fw_time_width, comp->build_time);
}
static int
display_pending_firmware(int fd)
{
@ -94,9 +66,9 @@ display_pending_firmware(int fd)
info.pending_image_component_count = 8;
for (i = 0; i < info.pending_image_component_count; i++)
scan_firmware(&info.pending_image_component[i]);
display_firmware(&header);
display_firmware(&header, "");
for (i = 0; i < info.pending_image_component_count; i++)
display_firmware(&info.pending_image_component[i]);
display_firmware(&info.pending_image_component[i], "");
return (0);
}

View File

@ -570,34 +570,6 @@ show_drives(int ac, char **av __unused)
}
MFI_COMMAND(show, drives, show_drives);
static void
scan_firmware(struct mfi_info_component *comp)
{
int len;
len = strlen(comp->name);
if (fw_name_width < len)
fw_name_width = len;
len = strlen(comp->version);
if (fw_version_width < len)
fw_version_width = len;
len = strlen(comp->build_date);
if (fw_date_width < len)
fw_date_width = len;
len = strlen(comp->build_time);
if (fw_time_width < len)
fw_time_width = len;
}
static void
display_firmware(struct mfi_info_component *comp, const char *tag)
{
printf("%-*s %-*s %-*s %-*s %s\n", fw_name_width, comp->name,
fw_version_width, comp->version, fw_date_width, comp->build_date,
fw_time_width, comp->build_time, tag);
}
static int
show_firmware(int ac, char **av __unused)
{

View File

@ -45,7 +45,7 @@ MFI_TABLE(top, abort);
int mfi_unit;
u_int mfi_opts;
int fw_name_width, fw_version_width, fw_date_width, fw_time_width;
static int fw_name_width, fw_version_width, fw_date_width, fw_time_width;
static void
usage(void)
@ -144,3 +144,31 @@ main(int ac, char **av)
warnx("Unknown command %s.", av[0]);
return (1);
}
void
scan_firmware(struct mfi_info_component *comp)
{
int len;
len = strlen(comp->name);
if (fw_name_width < len)
fw_name_width = len;
len = strlen(comp->version);
if (fw_version_width < len)
fw_version_width = len;
len = strlen(comp->build_date);
if (fw_date_width < len)
fw_date_width = len;
len = strlen(comp->build_time);
if (fw_time_width < len)
fw_time_width = len;
}
void
display_firmware(struct mfi_info_component *comp, const char *tag)
{
printf("%-*s %-*s %-*s %-*s %s\n", fw_name_width, comp->name,
fw_version_width, comp->version, fw_date_width, comp->build_date,
fw_time_width, comp->build_time, tag);
}

View File

@ -121,8 +121,8 @@ struct mfiutil_command {
#define MFI_DNAME_HONOR_OPTS 0x8000 /* Allow cmd line to override default */
extern int mfi_unit;
extern u_int mfi_opts;
extern int fw_name_width, fw_version_width, fw_date_width, fw_time_width;
void mbox_store_ldref(uint8_t *mbox, union mfi_ld_ref *ref);
void mbox_store_pdref(uint8_t *mbox, union mfi_pd_ref *ref);
@ -153,4 +153,7 @@ const char *mfi_status(u_int status_code);
const char *mfi_drive_name(struct mfi_pd_info *pinfo, uint16_t device_id,
uint32_t def);
void scan_firmware(struct mfi_info_component *comp);
void display_firmware(struct mfi_info_component *comp, const char *tag);
#endif /* !__MFIUTIL_H__ */