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.
 
 
 
 

61 lines
1004 B

  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 fmt_scaled(fs.f_frsize * fs.f_bavail);
  16. }
  17. const char *
  18. disk_perc(const char *mnt)
  19. {
  20. struct statvfs fs;
  21. if (statvfs(mnt, &fs) < 0) {
  22. warn("statvfs '%s':", mnt);
  23. return NULL;
  24. }
  25. return bprintf("%d", (int)(100 *
  26. (1.0f - ((float)fs.f_bavail / (float)fs.f_blocks))));
  27. }
  28. const char *
  29. disk_total(const char *mnt)
  30. {
  31. struct statvfs fs;
  32. if (statvfs(mnt, &fs) < 0) {
  33. warn("statvfs '%s':", mnt);
  34. return NULL;
  35. }
  36. return fmt_scaled(fs.f_frsize * fs.f_blocks);
  37. }
  38. const char *
  39. disk_used(const char *mnt)
  40. {
  41. struct statvfs fs;
  42. if (statvfs(mnt, &fs) < 0) {
  43. warn("statvfs '%s':", mnt);
  44. return NULL;
  45. }
  46. return fmt_scaled(fs.f_frsize * (fs.f_blocks - fs.f_bfree));
  47. }