51 int length =
snprintf(info,
sizeof(info),
"id: %llu\nblock_size: %llu\nmax_file_size: %llu\n", sb->
id,
221 LOG_ERR(
"filesystem already exposed\n");
228 panic(
NULL,
"failed to expose filesystem sysfs directory");
286 if (path ==
NULL || process ==
NULL)
329 while (*iter !=
NULL && **iter !=
'\0')
331 const char*
start = *iter;
335 *iter = end !=
NULL ? end + 1 :
NULL;
350 *value =
strchr(*key,
'=');
#define MAX_NAME
Maximum length of names.
#define MAX_PATH
Maximum length of filepaths.
#define assert(expression)
EFI_PHYSICAL_ADDRESS buffer
static list_t filesystems
static file_ops_t sbFileOps
static size_t superblock_read(file_t *file, void *buffer, size_t count, size_t *offset)
static uint64_t filesystem_iterate(dentry_t *dentry, dir_ctx_t *ctx)
static uint64_t filesystem_dir_lookup(vnode_t *dir, dentry_t *dentry)
static vnode_ops_t sbVnodeOps
static void superblock_cleanup(vnode_t *vnode)
static map_key_t filesystem_key(const char *name)
static dentry_ops_t dirDentryOps
static uint64_t filesystem_dir_iterate(dentry_t *dentry, dir_ctx_t *ctx)
static vnode_ops_t fsVnodeOps
static dentry_ops_t fsDentryOps
static vnode_ops_t dirVnodeOps
static uint64_t filesystem_lookup(vnode_t *dir, dentry_t *dentry)
path_t cwd_get(cwd_t *cwd, namespace_t *ns)
Get the current working directory.
void dentry_make_positive(dentry_t *dentry, vnode_t *vnode)
Make a dentry positive by associating it with an vnode.
bool dentry_iterate_dots(dentry_t *dentry, dir_ctx_t *ctx)
Helper function to iterate over the special entries "." and "..".
#define DENTRY_IS_POSITIVE(dentry)
Check if a dentry is positive.
void filesystem_expose(void)
Exposes the sysfs fs directory.
filesystem_t * filesystem_get_by_path(const char *path, process_t *process)
Gets a filesystem by path.
uint64_t filesystem_register(filesystem_t *fs)
Registers a filesystem.
bool options_next(const char **iter, char *buffer, size_t size, char **key, char **value)
Helper function for iterating over options passed to a filesystem mount operation.
filesystem_t * filesystem_get_by_name(const char *name)
Gets a filesystem by name.
void filesystem_unregister(filesystem_t *fs)
Unregisters a filesystem.
#define PATH_DEFER(path)
Defer path put.
uint64_t path_walk(path_t *path, const pathname_t *pathname, namespace_t *ns)
Walk a pathname to a path.
uint64_t pathname_init(pathname_t *pathname, const char *string)
Initialize a pathname.
dentry_t * sysfs_dir_new(dentry_t *parent, const char *name, const vnode_ops_t *vnodeOps, void *data)
Create a new directory inside a mounted sysfs instance.
vnode_t * vnode_new(superblock_t *superblock, vtype_t type, const vnode_ops_t *ops, const file_ops_t *fileOps)
Create a new vnode.
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
#define LOG_ERR(format,...)
namespace_t * process_get_ns(process_t *process)
Gets the namespace of a process.
static void rwlock_init(rwlock_t *lock)
Initializes a rwlock.
#define RWLOCK_READ_SCOPE(lock)
Acquires a rwlock for reading for the reminder of the current scope.
#define RWLOCK_CREATE()
Create a rwlock initializer.
#define RWLOCK_WRITE_SCOPE(lock)
Acquires a rwlock for writing for the reminder of the current scope.
void map_entry_init(map_entry_t *entry)
Initialize a map entry.
uint64_t map_insert(map_t *map, const map_key_t *key, map_entry_t *value)
Insert a key-value pair into the map.
void map_remove(map_t *map, map_entry_t *entry)
Remove a entry from the map.
map_entry_t * map_get(map_t *map, const map_key_t *key)
Get a value from the map by key.
static map_key_t map_key_string(const char *str)
Create a map key from a string.
#define MAP_CREATE()
Create a map initializer.
#define UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
#define REF(ptr)
Increment reference count.
#define UNREF(ptr)
Decrement reference count.
#define BUFFER_READ(buffer, count, offset, src, size)
Helper macros for implementing file operations dealing with simple buffers.
#define ENOENT
No such file or directory.
#define EINVAL
Invalid argument.
#define errno
Error number variable.
#define UNUSED(x)
Mark a variable as unused.
uint64_t sbid_t
A suberblock identifier that uniquely identifies a superblock within the system.
#define LIST_FOR_EACH(elem, list, member)
Iterates over a list.
static void list_remove(list_entry_t *entry)
Removes a list entry from its current list.
static void list_push_back(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list.
#define LIST_CREATE(name)
Creates a list initializer.
static bool list_is_empty(list_t *list)
Checks if a list is empty.
static void list_entry_init(list_entry_t *entry)
Initializes a list entry.
static list_entry_t * list_pop_front(list_t *list)
Pops the first entry from the list.
static void list_init(list_t *list)
Initializes a list.
#define NULL
Pointer error value.
#define ERR
Integer error value.
#define CONTAINER_OF_SAFE(ptr, type, member)
Safe container of macro.
_PUBLIC int sscanf(const char *_RESTRICT s, const char *_RESTRICT format,...)
_PUBLIC int snprintf(char *_RESTRICT s, size_t n, const char *_RESTRICT format,...)
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
_PUBLIC size_t strlen(const char *s)
_PUBLIC char * strchr(const char *s, int c)
size_t strnlen_s(const char *s, size_t maxsize)
Dentry operations structure.
uint64_t(* iterate)(dentry_t *dentry, dir_ctx_t *ctx)
Iterate over the entries in a directory dentry.
Directory entry structure.
char name[MAX_NAME]
The name of the dentry, immutable after creation.
vnode_t * vnode
Will be NULL if the dentry is negative, once positive it will never be modified.
superblock_t * superblock
Directory context used to iterate over directory entries.
size_t index
An index that the filesystem can use for its own purposes.
size_t pos
The current position in the directory, can be used to skip entries.
bool(* emit)(dir_ctx_t *ctx, const char *name, vtype_t type)
Emit function.
File operations structure.
size_t(* read)(file_t *file, void *buffer, size_t count, size_t *offset)
Filesystem structure, represents a filesystem type, e.g. fat32, tmpfs, devfs, etc.
list_entry_t entry
Used internally.
map_entry_t mapEntry
Used internally.
rwlock_t lock
Used internally.
list_t superblocks
Used internally.
Read-Write Ticket Lock structure.
vnode operations structure.
void(* cleanup)(vnode_t *vnode)
Cleanup function called when the vnode is being freed.
uint64_t(* lookup)(vnode_t *dir, dentry_t *target)
Look up a dentry in a directory vnode.
void * data
Filesystem defined data.