diff options
author | Baptiste Daroussin <bapt@FreeBSD.org> | 2015-12-11 20:45:39 +0000 |
---|---|---|
committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2015-12-11 20:45:39 +0000 |
commit | d7654478d3dc93e09534c65a86e7a28923b0eb4f (patch) | |
tree | 251519af3d649ea5dc2952367b4c474152f04457 /usr.sbin/sesutil/eltsub.c | |
parent | 95fd7f26154281528fc8fc01fd29e961a054555f (diff) | |
download | src-d7654478d3dc93e09534c65a86e7a28923b0eb4f.tar.gz src-d7654478d3dc93e09534c65a86e7a28923b0eb4f.zip |
sesutil: Add extra information specific to some SES devices to sesutil map
Rework stat2ascii preparing a buffer of what could be printed. This prevent the
risk of overflowing a static buffer.
Do not print those informations anymore in the "status" but into a new
"extra status" only printed if there are actually extra things to print.
Now add those extra informations:
* Thermal sensor temperature
* Cooling devices speed
* Voltage sensors, current consumption
Tested by: AllanJude
Sponsored by: Gandi.net
Differential Revision: https://reviews.freebsd.org/D4520
Notes
Notes:
svn path=/head/; revision=292121
Diffstat (limited to 'usr.sbin/sesutil/eltsub.c')
-rw-r--r-- | usr.sbin/sesutil/eltsub.c | 75 |
1 files changed, 58 insertions, 17 deletions
diff --git a/usr.sbin/sesutil/eltsub.c b/usr.sbin/sesutil/eltsub.c index 0e79bd2ce304..287530d1c591 100644 --- a/usr.sbin/sesutil/eltsub.c +++ b/usr.sbin/sesutil/eltsub.c @@ -32,6 +32,11 @@ * mjacob@feral.com */ +#include <sys/endian.h> +#include <sys/types.h> +#include <sys/sbuf.h> + +#include <err.h> #include <unistd.h> #include <stddef.h> #include <stdint.h> @@ -43,6 +48,13 @@ #include "eltsub.h" +/* + * offset by +20 degrees. + * The range of the value expresses a temperature between -19 and +235 degrees + * Celsius. A value of 00h is reserved. + */ +#define TEMPERATURE_OFFSET 20 + char * geteltnm(int type) { @@ -134,7 +146,7 @@ geteltnm(int type) return (rbuf); } -static char * +char * scode2ascii(u_char code) { static char rbuf[32]; @@ -173,22 +185,51 @@ scode2ascii(u_char code) return (rbuf); } - -char * -stat2ascii(int eletype, u_char *cstat) +struct sbuf * +stat2sbuf(int eletype, u_char *cstat) { - static char ebuf[256], *scode; + struct sbuf *buf; + + buf = sbuf_new_auto(); + if (buf == NULL) + err(EXIT_FAILURE, "sbuf_new_auto()"); - scode = scode2ascii(cstat[0]); - sprintf(ebuf, "%s%s%s%s%s%s (0x%02x 0x%02x 0x%02x 0x%02x)", - scode, - (cstat[0] & 0x40) ? ", Prd.Fail" : "", - (cstat[0] & 0x20) ? ", Disabled" : "", - (cstat[0] & 0x10) ? ", Swapped" : "", - ((eletype == ELMTYP_DEVICE || eletype == ELMTYP_ARRAY_DEV) - && (cstat[2] & 0x02)) ? ", LED=Locate" : "", - ((eletype == ELMTYP_DEVICE || eletype == ELMTYP_ARRAY_DEV) - && (cstat[3] & 0x20)) ? ", LED=Fault" : "", - cstat[0], cstat[1], cstat[2], cstat[3]); - return (ebuf); + if (cstat[0] & 0x40) + sbuf_printf(buf, "\t\t- Predicted Failure\n"); + if (cstat[0] & 0x20) + sbuf_printf(buf, "\t\t- Disabled\n"); + if (cstat[0] & 0x10) + sbuf_printf(buf, "\t\t- Swapped\n"); + switch (eletype) { + case ELMTYP_DEVICE: + if (cstat[2] & 0x02) + sbuf_printf(buf, "\t\t- LED=locate\n"); + if (cstat[2] & 0x20) + sbuf_printf(buf, "\t\t- LED=fault\n"); + break; + case ELMTYP_ARRAY_DEV: + if (cstat[2] & 0x02) + sbuf_printf(buf, "\t\t- LED=locate\n"); + if (cstat[2] & 0x20) + sbuf_printf(buf, "\t\t- LED=fault\n"); + break; + case ELMTYP_FAN: + sbuf_printf(buf, "\t\t- Speed: %d rpm\n", + (((0x7 & cstat[1]) << 8) + cstat[2]) * 10); + break; + case ELMTYP_THERM: + if (cstat[2]) { + sbuf_printf(buf, "\t\t- Temperature: %d C\n", + cstat[2] - TEMPERATURE_OFFSET); + } else { + sbuf_printf(buf, "\t\t- Temperature: -reserved-\n"); + } + break; + case ELMTYP_VOM: + sbuf_printf(buf, "\t\t- Voltage: %.2f V\n", + be16dec(cstat + 2) / 100.0); + break; + } + sbuf_finish(buf); + return (buf); } |