My slstatus configuration
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

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