From owner-svn-src-head@FreeBSD.ORG Sat Oct 20 10:20:07 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5A1C497A; Sat, 20 Oct 2012 10:20:07 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 306308FC08; Sat, 20 Oct 2012 10:20:07 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q9KAK75Q005476; Sat, 20 Oct 2012 10:20:07 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q9KAK6dh005471; Sat, 20 Oct 2012 10:20:06 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201210201020.q9KAK6dh005471@svn.freebsd.org> From: Ed Schouten Date: Sat, 20 Oct 2012 10:20:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r241776 - head/usr.sbin/mfiutil X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Oct 2012 10:20:07 -0000 Author: ed Date: Sat Oct 20 10:20:06 2012 New Revision: 241776 URL: http://svn.freebsd.org/changeset/base/241776 Log: 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 Modified: head/usr.sbin/mfiutil/mfi_flash.c head/usr.sbin/mfiutil/mfi_show.c head/usr.sbin/mfiutil/mfiutil.c head/usr.sbin/mfiutil/mfiutil.h Modified: head/usr.sbin/mfiutil/mfi_flash.c ============================================================================== --- head/usr.sbin/mfiutil/mfi_flash.c Sat Oct 20 10:16:55 2012 (r241775) +++ head/usr.sbin/mfiutil/mfi_flash.c Sat Oct 20 10:20:06 2012 (r241776) @@ -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); } Modified: head/usr.sbin/mfiutil/mfi_show.c ============================================================================== --- head/usr.sbin/mfiutil/mfi_show.c Sat Oct 20 10:16:55 2012 (r241775) +++ head/usr.sbin/mfiutil/mfi_show.c Sat Oct 20 10:20:06 2012 (r241776) @@ -570,34 +570,6 @@ error: } 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) { Modified: head/usr.sbin/mfiutil/mfiutil.c ============================================================================== --- head/usr.sbin/mfiutil/mfiutil.c Sat Oct 20 10:16:55 2012 (r241775) +++ head/usr.sbin/mfiutil/mfiutil.c Sat Oct 20 10:20:06 2012 (r241776) @@ -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); +} Modified: head/usr.sbin/mfiutil/mfiutil.h ============================================================================== --- head/usr.sbin/mfiutil/mfiutil.h Sat Oct 20 10:16:55 2012 (r241775) +++ head/usr.sbin/mfiutil/mfiutil.h Sat Oct 20 10:20:06 2012 (r241776) @@ -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__ */