19#include <aquila/errno.h>
50 char meminfo_buf[512];
68 memcpy(buf, meminfo_buf + off, ret);
85 sz +=
snprintf(kvmem_buf + sz,
sizeof(kvmem_buf) - sz,
88 if ((
size_t) sz >=
sizeof(kvmem_buf))
94 memcpy(buf, kvmem_buf + off, ret);
104 char version_buf[512];
107 "%s version %s (%s version %s) %s\n",
116 memcpy(buf, version_buf + off, ret);
132 memcpy(buf, uptime_buf + off, ret);
149 sz =
MIN(sz, (
int)
sizeof(info) - 1);
153 memcpy(buf, info + off, ret);
171 if ((
size_t) sz >=
sizeof(fs_buf))
177 memcpy(buf, fs_buf + off, ret);
187 char cmdline_buf[512];
195 memcpy(buf, cmdline_buf + off, ret);
205 char rdcmdline_buf[512];
216 memcpy(buf, rdcmdline_buf + off, ret);
226 char mounts_buf[4096];
233 sz +=
snprintf(mounts_buf + sz,
sizeof(mounts_buf) - sz,
235 if ((
size_t) sz >=
sizeof(mounts_buf))
242 memcpy(buf, mounts_buf + off, ret);
252 char buddyinfo_buf[4096];
258 sz +=
snprintf(buddyinfo_buf + sz,
sizeof(buddyinfo_buf) - sz,
"Zone DMA\n");
260 sz +=
snprintf(buddyinfo_buf + sz,
sizeof(buddyinfo_buf) - sz,
"2^%d: %d\n",
264 sz +=
snprintf(buddyinfo_buf + sz,
sizeof(buddyinfo_buf) - sz,
"\nZone Normal\n");
266 sz +=
snprintf(buddyinfo_buf + sz,
sizeof(buddyinfo_buf) - sz,
"2^%d: %d\n",
270 sz +=
snprintf(buddyinfo_buf + sz,
sizeof(buddyinfo_buf) - sz,
"\n");
275 memcpy(buf, buddyinfo_buf + off, ret);
292 sz +=
snprintf(dev_buf + sz,
sizeof(dev_buf) - sz,
"chrdev:\n");
293 for (
int i = 0; i < 256; ++i) {
296 if ((
size_t) sz >=
sizeof(dev_buf))
301 sz +=
snprintf(dev_buf + sz,
sizeof(dev_buf) - sz,
"\nblkdev:\n");
302 for (
int i = 0; i < 256; ++i) {
305 if ((
size_t) sz >=
sizeof(dev_buf))
312 memcpy(buf, dev_buf + off, ret);
334#define PROCFS_ENTRIES (sizeof(entries)/sizeof(entries[0]))
344 char status_buf[1024],
cwd[256];
349 int sz =
snprintf(status_buf,
sizeof(status_buf),
360 "sigpending: 0x%x\n",
376 static const char *states[] = {
"running",
"sleeping",
"waiting",
"zombie"};
383 sz +=
snprintf(status_buf + sz,
sizeof(status_buf) - sz,
384 "thread %d%s%s: %s%s%s%s\n",
thread->
tid,
394 memcpy(buf, status_buf + off, ret);
437 sz +=
snprintf(maps_buf + sz,
sizeof(maps_buf) - sz,
438 "%x-%x %s %x %x %x %s\n",
450 memcpy(buf, maps_buf + off, ret);
465 char vmstats_buf[4096];
480 const char *type =
"";
488 sz +=
snprintf(vmstats_buf + sz,
sizeof(vmstats_buf) - sz,
489 "%p-%p %s %p %p %s\n",
519#define PROCFS_PROC_ENTRIES (sizeof(proc_entries)/sizeof(proc_entries[0]))
523#define PROC_INO(pid) (((pid) + 1) * (PROCFS_PROC_ENTRIES + 1))
524#define INO_PID(ino) ((ino) / (PROCFS_PROC_ENTRIES + 1) - 1)
554 size_t size = io->
resid, done = 0;
557 while (done < size) {
571 if ((
size_t) r < len)
576 return done ? (
ssize_t) done : r;
587 strcpy(dirent->d_name,
".");
589 }
else if (offset == 1) {
591 strcpy(dirent->d_name,
"..");
606 snprintf(dirent->d_name, 10,
"self");
626 strcpy(dirent->d_name,
".");
628 }
else if (offset == 1) {
630 strcpy(dirent->d_name,
"..");
651 dirent->d_ino = -(i + 1);
656 if (!strcmp(
name,
"self")) {
666 if (!strcmp(buf,
name)) {
671 }
else if (
parent->ino > 0) {
675 if (!strcmp(
name,
"..")) {
699 }
else if ((
ssize_t) ino < 0) {
706 if (!node)
goto e_nomem;
709 node->
mode = S_IFREG | 0555;
711 node->
p = (
void *)
id;
735 if (!node)
goto e_nomem;
740 node->
mode = S_IFREG | 0555;
742 node->
mode = S_IFDIR | 0555;
746 node->
p = (
void *)
id;
840 .eof = __vfs_eof_always,
struct buddy buddies[BUDDY_ZONE_NR][BUDDY_MAX_ORDER+1]
void vnode_pages_free(struct vnode *vnode)
Frees a vnode's vm object and its cached pages, when the vnode itself is freed.
#define __CONFIG_COMPILER__
#define __CONFIG_TIMESTAMP__
#define __CONFIG_COMPILER_VERSION__
ssize_t iobuf_out(struct iobuf *io, const void *src, size_t n)
Copies bytes from the kernel into the iobuf's buffer, and moves past them.
struct queue * malloc_types
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
void kfree(void *)
Frees an object that kmalloc() gave.
void * memcpy(void *dst, const void *src, size_t n)
Copies n bytes; dst and src must not overlap.
int vfs_vnode_path(struct vnode *vnode, struct vnode *root, char *buf, size_t size)
Computes a vnode's path, for getcwd() and /proc/mounts: it goes up through .., and finds each directo...
#define MODULE_INIT(name, i, f)
int posix_file_open(struct file *file)
Finishes opening a file: with O_TRUNC, a regular file is truncated to 0 bytes.
int posix_file_close(struct file *file)
Closes an open file by dropping its reference to its vnode.
ssize_t posix_file_read(struct file *file, struct iobuf *io)
Reads from an open file at its offset, and moves the offset past what was read.
ssize_t posix_file_readdir(struct file *file, struct dirent *dirent)
Reads the directory entry at an open directory's offset, and moves the offset past it.
struct proc * proc_pid_find(pid_t pid)
Finds a process by its ID.
struct vcache procfs_vcache
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_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_buddyinfo(off_t off, size_t size, char *buf)
Makes /proc/buddyinfo: the buddy allocator's free blocks, by size.
static ssize_t procfs_rdcmdline(off_t off, size_t size, char *buf)
Makes /proc/rdcmdline: the RAM disk module's command line.
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 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_kvmem(off_t off, size_t size, char *buf)
Makes /proc/kvmem: the kernel's allocations, by malloc type.
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 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_devices(off_t off, size_t size, char *buf)
Makes /proc/devices: the registered device drivers.
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_cmdline(off_t off, size_t size, char *buf)
Makes /proc/cmdline: the kernel's command line.
struct vnode * procfs_root
static int procfs_mount(struct vnode *dir, int flags, void *data)
Mounts procfs on a directory: its one root directory is bound there.
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_filesystems(off_t off, size_t size, char *buf)
Makes /proc/filesystems: the installed filesystems.
static int procfs_close(struct vnode *vnode)
Frees a vnode that has no references left; the root stays.
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.
#define PROCFS_PROC_ENTRIES
static struct procfs_proc_entry proc_entries[]
static ssize_t procfs_readdir(struct vnode *vnode, off_t offset, struct dirent *dirent)
Reads a directory's entry at an offset.
static ssize_t procfs_uptime(off_t off, size_t size, char *buf)
Makes /proc/uptime: the time since boot.
static struct procfs_entry entries[]
static ssize_t procfs_mounts(off_t off, size_t size, char *buf)
Makes /proc/mounts: the mounted filesystems.
static int procfs_init()
Sets procfs up at boot: its root directory, and its vnode cache.
static ssize_t procfs_version(off_t off, size_t size, char *buf)
Makes /proc/version: the kernel's name and version.
int snprintf(char *s, size_t n, const char *fmt,...)
Formats a string into a buffer.
__PTRDIFF_TYPE__ intptr_t
One order of a buddy allocator's zone (mm/buddy.c): a bitmap of its blocks, a set bit for a block tha...
A device driver: its operations, any of which may be NULL.
The list of registered filesystem types.
A malloc type: what an allocation is for, which /proc/kvmem counts by.
A mount's description, as /proc/mounts shows it.
pid_t pid
the process's ID
struct proc * parent
its parent
struct vm_space vm_space
its address space
struct vm_entry * stack_vm
struct vnode * cwd
its current directory (a reference), or NULL for the root
struct vm_entry * heap_vm
its heap's and its stack's mappings
mode_t mask
its file mode creation mask (umask)
char * name
its name: the program it runs
uid_t uid
its user and group IDs
struct queue threads
its threads
sigset_t sig_pending
its pending signals, a bit (1 << sig) each: a signal sent again while it's pending is delivered once ...
sigset_t sigmask
its blocked signals, a bit (1 << sig) each
A file of the top directory: its name, and what makes its text.
ssize_t(*) read(off_t off, size_t size, char *buf)
A file of a process's directory: its name, and what makes its text.
ssize_t(*) read(int pid, off_t off, size_t size, void *buf)
struct list_node run_link
it's on the ready list (sched.c) while it's ready to run, or on the wait queue it sleeps on (waitq); ...
struct list_node timer_link
it's on the timer's list while it waits with a deadline
tid_t tid
the thread's ID, in its process
const char * name
A kernel thread's (process 0's): its name, and what it runs.
A filesystem's vnode cache (fs/vcache.c): its vnodes in memory, by their inode number,...
A mapping (map entry): a range of an address space, its permissions, and where its pages come from.
uint32_t flags
its permissions and flags (VM_*)
size_t off
where the mapping starts in its object
vaddr_t base
where the mapping starts in its address space
struct vm_object * vm_object
its object: what its other pages come from (a file)
void * p
the pager's own data (a file's vnode)
int type
its kind (VMOBJ_*)
struct queue vm_entries
its mappings (map entries), in address order
A file in memory (a vnode): what its inode says, and the kernel's own state.
size_t ref
how many references there are to it
void * p
the filesystem's own data
int gettime(struct timespec *ts)
Reads the wall clock (CLOCK_REALTIME).
uint64_t arch_rtime_ms(void)
Reads the monotonic clock, in milliseconds.
void vcache_init(struct vcache *vcache)
Sets up an empty vnode cache.
struct vnode * vcache_find(struct vcache *vcache, ino_t ino)
Finds the cached vnode of an inode.
int vcache_insert(struct vcache *vcache, struct vnode *vnode)
Adds a vnode to a cache.
int vcache_remove(struct vcache *vcache, struct vnode *vnode)
Takes a vnode out of a cache.
int vfs_bind(struct vnode *dir, struct vnode *root)
Mounts a filesystem on a directory: a lookup that reaches dir goes on in root instead.
struct fs_list * registered_fs
The installed filesystems.
int vfs_install(struct fs *fs)
Installs a filesystem, so that it can be mounted by name.
#define VMOBJ_ZERO
pages of zeros
#define VMOBJ_FILE
a file's pages
#define VM_SHARED
shared: a fork doesn't copy it
#define VM_UX
user execute