219 char* dest = cmdline;
397 "user_clocks %llu\nkernel_sched_clocks %llu\nstart_clocks %llu\nuser_pages %llu\nthread_count %llu", userClocks,
444 if (argc != 2 && argc != 3)
455 if (
sscanf(argv[1],
"%lld", &fd) != 1)
587 if (argc != 3 && argc != 4)
616 const char*
fsName = argv[2];
698 if (
sscanf(argv[1],
"%llu", &fd) != 1)
739 if (
sscanf(argv[1],
"%llu", &fd) != 1)
793 size_t length =
strlen(value);
1075 if (process ==
NULL)
1162 if (process ==
NULL)
1212 snprintf(name,
sizeof(name),
"%llu", process->
id);
1236 if (superblock ==
NULL)
1258 superblock->
root = dentry;
1259 return superblock->
root;
1271 panic(
NULL,
"Failed to register procfs filesystem");
#define MAX_NAME
Maximum length of names.
#define MAX_PATH
Maximum length of filepaths.
#define assert(expression)
static dentry_ops_t dentryOps
#define CTL_STANDARD_OPS_DEFINE(name,...)
Helper macro to define a standard ctl file operations structure.
void cwd_set(cwd_t *cwd, const path_t *newPath)
Set the current working directory.
path_t cwd_get(cwd_t *cwd, namespace_t *ns)
Get the current working directory.
void dentry_make_positive(dentry_t *dentry, inode_t *inode)
Make a dentry positive by associating it with an inode.
#define DENTRY_IS_DIR(dentry)
Check if the inode associated with a dentry is a directory.
dentry_t * dentry_new(superblock_t *superblock, dentry_t *parent, const char *name)
Create a new dentry.
bool dentry_iterate_dots(dentry_t *dentry, dir_ctx_t *ctx)
Helper function to iterate over the special entries "." and "..".
#define DENTRY_IS_POSITIVE(dentry)
Check if a dentry is positive.
fd_t file_table_dup2(file_table_t *table, fd_t oldFd, fd_t newFd)
Duplicate a file descriptor to a specific file descriptor.
uint64_t file_table_close(file_table_t *table, fd_t fd)
Free a file descriptor.
file_t * file_table_get(file_table_t *table, fd_t fd)
Get a file from its file descriptor.
uint64_t file_table_close_range(file_table_t *table, fd_t min, fd_t max)
Free a range of file descriptors.
uint64_t filesystem_register(filesystem_t *fs)
Registers a filesystem.
inode_t * inode_new(superblock_t *superblock, ino_t number, itype_t type, const inode_ops_t *ops, const file_ops_t *fileOps)
Create a new inode.
ino_t ino_gen(ino_t parentNumber, const char *name)
Helper to generate a consistent inode number for an entry in a directory.
mount_t * namespace_bind(namespace_t *ns, path_t *target, path_t *source, mode_t mode)
Bind a source path to a target path in a namespace.
mount_t * namespace_mount(namespace_t *ns, path_t *target, const char *fsName, const char *deviceName, mode_t mode, void *private)
Mount a filesystem in a namespace.
bool namespace_accessible(namespace_t *ns, namespace_t *other)
Check if mounts in a namespace can be propagated to another namespace.
mode_t
Path flags and permissions.
#define PATH_DEFER(path)
Defer path put.
uint64_t path_walk(path_t *path, const pathname_t *pathname, namespace_t *ns)
Walk a pathname to a path.
uint64_t pathname_init(pathname_t *pathname, const char *string)
Initialize a pathname.
uint64_t path_to_name(const path_t *path, pathname_t *pathname)
Convert a path to a pathname.
void procfs_init(void)
Register the procfs filesystem.
#define PROCFS_NAME
Process filesystem name.
superblock_t * superblock_new(filesystem_t *fs, block_device_t *device, const superblock_ops_t *ops, const dentry_ops_t *dentryOps)
Create a new superblock.
#define NOTE_MAX
Maximum size of a notes buffer.
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
uint64_t space_user_page_count(space_t *space)
Get the number of user pages allocated in the address space.
const char * env_get(env_t *env, const char *key)
Get the value of an environment variable.
uint64_t env_set(env_t *env, const char *key, const char *value)
Set the value of an environment variable.
uint64_t env_unset(env_t *env, const char *key)
Unset an environment variable.
group_t * group_get(group_member_t *member)
Retrieve the group of a group member.
uint64_t group_send_note(group_member_t *member, const char *note)
Sends a note to all processes in the group of the specified member.
void group_add(group_t *group, group_member_t *member)
Joins a process to a specific group.
void process_kill(process_t *process, const char *status)
Kills a process, pushing it to the reaper.
void process_set_ns(process_t *process, namespace_t *ns)
Sets the namespace of a process.
#define PROCESS_FOR_EACH(process)
Macro to iterate over all processes.
namespace_t * process_get_ns(process_t *process)
Gets the namespace of a process.
process_t * process_get(pid_t id)
Gets a process by its ID.
uint64_t thread_send_note(thread_t *thread, const char *string)
Send a note to a thread.
uint64_t wait_unblock(wait_queue_t *queue, uint64_t amount, errno_t err)
Unblock threads waiting on a wait queue.
#define WAIT_ALL
Used to indicate that the wait should unblock all waiting threads.
#define WAIT_BLOCK(queue, condition)
Blocks until the condition is true, will test the condition on every wakeup.
process_t * sched_process(void)
Retrieves the process of the currently running thread.
#define LOCK_SCOPE(lock)
Acquires a lock for the reminder of the current scope.
static void lock_release(lock_t *lock)
Releases a lock.
static void lock_acquire(lock_t *lock)
Acquires a lock, blocking until it is available.
#define MUTEX_SCOPE(mutex)
Acquires a mutex for the reminder of the current scope.
#define UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
#define REF(ptr)
Increment reference count.
#define UNREF(ptr)
Decrement reference count.
file_t * vfs_open(const pathname_t *pathname, process_t *process)
Open a file.
#define BUFFER_READ(buffer, count, offset, src, size)
Helper macros for implementing file operations dealing with simple buffers.
#define ENOENT
No such file or directory.
#define EINVAL
Invalid argument.
#define ENOMEM
Out of memory.
#define ENOTDIR
Not a directory.
#define errno
Error number variable.
#define EACCES
Permission denied.
#define ARRAY_SIZE(x)
Get the number of elements in a static array.
#define UNUSED(x)
Mark a variable as unused.
uint64_t mount(const char *mountpoint, const char *fs, const char *device)
System call for mounting a filesystem.
poll_events_t
Poll events type.
@ POLLIN
File descriptor is ready to read.
@ INODE_DIR
Is a directory.
@ INODE_SYMLINK
Is a symbolic link.
static list_entry_t * list_first(list_t *list)
Gets the first entry in the list without removing it.
static uint64_t list_length(list_t *list)
Gets the length of the list.
#define PRIORITY_MAX_USER
The maximum priority user space is allowed to specify, inclusive.
uint8_t priority_t
Priority type.
#define NULL
Pointer error value.
#define ERR
Integer error value.
__UINT64_TYPE__ fd_t
A file descriptor.
__UINT64_TYPE__ pid_t
Process Identifier.
#define CONTAINER_OF_SAFE(ptr, type, member)
Safe container of macro.
__UINT64_TYPE__ clock_t
A nanosecond time.
static clock_source_t source
Structure to describe the HPET to the sys time subsystem.
EFI_PHYSICAL_ADDRESS buffer
errno_t memcpy_s(void *_RESTRICT s1, rsize_t s1max, const void *_RESTRICT s2, rsize_t n)
static size_t procfs_wait_read(file_t *file, void *buffer, size_t count, size_t *offset)
static const procfs_entry_t pidEntries[]
static filesystem_t procfs
static uint64_t procfs_env_lookup(inode_t *dir, dentry_t *target)
static uint64_t procfs_ns_open(file_t *file)
static uint64_t procfs_ctl_bind(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 void procfs_ns_close(file_t *file)
static uint64_t procfs_ctl_setgroup(file_t *file, uint64_t argc, const char **argv)
static size_t procfs_prio_read(file_t *file, void *buffer, size_t count, size_t *offset)
static uint64_t procfs_env_create(inode_t *dir, dentry_t *target, mode_t mode)
static uint64_t procfs_ctl_touch(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 procfs_entry_t procEntries[]
static uint64_t procfs_ctl_mount(file_t *file, uint64_t argc, const char **argv)
static uint64_t procfs_self_readlink(inode_t *inode, char *buffer, uint64_t count)
static size_t procfs_pid_read(file_t *file, void *buffer, size_t count, size_t *offset)
static file_ops_t noteOps
static uint64_t procfs_ctl_dup2(file_t *file, uint64_t argc, const char **argv)
static file_ops_t prioOps
static file_ops_t notegroupOps
static file_ops_t envVarOps
static void procfs_pid_cleanup(inode_t *inode)
static dentry_ops_t envDentryOps
static inode_ops_t pidInodeOps
static uint64_t procfs_ctl_close(file_t *file, uint64_t argc, const char **argv)
static uint64_t procfs_revalidate_hide(dentry_t *dentry)
static wait_queue_t * procfs_wait_poll(file_t *file, poll_events_t *revents)
static void procfs_group_close(file_t *file)
static uint64_t procfs_env_remove(inode_t *dir, dentry_t *target)
static inode_ops_t procInodeOps
static uint64_t procfs_iterate(dentry_t *dentry, dir_ctx_t *ctx)
static uint64_t procfs_pid_iterate(dentry_t *dentry, dir_ctx_t *ctx)
static size_t procfs_cwd_read(file_t *file, void *buffer, size_t count, size_t *offset)
static size_t procfs_env_write(file_t *file, const void *buffer, size_t count, size_t *offset)
static dentry_ops_t hideDentryOps
static uint64_t procfs_pid_lookup(inode_t *dir, dentry_t *target)
static size_t procfs_note_write(file_t *file, const void *buffer, size_t count, size_t *offset)
static file_ops_t perfOps
static size_t procfs_perf_read(file_t *file, void *buffer, size_t count, size_t *offset)
static uint64_t procfs_lookup(inode_t *dir, dentry_t *target)
static uint64_t procfs_ctl_kill(file_t *file, uint64_t argc, const char **argv)
static inode_ops_t envInodeOps
static size_t procfs_cmdline_read(file_t *file, void *buffer, size_t count, size_t *offset)
static dentry_ops_t procDentryOps
static file_ops_t groupOps
static dentry_t * procfs_mount(filesystem_t *fs, block_device_t *device, void *private)
static file_ops_t waitOps
static size_t procfs_prio_write(file_t *file, const void *buffer, size_t count, size_t *offset)
static inode_ops_t selfOps
static dentry_ops_t pidDentryOps
static uint64_t procfs_group_open(file_t *file)
static uint64_t procfs_env_iterate(dentry_t *dentry, dir_ctx_t *ctx)
static size_t procfs_notegroup_write(file_t *file, const 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 file_ops_t cmdlineOps
#define atomic_store(object, desired)
#define atomic_load(object)
#define atomic_fetch_and(object, operand)
_PUBLIC int sscanf(const char *_RESTRICT s, const char *_RESTRICT format,...)
_PUBLIC int snprintf(char *_RESTRICT s, size_t n, const char *_RESTRICT format,...)
_PUBLIC long long int atoll(const char *nptr)
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
_PUBLIC size_t strlen(const char *s)
_PUBLIC int strcmp(const char *s1, const char *s2)
Dentry operations structure.
uint64_t(* revalidate)(dentry_t *dentry)
Called when the dentry is looked up or retrieved from cache.
uint64_t(* iterate)(dentry_t *dentry, dir_ctx_t *ctx)
Iterate over the entries in a directory dentry.
Directory entry structure.
inode_t * inode
Will be NULL if the dentry is negative, once positive it will never be modified.
char name[MAX_NAME]
Constant after creation.
superblock_t * superblock
Directory context used to iterate over directory entries.
size_t index
An index that the filesystem can use for its own purposes.
bool(* emit)(dir_ctx_t *ctx, const char *name, ino_t number, itype_t type)
Emit function.
size_t pos
The current position in the directory, can be used to skip entries.
File operations structure.
size_t(* read)(file_t *file, void *buffer, size_t count, size_t *offset)
size_t(* write)(file_t *file, const void *buffer, size_t count, size_t *offset)
uint64_t(* open)(file_t *file)
Filesystem structure, represents a filesystem type, e.g. fat32, tmpfs, devfs, etc.
Inode operations structure.
uint64_t(* readlink)(inode_t *inode, char *buffer, uint64_t size)
Retrieve the path of the symbolic link.
uint64_t(* lookup)(inode_t *dir, dentry_t *target)
Look up a dentry in a directory inode.
clock_t startTime
The time when the process was started.
char buffer[PROCESS_STATUS_MAX]
wait_queue_t suspendQueue
process_threads_t threads
const file_ops_t * fileOps
const inode_ops_t * inodeOps
const dentry_ops_t * dentryOps
dentry_t * root
Root dentry of the filesystem, should not take a reference.
Thread of execution structure.
The primitive that threads block on.