PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
sysfs.c File Reference
#include <kernel/fs/sysfs.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/sync/lock.h>
#include <assert.h>
#include <errno.h>
#include <stdatomic.h>
#include <sys/io.h>
#include <sys/list.h>
Include dependency graph for sysfs.c:

Go to the source code of this file.

Data Structures

struct  sysfs_mount_ctx_t
 

Functions

static dentry_tsysfs_mount (filesystem_t *fs, const char *devName, void *private)
 
void sysfs_init (void)
 Initializes the SysFS.
 
dentry_tsysfs_get_dev (void)
 Gets the default SysFS directory.
 
mount_tsysfs_mount_new (const path_t *parent, const char *name, namespace_t *ns, mount_flags_t flags, mode_t mode, const superblock_ops_t *superblockOps)
 Mount a new instance of SysFS.
 
dentry_tsysfs_dir_new (dentry_t *parent, const char *name, const inode_ops_t *inodeOps, void *private)
 Create a new directory inside a mounted SysFS instance.
 
dentry_tsysfs_file_new (dentry_t *parent, const char *name, const inode_ops_t *inodeOps, const file_ops_t *fileOps, void *private)
 Create a new file inside a mounted SysFS instance.
 

Variables

static mount_tdevMount = NULL
 
static file_ops_t dirOps
 
static dentry_ops_t dentryOps
 
static filesystem_t sysfs
 

Function Documentation

◆ sysfs_mount()

static dentry_t * sysfs_mount ( filesystem_t fs,
const char *  devName,
void *  private 
)
static

Definition at line 38 of file sysfs.c.

Here is the call graph for this function:

◆ sysfs_init()

void sysfs_init ( void  )

Initializes the SysFS.

Definition at line 82 of file sysfs.c.

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

◆ sysfs_get_dev()

dentry_t * sysfs_get_dev ( void  )

Gets the default SysFS directory.

The default SysFS directory is the root of the /dev mount. The /dev directory is for devices or "other" resources which may not warrant an entire dedicated filesystem.

Returns
A reference to the /dev SysFS directory.

Definition at line 99 of file sysfs.c.

◆ sysfs_mount_new()

mount_t * sysfs_mount_new ( const path_t parent,
const char *  name,
namespace_t ns,
mount_flags_t  flags,
mode_t  mode,
const superblock_ops_t superblockOps 
)

Mount a new instance of SysFS.

Used to, for example, create /dev, /proc and directories whose contents should only be visible within a specific namespace.

If parent is NULL, then the sysfs instance will be mounted to a already existing directory in the root of the namespace. If it is not NULL, then it must point to a sysfs directory, a new directory of the name name will be created inside it and the SysFS instance will be mounted there.

Parameters
parentThe parent directory to mount the SysFS in. If NULL, the root of the namespace is used.
nameThe name of the directory to mount the SysFS in.
nsThe namespace to mount the SysFS in, or NULL to use the current process's namespace.
flagsMount flags.
modeThe maximum allowed permissions for files/directories opened under this mount.
superblockOpsThe superblock operations for the new SysFS instance, can be NULL.
Returns
On success, the mounted SysFS instance. On failure, NULL and errno is set.

Definition at line 104 of file sysfs.c.

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

◆ sysfs_dir_new()

dentry_t * sysfs_dir_new ( dentry_t parent,
const char *  name,
const inode_ops_t inodeOps,
void *  private 
)

Create a new directory inside a mounted SysFS instance.

Used to, for example, create a new directory for a device or resource inside /dev or /proc.

Parameters
parentThe parent directory, if NULL then sysfs_get_dev() is used.
nameThe name of the new directory.
inodeOpsThe inode operations for the new directory, can be NULL.
privatePrivate data associated with the new directory, can be NULL, will be stored in the inode.
Returns
On success, the new SysFS directory. On failure, NULL and errno is set.

Definition at line 177 of file sysfs.c.

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

◆ sysfs_file_new()

dentry_t * sysfs_file_new ( dentry_t parent,
const char *  name,
const inode_ops_t inodeOps,
const file_ops_t fileOps,
void *  private 
)

Create a new file inside a mounted SysFS instance.

Used to, for example, create a new file for a device or resource inside /dev or /proc.

Parameters
parentThe parent directory, if NULL then sysfs_get_dev() is used.
nameThe name of the new file.
inodeOpsThe inode operations for the new file, can be NULL.
fileOpsThe file operations for the new file, can be NULL.
privatePrivate data associated with the new file, can be NULL.
Returns
On success, the new SysFS file. On failure, NULL and errno is set.

Definition at line 216 of file sysfs.c.

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

Variable Documentation

◆ devMount

mount_t* devMount = NULL
static

Definition at line 23 of file sysfs.c.

◆ dirOps

file_ops_t dirOps
static
Initial value:
= {
}
uint64_t file_generic_seek(file_t *file, int64_t offset, seek_origin_t origin)
Helper function for basic seeking.
Definition file.c:92

Definition at line 25 of file sysfs.c.

◆ dentryOps

dentry_ops_t dentryOps
static
Initial value:
= {
}
uint64_t dentry_generic_getdents(dentry_t *dentry, dirent_t *buffer, uint64_t count, uint64_t *offset, mode_t mode)
Helper function for a basic getdents.
Definition dentry.c:345

Definition at line 29 of file sysfs.c.

◆ sysfs

filesystem_t sysfs
static
Initial value:
= {
.name = SYSFS_NAME,
.mount = sysfs_mount,
}
static dentry_t * sysfs_mount(filesystem_t *fs, const char *devName, void *private)
Definition sysfs.c:38
#define SYSFS_NAME
Definition sysfs.h:23

Definition at line 77 of file sysfs.c.