52 size_t len =
strlen(parentString);
53 while (len > 1 && parentString[len - 1] ==
'/')
55 parentString[--len] =
'\0';
58 char* lastSlash =
strrchr(parentString,
'/');
59 if (lastSlash ==
NULL)
64 if (lastSlash == parentString)
66 parentString[1] =
'\0';
158 if (pathname ==
NULL || process ==
NULL)
225 if (pathname ==
NULL || process ==
NULL)
394 return file->
ops->
ioctl(file, request, argp, size);
440 for (
uint64_t i = 0; i < amount; i++)
453 if (ctx->
queues[j] == queue)
474 size_t readyCount = 0;
476 for (
uint64_t i = 0; i < amount; i++)
511 for (
uint64_t i = 0; i < amount; i++)
541 size_t readyCount = 0;
553 if (readyCount ==
ERR)
559 if (readyCount > 0 ||
uptime >= deadline)
683 if (prefix[0] !=
'\0')
718 if (prefix[0] ==
'\0')
789 bool removed =
false;
993 if (oldPathname ==
NULL || newPathname ==
NULL || process ==
NULL)
1106 if (oldPathname ==
NULL || newPathname ==
NULL || process ==
NULL)
1162 if (pathname ==
NULL || process ==
NULL)
1291 if (fdsLocal[0] ==
ERR)
1296 if (fdsLocal[1] ==
ERR)
1321 if (fromFile ==
NULL)
1475 for (
uint64_t i = 0; i < amount; i++)
1499 for (
uint64_t i = 0; i < amount; i++)
1506 for (
uint64_t i = 0; i < amount; i++)
1572 return vfs_link(&oldPathname, &newPathname, process);
#define MAX_PATH
Maximum length of filepaths.
#define assert(expression)
EFI_PHYSICAL_ADDRESS buffer
#define CONFIG_MAX_FD
Maximum file descriptor configuration.
#define SYSCALL_DEFINE(num, returnType,...)
Macro to define a syscall.
static uintptr_t address
Mapped virtual address of the HPET registers.
path_t cwd_get(cwd_t *cwd, namespace_t *ns)
Get the current working directory.
#define DENTRY_IS_DIR(dentry)
Check if the vnode associated with a dentry is a directory.
#define DENTRY_IS_POSITIVE(dentry)
Check if a dentry is positive.
#define DENTRY_IS_ROOT(dentry)
Macro to check if a dentry is the root entry in its filesystem.
dentry_t * dentry_rcu_get(const dentry_t *parent, const char *name, size_t length)
Get a dentry from the dentry cache in an RCU read-side critical section without traversing mountpoint...
uint64_t file_table_close(file_table_t *table, fd_t fd)
Free a file descriptor.
file_t * file_table_get(file_table_t *table, fd_t fd)
Get a file from its file descriptor.
fd_t file_table_open(file_table_t *table, file_t *file)
Allocate a new file descriptor for a file.
file_t * file_new(const path_t *path, mode_t mode)
Create a new file structure.
bool namespace_rcu_traverse(namespace_t *ns, mount_t **mount, dentry_t **dentry)
If the given path is a mountpoint in the namespace, traverse to the mounted filesystem in an RCU read...
mode_t
Path flags and permissions.
void path_put(path_t *path)
Put a path.
uint64_t mode_to_string(mode_t mode, char *out, uint64_t length)
Convert a mode to a string representation.
#define PATH_CREATE(inMount, inDentry)
Helper to create a path.
#define PATH_DEFER(path)
Defer path put.
uint64_t path_step(path_t *path, mode_t mode, const char *name, namespace_t *ns)
Walk a single path component.
uint64_t path_walk_parent_and_child(const path_t *from, path_t *outParent, path_t *outChild, const pathname_t *pathname, namespace_t *ns)
Traverse a pathname to its parent and child paths.
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.
void path_copy(path_t *dest, const path_t *src)
Copy a path.
#define PATH_EMPTY
Helper to create an empty path.
void vnode_truncate(vnode_t *vnode)
Truncate the vnode.
void space_unpin(space_t *space, const void *address, size_t length)
Unpins pages in a region previously pinned with space_pin() or space_pin_string().
uint64_t space_pin(space_t *space, const void *address, size_t length, stack_pointer_t *userStack)
Pins pages within a region of the address space.
uint64_t space_check_access(space_t *space, const void *addr, size_t length)
Checks if a virtual memory region is within the allowed address range of the space.
pml_flags_t vmm_prot_to_flags(prot_t prot)
Converts the user space memory protection flags to page table entry flags.
static process_t * process_current(void)
Retrieves the process of the currently running thread.
namespace_t * process_get_ns(process_t *process)
Gets the namespace of a process.
clock_t clock_uptime(void)
Retrieve the time in nanoseconds since boot.
static thread_t * thread_current(void)
Retrieves the currently running thread.
uint64_t thread_copy_from_user_pathname(thread_t *thread, pathname_t *pathname, const char *userPath)
Safely copy a string from user space and use it to initialize a pathname.
uint64_t thread_copy_to_user(thread_t *thread, void *userDest, const void *src, uint64_t length)
Safely copy data to user space.
uint64_t wait_block_prepare(wait_queue_t **waitQueues, uint64_t amount, clock_t timeout)
Prepare to block the currently running thread.
uint64_t wait_block_commit(void)
Block the currently running thread.
void wait_block_cancel(void)
Cancels blocking of the currently running thread.
void mutex_release(mutex_t *mtx)
Releases a mutex.
void mutex_acquire(mutex_t *mtx)
Acquires a mutex, blocking until it is available.
#define MUTEX_SCOPE(mutex)
Acquires a mutex for the reminder of the current scope.
static void rcu_read_unlock(void)
RCU read-side critical section end.
static void rcu_read_lock(void)
RCU read-side critical section begin.
#define REF_COUNT(ptr)
Get current reference count.
#define UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
#define UNREF(ptr)
Decrement reference count.
size_t vfs_seek(file_t *file, ssize_t offset, seek_origin_t origin)
Seek in a file.
uint64_t vfs_poll(poll_file_t *files, uint64_t amount, clock_t timeout)
Poll multiple files.
size_t vfs_write(file_t *file, const void *buffer, size_t count)
Write to a file.
size_t vfs_read(file_t *file, void *buffer, size_t count)
Read from a file.
file_t * vfs_open(const pathname_t *pathname, process_t *process)
Open a file.
size_t vfs_readlink(vnode_t *symlink, char *buffer, size_t count)
Read the path in a symbolic link.
uint64_t vfs_symlink(const pathname_t *oldPathname, const pathname_t *newPathname, process_t *process)
Create a symbolic link.
size_t vfs_getdents(file_t *file, dirent_t *buffer, size_t count)
Get directory entries from a directory file.
uint64_t vfs_remove(const pathname_t *pathname, process_t *process)
Remove a file or directory.
uint64_t vfs_stat(const pathname_t *pathname, stat_t *buffer, process_t *process)
Get file information.
file_t * vfs_openat(const path_t *from, const pathname_t *pathname, process_t *process)
Open a file relative to another path.
void * vfs_mmap(file_t *file, void *address, size_t length, pml_flags_t flags)
Memory map a file.
uint64_t vfs_link(const pathname_t *oldPathname, const pathname_t *newPathname, process_t *process)
Make the same file appear twice in the filesystem.
uint64_t vfs_open2(const pathname_t *pathname, file_t *files[2], process_t *process)
Open one file, returning two file handles.
uint64_t vfs_ioctl(file_t *file, uint64_t request, void *argp, size_t size)
Perform an ioctl operation on a file.
uint64_t vfs_id_get(void)
Generates a new unique ID, to be used for any VFS object.
#define ENOENT
No such file or directory.
#define EEXIST
File exists.
#define ESPIPE
Illegal seek.
#define EINVAL
Invalid argument.
#define EXDEV
Cross-device link.
#define EFAULT
Bad address.
#define ENOSYS
Function not implemented.
#define ETIMEDOUT
Connection timed out.
#define ENOMEM
Out of memory.
#define EBUSY
Device or resource busy.
#define ENOTDIR
Not a directory.
#define errno
Error number variable.
#define ENODEV
No such device.
#define EACCES
Permission denied.
#define ENOTTY
Not a typewriter.
#define EBADF
Bad file number.
#define EPERM
Operation not permitted.
#define EISDIR
Is a directory.
dirent_flags_t
Directory entry flags.
uint64_t mount(const char *mountpoint, const char *fs, const char *options)
System call for mounting a filesystem.
uint64_t symlink(const char *target, const char *linkpath)
System call for creating a symbolic link.
uint8_t seek_origin_t
Type for the seek() origin argument.
poll_events_t
Poll events type.
#define POLL_SPECIAL
Poll event values that will always be checked and included even if not specified.
@ VSYMLINK
Is a symbolic link.
@ DIRENT_MOUNTED
The directory entry is a mountpoint.
@ POLLNVAL
Invalid file descriptor.
clock_t uptime(void)
System call for retreving the time since boot.
prot_t
Memory protection flags.
@ PROT_READ
Readable memory.
@ PROT_EXECUTE
Executable memory.
@ PROT_WRITE
Writable memory.
#define NULL
Pointer error value.
__INT64_TYPE__ ssize_t
Signed size type.
#define FD_NONE
No file descriptor.
#define ERR
Integer error value.
#define CLOCKS_REMAINING(deadline, uptime)
Safely calculate remaining time until deadline.
__UINT64_TYPE__ fd_t
File descriptor type.
#define CLOCKS_DEADLINE(timeout, uptime)
Safely calculate deadline from timeout.
__UINT64_TYPE__ clock_t
A nanosecond time.
static const path_flag_t flags[]
#define RFLAGS_INTERRUPT_ENABLE
static uint64_t rflags_read(void)
#define atomic_load(object)
#define ATOMIC_VAR_INIT(value)
#define atomic_fetch_add(object, operand)
_PUBLIC int snprintf(char *_RESTRICT s, size_t n, const char *_RESTRICT format,...)
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
_PUBLIC char * strncpy(char *_RESTRICT s1, const char *_RESTRICT s2, size_t n)
_PUBLIC size_t strlen(const char *s)
_PUBLIC char * strrchr(const char *s, int c)
_PUBLIC int strcmp(const char *s1, const char *s2)
_PUBLIC void * memset(void *s, int c, size_t n)
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.
dentry_t * parent
The parent dentry, will be itself if this is the root 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 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.
char path[MAX_PATH]
The relative path of the entry.
char mode[MAX_PATH]
The flags of the paths mount.
size_t(* seek)(file_t *file, ssize_t offset, seek_origin_t origin)
size_t(* read)(file_t *file, void *buffer, size_t count, size_t *offset)
void *(* mmap)(file_t *file, void *address, size_t length, size_t *offset, pml_flags_t flags)
size_t(* write)(file_t *file, const void *buffer, size_t count, size_t *offset)
uint64_t(* ioctl)(file_t *file, uint64_t request, void *argp, size_t size)
uint64_t(* open)(file_t *file)
mode_t mode
Specifies the maximum permissions for this mount and if it is a directory or a file.
A entry in a page table without a specified address or callback ID.
Structure for polling multiple files.
Poll file descriptor structure.
poll_events_t revents
The events that occurred.
poll_events_t events
The events to wait for.
fd_t fd
The file descriptor to poll.
Virtual address space structure.
Thread of execution structure.
process_t * process
The parent process that the thread executes within.
stack_pointer_t userStack
The user stack of the thread.
uint16_t lookupTable[CONFIG_MAX_FD]
wait_queue_t * queues[CONFIG_MAX_FD]
uint64_t(* link)(vnode_t *dir, dentry_t *old, dentry_t *new)
Make the same file vnode appear twice in the filesystem.
uint64_t(* symlink)(vnode_t *dir, dentry_t *target, const char *dest)
Create a symbolic link.
uint64_t size
Used for convenience by certain filesystems, does not represent the file size.
The primitive that threads block on.
static uint64_t vfs_open_lookup(path_t *path, const pathname_t *pathname, namespace_t *namespace)
static uint64_t vfs_create(path_t *path, const pathname_t *pathname, namespace_t *ns)
static uint64_t vfs_poll_ctx_check_events(vfs_poll_ctx_t *ctx, poll_file_t *files, uint64_t amount)
static bool vfs_dir_emit(dir_ctx_t *ctx, const char *name, vtype_t type)
static uint64_t vfs_poll_ctx_init(vfs_poll_ctx_t *ctx, poll_file_t *files, uint64_t amount)
static uint64_t vfs_remove_recursive(path_t *path, process_t *process)
static uint64_t vfs_getdents_recursive_step(path_t *path, mode_t mode, getdents_recursive_ctx_t *ctx, const char *prefix, namespace_t *ns)