18typedef struct path_flag_short
36typedef struct path_flag
57 if (flag ==
NULL || length == 0)
65 if (len == length &&
strncmp(flag,
flags[i].name, length) == 0)
72 for (
uint64_t i = 0; i < length; i++)
116 while (
string[index] !=
'\0' &&
string[index] !=
':')
118 if (
string[index] ==
'/')
120 currentNameLength = 0;
137 pathname->
string[index] =
string[index];
141 pathname->
string[index] =
'\0';
143 if (
string[index] !=
':')
150 const char*
flags = &
string[index];
154 while (
string[index] ==
':')
159 if (
string[index] ==
'\0')
164 const char* token = &
string[index];
165 while (
string[index] !=
'\0' &&
string[index] !=
':')
175 uint64_t tokenLength = &
string[index] - token;
189 pathname->
mode |= mode;
355 const char* p = pathname->
string;
356 if (pathname->
string[0] ==
'/')
391 const char* componentStart = p;
392 while (*p !=
'\0' && *p !=
'/')
409 memcpy(component, componentStart, len);
410 component[len] =
'\0';
412 if (
strcmp(component,
".") == 0)
417 if (
strcmp(component,
"..") == 0)
461 while (len > 1 &&
string[len - 1] ==
'/')
463 string[len - 1] =
'\0';
467 char* lastSlash =
strrchr(
string,
'/');
468 if (lastSlash ==
NULL)
475 char* lastComponent = lastSlash + 1;
479 if (lastSlash ==
string)
494 return path_walk(path, &parentPathname, ns);
538 pathname->
string[index] =
'\0';
546 pathname->
string[index] =
'/';
555 if (index < nameLength + 1)
567 pathname->
string[index] =
'/';
575 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)
dentry_t * dentry_lookup(const path_t *parent, const char *name)
Lookup a dentry for the given name. Will NOT traverse mountpoints.
#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 *out)
Get the root path of a namespace.
uint64_t namespace_traverse(namespace_t *ns, path_t *path)
If the given path is a mountpoint in the namespace, traverse to the mounted filesystem,...
mode_t
Path flags and permissions.
void path_put(path_t *path)
Put a path.
#define PATH_CREATE(inMount, inDentry)
Helper to create a path.
#define PATH_DEFER(path)
Defer path put.
uint64_t path_step(path_t *path, const char *component, namespace_t *ns)
Walk a single step in a path.
#define PATH_HANDLE_DOTDOT_MAX_ITER
Maximum iterations to handle .. in 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.
uint64_t path_walk_parent(path_t *path, const pathname_t *pathname, char *outLastName, namespace_t *ns)
Walk a pathname to its parent and get the name of the last 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.
uint64_t path_to_name(const path_t *path, pathname_t *pathname)
Convert a path to a pathname.
#define UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
#define REF(ptr)
Increment reference count.
#define UNREF(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 errno
Error number variable.
#define NULL
Pointer error value.
#define ERR
Integer error value.
static const path_flag_t flags[]
static uint64_t path_handle_dotdot(path_t *path)
static bool path_is_name_valid(const char *name)
static path_flag_short_t shortFlags[UINT8_MAX+1]
static mode_t path_flag_to_mode(const char *flag, uint64_t length)
static map_t flagShortMap
_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 int strncmp(const char *s1, const char *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.
char name[MAX_NAME]
Constant after creation.
dentry_t * target
The dentry which the source is mounted to, can be NULL for the root filesystem.
mount_t * parent
The parent mount, can be NULL for the root filesystem.
dentry_t * source
The dentry to appear at target once mounted, usually the root dentry of the mounted filesystem.