minix/servers/procfs/root.c

212 lines
5.7 KiB
C
Raw Normal View History

/* ProcFS - root.c - by Alen Stojanov and David van Moolenbroek */
#include "inc.h"
#if defined (__i386__)
#include <machine/pci.h>
#endif
2011-12-11 15:24:28 +01:00
#include <minix/dmap.h>
#include "cpuinfo.h"
#include "mounts.h"
2012-03-25 20:25:53 +02:00
static void root_hz(void);
static void root_uptime(void);
static void root_loadavg(void);
static void root_kinfo(void);
static void root_meminfo(void);
#if defined(__i386__)
2012-03-25 20:25:53 +02:00
static void root_pci(void);
#endif
2012-03-25 20:25:53 +02:00
static void root_dmap(void);
2012-09-26 17:14:14 +02:00
static void root_ipcvecs(void);
struct file root_files[] = {
{ "hz", REG_ALL_MODE, (data_t) root_hz },
{ "uptime", REG_ALL_MODE, (data_t) root_uptime },
{ "loadavg", REG_ALL_MODE, (data_t) root_loadavg },
{ "kinfo", REG_ALL_MODE, (data_t) root_kinfo },
{ "meminfo", REG_ALL_MODE, (data_t) root_meminfo },
#if defined(__i386__)
{ "pci", REG_ALL_MODE, (data_t) root_pci },
#endif
2011-12-11 15:24:28 +01:00
{ "dmap", REG_ALL_MODE, (data_t) root_dmap },
#if defined(__i386__)
{ "cpuinfo", REG_ALL_MODE, (data_t) root_cpuinfo },
#endif
2012-09-26 17:14:14 +02:00
{ "ipcvecs", REG_ALL_MODE, (data_t) root_ipcvecs },
{ "mounts", REG_ALL_MODE, (data_t) root_mounts },
{ NULL, 0, NULL }
};
/*===========================================================================*
* root_hz *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
static void root_hz(void)
{
/* Print the system clock frequency.
*/
buf_printf("%lu\n", (long) sys_hz());
}
/*===========================================================================*
* root_loadavg *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
static void root_loadavg(void)
{
/* Print load averages.
*/
Build NetBSD libc library in world in ELF mode. 3 sets of libraries are built now: . ack: all libraries that ack can compile (/usr/lib/i386/) . clang+elf: all libraries with minix headers (/usr/lib/) . clang+elf: all libraries with netbsd headers (/usr/netbsd/) Once everything can be compiled with netbsd libraries and headers, the /usr/netbsd hierarchy will be obsolete and its libraries compiled with netbsd headers will be installed in /usr/lib, and its headers in /usr/include. (i.e. minix libc and current minix headers set will be gone.) To use the NetBSD libc system (libraries + headers) before it is the default libc, see: http://wiki.minix3.org/en/DevelopersGuide/UsingNetBSDCode This wiki page also documents the maintenance of the patch files of minix-specific changes to imported NetBSD code. Changes in this commit: . libsys: Add NBSD compilation and create a safe NBSD-based libc. . Port rest of libraries (except libddekit) to new header system. . Enable compilation of libddekit with new headers. . Enable kernel compilation with new headers. . Enable drivers compilation with new headers. . Port legacy commands to new headers and libc. . Port servers to new headers. . Add <sys/sigcontext.h> in compat library. . Remove dependency file in tree. . Enable compilation of common/lib/libc/atomic in libsys . Do not generate RCSID strings in libc. . Temporarily disable zoneinfo as they are incompatible with NetBSD format . obj-nbsd for .gitignore . Procfs: use only integer arithmetic. (Antoine Leca) . Increase ramdisk size to create NBSD-based images. . Remove INCSYMLINKS handling hack. . Add nbsd_include/sys/exec_elf.h . Enable ELF compilation with NBSD libc. . Add 'make nbsdsrc' in tools to download reference NetBSD sources. . Automate minix-port.patch creation. . Avoid using fstavfs() as it is *extremely* slow and unneeded. . Set err() as PRIVATE to avoid name clash with libc. . [NBSD] servers/vm: remove compilation warnings. . u32 is not a long in NBSD headers. . UPDATING info on netbsd hierarchy . commands fixes for netbsd libc
2011-04-27 15:00:52 +02:00
struct load loads[3];
ldiv_t avg[3];
Build NetBSD libc library in world in ELF mode. 3 sets of libraries are built now: . ack: all libraries that ack can compile (/usr/lib/i386/) . clang+elf: all libraries with minix headers (/usr/lib/) . clang+elf: all libraries with netbsd headers (/usr/netbsd/) Once everything can be compiled with netbsd libraries and headers, the /usr/netbsd hierarchy will be obsolete and its libraries compiled with netbsd headers will be installed in /usr/lib, and its headers in /usr/include. (i.e. minix libc and current minix headers set will be gone.) To use the NetBSD libc system (libraries + headers) before it is the default libc, see: http://wiki.minix3.org/en/DevelopersGuide/UsingNetBSDCode This wiki page also documents the maintenance of the patch files of minix-specific changes to imported NetBSD code. Changes in this commit: . libsys: Add NBSD compilation and create a safe NBSD-based libc. . Port rest of libraries (except libddekit) to new header system. . Enable compilation of libddekit with new headers. . Enable kernel compilation with new headers. . Enable drivers compilation with new headers. . Port legacy commands to new headers and libc. . Port servers to new headers. . Add <sys/sigcontext.h> in compat library. . Remove dependency file in tree. . Enable compilation of common/lib/libc/atomic in libsys . Do not generate RCSID strings in libc. . Temporarily disable zoneinfo as they are incompatible with NetBSD format . obj-nbsd for .gitignore . Procfs: use only integer arithmetic. (Antoine Leca) . Increase ramdisk size to create NBSD-based images. . Remove INCSYMLINKS handling hack. . Add nbsd_include/sys/exec_elf.h . Enable ELF compilation with NBSD libc. . Add 'make nbsdsrc' in tools to download reference NetBSD sources. . Automate minix-port.patch creation. . Avoid using fstavfs() as it is *extremely* slow and unneeded. . Set err() as PRIVATE to avoid name clash with libc. . [NBSD] servers/vm: remove compilation warnings. . u32 is not a long in NBSD headers. . UPDATING info on netbsd hierarchy . commands fixes for netbsd libc
2011-04-27 15:00:52 +02:00
if (procfs_getloadavg(loads, 3) != 3)
return;
Build NetBSD libc library in world in ELF mode. 3 sets of libraries are built now: . ack: all libraries that ack can compile (/usr/lib/i386/) . clang+elf: all libraries with minix headers (/usr/lib/) . clang+elf: all libraries with netbsd headers (/usr/netbsd/) Once everything can be compiled with netbsd libraries and headers, the /usr/netbsd hierarchy will be obsolete and its libraries compiled with netbsd headers will be installed in /usr/lib, and its headers in /usr/include. (i.e. minix libc and current minix headers set will be gone.) To use the NetBSD libc system (libraries + headers) before it is the default libc, see: http://wiki.minix3.org/en/DevelopersGuide/UsingNetBSDCode This wiki page also documents the maintenance of the patch files of minix-specific changes to imported NetBSD code. Changes in this commit: . libsys: Add NBSD compilation and create a safe NBSD-based libc. . Port rest of libraries (except libddekit) to new header system. . Enable compilation of libddekit with new headers. . Enable kernel compilation with new headers. . Enable drivers compilation with new headers. . Port legacy commands to new headers and libc. . Port servers to new headers. . Add <sys/sigcontext.h> in compat library. . Remove dependency file in tree. . Enable compilation of common/lib/libc/atomic in libsys . Do not generate RCSID strings in libc. . Temporarily disable zoneinfo as they are incompatible with NetBSD format . obj-nbsd for .gitignore . Procfs: use only integer arithmetic. (Antoine Leca) . Increase ramdisk size to create NBSD-based images. . Remove INCSYMLINKS handling hack. . Add nbsd_include/sys/exec_elf.h . Enable ELF compilation with NBSD libc. . Add 'make nbsdsrc' in tools to download reference NetBSD sources. . Automate minix-port.patch creation. . Avoid using fstavfs() as it is *extremely* slow and unneeded. . Set err() as PRIVATE to avoid name clash with libc. . [NBSD] servers/vm: remove compilation warnings. . u32 is not a long in NBSD headers. . UPDATING info on netbsd hierarchy . commands fixes for netbsd libc
2011-04-27 15:00:52 +02:00
avg[0] = ldiv(100L * loads[0].proc_load / loads[0].ticks, 100);
avg[1] = ldiv(100L * loads[1].proc_load / loads[1].ticks, 100);
avg[2] = ldiv(100L * loads[2].proc_load / loads[2].ticks, 100);
buf_printf("%ld.%0.2ld %ld.%02ld %ld.%02ld\n",
avg[0].quot, avg[0].rem, avg[1].quot, avg[1].rem,
avg[2].quot, avg[2].rem);
}
/*===========================================================================*
* root_uptime *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
static void root_uptime(void)
{
/* Print the current uptime.
*/
clock_t ticks;
Build NetBSD libc library in world in ELF mode. 3 sets of libraries are built now: . ack: all libraries that ack can compile (/usr/lib/i386/) . clang+elf: all libraries with minix headers (/usr/lib/) . clang+elf: all libraries with netbsd headers (/usr/netbsd/) Once everything can be compiled with netbsd libraries and headers, the /usr/netbsd hierarchy will be obsolete and its libraries compiled with netbsd headers will be installed in /usr/lib, and its headers in /usr/include. (i.e. minix libc and current minix headers set will be gone.) To use the NetBSD libc system (libraries + headers) before it is the default libc, see: http://wiki.minix3.org/en/DevelopersGuide/UsingNetBSDCode This wiki page also documents the maintenance of the patch files of minix-specific changes to imported NetBSD code. Changes in this commit: . libsys: Add NBSD compilation and create a safe NBSD-based libc. . Port rest of libraries (except libddekit) to new header system. . Enable compilation of libddekit with new headers. . Enable kernel compilation with new headers. . Enable drivers compilation with new headers. . Port legacy commands to new headers and libc. . Port servers to new headers. . Add <sys/sigcontext.h> in compat library. . Remove dependency file in tree. . Enable compilation of common/lib/libc/atomic in libsys . Do not generate RCSID strings in libc. . Temporarily disable zoneinfo as they are incompatible with NetBSD format . obj-nbsd for .gitignore . Procfs: use only integer arithmetic. (Antoine Leca) . Increase ramdisk size to create NBSD-based images. . Remove INCSYMLINKS handling hack. . Add nbsd_include/sys/exec_elf.h . Enable ELF compilation with NBSD libc. . Add 'make nbsdsrc' in tools to download reference NetBSD sources. . Automate minix-port.patch creation. . Avoid using fstavfs() as it is *extremely* slow and unneeded. . Set err() as PRIVATE to avoid name clash with libc. . [NBSD] servers/vm: remove compilation warnings. . u32 is not a long in NBSD headers. . UPDATING info on netbsd hierarchy . commands fixes for netbsd libc
2011-04-27 15:00:52 +02:00
ldiv_t division;
if (getuptime(&ticks) != OK)
return;
Build NetBSD libc library in world in ELF mode. 3 sets of libraries are built now: . ack: all libraries that ack can compile (/usr/lib/i386/) . clang+elf: all libraries with minix headers (/usr/lib/) . clang+elf: all libraries with netbsd headers (/usr/netbsd/) Once everything can be compiled with netbsd libraries and headers, the /usr/netbsd hierarchy will be obsolete and its libraries compiled with netbsd headers will be installed in /usr/lib, and its headers in /usr/include. (i.e. minix libc and current minix headers set will be gone.) To use the NetBSD libc system (libraries + headers) before it is the default libc, see: http://wiki.minix3.org/en/DevelopersGuide/UsingNetBSDCode This wiki page also documents the maintenance of the patch files of minix-specific changes to imported NetBSD code. Changes in this commit: . libsys: Add NBSD compilation and create a safe NBSD-based libc. . Port rest of libraries (except libddekit) to new header system. . Enable compilation of libddekit with new headers. . Enable kernel compilation with new headers. . Enable drivers compilation with new headers. . Port legacy commands to new headers and libc. . Port servers to new headers. . Add <sys/sigcontext.h> in compat library. . Remove dependency file in tree. . Enable compilation of common/lib/libc/atomic in libsys . Do not generate RCSID strings in libc. . Temporarily disable zoneinfo as they are incompatible with NetBSD format . obj-nbsd for .gitignore . Procfs: use only integer arithmetic. (Antoine Leca) . Increase ramdisk size to create NBSD-based images. . Remove INCSYMLINKS handling hack. . Add nbsd_include/sys/exec_elf.h . Enable ELF compilation with NBSD libc. . Add 'make nbsdsrc' in tools to download reference NetBSD sources. . Automate minix-port.patch creation. . Avoid using fstavfs() as it is *extremely* slow and unneeded. . Set err() as PRIVATE to avoid name clash with libc. . [NBSD] servers/vm: remove compilation warnings. . u32 is not a long in NBSD headers. . UPDATING info on netbsd hierarchy . commands fixes for netbsd libc
2011-04-27 15:00:52 +02:00
division = ldiv(100L * ticks / sys_hz(), 100L);
Build NetBSD libc library in world in ELF mode. 3 sets of libraries are built now: . ack: all libraries that ack can compile (/usr/lib/i386/) . clang+elf: all libraries with minix headers (/usr/lib/) . clang+elf: all libraries with netbsd headers (/usr/netbsd/) Once everything can be compiled with netbsd libraries and headers, the /usr/netbsd hierarchy will be obsolete and its libraries compiled with netbsd headers will be installed in /usr/lib, and its headers in /usr/include. (i.e. minix libc and current minix headers set will be gone.) To use the NetBSD libc system (libraries + headers) before it is the default libc, see: http://wiki.minix3.org/en/DevelopersGuide/UsingNetBSDCode This wiki page also documents the maintenance of the patch files of minix-specific changes to imported NetBSD code. Changes in this commit: . libsys: Add NBSD compilation and create a safe NBSD-based libc. . Port rest of libraries (except libddekit) to new header system. . Enable compilation of libddekit with new headers. . Enable kernel compilation with new headers. . Enable drivers compilation with new headers. . Port legacy commands to new headers and libc. . Port servers to new headers. . Add <sys/sigcontext.h> in compat library. . Remove dependency file in tree. . Enable compilation of common/lib/libc/atomic in libsys . Do not generate RCSID strings in libc. . Temporarily disable zoneinfo as they are incompatible with NetBSD format . obj-nbsd for .gitignore . Procfs: use only integer arithmetic. (Antoine Leca) . Increase ramdisk size to create NBSD-based images. . Remove INCSYMLINKS handling hack. . Add nbsd_include/sys/exec_elf.h . Enable ELF compilation with NBSD libc. . Add 'make nbsdsrc' in tools to download reference NetBSD sources. . Automate minix-port.patch creation. . Avoid using fstavfs() as it is *extremely* slow and unneeded. . Set err() as PRIVATE to avoid name clash with libc. . [NBSD] servers/vm: remove compilation warnings. . u32 is not a long in NBSD headers. . UPDATING info on netbsd hierarchy . commands fixes for netbsd libc
2011-04-27 15:00:52 +02:00
buf_printf("%ld.%0.2ld\n", division.quot, division.rem);
}
/*===========================================================================*
* root_kinfo *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
static void root_kinfo(void)
{
/* Print general kernel information.
*/
struct kinfo kinfo;
if (sys_getkinfo(&kinfo) != OK)
return;
buf_printf("%u %u\n", kinfo.nr_procs, kinfo.nr_tasks);
}
/*===========================================================================*
* root_meminfo *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
static void root_meminfo(void)
{
/* Print general memory information.
*/
struct vm_stats_info vsi;
if (vm_info_stats(&vsi) != OK)
return;
buf_printf("%u %lu %lu %lu %lu\n", vsi.vsi_pagesize,
vsi.vsi_total, vsi.vsi_free, vsi.vsi_largest, vsi.vsi_cached);
}
/*===========================================================================*
* root_pci *
*===========================================================================*/
#if defined(__i386__)
2012-03-25 20:25:53 +02:00
static void root_pci(void)
{
/* Print information about PCI devices present in the system.
*/
u16_t vid, did;
u8_t bcr, scr, pifr;
char *slot_name, *dev_name;
int r, devind;
static int first = TRUE;
/* This should be taken care of behind the scenes by the PCI lib. */
if (first) {
pci_init();
first = FALSE;
}
/* Iterate over all devices, printing info for each of them. */
r = pci_first_dev(&devind, &vid, &did);
while (r == 1) {
slot_name = pci_slot_name(devind);
dev_name = pci_dev_name(vid, did);
bcr = pci_attr_r8(devind, PCI_BCR);
scr = pci_attr_r8(devind, PCI_SCR);
pifr = pci_attr_r8(devind, PCI_PIFR);
buf_printf("%s %x/%x/%x %04X:%04X %s\n",
slot_name ? slot_name : "-",
bcr, scr, pifr, vid, did,
dev_name ? dev_name : "");
r = pci_next_dev(&devind, &vid, &did);
}
}
#endif /* defined(__i386__) */
2011-12-11 15:24:28 +01:00
/*===========================================================================*
* root_dmap *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
static void root_dmap(void)
2011-12-11 15:24:28 +01:00
{
struct dmap dmap[NR_DEVICES];
int i;
if (getsysinfo(VFS_PROC_NR, SI_DMAP_TAB, dmap, sizeof(dmap)) != OK)
return;
for (i = 0; i < NR_DEVICES; i++) {
if (dmap[i].dmap_driver == NONE)
continue;
buf_printf("%u %s %u\n", i, dmap[i].dmap_label,
dmap[i].dmap_driver);
}
}
2012-09-26 17:14:14 +02:00
/*===========================================================================*
* root_ipcvecs *
*===========================================================================*/
static void root_ipcvecs(void)
{
extern struct minix_kerninfo *_minix_kerninfo;
extern struct minix_ipcvecs _minix_ipcvecs;
/* only print this if the kernel provides the info; otherwise binaries
* will be using their own in-libc vectors that are normal symbols in the
* binary.
*/
if(!_minix_kerninfo || !(_minix_kerninfo->ki_flags & MINIX_KIF_IPCVECS))
return;
/* print the vectors with an descriptive name and the additional (k)
* to distinguish them from regular symbols.
*/
#define PRINT_ENTRYPOINT(name) \
buf_printf("%08lx T %s(k)\n", _minix_ipcvecs.name, #name)
2012-09-26 17:14:14 +02:00
PRINT_ENTRYPOINT(sendrec);
PRINT_ENTRYPOINT(send);
PRINT_ENTRYPOINT(notify);
PRINT_ENTRYPOINT(senda);
PRINT_ENTRYPOINT(sendnb);
PRINT_ENTRYPOINT(receive);
PRINT_ENTRYPOINT(do_kernel_call);
}