My slstatus configuration
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

disk.c 1.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <err.h>
  2. #include <stdio.h>
  3. #include <sys/statvfs.h>
  4. #include "util.h"
  5. const char *
  6. disk_free(const char *mnt)
  7. {
  8. struct statvfs fs;
  9. if (statvfs(mnt, &fs) < 0) {
  10. warn("Failed to get filesystem info");
  11. return NULL;
  12. }
  13. return bprintf("%f", (float)fs.f_bsize * (float)fs.f_bfree / 1024 / 1024 / 1024);
  14. }
  15. const char *
  16. disk_perc(const char *mnt)
  17. {
  18. int perc;
  19. struct statvfs fs;
  20. if (statvfs(mnt, &fs) < 0) {
  21. warn("Failed to get filesystem info");
  22. return NULL;
  23. }
  24. perc = 100 * (1.0f - ((float)fs.f_bfree / (float)fs.f_blocks));
  25. return bprintf("%d", perc);
  26. }
  27. const char *
  28. disk_total(const char *mnt)
  29. {
  30. struct statvfs fs;
  31. if (statvfs(mnt, &fs) < 0) {
  32. warn("Failed to get filesystem info");
  33. return NULL;
  34. }
  35. return bprintf("%f", (float)fs.f_bsize * (float)fs.f_blocks / 1024 / 1024 / 1024);
  36. }
  37. const char *
  38. disk_used(const char *mnt)
  39. {
  40. struct statvfs fs;
  41. if (statvfs(mnt, &fs) < 0) {
  42. warn("Failed to get filesystem info");
  43. return NULL;
  44. }
  45. return bprintf("%f", (float)fs.f_bsize * ((float)fs.f_blocks - (float)fs.f_bfree) / 1024 / 1024 / 1024);
  46. }