diff options
Diffstat (limited to 'darwin.c')
-rw-r--r-- | darwin.c | 48 |
1 files changed, 47 insertions, 1 deletions
@@ -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 |