tst-statfs.c 723 B

123456789101112131415161718192021222324252627282930313233
  1. #define _FILE_OFFSET_BITS 64
  2. #include <sys/vfs.h>
  3. #include <errno.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. int
  8. main(int argc, char* argv[])
  9. {
  10. struct statfs s;
  11. int ret = 0, i;
  12. for (i = 1; i < argc; i++) {
  13. if (statfs(argv[i], &s) != 0) {
  14. fprintf(stderr, "%s: %s: statfs failed. %s\n",
  15. *argv, argv[i], strerror(errno));
  16. exit(EXIT_FAILURE);
  17. }
  18. ++ret;
  19. printf("statfs %s:\n\tblocks=%lld\n\tblkfree=%lld\n\tbsize=%d\n",
  20. argv[i], s.f_blocks, s.f_bfree, s.f_bsize);
  21. #ifdef _STATFS_F_FRSIZE
  22. printf("\tfrsize=%lld\n", s.f_frsize);
  23. #elif defined __mips__
  24. printf("\tfrsize=mips, unsupported?\n");
  25. #else
  26. # error no _STATFS_F_FRSIZE
  27. #endif
  28. }
  29. exit(ret ? EXIT_SUCCESS : EXIT_FAILURE);
  30. }