#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/statvfs.h>
int
main(int argc, char **argv)
{
struct statvfs st;
if (argc != 2)
{
fprintf(stderr, "Usage: %s path\n", argv[0]);
exit(EXIT_FAILURE);
}
if (statvfs(argv[1], &st) < 0)
{
fprintf(stderr, "Failed to statvfs: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
/* Filesystem block size */
printf("Block size: %lu\n", st.f_bsize);
/* Total block size */
printf("Total blocks: %lu (%llu Bytes)\n",
st.f_blocks, (unsigned long long) st.f_bsize * st.f_blocks);
/* Used block size */
printf("Used blocks: %lu (%llu Bytes)\n",
st.f_blocks - st.f_bfree,
(unsigned long long) st.f_bsize * (st.f_blocks - st.f_bfree));
/* Free block size */
printf("Free blocks: %lu (%llu Bytes)\n",
st.f_bfree, (unsigned long long) st.f_bsize * st.f_bfree);
/* Available block size for non-superuser */
printf("Available blocks (For non-superuser): %lu (%llu Bytes)\n",
st.f_bavail, (unsigned long long) st.f_bsize * st.f_bavail);
return 0;
}

comments
comments rss (+댓글 쓰러가기)