/* vi: set sw=4 ts=4: */
/*
 * Mini df implementation for busybox
 *
 * Copyright (C) 1999,2000,2001 by Lineo, inc.
 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
 * based on original code by (I think) Bruce Perens <bruce@pixar.com>.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <mntent.h>
#include <sys/vfs.h>
#include <getopt.h>
#include "busybox.h"

extern const char mtab_file[];	/* Defined in utility.c */
#ifdef BB_FEATURE_HUMAN_READABLE
static unsigned long disp_hr = KILOBYTE; 
#endif

static int df(char *device, const char *mountPoint)
{
	struct statfs s;
	long blocks_used;
	long blocks_percent_used;
#ifdef BB_FEATURE_HUMAN_READABLE
	long base;
#endif	

	if (statfs(mountPoint, &s) != 0) {
		perror_msg("%s", mountPoint);
		return FALSE;
	}

	if (s.f_blocks > 0) {
		blocks_used = s.f_blocks - s.f_bfree;
		if(blocks_used == 0)
			blocks_percent_used = 0;
		else {
			blocks_percent_used = (long)
			  (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
		}
		if (strcmp(device, "/dev/root") == 0) {
			/* Adjusts device to be the real root device,
			 * or leaves device alone if it can't find it */
			find_real_root_device_name( device);
		}
		#ifdef BB_FEATURE_HUMAN_READABLE
		switch (disp_hr) {
			case MEGABYTE:
				base = KILOBYTE;
				break;
			case KILOBYTE:
				base = 1;
				break;
			default:
				base = 0;
		}
		printf("%-20s %9s ", device,
			   format(s.f_blocks * (s.f_bsize/KILOBYTE), base));
		printf("%9s ",
			   format((s.f_blocks - s.f_bfree) * (s.f_bsize/KILOBYTE), base));
		printf("%9s %3ld%% %s\n",
			   format(s.f_bavail * (s.f_bsize/KILOBYTE), base),
			   blocks_percent_used, mountPoint);
#else
		printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
				device,
				(long) (s.f_blocks * (s.f_bsize / KILOBYTE)),
				(long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / KILOBYTE)),
				(long) (s.f_bavail * (s.f_bsize / KILOBYTE)),
				blocks_percent_used, mountPoint);
#endif
	}

	return TRUE;
}

extern int df_main(int argc, char **argv)
{
	int status = EXIT_SUCCESS;
	int opt = 0;
	int i = 0;

	while ((opt = getopt(argc, argv, 
#ifdef BB_FEATURE_HUMAN_READABLE
	"hm"
#endif
	"k"
)) > 0)
	{
		switch (opt) {
#ifdef BB_FEATURE_HUMAN_READABLE
			case 'h': disp_hr = 0;         break;
			case 'm': disp_hr = MEGABYTE;  break;
#endif
			case 'k': break;
			default:
					  show_usage();
		}
	}

	printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
#ifdef BB_FEATURE_HUMAN_READABLE
			(KILOBYTE == disp_hr) ? "1k-blocks" :
			(MEGABYTE == disp_hr) ? "1M-blocks" : "     Size",
#else
		   "1k-blocks",
#endif
	       "Used", "Available", "Use%", "Mounted on");


	if(optind < argc) {
		struct mntent *mountEntry;
		for(i = optind; i < argc; i++)
		{
			if ((mountEntry = find_mount_point(argv[i], mtab_file)) == 0) {
				error_msg("%s: can't find mount point.", argv[i]);
				status = EXIT_FAILURE;
			} else if (!df(mountEntry->mnt_fsname, mountEntry->mnt_dir))
				status = EXIT_FAILURE;
		}
	} else {
		FILE *mountTable;
		struct mntent *mountEntry;

		mountTable = setmntent(mtab_file, "r");
		if (mountTable == 0) {
			perror_msg("%s", mtab_file);
			return EXIT_FAILURE;
		}

		while ((mountEntry = getmntent(mountTable))) {
			if (!df(mountEntry->mnt_fsname, mountEntry->mnt_dir))
				status = EXIT_FAILURE;
		}
		endmntent(mountTable);
	}

	return status;
}

/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
