PatchworkOS  dbbdc99
A non-POSIX operating system.
Loading...
Searching...
No Matches
procfs.c File Reference
#include <_libstd/MAX_NAME.h>
#include <kernel/fs/procfs.h>
#include <kernel/fs/ctl.h>
#include <kernel/fs/dentry.h>
#include <kernel/fs/file.h>
#include <kernel/fs/filesystem.h>
#include <kernel/fs/mount.h>
#include <kernel/fs/namespace.h>
#include <kernel/fs/path.h>
#include <kernel/fs/superblock.h>
#include <kernel/fs/vfs.h>
#include <kernel/fs/vnode.h>
#include <kernel/log/log.h>
#include <kernel/log/panic.h>
#include <kernel/proc/process.h>
#include <kernel/sched/sched.h>
#include <kernel/sched/thread.h>
#include <kernel/sync/lock.h>
#include <assert.h>
#include <errno.h>
#include <kernel/sync/rcu.h>
#include <stdatomic.h>
#include <stdlib.h>
#include <string.h>
#include <sys/fs.h>
#include <sys/list.h>
Include dependency graph for procfs.c:

Go to the source code of this file.

Data Structures

struct  procfs_entry_t
 

Functions

static uint64_t procfs_revalidate_hide (dentry_t *dentry)
 
static size_t procfs_prio_read (file_t *file, void *buffer, size_t count, size_t *offset)
 
static size_t procfs_prio_write (file_t *file, const void *buffer, size_t count, size_t *offset)
 
static size_t procfs_cwd_read (file_t *file, void *buffer, size_t count, size_t *offset)
 
static size_t procfs_cwd_write (file_t *file, const void *buffer, size_t count, size_t *offset)
 
static size_t procfs_cmdline_read (file_t *file, void *buffer, size_t count, size_t *offset)
 
static size_t procfs_note_write (file_t *file, const void *buffer, size_t count, size_t *offset)
 
static size_t procfs_notegroup_write (file_t *file, const void *buffer, size_t count, size_t *offset)
 
static uint64_t procfs_group_open (file_t *file)
 
static void procfs_group_close (file_t *file)
 
static size_t procfs_pid_read (file_t *file, void *buffer, size_t count, size_t *offset)
 
static size_t procfs_wait_read (file_t *file, void *buffer, size_t count, size_t *offset)
 
static wait_queue_tprocfs_wait_poll (file_t *file, poll_events_t *revents)
 
static size_t procfs_perf_read (file_t *file, void *buffer, size_t count, size_t *offset)
 
static uint64_t procfs_ns_open (file_t *file)
 
static void procfs_ns_close (file_t *file)
 
static uint64_t procfs_ctl_close (file_t *file, uint64_t argc, const char **argv)
 
static uint64_t procfs_ctl_dup2 (file_t *file, uint64_t argc, const char **argv)
 
static uint64_t procfs_ctl_bind (file_t *file, uint64_t argc, const char **argv)
 
static uint64_t procfs_ctl_mount (file_t *file, uint64_t argc, const char **argv)
 
static uint64_t procfs_ctl_touch (file_t *file, uint64_t argc, const char **argv)
 
static uint64_t procfs_ctl_start (file_t *file, uint64_t argc, const char **argv)
 
static uint64_t procfs_ctl_kill (file_t *file, uint64_t argc, const char **argv)
 
static uint64_t procfs_ctl_setns (file_t *file, uint64_t argc, const char **argv)
 
static uint64_t procfs_ctl_setgroup (file_t *file, uint64_t argc, const char **argv)
 
 CTL_STANDARD_OPS_DEFINE (ctlOps, { {"close", procfs_ctl_close, 2, 3}, {"dup2", procfs_ctl_dup2, 3, 3}, {"bind", procfs_ctl_bind, 3, 3}, {"mount", procfs_ctl_mount, 3, 4}, {"touch", procfs_ctl_touch, 2, 2}, {"start", procfs_ctl_start, 1, 1}, {"kill", procfs_ctl_kill, 1, 2}, {"setns", procfs_ctl_setns, 2, 2}, {"setgroup", procfs_ctl_setgroup, 2, 2}, {0}, })
 
static size_t procfs_env_write (file_t *file, const void *buffer, size_t count, size_t *offset)
 
static uint64_t procfs_env_lookup (vnode_t *dir, dentry_t *target)
 
