From b84ab23c09a87b0341249f8bb4cf55cd742f7523 Mon Sep 17 00:00:00 2001 From: Alastair Poole Date: Sat, 9 Jun 2018 18:31:53 +0100 Subject: [PATCH] Add FreeBSD support for mount size/usage. --- src/disks.c | 14 +++++++++++--- src/ui.c | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/disks.c b/src/disks.c index f072060..27a4124 100644 --- a/src/disks.c +++ b/src/disks.c @@ -77,15 +77,23 @@ disk_mount_point_get(const char *path) Eina_Bool disk_usage_get(const char *mountpoint, unsigned long *total, unsigned long *used) { +#if defined(__linux__) struct statvfs stats; - *total = *used = 0; - if (statvfs(mountpoint, &stats) < 0) return EINA_FALSE; *total = stats.f_frsize * stats.f_blocks; *used = stats.f_bsize * stats.f_bavail; +#elif defined(__FreeBSD__) || defined(__DragonFly__) + struct statfs stats; + + if (statfs(mountpoint, &stats) < 0) + return EINA_FALSE; + + *total = stats.f_bsize * stats.f_blocks; + *used = *total - (stats.f_bsize * stats.f_bfree); +#endif return EINA_TRUE; } @@ -146,7 +154,7 @@ disks_get(void) list = eina_list_append(list, strdup(mounts[i].f_mntfromname)); } - list = list_sort(list, _cmp_cb); + list = eina_list_sort(list, eina_list_count(list), _cmp_cb); return list; #elif defined(__OpenBSD__) || defined(__NetBSD__) diff --git a/src/ui.c b/src/ui.c index 0f761b5..3a20715 100644 --- a/src/ui.c +++ b/src/ui.c @@ -798,7 +798,7 @@ _progress_disk_format_cb(double val) { char buf[1024]; - snprintf(buf, sizeof(buf), "%.2fM of %.1f M", (double) (_disk_used), (double) (_disk_total)); + snprintf(buf, sizeof(buf), "%luM of %luM", _disk_used, _disk_total); return strdup(buf); }