Blame examples/mountlist.c

Packit d37888
/* Copyright (C) 1998-99 Martin Baulig
Packit d37888
   This file is part of LibGTop 1.0.
Packit d37888
Packit d37888
   Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
Packit d37888
Packit d37888
   LibGTop is free software; you can redistribute it and/or modify it
Packit d37888
   under the terms of the GNU General Public License as published by
Packit d37888
   the Free Software Foundation; either version 2 of the License,
Packit d37888
   or (at your option) any later version.
Packit d37888
Packit d37888
   LibGTop is distributed in the hope that it will be useful, but WITHOUT
Packit d37888
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Packit d37888
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
Packit d37888
   for more details.
Packit d37888
Packit d37888
   You should have received a copy of the GNU General Public License
Packit d37888
   along with LibGTop; see the file COPYING. If not, write to the
Packit d37888
   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Packit d37888
   Boston, MA 02110-1301, USA.
Packit d37888
*/
Packit d37888
Packit d37888
#ifdef HAVE_CONFIG_H
Packit d37888
#  include <config.h>
Packit d37888
#endif
Packit d37888
Packit d37888
#include <locale.h>
Packit d37888
#include <libintl.h>
Packit d37888
#include <stdio.h>
Packit d37888
Packit d37888
#include <glibtop.h>
Packit d37888
#include <glibtop/open.h>
Packit d37888
#include <glibtop/close.h>
Packit d37888
Packit d37888
#include <glibtop/parameter.h>
Packit d37888
Packit d37888
#include <glibtop/mountlist.h>
Packit d37888
#include <glibtop/fsusage.h>
Packit d37888
Packit d37888
#ifndef PROFILE_COUNT
Packit d37888
#define PROFILE_COUNT	1000
Packit d37888
#endif
Packit d37888
Packit d37888
int
Packit d37888
main (int argc, char *argv [])
Packit d37888
{
Packit d37888
	glibtop_fsusage fsusage;
Packit d37888
	glibtop_mountlist mount_list;
Packit d37888
	glibtop_mountentry *mount_entries;
Packit d37888
	unsigned c, index, method, count, port;
Packit d37888
	char buffer [BUFSIZ];
Packit d37888
Packit d37888
	setlocale (LC_ALL, "");
Packit d37888
	bindtextdomain (GETTEXT_PACKAGE, GTOPLOCALEDIR);
Packit d37888
	textdomain (GETTEXT_PACKAGE);
Packit d37888
Packit d37888
	glibtop_init_r (&glibtop_global_server, 0, GLIBTOP_INIT_NO_OPEN);
Packit d37888
Packit d37888
	glibtop_get_parameter (GLIBTOP_PARAM_METHOD, &method, sizeof (method));
Packit d37888
Packit d37888
	printf ("Method = %d\n", method);
Packit d37888
Packit d37888
	count = glibtop_get_parameter (GLIBTOP_PARAM_COMMAND, buffer, BUFSIZ);
Packit d37888
	buffer [count] = 0;
Packit d37888
Packit d37888
	printf ("Command = '%s'\n", buffer);
Packit d37888
Packit d37888
	count = glibtop_get_parameter (GLIBTOP_PARAM_HOST, buffer, BUFSIZ);
Packit d37888
	buffer [count] = 0;
Packit d37888
Packit d37888
	glibtop_get_parameter (GLIBTOP_PARAM_PORT, &port, sizeof (port));
Packit d37888
Packit d37888
	printf ("Host = '%s' - %u\n\n", buffer, port);
Packit d37888
Packit d37888
	printf ("sbrk (0) = %p\n\n", sbrk (0));
Packit d37888
Packit d37888
	for (c = 0; c < PROFILE_COUNT; c++) {
Packit d37888
		mount_entries = glibtop_get_mountlist (&mount_list, 1);
Packit d37888
Packit d37888
		g_free (mount_entries);
Packit d37888
	}
Packit d37888
Packit d37888
	printf ("sbrk (0) = %p\n\n", sbrk (0));
Packit d37888
Packit d37888
	mount_entries = glibtop_get_mountlist (&mount_list, 1);
Packit d37888
Packit d37888
	if (mount_entries == NULL)
Packit d37888
		_exit (1);
Packit d37888
Packit d37888
	for (index = 0; index < mount_list.number; index++)
Packit d37888
		printf ("Mount_Entry: %-30s %-10s %-20s\n",
Packit d37888
			mount_entries [index].mountdir,
Packit d37888
			mount_entries [index].type,
Packit d37888
			mount_entries [index].devname);
Packit d37888
Packit d37888
	printf ("\n\n%-16s %9s %9s %9s %9s %9s %9s\n",
Packit d37888
		"Mount", "Blocks", "Free", "Avail", "Files", "Free", "BlockSz");
Packit d37888
Packit d37888
	for (index = 0; index < mount_list.number; index++) {
Packit d37888
		glibtop_get_fsusage (&fsusage,
Packit d37888
				     mount_entries [index].mountdir);
Packit d37888
Packit d37888
		printf ("%-16s %9Lu %9Lu %9Lu %9Lu %9Lu %9d\n",
Packit d37888
			mount_entries [index].mountdir,
Packit d37888
			fsusage.blocks, fsusage.bfree,
Packit d37888
			fsusage.bavail, fsusage.files,
Packit d37888
			fsusage.ffree, fsusage.block_size);
Packit d37888
	}
Packit d37888
Packit d37888
	g_free (mount_entries);
Packit d37888
Packit d37888
	printf ("\nsbrk (0) = %p\n\n", sbrk (0));
Packit d37888
Packit d37888
	glibtop_close ();
Packit d37888
Packit d37888
	exit (0);
Packit d37888
}