/* 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
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 divisor, 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:
				divisor = KILOBYTE;
				base = KILOBYTE;
				break;
			case KILOBYTE:
				divisor = KILOBYTE;
				base = 1;
				break;
			default:
				divisor = KILOBYTE;
				base = 0;
		}

		printf("%-20s %9s ", device,
			   format((s.f_blocks * (s.f_bsize / divisor)), base));
		printf("%9s ",
			   format(((s.f_blocks - s.f_bfree) * 
					   (s.f_bsize / divisor)), base));
		printf("%9s %3ld%% %s\n",
			   format((s.f_bavail * (s.f_bsize / divisor)), 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:
*/
