New file.

1998-07-22  Martin Baulig  <martin@home-of-linux.org>

	* include/glibtop/fsusage.h: New file.

	* features.def: Added new feature `fsusage'.

	* sysdeps/common/fsusage.c (glibtop_get_fsusage_s): New function.
	(get_fs_usage): Declared as `static'.

	* sysdeps/names/fsusage.c: New file.
This commit is contained in:
Martin Baulig
1998-07-22 22:56:09 +00:00
committed by Martin Baulig
parent a90bffbbf6
commit 954a78f200
15 changed files with 234 additions and 19 deletions

View File

@@ -1,5 +1,14 @@
1998-07-22 Martin Baulig <martin@home-of-linux.org> 1998-07-22 Martin Baulig <martin@home-of-linux.org>
* include/glibtop/fsusage.h: New file.
* features.def: Added new feature `fsusage'.
* sysdeps/common/fsusage.c (glibtop_get_fsusage_s): New function.
(get_fs_usage): Declared as `static'.
* sysdeps/names/fsusage.c: New file.
* include/glibtop/mountlist.h: New file. * include/glibtop/mountlist.h: New file.
* features.def: Added new feature `mountlist'. * features.def: Added new feature `mountlist'.

View File

@@ -29,6 +29,7 @@
#include <glibtop/parameter.h> #include <glibtop/parameter.h>
#include <glibtop/mountlist.h> #include <glibtop/mountlist.h>
#include <glibtop/fsusage.h>
#ifndef PROFILE_COUNT #ifndef PROFILE_COUNT
#define PROFILE_COUNT 1000 #define PROFILE_COUNT 1000
@@ -37,6 +38,7 @@
int int
main (int argc, char *argv []) main (int argc, char *argv [])
{ {
glibtop_fsusage fsusage;
glibtop_mountlist mount_list; glibtop_mountlist mount_list;
glibtop_mountentry *mount_entries; glibtop_mountentry *mount_entries;
unsigned c, index, method, count, port; unsigned c, index, method, count, port;
@@ -85,8 +87,24 @@ main (int argc, char *argv [])
mount_entries [index].type, mount_entries [index].type,
mount_entries [index].devname); mount_entries [index].devname);
printf ("\n\n%-23s %9s %9s %9s %9s %9s\n\n",
"", "Blocks", "Free", "Avail", "Files", "Free");
for (index = 0; index < mount_list.number; index++) {
glibtop_get_fsusage (&fsusage,
mount_entries [index].mountdir);
printf ("Usage: %-16s %9lu %9lu %9lu %9lu %9lu\n",
mount_entries [index].mountdir,
fsusage.blocks, fsusage.bfree,
fsusage.bavail, fsusage.files,
fsusage.ffree);
}
glibtop_free (mount_entries); glibtop_free (mount_entries);
printf ("\nsbrk (0) = %p\n\n", sbrk (0));
glibtop_close (); glibtop_close ();
exit (0); exit (0);

View File

@@ -15,3 +15,4 @@ proc_signal ulong(signal,blocked,sigignore,sigcatch)
proc_kernel ulong(k_flags,min_flt,maj_flt,cmin_flt,cmaj_flt,kstk_esp,kstk_eip,wchan) proc_kernel ulong(k_flags,min_flt,maj_flt,cmin_flt,cmaj_flt,kstk_esp,kstk_eip,wchan)
proc_segment long(trs,lrs,drs,dt):ulong(start_code,end_code,start_stack) proc_segment long(trs,lrs,drs,dt):ulong(start_code,end_code,start_stack)
@mountlist ulong(number,size,total) @mountlist ulong(number,size,total)
fsusage ulong(blocks,bfree,bavail,files,ffree)

View File

@@ -49,8 +49,9 @@ __BEGIN_DECLS
#define GLIBTOP_CMND_PROC_SEGMENT 17 #define GLIBTOP_CMND_PROC_SEGMENT 17
#define GLIBTOP_CMND_MOUNTLIST 18 #define GLIBTOP_CMND_MOUNTLIST 18
#define GLIBTOP_CMND_FSUSAGE 19
#define GLIBTOP_MAX_CMND 19 #define GLIBTOP_MAX_CMND 20
#define _GLIBTOP_PARAM_SIZE 16 #define _GLIBTOP_PARAM_SIZE 16

90
include/glibtop/fsusage.h Normal file
View File

