29 buffer.parentId = parentId;
30 buffer.mountpointId = mountpointId;
203 if (
stack->count == 0)
323 if (ancestor == descendant)
361 bool traversed =
false;
558 if (filesystem ==
NULL)
630 if (sourceFile ==
NULL)
#define MAX_PATH
Maximum length of filepaths.
#define assert(expression)
EFI_PHYSICAL_ADDRESS buffer
#define SYSCALL_DEFINE(num, returnType,...)
Macro to define a syscall.
static clock_source_t source
Structure to describe the HPET to the sys time subsystem.
path_t cwd_get(cwd_t *cwd, namespace_t *ns)
Get the current working directory.
uint64_t dentry_id_t
Dentry ID type.
file_t * file_table_get(file_table_t *table, fd_t fd)
Get a file from its file descriptor.
filesystem_t * filesystem_get_by_path(const char *path, process_t *process)
Gets a filesystem by path.
mount_t * mount_new(superblock_t *superblock, dentry_t *source, dentry_t *target, mount_t *parent, mode_t mode)
Create a new mount.
#define MOUNT_IS_ROOT(mount)
Check if a mount is a root mount within its namespace.
uint64_t mount_id_t
Mount ID type.
mount_t * namespace_bind(namespace_t *ns, path_t *target, path_t *source, mode_t mode)
Bind a source path to a target path in a namespace.
void namespace_unmount(namespace_t *ns, mount_t *mount, mode_t mode)
Remove a mount in a namespace.
uint64_t namespace_copy(namespace_t *dest, namespace_t *src)
Copy mounts from one namespace to another.
namespace_t * namespace_new(namespace_t *parent)
Create a new namespace.
mount_t * namespace_mount(namespace_t *ns, path_t *target, filesystem_t *fs, const char *options, mode_t mode, void *data)
Mount a filesystem in a namespace.
void namespace_rcu_get_root(namespace_t *ns, mount_t **mount, dentry_t **dentry)
Get the root mount of a namespace in an RCU read critical section.
#define NAMESPACE_MAX_TRAVERSE
Maximum number of iterative mount traversals when following mountpoints.
void namespace_get_root(namespace_t *ns, path_t *out)
Get the root path of a namespace.
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...
bool namespace_accessible(namespace_t *ns, namespace_t *other)
Check if mounts in a namespace can be propagated to another namespace.
mode_t
Path flags and permissions.
#define PATH_IS_VALID(path)
Check if a path is valid.
uint64_t mode_check(mode_t *mode, mode_t maxPerms)
Check and adjust mode permissions.
#define PATH_DEFER(path)
Defer path put.
void path_set(path_t *path, mount_t *mount, dentry_t *dentry)
Set a path.
uint64_t path_walk(path_t *path, const pathname_t *pathname, namespace_t *ns)
Walk a pathname to a path.
namespace_t * process_get_ns(process_t *process)
Gets the namespace of a process.
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_from_user_string(thread_t *thread, char *dest, const char *userSrc, uint64_t size)
Safely copy a string from user space.
static void rwlock_write_release(rwlock_t *lock)
Releases a rwlock from writing.
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.
static void rwlock_write_acquire(rwlock_t *lock)
Acquires a rwlock for writing, blocking until it is available.
#define RWLOCK_WRITE_SCOPE(lock)
Acquires a rwlock for writing for the reminder of the current scope.
static map_key_t map_key_buffer(const void *buffer, uint64_t length)
Create a map key from a buffer.
void map_init(map_t *map)
Initialize a map.
void map_deinit(map_t *map)
Deinitialize a map.
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.
#define UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
#define REF(ptr)
Increment reference count.
static void ref_init(ref_t *ref, void *callback)
Initialize a reference counter.
#define UNREF(ptr)
Decrement reference count.
#define EINVAL
Invalid argument.
#define ENOMEM
Out of memory.
#define errno
Error number variable.
#define ARRAY_SIZE(x)
Get the number of elements in a static array.
uint64_t mount(const char *mountpoint, const char *fs, const char *options)
System call for mounting a filesystem.
uint64_t bind(const char *mountpoint, fd_t source)
System call for binding a file descriptor to a mountpoint.
#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 list_entry_t * list_first(list_t *list)
Gets the first entry in the list without removing it.
static void list_push_back(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list.
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 void list_init(list_t *list)
Initializes a list.
#define NULL
Pointer error value.
#define ERR
Integer error value.
#define CONTAINER_OF(ptr, type, member)
Container of macro.
__UINT64_TYPE__ fd_t
File descriptor type.
#define CONTAINER_OF_SAFE(ptr, type, member)
Safe container of macro.
static void namespace_remove(namespace_t *ns, mount_t *mount, mode_t mode)
static map_key_t root_key(void)
static bool namespace_is_descendant(namespace_t *ancestor, namespace_t *descendant)
static uint64_t mount_stack_init(namespace_t *ns, mount_stack_t *stack, map_key_t *key)
static void mount_stack_remove(mount_stack_t *stack, mount_t *mount)
static void namespace_free(namespace_t *ns)
static map_key_t mount_key_from_mount(mount_t *mount)
static map_key_t mount_key(mount_id_t parentId, dentry_id_t mountpointId)
static uint64_t namespace_add(namespace_t *ns, mount_t *mount)
static uint64_t mount_stack_push(mount_stack_t *stack, mount_t *mount)
static mount_stack_t * namespace_get_stack(namespace_t *ns, const map_key_t *key)
static void mount_stack_free(namespace_t *ns, mount_stack_t *stack)
static page_stack_t * stack
#define atomic_load(object)
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
_PUBLIC void * memmove(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
Directory entry structure.
superblock_t * superblock
Filesystem structure, represents a filesystem type, e.g. fat32, tmpfs, devfs, etc.
dentry_t *(* mount)(filesystem_t *fs, const char *details, void *data)
Mount a filesystem.
mount_t * mounts[MOUNT_STACK_MAX_MOUNTS]
dentry_t * source
The dentry to appear at target once mounted, usually the root dentry of the mounted filesystem.
mount_stack_t root
The root mount stack.
list_entry_t entry
The entry for the parent's children list.
namespace_t * parent
The parent namespace, can be NULL.
list_t stacks
List of mount_stack_t in this namespace.
map_t mountMap
Map used to go from source dentries to namespace mount stacks.
list_t children
List of child namespaces.
dentry_t * root
Root dentry of the filesystem, should not take a reference.
Thread of execution structure.
process_t * process
The parent process that the thread executes within.