xref: /minix3/minix/fs/procfs/root.c (revision f1abbce7257a5fbf50b3422d6dd5631fd0bf26a5)
1*f1abbce7SDavid van Moolenbroek /* ProcFS - root.c - generators for static files in the root directory */
2433d6423SLionel Sambuc 
3433d6423SLionel Sambuc #include "inc.h"
4433d6423SLionel Sambuc 
5433d6423SLionel Sambuc #if defined (__i386__)
6433d6423SLionel Sambuc #include <machine/pci.h>
7433d6423SLionel Sambuc #endif
8433d6423SLionel Sambuc #include <minix/dmap.h>
9433d6423SLionel Sambuc 
10433d6423SLionel Sambuc static void root_hz(void);
11433d6423SLionel Sambuc static void root_uptime(void);
12433d6423SLionel Sambuc static void root_loadavg(void);
13433d6423SLionel Sambuc static void root_kinfo(void);
14433d6423SLionel Sambuc static void root_meminfo(void);
15433d6423SLionel Sambuc #if defined(__i386__)
16433d6423SLionel Sambuc static void root_pci(void);
17433d6423SLionel Sambuc #endif
18433d6423SLionel Sambuc static void root_dmap(void);
19433d6423SLionel Sambuc static void root_ipcvecs(void);
20433d6423SLionel Sambuc static void root_mounts(void);
21433d6423SLionel Sambuc 
22433d6423SLionel Sambuc struct file root_files[] = {
23433d6423SLionel Sambuc 	{ "hz",		REG_ALL_MODE,	(data_t) root_hz	},
24433d6423SLionel Sambuc 	{ "uptime",	REG_ALL_MODE,	(data_t) root_uptime	},
25433d6423SLionel Sambuc 	{ "loadavg",	REG_ALL_MODE,	(data_t) root_loadavg	},
26433d6423SLionel Sambuc 	{ "kinfo",	REG_ALL_MODE,	(data_t) root_kinfo	},
27433d6423SLionel Sambuc 	{ "meminfo",	REG_ALL_MODE,	(data_t) root_meminfo	},
28433d6423SLionel Sambuc #if defined(__i386__)
29433d6423SLionel Sambuc 	{ "pci",	REG_ALL_MODE,	(data_t) root_pci	},
30433d6423SLionel Sambuc #endif
31433d6423SLionel Sambuc 	{ "dmap",	REG_ALL_MODE,	(data_t) root_dmap	},
32433d6423SLionel Sambuc #if defined(__i386__)
33433d6423SLionel Sambuc 	{ "cpuinfo",	REG_ALL_MODE,	(data_t) root_cpuinfo	},
34433d6423SLionel Sambuc #endif
35433d6423SLionel Sambuc 	{ "ipcvecs",	REG_ALL_MODE,	(data_t) root_ipcvecs	},
36433d6423SLionel Sambuc 	{ "mounts",	REG_ALL_MODE,	(data_t) root_mounts	},
37433d6423SLionel Sambuc 	{ NULL,		0,		NULL			}
38433d6423SLionel Sambuc };
39433d6423SLionel Sambuc 
40*f1abbce7SDavid van Moolenbroek /*
41*f1abbce7SDavid van Moolenbroek  * Print the system clock frequency.
42433d6423SLionel Sambuc  */
43*f1abbce7SDavid van Moolenbroek static void
44*f1abbce7SDavid van Moolenbroek root_hz(void)
45*f1abbce7SDavid van Moolenbroek {
46433d6423SLionel Sambuc 
47*f1abbce7SDavid van Moolenbroek 	buf_printf("%lu\n", (unsigned long)sys_hz());
48433d6423SLionel Sambuc }
49433d6423SLionel Sambuc 
50*f1abbce7SDavid van Moolenbroek /*
51*f1abbce7SDavid van Moolenbroek  * Print load averages.
52433d6423SLionel Sambuc  */
53*f1abbce7SDavid van Moolenbroek static void
54*f1abbce7SDavid van Moolenbroek root_loadavg(void)
55*f1abbce7SDavid van Moolenbroek {
56433d6423SLionel Sambuc 	struct load loads[3];
57433d6423SLionel Sambuc 	ldiv_t avg[3];
58433d6423SLionel Sambuc 
59433d6423SLionel Sambuc 	if (procfs_getloadavg(loads, 3) != 3)
60433d6423SLionel Sambuc 		return;
61433d6423SLionel Sambuc 
62433d6423SLionel Sambuc 	avg[0] = ldiv(100L * loads[0].proc_load / loads[0].ticks, 100);
63433d6423SLionel Sambuc 	avg[1] = ldiv(100L * loads[1].proc_load / loads[1].ticks, 100);
64433d6423SLionel Sambuc 	avg[2] = ldiv(100L * loads[2].proc_load / loads[2].ticks, 100);
65433d6423SLionel Sambuc 
66433d6423SLionel Sambuc 	buf_printf("%ld.%02ld %ld.%02ld %ld.%02ld\n",
67433d6423SLionel Sambuc 	    avg[0].quot, avg[0].rem, avg[1].quot, avg[1].rem,
68433d6423SLionel Sambuc 	    avg[2].quot, avg[2].rem);
69433d6423SLionel Sambuc }
70433d6423SLionel Sambuc 
71*f1abbce7SDavid van Moolenbroek /*
72*f1abbce7SDavid van Moolenbroek  * Print the current uptime.
73433d6423SLionel Sambuc  */
74*f1abbce7SDavid van Moolenbroek static void
75*f1abbce7SDavid van Moolenbroek root_uptime(void)
76*f1abbce7SDavid van Moolenbroek {
77433d6423SLionel Sambuc 	clock_t ticks;
78433d6423SLionel Sambuc 	ldiv_t division;
79433d6423SLionel Sambuc 
80433d6423SLionel Sambuc 	if (getticks(&ticks) != OK)
81433d6423SLionel Sambuc 		return;
82433d6423SLionel Sambuc 	division = ldiv(100L * ticks / sys_hz(), 100L);
83433d6423SLionel Sambuc 
84433d6423SLionel Sambuc 	buf_printf("%ld.%0.2ld\n", division.quot, division.rem);
85433d6423SLionel Sambuc }
86433d6423SLionel Sambuc 
87*f1abbce7SDavid van Moolenbroek /*
88*f1abbce7SDavid van Moolenbroek  * Print general kernel information.
89433d6423SLionel Sambuc  */
90*f1abbce7SDavid van Moolenbroek static void
91*f1abbce7SDavid van Moolenbroek root_kinfo(void)
92*f1abbce7SDavid van Moolenbroek {
93433d6423SLionel Sambuc 	struct kinfo kinfo;
94433d6423SLionel Sambuc 
95433d6423SLionel Sambuc 	if (sys_getkinfo(&kinfo) != OK)
96433d6423SLionel Sambuc 		return;
97433d6423SLionel Sambuc 
98433d6423SLionel Sambuc 	buf_printf("%u %u\n", kinfo.nr_procs, kinfo.nr_tasks);
99433d6423SLionel Sambuc }
100433d6423SLionel Sambuc 
101*f1abbce7SDavid van Moolenbroek /*
102*f1abbce7SDavid van Moolenbroek  * Print general memory information.
103433d6423SLionel Sambuc  */
104*f1abbce7SDavid van Moolenbroek static void
105*f1abbce7SDavid van Moolenbroek root_meminfo(void)
106*f1abbce7SDavid van Moolenbroek {
107433d6423SLionel Sambuc 	struct vm_stats_info vsi;
108433d6423SLionel Sambuc 
109433d6423SLionel Sambuc 	if (vm_info_stats(&vsi) != OK)
110433d6423SLionel Sambuc 		return;
111433d6423SLionel Sambuc 
112*f1abbce7SDavid van Moolenbroek 	buf_printf("%u %lu %lu %lu %lu\n", vsi.vsi_pagesize, vsi.vsi_total,
113*f1abbce7SDavid van Moolenbroek 	    vsi.vsi_free, vsi.vsi_largest, vsi.vsi_cached);
114433d6423SLionel Sambuc }
115433d6423SLionel Sambuc 
116433d6423SLionel Sambuc #if defined(__i386__)
117*f1abbce7SDavid van Moolenbroek /*
118*f1abbce7SDavid van Moolenbroek  * Print information about PCI devices present in the system.
119433d6423SLionel Sambuc  */
120*f1abbce7SDavid van Moolenbroek static void
121*f1abbce7SDavid van Moolenbroek root_pci(void)
122*f1abbce7SDavid van Moolenbroek {
1239e77ef50SLionel Sambuc 	u16_t vid, did, subvid, subdid;
1249e77ef50SLionel Sambuc 	u8_t bcr, scr, pifr, rev;
125433d6423SLionel Sambuc 	char *slot_name, *dev_name;
126433d6423SLionel Sambuc 	int r, devind;
127433d6423SLionel Sambuc 	static int first = TRUE;
128433d6423SLionel Sambuc 
129433d6423SLionel Sambuc 	/* This should be taken care of behind the scenes by the PCI lib. */
130433d6423SLionel Sambuc 	if (first) {
131433d6423SLionel Sambuc 		pci_init();
132433d6423SLionel Sambuc 		first = FALSE;
133433d6423SLionel Sambuc 	}
134433d6423SLionel Sambuc 
135433d6423SLionel Sambuc 	/* Iterate over all devices, printing info for each of them. */
136433d6423SLionel Sambuc 	r = pci_first_dev(&devind, &vid, &did);
137433d6423SLionel Sambuc 	while (r == 1) {
138433d6423SLionel Sambuc 		slot_name = pci_slot_name(devind);
139433d6423SLionel Sambuc 		dev_name = pci_dev_name(vid, did);
140433d6423SLionel Sambuc 
141433d6423SLionel Sambuc 		bcr = pci_attr_r8(devind, PCI_BCR);
142433d6423SLionel Sambuc 		scr = pci_attr_r8(devind, PCI_SCR);
143433d6423SLionel Sambuc 		pifr = pci_attr_r8(devind, PCI_PIFR);
1449e77ef50SLionel Sambuc 		rev = pci_attr_r8(devind, PCI_REV);
1459e77ef50SLionel Sambuc 		subvid = pci_attr_r16(devind, PCI_SUBVID);
1469e77ef50SLionel Sambuc 		subdid = pci_attr_r16(devind, PCI_SUBDID);
147433d6423SLionel Sambuc 
1489e77ef50SLionel Sambuc 		buf_printf("%s %x/%x/%x/%x %04X:%04X:%04X:%04X %s\n",
1499e77ef50SLionel Sambuc 		    slot_name ? slot_name : "-1.-1.-1.-1",
1509e77ef50SLionel Sambuc 		    bcr, scr, pifr, rev,
1519e77ef50SLionel Sambuc 		    vid, did, subvid, subdid,
152433d6423SLionel Sambuc 		    dev_name ? dev_name : "");
153433d6423SLionel Sambuc 
154433d6423SLionel Sambuc 		r = pci_next_dev(&devind, &vid, &did);
155433d6423SLionel Sambuc 	}
156433d6423SLionel Sambuc }
157433d6423SLionel Sambuc #endif /* defined(__i386__) */
158433d6423SLionel Sambuc 
159*f1abbce7SDavid van Moolenbroek /*
160*f1abbce7SDavid van Moolenbroek  * Print a list of drivers that have been assigned major device numbers.
161*f1abbce7SDavid van Moolenbroek  */
162*f1abbce7SDavid van Moolenbroek static void
163*f1abbce7SDavid van Moolenbroek root_dmap(void)
164433d6423SLionel Sambuc {
165433d6423SLionel Sambuc 	struct dmap dmap[NR_DEVICES];
166433d6423SLionel Sambuc 	int i;
167433d6423SLionel Sambuc 
168433d6423SLionel Sambuc 	if (getsysinfo(VFS_PROC_NR, SI_DMAP_TAB, dmap, sizeof(dmap)) != OK)
169433d6423SLionel Sambuc 		return;
170433d6423SLionel Sambuc 
171433d6423SLionel Sambuc 	for (i = 0; i < NR_DEVICES; i++) {
172433d6423SLionel Sambuc 		if (dmap[i].dmap_driver == NONE)
173433d6423SLionel Sambuc 			continue;
174433d6423SLionel Sambuc 
175433d6423SLionel Sambuc 		buf_printf("%u %s %u\n", i, dmap[i].dmap_label,
176433d6423SLionel Sambuc 		    dmap[i].dmap_driver);
177433d6423SLionel Sambuc 	}
178433d6423SLionel Sambuc }
179433d6423SLionel Sambuc 
180*f1abbce7SDavid van Moolenbroek /*
181*f1abbce7SDavid van Moolenbroek  * Print a list of IPC vectors with their addresses.
182*f1abbce7SDavid van Moolenbroek  */
183*f1abbce7SDavid van Moolenbroek static void
184*f1abbce7SDavid van Moolenbroek root_ipcvecs(void)
185433d6423SLionel Sambuc {
186433d6423SLionel Sambuc 	extern struct minix_kerninfo *_minix_kerninfo;
187433d6423SLionel Sambuc 	extern struct minix_ipcvecs _minix_ipcvecs;
188433d6423SLionel Sambuc 
189*f1abbce7SDavid van Moolenbroek 	/*
190*f1abbce7SDavid van Moolenbroek 	 * Only print this if the kernel provides the info; otherwise binaries
191*f1abbce7SDavid van Moolenbroek 	 * will be using their own in-libc vectors that are normal symbols in
192*f1abbce7SDavid van Moolenbroek 	 * the binary.
193433d6423SLionel Sambuc 	 */
194*f1abbce7SDavid van Moolenbroek 	if (!_minix_kerninfo ||
195*f1abbce7SDavid van Moolenbroek 	    !(_minix_kerninfo->ki_flags & MINIX_KIF_IPCVECS))
196433d6423SLionel Sambuc 		return;
197433d6423SLionel Sambuc 
198*f1abbce7SDavid van Moolenbroek 	/*
199*f1abbce7SDavid van Moolenbroek 	 * Print the vectors with an descriptive name and the additional (k)
200433d6423SLionel Sambuc 	 * to distinguish them from regular symbols.
201433d6423SLionel Sambuc 	 */
202433d6423SLionel Sambuc #define PRINT_ENTRYPOINT(name) \
203*f1abbce7SDavid van Moolenbroek 	buf_printf("%08lx T %s(k)\n", \
204*f1abbce7SDavid van Moolenbroek 	    (unsigned long)_minix_ipcvecs.name, #name)
205433d6423SLionel Sambuc 
206433d6423SLionel Sambuc 	PRINT_ENTRYPOINT(sendrec);
207433d6423SLionel Sambuc 	PRINT_ENTRYPOINT(send);
208433d6423SLionel Sambuc 	PRINT_ENTRYPOINT(notify);
209433d6423SLionel Sambuc 	PRINT_ENTRYPOINT(senda);
210433d6423SLionel Sambuc 	PRINT_ENTRYPOINT(sendnb);
211433d6423SLionel Sambuc 	PRINT_ENTRYPOINT(receive);
212433d6423SLionel Sambuc 	PRINT_ENTRYPOINT(do_kernel_call);
213433d6423SLionel Sambuc }
214433d6423SLionel Sambuc 
215*f1abbce7SDavid van Moolenbroek /*
216*f1abbce7SDavid van Moolenbroek  * Print the list of mounted file systems.
217*f1abbce7SDavid van Moolenbroek  */
218433d6423SLionel Sambuc static void
219433d6423SLionel Sambuc root_mounts(void)
220433d6423SLionel Sambuc {
221433d6423SLionel Sambuc 	struct statvfs buf[NR_MNTS];
222433d6423SLionel Sambuc 	int i, count;
223433d6423SLionel Sambuc 
224433d6423SLionel Sambuc 	if ((count = getvfsstat(buf, sizeof(buf), ST_NOWAIT)) < 0)
225433d6423SLionel Sambuc 		return;
226433d6423SLionel Sambuc 
227433d6423SLionel Sambuc 	for (i = 0; i < count; i++) {
228433d6423SLionel Sambuc 		buf_printf("%s on %s type %s (%s)\n", buf[i].f_mntfromname,
229433d6423SLionel Sambuc 		    buf[i].f_mntonname, buf[i].f_fstypename,
230433d6423SLionel Sambuc 		    (buf[i].f_flag & ST_RDONLY) ? "ro" : "rw");
231433d6423SLionel Sambuc 	}
232433d6423SLionel Sambuc }
233