@@ -0,0 +1,90 @@
/* $Id$ */
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Top Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef __GLIBTOP_FSUSAGE_H__
#define __GLIBTOP_FSUSAGE_H__
#include <glibtop.h>
#include <glibtop/global.h>
__BEGIN_DECLS
#define GLIBTOP_FSUSAGE_BLOCKS 0
#define GLIBTOP_FSUSAGE_BFREE 1
#define GLIBTOP_FSUSAGE_BAVAIL 2
#define GLIBTOP_FSUSAGE_FILES 3
#define GLIBTOP_FSUSAGE_FFREE 4
#define GLIBTOP_MAX_FSUSAGE 5
typedef struct _glibtop_fsusage glibtop_fsusage;
struct _glibtop_fsusage
{
unsigned long flags,
blocks, /* Total blocks. */
bfree, /* Free blocks available to superuser. */
bavail, /* Free blocks available to non-superuser. */
files, /* Total file nodes. */
ffree; /* Free file nodes. */
};
#define glibtop_get_fsusage(fsusage,disk) glibtop_get_fsusage_l(glibtop_global_server, fsusage, disk)
#define glibtop_get_fsusage_r glibtop_get_fsusage_s
extern void glibtop_get_fsusage_l __P((glibtop *, glibtop_fsusage *, const char *));
extern void glibtop_get_fsusage_s __P((glibtop *, glibtop_fsusage *, const char *));
#ifdef HAVE_GUILE
/* You need to link with -lgtop_guile to get this stuff here. */
extern SCM glibtop_guile_get_fsusage __P((SCM));
#endif
#ifdef GLIBTOP_GUILE_NAMES
/* You need to link with -lgtop_guile_names to get this stuff here. */
extern SCM glibtop_guile_names_fsusage __P((void));
extern SCM glibtop_guile_types_fsusage __P((void));
extern SCM glibtop_guile_labels_fsusage __P((void));
extern SCM glibtop_guile_descriptions_fsusage __P((void));
#endif
#ifdef GLIBTOP_NAMES
/* You need to link with -lgtop_names to get this stuff here. */
extern const char *glibtop_names_fsusage [];
extern const unsigned glibtop_types_fsusage [];
extern const char *glibtop_labels_fsusage [];
extern const char *glibtop_descriptions_fsusage [];
#endif
__END_DECLS
#endif

View File

@@ -45,8 +45,9 @@ __BEGIN_DECLS
#define GLIBTOP_SYSDEPS_PROC_KERNEL 15 #define GLIBTOP_SYSDEPS_PROC_KERNEL 15
#define GLIBTOP_SYSDEPS_PROC_SEGMENT 16 #define GLIBTOP_SYSDEPS_PROC_SEGMENT 16
#define GLIBTOP_SYSDEPS_MOUNTLIST 17 #define GLIBTOP_SYSDEPS_MOUNTLIST 17
#define GLIBTOP_SYSDEPS_FSUSAGE 18
#define GLIBTOP_MAX_SYSDEPS 18 #define GLIBTOP_MAX_SYSDEPS 19
#define GLIBTOP_SYSDEPS_ALL ((1 << GLIBTOP_MAX_SYSDEPS) - 1) #define GLIBTOP_SYSDEPS_ALL ((1 << GLIBTOP_MAX_SYSDEPS) - 1)
@@ -72,7 +73,8 @@ struct _glibtop_sysdeps
proc_signal, /* glibtop_proc_signal */ proc_signal, /* glibtop_proc_signal */
proc_kernel, /* glibtop_proc_kernel */ proc_kernel, /* glibtop_proc_kernel */
proc_segment, /* glibtop_proc_segment */ proc_segment, /* glibtop_proc_segment */
mountlist; /* glibtop_mountlist */ mountlist, /* glibtop_mountlist */
fsusage; /* glibtop_fsusage */
}; };
#define glibtop_get_sysdeps(sysdeps) glibtop_get_sysdeps_r(glibtop_global_server,sysdeps) #define glibtop_get_sysdeps(sysdeps) glibtop_get_sysdeps_r(glibtop_global_server,sysdeps)

View File

@@ -41,6 +41,7 @@
#include <glibtop/procsegment.h> #include <glibtop/procsegment.h>
#include <glibtop/mountlist.h> #include <glibtop/mountlist.h>
#include <glibtop/fsusage.h>
__BEGIN_DECLS __BEGIN_DECLS
@@ -65,6 +66,7 @@ union _glibtop_union
glibtop_proc_kernel proc_kernel; glibtop_proc_kernel proc_kernel;
glibtop_proc_segment proc_segment; glibtop_proc_segment proc_segment;
glibtop_mountlist mountlist; glibtop_mountlist mountlist;
glibtop_fsusage fsusage;
}; };
__END_DECLS __END_DECLS

View File

