PatchworkOS
Loading...
Searching...
No Matches
vfs.h
Go to the documentation of this file.
1#pragma once
2
3#include <kernel/fs/dentry.h>
4#include <kernel/fs/file.h>
5#include <kernel/fs/inode.h>
6#include <kernel/fs/mount.h>
7#include <kernel/fs/path.h>
9#include <kernel/fs/sysfs.h>
10#include <kernel/proc/process.h>
11#include <kernel/sync/rwlock.h>
12#include <kernel/utils/map.h>
13
14#include <sys/io.h>
15#include <sys/list.h>
16#include <sys/math.h>
17#include <sys/proc.h>
18
19typedef struct filesystem filesystem_t;
20
34#define VFS_ROOT_ENTRY_NAME "__root__"
35
39#define VFS_DEVICE_NAME_NONE "__no_device__"
40
44typedef struct filesystem
45{
47 const char* name;
48 dentry_t* (*mount)(filesystem_t* fs, const char* devName, void* private);
50
54typedef struct
55{
59
63typedef struct
64{
67} vfs_map_t;
68
72void vfs_init(void);
73
79
88
97
105filesystem_t* vfs_get_fs(const char* name);
106
120
133dentry_t* vfs_get_dentry(const dentry_t* parent, const char* name);
134
143dentry_t* vfs_get_or_lookup_dentry(const path_t* parent, const char* name);
144
154
164
170void vfs_remove_superblock(superblock_t* superblock);
171
177void vfs_remove_inode(inode_t* inode);
178
184void vfs_remove_dentry(dentry_t* dentry);
185
195uint64_t vfs_walk(path_t* outPath, const pathname_t* pathname, walk_flags_t flags, process_t* process);
196
207uint64_t vfs_walk_parent(path_t* outPath, const pathname_t* pathname, char* outLastName, walk_flags_t flags,
208 process_t* process);
209
220uint64_t vfs_walk_parent_and_child(path_t* outParent, path_t* outChild, const pathname_t* pathname, walk_flags_t flags,
221 process_t* process);
222
232bool vfs_is_name_valid(const char* name);
233
241file_t* vfs_open(const pathname_t* pathname, process_t* process);
242
253uint64_t vfs_open2(const pathname_t* pathname, file_t* files[2], process_t* process);
254
266
278
290
300uint64_t vfs_ioctl(file_t* file, uint64_t request, void* argp, uint64_t size);
301
311void* vfs_mmap(file_t* file, void* address, uint64_t length, pml_flags_t flags);
312
322
332
341uint64_t vfs_stat(const pathname_t* pathname, stat_t* buffer, process_t* process);
342
351uint64_t vfs_link(const pathname_t* oldPathname, const pathname_t* newPathname, process_t* process);
352
360uint64_t vfs_remove(const pathname_t* pathname, process_t* process);
361
372#define BUFFER_READ(buffer, count, offset, src, size) \
373 ({ \
374 uint64_t readCount = (*(offset) <= (size)) ? MIN((count), (size) - *(offset)) : 0; \
375 memcpy((buffer), (src) + *(offset), readCount); \
376 *(offset) += readCount; \
377 readCount; \
378 })
379
walk_flags_t
Flags for walking a path.
Definition path.h:100
uint64_t vfs_ioctl(file_t *file, uint64_t request, void *argp, uint64_t size)
Perform an ioctl operation on a file.
Definition vfs.c:839
uint64_t vfs_register_fs(filesystem_t *fs)
Registers a filesystem.
Definition vfs.c:102
uint64_t vfs_unregister_fs(filesystem_t *fs)
Unregisters a filesystem.
Definition vfs.c:127
uint64_t vfs_get_new_id(void)
Generates a new unique ID.
Definition vfs.c:97
uint64_t vfs_seek(file_t *file, int64_t offset, seek_origin_t origin)
Seek in a file.
Definition vfs.c:807
void * vfs_mmap(file_t *file, void *address, uint64_t length, pml_flags_t flags)
Memory map a file.
Definition vfs.c:889
void vfs_remove_inode(inode_t *inode)
Remove an inode from the inode cache.
Definition vfs.c:312
bool vfs_is_name_valid(const char *name)
Check if a name is valid.
Definition vfs.c:401
uint64_t vfs_walk_parent_and_child(path_t *outParent, path_t *outChild, const pathname_t *pathname, walk_flags_t flags, process_t *process)
Walk a pathname to path and its parent path, starting from the current process's working directory.
Definition vfs.c:378
filesystem_t * vfs_get_fs(const char *name)
Gets a filesystem by name.
Definition vfs.c:152
uint64_t vfs_poll(poll_file_t *files, uint64_t amount, clock_t timeout)
Poll multiple files.
Definition vfs.c:1021
uint64_t vfs_getdents(file_t *file, dirent_t *buffer, uint64_t count)
Get directory entries from a directory file.
Definition vfs.c:1166
void vfs_remove_dentry(dentry_t *dentry)
Remove a dentry from the dentry cache.
Definition vfs.c:324
uint64_t vfs_write(file_t *file, const void *buffer, uint64_t count)
Write to a file.
Definition vfs.c:748
file_t * vfs_open(const pathname_t *pathname, process_t *process)
Open a file.
Definition vfs.c:531
uint64_t vfs_add_dentry(dentry_t *dentry)
Add a dentry to the dentry cache.
Definition vfs.c:288
dentry_t * vfs_get_or_lookup_dentry(const path_t *parent, const char *name)
Get or lookup a dentry for the given name. Will NOT traverse mountpoints.
Definition vfs.c:227
uint64_t vfs_remove(const pathname_t *pathname, process_t *process)
Remove a file or directory.
Definition vfs.c:1377
dentry_t * vfs_get_dentry(const dentry_t *parent, const char *name)
Get a dentry for the given name. Will NOT traverse mountpoints.
Definition vfs.c:215
uint64_t vfs_stat(const pathname_t *pathname, stat_t *buffer, process_t *process)
Get file information.
Definition vfs.c:1222
uint64_t vfs_walk_parent(path_t *outPath, const pathname_t *pathname, char *outLastName, walk_flags_t flags, process_t *process)
Walk a pathname to its parent path, starting from the current process's working directory.
Definition vfs.c:359
void vfs_remove_superblock(superblock_t *superblock)
Remove a superblock from the superblock list.
Definition vfs.c:301
uint64_t vfs_read(file_t *file, void *buffer, uint64_t count)
Read from a file.
Definition vfs.c:694
uint64_t vfs_walk(path_t *outPath, const pathname_t *pathname, walk_flags_t flags, process_t *process)
Walk a pathname to a path, starting from the current process's working directory.
Definition vfs.c:341
void vfs_init(void)
Initializes the VFS.
Definition vfs.c:83
uint64_t vfs_link(const pathname_t *oldPathname, const pathname_t *newPathname, process_t *process)
Make the same file appear twice in the filesystem.
Definition vfs.c:1281
uint64_t vfs_open2(const pathname_t *pathname, file_t *files[2], process_t *process)
Open one file, returning two file handles.
Definition vfs.c:593
inode_t * vfs_get_inode(superblock_t *superblock, inode_number_t number)
Get an inode for the given superblock and inode number.
Definition vfs.c:168
uint64_t vfs_add_inode(inode_t *inode)
Add a inode to the inode cache.
Definition vfs.c:275
uint64_t inode_number_t
Inode number enum.
Definition io.h:353
uint8_t seek_origin_t
Type for the seek() origin argument.
Definition io.h:262
__UINT64_TYPE__ clock_t
A nanosecond time.
Definition clock_t.h:13
static uintptr_t address
Definition hpet.c:12
static list_t files
Definition file.c:9
static dentry_t * file
Definition log_file.c:17
EFI_PHYSICAL_ADDRESS buffer
Definition mem.c:15
static atomic_long count
Definition main.c:9
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__INT64_TYPE__ int64_t
Definition stdint.h:16
Directory entry structure.
Definition dentry.h:83
Directory entry struct.
Definition io.h:424
File structure.
Definition file.h:37
Filesystem structure, represents a filesystem type, e.g. fat32, ramfs, sysfs, etc.
Definition vfs.h:45
list_entry_t entry
Definition vfs.h:46
const char * name
Definition vfs.h:47
Inode structure.
Definition inode.h:54
A entry in a doubly linked list.
Definition list.h:38
A doubly linked list.
Definition list.h:51
Hash map structure.
Definition map.h:76
Path structure.
Definition path.h:110
Pathname structure.
Definition path.h:122
A entry in a page table without a specified address or callback ID.
Structure for polling multiple files.
Definition file.h:74
Process structure.
Definition process.h:53
Read-Write Ticket Lock structure.
Definition rwlock.h:59
Stat type.
Definition io.h:360
Superblock structure.
Definition superblock.h:44
Helper structure for lists with a lock.
Definition vfs.h:55
list_t list
Definition vfs.h:56
rwlock_t lock
Definition vfs.h:57
Helper structure for maps with a lock.
Definition vfs.h:64
map_t map
Definition vfs.h:65
rwlock_t lock
Definition vfs.h:66