/*
 * displays statfs output. (C) 2006 Christian Neumair <chris@gnome-de.org>, GPLv2 or later */

#include <sys/statfs.h>
#include <errno.h>
#include <stdio.h>

int
main (int    argc,
      char **argv)
{
	struct statfs buf;

	if (argc != 2)
		return 1;

	if (statfs (argv[1], &buf) != 0) {
		char *err;

		switch (errno) {
			case EACCES:
				err = "EACCES";
				break;
			case EBADF:
				err = "EBADF";
				break;
			case EFAULT:
				err = "EFAULT";
				break;
			case EINTR:
				err = "EINTR";
				break;
			case EIO:
				err = "EIO";
				break;
			case ELOOP:
				err = "ELOOP";
				break;
			case ENAMETOOLONG:
				err = "ENAMETOOLONG";
				break;
			case ENOENT:
				err = "ENOENT";
				break;
			case ENOMEM:
				err = "ENOMEM";
				break;
			case ENOSYS:
				err = "ENOSYS";
				break;
			case ENOTDIR:
				err = "ENOTDIR";
				break;
			case EOVERFLOW:
				err = "EOVERFLOW";
				break;
			default:
				err = "(SHOULD_NOT_HAPPEN)";
				break;
		}
		fprintf (stderr, "error during statfs %s\n", err);
		return 1;
	}

	printf ("FS type: %x\n", buf.f_type);
	printf ("block size: %d\n", buf.f_bsize);
	printf ("data blocks: %d\n", buf.f_blocks);
	printf ("free data blocks: %d\n", buf.f_bfree);
	printf ("avail. user data blocks: %d\n", buf.f_bavail);
	printf ("file nodes: %d\n", buf.f_files);
	printf ("free file nodes: %d\n", buf.f_ffree);
	/* skipping f_fsid */
	printf ("f_namelen: %d\n", buf.f_namelen);
	return 0;
}
