Show temperatures in degrees fahrenheit by the option.
Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
__u16 temperature = smart->temperature[1] << 8 | smart->temperature[0];
int i;
bool human = stdout_print_ops.flags & VERBOSE;
+ bool fahrenheit = !!(stdout_print_ops.flags & FAHRENHEIT);
printf("Smart Log for NVME device:%s namespace-id:%x\n", devname, nsid);
printf("critical_warning : %#x\n",
printf(" Persistent Mem. RO[5] : %d\n", (smart->critical_warning & 0x20) >> 5);
}
- printf("temperature : %ld °C (%u K)\n",
- kelvin_to_celsius(temperature), temperature);
+ printf("temperature : %s (%u K)\n",
+ nvme_degrees_string(temperature, fahrenheit), temperature);
printf("available_spare : %u%%\n",
smart->avail_spare);
printf("available_spare_threshold : %u%%\n",
le32_to_cpu(smart->warning_temp_time));
printf("Critical Composite Temperature Time : %u\n",
le32_to_cpu(smart->critical_comp_time));
- for (i = 0; i < 8; i++) {
- __s32 temp = le16_to_cpu(smart->temp_sensor[i]);
-
- if (temp == 0)
+ for (i = 0; i < ARRAY_SIZE(smart->temp_sensor); i++) {
+ temperature = le16_to_cpu(smart->temp_sensor[i]);
+ if (!temperature)
continue;
- printf("Temperature Sensor %d : %ld °C (%u K)\n",
- i + 1, kelvin_to_celsius(temp), temp);
+ printf("Temperature Sensor %d : %s (%u K)\n", i + 1,
+ nvme_degrees_string(temperature, fahrenheit), temperature);
}
printf("Thermal Management T1 Trans Count : %u\n",
le32_to_cpu(smart->thm_temp1_trans_count));
nvme_print(endurance_log, flags, endurance_log, group_id, devname);
}
+const char *nvme_degrees_string(long t, bool fahrenheit)
+{
+ static char str[STR_LEN];
+ long val = kelvin_to_celsius(t);
+
+ if (fahrenheit)
+ val = kelvin_to_fahrenheit(t);
+
+ sprintf(str, "%ld °%s", val, fahrenheit ? "F" : "C");
+
+
+ return str;
+}
+
void nvme_show_smart_log(struct nvme_smart_log *smart, unsigned int nsid,
const char *devname, enum nvme_print_flags flags)
{
bool nvme_is_fabrics_reg(int offset);
bool nvme_registers_cmbloc_support(__u32 cmbsz);
bool nvme_registers_pmrctl_ready(__u32 pmrctl);
+const char *nvme_degrees_string(long t, bool fahrenheit);
#endif /* NVME_PRINT_H */
static const char *dry = "show command instead of sending";
static const char *dspec_w_dtype = "directive specification associated with directive type";
static const char *dtype = "directive type";
+static const char *fahrenheit = "show temperatures in degrees fahrenheit";
static const char *force_unit_access = "force device to commit data before command completes";
static const char *human_readable_directive = "show directive in readable format";
static const char *human_readable_identify = "show identify in readable format";
__u32 namespace_id;
bool raw_binary;
bool human_readable;
+ bool fahrenheit;
};
struct config cfg = {
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_output),
- OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable_info));
+ OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable_info),
+ OPT_FLAG("fahrenheit", 'f', &cfg.fahrenheit, fahrenheit));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
if (cfg.human_readable)
flags |= VERBOSE;
+ if (cfg.fahrenheit)
+ flags |= FAHRENHEIT;
+
smart_log = nvme_alloc(sizeof(*smart_log));
if (!smart_log)
return -ENOMEM;
#include "util/cleanup.h"
enum nvme_print_flags {
- NORMAL = 0,
- VERBOSE = 1 << 0, /* verbosely decode complex values for humans */
- JSON = 1 << 1, /* display in json format */
- VS = 1 << 2, /* hex dump vendor specific data areas */
- BINARY = 1 << 3, /* binary dump raw bytes */
+ NORMAL = 0,
+ VERBOSE = 1 << 0, /* verbosely decode complex values for humans */
+ JSON = 1 << 1, /* display in json format */
+ VS = 1 << 2, /* hex dump vendor specific data areas */
+ BINARY = 1 << 3, /* binary dump raw bytes */
+ FAHRENHEIT = 1 << 4, /* show temperatures in degrees fahrenheit */
};
enum nvme_cli_topo_ranking {
return t + ABSOLUTE_ZERO_CELSIUS;
}
+static inline long celsius_to_fahrenheit(long t)
+{
+ return t * 9 / 5 + 32;
+}
+
+static inline long kelvin_to_fahrenheit(long t)
+{
+ return celsius_to_fahrenheit(kelvin_to_celsius(t));
+}
+
/* uint128_t is not always available, define our own. */
union nvme_uint128 {
__u8 bytes[16];