summaryrefslogtreecommitdiffstats
path: root/src/hardware/smartctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hardware/smartctl.c')
-rw-r--r--src/hardware/smartctl.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/hardware/smartctl.c b/src/hardware/smartctl.c
index 835e8b5..b1b0ce7 100644
--- a/src/hardware/smartctl.c
+++ b/src/hardware/smartctl.c
@@ -39,6 +39,7 @@ void init_smctlhdd_struct(SmartctlHdd *hdd)
hdd->port_speed = 0;
hdd->max_port_speed = 0;
hdd->rpm = 0xffffffff;
+ hdd->capacity = 0;
}
/*
@@ -333,6 +334,32 @@ short smartctl_get_hdds(SmartctlHdd **hdds, unsigned *hdds_nb)
buf = NULL;
continue;
}
+ /* Capacity */
+ buf = copy_string_part_after_delim(buffer[i], "User Capacity:");
+ if (buf) {
+ /* capacity is in bytes and uses thousand separator -
+ * it must be cleaned */
+ char *buf2 = (char *)calloc(strlen(buf), sizeof(char));
+ if (buf2) {
+ int k = 0;
+ for (int j = 0; buf[j]; j++) {
+ if (buf[j] >= '0' && buf[j] <= '9') {
+ buf2[k++] = buf[j];
+ } else if (buf[j] == 'b') {
+ /* word after capacity is "bytes" */
+ break;
+ }
+ }
+ buf2[k] = '\0';
+ sscanf(buf2, "%lu", &(*hdds)[curr_hdd].capacity);
+ free(buf2);
+ } else {
+ warn("Failed to allocate memory.");
+ }
+ free(buf);
+ buf = NULL;
+ continue;
+ }
}
free_2d_buffer(&buffer, &buffer_size);