static uint64_t procfs_env_create (vnode_t *dir, dentry_t *target, mode_t mode)
 
static uint64_t procfs_env_remove (vnode_t *dir, dentry_t *target)
 
static uint64_t procfs_env_iterate (dentry_t *dentry, dir_ctx_t *ctx)
 
static uint64_t procfs_self_readlink (vnode_t *vnode, char *buffer, uint64_t count)
 
static uint64_t procfs_pid_lookup (vnode_t *dir, dentry_t *target)
 
static void procfs_pid_cleanup (vnode_t *vnode)
 
static uint64_t procfs_pid_iterate (dentry_t *dentry, dir_ctx_t *ctx)
 
static uint64_t procfs_lookup (vnode_t *dir, dentry_t *target)
 
static uint64_t procfs_iterate (dentry_t *dentry, dir_ctx_t *ctx)
 
static dentry_tprocfs_mount (filesystem_t *fs, const char *options, void *data)
 
void procfs_init (void)
 Register the procfs filesystem.
 

Variables

static dentry_ops_t hideDentryOps
 
static file_ops_t prioOps
 
static file_ops_t cwdOps
 
static file_ops_t cmdlineOps
 
static file_ops_t noteOps
 
static file_ops_t notegroupOps
 
static file_ops_t groupOps
 
static file_ops_t pidOps
 
static file_ops_t waitOps
 
static file_ops_t perfOps
 
static file_ops_t nsOps
 
static file_ops_t envVarOps
 
static vnode_ops_t envVnodeOps
 
static dentry_ops_t envDentryOps
 
static vnode_ops_t selfOps
 
static const procfs_entry_t pidEntries []
 
static procfs_entry_t procEntries []
 
static vnode_ops_t pidVnodeOps
 
static dentry_ops_t pidDentryOps
 
static vnode_ops_t procVnodeOps
 
static dentry_ops_t procDentryOps
 
static filesystem_t procfs
 

Function Documentation

◆ procfs_revalidate_hide()

static uint64_t procfs_revalidate_hide ( dentry_t dentry)
static

Definition at line 30 of file procfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ procfs_prio_read()

static size_t procfs_prio_read ( file_t file,
void *  buffer,
size_t  count,
size_t offset 
)
static

Definition at line 64 of file procfs.c.

Here is the call graph for this function:

◆ procfs_prio_write()

static size_t procfs_prio_write ( file_t file,
const void *  buffer,
size_t  count,
size_t offset 
)
static

Definition at line 75 of file procfs.c.

Here is the call graph for this function:

◆ procfs_cwd_read()

static size_t procfs_cwd_read ( file_t file,
void *  buffer,
size_t  count,
size_t offset 
)
static

Definition at line 112 of file procfs.c.

Here is the call graph for this function:

◆ procfs_cwd_write()

static size_t procfs_cwd_write ( file_t file,
const void *  buffer,
size_t  count,
size_t offset 
)
static

Definition at line 136 of file procfs.c.

Here is the call graph for this function:

◆ procfs_cmdline_read()

static size_t procfs_cmdline_read ( file_t file,
void *  buffer,
size_t  count,
size_t offset 
)
static

Definition at line 194 of file procfs.c.

Here is the call graph for this function:

◆ procfs_note_write()

static size_t procfs_note_write ( file_t file,
const void *  buffer,
size_t  count,
size_t offset 
)
static

Definition at line 238 of file procfs.c.

Here is the call graph for this function:

◆ procfs_notegroup_write()

static size_t procfs_notegroup_write ( file_t file,
const void *  buffer,
size_t  count,
size_t offset 
)
static

Definition at line 278 of file procfs.c.

Here is the call graph for this function:

◆ procfs_group_open()

static uint64_t procfs_group_open ( file_t file)
static

Definition at line 308 of file procfs.c.

Here is the call graph for this function:

◆ procfs_group_close()

static void procfs_group_close ( file_t file)
static

Definition at line 322 of file procfs.c.

◆ procfs_pid_read()

static size_t procfs_pid_read ( file_t file,
void *  buffer,
size_t  count,
size_t offset 
)
static

Definition at line 339 of file procfs.c.

Here is the call graph for this function:

◆ procfs_wait_read()

static size_t procfs_wait_read ( file_t file,
void *  buffer,
size_t  count,
size_t offset 
)
static

