aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.h3
-rw-r--r--darwin.c48
2 files changed, 50 insertions, 1 deletions
diff --git a/common.h b/common.h
index 9cc3e6b..a5a1fee 100644
--- a/common.h
+++ b/common.h
@@ -19,6 +19,9 @@
#elif defined(__APPLE__)
#include <sys/types.h>
#include <sys/sysctl.h>
+#include <sys/param.h>
+#include <sys/ucred.h>
+#include <sys/mount.h>
#endif
union regs_t {
diff --git a/darwin.c b/darwin.c
index 4a5986b..2d9b3f6 100644
--- a/darwin.c
+++ b/darwin.c
@@ -33,6 +33,52 @@ int get_sys_os_dist(char **name, char **version) {
}
struct Block_Device **get_block_devices(size_t *total) {
- return NULL;
+ struct Block_Device **result;
+ size_t devices_total;
+ size_t count;
+ struct statfs *mnt;
+ int mnt_flags;
+
+ if (!(devices_total = getmntinfo(&mnt, mnt_flags))) {
+ perror("Unable to read mount points");
+ return NULL;
+ }
+
+ result = calloc(devices_total + 1, sizeof(*result));
+ if (!result) {
+ perror("Unable to allocate device array");
+ return NULL;
+ }
+
+ count = 0;
+ char path_prev[PATH_MAX] = {0};
+ for (size_t i = 0; i < devices_total; i++) {
+ if (strncmp(mnt[i].f_mntfromname, "/dev/", 5) != 0) {
+ continue;
+ }
+ result[count] = calloc(1, sizeof(*result[0]));
+ if (!result[count]) {
+ perror("Unable to allocate mount point record");
+ exit(1);
+ }
+ char path_temp[PATH_MAX] = {0};
+ size_t dnum = 0;
+ sscanf(&mnt[i].f_mntfromname[5], "disk%zus%*s", &dnum);
+ sprintf(path_temp, "disk%zu", dnum);
+ if (strlen(path_prev) && !strcmp(path_prev, path_temp)) {
+ continue;
+ }
+ strcpy(path_prev, path_temp);
+ result[count]->path = strdup(path_temp);
+ result[count]->model = strdup("Unnamed");
+ result[count]->size = (mnt[i].f_bsize * mnt[i].f_blocks) / 1024;
+ count++;
+ }
+ if (devices_total != count) {
+ *total = count;
+ } else {
+ *total = devices_total;
+ }
+ return result;
}
#endif