16typedef struct path_flag_entry
36 if (flag ==
NULL || length == 0)
95 panic(
NULL,
"Failed to init short flag map");
102 if (pathname ==
NULL)
127 while (
string[index] !=
'\0' &&
string[index] !=
':')
129 if (
string[index] ==
'/')
131 currentNameLength = 0;
148 pathname->
string[index] =
string[index];
152 pathname->
string[index] =
'\0';
154 if (
string[index] !=
':')
161 const char* flags = &
string[index];
165 while (
string[index] ==
':')
170 if (
string[index] ==
'\0')
175 const char* token = &
string[index];
176 while (
string[index] !=
'\0' &&
string[index] !=
':')
186 uint64_t tokenLength = &
string[index] - token;
289 current->
mount = newMount;
291 current->
dentry = newDentry;
305 if (parent ==
NULL || parent == current->
dentry)
313 current->
dentry = new_parent;
385 if (pathname->
string[0] ==
'\0')
392 const char* p = pathname->
string;
393 if (pathname->
string[0] ==
'/')
439 const char* componentStart = p;
440 while (*p !=
'\0' && *p !=
'/')
457 memcpy(component, componentStart, len);
458 component[len] =
'\0';
460 if (
strcmp(component,
".") == 0)
465 if (
strcmp(component,
"..") == 0)
520 if (pathname->
string[0] ==
'\0')
539 while (len > 1 &&
string[len - 1] ==
'/')
541 string[len - 1] =
'\0';
545 char* lastSlash =
strrchr(
string,
'/');
546 if (lastSlash ==
NULL)
561 char* lastComponent = lastSlash + 1;
565 if (lastSlash ==
string)
600 pathname->
string[index] =
'\0';
608 pathname->
string[index] =
'/';
617 if (index < nameLength + 1)
629 pathname->
string[index] =
'/';
637 pathname->
string[length] =
'\0';
#define MAX_NAME
Maximum length of names.
#define MAX_PATH
Maximum length of filepaths.
#define assert(expression)
_PUBLIC int isalnum(int c)
#define DENTRY_IS_ROOT(dentry)
Macro to check if a dentry is the root entry in its filesystem.
uint64_t namespace_get_root_path(namespace_t *ns, path_t *outPath)
Get the root path of a namespace.
uint64_t namespace_traverse_mount(namespace_t *ns, const path_t *mountpoint, path_t *outRoot)
Traverse a mountpoint path to the root of the mounted filesystem.
uint64_t path_walk_parent(path_t *outPath, const pathname_t *pathname, const path_t *start, char *outLastName, walk_flags_t flags, namespace_t *ns)
Traverse a pathname to its parent and get the last component name.
void path_put(path_t *path)
Put a path.
#define PATH_CREATE(inMount, inDentry)
Helper to create a path.
uint64_t path_walk(path_t *outPath, const pathname_t *pathname, const path_t *start, walk_flags_t flags, namespace_t *ns)
Traverse a pathname from a specified starting path.
#define PATH_DEFER(path)
Defer path put.
#define PATH_HANDLE_DOTDOT_MAX_ITER
Maximum iterations to handle .. in a path.
uint64_t path_walk_single_step(path_t *outPath, const path_t *parent, const char *component, walk_flags_t flags, namespace_t *ns)
Traverse a single component from a parent path.
walk_flags_t
Flags for walking a path.
void path_set(path_t *path, mount_t *mount, dentry_t *dentry)
Set a path.
#define PATH_VALID_CHAR(ch)
Check if a char is valid.
#define PATHNAME_IS_VALID(pathname)
Check if a pathname is valid.
void path_flags_init(void)
Initialize path flags resolution.
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.
uint64_t path_to_name(const path_t *path, pathname_t *pathname)
Convert a path to a pathname.
#define PATH_EMPTY
Helper to create an empty path.
@ WALK_NEGATIVE_IS_OK
If a negative dentry is ok, if not specified then it is considered an error.
bool vfs_is_name_valid(const char *name)
Check if a name is valid.
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.
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
static map_key_t map_key_buffer(const void *buffer, uint64_t length)
Create a map key from a buffer.
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.
uint64_t map_init(map_t *map)
Initialize a 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 DEREF_DEFER(ptr)
RAII-style cleanup for scoped references.
#define REF(ptr)
Increment reference count.
#define DEREF(ptr)
Decrement reference count.
#define ENOENT
No such file or directory.
#define EINVAL
Invalid argument.
#define ELOOP
Too many symbolic links encountered.
#define ENAMETOOLONG
File name too long.
#define EBADFLAG
Invalid path flag.
#define errno
Error number variable.
#define NULL
Pointer error value.
#define ERR
Integer error value.
#define CONTAINER_OF_SAFE(ptr, type, member)
Safe container of macro.
static uint64_t path_handle_dotdot(path_t *current)
static path_flag_entry_t flagEntries[]
static path_flag_entry_t * path_flags_get(const char *flag, uint64_t length)
static map_t flagShortMap
#define atomic_load(object)
_PUBLIC void * memmove(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
_PUBLIC char * strncpy(char *_RESTRICT s1, const char *_RESTRICT s2, size_t n)
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
_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)
size_t strnlen_s(const char *s, size_t maxsize)
Directory entry structure.
atomic_uint64_t mountCount
dentry_t * mountpoint
The dentry that this filesystem is mounted on, can be NULL for the root filesystem.
dentry_t * root
The root dentry of the mounted filesystem.
mount_t * parent
The parent mount, can be NULL for the root filesystem.