Definition at line 352 of file procfs.c.

Here is the call graph for this function:

◆ procfs_wait_poll()

static wait_queue_t * procfs_wait_poll ( file_t file,
poll_events_t revents 
)
static

Definition at line 367 of file procfs.c.

◆ procfs_perf_read()

static size_t procfs_perf_read ( file_t file,
void *  buffer,
size_t  count,
size_t offset 
)
static

Definition at line 384 of file procfs.c.

Here is the call graph for this function:

◆ procfs_ns_open()

static uint64_t procfs_ns_open ( file_t file)
static

Definition at line 414 of file procfs.c.

Here is the call graph for this function:

◆ procfs_ns_close()

static void procfs_ns_close ( file_t file)
static

Definition at line 428 of file procfs.c.

◆ procfs_ctl_close()

static uint64_t procfs_ctl_close ( file_t file,
uint64_t  argc,
const char **  argv 
)
static

Definition at line 444 of file procfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ procfs_ctl_dup2()

static uint64_t procfs_ctl_dup2 ( file_t file,
uint64_t  argc,
const char **  argv 
)
static

Definition at line 493 of file procfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ procfs_ctl_bind()

static uint64_t procfs_ctl_bind ( file_t file,
uint64_t  argc,
const char **  argv 
)
static

Definition at line 525 of file procfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ procfs_ctl_mount()

static uint64_t procfs_ctl_mount ( file_t file,
uint64_t  argc,
const char **  argv 
)
static

Definition at line 587 of file procfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ procfs_ctl_touch()

static uint64_t procfs_ctl_touch ( file_t file,
uint64_t  argc,
const char **  argv 
)
static

Definition at line 635 of file procfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ procfs_ctl_start()

static uint64_t procfs_ctl_start ( file_t file,
uint64_t  argc,
const char **  argv 
)
static

Definition at line 660 of file procfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ procfs_ctl_kill()

static uint64_t procfs_ctl_kill ( file_t file,
uint64_t  argc,
const char **  argv 
)
static

Definition at line 678 of file procfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ procfs_ctl_setns()

static uint64_t procfs_ctl_setns ( file_t file,
uint64_t  argc,
const char **  argv 
)
static

Definition at line 695 of file procfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ procfs_ctl_setgroup()

static uint64_t procfs_ctl_setgroup ( file_t file,
uint64_t  argc,
const char **  argv 
)
static

Definition at line 736 of file procfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CTL_STANDARD_OPS_DEFINE()

CTL_STANDARD_OPS_DEFINE ( ctlOps  ,
{ {"close", procfs_ctl_close, 2, 3}, {"dup2", procfs_ctl_dup2, 3, 3}, {"bind", procfs_ctl_bind, 3, 3}, {"mount", procfs_ctl_mount, 3, 4}, {"touch", procfs_ctl_touch, 2, 2}, {"start", procfs_ctl_start, 1, 1}, {"kill", procfs_ctl_kill, 1, 2}, {"setns", procfs_ctl_setns, 2, 2}, {"setgroup", procfs_ctl_setgroup, 2, 2}, {0}, }   
)

Definition at line 777 of file procfs.c.

Here is the call graph for this function:

◆ procfs_env_write()

static size_t procfs_env_write ( file_t file,
const void *  buffer,
size_t  count,
size_t offset 
)
static

Definition at line 805 of file procfs.c.

Here is the call graph for this function:

◆ procfs_env_lookup()

static uint64_t procfs_env_lookup ( vnode_t dir,
dentry_t target 
)
static

Definition at line 834 of file procfs.c.

Here is the call graph for this function:

◆ procfs_env_create()

static uint64_t procfs_env_create ( vnode_t dir,
dentry_t target,
mode_t  mode 
)
static

Definition at line 859 of file procfs.c.

Here is the call graph for this function:

◆ procfs_env_remove()

static uint64_t procfs_env_remove ( vnode_t dir,
dentry_t target 
)
static

Definition at line 887 of file procfs.c.

Here is the call graph for this function:

◆ procfs_env_iterate()

static uint64_t procfs_env_iterate ( dentry_t dentry,
dir_ctx_t ctx 
)
static

Definition at line 906 of file procfs.c.

Here is the call graph for this function:

◆ procfs_self_readlink()