@@ -26,6 +26,8 @@ function output(feature) {
} }
if (feature ~ /^proc_/) { if (feature ~ /^proc_/) {
param = ", pid_t pid"; param = ", pid_t pid";
} else if (feature ~ /^fsusage$/) {
param = ", const char *mountdir";
} else { } else {
param = ""; param = "";
} }
@@ -46,6 +48,13 @@ function output(feature) {
print "\t} else {"; print "\t} else {";
print "#if (!GLIBTOP_SUID_"toupper(feature)")"; print "#if (!GLIBTOP_SUID_"toupper(feature)")";
print "\t\tglibtop_get_"feature"_r (server, buf, pid);"; print "\t\tglibtop_get_"feature"_r (server, buf, pid);";
} else if (feature ~ /^fsusage$/) {
print "\t\tglibtop_call_l (server, GLIBTOP_CMND_"toupper(feature)",";
print "\t\t\t\tstrlen (mountdir) + 1, mountdir,";
print "\t\t\t\tsizeof (glibtop_"feature"), buf);";
print "\t} else {";
print "#if (!GLIBTOP_SUID_"toupper(feature)")";
print "\t\tglibtop_get_"feature"_r (server, buf, mountdir);";
} else { } else {
if (feature ~ /^mountlist$/) { if (feature ~ /^mountlist$/) {
print "\t\treturn glibtop_call_l (server, GLIBTOP_CMND_MOUNTLIST,"; print "\t\treturn glibtop_call_l (server, GLIBTOP_CMND_MOUNTLIST,";

View File

@@ -166,6 +166,12 @@ handle_parent_connection (int s)
resp->u.data.mountlist.total, mount_list); resp->u.data.mountlist.total, mount_list);
glibtop_free_r (server, mount_list); glibtop_free_r (server, mount_list);
break; break;
case GLIBTOP_CMND_FSUSAGE:
glibtop_get_fsusage_l
(server, &resp->u.data.fsusage, parameter);
do_output (s, resp, _offset_data (fsusage),
0, NULL);
break;
default: default:
glibtop_warn ("Parent received unknown command %u", glibtop_warn ("Parent received unknown command %u",
cmnd->command); cmnd->command);

View File

@@ -62,6 +62,13 @@ int statfs ();
int statvfs (); int statvfs ();
#endif #endif
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/fsusage.h>
static int get_fs_usage __P ((const char *, const char *,
struct fs_usage *));
int safe_read (); int safe_read ();
/* Return the number of TOSIZE-byte blocks used by /* Return the number of TOSIZE-byte blocks used by
@@ -93,7 +100,7 @@ adjust_blocks (blocks, fromsize, tosize)
Return 0 if successful, -1 if not. When returning -1, ensure that Return 0 if successful, -1 if not. When returning -1, ensure that
ERRNO is either a system error value, or zero if DISK is NULL ERRNO is either a system error value, or zero if DISK is NULL
on a system that requires a non-NULL value. */ on a system that requires a non-NULL value. */
int static int
get_fs_usage (path, disk, fsp) get_fs_usage (path, disk, fsp)
const char *path; const char *path;
const char *disk; const char *disk;
@@ -272,3 +279,23 @@ statfs (path, fsb)
} }
#endif /* _AIX && _I386 */ #endif /* _AIX && _I386 */
void
glibtop_get_fsusage_s (glibtop *server, glibtop_fsusage *buf,
const char *disk)
{
struct fs_usage fsp;
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_fsusage));
if (get_fs_usage (disk, disk, &fsp))
return;
buf->blocks = fsp.fsu_blocks;
buf->bfree = fsp.fsu_bfree;
buf->bavail = fsp.fsu_bavail;
buf->files = fsp.fsu_files;
buf->ffree = fsp.fsu_ffree;
}

View File

@@ -25,13 +25,3 @@ struct fs_usage
long fsu_ffree; /* Free file nodes. */ long fsu_ffree; /* Free file nodes. */
}; };
#ifndef __P
#if defined (__GNUC__) || (defined (__STDC__) && __STDC__)
#define __P(args) args
#else
#define __P(args) ()
#endif /* GCC. */
#endif /* Not __P. */
int get_fs_usage __P ((const char *path, const char *disk,
struct fs_usage *fsp));

View File

