|
PatchworkOS
|
#include <kernel/fs/sysfs.h>#include <kernel/fs/dentry.h>#include <kernel/fs/namespace.h>#include <kernel/fs/vfs.h>#include <kernel/log/log.h>#include <kernel/log/panic.h>#include <kernel/sync/lock.h>#include <assert.h>#include <errno.h>#include <stdatomic.h>#include <sys/list.h>Go to the source code of this file.
Data Structures | |
| struct | sysfs_mount_ctx_t |
Functions | |
| static | _Atomic (inode_number_t) |
| static dentry_t * | sysfs_mount (filesystem_t *fs, const char *devName, void *private) |
| void | sysfs_init (void) |
| Initializes the SysFS. | |
| dentry_t * | sysfs_get_dev (void) |
| Gets the default SysFS directory. | |
| 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. | |
| 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. | |
| 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. | |
Variables | |
| static dentry_ops_t | dentryOps |
| static filesystem_t | sysfs |
|
staticnew |
| 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.
| parent | The parent directory, if NULL then sysfs_get_dev() is used. |
| name | The name of the new directory. |
| inodeOps | The inode operations for the new directory, can be NULL. |
| private | Private data associated with the new directory, can be NULL, will be stored in the inode. |
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().
| 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.
| parent | The parent directory, if NULL then sysfs_get_dev() is used. |
| name | The name of the new file. |
| inodeOps | The inode operations for the new file, can be NULL. |
| fileOps | The file operations for the new file, can be NULL. |
| private | Private data associated with the new file, can be NULL. |
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().
| 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.
/dev SysFS directory. Definition at line 95 of file sysfs.c.
References REF, and mount_t::root.
| 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().
|
static |
Definition at line 32 of file sysfs.c.
References atomic_fetch_add, dentry_make_positive(), dentry_new(), dentryOps, DEREF_DEFER, ERR, INODE_DIR, inode_new(), NULL, REF, superblock_t::root, superblock_new(), sysfs_mount_ctx_t::superblockOps, superblockOps, VFS_DEVICE_NAME_NONE, and VFS_ROOT_ENTRY_NAME.
| 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.
| parent | The parent directory to mount the SysFS in. If NULL, the root of the namespace is used. |
| name | The name of the directory to mount the SysFS in. |
| ns | The namespace to mount the SysFS in. If NULL, the kernel process's namespace is used. |
| superblockOps | The superblock operations for the new SysFS instance, can be NULL. |
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().
|
static |
Definition at line 23 of file sysfs.c.
Referenced by sysfs_mount().
|
static |
Definition at line 74 of file sysfs.c.
Referenced by sysfs_dir_new(), sysfs_file_new(), sysfs_init(), and sysfs_mount_new().