static uint64_t procfs_self_readlink ( vnode_t vnode,
char *  buffer,
uint64_t  count 
)
static

Definition at line 939 of file procfs.c.

Here is the call graph for this function:

◆ procfs_pid_lookup()

static uint64_t procfs_pid_lookup ( vnode_t dir,
dentry_t target 
)
static

Definition at line 1046 of file procfs.c.

Here is the call graph for this function:

◆ procfs_pid_cleanup()

static void procfs_pid_cleanup ( vnode_t vnode)
static

Definition at line 1078 of file procfs.c.

◆ procfs_pid_iterate()

static uint64_t procfs_pid_iterate ( dentry_t dentry,
dir_ctx_t ctx 
)
static

Definition at line 1090 of file procfs.c.

Here is the call graph for this function:

◆ procfs_lookup()

static uint64_t procfs_lookup ( vnode_t dir,
dentry_t target 
)
static

Definition at line 1140 of file procfs.c.

Here is the call graph for this function:

◆ procfs_iterate()

static uint64_t procfs_iterate ( dentry_t dentry,
dir_ctx_t ctx 
)
static

Definition at line 1188 of file procfs.c.

Here is the call graph for this function:

◆ procfs_mount()

static dentry_t * procfs_mount ( filesystem_t fs,
const char *  options,
void *  data 
)
static

Definition at line 1237 of file procfs.c.

Here is the call graph for this function:

Variable Documentation

◆ hideDentryOps

dentry_ops_t hideDentryOps
static
Initial value:
= {
.revalidate = procfs_revalidate_hide,
}
static uint64_t procfs_revalidate_hide(dentry_t *dentry)
Definition procfs.c:30

Definition at line 60 of file procfs.c.

◆ prioOps

file_ops_t prioOps
static
Initial value:
= {
}
static size_t procfs_prio_read(file_t *file, void *buffer, size_t count, size_t *offset)
Definition procfs.c:64
static size_t procfs_prio_write(file_t *file, const void *buffer, size_t count, size_t *offset)
Definition procfs.c:75

Definition at line 107 of file procfs.c.

◆ cwdOps

file_ops_t cwdOps
static
Initial value:
= {
.read = procfs_cwd_read,
.write = procfs_cwd_write,
}
static size_t procfs_cwd_read(file_t *file, void *buffer, size_t count, size_t *offset)
Definition procfs.c:112
static size_t procfs_cwd_write(file_t *file, const void *buffer, size_t count, size_t *offset)
Definition procfs.c:136

Definition at line 189 of file procfs.c.

◆ cmdlineOps

file_ops_t cmdlineOps
static
Initial value:
= {
}
static size_t procfs_cmdline_read(file_t *file, void *buffer, size_t count, size_t *offset)
Definition procfs.c:194

Definition at line 234 of file procfs.c.

◆ noteOps

file_ops_t noteOps
static
Initial value:
= {
}
static size_t procfs_note_write(file_t *file, const void *buffer, size_t count, size_t *offset)
Definition procfs.c:238

Definition at line 274 of file procfs.c.

◆ notegroupOps

file_ops_t notegroupOps
static
Initial value:
= {
}
static size_t procfs_notegroup_write(file_t *file, const void *buffer, size_t count, size_t *offset)
Definition procfs.c:278

Definition at line 304 of file procfs.c.

◆ groupOps

file_ops_t groupOps
static
Initial value:
= {
}
static void procfs_group_close(file_t *file)
Definition procfs.c:322
static uint64_t procfs_group_open(file_t *file)
Definition procfs.c:308

Definition at line 334 of file procfs.c.

◆ pidOps

file_ops_t pidOps
static
Initial value:
= {
.read = procfs_pid_read,
}
static size_t procfs_pid_read(file_t *file, void *buffer, size_t count, size_t *offset)
Definition procfs.c:339

Definition at line 348 of file procfs.c.

◆ waitOps

file_ops_t waitOps
static
Initial value:
= {
}
static size_t procfs_wait_read(file_t *file, void *buffer, size_t count, size_t *offset)
Definition procfs.c:352
static wait_queue_t * procfs_wait_poll(file_t *file, poll_events_t *revents)
Definition procfs.c:367

Definition at line 379 of file procfs.c.

◆ perfOps

file_ops_t perfOps
static
Initial value:
= {
}
static size_t procfs_perf_read(file_t *file, void *buffer, size_t count, size_t *offset)
Definition procfs.c:384

