xref: /minix3/minix/fs/procfs/root.c (revision d91f738bd8d93aa6befa2a8d07581040607a512a)
1f1abbce7SDavid 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 
40f1abbce7SDavid van Moolenbroek /*
41f1abbce7SDavid van Moolenbroek  * Print the system clock frequency.
42433d6423SLionel Sambuc  */
43f1abbce7SDavid van Moolenbroek static void
root_hz(void)44f1abbce7SDavid van Moolenbroek root_hz(void)
45f1abbce7SDavid van Moolenbroek {
46433d6423SLionel Sambuc 
47f1abbce7SDavid van Moolenbroek 	buf_printf("%lu\n", (unsigned long)sys_hz());
48433d6423SLionel Sambuc }
49433d6423SLionel Sambuc 
50f1abbce7SDavid van Moolenbroek /*
51f1abbce7SDavid van Moolenbroek  * Print load averages.
52433d6423SLionel Sambuc  */
53f1abbce7SDavid van Moolenbroek static void
root_loadavg(void)54f1abbce7SDavid van Moolenbroek root_loadavg(void)
55f1abbce7SDavid 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 
71f1abbce7SDavid van Moolenbroek /*
72f1abbce7SDavid van Moolenbroek  * Print the current uptime.
73433d6423SLionel Sambuc  */
74f1abbce7SDavid van Moolenbroek static void
root_uptime(void)75f1abbce7SDavid van Moolenbroek root_uptime(void)
76f1abbce7SDavid van Moolenbroek {
77433d6423SLionel Sambuc 	ldiv_t division;
78433d6423SLionel Sambuc 
79*d91f738bSDavid van Moolenbroek 	division = ldiv(100L * getticks() / sys_hz(), 100L);
80433d6423SLionel Sambuc 
81433d6423SLionel Sambuc 	buf_printf("%ld.%0.2ld\n", division.quot, division.rem);
82433d6423SLionel Sambuc }
83433d6423SLionel Sambuc 
84f1abbce7SDavid van Moolenbroek /*
85f1abbce7SDavid van Moolenbroek  * Print general kernel information.
86433d6423SLionel Sambuc  */
87f1abbce7SDavid van Moolenbroek static void
root_kinfo(void)88f1abbce7SDavid van Moolenbroek root_kinfo(void)
89f1abbce7SDavid van Moolenbroek {
90433d6423SLionel Sambuc 	struct kinfo kinfo;
91433d6423SLionel Sambuc 
92433d6423SLionel Sambuc 	if (sys_getkinfo(&kinfo) != OK)
93433d6423SLionel Sambuc 		return;
94433d6423SLionel Sambuc 
95433d6423SLionel Sambuc 	buf_printf("%u %u\n", kinfo.nr_procs, kinfo.nr_tasks);
96433d6423SLionel Sambuc }
97433d6423SLionel Sambuc 
98f1abbce7SDavid van Moolenbroek /*
99f1abbce7SDavid van Moolenbroek  * Print general memory information.
100433d6423SLionel Sambuc  */
101f1abbce7SDavid van Moolenbroek static void
root_meminfo(void)102f1abbce7SDavid van Moolenbroek root_meminfo(void)
103f1abbce7SDavid van Moolenbroek {
104433d6423SLionel Sambuc 	struct vm_stats_info vsi;
105433d6423SLionel Sambuc 
106433d6423SLionel Sambuc 	if (vm_info_stats(&vsi) != OK)
107433d6423SLionel Sambuc 		return;
108433d6423SLionel Sambuc 
109f1abbce7SDavid van Moolenbroek 	buf_printf("%u %lu %lu %lu %lu\n", vsi.vsi_pagesize, vsi.vsi_total,
110f1abbce7SDavid van Moolenbroek 	    vsi.vsi_free, vsi.vsi_largest, vsi.vsi_cached);
111433d6423SLionel Sambuc }
112433d6423SLionel Sambuc 
113433d6423SLionel Sambuc #if defined(__i386__)
114f1abbce7SDavid van Moolenbroek /*
115f1abbce7SDavid van Moolenbroek  * Print information about PCI devices present in the system.
116433d6423SLionel Sambuc  */
117f1abbce7SDavid van Moolenbroek static void
root_pci(void)118f1abbce7SDavid van Moolenbroek root_pci(void)
119f1abbce7SDavid van Moolenbroek {
1209e77ef50SLionel Sambuc 	u16_t vid, did, subvid, subdid;
1219e77ef50SLionel Sambuc 	u8_t bcr, scr, pifr, rev;
122433d6423SLionel Sambuc 	char *slot_name, *dev_name;
123433d6423SLionel Sambuc 	int r, devind;
124433d6423SLionel Sambuc 	static int first = TRUE;
125433d6423SLionel Sambuc 
126433d6423SLionel Sambuc 	/* This should be taken care of behind the scenes by the PCI lib. */
127433d6423SLionel Sambuc 	if (first) {
128433d6423SLionel Sambuc 		pci_init();
129433d6423SLionel Sambuc 		first = FALSE;
130433d6423SLionel Sambuc 	}
131433d6423SLionel Sambuc 
132433d6423SLionel Sambuc 	/* Iterate over all devices, printing info for each of them. */
133433d6423SLionel Sambuc 	r = pci_first_dev(&devind, &vid, &did);
134433d6423SLionel Sambuc 	while (r == 1) {
135433d6423SLionel Sambuc 		slot_name = pci_slot_name(devind);
136433d6423SLionel Sambuc 		dev_name = pci_dev_name(vid, did);
137433d6423SLionel Sambuc 
138433d6423SLionel Sambuc 		bcr = pci_attr_r8(devind, PCI_BCR);
139433d6423SLionel Sambuc 		scr = pci_attr_r8(devind, PCI_SCR);
140433d6423SLionel Sambuc 		pifr = pci_attr_r8(devind, PCI_PIFR);
1419e77ef50SLionel Sambuc 		rev = pci_attr_r8(devind, PCI_REV);
1429e77ef50SLionel Sambuc 		subvid = pci_attr_r16(devind, PCI_SUBVID);
1439e77ef50SLionel Sambuc 		subdid = pci_attr_r16(devind, PCI_SUBDID);
144433d6423SLionel Sambuc 
1459e77ef50SLionel Sambuc 		buf_printf("%s %x/%x/%x/%x %04X:%04X:%04X:%04X %s\n",
1469e77ef50SLionel Sambuc 		    slot_name ? slot_name : "-1.-1.-1.-1",
1479e77ef50SLionel Sambuc 		    bcr, scr, pifr, rev,
1489e77ef50SLionel Sambuc 		    vid, did, subvid, subdid,
149433d6423SLionel Sambuc 		    dev_name ? dev_name : "");
150433d6423SLionel Sambuc 
151433d6423SLionel Sambuc 		r = pci_next_dev(&devind, &vid, &did);
152433d6423SLionel Sambuc 	}
153433d6423SLionel Sambuc }
154433d6423SLionel Sambuc #endif /* defined(__i386__) */
155433d6423SLionel Sambuc 
156f1abbce7SDavid van Moolenbroek /*
157f1abbce7SDavid van Moolenbroek  * Print a list of drivers that have been assigned major device numbers.
158f1abbce7SDavid van Moolenbroek  */
159f1abbce7SDavid van Moolenbroek static void
root_dmap(void)160f1abbce7SDavid van Moolenbroek root_dmap(void)
161433d6423SLionel Sambuc {
162433d6423SLionel Sambuc 	struct dmap dmap[NR_DEVICES];
163433d6423SLionel Sambuc 	int i;
164433d6423SLionel Sambuc 
165433d6423SLionel Sambuc 	if (getsysinfo(VFS_PROC_NR, SI_DMAP_TAB, dmap, sizeof(dmap)) != OK)
166433d6423SLionel Sambuc 		return;
167433d6423SLionel Sambuc 
168433d6423SLionel Sambuc 	for (i = 0; i < NR_DEVICES; i++) {
169433d6423SLionel Sambuc 		if (dmap[i].dmap_driver == NONE)
170433d6423SLionel Sambuc 			continue;
171433d6423SLionel Sambuc 
172433d6423SLionel Sambuc 		buf_printf("%u %s %u\n", i, dmap[i].dmap_label,
173433d6423SLionel Sambuc 		    dmap[i].dmap_driver);
174433d6423SLionel Sambuc 	}
175433d6423SLionel Sambuc }
176433d6423SLionel Sambuc 
177f1abbce7SDavid van Moolenbroek /*
178f1abbce7SDavid van Moolenbroek  * Print a list of IPC vectors with their addresses.
179f1abbce7SDavid van Moolenbroek  */
180f1abbce7SDavid van Moolenbroek static void
root_ipcvecs(void)181f1abbce7SDavid van Moolenbroek root_ipcvecs(void)
182433d6423SLionel Sambuc {
183433d6423SLionel Sambuc 	extern struct minix_ipcvecs _minix_ipcvecs;
184433d6423SLionel Sambuc 
185f1abbce7SDavid van Moolenbroek 	/*
186f1abbce7SDavid van Moolenbroek 	 * Only print this if the kernel provides the info; otherwise binaries
187f1abbce7SDavid van Moolenbroek 	 * will be using their own in-libc vectors that are normal symbols in
188f1abbce7SDavid van Moolenbroek 	 * the binary.
189433d6423SLionel Sambuc 	 */
190594df55eSDavid van Moolenbroek 	if (!(get_minix_kerninfo()->ki_flags & MINIX_KIF_IPCVECS))
191433d6423SLionel Sambuc 		return;
192433d6423SLionel Sambuc 
193f1abbce7SDavid van Moolenbroek 	/*
194f1abbce7SDavid van Moolenbroek 	 * Print the vectors with an descriptive name and the additional (k)
195433d6423SLionel Sambuc 	 * to distinguish them from regular symbols.
196433d6423SLionel Sambuc 	 */
197433d6423SLionel Sambuc #define PRINT_ENTRYPOINT(name) \
198f1abbce7SDavid van Moolenbroek 	buf_printf("%08lx T %s(k)\n", \
199f1abbce7SDavid van Moolenbroek 	    (unsigned long)_minix_ipcvecs.name, #name)
200433d6423SLionel Sambuc 
201433d6423SLionel Sambuc 	PRINT_ENTRYPOINT(sendrec);
202433d6423SLionel Sambuc 	PRINT_ENTRYPOINT(send);
203433d6423SLionel Sambuc 	PRINT_ENTRYPOINT(notify);
204433d6423SLionel Sambuc 	PRINT_ENTRYPOINT(senda);
205433d6423SLionel Sambuc 	PRINT_ENTRYPOINT(sendnb);
206433d6423SLionel Sambuc 	PRINT_ENTRYPOINT(receive);
207433d6423SLionel Sambuc 	PRINT_ENTRYPOINT(do_kernel_call);
208433d6423SLionel Sambuc }
209433d6423SLionel Sambuc 
210f1abbce7SDavid van Moolenbroek /*
211f1abbce7SDavid van Moolenbroek  * Print the list of mounted file systems.
212f1abbce7SDavid van Moolenbroek  */
213433d6423SLionel Sambuc static void
root_mounts(void)214433d6423SLionel Sambuc root_mounts(void)
215433d6423SLionel Sambuc {
216433d6423SLionel Sambuc 	struct statvfs buf[NR_MNTS];
217433d6423SLionel Sambuc 	int i, count;
218433d6423SLionel Sambuc 
219433d6423SLionel Sambuc 	if ((count = getvfsstat(buf, sizeof(buf), ST_NOWAIT)) < 0)
220433d6423SLionel Sambuc 		return;
221433d6423SLionel Sambuc 
222433d6423SLionel Sambuc 	for (i = 0; i < count; i++) {
223433d6423SLionel Sambuc 		buf_printf("%s on %s type %s (%s)\n", buf[i].f_mntfromname,
224433d6423SLionel Sambuc 		    buf[i].f_mntonname, buf[i].f_fstypename,
225433d6423SLionel Sambuc 		    (buf[i].f_flag & ST_RDONLY) ? "ro" : "rw");
226433d6423SLionel Sambuc 	}
227433d6423SLionel Sambuc }
228