2 * SPDX-License-Identifier: BSD-4-Clause
4 * Copyright (c) 2000 Dag-Erling Coïdan Smørgrav
5 * Copyright (c) 1999 Pierre Beyssac
6 * Copyright (c) 1993 Jan-Simon Pendry
8 * The Regents of the University of California. All rights reserved.
10 * This code is derived from software contributed to Berkeley by
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 * @(#)procfs_status.c 8.4 (Berkeley) 6/15/94
44 #include <sys/cdefs.h>
45 __FBSDID("$FreeBSD$");
47 #include <sys/param.h>
48 #include <sys/queue.h>
49 #include <sys/blist.h>
52 #include <sys/fcntl.h>
53 #include <sys/filedesc.h>
55 #include <sys/kernel.h>
56 #include <sys/limits.h>
57 #include <sys/linker.h>
59 #include <sys/malloc.h>
61 #include <sys/mutex.h>
62 #include <sys/namei.h>
64 #include <sys/ptrace.h>
65 #include <sys/resourcevar.h>
66 #include <sys/resource.h>
70 #include <sys/socket.h>
71 #include <sys/syscallsubr.h>
72 #include <sys/sysctl.h>
73 #include <sys/sysent.h>
74 #include <sys/systm.h>
79 #include <sys/vmmeter.h>
80 #include <sys/vnode.h>
84 #include <net/if_var.h>
85 #include <net/if_types.h>
88 #include <vm/vm_extern.h>
90 #include <vm/vm_map.h>
91 #include <vm/vm_param.h>
92 #include <vm/vm_object.h>
93 #include <vm/swap_pager.h>
95 #include <machine/clock.h>
97 #include <geom/geom.h>
98 #include <geom/geom_int.h>
100 #if defined(__i386__) || defined(__amd64__)
101 #include <machine/cputypes.h>
102 #include <machine/md_var.h>
103 #endif /* __i386__ || __amd64__ */
105 #include <compat/linux/linux.h>
106 #include <compat/linux/linux_mib.h>
107 #include <compat/linux/linux_misc.h>
108 #include <compat/linux/linux_util.h>
109 #include <fs/pseudofs/pseudofs.h>
110 #include <fs/procfs/procfs.h>
113 * Various conversion macros
115 #define T2J(x) ((long)(((x) * 100ULL) / (stathz ? stathz : hz))) /* ticks to jiffies */
116 #define T2CS(x) ((unsigned long)(((x) * 100ULL) / (stathz ? stathz : hz))) /* ticks to centiseconds */
117 #define T2S(x) ((x) / (stathz ? stathz : hz)) /* ticks to seconds */
118 #define B2K(x) ((x) >> 10) /* bytes to kbytes */
119 #define B2P(x) ((x) >> PAGE_SHIFT) /* bytes to pages */
120 #define P2B(x) ((x) << PAGE_SHIFT) /* pages to bytes */
121 #define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* pages to kbytes */
122 #define TV2J(x) ((x)->tv_sec * 100UL + (x)->tv_usec / 10000)
125 * @brief Mapping of ki_stat in struct kinfo_proc to the linux state
127 * The linux procfs state field displays one of the characters RSDZTW to
128 * denote running, sleeping in an interruptible wait, waiting in an
129 * uninterruptible disk sleep, a zombie process, process is being traced
130 * or stopped, or process is paging respectively.
132 * Our struct kinfo_proc contains the variable ki_stat which contains a
133 * value out of SIDL, SRUN, SSLEEP, SSTOP, SZOMB, SWAIT and SLOCK.
135 * This character array is used with ki_stati-1 as an index and tries to
136 * map our states to suitable linux states.
138 static char linux_state[] = "RRSTZDD";
141 * Filler function for proc/meminfo
144 linprocfs_domeminfo(PFS_FILL_ARGS)
146 unsigned long memtotal; /* total memory in bytes */
147 unsigned long memused; /* used memory in bytes */
148 unsigned long memfree; /* free memory in bytes */
149 unsigned long buffers, cached; /* buffer / cache memory ??? */
150 unsigned long long swaptotal; /* total swap space in bytes */
151 unsigned long long swapused; /* used swap space in bytes */
152 unsigned long long swapfree; /* free swap space in bytes */
155 memtotal = physmem * PAGE_SIZE;
157 * The correct thing here would be:
159 memfree = vm_free_count() * PAGE_SIZE;
160 memused = memtotal - memfree;
162 * but it might mislead linux binaries into thinking there
163 * is very little memory left, so we cheat and tell them that
164 * all memory that isn't wired down is free.
166 memused = vm_wire_count() * PAGE_SIZE;
167 memfree = memtotal - memused;
168 swap_pager_status(&i, &j);
169 swaptotal = (unsigned long long)i * PAGE_SIZE;
170 swapused = (unsigned long long)j * PAGE_SIZE;
171 swapfree = swaptotal - swapused;
173 * We'd love to be able to write:
177 * but bufspace is internal to vfs_bio.c and we don't feel
178 * like unstaticizing it just for linprocfs's sake.
181 cached = vm_inactive_count() * PAGE_SIZE;
184 "MemTotal: %9lu kB\n"
188 "SwapTotal:%9llu kB\n"
189 "SwapFree: %9llu kB\n",
190 B2K(memtotal), B2K(memfree), B2K(buffers),
191 B2K(cached), B2K(swaptotal), B2K(swapfree));
196 #if defined(__i386__) || defined(__amd64__)
198 * Filler function for proc/cpuinfo (i386 & amd64 version)
201 linprocfs_docpuinfo(PFS_FILL_ARGS)
212 * We default the flags to include all non-conflicting flags,
213 * and the Intel versions of conflicting flags.
215 static char *flags[] = {
216 "fpu", "vme", "de", "pse", "tsc",
217 "msr", "pae", "mce", "cx8", "apic",
218 "sep", "sep", "mtrr", "pge", "mca",
219 "cmov", "pat", "pse36", "pn", "b19",
220 "b20", "b21", "mmxext", "mmx", "fxsr",
221 "xmm", "sse2", "b27", "b28", "b29",
225 static char *power_flags[] = {
228 "100mhzsteps", "hwpstate", "",
229 "cpb", "eff_freq_ro", "proc_feedback",
233 hw_model[0] = CTL_HW;
234 hw_model[1] = HW_MODEL;
236 size = sizeof(model);
237 if (kernel_sysctl(td, hw_model, 2, &model, &size, 0, 0, 0, 0) != 0)
238 strcpy(model, "unknown");
240 switch (cpu_vendor_id) {
242 if (cpu_class < CPUCLASS_686)
245 case CPU_VENDOR_CYRIX:
250 if (cpu_exthigh >= 0x80000006)
251 do_cpuid(0x80000006, cache_size);
253 memset(cache_size, 0, sizeof(cache_size));
254 for (i = 0; i < mp_ncpus; ++i) {
257 freq = atomic_load_acq_64(&tsc_freq);
259 fqmhz = (freq + 4999) / 1000000;
260 fqkhz = ((freq + 4999) / 10000) % 100;
264 "vendor_id\t: %.20s\n"
269 "cpu MHz\t\t: %d.%02d\n"
270 "cache size\t: %d KB\n"
271 "physical id\t: %d\n"
276 "initial apicid\t: %d\n"
278 "fpu_exception\t: %s\n"
279 "cpuid level\t: %d\n"
281 i, cpu_vendor, CPUID_TO_FAMILY(cpu_id),
282 CPUID_TO_MODEL(cpu_id), model, cpu_id & CPUID_STEPPING,
284 (cache_size[2] >> 16), 0, mp_ncpus, i, mp_ncpus,
285 i, i, /*cpu_id & CPUID_LOCAL_APIC_ID ??*/
286 (cpu_feature & CPUID_FPU) ? "yes" : "no", "yes",
287 CPUID_TO_FAMILY(cpu_id), "yes");
288 sbuf_cat(sb, "flags\t\t:");
289 for (j = 0; j < nitems(flags); j++)
290 if (cpu_feature & (1 << j))
291 sbuf_printf(sb, " %s", flags[j]);
295 "bogomips\t: %d.%02d\n"
296 "clflush size\t: %d\n"
297 "cache_alignment\t: %d\n"
298 "address sizes\t: %d bits physical, %d bits virtual\n",
299 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
300 (has_f00f_bug) ? "Intel F00F" : "",
305 cpu_clflush_line_size, cpu_clflush_line_size,
307 (cpu_maxphyaddr > 32) ? 48 : 0);
308 sbuf_cat(sb, "power management: ");
309 for (j = 0; j < nitems(power_flags); j++)
310 if (amd_pminfo & (1 << j))
311 sbuf_printf(sb, " %s", power_flags[j]);
312 sbuf_cat(sb, "\n\n");
314 /* XXX per-cpu vendor / class / model / id? */
321 /* ARM64TODO: implement non-stubbed linprocfs_docpuinfo */
323 linprocfs_docpuinfo(PFS_FILL_ARGS)
327 for (i = 0; i < mp_ncpus; ++i) {
330 "BogoMIPS\t: %d.%02d\n",
332 sbuf_cat(sb, "Features\t: ");
335 "CPU implementer\t: \n"
336 "CPU architecture: \n"
337 "CPU variant\t: 0x%x\n"
339 "CPU revision\t: %d\n",
346 #endif /* __i386__ || __amd64__ */
349 * Filler function for proc/mtab
351 * This file doesn't exist in Linux' procfs, but is included here so
352 * users can symlink /compat/linux/etc/mtab to /proc/mtab
355 linprocfs_domtab(PFS_FILL_ARGS)
359 char *dlep, *flep, *mntto, *mntfrom, *fstype;
362 struct statfs *buf, *sp;
365 /* resolve symlinks etc. in the emulation tree prefix */
366 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, linux_emul_path, td);
369 lep = linux_emul_path;
371 if (vn_fullpath(td, nd.ni_vp, &dlep, &flep) == 0)
375 lep_len = strlen(lep);
378 error = kern_getfsstat(td, &buf, SIZE_T_MAX, &count,
379 UIO_SYSSPACE, MNT_WAIT);
386 for (sp = buf; count > 0; sp++, count--) {
387 /* determine device name */
388 mntfrom = sp->f_mntfromname;
390 /* determine mount point */
391 mntto = sp->f_mntonname;
392 if (strncmp(mntto, lep, lep_len) == 0 && mntto[lep_len] == '/')
395 /* determine fs type */
396 fstype = sp->f_fstypename;
397 if (strcmp(fstype, pn->pn_info->pi_name) == 0)
398 mntfrom = fstype = "proc";
399 else if (strcmp(fstype, "procfs") == 0)
402 if (strcmp(fstype, "linsysfs") == 0) {
403 sbuf_printf(sb, "/sys %s sysfs %s", mntto,
404 sp->f_flags & MNT_RDONLY ? "ro" : "rw");
406 /* For Linux msdosfs is called vfat */
407 if (strcmp(fstype, "msdosfs") == 0)
409 sbuf_printf(sb, "%s %s %s %s", mntfrom, mntto, fstype,
410 sp->f_flags & MNT_RDONLY ? "ro" : "rw");
412 #define ADD_OPTION(opt, name) \
413 if (sp->f_flags & (opt)) sbuf_printf(sb, "," name);
414 ADD_OPTION(MNT_SYNCHRONOUS, "sync");
415 ADD_OPTION(MNT_NOEXEC, "noexec");
416 ADD_OPTION(MNT_NOSUID, "nosuid");
417 ADD_OPTION(MNT_UNION, "union");
418 ADD_OPTION(MNT_ASYNC, "async");
419 ADD_OPTION(MNT_SUIDDIR, "suiddir");
420 ADD_OPTION(MNT_NOSYMFOLLOW, "nosymfollow");
421 ADD_OPTION(MNT_NOATIME, "noatime");
423 /* a real Linux mtab will also show NFS options */
424 sbuf_printf(sb, " 0 0\n");
433 * Filler function for proc/partitions
436 linprocfs_dopartitions(PFS_FILL_ARGS)
440 struct g_provider *pp;
444 sbuf_printf(sb, "major minor #blocks name rio rmerge rsect "
445 "ruse wio wmerge wsect wuse running use aveq\n");
447 LIST_FOREACH(cp, &g_classes, class) {
448 if (strcmp(cp->name, "DISK") == 0 ||
449 strcmp(cp->name, "PART") == 0)
450 LIST_FOREACH(gp, &cp->geom, geom) {
451 LIST_FOREACH(pp, &gp->provider, provider) {
452 if (linux_driver_get_major_minor(
453 pp->name, &major, &minor) != 0) {
457 sbuf_printf(sb, "%d %d %lld %s "
459 "%d %d %d %d %d %d\n",
461 (long long)pp->mediasize, pp->name,
473 * Filler function for proc/stat
475 * Output depends on kernel version:
478 * user nice system idle
480 * user nice system idle iowait
482 * user nice system idle iowait irq softirq steal
484 * user nice system idle iowait irq softirq steal guest
486 * user nice system idle iowait irq softirq steal guest guest_nice
489 linprocfs_dostat(PFS_FILL_ARGS)
492 long cp_time[CPUSTATES];
494 struct timeval boottime;
497 bool has_intr = true;
499 if (linux_kernver(td) >= LINUX_KERNVER(2,6,33)) {
500 zero_pad = " 0 0 0 0\n";
501 } else if (linux_kernver(td) >= LINUX_KERNVER(2,6,24)) {
502 zero_pad = " 0 0 0\n";
503 } else if (linux_kernver(td) >= LINUX_KERNVER(2,6,11)) {
505 } else if (linux_kernver(td) >= LINUX_KERNVER(2,5,41)) {
513 read_cpu_time(cp_time);
514 getboottime(&boottime);
515 /* Parameters common to all versions */
516 sbuf_printf(sb, "cpu %lu %lu %lu %lu",
517 T2J(cp_time[CP_USER]),
518 T2J(cp_time[CP_NICE]),
519 T2J(cp_time[CP_SYS]),
520 T2J(cp_time[CP_IDLE]));
522 /* Print interrupt stats if available */
524 sbuf_printf(sb, " 0 %lu", T2J(cp_time[CP_INTR]));
527 /* Pad out remaining fields depending on version */
528 sbuf_printf(sb, "%s", zero_pad);
532 cp = pcpu->pc_cp_time;
533 sbuf_printf(sb, "cpu%d %lu %lu %lu %lu", i,
540 sbuf_printf(sb, " 0 %lu", T2J(cp[CP_INTR]));
543 sbuf_printf(sb, "%s", zero_pad);
552 (uintmax_t)VM_CNT_FETCH(v_vnodepgsin),
553 (uintmax_t)VM_CNT_FETCH(v_vnodepgsout),
554 (uintmax_t)VM_CNT_FETCH(v_swappgsin),
555 (uintmax_t)VM_CNT_FETCH(v_swappgsout),
556 (uintmax_t)VM_CNT_FETCH(v_intr),
557 (uintmax_t)VM_CNT_FETCH(v_swtch),
558 (long long)boottime.tv_sec);
563 linprocfs_doswaps(PFS_FILL_ARGS)
566 uintmax_t total, used;
568 char devname[SPECNAMELEN + 1];
570 sbuf_printf(sb, "Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
572 if (swap_dev_info(n, &xsw, devname, sizeof(devname)) != 0)
574 total = (uintmax_t)xsw.xsw_nblks * PAGE_SIZE / 1024;
575 used = (uintmax_t)xsw.xsw_used * PAGE_SIZE / 1024;
578 * The space and not tab after the device name is on
579 * purpose. Linux does so.
581 sbuf_printf(sb, "/dev/%-34s unknown\t\t%jd\t%jd\t-1\n",
582 devname, total, used);
588 * Filler function for proc/uptime
591 linprocfs_douptime(PFS_FILL_ARGS)
593 long cp_time[CPUSTATES];
597 read_cpu_time(cp_time);
598 sbuf_printf(sb, "%lld.%02ld %ld.%02lu\n",
599 (long long)tv.tv_sec, tv.tv_usec / 10000,
600 T2S(cp_time[CP_IDLE] / mp_ncpus),
601 T2CS(cp_time[CP_IDLE] / mp_ncpus) % 100);
609 linprocfs_osbuild(struct thread *td, struct sbuf *sb)
615 strncpy(osbuild, version, 256);
617 cp1 = strstr(osbuild, "\n");
618 cp2 = strstr(osbuild, ":");
621 cp1 = strstr(osbuild, "#");
625 sbuf_printf(sb, "%s%s", cp1, cp2 + 1);
628 sbuf_cat(sb, "#4 Sun Dec 18 04:30:00 CET 1977");
635 linprocfs_osbuilder(struct thread *td, struct sbuf *sb)
641 cp = strstr(version, "\n ");
643 strncpy(builder, cp + 5, 256);
645 cp = strstr(builder, ":");
650 sbuf_cat(sb, builder);
653 sbuf_cat(sb, "des@freebsd.org");
657 * Filler function for proc/version
660 linprocfs_doversion(PFS_FILL_ARGS)
662 char osname[LINUX_MAX_UTSNAME];
663 char osrelease[LINUX_MAX_UTSNAME];
665 linux_get_osname(td, osname);
666 linux_get_osrelease(td, osrelease);
667 sbuf_printf(sb, "%s version %s (", osname, osrelease);
668 linprocfs_osbuilder(td, sb);
669 sbuf_cat(sb, ") (gcc version " __VERSION__ ") ");
670 linprocfs_osbuild(td, sb);
677 * Filler function for proc/loadavg
680 linprocfs_doloadavg(PFS_FILL_ARGS)
684 "%d.%02d %d.%02d %d.%02d %d/%d %d\n",
685 (int)(averunnable.ldavg[0] / averunnable.fscale),
686 (int)(averunnable.ldavg[0] * 100 / averunnable.fscale % 100),
687 (int)(averunnable.ldavg[1] / averunnable.fscale),
688 (int)(averunnable.ldavg[1] * 100 / averunnable.fscale % 100),
689 (int)(averunnable.ldavg[2] / averunnable.fscale),
690 (int)(averunnable.ldavg[2] * 100 / averunnable.fscale % 100),
691 1, /* number of running tasks */
692 nprocs, /* number of tasks */
693 lastpid /* the last pid */
699 * Filler function for proc/pid/stat
702 linprocfs_doprocstat(PFS_FILL_ARGS)
704 struct kinfo_proc kp;
705 struct timeval boottime;
707 static int ratelimit = 0;
708 vm_offset_t startcode, startdata;
710 getboottime(&boottime);
711 sx_slock(&proctree_lock);
713 fill_kinfo_proc(p, &kp);
714 sx_sunlock(&proctree_lock);
716 startcode = (vm_offset_t)p->p_vmspace->vm_taddr;
717 startdata = (vm_offset_t)p->p_vmspace->vm_daddr;
722 sbuf_printf(sb, "%d", p->p_pid);
723 #define PS_ADD(name, fmt, arg) sbuf_printf(sb, " " fmt, arg)
724 PS_ADD("comm", "(%s)", p->p_comm);
725 if (kp.ki_stat > sizeof(linux_state)) {
728 if (ratelimit == 0) {
729 printf("linprocfs: don't know how to handle unknown FreeBSD state %d/%zd, mapping to R\n",
730 kp.ki_stat, sizeof(linux_state));
734 state = linux_state[kp.ki_stat - 1];
735 PS_ADD("state", "%c", state);
736 PS_ADD("ppid", "%d", p->p_pptr ? p->p_pptr->p_pid : 0);
737 PS_ADD("pgrp", "%d", p->p_pgid);
738 PS_ADD("session", "%d", p->p_session->s_sid);
740 PS_ADD("tty", "%ju", (uintmax_t)kp.ki_tdev);
741 PS_ADD("tpgid", "%d", kp.ki_tpgid);
742 PS_ADD("flags", "%u", 0); /* XXX */
743 PS_ADD("minflt", "%lu", kp.ki_rusage.ru_minflt);
744 PS_ADD("cminflt", "%lu", kp.ki_rusage_ch.ru_minflt);
745 PS_ADD("majflt", "%lu", kp.ki_rusage.ru_majflt);
746 PS_ADD("cmajflt", "%lu", kp.ki_rusage_ch.ru_majflt);
747 PS_ADD("utime", "%ld", TV2J(&kp.ki_rusage.ru_utime));
748 PS_ADD("stime", "%ld", TV2J(&kp.ki_rusage.ru_stime));
749 PS_ADD("cutime", "%ld", TV2J(&kp.ki_rusage_ch.ru_utime));
750 PS_ADD("cstime", "%ld", TV2J(&kp.ki_rusage_ch.ru_stime));
751 PS_ADD("priority", "%d", kp.ki_pri.pri_user);
752 PS_ADD("nice", "%d", kp.ki_nice); /* 19 (nicest) to -19 */
753 PS_ADD("0", "%d", 0); /* removed field */
754 PS_ADD("itrealvalue", "%d", 0); /* XXX */
755 PS_ADD("starttime", "%lu", TV2J(&kp.ki_start) - TV2J(&boottime));
756 PS_ADD("vsize", "%ju", P2K((uintmax_t)kp.ki_size));
757 PS_ADD("rss", "%ju", (uintmax_t)kp.ki_rssize);
758 PS_ADD("rlim", "%lu", kp.ki_rusage.ru_maxrss);
759 PS_ADD("startcode", "%ju", (uintmax_t)startcode);
760 PS_ADD("endcode", "%ju", (uintmax_t)startdata);
761 PS_ADD("startstack", "%u", 0); /* XXX */
762 PS_ADD("kstkesp", "%u", 0); /* XXX */
763 PS_ADD("kstkeip", "%u", 0); /* XXX */
764 PS_ADD("signal", "%u", 0); /* XXX */
765 PS_ADD("blocked", "%u", 0); /* XXX */
766 PS_ADD("sigignore", "%u", 0); /* XXX */
767 PS_ADD("sigcatch", "%u", 0); /* XXX */
768 PS_ADD("wchan", "%u", 0); /* XXX */
769 PS_ADD("nswap", "%lu", kp.ki_rusage.ru_nswap);
770 PS_ADD("cnswap", "%lu", kp.ki_rusage_ch.ru_nswap);
771 PS_ADD("exitsignal", "%d", 0); /* XXX */
772 PS_ADD("processor", "%u", kp.ki_lastcpu);
773 PS_ADD("rt_priority", "%u", 0); /* XXX */ /* >= 2.5.19 */
774 PS_ADD("policy", "%u", kp.ki_pri.pri_class); /* >= 2.5.19 */
782 * Filler function for proc/pid/statm
785 linprocfs_doprocstatm(PFS_FILL_ARGS)
787 struct kinfo_proc kp;
790 sx_slock(&proctree_lock);
792 fill_kinfo_proc(p, &kp);
794 sx_sunlock(&proctree_lock);
797 * See comments in linprocfs_doprocstatus() regarding the
798 * computation of lsize.
800 /* size resident share trs drs lrs dt */
801 sbuf_printf(sb, "%ju ", B2P((uintmax_t)kp.ki_size));
802 sbuf_printf(sb, "%ju ", (uintmax_t)kp.ki_rssize);
803 sbuf_printf(sb, "%ju ", (uintmax_t)0); /* XXX */
804 sbuf_printf(sb, "%ju ", (uintmax_t)kp.ki_tsize);
805 sbuf_printf(sb, "%ju ", (uintmax_t)(kp.ki_dsize + kp.ki_ssize));
806 lsize = B2P(kp.ki_size) - kp.ki_dsize -
807 kp.ki_ssize - kp.ki_tsize - 1;
808 sbuf_printf(sb, "%ju ", (uintmax_t)lsize);
809 sbuf_printf(sb, "%ju\n", (uintmax_t)0); /* XXX */
815 * Filler function for proc/pid/status
818 linprocfs_doprocstatus(PFS_FILL_ARGS)
820 struct kinfo_proc kp;
825 l_sigset_t siglist, sigignore, sigcatch;
828 sx_slock(&proctree_lock);
830 td2 = FIRST_THREAD_IN_PROC(p); /* XXXKSE pretend only one thread */
832 if (P_SHOULDSTOP(p)) {
833 state = "T (stopped)";
840 if (p->p_flag & P_WEXIT) {
841 state = "X (exiting)";
844 switch(td2->td_state) {
846 state = "S (sleeping)";
850 state = "R (running)";
853 state = "? (unknown)";
858 state = "Z (zombie)";
861 state = "? (unknown)";
866 fill_kinfo_proc(p, &kp);
867 sx_sunlock(&proctree_lock);
869 sbuf_printf(sb, "Name:\t%s\n", p->p_comm); /* XXX escape */
870 sbuf_printf(sb, "State:\t%s\n", state);
875 sbuf_printf(sb, "Pid:\t%d\n", p->p_pid);
876 sbuf_printf(sb, "PPid:\t%d\n", kp.ki_ppid );
877 sbuf_printf(sb, "TracerPid:\t%d\n", kp.ki_tracer );
878 sbuf_printf(sb, "Uid:\t%d %d %d %d\n", p->p_ucred->cr_ruid,
880 p->p_ucred->cr_svuid,
881 /* FreeBSD doesn't have fsuid */
883 sbuf_printf(sb, "Gid:\t%d %d %d %d\n", p->p_ucred->cr_rgid,
885 p->p_ucred->cr_svgid,
886 /* FreeBSD doesn't have fsgid */
888 sbuf_cat(sb, "Groups:\t");
889 for (i = 0; i < p->p_ucred->cr_ngroups; i++)
890 sbuf_printf(sb, "%d ", p->p_ucred->cr_groups[i]);
897 * While our approximation of VmLib may not be accurate (I
898 * don't know of a simple way to verify it, and I'm not sure
899 * it has much meaning anyway), I believe it's good enough.
901 * The same code that could (I think) accurately compute VmLib
902 * could also compute VmLck, but I don't really care enough to
903 * implement it. Submissions are welcome.
905 sbuf_printf(sb, "VmSize:\t%8ju kB\n", B2K((uintmax_t)kp.ki_size));
906 sbuf_printf(sb, "VmLck:\t%8u kB\n", P2K(0)); /* XXX */
907 sbuf_printf(sb, "VmRSS:\t%8ju kB\n", P2K((uintmax_t)kp.ki_rssize));
908 sbuf_printf(sb, "VmData:\t%8ju kB\n", P2K((uintmax_t)kp.ki_dsize));
909 sbuf_printf(sb, "VmStk:\t%8ju kB\n", P2K((uintmax_t)kp.ki_ssize));
910 sbuf_printf(sb, "VmExe:\t%8ju kB\n", P2K((uintmax_t)kp.ki_tsize));
911 lsize = B2P(kp.ki_size) - kp.ki_dsize -
912 kp.ki_ssize - kp.ki_tsize - 1;
913 sbuf_printf(sb, "VmLib:\t%8ju kB\n", P2K((uintmax_t)lsize));
919 bsd_to_linux_sigset(&p->p_siglist, &siglist);
921 mtx_lock(&ps->ps_mtx);
922 bsd_to_linux_sigset(&ps->ps_sigignore, &sigignore);
923 bsd_to_linux_sigset(&ps->ps_sigcatch, &sigcatch);
924 mtx_unlock(&ps->ps_mtx);
927 sbuf_printf(sb, "SigPnd:\t%016jx\n", siglist.__mask);
929 * XXX. SigBlk - target thread's signal mask, td_sigmask.
930 * To implement SigBlk pseudofs should support proc/tid dir entries.
932 sbuf_printf(sb, "SigBlk:\t%016x\n", 0);
933 sbuf_printf(sb, "SigIgn:\t%016jx\n", sigignore.__mask);
934 sbuf_printf(sb, "SigCgt:\t%016jx\n", sigcatch.__mask);
937 * Linux also prints the capability masks, but we don't have
938 * capabilities yet, and when we do get them they're likely to
939 * be meaningless to Linux programs, so we lie. XXX
941 sbuf_printf(sb, "CapInh:\t%016x\n", 0);
942 sbuf_printf(sb, "CapPrm:\t%016x\n", 0);
943 sbuf_printf(sb, "CapEff:\t%016x\n", 0);
950 * Filler function for proc/pid/cwd
953 linprocfs_doproccwd(PFS_FILL_ARGS)
955 struct filedesc *fdp;
957 char *fullpath = "unknown";
958 char *freepath = NULL;
965 FILEDESC_SUNLOCK(fdp);
966 vn_fullpath(td, vp, &fullpath, &freepath);
969 sbuf_printf(sb, "%s", fullpath);
971 free(freepath, M_TEMP);
976 * Filler function for proc/pid/root
979 linprocfs_doprocroot(PFS_FILL_ARGS)
981 struct filedesc *fdp;
983 char *fullpath = "unknown";
984 char *freepath = NULL;
988 vp = jailed(p->p_ucred) ? fdp->fd_jdir : fdp->fd_rdir;
991 FILEDESC_SUNLOCK(fdp);
992 vn_fullpath(td, vp, &fullpath, &freepath);
995 sbuf_printf(sb, "%s", fullpath);
997 free(freepath, M_TEMP);
1002 * Filler function for proc/pid/cmdline
1005 linprocfs_doproccmdline(PFS_FILL_ARGS)
1010 if ((ret = p_cansee(td, p)) != 0) {
1016 * Mimic linux behavior and pass only processes with usermode
1017 * address space as valid. Return zero silently otherwize.
1019 if (p->p_vmspace == &vmspace0) {
1023 if (p->p_args != NULL) {
1024 sbuf_bcpy(sb, p->p_args->ar_args, p->p_args->ar_length);
1029 if ((p->p_flag & P_SYSTEM) != 0) {
1036 ret = proc_getargv(td, p, sb);
1041 * Filler function for proc/pid/environ
1044 linprocfs_doprocenviron(PFS_FILL_ARGS)
1048 * Mimic linux behavior and pass only processes with usermode
1049 * address space as valid. Return zero silently otherwize.
1051 if (p->p_vmspace == &vmspace0)
1054 return (proc_getenvv(td, p, sb));
1057 static char l32_map_str[] = "%08lx-%08lx %s%s%s%s %08lx %02x:%02x %lu%s%s\n";
1058 static char l64_map_str[] = "%016lx-%016lx %s%s%s%s %08lx %02x:%02x %lu%s%s\n";
1059 static char vdso_str[] = " [vdso]";
1060 static char stack_str[] = " [stack]";
1063 * Filler function for proc/pid/maps
1066 linprocfs_doprocmaps(PFS_FILL_ARGS)
1070 vm_map_entry_t entry, tmp_entry;
1071 vm_object_t obj, tobj, lobj;
1072 vm_offset_t e_start, e_end;
1073 vm_ooffset_t off = 0;
1075 unsigned int last_timestamp;
1076 char *name = "", *freename = NULL;
1077 const char *l_map_str;
1079 int ref_count, shadow_count, flags;
1085 error = p_candebug(td, p);
1090 if (uio->uio_rw != UIO_READ)
1091 return (EOPNOTSUPP);
1094 vm = vmspace_acquire_ref(p);
1098 if (SV_CURPROC_FLAG(SV_LP64))
1099 l_map_str = l64_map_str;
1101 l_map_str = l32_map_str;
1103 vm_map_lock_read(map);
1104 for (entry = map->header.next; entry != &map->header;
1105 entry = entry->next) {
1108 if (entry->eflags & MAP_ENTRY_IS_SUB_MAP)
1110 e_prot = entry->protection;
1111 e_start = entry->start;
1113 obj = entry->object.vm_object;
1114 for (lobj = tobj = obj; tobj; tobj = tobj->backing_object) {
1115 VM_OBJECT_RLOCK(tobj);
1117 VM_OBJECT_RUNLOCK(lobj);
1120 last_timestamp = map->timestamp;
1121 vm_map_unlock_read(map);
1124 off = IDX_TO_OFF(lobj->size);
1125 vp = vm_object_vnode(lobj);
1129 VM_OBJECT_RUNLOCK(lobj);
1131 ref_count = obj->ref_count;
1132 shadow_count = obj->shadow_count;
1133 VM_OBJECT_RUNLOCK(obj);
1135 vn_fullpath(td, vp, &name, &freename);
1136 vn_lock(vp, LK_SHARED | LK_RETRY);
1137 VOP_GETATTR(vp, &vat, td->td_ucred);
1138 ino = vat.va_fileid;
1140 } else if (SV_PROC_ABI(p) == SV_ABI_LINUX) {
1141 if (e_start == p->p_sysent->sv_shared_page_base)
1143 if (e_end == p->p_sysent->sv_usrstack)
1154 * start, end, access, offset, major, minor, inode, name.
1156 error = sbuf_printf(sb, l_map_str,
1157 (u_long)e_start, (u_long)e_end,
1158 (e_prot & VM_PROT_READ)?"r":"-",
1159 (e_prot & VM_PROT_WRITE)?"w":"-",
1160 (e_prot & VM_PROT_EXECUTE)?"x":"-",
1170 free(freename, M_TEMP);
1171 vm_map_lock_read(map);
1176 if (last_timestamp != map->timestamp) {
1178 * Look again for the entry because the map was
1179 * modified while it was unlocked. Specifically,
1180 * the entry may have been clipped, merged, or deleted.
1182 vm_map_lookup_entry(map, e_end - 1, &tmp_entry);
1186 vm_map_unlock_read(map);
1193 * Criteria for interface name translation
1195 #define IFP_IS_ETH(ifp) (ifp->if_type == IFT_ETHER)
1198 linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen)
1200 struct ifnet *ifscan;
1203 IFNET_RLOCK_ASSERT();
1205 /* Short-circuit non ethernet interfaces */
1206 if (!IFP_IS_ETH(ifp))
1207 return (strlcpy(buffer, ifp->if_xname, buflen));
1209 /* Determine the (relative) unit number for ethernet interfaces */
1211 CK_STAILQ_FOREACH(ifscan, &V_ifnet, if_link) {
1213 return (snprintf(buffer, buflen, "eth%d", ethno));
1214 if (IFP_IS_ETH(ifscan))
1222 * Filler function for proc/net/dev
1225 linprocfs_donetdev(PFS_FILL_ARGS)
1227 char ifname[16]; /* XXX LINUX_IFNAMSIZ */
1230 sbuf_printf(sb, "%6s|%58s|%s\n"
1232 "Inter-", " Receive", " Transmit",
1234 "bytes packets errs drop fifo frame compressed multicast",
1235 "bytes packets errs drop fifo colls carrier compressed");
1237 CURVNET_SET(TD_TO_VNET(curthread));
1239 CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) {
1240 linux_ifname(ifp, ifname, sizeof ifname);
1241 sbuf_printf(sb, "%6.6s: ", ifname);
1242 sbuf_printf(sb, "%7ju %7ju %4ju %4ju %4lu %5lu %10lu %9ju ",
1243 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IBYTES),
1244 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IPACKETS),
1245 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IERRORS),
1246 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IQDROPS),
1247 /* rx_missed_errors */
1248 0UL, /* rx_fifo_errors */
1249 0UL, /* rx_length_errors +
1252 * rx_frame_errors */
1253 0UL, /* rx_compressed */
1254 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IMCASTS));
1255 /* XXX-BZ rx only? */
1256 sbuf_printf(sb, "%8ju %7ju %4ju %4ju %4lu %5ju %7lu %10lu\n",
1257 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OBYTES),
1258 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OPACKETS),
1259 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OERRORS),
1260 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OQDROPS),
1261 0UL, /* tx_fifo_errors */
1262 (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_COLLISIONS),
1263 0UL, /* tx_carrier_errors +
1264 * tx_aborted_errors +
1265 * tx_window_errors +
1266 * tx_heartbeat_errors*/
1267 0UL); /* tx_compressed */
1276 * Filler function for proc/sys/kernel/osrelease
1279 linprocfs_doosrelease(PFS_FILL_ARGS)
1281 char osrelease[LINUX_MAX_UTSNAME];
1283 linux_get_osrelease(td, osrelease);
1284 sbuf_printf(sb, "%s\n", osrelease);
1290 * Filler function for proc/sys/kernel/ostype
1293 linprocfs_doostype(PFS_FILL_ARGS)
1295 char osname[LINUX_MAX_UTSNAME];
1297 linux_get_osname(td, osname);
1298 sbuf_printf(sb, "%s\n", osname);
1304 * Filler function for proc/sys/kernel/version
1307 linprocfs_doosbuild(PFS_FILL_ARGS)
1310 linprocfs_osbuild(td, sb);
1316 * Filler function for proc/sys/kernel/msgmni
1319 linprocfs_domsgmni(PFS_FILL_ARGS)
1322 sbuf_printf(sb, "%d\n", msginfo.msgmni);
1327 * Filler function for proc/sys/kernel/pid_max
1330 linprocfs_dopid_max(PFS_FILL_ARGS)
1333 sbuf_printf(sb, "%i\n", PID_MAX);
1338 * Filler function for proc/sys/kernel/sem
1341 linprocfs_dosem(PFS_FILL_ARGS)
1344 sbuf_printf(sb, "%d %d %d %d\n", seminfo.semmsl, seminfo.semmns,
1345 seminfo.semopm, seminfo.semmni);
1350 * Filler function for proc/sys/vm/min_free_kbytes
1352 * This mirrors the approach in illumos to return zero for reads. Effectively,
1353 * it says, no memory is kept in reserve for "atomic allocations". This class
1354 * of allocation can be used at times when a thread cannot be suspended.
1357 linprocfs_dominfree(PFS_FILL_ARGS)
1360 sbuf_printf(sb, "%d\n", 0);
1365 * Filler function for proc/scsi/device_info
1368 linprocfs_doscsidevinfo(PFS_FILL_ARGS)
1375 * Filler function for proc/scsi/scsi
1378 linprocfs_doscsiscsi(PFS_FILL_ARGS)
1385 * Filler function for proc/devices
1388 linprocfs_dodevices(PFS_FILL_ARGS)
1391 sbuf_printf(sb, "Character devices:\n");
1393 char_devices = linux_get_char_devices();
1394 sbuf_printf(sb, "%s", char_devices);
1395 linux_free_get_char_devices(char_devices);
1397 sbuf_printf(sb, "\nBlock devices:\n");
1403 * Filler function for proc/cmdline
1406 linprocfs_docmdline(PFS_FILL_ARGS)
1409 sbuf_printf(sb, "BOOT_IMAGE=%s", kernelname);
1410 sbuf_printf(sb, " ro root=302\n");
1415 * Filler function for proc/filesystems
1418 linprocfs_dofilesystems(PFS_FILL_ARGS)
1420 struct vfsconf *vfsp;
1423 TAILQ_FOREACH(vfsp, &vfsconf, vfc_list) {
1424 if (vfsp->vfc_flags & VFCF_SYNTHETIC)
1425 sbuf_printf(sb, "nodev");
1426 sbuf_printf(sb, "\t%s\n", vfsp->vfc_name);
1434 * Filler function for proc/modules
1437 linprocfs_domodules(PFS_FILL_ARGS)
1439 struct linker_file *lf;
1441 TAILQ_FOREACH(lf, &linker_files, link) {
1442 sbuf_printf(sb, "%-20s%8lu%4d\n", lf->filename,
1443 (unsigned long)lf->size, lf->refs);
1450 * Filler function for proc/pid/fd
1453 linprocfs_dofdescfs(PFS_FILL_ARGS)
1457 sbuf_printf(sb, "/dev/fd");
1459 sbuf_printf(sb, "unknown");
1464 * Filler function for proc/pid/limits
1466 static const struct linux_rlimit_ident {
1469 unsigned int rlim_id;
1470 } linux_rlimits_ident[] = {
1471 { "Max cpu time", "seconds", RLIMIT_CPU },
1472 { "Max file size", "bytes", RLIMIT_FSIZE },
1473 { "Max data size", "bytes", RLIMIT_DATA },
1474 { "Max stack size", "bytes", RLIMIT_STACK },
1475 { "Max core file size", "bytes", RLIMIT_CORE },
1476 { "Max resident set", "bytes", RLIMIT_RSS },
1477 { "Max processes", "processes", RLIMIT_NPROC },
1478 { "Max open files", "files", RLIMIT_NOFILE },
1479 { "Max locked memory", "bytes", RLIMIT_MEMLOCK },
1480 { "Max address space", "bytes", RLIMIT_AS },
1481 { "Max file locks", "locks", LINUX_RLIMIT_LOCKS },
1482 { "Max pending signals", "signals", LINUX_RLIMIT_SIGPENDING },
1483 { "Max msgqueue size", "bytes", LINUX_RLIMIT_MSGQUEUE },
1484 { "Max nice priority", "", LINUX_RLIMIT_NICE },
1485 { "Max realtime priority", "", LINUX_RLIMIT_RTPRIO },
1486 { "Max realtime timeout", "us", LINUX_RLIMIT_RTTIME },
1491 linprocfs_doproclimits(PFS_FILL_ARGS)
1493 const struct linux_rlimit_ident *li;
1494 struct plimit *limp;
1502 limp = lim_hold(p->p_limit);
1505 sbuf_printf(sb, "%-26s%-21s%-21s%-21s\n", "Limit", "Soft Limit",
1506 "Hard Limit", "Units");
1507 for (li = linux_rlimits_ident; li->desc != NULL; ++li) {
1508 switch (li->rlim_id)
1510 case LINUX_RLIMIT_LOCKS:
1512 case LINUX_RLIMIT_RTTIME:
1513 rl.rlim_cur = RLIM_INFINITY;
1515 case LINUX_RLIMIT_SIGPENDING:
1516 error = kernel_sysctlbyname(td,
1517 "kern.sigqueue.max_pending_per_proc",
1518 &res, &size, 0, 0, 0, 0);
1524 case LINUX_RLIMIT_MSGQUEUE:
1525 error = kernel_sysctlbyname(td,
1526 "kern.ipc.msgmnb", &res, &size, 0, 0, 0, 0);
1532 case LINUX_RLIMIT_NICE:
1534 case LINUX_RLIMIT_RTPRIO:
1539 rl = limp->pl_rlimit[li->rlim_id];
1542 if (rl.rlim_cur == RLIM_INFINITY)
1543 sbuf_printf(sb, "%-26s%-21s%-21s%-10s\n",
1544 li->desc, "unlimited", "unlimited", li->unit);
1546 sbuf_printf(sb, "%-26s%-21llu%-21llu%-10s\n",
1547 li->desc, (unsigned long long)rl.rlim_cur,
1548 (unsigned long long)rl.rlim_max, li->unit);
1556 * Filler function for proc/sys/kernel/random/uuid
1559 linprocfs_douuid(PFS_FILL_ARGS)
1563 kern_uuidgen(&uuid, 1);
1564 sbuf_printf_uuid(sb, &uuid);
1565 sbuf_printf(sb, "\n");
1570 * Filler function for proc/pid/auxv
1573 linprocfs_doauxv(PFS_FILL_ARGS)
1576 off_t buflen, resid;
1580 * Mimic linux behavior and pass only processes with usermode
1581 * address space as valid. Return zero silently otherwise.
1583 if (p->p_vmspace == &vmspace0)
1586 if (uio->uio_resid == 0)
1588 if (uio->uio_offset < 0 || uio->uio_resid < 0)
1591 asb = sbuf_new_auto();
1594 error = proc_getauxv(td, p, asb);
1596 error = sbuf_finish(asb);
1598 resid = sbuf_len(asb) - uio->uio_offset;
1599 if (resid > uio->uio_resid)
1600 buflen = uio->uio_resid;
1603 if (buflen > IOSIZE_MAX)
1605 if (buflen > MAXPHYS)
1611 error = uiomove(sbuf_data(asb) + uio->uio_offset, buflen, uio);
1620 linprocfs_init(PFS_INIT_ARGS)
1622 struct pfs_node *root;
1623 struct pfs_node *dir;
1624 struct pfs_node *sys;
1629 pfs_create_file(root, "cmdline", &linprocfs_docmdline,
1630 NULL, NULL, NULL, PFS_RD);
1631 pfs_create_file(root, "cpuinfo", &linprocfs_docpuinfo,
1632 NULL, NULL, NULL, PFS_RD);
1633 pfs_create_file(root, "devices", &linprocfs_dodevices,
1634 NULL, NULL, NULL, PFS_RD);
1635 pfs_create_file(root, "filesystems", &linprocfs_dofilesystems,
1636 NULL, NULL, NULL, PFS_RD);
1637 pfs_create_file(root, "loadavg", &linprocfs_doloadavg,
1638 NULL, NULL, NULL, PFS_RD);
1639 pfs_create_file(root, "meminfo", &linprocfs_domeminfo,
1640 NULL, NULL, NULL, PFS_RD);
1642 pfs_create_file(root, "modules", &linprocfs_domodules,
1643 NULL, NULL, NULL, PFS_RD);
1645 pfs_create_file(root, "mounts", &linprocfs_domtab,
1646 NULL, NULL, NULL, PFS_RD);
1647 pfs_create_file(root, "mtab", &linprocfs_domtab,
1648 NULL, NULL, NULL, PFS_RD);
1649 pfs_create_file(root, "partitions", &linprocfs_dopartitions,
1650 NULL, NULL, NULL, PFS_RD);
1651 pfs_create_link(root, "self", &procfs_docurproc,
1652 NULL, NULL, NULL, 0);
1653 pfs_create_file(root, "stat", &linprocfs_dostat,
1654 NULL, NULL, NULL, PFS_RD);
1655 pfs_create_file(root, "swaps", &linprocfs_doswaps,
1656 NULL, NULL, NULL, PFS_RD);
1657 pfs_create_file(root, "uptime", &linprocfs_douptime,
1658 NULL, NULL, NULL, PFS_RD);
1659 pfs_create_file(root, "version", &linprocfs_doversion,
1660 NULL, NULL, NULL, PFS_RD);
1663 dir = pfs_create_dir(root, "net", NULL, NULL, NULL, 0);
1664 pfs_create_file(dir, "dev", &linprocfs_donetdev,
1665 NULL, NULL, NULL, PFS_RD);
1667 /* /proc/<pid>/... */
1668 dir = pfs_create_dir(root, "pid", NULL, NULL, NULL, PFS_PROCDEP);
1669 pfs_create_file(dir, "cmdline", &linprocfs_doproccmdline,
1670 NULL, NULL, NULL, PFS_RD);
1671 pfs_create_link(dir, "cwd", &linprocfs_doproccwd,
1672 NULL, NULL, NULL, 0);
1673 pfs_create_file(dir, "environ", &linprocfs_doprocenviron,
1674 NULL, &procfs_candebug, NULL, PFS_RD);
1675 pfs_create_link(dir, "exe", &procfs_doprocfile,
1676 NULL, &procfs_notsystem, NULL, 0);
1677 pfs_create_file(dir, "maps", &linprocfs_doprocmaps,
1678 NULL, NULL, NULL, PFS_RD);
1679 pfs_create_file(dir, "mem", &procfs_doprocmem,
1680 procfs_attr_rw, &procfs_candebug, NULL, PFS_RDWR | PFS_RAW);
1681 pfs_create_file(dir, "mounts", &linprocfs_domtab,
1682 NULL, NULL, NULL, PFS_RD);
1683 pfs_create_link(dir, "root", &linprocfs_doprocroot,
1684 NULL, NULL, NULL, 0);
1685 pfs_create_file(dir, "stat", &linprocfs_doprocstat,
1686 NULL, NULL, NULL, PFS_RD);
1687 pfs_create_file(dir, "statm", &linprocfs_doprocstatm,
1688 NULL, NULL, NULL, PFS_RD);
1689 pfs_create_file(dir, "status", &linprocfs_doprocstatus,
1690 NULL, NULL, NULL, PFS_RD);
1691 pfs_create_link(dir, "fd", &linprocfs_dofdescfs,
1692 NULL, NULL, NULL, 0);
1693 pfs_create_file(dir, "auxv", &linprocfs_doauxv,
1694 NULL, &procfs_candebug, NULL, PFS_RD|PFS_RAWRD);
1695 pfs_create_file(dir, "limits", &linprocfs_doproclimits,
1696 NULL, NULL, NULL, PFS_RD);
1698 /* /proc/scsi/... */
1699 dir = pfs_create_dir(root, "scsi", NULL, NULL, NULL, 0);
1700 pfs_create_file(dir, "device_info", &linprocfs_doscsidevinfo,
1701 NULL, NULL, NULL, PFS_RD);
1702 pfs_create_file(dir, "scsi", &linprocfs_doscsiscsi,
1703 NULL, NULL, NULL, PFS_RD);
1706 sys = pfs_create_dir(root, "sys", NULL, NULL, NULL, 0);
1707 /* /proc/sys/kernel/... */
1708 dir = pfs_create_dir(sys, "kernel", NULL, NULL, NULL, 0);
1709 pfs_create_file(dir, "osrelease", &linprocfs_doosrelease,
1710 NULL, NULL, NULL, PFS_RD);
1711 pfs_create_file(dir, "ostype", &linprocfs_doostype,
1712 NULL, NULL, NULL, PFS_RD);
1713 pfs_create_file(dir, "version", &linprocfs_doosbuild,
1714 NULL, NULL, NULL, PFS_RD);
1715 pfs_create_file(dir, "msgmni", &linprocfs_domsgmni,
1716 NULL, NULL, NULL, PFS_RD);
1717 pfs_create_file(dir, "pid_max", &linprocfs_dopid_max,
1718 NULL, NULL, NULL, PFS_RD);
1719 pfs_create_file(dir, "sem", &linprocfs_dosem,
1720 NULL, NULL, NULL, PFS_RD);
1722 /* /proc/sys/kernel/random/... */
1723 dir = pfs_create_dir(dir, "random", NULL, NULL, NULL, 0);
1724 pfs_create_file(dir, "uuid", &linprocfs_douuid,
1725 NULL, NULL, NULL, PFS_RD);
1727 /* /proc/sys/vm/.... */
1728 dir = pfs_create_dir(sys, "vm", NULL, NULL, NULL, 0);
1729 pfs_create_file(dir, "min_free_kbytes", &linprocfs_dominfree,
1730 NULL, NULL, NULL, PFS_RD);
1739 linprocfs_uninit(PFS_INIT_ARGS)
1742 /* nothing to do, pseudofs will GC */
1746 PSEUDOFS(linprocfs, 1, VFCF_JAIL);
1747 #if defined(__aarch64__) || defined(__amd64__)
1748 MODULE_DEPEND(linprocfs, linux_common, 1, 1, 1);
1750 MODULE_DEPEND(linprocfs, linux, 1, 1, 1);
1752 MODULE_DEPEND(linprocfs, procfs, 1, 1, 1);
1753 MODULE_DEPEND(linprocfs, sysvmsg, 1, 1, 1);
1754 MODULE_DEPEND(linprocfs, sysvsem, 1, 1, 1);