Definition at line 410 of file procfs.c.

◆ nsOps

file_ops_t nsOps
static
Initial value:
= {
.open = procfs_ns_open,
.close = procfs_ns_close,
}
static uint64_t procfs_ns_open(file_t *file)
Definition procfs.c:414
static void procfs_ns_close(file_t *file)
Definition procfs.c:428

Definition at line 439 of file procfs.c.

◆ envVarOps

file_ops_t envVarOps
static
Initial value:
= {
.read = procfs_env_read,
.write = procfs_env_write,
}
static size_t procfs_env_write(file_t *file, const void *buffer, size_t count, size_t *offset)
Definition procfs.c:805

Definition at line 829 of file procfs.c.

◆ envVnodeOps

vnode_ops_t envVnodeOps
static
Initial value:
= {
.lookup = procfs_env_lookup,
.create = procfs_env_create,
.remove = procfs_env_remove,
}
static uint64_t procfs_env_lookup(vnode_t *dir, dentry_t *target)
Definition procfs.c:834
static uint64_t procfs_env_remove(vnode_t *dir, dentry_t *target)
Definition procfs.c:887
static uint64_t procfs_env_create(vnode_t *dir, dentry_t *target, mode_t mode)
Definition procfs.c:859

Definition at line 900 of file procfs.c.

◆ envDentryOps

dentry_ops_t envDentryOps
static
Initial value:
= {
.iterate = procfs_env_iterate,
.revalidate = procfs_revalidate_hide,
}
static uint64_t procfs_env_iterate(dentry_t *dentry, dir_ctx_t *ctx)
Definition procfs.c:906

Definition at line 934 of file procfs.c.

◆ selfOps

vnode_ops_t selfOps
static
Initial value:
= {
.readlink = procfs_self_readlink,
}
static uint64_t procfs_self_readlink(vnode_t *vnode, char *buffer, uint64_t count)
Definition procfs.c:939

Definition at line 953 of file procfs.c.

◆ pidEntries

const procfs_entry_t pidEntries[]
static

Definition at line 966 of file procfs.c.

◆ procEntries

procfs_entry_t procEntries[]
static
Initial value:
= {
{
.name = "self",
.type = VSYMLINK,
.vnodeOps = &selfOps,
.fileOps = NULL,
},
}
@ VSYMLINK
Is a symbolic link.
Definition fs.h:345
#define NULL
Pointer error value.
Definition NULL.h:25
static vnode_ops_t selfOps
Definition procfs.c:953

Definition at line 1037 of file procfs.c.

◆ pidVnodeOps

vnode_ops_t pidVnodeOps
static
Initial value:
= {
.lookup = procfs_pid_lookup,
.cleanup = procfs_pid_cleanup,
}
static void procfs_pid_cleanup(vnode_t *vnode)
Definition procfs.c:1078
static uint64_t procfs_pid_lookup(vnode_t *dir, dentry_t *target)
Definition procfs.c:1046

Definition at line 1131 of file procfs.c.

◆ pidDentryOps

dentry_ops_t pidDentryOps
static
Initial value:
= {
.iterate = procfs_pid_iterate,
}
static uint64_t procfs_pid_iterate(dentry_t *dentry, dir_ctx_t *ctx)
Definition procfs.c:1090

Definition at line 1136 of file procfs.c.

◆ procVnodeOps

vnode_ops_t procVnodeOps
static
Initial value:
= {
.lookup = procfs_lookup,
}
static uint64_t procfs_lookup(vnode_t *dir, dentry_t *target)
Definition procfs.c:1140

Definition at line 1229 of file procfs.c.

◆ procDentryOps

dentry_ops_t procDentryOps
static
Initial value:
= {
.iterate = procfs_iterate,
}
static uint64_t procfs_iterate(dentry_t *dentry, dir_ctx_t *ctx)
Definition procfs.c:1188

Definition at line 1233 of file procfs.c.

◆ procfs

filesystem_t procfs
static
Initial value:
= {
.name = PROCFS_NAME,
.mount = procfs_mount,
}
#define PROCFS_NAME
Process filesystem name.
Definition procfs.h:205
static dentry_t * procfs_mount(filesystem_t *fs, const char *options, void *data)
Definition procfs.c:1237

Definition at line 1274 of file procfs.c.