PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
filesystem.c
Go to the documentation of this file.
2
4#include <kernel/fs/cwd.h>
5#include <kernel/fs/dentry.h>
7#include <kernel/fs/inode.h>
8#include <kernel/fs/key.h>
9#include <kernel/fs/mount.h>
10#include <kernel/fs/path.h>
11#include <kernel/fs/sysfs.h>
12#include <kernel/log/log.h>
13#include <kernel/log/panic.h>
14#include <kernel/mem/vmm.h>
15#include <kernel/proc/process.h>
16#include <kernel/sched/sched.h>
17#include <kernel/sched/clock.h>
18#include <kernel/sched/timer.h>
19#include <kernel/sched/wait.h>
20#include <kernel/sync/mutex.h>
21#include <kernel/sync/rwlock.h>
22#include <kernel/utils/ref.h>
23
24#include <kernel/cpu/regs.h>
25
26#include <errno.h>
27#include <stdint.h>
28#include <string.h>
29#include <sys/io.h>
30#include <sys/list.h>
31
34
35static map_key_t filesystem_key(const char* name)
36{
37 return map_key_string(name);
38}
39
41{
42 if (fs == NULL || strnlen_s(fs->name, MAX_NAME) > MAX_NAME)
43 {
44 errno = EINVAL;
45 return ERR;
46 }
47
50 rwlock_init(&fs->lock);
51
52 map_key_t key = filesystem_key(fs->name);
53
55
56 if (map_insert(&filesystems, &key, &fs->mapEntry) == ERR)
57 {
58 return ERR;
59 }
60
61 return 0;
62}
63
65{
66 if (fs == NULL)
67 {
68 return;
69 }
70
73
74 while (!list_is_empty(&fs->superblocks))
75 {
77 }
78}
79
80filesystem_t* filesystem_get(const char* name)
81{
83
84 map_key_t key = filesystem_key(name);
85 return CONTAINER_OF_SAFE(map_get(&filesystems, &key), filesystem_t, mapEntry);
86}
#define MAX_NAME
Maximum length of names.
Definition MAX_NAME.h:11
static rwlock_t filesystemsLock
Definition filesystem.c:33
static map_t filesystems
Definition filesystem.c:32
static map_key_t filesystem_key(const char *name)
Definition filesystem.c:35
filesystem_t * filesystem_get(const char *name)
Gets a filesystem by name.
Definition filesystem.c:80
uint64_t filesystem_register(filesystem_t *fs)
Registers a filesystem.
Definition filesystem.c:40
void filesystem_unregister(filesystem_t *fs)
Unregisters a filesystem.
Definition filesystem.c:64
#define RWLOCK_READ_SCOPE(lock)
Acquires a rwlock for reading for the reminder of the current scope.
Definition rwlock.h:29
void rwlock_init(rwlock_t *lock)
Initializes a rwlock.
Definition rwlock.c:8
#define RWLOCK_CREATE()
Create a rwlock initializer.
Definition rwlock.h:47
#define RWLOCK_WRITE_SCOPE(lock)
Acquires a rwlock for writing for the reminder of the current scope.
Definition rwlock.h:38
void map_entry_init(map_entry_t *entry)
Initialize a map entry.
Definition map.c:71
uint64_t map_insert(map_t *map, const map_key_t *key, map_entry_t *value)
Insert a key-value pair into the map.
Definition map.c:204
void map_remove(map_t *map, map_entry_t *entry)
Remove a entry from the map.
Definition map.c:353
map_entry_t * map_get(map_t *map, const map_key_t *key)
Get a value from the map by key.
Definition map.c:287
static map_key_t map_key_string(const char *str)
Create a map key from a string.
Definition map.h:143
#define MAP_CREATE()
Create a map initializer.
Definition map.h:160
#define EINVAL
Invalid argument.
Definition errno.h:142
#define errno
Error number variable.
Definition errno.h:27
static list_entry_t * list_pop_first(list_t *list)
Pops the first entry from the list.
Definition list.h:375
static bool list_is_empty(list_t *list)
Checks if a list is empty.
Definition list.h:227
static void list_init(list_t *list)
Initializes a list.
Definition list.h:196
#define NULL
Pointer error value.
Definition NULL.h:23
#define ERR
Integer error value.
Definition ERR.h:17
#define CONTAINER_OF_SAFE(ptr, type, member)
Safe container of macro.
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
size_t strnlen_s(const char *s, size_t maxsize)
Definition strnlen_s.c:4
Filesystem structure, represents a filesystem type, e.g. fat32, ramfs, sysfs, etc.
Definition filesystem.h:31
const char * name
Definition filesystem.h:35
map_entry_t mapEntry
Used internally.
Definition filesystem.h:32
rwlock_t lock
Used internally.
Definition filesystem.h:34
list_t superblocks
Used internally.
Definition filesystem.h:33
Map key stucture.
Definition map.h:56
Hash map structure.
Definition map.h:89
Read-Write Ticket Lock structure.
Definition rwlock.h:61