libutil: add O_NOCTTY back to old pty open code
[minix.git] / servers / procfs / root.c
blobdfd5b20e9353f9de6242007bf96b1f11ea9218d7
1 /* ProcFS - root.c - by Alen Stojanov and David van Moolenbroek */
3 #include "inc.h"
4 #include <machine/pci.h>
5 #include <minix/dmap.h>
6 #include "cpuinfo.h"
7 #include "mounts.h"
9 static void root_hz(void);
10 static void root_uptime(void);
11 static void root_loadavg(void);
12 static void root_kinfo(void);
13 static void root_meminfo(void);
14 static void root_pci(void);
15 static void root_dmap(void);
16 static void root_ipcvecs(void);
18 struct file root_files[] = {
19 { "hz", REG_ALL_MODE, (data_t) root_hz },
20 { "uptime", REG_ALL_MODE, (data_t) root_uptime },
21 { "loadavg", REG_ALL_MODE, (data_t) root_loadavg },
22 { "kinfo", REG_ALL_MODE, (data_t) root_kinfo },
23 { "meminfo", REG_ALL_MODE, (data_t) root_meminfo },
24 { "pci", REG_ALL_MODE, (data_t) root_pci },
25 { "dmap", REG_ALL_MODE, (data_t) root_dmap },
26 { "cpuinfo", REG_ALL_MODE, (data_t) root_cpuinfo },
27 { "ipcvecs", REG_ALL_MODE, (data_t) root_ipcvecs },
28 { "mounts", REG_ALL_MODE, (data_t) root_mounts },
29 { NULL, 0, NULL }
32 /*===========================================================================*
33 * root_hz *
34 *===========================================================================*/
35 static void root_hz(void)
37 /* Print the system clock frequency.
40 buf_printf("%lu\n", (long) sys_hz());
43 /*===========================================================================*
44 * root_loadavg *
45 *===========================================================================*/
46 static void root_loadavg(void)
48 /* Print load averages.
50 struct load loads[3];
51 ldiv_t avg[3];
53 if (procfs_getloadavg(loads, 3) != 3)
54 return;
56 avg[0] = ldiv(100L * loads[0].proc_load / loads[0].ticks, 100);
57 avg[1] = ldiv(100L * loads[1].proc_load / loads[1].ticks, 100);
58 avg[2] = ldiv(100L * loads[2].proc_load / loads[2].ticks, 100);
60 buf_printf("%ld.%0.2ld %ld.%02ld %ld.%02ld\n",
61 avg[0].quot, avg[0].rem, avg[1].quot, avg[1].rem,
62 avg[2].quot, avg[2].rem);
65 /*===========================================================================*
66 * root_uptime *
67 *===========================================================================*/
68 static void root_uptime(void)
70 /* Print the current uptime.
72 clock_t ticks;
73 ldiv_t division;
75 if (getuptime(&ticks) != OK)
76 return;
77 division = ldiv(100L * ticks / sys_hz(), 100L);
79 buf_printf("%ld.%0.2ld\n", division.quot, division.rem);
82 /*===========================================================================*
83 * root_kinfo *
84 *===========================================================================*/
85 static void root_kinfo(void)
87 /* Print general kernel information.
89 struct kinfo kinfo;
91 if (sys_getkinfo(&kinfo) != OK)
92 return;
94 buf_printf("%u %u\n", kinfo.nr_procs, kinfo.nr_tasks);
97 /*===========================================================================*
98 * root_meminfo *
99 *===========================================================================*/
100 static void root_meminfo(void)
102 /* Print general memory information.
104 struct vm_stats_info vsi;
106 if (vm_info_stats(&vsi) != OK)
107 return;
109 buf_printf("%u %lu %lu %lu %lu\n", vsi.vsi_pagesize,
110 vsi.vsi_total, vsi.vsi_free, vsi.vsi_largest, vsi.vsi_cached);
113 /*===========================================================================*
114 * root_pci *
115 *===========================================================================*/
116 static void root_pci(void)
118 /* Print information about PCI devices present in the system.
120 u16_t vid, did;
121 u8_t bcr, scr, pifr;
122 char *slot_name, *dev_name;
123 int r, devind;
124 static int first = TRUE;
126 /* This should be taken care of behind the scenes by the PCI lib. */
127 if (first) {
128 pci_init();
129 first = FALSE;
132 /* Iterate over all devices, printing info for each of them. */
133 r = pci_first_dev(&devind, &vid, &did);
134 while (r == 1) {
135 slot_name = pci_slot_name(devind);
136 dev_name = pci_dev_name(vid, did);
138 bcr = pci_attr_r8(devind, PCI_BCR);
139 scr = pci_attr_r8(devind, PCI_SCR);
140 pifr = pci_attr_r8(devind, PCI_PIFR);
142 buf_printf("%s %x/%x/%x %04X:%04X %s\n",
143 slot_name ? slot_name : "-",
144 bcr, scr, pifr, vid, did,
145 dev_name ? dev_name : "");
147 r = pci_next_dev(&devind, &vid, &did);
151 /*===========================================================================*
152 * root_dmap *
153 *===========================================================================*/
154 static void root_dmap(void)
156 struct dmap dmap[NR_DEVICES];
157 int i;
159 if (getsysinfo(VFS_PROC_NR, SI_DMAP_TAB, dmap, sizeof(dmap)) != OK)
160 return;
162 for (i = 0; i < NR_DEVICES; i++) {
163 if (dmap[i].dmap_driver == NONE)
164 continue;
166 buf_printf("%u %s %u\n", i, dmap[i].dmap_label,
167 dmap[i].dmap_driver);
171 /*===========================================================================*
172 * root_ipcvecs *
173 *===========================================================================*/
174 static void root_ipcvecs(void)
176 extern struct minix_kerninfo *_minix_kerninfo;
177 extern struct minix_ipcvecs _minix_ipcvecs;
179 /* only print this if the kernel provides the info; otherwise binaries
180 * will be using their own in-libc vectors that are normal symbols in the
181 * binary.
183 if(!_minix_kerninfo || !(_minix_kerninfo->ki_flags & MINIX_KIF_IPCVECS))
184 return;
186 /* print the vectors with an descriptive name and the additional (k)
187 * to distinguish them from regular symbols.
189 #define PRINT_ENTRYPOINT(name) \
190 buf_printf("%08lx T %s(k)\n", _minix_ipcvecs.name, #name)
192 PRINT_ENTRYPOINT(sendrec);
193 PRINT_ENTRYPOINT(send);
194 PRINT_ENTRYPOINT(notify);
195 PRINT_ENTRYPOINT(senda);
196 PRINT_ENTRYPOINT(sendnb);
197 PRINT_ENTRYPOINT(receive);
198 PRINT_ENTRYPOINT(do_kernel_call);