vfs: add vfs_open

vfs_open parses a path and returns the correct inode. The out inode is a
double pointer argument passed to vfs_open, and the return value is an
error code, or 0

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-07-01 23:06:39 +02:00
commit a8540494a9
11 changed files with 345 additions and 137 deletions

View file

@ -15,9 +15,7 @@ void *memcpy(void *dest, const void *src, size_t num)
int strcmp(const char *a, const char *b)
{
while (*a && *b) {
if (*a != *b)
return *a - *b;
while (*a && *a == *b) {
a++;
b++;
}
@ -26,12 +24,14 @@ int strcmp(const char *a, const char *b)
int strncmp(const char *a, const char *b, size_t n)
{
if (n == 0)
return 0;
for (size_t i = 0; i < n; i++) {
if (a[i] != b[i])
if (a[i] != b[i] || !a[i] || !b[i])
return a[i] - b[i];
if (!a[i] || !b[i])
break;
}
return 0;
}
@ -177,24 +177,21 @@ static char *udirname(char *path)
if (!path || !*path)
return ".";
size_t len = strlen(path);
while (len > 1 && path[len - 1] == '/')
path[--len] = '\0';
int last_slash_idx = -1;
for (int i = 0; path[i] != '\0'; i++)
if (path[i] == '/')
last_slash_idx = i;
if (last_slash_idx == -1)
return ".";
return ".";
if (last_slash_idx == 0)
return "/";
return "/";
path[last_slash_idx] = '\0';
path[last_slash_idx] = '\0';
return path;
}
@ -203,18 +200,15 @@ static char *ubasename(char *path)
if (!path || !*path)
return ".";
size_t len = strlen(path);
while (len > 1 && path[len - 1] == '/')
path[--len] = '\0';
int last_slash_idx = -1;
for (int i = 0; path[i] != '\0'; i++)
if (path[i] == '/')
last_slash_idx = i;
if (last_slash_idx == -1)
return path;
if (path[last_slash_idx + 1] == '\0' && last_slash_idx == 0)