PatchworkOS
Loading...
Searching...
No Matches
sysfs.h File Reference
#include <kernel/fs/dentry.h>
#include <kernel/fs/inode.h>

Go to the source code of this file.

Macros

#define SYSFS_NAME   "sysfs"
 

Typedefs

typedef struct file file_t
 
typedef struct file_ops file_ops_t
 
typedef struct superblock superblock_t
 
typedef struct superblock_ops superblock_ops_t
 

Functions

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, 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.
 

Macro Definition Documentation

◆ SYSFS_NAME

#define SYSFS_NAME   "sysfs"

Definition at line 22 of file sysfs.h.

Typedef Documentation

◆ file_ops_t

typedef struct file_ops file_ops_t

Definition at line 7 of file sysfs.h.

◆ file_t

typedef struct file file_t

Definition at line 6 of file sysfs.h.

◆ superblock_ops_t

typedef struct superblock_ops superblock_ops_t

Definition at line 10 of file sysfs.h.

◆ superblock_t

typedef struct superblock superblock_t

Definition at line 9 of file sysfs.h.

Function Documentation

◆ 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 174 of file sysfs.c.

References atomic_fetch_add, dentry_make_positive(), dentry_new(), DEREF_DEFER, EINVAL, ERR, errno, EXDEV, superblock_t::fs, INODE_DIR, inode_new(), inodeOps, NULL, inode_t::private, REF, mount_t::root, dentry_t::superblock, and sysfs.

Referenced by acpi_tables_expose(), fb_new(), kbd_new(), local_listen_dir_init(), mouse_new(), pipe_init(), process_dir_init(), process_procfs_init(), shmem_init(), socket_family_register(), and statistics_init().

◆ 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.

References atomic_fetch_add, dentry_make_positive(), dentry_new(), DEREF_DEFER, EINVAL, ERR, errno, EXDEV, file, fileOps, superblock_t::fs, INODE_FILE, inode_new(), inodeOps, NULL, inode_t::private, REF, mount_t::root, dentry_t::superblock, and sysfs.

Referenced by acpi_tables_expose(), const_init(), fb_new(), kbd_new(), local_listen_new(), log_file_expose(), mouse_new(), pipe_init(), process_dir_init(), shmem_init(), socket_family_register(), socket_new(), and statistics_init().

◆ 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 95 of file sysfs.c.

References REF, and mount_t::root.

◆ sysfs_init()

void sysfs_init ( void  )

Initializes the SysFS.

Definition at line 79 of file sysfs.c.

References ERR, LOG_INFO, NULL, panic(), sysfs, sysfs_mount_new(), and vfs_register_fs().

Referenced by init_finalize().

◆ sysfs_mount_new()

mount_t * sysfs_mount_new ( const path_t parent,
const char *  name,
namespace_t ns,
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. If NULL, the kernel process's namespace is used.
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 100 of file sysfs.c.

References assert, atomic_fetch_add, path_t::dentry, dentry_make_positive(), dentry_new(), DEREF_DEFER, EINVAL, ERR, errno, EXDEV, superblock_t::fs, INODE_DIR, inode_new(), kernelProcess, path_t::mount, mount, namespace_mount(), NULL, PATH_CREATE, PATH_DEFER, PATH_EMPTY, path_put(), path_set(), process_get_kernel(), mount_t::root, namespace_t::rootMount, dentry_t::superblock, sysfs_mount_ctx_t::superblockOps, superblockOps, sysfs, SYSFS_NAME, VFS_DEVICE_NAME_NONE, and vfs_get_or_lookup_dentry().

Referenced by acpi_get_sysfs_root(), net_init(), process_procfs_init(), socket_new(), and sysfs_init().