From owner-svn-src-stable@FreeBSD.ORG Tue Sep 27 17:11:10 2011 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0CFD310656B6; Tue, 27 Sep 2011 17:11:10 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E670E8FC17; Tue, 27 Sep 2011 17:11:09 +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 p8RHB9Fp032932; Tue, 27 Sep 2011 17:11:09 GMT (envelope-from emaste@svn.freebsd.org) Received: (from emaste@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p8RHB9Nu032930; Tue, 27 Sep 2011 17:11:09 GMT (envelope-from emaste@svn.freebsd.org) Message-Id: <201109271711.p8RHB9Nu032930@svn.freebsd.org> From: Ed Maste Date: Tue, 27 Sep 2011 17:11:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-other@freebsd.org X-SVN-Group: stable-other MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225804 - stable/9/usr.sbin/mfiutil X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Sep 2011 17:11:10 -0000 Author: emaste Date: Tue Sep 27 17:11:09 2011 New Revision: 225804 URL: http://svn.freebsd.org/changeset/base/225804 Log: MFC r225798: Improve battery capacity reporting When a status pointer is passed in mfi_dcmd_command does not return an errno (if the ioctl is successful), so move the test for NO_HW_PRESENT outside of the error case. This should fix incorrect reporting for systems with a dead or no battery. Additionally, handle error codes other than NO_HW_PRESENT by omitting the battery capacity display. LSI's supercap-based parts (CV series) report their data using the same interface as battery-based parts, except that they do not include the capacity stats (state of charge, cumulative charge cycles, etc.) PR: bin/160581 Approved by: re Modified: stable/9/usr.sbin/mfiutil/mfi_show.c Directory Properties: stable/9/usr.sbin/mfiutil/ (props changed) Modified: stable/9/usr.sbin/mfiutil/mfi_show.c ============================================================================== --- stable/9/usr.sbin/mfiutil/mfi_show.c Tue Sep 27 17:04:13 2011 (r225803) +++ stable/9/usr.sbin/mfiutil/mfi_show.c Tue Sep 27 17:11:09 2011 (r225804) @@ -141,7 +141,7 @@ show_battery(int ac, char **av) struct mfi_bbu_design_info design; struct mfi_bbu_status stat; uint8_t status; - int comma, error, fd; + int comma, error, fd, show_capacity; if (ac != 1) { warnx("show battery: extra arguments"); @@ -157,16 +157,17 @@ show_battery(int ac, char **av) if (mfi_dcmd_command(fd, MFI_DCMD_BBU_GET_CAPACITY_INFO, &cap, sizeof(cap), NULL, 0, &status) < 0) { - if (status == MFI_STAT_NO_HW_PRESENT) { - printf("mfi%d: No battery present\n", mfi_unit); - close(fd); - return (0); - } error = errno; warn("Failed to get capacity info"); close(fd); return (error); } + if (status == MFI_STAT_NO_HW_PRESENT) { + printf("mfi%d: No battery present\n", mfi_unit); + close(fd); + return (0); + } + show_capacity = (status == MFI_STAT_OK); if (mfi_dcmd_command(fd, MFI_DCMD_BBU_GET_DESIGN_INFO, &design, sizeof(design), NULL, 0, NULL) < 0) { @@ -192,10 +193,14 @@ show_battery(int ac, char **av) printf(" Model: %s\n", design.device_name); printf(" Chemistry: %s\n", design.device_chemistry); printf(" Design Capacity: %d mAh\n", design.design_capacity); - printf(" Full Charge Capacity: %d mAh\n", cap.full_charge_capacity); - printf(" Current Capacity: %d mAh\n", cap.remaining_capacity); - printf(" Charge Cycles: %d\n", cap.cycle_count); - printf(" Current Charge: %d%%\n", cap.relative_charge); + if (show_capacity) { + printf(" Full Charge Capacity: %d mAh\n", + cap.full_charge_capacity); + printf(" Current Capacity: %d mAh\n", + cap.remaining_capacity); + printf(" Charge Cycles: %d\n", cap.cycle_count); + printf(" Current Charge: %d%%\n", cap.relative_charge); + } printf(" Design Voltage: %d mV\n", design.design_voltage); printf(" Current Voltage: %d mV\n", stat.voltage); printf(" Temperature: %d C\n", stat.temperature);