Add FreeBSD support for mount size/usage.

This commit is contained in:
Alastair Poole 2018-06-09 18:31:53 +01:00
parent a1bfadafaa
commit b84ab23c09
2 changed files with 12 additions and 4 deletions

View File

@ -77,15 +77,23 @@ disk_mount_point_get(const char *path)
Eina_Bool Eina_Bool
disk_usage_get(const char *mountpoint, unsigned long *total, unsigned long *used) disk_usage_get(const char *mountpoint, unsigned long *total, unsigned long *used)
{ {
#if defined(__linux__)
struct statvfs stats; struct statvfs stats;
*total = *used = 0;
if (statvfs(mountpoint, &stats) < 0) if (statvfs(mountpoint, &stats) < 0)
return EINA_FALSE; return EINA_FALSE;
*total = stats.f_frsize * stats.f_blocks; *total = stats.f_frsize * stats.f_blocks;
*used = stats.f_bsize * stats.f_bavail; *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; return EINA_TRUE;
} }
@ -146,7 +154,7 @@ disks_get(void)
list = eina_list_append(list, strdup(mounts[i].f_mntfromname)); 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; return list;
#elif defined(__OpenBSD__) || defined(__NetBSD__) #elif defined(__OpenBSD__) || defined(__NetBSD__)

View File

@ -798,7 +798,7 @@ _progress_disk_format_cb(double val)
{ {
char buf[1024]; 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); return strdup(buf);
} }