|
AquilaOS documentation
How it works, and its code
|
procfs: the kernel's and the processes' state as files, usually mounted on /proc. More...
#include <core/system.h>#include <core/arch.h>#include <core/module.h>#include <core/string.h>#include <core/time.h>#include <aquila/errno.h>#include <boot/boot.h>#include <fs/vfs.h>#include <fs/iobuf.h>#include <fs/devfs.h>#include <fs/posix.h>#include <fs/vcache.h>#include <sys/proc.h>#include <sys/sched.h>#include <mm/vm.h>#include <mm/buddy.h>#include <ds/buddy.h>Go to the source code of this file.
Data Structures | |
| struct | procfs_entry |
| A file of the top directory: its name, and what makes its text. More... | |
| struct | procfs_proc_entry |
| A file of a process's directory: its name, and what makes its text. More... | |
Macros | |
| #define | PROCFS_ENTRIES (sizeof(entries)/sizeof(entries[0])) |
| #define | PROCFS_PROC_ENTRIES (sizeof(proc_entries)/sizeof(proc_entries[0])) |
| #define | PROC_INO(pid) |
| #define | INO_PID(ino) |
Functions | |
| static ssize_t | procfs_meminfo (off_t off, size_t size, char *buf) |
| Makes /proc/meminfo: the memory there is, and how it's used. | |
| static ssize_t | procfs_kvmem (off_t off, size_t size, char *buf) |
| Makes /proc/kvmem: the kernel's allocations, by malloc type. | |
| static ssize_t | procfs_version (off_t off, size_t size, char *buf) |
| Makes /proc/version: the kernel's name and version. | |
| static ssize_t | procfs_uptime (off_t off, size_t size, char *buf) |
| Makes /proc/uptime: the time since boot. | |
| int | arch_interrupts_info (char *buf, size_t size) |
| static ssize_t | procfs_interrupts (off_t off, size_t size, char *buf) |
| Makes /proc/interrupts: the interrupt controller and the IRQs, as the architecture describes them. | |
| static ssize_t | procfs_filesystems (off_t off, size_t size, char *buf) |
| Makes /proc/filesystems: the installed filesystems. | |
| static ssize_t | procfs_cmdline (off_t off, size_t size, char *buf) |
| Makes /proc/cmdline: the kernel's command line. | |
| static ssize_t | procfs_rdcmdline (off_t off, size_t size, char *buf) |
| Makes /proc/rdcmdline: the RAM disk module's command line. | |
| static ssize_t | procfs_mounts (off_t off, size_t size, char *buf) |
| Makes /proc/mounts: the mounted filesystems. | |
| static ssize_t | procfs_buddyinfo (off_t off, size_t size, char *buf) |
| Makes /proc/buddyinfo: the buddy allocator's free blocks, by size. | |
| static ssize_t | procfs_devices (off_t off, size_t size, char *buf) |
| Makes /proc/devices: the registered device drivers. | |
| static ssize_t | procfs_proc_status (int pid, off_t off, size_t size, void *buf) |
| Makes a process's status: its IDs, its state and its threads'. | |
| static ssize_t | procfs_proc_maps (int pid, off_t off, size_t size, void *buf) |
| Makes a process's maps: its mappings, as Linux's /proc/<pid>/maps shows them. | |
| static ssize_t | procfs_proc_vmstats (int pid, off_t off, size_t size, void *buf) |
| Makes a process's vmstats: its mappings and their vm objects. | |
| static ssize_t | procfs_entry_read (struct vnode *node, off_t offset, size_t size, char *buf) |
| Makes the text of a file of procfs, from an offset, into a kernel buffer. | |
| static ssize_t | procfs_read (struct vnode *node, off_t offset, struct iobuf *io) |
| Reads a file of procfs: its text is made a page at a time, and copied out through the iobuf. | |
| static ssize_t | procfs_readdir (struct vnode *vnode, off_t offset, struct dirent *dirent) |
| Reads a directory's entry at an offset. | |
| static int | procfs_finddir (struct vnode *parent, const char *name, struct dirent *dirent) |
| Finds the entry of a directory that has a name, and its inode number. | |
| static int | procfs_vget (struct vnode *super, ino_t ino, struct vnode **vnode) |
| Gets the vnode of an inode number, making it if it isn't in use. | |
| static int | procfs_close (struct vnode *vnode) |
| Frees a vnode that has no references left; the root stays. | |
| static int | procfs_init () |
| Sets procfs up at boot: its root directory, and its vnode cache. | |
| static int | procfs_mount (struct vnode *dir, int flags, void *data) |
| Mounts procfs on a directory: its one root directory is bound there. | |
Variables | |
| struct fs | procfs |
| struct vnode * | procfs_root = NULL |
| struct vcache | procfs_vcache = {0} |
| static struct procfs_entry | entries [] |
| static struct procfs_proc_entry | proc_entries [] |
procfs: the kernel's and the processes' state as files, usually mounted on /proc.
Its files hold no data: reading one makes its text then, a snapshot. The top directory has the system's files (meminfo, mounts, ...), self, and a directory for each process, named by its ID, with the process's files (status, maps, vmstats). Vnodes are made when they are looked up, and their inode numbers say what they are: a system file's is negative, and a process's directory and its files have consecutive numbers from the process's ID.
Definition in file procfs.c.
| #define INO_PID | ( | ino | ) |
Definition at line 524 of file procfs.c.
Referenced by procfs_entry_read(), procfs_finddir(), procfs_readdir(), and procfs_vget().
| #define PROC_INO | ( | pid | ) |
Definition at line 523 of file procfs.c.
Referenced by procfs_finddir().
Definition at line 334 of file procfs.c.
Referenced by procfs_entry_read(), procfs_finddir(), procfs_readdir(), and procfs_vget().
| #define PROCFS_PROC_ENTRIES (sizeof(proc_entries)/sizeof(proc_entries[0])) |
Definition at line 519 of file procfs.c.
Referenced by procfs_entry_read(), procfs_finddir(), procfs_readdir(), and procfs_vget().
| int arch_interrupts_info | ( | char * | buf, |
| size_t | size ) |
Definition at line 105 of file irq.c.
References arch_interrupts_info(), chip, chip_of(), counts, cpus, cpus_count, x86_irq_chip::describe, handlers, IRQ_NR, irqs, snprintf(), x86_irq_chip::timer, x86_irq_chip_name(), X86_IRQ_NR, and X86_IRQ_TIMER.
Referenced by arch_interrupts_info(), and procfs_interrupts().
Makes /proc/buddyinfo: the buddy allocator's free blocks, by size.
Definition at line 250 of file procfs.c.
References buddies, BUDDY_MAX_ORDER, BUDDY_ZONE_NR, memcpy(), MIN, procfs_buddyinfo(), snprintf(), and buddy::usable.
Referenced by procfs_buddyinfo().
|
static |
Frees a vnode that has no references left; the root stays.
Definition at line 770 of file procfs.c.
References vnode::ino, kfree(), procfs_close(), procfs_root, procfs_vcache, vnode::ref, vcache_find(), vcache_remove(), and vnode_pages_free().
Referenced by procfs_close().
Makes /proc/cmdline: the kernel's command line.
Definition at line 185 of file procfs.c.
References __kboot, boot::cmdline, memcpy(), MIN, procfs_cmdline(), and snprintf().
Referenced by procfs_cmdline().
Makes /proc/devices: the registered device drivers.
Definition at line 283 of file procfs.c.
References blkdev, chrdev, memcpy(), MIN, dev::name, procfs_devices(), and snprintf().
Referenced by procfs_devices().
Makes the text of a file of procfs, from an offset, into a kernel buffer.
Returns how many bytes there are, or a negative errno.
Definition at line 528 of file procfs.c.
References entries, vnode::ino, INO_PID, vnode::p, proc_entries, PROCFS_ENTRIES, procfs_entry_read(), PROCFS_PROC_ENTRIES, procfs_entry::read, and procfs_proc_entry::read.
Referenced by procfs_entry_read(), and procfs_read().
Makes /proc/filesystems: the installed filesystems.
Definition at line 161 of file procfs.c.
References memcpy(), MIN, fs::name, fs::nodev, procfs_filesystems(), registered_fs, and snprintf().
Referenced by procfs_filesystems().
|
static |
Finds the entry of a directory that has a name, and its inode number.
Definition at line 646 of file procfs.c.
References curproc, entries, INO_PID, proc::name, proc::parent, proc::pid, proc_entries, PROC_INO, PROCFS_ENTRIES, procfs_finddir(), PROCFS_PROC_ENTRIES, procfs_root, procs, queue_for, and snprintf().
Referenced by procfs_finddir().
|
static |
Sets procfs up at boot: its root directory, and its vnode cache.
Definition at line 789 of file procfs.c.
References vnode::atime, vnode::ctime, vnode::fs, gettime(), vnode::ino, kmalloc(), M_ZERO, vnode::mode, vnode::mtime, procfs, procfs_init(), procfs_root, procfs_vcache, vnode::ref, vcache_init(), and vfs_install().
Referenced by procfs_init().
Makes /proc/interrupts: the interrupt controller and the IRQs, as the architecture describes them.
Definition at line 144 of file procfs.c.
References arch_interrupts_info(), memcpy(), MIN, and procfs_interrupts().
Referenced by procfs_interrupts().
Makes /proc/kvmem: the kernel's allocations, by malloc type.
Definition at line 76 of file procfs.c.
References malloc_types, memcpy(), MIN, malloc_type::name, malloc_type::nr, procfs_kvmem(), queue_for, snprintf(), and malloc_type::total.
Referenced by procfs_kvmem().
Makes /proc/meminfo: the memory there is, and how it's used.
Definition at line 48 of file procfs.c.
References k_total_mem, k_used_mem, kvmem_obj_cnt, kvmem_used, memcpy(), MIN, procfs_meminfo(), slab_used, and snprintf().
Referenced by procfs_meminfo().
|
static |
Mounts procfs on a directory: its one root directory is bound there.
Returns 0, or -EBUSY if something is mounted on the directory, or procfs is mounted elsewhere already.
Definition at line 815 of file procfs.c.
References procfs_mount(), procfs_root, and vfs_bind().
Referenced by procfs_mount().
Makes /proc/mounts: the mounted filesystems.
Definition at line 224 of file procfs.c.
References mountpoint::dev, memcpy(), MIN, mounts, mountpoint::options, mountpoint::path, procfs_mounts(), queue_for, snprintf(), and mountpoint::type.
Referenced by procfs_mounts().
Makes a process's maps: its mappings, as Linux's /proc/<pid>/maps shows them.
Definition at line 403 of file procfs.c.
References vm_entry::base, vnode::dev, vm_entry::flags, proc::heap_vm, vnode::ino, memcpy(), MIN, NULL, vm_entry::off, vm_object::p, proc::pid, proc_pid_find(), procfs_proc_maps(), queue_for, vm_entry::size, vnode::size, snprintf(), proc::stack_vm, vm_object::type, vm_space::vm_entries, vm_entry::vm_object, VM_SHARED, proc::vm_space, VM_UR, VM_UW, VM_UX, and VMOBJ_FILE.
Referenced by procfs_proc_maps().
Makes a process's status: its IDs, its state and its threads'.
Definition at line 337 of file procfs.c.
References queue::count, curthread, proc::cwd, proc::gid, proc::heap, proc::mask, memcpy(), MIN, proc::name, thread::name, NULL, proc::parent, proc::pid, proc_pid_find(), procfs_proc_status(), queue_for, thread::run_link, proc::sig_pending, proc::sigmask, snprintf(), thread::state, proc::threads, thread::tid, thread::timer_link, proc::uid, vfs_vnode_path(), and thread::waitq.
Referenced by procfs_proc_status().
Makes a process's vmstats: its mappings and their vm objects.
Definition at line 458 of file procfs.c.
References vm_entry::base, vm_entry::flags, memcpy(), MIN, vm_entry::off, proc::pid, proc_pid_find(), procfs_proc_vmstats(), queue_for, vm_entry::size, snprintf(), vm_object::type, vm_space::vm_entries, vm_entry::vm_object, VM_SHARED, proc::vm_space, VM_UR, VM_UW, VM_UX, VMOBJ_FILE, and VMOBJ_ZERO.
Referenced by procfs_proc_vmstats().
Makes /proc/rdcmdline: the RAM disk module's command line.
Definition at line 203 of file procfs.c.
References __kboot, boot::cmdline, module_t::cmdline, memcpy(), MIN, boot::modules, boot::modules_count, procfs_rdcmdline(), and snprintf().
Referenced by procfs_rdcmdline().
Reads a file of procfs: its text is made a page at a time, and copied out through the iobuf.
Definition at line 547 of file procfs.c.
References iobuf_out(), kfree(), kmalloc(), MIN, PAGE_SIZE, procfs_entry_read(), procfs_read(), and iobuf::resid.
Referenced by procfs_read().
Reads a directory's entry at an offset.
The entries are . and .., then the top directory's files, self and the processes, or a process's files.
Definition at line 582 of file procfs.c.
References entries, vnode::ino, INO_PID, procfs_entry::name, procfs_proc_entry::name, proc::pid, proc_entries, PROCFS_ENTRIES, PROCFS_PROC_ENTRIES, procfs_readdir(), procfs_root, procs, queue_for, and snprintf().
Referenced by procfs_readdir().
Makes /proc/uptime: the time since boot.
Definition at line 124 of file procfs.c.
References arch_rtime_ms(), memcpy(), MIN, procfs_uptime(), and snprintf().
Referenced by procfs_uptime().
Makes /proc/version: the kernel's name and version.
Definition at line 102 of file procfs.c.
References __CONFIG_COMPILER__, __CONFIG_COMPILER_VERSION__, __CONFIG_TIMESTAMP__, memcpy(), MIN, procfs_version(), snprintf(), UTSNAME_RELEASE, and UTSNAME_SYSNAME.
Referenced by procfs_version().
Gets the vnode of an inode number, making it if it isn't in use.
Definition at line 692 of file procfs.c.
References vnode::atime, vnode::ctime, vnode::fs, gettime(), vnode::ino, INO_PID, kmalloc(), M_ZERO, vnode::mode, vnode::mtime, NULL, vnode::p, procfs, PROCFS_ENTRIES, PROCFS_PROC_ENTRIES, procfs_root, procfs_vcache, procfs_vget(), vcache_find(), and vcache_insert().
Referenced by procfs_vget().
|
static |
Definition at line 320 of file procfs.c.
Referenced by procfs_entry_read(), procfs_finddir(), and procfs_readdir().
|
static |
Definition at line 513 of file procfs.c.
Referenced by procfs_entry_read(), procfs_finddir(), and procfs_readdir().
| struct fs procfs |
Definition at line 35 of file procfs.c.
Referenced by procfs_init(), and procfs_vget().
Definition at line 44 of file procfs.c.
Referenced by procfs_close(), procfs_finddir(), procfs_init(), procfs_mount(), procfs_readdir(), and procfs_vget().
| struct vcache procfs_vcache = {0} |
Definition at line 45 of file procfs.c.
Referenced by procfs_close(), procfs_init(), and procfs_vget().