@@ -30,6 +30,10 @@ BEGIN {
output = "SCM\nglibtop_guile_get_"$1" (SCM pid)\n{\n"; output = "SCM\nglibtop_guile_get_"$1" (SCM pid)\n{\n";
output = output"\tglibtop_"$1" "$1";\n\n"; output = output"\tglibtop_"$1" "$1";\n\n";
output = output"\tglibtop_get_"$1" (&"$1", (pid_t) gh_scm2long (pid));\n\n"; output = output"\tglibtop_get_"$1" (&"$1", (pid_t) gh_scm2long (pid));\n\n";
} else if ($1 ~ /^fsusage$/) {
output = "SCM\nglibtop_guile_get_"$1" (SCM mountdir)\n{\n";
output = output"\tglibtop_"$1" "$1";\n\n";
output = output"\tglibtop_get_"$1" (&"$1", gh_scm2newstr (mountdir, NULL));\n\n";
} else { } else {
output = "SCM\nglibtop_guile_get_"$1" (void)\n{\n"; output = "SCM\nglibtop_guile_get_"$1" (void)\n{\n";
output = output"\tglibtop_"$1" "$1";\n\n"; output = output"\tglibtop_"$1" "$1";\n\n";
@@ -77,6 +81,8 @@ END {
for (feature in features) { for (feature in features) {
if (feature ~ /^proc_/) { if (feature ~ /^proc_/) {
print "\tgh_new_procedure1_0"; print "\tgh_new_procedure1_0";
} else if (feature ~ /^fsusage$/) {
print "\tgh_new_procedure1_0";
} else { } else {
print "\tgh_new_procedure0_0"; print "\tgh_new_procedure0_0";
} }

View File

@@ -12,5 +12,4 @@ libgtop_names_la_SOURCES = cpu.c mem.c swap.c uptime.c loadavg.c \
shm_limits.c msg_limits.c sem_limits.c \ shm_limits.c msg_limits.c sem_limits.c \
proclist.c sysdeps.c procstate.c procuid.c \ proclist.c sysdeps.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c prockernel.c \ proctime.c procmem.c procsignal.c prockernel.c \
procsegment.c procsegment.c fsusage.c

51
sysdeps/names/fsusage.c Normal file
View File

@@ -0,0 +1,51 @@
/* $Id$ */
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Top Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <glibtop/fsusage.h>
const char *glibtop_names_fsusage [GLIBTOP_MAX_FSUSAGE] =
{
"blocks", "bfree", "bavail", "files", "ffree"
};
const unsigned glibtop_types_fsusage [GLIBTOP_MAX_FSUSAGE] =
{
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG,
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG
};
const char *glibtop_labels_fsusage [GLIBTOP_MAX_FSUSAGE] =
{
N_("Total blocks"),
N_("Free blocks"),
N_("Available blocks"),
N_("Total file nodes"),
N_("Free file nodes")
};
const char *glibtop_descriptions_fsusage [GLIBTOP_MAX_FSUSAGE] =
{
N_("Total blocks"),
N_("Free blocks available to the superuser"),
N_("Free blocks available to non-superusers"),
N_("Total file nodes"),
N_("Free file nodes")
};

View File

@@ -26,7 +26,8 @@ const char *glibtop_names_sysdeps [GLIBTOP_MAX_SYSDEPS] =
"features", "cpu", "mem", "swap", "uptime", "loadavg", "features", "cpu", "mem", "swap", "uptime", "loadavg",
"shm_limits", "msg_limits", "sem_limits", "proclist", "shm_limits", "msg_limits", "sem_limits", "proclist",
"proc_state", "proc_uid", "proc_mem", "proc_time", "proc_state", "proc_uid", "proc_mem", "proc_time",
"proc_signal", "proc_kernel", "proc_segment", "mountlist" "proc_signal", "proc_kernel", "proc_segment", "mountlist",
"fsusage"
}; };
const unsigned glibtop_types_sysdeps [GLIBTOP_MAX_SYSDEPS] = const unsigned glibtop_types_sysdeps [GLIBTOP_MAX_SYSDEPS] =
@@ -36,7 +37,8 @@ const unsigned glibtop_types_sysdeps [GLIBTOP_MAX_SYSDEPS] =
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG,
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG,
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG,
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG,
GLIBTOP_TYPE_ULONG
}; };
const char *glibtop_labels_sysdeps [GLIBTOP_MAX_SYSDEPS] = const char *glibtop_labels_sysdeps [GLIBTOP_MAX_SYSDEPS] =
@@ -58,7 +60,8 @@ const char *glibtop_labels_sysdeps [GLIBTOP_MAX_SYSDEPS] =
N_("Process Signal information"), N_("Process Signal information"),
N_("Process Kernel Data information"), N_("Process Kernel Data information"),
N_("Process Segment information"), N_("Process Segment information"),
N_("Mount List") N_("Mount List"),
N_("File System Usage"),
}; };
const char *glibtop_descriptions_sysdeps [GLIBTOP_MAX_SYSDEPS] = const char *glibtop_descriptions_sysdeps [GLIBTOP_MAX_SYSDEPS] =
@@ -81,4 +84,5 @@ const char *glibtop_descriptions_sysdeps [GLIBTOP_MAX_SYSDEPS] =
N_("Process Kernel Data information"), N_("Process Kernel Data information"),
N_("Process Segment information"), N_("Process Segment information"),
N_("List of currently mounted filesystems"), N_("List of currently mounted filesystems"),
N_("File System Usage"),
}; };