PatchworkOS  621ae6b
A non-POSIX operating system.
Loading...
Searching...
No Matches
devfs.c File Reference
#include <kernel/fs/devfs.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 <stdlib.h>
#include <string.h>
#include <sys/io.h>
#include <sys/list.h>
Include dependency graph for devfs.c:

Go to the source code of this file.

Functions

static dentry_tdevfs_mount (filesystem_t *fs, block_device_t *device, void *private)
 
void devfs_init (void)
 Initializes the devfs.
 
dentry_tdevfs_dir_new (dentry_t *parent, const char *name, const inode_ops_t *inodeOps, void *private)
 Create a new directory inside a mounted devfs instance.
 
dentry_tdevfs_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 devfs instance.
 
dentry_tdevfs_symlink_new (dentry_t *parent, const char *name, const inode_ops_t *inodeOps, void *private)
 Create a new symbolic link inside a mounted devfs instance.
 
uint64_t devfs_files_new (list_t *out, dentry_t *parent, const devfs_file_desc_t *descs)
 Create multiple files in a devfs directory.
 
void devfs_files_free (list_t *files)
 Free all files in a list created by devfs_files_new().
 

Variables

static dentry_troot = NULL
 
static file_ops_t dirOps
 
static dentry_ops_t dentryOps
 
static filesystem_t devfs
 

Function Documentation

◆ devfs_mount()

static dentry_t * devfs_mount ( filesystem_t fs,
block_device_t device,
void private 
)
static

Definition at line 35 of file devfs.c.

◆ devfs_init()

void devfs_init ( void  )

Initializes the devfs.

Definition at line 49 of file devfs.c.

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

◆ devfs_dir_new()

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

Create a new directory inside a mounted devfs 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 the root is used.
nameThe name of the new directory.
inodeOpsThe inode operations for the new directory, can be NULL.
privatePrivate data to store in the inode of the new directory, can be NULL.
Returns
On success, the new devfs directory. On failure, NULL and errno is set.

Definition at line 81 of file devfs.c.

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

◆ devfs_file_new()

dentry_t * devfs_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 devfs 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 the root 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 to store in the inode of the new file, can be NULL.
Returns
On success, the new devfs file. On failure, NULL and errno is set.

Definition at line 120 of file devfs.c.

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

◆ devfs_symlink_new()

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

Create a new symbolic link inside a mounted devfs instance.

Parameters
parentThe parent directory, if NULL then the root is used.
nameThe name of the new symbolic link.
inodeOpsThe inode operations for the new symbolic link.
privatePrivate data to store in the inode of the new symbolic link, can be NULL.
Returns
On success, the new devfs symbolic link. On failure, NULL and errno is set.

Definition at line 160 of file devfs.c.

Here is the call graph for this function:

◆ devfs_files_new()

uint64_t devfs_files_new ( list_t out,
dentry_t parent,
const devfs_file_desc_t descs 
)

Create multiple files in a devfs directory.

Parameters
outOutput list to store created dentries, can be NULL. The dentries use the otherEntry list entry.
parentThe parent directory, if NULL then the root is used.
descsArray of file descriptors, terminated by an entry with name == NULL.
Returns
On success, the number of files created. On failure, ERR and errno is set.

Definition at line 194 of file devfs.c.

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

◆ devfs_files_free()

void devfs_files_free ( list_t files)

Free all files in a list created by devfs_files_new().

Parameters
filesThe list of files to free.

Definition at line 249 of file devfs.c.

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

Variable Documentation

◆ root

dentry_t* root = NULL
static

Definition at line 25 of file devfs.c.

◆ dirOps

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

Definition at line 27 of file devfs.c.

◆ dentryOps

dentry_ops_t dentryOps
static
Initial value:
= {
}
uint64_t dentry_generic_iterate(dentry_t *dentry, dir_ctx_t *ctx)
Helper function for a basic iterate.
Definition dentry.c:313

Definition at line 31 of file devfs.c.

◆ devfs

filesystem_t devfs
static
Initial value:
= {
.name = DEVFS_NAME,
.mount = devfs_mount,
}
static dentry_t * devfs_mount(filesystem_t *fs, block_device_t *device, void *private)
Definition devfs.c:35
#define DEVFS_NAME
The name of the device filesystem.
Definition devfs.h:23

Definition at line 44 of file devfs.c.