My slstatus configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

65 lines
1.2 KiB

  1. /* See LICENSE file for copyright and license details. */
  2. #include <errno.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <sys/statvfs.h>
  6. #include "../util.h"
  7. const char *
  8. disk_free(const char *mnt)
  9. {
  10. struct statvfs fs;
  11. if (statvfs(mnt, &fs) < 0) {
  12. warn("statvfs '%s':", mnt);
  13. return NULL;
  14. }
  15. return bprintf("%f",
  16. (float)fs.f_frsize * (float)fs.f_bavail / 1024 / 1024 / 1024);
  17. }
  18. const char *
  19. disk_perc(const char *mnt)
  20. {
  21. struct statvfs fs;
  22. if (statvfs(mnt, &fs) < 0) {
  23. warn("statvfs '%s':", mnt);
  24. return NULL;
  25. }
  26. return bprintf("%d", (int)(100 *
  27. (1.0f - ((float)fs.f_bavail / (float)fs.f_blocks))));
  28. }
  29. const char *
  30. disk_total(const char *mnt)
  31. {
  32. struct statvfs fs;
  33. if (statvfs(mnt, &fs) < 0) {
  34. warn("statvfs '%s':", mnt);
  35. return NULL;
  36. }
  37. return bprintf("%f",
  38. (float)fs.f_frsize * (float)fs.f_blocks / 1024 / 1024 / 1024);
  39. }
  40. const char *
  41. disk_used(const char *mnt)
  42. {
  43. struct statvfs fs;
  44. if (statvfs(mnt, &fs) < 0) {
  45. warn("statvfs '%s':", mnt);
  46. return NULL;
  47. }
  48. return bprintf("%f",
  49. (float)fs.f_frsize * ((float)fs.f_blocks -
  50. (float)fs.f_bfree) / 1024 / 1024 / 1024);
  51. }