PatchworkOS  10941b4
A non-POSIX operating system.
Loading...
Searching...
No Matches
procfs.c File Reference
#include <_internal/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/inode.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/log/log.h>
#include <kernel/log/panic.h>
#include <kernel/sched/sched.h>
#include <kernel/sched/thread.h>
#include <kernel/sync/lock.h>
#include <assert.h>
#include <errno.h>
#include <stdatomic.h>
#include <stdlib.h>
#include <string.h>
#include <sys/io.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 (inode_t *dir, dentry_t *target)
 
static uint64_t procfs_env_create (inode_t *dir, dentry_t *target, mode_t mode)
 
static uint64_t procfs_env_remove (inode_t *dir, dentry_t *target)
 
static uint64_t procfs_env_iterate (dentry_t *dentry, dir_ctx_t *ctx)
 
static uint64_t procfs_self_readlink (inode_t *inode, char *buffer, uint64_t count)
 
static uint64_t procfs_pid_lookup (inode_t *dir, dentry_t *target)
 
static void procfs_pid_cleanup (inode_t *inode)
 
static uint64_t procfs_pid_iterate (dentry_t *dentry, dir_ctx_t *ctx)
 
static uint64_t procfs_lookup (inode_t *dir, dentry_t *target)
 
static uint64_t procfs_iterate (dentry_t *dentry, dir_ctx_t *ctx)
 
static dentry_tprocfs_mount (filesystem_t *fs, block_device_t *device, void *private)
 
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 inode_ops_t envInodeOps
 
static dentry_ops_t envDentryOps
 
static inode_ops_t selfOps
 
static const procfs_entry_t pidEntries []
 
static procfs_entry_t procEntries []
 
static inode_ops_t pidInodeOps
 
static dentry_ops_t pidDentryOps
 
static inode_ops_t procInodeOps
 
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 28 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 62 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 73 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 110 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 134 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 192 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 236 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 276 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 306 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 320 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 337 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 350 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 365 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 382 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 412 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 426 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 442 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 491 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 523 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 585 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 633 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 658 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 676 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 693 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 734 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 775 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 803 of file procfs.c.

Here is the call graph for this function:

◆ procfs_env_lookup()

static uint64_t procfs_env_lookup ( inode_t dir,
dentry_t target 
)
static

Definition at line 832 of file procfs.c.

Here is the call graph for this function:

◆ procfs_env_create()

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

Definition at line 857 of file procfs.c.

Here is the call graph for this function:

◆ procfs_env_remove()

static uint64_t procfs_env_remove ( inode_t dir,
dentry_t target 
)
static

Definition at line 885 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 904 of file procfs.c.

Here is the call graph for this function:

◆ procfs_self_readlink()

static uint64_t procfs_self_readlink ( inode_t inode,
char buffer,
uint64_t  count 
)
static

Definition at line 938 of file procfs.c.

Here is the call graph for this function:

◆ procfs_pid_lookup()

static uint64_t procfs_pid_lookup ( inode_t dir,
dentry_t target 
)
static

Definition at line 1045 of file procfs.c.

Here is the call graph for this function:

◆ procfs_pid_cleanup()

static void procfs_pid_cleanup ( inode_t inode)
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 ( inode_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,
block_device_t device,
void private 
)
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:28

Definition at line 58 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:62
static size_t procfs_prio_write(file_t *file, const void *buffer, size_t count, size_t *offset)
Definition procfs.c:73

Definition at line 105 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:110
static size_t procfs_cwd_write(file_t *file, const void *buffer, size_t count, size_t *offset)
Definition procfs.c:134

Definition at line 187 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:192

Definition at line 232 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:236

Definition at line 272 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:276

Definition at line 302 of file procfs.c.

◆ groupOps

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

Definition at line 332 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:337

Definition at line 346 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:350
static wait_queue_t * procfs_wait_poll(file_t *file, poll_events_t *revents)
Definition procfs.c:365

Definition at line 377 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:382

Definition at line 408 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:412
static void procfs_ns_close(file_t *file)
Definition procfs.c:426

Definition at line 437 of file procfs.c.

◆ envVarOps

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

Definition at line 827 of file procfs.c.

◆ envInodeOps

inode_ops_t envInodeOps
static
Initial value:
= {
.lookup = procfs_env_lookup,
.create = procfs_env_create,
.remove = procfs_env_remove,
}
static uint64_t procfs_env_lookup(inode_t *dir, dentry_t *target)
Definition procfs.c:832
static uint64_t procfs_env_create(inode_t *dir, dentry_t *target, mode_t mode)
Definition procfs.c:857
static uint64_t procfs_env_remove(inode_t *dir, dentry_t *target)
Definition procfs.c:885

Definition at line 898 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:904

Definition at line 933 of file procfs.c.

◆ selfOps

inode_ops_t selfOps
static
Initial value:
= {
.readlink = procfs_self_readlink,
}
static uint64_t procfs_self_readlink(inode_t *inode, char *buffer, uint64_t count)
Definition procfs.c:938

Definition at line 952 of file procfs.c.

◆ pidEntries

const procfs_entry_t pidEntries[]
static

Definition at line 965 of file procfs.c.

◆ procEntries

procfs_entry_t procEntries[]
static
Initial value:
= {
{
.name = "self",
.type = INODE_SYMLINK,
.inodeOps = &selfOps,
.fileOps = NULL,
},
}
@ INODE_SYMLINK
Is a symbolic link.
Definition io.h:344
#define NULL
Pointer error value.
Definition NULL.h:23
static inode_ops_t selfOps
Definition procfs.c:952

Definition at line 1036 of file procfs.c.

◆ pidInodeOps

inode_ops_t pidInodeOps
static
Initial value:
= {
.lookup = procfs_pid_lookup,
.cleanup = procfs_pid_cleanup,
}
static void procfs_pid_cleanup(inode_t *inode)
Definition procfs.c:1078
static uint64_t procfs_pid_lookup(inode_t *dir, dentry_t *target)
Definition procfs.c:1045

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.

◆ procInodeOps

inode_ops_t procInodeOps
static
Initial value:
= {
.lookup = procfs_lookup,
}
static uint64_t procfs_lookup(inode_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:204
static dentry_t * procfs_mount(filesystem_t *fs, block_device_t *device, void *private)
Definition procfs.c:1237

Definition at line 1268 of file procfs.c.