PatchworkOS  10941b4
A non-POSIX operating system.
Loading...
Searching...
No Matches
devfs.h
Go to the documentation of this file.
1#pragma once
2
3#include <kernel/fs/dentry.h>
4#include <kernel/fs/inode.h>
5#include <sys/io.h>
6
7typedef struct file file_t;
8typedef struct file_ops file_ops_t;
9
10typedef struct superblock superblock_t;
11typedef struct superblock_ops superblock_ops_t;
12
13/**
14 * @brief Device Filesystem.
15 * @ingroup kernel_fs
16 * @defgroup kernel_fs_devfs Device Filesystem
17 *
18 * The devfs is a virtual filesystem that provides access to devices and resources.
19 *
20 * @{
21 */
22
23/**
24 * @brief The name of the device filesystem.
25 */
26#define DEVFS_NAME "devfs"
27
28/**
29 * @brief Initializes the devfs.
30 */
31void devfs_init(void);
32
33/**
34 * @brief Create a new directory inside a mounted devfs instance.
35 *
36 * @param parent The parent directory, if `NULL` then the root is used.
37 * @param name The name of the new directory.
38 * @param inodeOps The inode operations for the new directory, can be `NULL`.
39 * @param private Private data to store in the inode of the new directory, can be `NULL`.
40 * @return On success, the new devfs directory. On failure, `NULL` and `errno` is set.
41 */
42dentry_t* devfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* private);
43
44/**
45 * @brief Create a new file inside a mounted devfs instance.
46 *
47 * @param parent The parent directory, if `NULL` then the root is used.
48 * @param name The name of the new file.
49 * @param inodeOps The inode operations for the new file, can be `NULL`.
50 * @param fileOps The file operations for the new file, can be `NULL`.
51 * @param private Private data to store in the inode of the new file, can be `NULL`.
52 * @return On success, the new devfs file. On failure, `NULL` and `errno` is set.
53 */
54dentry_t* devfs_file_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, const file_ops_t* fileOps,
55 void* private);
56
57/**
58 * @brief Create a new symbolic link inside a mounted devfs instance.
59 *
60 * @param parent The parent directory, if `NULL` then the root is used.
61 * @param name The name of the new symbolic link.
62 * @param inodeOps The inode operations for the new symbolic link.
63 * @param private Private data to store in the inode of the new symbolic link, can be `NULL`.
64 * @return On success, the new devfs symbolic link. On failure, `NULL` and `errno` is set.
65 */
66dentry_t* devfs_symlink_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* private);
67
68/**
69 * @brief Descriptor for batch file creation.
70 * @struct devfs_file_desc_t
71 */
72typedef struct devfs_file_desc
73{
74 const char* name; ///< Name of the file, `NULL` marks end of array.
75 const inode_ops_t* inodeOps; ///< Inode operations, can be `NULL`.
76 const file_ops_t* fileOps; ///< File operations, can be `NULL`.
77 void* private; ///< Private data to store in the inode of the file.
79
80/**
81 * @brief Create multiple files in a devfs directory.
82 *
83 * @param out Output list to store created dentries, can be `NULL`. The dentries use the `otherEntry` list entry.
84 * @param parent The parent directory, if `NULL` then the root is used.
85 * @param descs Array of file descriptors, terminated by an entry with `name == NULL`.
86 * @return On success, the number of files created. On failure, `ERR` and `errno` is set.
87 */
88uint64_t devfs_files_new(list_t* out, dentry_t* parent, const devfs_file_desc_t* descs);
89
90/**
91 * @brief Free all files in a list created by `devfs_files_new()`.
92 *
93 * @param files The list of files to free.
94 */
96
97/** @} */
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.
Definition devfs.c:81
uint64_t devfs_files_new(list_t *out, dentry_t *parent, const devfs_file_desc_t *descs)
Create multiple files in a devfs directory.
Definition devfs.c:194
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.
Definition devfs.c:160
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.
Definition devfs.c:120
void devfs_init(void)
Initializes the devfs.
Definition devfs.c:49
void devfs_files_free(list_t *files)
Free all files in a list created by devfs_files_new().
Definition devfs.c:249
static list_t files
Definition file.c:9
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Directory entry structure.
Definition dentry.h:153
Descriptor for batch file creation.
Definition devfs.h:73
const file_ops_t * fileOps
File operations, can be NULL.
Definition devfs.h:76
const inode_ops_t * inodeOps
Inode operations, can be NULL.
Definition devfs.h:75
const char * name
Name of the file, NULL marks end of array.
Definition devfs.h:74
File operations structure.
Definition file.h:54
File structure.
Definition file.h:39
Inode operations structure.
Definition inode.h:74
A doubly linked list.
Definition list.h:47
Superblock operations structure.
Definition superblock.h:75
Superblock structure.
Definition superblock.h:49
static inode_ops_t inodeOps
Definition tmpfs.c:195
static file_ops_t fileOps
Definition tmpfs.c:86