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.
 
 
 
 

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