summaryrefslogtreecommitdiff
path: root/usr.sbin/mfiutil
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2011-09-27 14:28:07 +0000
committerEd Maste <emaste@FreeBSD.org>2011-09-27 14:28:07 +0000
commitb08d3049f03327723a6adb372d8432808a575921 (patch)
tree4aa4a29572f489798234793a4f39685e7531616e /usr.sbin/mfiutil
parent79a5956c23b590f1818e6b3a0e2414b11b4ed28a (diff)
downloadsrc-test2-b08d3049f03327723a6adb372d8432808a575921.tar.gz
src-test2-b08d3049f03327723a6adb372d8432808a575921.zip
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.) Reviewd by: jhb, bz Tested by: pluknet@, Garrett Cooper PR: bin/160581 MFC after: 1 week
Notes
Notes: svn path=/head/; revision=225798
Diffstat (limited to 'usr.sbin/mfiutil')
-rw-r--r--usr.sbin/mfiutil/mfi_show.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/usr.sbin/mfiutil/mfi_show.c b/usr.sbin/mfiutil/mfi_show.c
index 9d9f7a11c57c..4f83b52e3100 100644
--- a/usr.sbin/mfiutil/mfi_show.c
+++ b/usr.sbin/mfiutil/mfi_show.c
@@ -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);