df.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* df.c:
  2. *
  3. * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>,
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. */
  10. #include "sash.h"
  11. #include <fcntl.h>
  12. #include <sys/types.h>
  13. #include <sys/vfs.h>
  14. #include <sys/stat.h>
  15. #include <dirent.h>
  16. #include <pwd.h>
  17. #include <grp.h>
  18. #include <time.h>
  19. #include <linux/major.h>
  20. #ifdef __UC_LIBC__
  21. #include <linux/types.h>
  22. #endif
  23. #include <sys/time.h>
  24. #include <sys/param.h>
  25. #include <errno.h>
  26. void
  27. do_df(int argc, char * argv[])
  28. {
  29. char * name;
  30. struct statfs stbuf;
  31. #if 0
  32. fclose(stdin);
  33. #endif
  34. if (argc<2)
  35. name = "/";
  36. else
  37. name = argv[1];
  38. if (statfs(name, &stbuf) == -1) {
  39. printf("Unable to get disk space of %s: %s\n", name, strerror(errno));
  40. return;
  41. }
  42. printf("Total Kbytes: %ld\n", (stbuf.f_bsize / 256) * (stbuf.f_blocks / 4));
  43. printf("Free Kbytes: %ld\n", (stbuf.f_bsize / 256) * (stbuf.f_bfree / 4));
  44. printf("Total nodes: %ld\n", stbuf.f_files);
  45. printf("Free nodes: %ld\n", stbuf.f_ffree);
  46. }